From c55ba6b4cc6df88b8f2ff6be2f30e1e0979d427d Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Fri, 10 Mar 2023 16:00:12 +0000 Subject: [PATCH] Don't downcast molecules to single residues and atoms. [closes #16] --- .../Sandpit/Exscientia/_SireWrappers/_search_result.py | 10 +--------- python/BioSimSpace/_SireWrappers/_search_result.py | 10 +--------- test/Sandpit/Exscientia/_SireWrappers/test_system.py | 6 +++--- test/_SireWrappers/test_system.py | 6 +++--- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_search_result.py b/python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_search_result.py index 2c33900b4..0ce4b7062 100644 --- a/python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_search_result.py +++ b/python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_search_result.py @@ -141,15 +141,7 @@ def __getitem__(self, key): return _Residue(result) # Molecule. elif isinstance(result, _Sire.Mol._Mol.Molecule): - # If the molecule contains a single atom, then convert to an atom. - if result.nAtoms() == 1: - return _Atom(result.atom()) - # If there's a single residue, the convert to a residue. - elif result.nResidues() == 1: - return _Residue(result.residue()) - # Otherwise, append the molecule. - else: - return _Molecule(result) + return _Molecule(result) # Bond elif isinstance(result, _Sire.MM._MM.Bond): return _Bond(result) diff --git a/python/BioSimSpace/_SireWrappers/_search_result.py b/python/BioSimSpace/_SireWrappers/_search_result.py index 2c33900b4..0ce4b7062 100644 --- a/python/BioSimSpace/_SireWrappers/_search_result.py +++ b/python/BioSimSpace/_SireWrappers/_search_result.py @@ -141,15 +141,7 @@ def __getitem__(self, key): return _Residue(result) # Molecule. elif isinstance(result, _Sire.Mol._Mol.Molecule): - # If the molecule contains a single atom, then convert to an atom. - if result.nAtoms() == 1: - return _Atom(result.atom()) - # If there's a single residue, the convert to a residue. - elif result.nResidues() == 1: - return _Residue(result.residue()) - # Otherwise, append the molecule. - else: - return _Molecule(result) + return _Molecule(result) # Bond elif isinstance(result, _Sire.MM._MM.Bond): return _Bond(result) diff --git a/test/Sandpit/Exscientia/_SireWrappers/test_system.py b/test/Sandpit/Exscientia/_SireWrappers/test_system.py index 9c7e4514e..223cbe417 100644 --- a/test/Sandpit/Exscientia/_SireWrappers/test_system.py +++ b/test/Sandpit/Exscientia/_SireWrappers/test_system.py @@ -71,7 +71,7 @@ def test_atom_reindexing(system): def test_residue_reindexing(system): # Search for all waters by residue name. - results = system.search("resname WAT") + results = system.search("resname WAT").residues() # There are 3 residues in the alanine-dipeptide, then one in each water # molecule. This means that residue indexing should start at 3 and @@ -89,7 +89,7 @@ def test_residue_reindexing(system): def test_molecule_reindexing(system): # Search for all waters by residue name. - results = system.search("resname WAT") + results = system.search("resname WAT").molecules() # There are 631 molecules in the system: an alanine-dipeptide, followed by # 630 water molecules. This means that molecule indexing should start at 1 @@ -103,7 +103,7 @@ def test_molecule_reindexing(system): # As such, we convert each result to a molecule. for residue in results: # Ensure the absolute index matches. - assert system.getIndex(residue.toMolecule()) == index + assert system.getIndex(residue) == index index += 1 diff --git a/test/_SireWrappers/test_system.py b/test/_SireWrappers/test_system.py index 1ad8932ea..3b6b0cd90 100644 --- a/test/_SireWrappers/test_system.py +++ b/test/_SireWrappers/test_system.py @@ -71,7 +71,7 @@ def test_atom_reindexing(system): def test_residue_reindexing(system): # Search for all waters by residue name. - results = system.search("resname WAT") + results = system.search("resname WAT").residues() # There are 3 residues in the alanine-dipeptide, then one in each water # molecule. This means that residue indexing should start at 3 and @@ -89,7 +89,7 @@ def test_residue_reindexing(system): def test_molecule_reindexing(system): # Search for all waters by residue name. - results = system.search("resname WAT") + results = system.search("resname WAT").molecules() # There are 631 molecules in the system: an alanine-dipeptide, followed by # 630 water molecules. This means that molecule indexing should start at 1 @@ -103,7 +103,7 @@ def test_molecule_reindexing(system): # As such, we convert each result to a molecule. for residue in results: # Ensure the absolute index matches. - assert system.getIndex(residue.toMolecule()) == index + assert system.getIndex(residue) == index index += 1