Skip to content

Commit

Permalink
add has_hoomd back to io.py, handle tests that use hoomd via gmso
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Oct 25, 2024
1 parent b625c6b commit e51631b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mbuild/tests/test_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
get_fn,
has_foyer,
has_freud,
has_hoomd,
has_intermol,
has_mdtraj,
has_networkx,
Expand Down Expand Up @@ -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:

Check failure

Code scanning / CodeQL

Syntax error Error test

Syntax Error (in Python 3).
return True
outfile = "methyl_out" + extension
ch3.save(filename=outfile)
assert os.path.exists(outfile)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion mbuild/tests/test_rigid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'get_fn' is not used.


class TestRigid(BaseTest):
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions mbuild/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ def import_(module):
raise DelayImportError(m)


try:
import hoomd

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'hoomd' is not used.

has_hoomd = True
del hoomd
except ImportError:
has_hoomd = False

try:
import intermol

Expand Down

0 comments on commit e51631b

Please sign in to comment.