Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions evaluator/utils/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import string
import subprocess
import tempfile
from collections import defaultdict
from distutils.spawn import find_executable
from functools import reduce

Expand Down Expand Up @@ -113,7 +114,6 @@ def pack_box(
raise ValueError("Either a `box_size` or `mass_density` must be specified.")

if box_size is not None and len(box_size) != 3:

raise ValueError("`box_size` must be a pint.Quantity wrapped list of length 3")

if mass_density is not None and box_aspect_ratio is None:
Expand All @@ -122,10 +122,11 @@ def pack_box(
if box_aspect_ratio is not None:

assert len(box_aspect_ratio) == 3
assert box_aspect_ratio[0] * box_aspect_ratio[1] * box_aspect_ratio[2] > 0
assert all(x > 0.0 for x in box_aspect_ratio)

# noinspection PyTypeChecker
if len(molecules) != len(number_of_copies):

raise ValueError(
"Length of `molecules` and `number_of_copies` must be identical."
)
Expand Down Expand Up @@ -488,6 +489,7 @@ def _create_pdb_and_topology(molecule, file_path):
topology = Topology.from_molecules([molecule])

with tempfile.NamedTemporaryFile(mode="r+", suffix=".pdb") as pdb_file:

PDBFile.writeFile(topology.to_openmm(), molecule.conformers[0], pdb_file)
pdb_file.flush()
mdtraj_molecule = mdtraj.load_pdb(pdb_file.name)
Expand Down Expand Up @@ -534,6 +536,18 @@ def _create_pdb_and_topology(molecule, file_path):
for atom in residue.atoms:
atom.name = "Na+"

else:

# Assign unique atom names as the OpenFF toolkit does not.
element_counter = defaultdict(int)

for atom in residue.atoms:

atom.name = (
f"{atom.element.symbol}{element_counter[atom.element.symbol] + 1}"
)
element_counter[atom.element.symbol] += 1

for original_residue_name in residue_map:

if residue_map[original_residue_name] is not None:
Expand Down