Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mismatched gmso residue name when molecule is loaded from mol2 #37

Merged
merged 5 commits into from
Aug 31, 2023
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
6 changes: 6 additions & 0 deletions hoomd_organics/base/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ def _validate_force_field(self):
def assign_mol_name(self, name):
for mol in self.molecules:
mol.name = name
# TODO: This is a hack to make sure that the name of the children is
# also updated, so that when converting to gmso, all the sites have
# the correct name. This needs additional investigation into gmso's
# convert mbuilder to gmso functionality.
for child in mol.children:
child.name = name


class Polymer(Molecule):
Expand Down
17 changes: 17 additions & 0 deletions hoomd_organics/tests/base/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_single_mol_type(self, benzene_molecule):
)
assert system.n_mol_types == 1
assert len(system.all_molecules) == len(benzene_mols.molecules)
assert system.gmso_system.is_typed()
assert len(system.hoomd_forcefield) > 0
assert system.n_particles == system.hoomd_snapshot.particles.N
assert system.hoomd_snapshot.particles.types == ["opls_145", "opls_146"]
Expand All @@ -47,6 +48,7 @@ def test_multiple_mol_types(self, benzene_molecule, ethane_molecule):
)
assert system.all_molecules[0].name == "0"
assert system.all_molecules[-1].name == "1"
assert system.gmso_system.is_typed()
assert len(system.hoomd_forcefield) > 0
assert system.n_particles == system.hoomd_snapshot.particles.N
assert system.hoomd_snapshot.particles.types == [
Expand Down Expand Up @@ -74,6 +76,7 @@ def test_multiple_mol_types_different_ff(
) + len(pps_mol.molecules)
assert system.all_molecules[0].name == "0"
assert system.all_molecules[-1].name == "1"
assert system.gmso_system.is_typed()
assert len(system.hoomd_forcefield) > 0
for hoomd_force in system.hoomd_forcefield:
if isinstance(hoomd_force, hoomd.md.pair.LJ):
Expand All @@ -90,6 +93,19 @@ def test_multiple_mol_types_different_ff(
"sh",
]

def test_system_from_mol2_mol_parameterization(self, benzene_molecule_mol2):
benzene_mol = benzene_molecule_mol2(n_mols=3)
system = Pack(
molecules=[benzene_mol],
density=0.8,
r_cut=2.5,
force_field=OPLS_AA(),
auto_scale=True,
)
assert system.gmso_system.is_typed()
assert len(system.hoomd_forcefield) > 0
assert system.n_particles == system.hoomd_snapshot.particles.N

def test_remove_hydrogen(self, benzene_molecule):
benzene_mol = benzene_molecule(n_mols=3)
system = Pack(
Expand All @@ -100,6 +116,7 @@ def test_remove_hydrogen(self, benzene_molecule):
auto_scale=True,
remove_hydrogens=True,
)
assert system.gmso_system.is_typed()
assert len(system.hoomd_forcefield) > 0
assert list(system.hoomd_forcefield[0].params.keys()) == [
("opls_145", "opls_145")
Expand Down
8 changes: 8 additions & 0 deletions hoomd_organics/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ def _benzene_molecule(n_mols):

return _benzene_molecule

@pytest.fixture()
def benzene_molecule_mol2(self, benzene_mol2):
def _benzene_molecule(n_mols):
benzene = Molecule(num_mols=n_mols, file=benzene_mol2)
return benzene

return _benzene_molecule

@pytest.fixture()
def ethane_molecule(self, ethane_smiles):
def _ethane_molecule(n_mols):
Expand Down
Loading