@@ -273,13 +273,20 @@ def run(self):
273
273
self .logger .debug (pprint .pformat (result ))
274
274
275
275
# Get the bond orders and extra parameters like ff atom types
276
- bond_orders = []
277
276
extra_data = {}
278
277
total_q = 0.0
278
+ offset = 0
279
+ i_indices = []
280
+ j_indices = []
281
+ bond_orders = []
279
282
for molecule in molecules :
280
283
n = molecule ["number" ]
281
- orders = molecule ["configuration" ].bonds .get_column_data ("bondorder" )
282
- bond_orders .extend (orders * n )
284
+ for _ in range (n ):
285
+ for i , j , bond_order in molecule ["bonds" ]:
286
+ i_indices .append (i + offset )
287
+ j_indices .append (j + offset )
288
+ bond_orders .append (bond_order )
289
+ offset += molecule ["configuration" ].n_atoms
283
290
284
291
total_q += n * molecule ["configuration" ].charge
285
292
@@ -303,8 +310,12 @@ def run(self):
303
310
configuration .coordinate_system = "Cartesian"
304
311
configuration .from_pdb_text (result ["packmol.pdb" ]["data" ])
305
312
306
- # And set the bond orders and extra data we saved earlier.
307
- configuration .bonds .get_column ("bondorder" )[:] = bond_orders
313
+ ids = configuration .atoms .ids
314
+ i_atoms = [ids [x ] for x in i_indices ]
315
+ j_atoms = [ids [x ] for x in j_indices ]
316
+ configuration .bonds .append (i = i_atoms , j = j_atoms , bondorder = bond_orders )
317
+
318
+ # And set the extra data we saved earlier.
308
319
for key , values in extra_data .items ():
309
320
if key not in configuration .atoms :
310
321
if "atom_types_" in key :
@@ -438,6 +449,9 @@ def round_copies(n_copies, molecules):
438
449
if ff is not None :
439
450
if ff_key not in tmp_configuration .atoms or assign_ff_always :
440
451
ff .assign_forcefield (tmp_configuration )
452
+ else :
453
+ if any (typ is None for typ in tmp_configuration .atoms [ff_key ]):
454
+ ff .assign_forcefield (tmp_configuration )
441
455
442
456
tmp_mass = tmp_configuration .mass * ureg .g / ureg .mol
443
457
tmp_mass .ito ("kg" )
@@ -455,6 +469,14 @@ def round_copies(n_copies, molecules):
455
469
n_fluid_atoms += count * tmp_configuration .n_atoms
456
470
fluid_mass += count * tmp_mass
457
471
472
+ # Keep track of the bonding information to add at end_bond
473
+ bonds = []
474
+ index = {_id : i for i , _id in enumerate (tmp_configuration .atoms .ids )}
475
+ for row in tmp_configuration .bonds .bonds ():
476
+ bonds .append ((index [row ["i" ]], index [row ["j" ]], row ["bondorder" ]))
477
+ tmp_configuration .bonds .clear ()
478
+ tmp_configuration .db .commit ()
479
+
458
480
molecules .append (
459
481
{
460
482
"configuration" : tmp_configuration ,
@@ -463,6 +485,7 @@ def round_copies(n_copies, molecules):
463
485
"mass" : tmp_mass ,
464
486
"n_atoms" : tmp_configuration .n_atoms ,
465
487
"definition" : definition ,
488
+ "bonds" : bonds ,
466
489
}
467
490
)
468
491
0 commit comments