Skip to content

Commit 93aba91

Browse files
authored
Merge branch 'python' into fix-4825
2 parents f418147 + 2c14952 commit 93aba91

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

doc/tutorials/electrodes/electrodes_part2.ipynb

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,18 +625,58 @@
625625
"metadata": {},
626626
"outputs": [],
627627
"source": [
628-
"system.integrator.set_steepest_descent(f_max=10, gamma=50.0,\n",
629-
" max_displacement=0.02)\n",
630-
"system.integrator.run(250)\n",
631-
"system.integrator.set_vv()\n",
632-
"system.thermostat.set_langevin(kT=1.0, gamma=0.1, seed=42)"
628+
"# suitable minimization parameters for this system\n",
629+
"F_TOL = 1e-2\n",
630+
"DAMPING = 30\n",
631+
"MAX_STEPS = 10000\n",
632+
"MAX_DISPLACEMENT = 0.01 * LJ_SIGMA\n",
633+
"EM_STEP = 10"
634+
]
635+
},
636+
{
637+
"cell_type": "code",
638+
"execution_count": null,
639+
"metadata": {
640+
"scrolled": true
641+
},
642+
"outputs": [],
643+
"source": [
644+
"# Set up steepest descent integration\n",
645+
"system.integrator.set_steepest_descent(f_max=0, # use a relative convergence criterion only\n",
646+
" gamma=DAMPING,\n",
647+
" max_displacement=MAX_DISPLACEMENT)\n",
648+
"\n",
649+
"# Initialize integrator to obtain initial forces\n",
650+
"system.integrator.run(0)\n",
651+
"old_force = np.max(np.linalg.norm(system.part.all().f, axis=1))\n",
652+
"\n",
653+
"\n",
654+
"while system.time / system.time_step < MAX_STEPS:\n",
655+
" system.integrator.run(EM_STEP)\n",
656+
" force = np.max(np.linalg.norm(system.part.all().f, axis=1))\n",
657+
" rel_force = np.abs((force - old_force) / old_force)\n",
658+
" print(f'rel. force change: {rel_force:.2e}')\n",
659+
" if rel_force < F_TOL:\n",
660+
" break\n",
661+
" old_force = force"
633662
]
634663
},
635664
{
636665
"cell_type": "markdown",
637666
"metadata": {},
638667
"source": [
639-
"## Equilibrate the ion distribution"
668+
"### 2.2 Equilibrate the ion distribution"
669+
]
670+
},
671+
{
672+
"cell_type": "code",
673+
"execution_count": null,
674+
"metadata": {},
675+
"outputs": [],
676+
"source": [
677+
"# Switch to velocity verlet integration using a Langevin thermostat\n",
678+
"system.integrator.set_vv()\n",
679+
"system.thermostat.set_langevin(kT=1.0, gamma=0.1, seed=42)"
640680
]
641681
},
642682
{
@@ -1015,7 +1055,9 @@
10151055
{
10161056
"cell_type": "code",
10171057
"execution_count": null,
1018-
"metadata": {},
1058+
"metadata": {
1059+
"scrolled": true
1060+
},
10191061
"outputs": [],
10201062
"source": [
10211063
"fig, ax = plt.subplots(figsize=(10, 6))\n",

testsuite/scripts/tutorials/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ tutorial_test(FILE test_ferrofluid_2.py)
6262
tutorial_test(FILE test_ferrofluid_3.py)
6363
tutorial_test(FILE test_constant_pH__ideal.py)
6464
tutorial_test(FILE test_electrodes_1.py)
65-
# tutorial_test(FILE test_electrodes_2.py) # TODO: unstable, see issue #4798
65+
tutorial_test(FILE test_electrodes_2.py)
6666
tutorial_test(FILE test_constant_pH__interactions.py)
6767
tutorial_test(FILE test_widom_insertion.py)
6868
tutorial_test(FILE test_grand_canonical_monte_carlo.py)

testsuite/scripts/tutorials/test_electrodes_2.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from scipy import constants
2424

2525
params = {'N_SAMPLES_EQUIL': 25, 'N_SAMPLES_PROD': 5,
26-
'N_SAMPLES_EQUIL_CAP': 5, 'N_SAMPLES_CAP': 1,
27-
'MIN_PHI': 1, 'MAX_PHI': 2.5, 'N_PHI': 4}
26+
'N_SAMPLES_EQUIL_CAP': 0, 'N_SAMPLES_CAP': 5,
27+
'MIN_PHI': 5, 'MAX_PHI': 5, 'N_PHI': 1}
2828

2929
tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
3030
"@TUTORIALS_DIR@/electrodes/electrodes_part2.py",
@@ -60,12 +60,13 @@ def test_charge_profile(self):
6060

6161
def test_capacitance(self):
6262
# For low potentials the capacitance should be in line with Grahame/DH
63-
# equilibration performance limiting
63+
# equilibration performance limiting, just use the system equilibrated
64+
# in the first part
6465
grahame = -tutorial.sigma_vs_phi[:, 0] / (
6566
constants.elementary_charge / (constants.Boltzmann * tutorial.TEMPERATURE))
6667
msg = 'The capacitance at low potentials should be in line with Grahame/DH.'
6768
np.testing.assert_allclose(
68-
grahame, tutorial.sigma_vs_phi[:, 1], atol=.015, err_msg=msg)
69+
grahame, tutorial.sigma_vs_phi[:, 1], atol=.05, err_msg=msg)
6970

7071

7172
if __name__ == "__main__":

0 commit comments

Comments
 (0)