From e51631b4f034104e92286db12fbc30edf1244b15 Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Fri, 25 Oct 2024 14:39:37 -0600 Subject: [PATCH] add has_hoomd back to io.py, handle tests that use hoomd via gmso --- mbuild/tests/test_compound.py | 6 +++++- mbuild/tests/test_rigid.py | 3 ++- mbuild/utils/io.py | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mbuild/tests/test_compound.py b/mbuild/tests/test_compound.py index 80f0cc533..3ed142af9 100644 --- a/mbuild/tests/test_compound.py +++ b/mbuild/tests/test_compound.py @@ -16,6 +16,7 @@ get_fn, has_foyer, has_freud, + has_hoomd, has_intermol, has_mdtraj, has_networkx, @@ -383,6 +384,9 @@ def test_load_protein(self): ], ) def test_save_simple(self, ch3, extension): + # Can't save gsd files with Windows + if extension == ".gsd" as not has_hoomd: + return True outfile = "methyl_out" + extension ch3.save(filename=outfile) assert os.path.exists(outfile) @@ -425,7 +429,7 @@ def test_save_box(self, ch3): assert np.array_equal(pad_attr, custom_attr) def test_save_overwrite(self, ch3): - extensions = [".gsd", ".mol2", ".xyz", ".gro"] + extensions = [".mol2", ".xyz", ".gro"] for ext in extensions: outfile = "lyhtem" + ext ch3.save(filename=outfile) diff --git a/mbuild/tests/test_rigid.py b/mbuild/tests/test_rigid.py index 20066b885..26c5a9c1d 100644 --- a/mbuild/tests/test_rigid.py +++ b/mbuild/tests/test_rigid.py @@ -3,7 +3,7 @@ import mbuild as mb from mbuild.tests.base_test import BaseTest -from mbuild.utils.io import get_fn +from mbuild.utils.io import get_fn, has_hoomd class TestRigid(BaseTest): @@ -114,6 +114,7 @@ def test_label_rigid_bodies_single_partial(self, benzene): assert len(list(benzene.rigid_particles())) == 6 assert len(list(benzene.rigid_particles(rigid_id=0))) == 6 + @pytest.mark.skipif(not has_hoomd, reason="HOOMD not installed.") def test_save_non_sequential_rigid_ids(self, benzene): n_benzenes = 10 filled = mb.fill_box( diff --git a/mbuild/utils/io.py b/mbuild/utils/io.py index ec3de4a7a..7c2f2e0f0 100644 --- a/mbuild/utils/io.py +++ b/mbuild/utils/io.py @@ -259,6 +259,14 @@ def import_(module): raise DelayImportError(m) +try: + import hoomd + + has_hoomd = True + del hoomd +except ImportError: + has_hoomd = False + try: import intermol