Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions openff/interchange/_tests/unit_tests/components/test_packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,16 @@ def test_save_error_on_convergence_failure(self, use_local_path):
assert "STOP 173" in open("packmol_error.log").read()
else:
assert not pathlib.Path("packmol_error.log").is_file()

def test_trim_zero_molecules(self, caffeine, water, ligand, ethanol):
"""
Test that pack_box trims molecules from inputs when the count is zero.
See Issue #1267: https://github.com/openforcefield/openff-interchange/issues/1267
"""
topology = pack_box(
molecules=[caffeine, ligand, water, ethanol],
number_of_copies=[1, 0, 10, 0],
box_vectors=Quantity(3 * numpy.eye(3), "nanometer"),
)

assert topology.n_molecules == 11
10 changes: 7 additions & 3 deletions openff/interchange/components/_packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ def _build_input_file(
Parameters
----------
molecule_file_names: list of str
The paths to the molecule pdb files.
The paths to the molecule pdb files. No file will be produced for molecules where corresponding count is zero.
molecule_counts: list of int
The number of each molecule to add.
The number of each molecule to add. No file will be produced for molecules where corresponding count is zero.
structure_to_solvate: str, optional
The path to the structure to solvate.
box_size: openff.units.Quantity
Expand Down Expand Up @@ -504,6 +504,9 @@ def _build_input_file(

# Add a section for each type of molecule to add.
for file_name, count in zip(molecule_file_names, molecule_counts):
if count == 0:
continue

input_lines.extend(
[
f"structure {file_name}",
Expand Down Expand Up @@ -578,7 +581,8 @@ def pack_box(
The molecules in the system.
number_of_copies : list of int
A list of the number of copies of each molecule type, of length
equal to the length of ``molecules``.
equal to the length of ``molecules``. If any element is zero, the
corresponding molecule is not added.
solute: Topology, optional
An OpenFF :py:class:`Topology <openff.toolkit.Topology>` to
include in the box. If ``box_vectors`` and ``target_density`` are not
Expand Down
Loading