Skip to content

Commit 2d9235d

Browse files
authored
Merge pull request #37 from molssi-seamm/dev
Bugfix: bonding incorrect in some cases.
2 parents e2ada58 + 5423af6 commit 2d9235d

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

HISTORY.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
=======
22
History
33
=======
4+
2024.6.29 -- Bugfix: bonding incorrect in some cases.
5+
* The use of PDB with Packmol could in some cases lead to multiple bonds in the
6+
wrong place. This release fixes that problem.
7+
48
2024.6.21.2 -- Another internal release for Docker.
59

610
2024.6.21.1 -- Internal release for Docker

packmol_step/packmol.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,20 @@ def run(self):
273273
self.logger.debug(pprint.pformat(result))
274274

275275
# Get the bond orders and extra parameters like ff atom types
276-
bond_orders = []
277276
extra_data = {}
278277
total_q = 0.0
278+
offset = 0
279+
i_indices = []
280+
j_indices = []
281+
bond_orders = []
279282
for molecule in molecules:
280283
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
283290

284291
total_q += n * molecule["configuration"].charge
285292

@@ -303,8 +310,12 @@ def run(self):
303310
configuration.coordinate_system = "Cartesian"
304311
configuration.from_pdb_text(result["packmol.pdb"]["data"])
305312

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.
308319
for key, values in extra_data.items():
309320
if key not in configuration.atoms:
310321
if "atom_types_" in key:
@@ -438,6 +449,9 @@ def round_copies(n_copies, molecules):
438449
if ff is not None:
439450
if ff_key not in tmp_configuration.atoms or assign_ff_always:
440451
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)
441455

442456
tmp_mass = tmp_configuration.mass * ureg.g / ureg.mol
443457
tmp_mass.ito("kg")
@@ -455,6 +469,14 @@ def round_copies(n_copies, molecules):
455469
n_fluid_atoms += count * tmp_configuration.n_atoms
456470
fluid_mass += count * tmp_mass
457471

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+
458480
molecules.append(
459481
{
460482
"configuration": tmp_configuration,
@@ -463,6 +485,7 @@ def round_copies(n_copies, molecules):
463485
"mass": tmp_mass,
464486
"n_atoms": tmp_configuration.n_atoms,
465487
"definition": definition,
488+
"bonds": bonds,
466489
}
467490
)
468491

0 commit comments

Comments
 (0)