2929import espressomd .accumulators
3030import espressomd .electrostatics
3131import espressomd .interactions
32- import espressomd .virtual_sites
3332import espressomd .drude_helpers
33+ import espressomd .virtual_sites
3434import espressomd .visualization_opengl
3535
3636required_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
204199for 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
251228print ("\n -->E minimization" )
@@ -275,6 +252,8 @@ def combination_rule_sigma(rule, sig1, sig2):
275252
276253system .actors .add (p3m )
277254
255+ cation_drude_parts = []
256+
278257if 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
330316print ("\n -->Short equilibration with smaller time step" )
331317system .time_step = 0.1 * fs_to_md_time
332318system .integrator .run (1000 )
333319system .time_step = time_step_fs * fs_to_md_time
334320
335-
336321print ("\n -->Timing" )
337322start = time .time ()
338323n_timing_steps = 1000
0 commit comments