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

Don't downcast molecules to single residues and atoms. [closes #16] #19

Merged
merged 1 commit into from
Mar 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions python/BioSimSpace/_SireWrappers/_search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/Sandpit/Exscientia/_SireWrappers/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test/_SireWrappers/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down