1313import string
1414import subprocess
1515import tempfile
16+ from collections import defaultdict
1617from distutils .spawn import find_executable
1718from functools import reduce
1819
@@ -113,7 +114,6 @@ def pack_box(
113114 raise ValueError ("Either a `box_size` or `mass_density` must be specified." )
114115
115116 if box_size is not None and len (box_size ) != 3 :
116-
117117 raise ValueError ("`box_size` must be a pint.Quantity wrapped list of length 3" )
118118
119119 if mass_density is not None and box_aspect_ratio is None :
@@ -122,10 +122,11 @@ def pack_box(
122122 if box_aspect_ratio is not None :
123123
124124 assert len (box_aspect_ratio ) == 3
125- assert box_aspect_ratio [ 0 ] * box_aspect_ratio [ 1 ] * box_aspect_ratio [ 2 ] > 0
125+ assert all ( x > 0.0 for x in box_aspect_ratio )
126126
127127 # noinspection PyTypeChecker
128128 if len (molecules ) != len (number_of_copies ):
129+
129130 raise ValueError (
130131 "Length of `molecules` and `number_of_copies` must be identical."
131132 )
@@ -488,6 +489,7 @@ def _create_pdb_and_topology(molecule, file_path):
488489 topology = Topology .from_molecules ([molecule ])
489490
490491 with tempfile .NamedTemporaryFile (mode = "r+" , suffix = ".pdb" ) as pdb_file :
492+
491493 PDBFile .writeFile (topology .to_openmm (), molecule .conformers [0 ], pdb_file )
492494 pdb_file .flush ()
493495 mdtraj_molecule = mdtraj .load_pdb (pdb_file .name )
@@ -534,6 +536,18 @@ def _create_pdb_and_topology(molecule, file_path):
534536 for atom in residue .atoms :
535537 atom .name = "Na+"
536538
539+ else :
540+
541+ # Assign unique atom names as the OpenFF toolkit does not.
542+ element_counter = defaultdict (int )
543+
544+ for atom in residue .atoms :
545+
546+ atom .name = (
547+ f"{ atom .element .symbol } { element_counter [atom .element .symbol ] + 1 } "
548+ )
549+ element_counter [atom .element .symbol ] += 1
550+
537551 for original_residue_name in residue_map :
538552
539553 if residue_map [original_residue_name ] is not None :
0 commit comments