Skip to content

Commit c855d3d

Browse files
committed
Merge branch 'python' into walberla
2 parents 67bc916 + d574bfd commit c855d3d

7 files changed

Lines changed: 420 additions & 391 deletions

File tree

doc/sphinx/advanced_methods.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,13 +1494,15 @@ polarizability :math:`\alpha` (in units of inverse volume) with :math:`q_d =
14941494

14951495
The following helper method takes into account all the preceding considerations
14961496
and can be used to conveniently add a Drude particle to a given core particle.
1497-
As it also adds the first two bonds between Drude and core, these bonds have to
1498-
be created beforehand::
1497+
It returns an `espressomd.particle_data.ParticleHandle` to the created Drude
1498+
particle. Note that as the function also adds the first two bonds between Drude
1499+
and core, these bonds have to be already available.::
14991500

15001501
import espressomd.drude_helpers
1501-
espressomd.drude_helpers(<system>, <harmonic_bond>, <thermalized_bond>,
1502-
<core particle>, <id drude>, <type drude>, <alpha>, <mass drude>,
1503-
<coulomb_prefactor>, <thole damping>, <verbose>)
1502+
dh = espressomd.drude_helpers.DrudeHelpers()
1503+
drude_part = dh.add_drude_particle_to_core(<system>, <harmonic_bond>,
1504+
<thermalized_bond>, <core particle>, <type drude>, <alpha>,
1505+
<mass drude>, <coulomb_prefactor>, <thole damping>, <verbose>)
15041506

15051507
The arguments of the helper function are:
15061508
* ``<system>``: The :class:`espressomd.System() <espressomd.system.System>`.
@@ -1509,7 +1511,6 @@ The arguments of the helper function are:
15091511
* ``<thermalized_bond>``: The thermalized distance bond for the cold and hot
15101512
thermostats.
15111513
* ``<core particle>``: The core particle on which the Drude particle is added.
1512-
* ``<id drude>``: The user-defined id of the Drude particle that is created.
15131514
* ``<type drude>``: The user-defined type of the Drude particle.
15141515
Each Drude particle of each complex should have an
15151516
individual type (e.g. in an ionic system with Anions (type 0) and Cations
@@ -1528,10 +1529,11 @@ One bond type of this kind is needed per Drude type. The above helper function a
15281529
tracks particle types, ids and charges of Drude and core particles, so a simple call of
15291530
another helper function::
15301531

1531-
espressomd.drude_helpers.setup_and_add_drude_exclusion_bonds(S)
1532+
dh.setup_and_add_drude_exclusion_bonds(system)
15321533

15331534
will use this data to create a :ref:`Subtract P3M short-range bond` per Drude type
1534-
and set it up it between all Drude and core particles collected in calls of :meth:`~espressomd.drude_helpers.add_drude_particle_to_core`.
1535+
and set it up it between all Drude and core particles collected in calls of
1536+
:meth:`~espressomd.drude_helpers.DrudeHelpers.add_drude_particle_to_core`.
15351537

15361538
.. _Canceling intramolecular electrostatics:
15371539

doc/sphinx/inter_non-bonded.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ cores, except the one it's connected to. This exception is handled internally
635635
by disabling Thole interaction between particles connected via Drude bonds.
636636
Also, each Drude core has a Thole correction interaction with all other Drude
637637
cores and Drude charges. To assist with the bookkeeping of mixed scaling
638-
coefficients, the helper method :meth:`~espressomd.drude_helpers.add_drude_particle_to_core` (see
638+
coefficients, the helper method :meth:`~espressomd.drude_helpers.DrudeHelpers.add_drude_particle_to_core` (see
639639
:ref:`Particle polarizability with thermalized cold Drude oscillators`)
640640
collects all core types, Drude types and relevant parameters when a Drude
641641
particle is created. The user already provided all the information when
@@ -647,7 +647,7 @@ given the :class:`espressomd.System() <espressomd.system.System>` object, uses t
647647
necessary Thole interactions. The method calculates the mixed scaling
648648
coefficient ``s`` and creates the non-bonded Thole interactions between the
649649
collected types to cover all the Drude-Drude, Drude-core and core-core
650-
combinations. No further calls of :meth:`~espressomd.drude_helpers.add_drude_particle_to_core` should
650+
combinations. No further calls of :meth:`~espressomd.drude_helpers.DrudeHelpers.add_drude_particle_to_core` should
651651
follow. Set ``verbose`` to ``True`` to print out the coefficients, charge factors
652652
and involved types.
653653

samples/drude_bmimpf6.py

Lines changed: 56 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import espressomd.accumulators
3030
import espressomd.electrostatics
3131
import espressomd.interactions
32-
import espressomd.virtual_sites
3332
import espressomd.drude_helpers
33+
import espressomd.virtual_sites
3434
import espressomd.visualization_opengl
3535

3636
required_features = ["LENNARD_JONES", "P3M", "MASS", "ROTATION",
@@ -193,59 +193,36 @@ def combination_rule_sigma(rule, sig1, sig2):
193193
epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")
194194

195195
# Place Particles
196-
rid = 0
197-
anion_ids = []
198-
cation_sites_ids = []
199-
cation_com_ids = []
200-
cation_c1_ids = []
201-
cation_c2_ids = []
202-
cation_c3_ids = []
196+
anions = []
197+
cations = []
203198

204199
for i in range(n_ionpairs):
205-
system.part.add(id=rid, type=types["PF6"], pos=np.random.random(3) * box_l,
206-
q=charges["PF6"], mass=masses["PF6"])
207-
anion_ids.append(rid)
208-
if args.drude:
209-
rid += 2
210-
else:
211-
rid += 1
200+
# Add an anion ...
201+
anions.append(
202+
system.part.add(type=types["PF6"], pos=np.random.random(3) * box_l,
203+
q=charges["PF6"], mass=masses["PF6"]))
212204

213-
for i in range(n_ionpairs):
205+
# ... and a cation
214206
pos_com = np.random.random(3) * box_l
215-
system.part.add(
216-
id=rid, type=types["BMIM_COM"], pos=pos_com,
207+
cation_com = system.part.add(
208+
type=types["BMIM_COM"], pos=pos_com,
217209
mass=masses["BMIM_COM"], rinertia=[646.284, 585.158, 61.126],
218210
gamma=0, rotation=[1, 1, 1])
219-
cation_com_ids.append(rid)
220-
com_id = rid
221-
rid += 1
222-
system.part.add(id=rid, type=types["BMIM_C1"],
223-
pos=pos_com + [0, -0.527, 1.365], q=charges["BMIM_C1"])
224-
system.part[rid].vs_auto_relate_to(com_id)
225-
cation_c1_ids.append(rid)
226-
cation_sites_ids.append(rid)
227-
if args.drude:
228-
rid += 2
229-
else:
230-
rid += 1
231-
system.part.add(id=rid, type=types["BMIM_C2"],
232-
pos=pos_com + [0, 1.641, 2.987], q=charges["BMIM_C2"])
233-
system.part[rid].vs_auto_relate_to(com_id)
234-
cation_c2_ids.append(rid)
235-
cation_sites_ids.append(rid)
236-
if args.drude:
237-
rid += 2
238-
else:
239-
rid += 1
240-
system.part.add(id=rid, type=types["BMIM_C3"],
241-
pos=pos_com + [0, 0.187, -2.389], q=charges["BMIM_C3"])
242-
system.part[rid].vs_auto_relate_to(com_id)
243-
cation_c3_ids.append(rid)
244-
cation_sites_ids.append(rid)
245-
if args.drude:
246-
rid += 2
247-
else:
248-
rid += 1
211+
212+
cation_c1 = system.part.add(type=types["BMIM_C1"],
213+
pos=pos_com + [0, -0.527, 1.365], q=charges["BMIM_C1"])
214+
cation_c1.vs_auto_relate_to(cation_com)
215+
cations.append([cation_c1])
216+
217+
cation_c2 = system.part.add(type=types["BMIM_C2"],
218+
pos=pos_com + [0, 1.641, 2.987], q=charges["BMIM_C2"])
219+
cation_c2.vs_auto_relate_to(cation_com)
220+
cations[-1].append(cation_c2)
221+
222+
cation_c3 = system.part.add(type=types["BMIM_C3"],
223+
pos=pos_com + [0, 0.187, -2.389], q=charges["BMIM_C3"])
224+
cation_c3.vs_auto_relate_to(cation_com)
225+
cations[-1].append(cation_c3)
249226

250227
# ENERGY MINIMIZATION
251228
print("\n-->E minimization")
@@ -275,6 +252,8 @@ def combination_rule_sigma(rule, sig1, sig2):
275252

276253
system.actors.add(p3m)
277254

255+
cation_drude_parts = []
256+
278257
if args.drude:
279258
print("-->Adding Drude related bonds")
280259
thermalized_dist_bond = espressomd.interactions.ThermalizedBond(
@@ -286,53 +265,59 @@ def combination_rule_sigma(rule, sig1, sig2):
286265
system.bonded_inter.add(thermalized_dist_bond)
287266
system.bonded_inter.add(harmonic_bond)
288267

289-
for i in anion_ids:
290-
espressomd.drude_helpers.add_drude_particle_to_core(
291-
system, harmonic_bond, thermalized_dist_bond, system.part[i],
292-
i + 1, types["PF6_D"], polarizations["PF6"],
268+
dh = espressomd.drude_helpers.DrudeHelpers()
269+
270+
# Add Drude particles for the anions ...
271+
for anion in anions:
272+
dh.add_drude_particle_to_core(
273+
system, harmonic_bond, thermalized_dist_bond, anion,
274+
types["PF6_D"], polarizations["PF6"],
293275
args.mass_drude, coulomb_prefactor)
294-
for i in cation_c1_ids:
295-
espressomd.drude_helpers.add_drude_particle_to_core(
296-
system, harmonic_bond, thermalized_dist_bond, system.part[i],
297-
i + 1, types["BMIM_C1_D"], polarizations["BMIM_C1"],
276+
277+
# ... and for the cations
278+
for cation in cations:
279+
cation_c1_drude = dh.add_drude_particle_to_core(
280+
system, harmonic_bond, thermalized_dist_bond, cation[0],
281+
types["BMIM_C1_D"], polarizations["BMIM_C1"],
298282
args.mass_drude, coulomb_prefactor)
299-
for i in cation_c2_ids:
300-
espressomd.drude_helpers.add_drude_particle_to_core(
301-
system, harmonic_bond, thermalized_dist_bond, system.part[i],
302-
i + 1, types["BMIM_C2_D"], polarizations["BMIM_C2"],
283+
cation_drude_parts.append([cation_c1_drude])
284+
285+
cation_c2_drude = dh.add_drude_particle_to_core(
286+
system, harmonic_bond, thermalized_dist_bond, cation[1],
287+
types["BMIM_C2_D"], polarizations["BMIM_C2"],
303288
args.mass_drude, coulomb_prefactor)
304-
for i in cation_c3_ids:
305-
espressomd.drude_helpers.add_drude_particle_to_core(
306-
system, harmonic_bond, thermalized_dist_bond, system.part[i],
307-
i + 1, types["BMIM_C3_D"], polarizations["BMIM_C3"],
289+
cation_drude_parts[-1].append(cation_c2_drude)
290+
291+
cation_c3_drude = dh.add_drude_particle_to_core(
292+
system, harmonic_bond, thermalized_dist_bond, cation[2],
293+
types["BMIM_C3_D"], polarizations["BMIM_C3"],
308294
args.mass_drude, coulomb_prefactor)
295+
cation_drude_parts[-1].append(cation_c3_drude)
309296

310-
espressomd.drude_helpers.setup_and_add_drude_exclusion_bonds(system)
297+
dh.setup_and_add_drude_exclusion_bonds(system)
311298

312299
if args.thole:
313300
print("-->Adding Thole interactions")
314-
espressomd.drude_helpers.add_all_thole(system)
301+
dh.add_all_thole(system)
315302

316303
if args.intra_ex:
317304
# SETUP BONDS ONCE
318305
print("-->Adding intramolecular exclusions")
319-
espressomd.drude_helpers.setup_intramol_exclusion_bonds(
306+
dh.setup_intramol_exclusion_bonds(
320307
system,
321308
[types["BMIM_C1_D"], types["BMIM_C2_D"], types["BMIM_C3_D"]],
322309
[types["BMIM_C1"], types["BMIM_C2"], types["BMIM_C3"]],
323310
[charges["BMIM_C1"], charges["BMIM_C2"], charges["BMIM_C3"]])
324311

325312
# ADD SR EX BONDS PER MOLECULE
326-
for i in cation_c1_ids:
327-
espressomd.drude_helpers.add_intramol_exclusion_bonds(
328-
system, [i + 1, i + 3, i + 5], [i, i + 2, i + 4])
313+
for cation_drude_part, cation in zip(cation_drude_parts, cations):
314+
dh.add_intramol_exclusion_bonds(cation_drude_part, cation)
329315

330316
print("\n-->Short equilibration with smaller time step")
331317
system.time_step = 0.1 * fs_to_md_time
332318
system.integrator.run(1000)
333319
system.time_step = time_step_fs * fs_to_md_time
334320

335-
336321
print("\n-->Timing")
337322
start = time.time()
338323
n_timing_steps = 1000

0 commit comments

Comments
 (0)