Skip to content

Commit

Permalink
Fix failing tests with latest version of packmol (#1189)
Browse files Browse the repository at this point in the history
* Update packmol arguments to raise Errors on overlapping molecules on overpacked boxes

* Add test for old packmol on windows
  • Loading branch information
CalCraven authored Jun 3, 2024
1 parent fe6796a commit 2d16145
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mbuild/tests/test_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ def test_mass_property(self, h2o):

assert np.allclose(h2o.mass, 18.015, atol=1e-5)

system = mb.fill_box(compound=h2o, n_compounds=5, box=[0.5, 0.5, 0.5])
system = mb.fill_box(
compound=h2o, n_compounds=5, box=[0.5, 0.5, 0.5], overlap=0.01
)
assert np.allclose(system.mass, 5 * h2o.mass, atol=1e-5)

def test_mass_setter(self, ethane):
Expand Down Expand Up @@ -1471,7 +1473,7 @@ def test_fillbox_then_parmed(self):
box = Box.from_mins_maxs_angles(
mins=(2, 2, 2), maxs=(3, 3, 3), angles=(90.0, 90.0, 90.0)
)
bead_box = mb.fill_box(bead, 100, box=[2, 2, 2, 3, 3, 3])
bead_box = mb.fill_box(bead, 100, box=[2, 2, 2, 3, 3, 3], overlap=0.01)
bead_box_in_pmd = bead_box.to_parmed(box=box)

assert isinstance(bead_box_in_pmd, pmd.Structure)
Expand Down
12 changes: 10 additions & 2 deletions mbuild/tests/test_packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,16 @@ def test_packmol_error(self, h2o):
mb.fill_box(h2o, n_compounds=10, box=[0, 0, 0])

def test_packmol_warning(self, h2o):
with pytest.warns(UserWarning):
mb.fill_box(h2o, n_compounds=10, box=[1, 1, 1], overlap=10)
import sys

if (
"win" in sys.platform and not sys.platform == "darwin"
): # windows uses old 20.0.4 of packmol, which raises a warning
with pytest.warns(UserWarning):
mb.fill_box(h2o, n_compounds=10, box=[1, 1, 1], overlap=10)
else:
with pytest.raises(RuntimeError):
mb.fill_box(h2o, n_compounds=10, box=[1, 1, 1], overlap=10)

def test_rotate(self, h2o):
filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True)
Expand Down

0 comments on commit 2d16145

Please sign in to comment.