From 357aa315b15bea8102a4a67f50fa8b9c684477d2 Mon Sep 17 00:00:00 2001 From: PEFrankel <134018002+PEFrankel@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:35:50 -0600 Subject: [PATCH 1/3] Update _export.py --- openff/interchange/interop/gromacs/export/_export.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openff/interchange/interop/gromacs/export/_export.py b/openff/interchange/interop/gromacs/export/_export.py index e16f375b..f031d6ca 100644 --- a/openff/interchange/interop/gromacs/export/_export.py +++ b/openff/interchange/interop/gromacs/export/_export.py @@ -445,6 +445,7 @@ def _write_gro(self, gro, decimal: int): gro.write(f"{n_particles}\n") count = 0 + residue_id = 1 for molecule_name, molecule in self.system.molecule_types.items(): n_copies = self.system.molecules[molecule_name] @@ -456,7 +457,8 @@ def _write_gro(self, gro, decimal: int): f"%{decimal + 5}.{decimal}f" f"%{decimal + 5}.{decimal}f\n" % ( - atom.residue_index, # This needs to be looked up from a different data structure + residue_id = 1, + # (hidden: 1013) atom.residue_index, # This needs to be looked up from a different data structure atom.residue_name[:5], atom.name[:5], (count + 1) % 100000, @@ -467,6 +469,7 @@ def _write_gro(self, gro, decimal: int): ) count += 1 + residue_id += 1 if self.system.box is None: warnings.warn( From ce25fc4c600f7de3f68a89419d2857387bcfa1fa Mon Sep 17 00:00:00 2001 From: PEFrankel <134018002+PEFrankel@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:36:49 -0600 Subject: [PATCH 2/3] Update test_export.py --- .../interop/gromacs/export/test_export.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py b/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py index fbfcaca1..e01d3577 100644 --- a/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py +++ b/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py @@ -192,6 +192,27 @@ def test_atom_names_pdb(self): openmm_atom_names = openmm.app.GromacsGroFile("atom_names.gro").atomNames assert openmm_atom_names == pdb_atom_names + + def test_residue_id_increment(self): + """Test that residue IDs increment properly for multiple molecules.""" + + mol1 = MoleculeWithConformer.from_smiles("CCO") + mol2 = MoleculeWithConformer.from_smiles("CCO") + + for atom in mol1.atoms: + atom.metadata["residue_name"] = "MOL1" + for atom in mol2.atoms: + atom.metadata["residue_name"] = "MOL2" + + interchange = Interchange.from_smirnoff(ForceField("openff-2.0.0.offxml"), [mol1, mol2]) + interchange.to_gro("resid.gro") + + with open("resid.gro", "r") as gro_file: + lines = gro_file.readlines() + residue_ids = {int(line[:5].strip()) for line in lines[2:-2]} + + # expecting residue IDs 1 and 2 for MOL1 and MOL2 respectively + assert residue_ids == {1, 2} class TestGROMACS(_NeedsGROMACS): From c39effa366cc7e7a4a0af32b3ed6a54e3372a2ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:40:13 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../unit_tests/interop/gromacs/export/test_export.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py b/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py index e01d3577..dea1935c 100644 --- a/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py +++ b/openff/interchange/_tests/unit_tests/interop/gromacs/export/test_export.py @@ -192,7 +192,7 @@ def test_atom_names_pdb(self): openmm_atom_names = openmm.app.GromacsGroFile("atom_names.gro").atomNames assert openmm_atom_names == pdb_atom_names - + def test_residue_id_increment(self): """Test that residue IDs increment properly for multiple molecules.""" @@ -204,10 +204,12 @@ def test_residue_id_increment(self): for atom in mol2.atoms: atom.metadata["residue_name"] = "MOL2" - interchange = Interchange.from_smirnoff(ForceField("openff-2.0.0.offxml"), [mol1, mol2]) + interchange = Interchange.from_smirnoff( + ForceField("openff-2.0.0.offxml"), [mol1, mol2] + ) interchange.to_gro("resid.gro") - with open("resid.gro", "r") as gro_file: + with open("resid.gro") as gro_file: lines = gro_file.readlines() residue_ids = {int(line[:5].strip()) for line in lines[2:-2]}