Skip to content

Commit

Permalink
Enumerate input molecule with stereoisomers
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Nov 28, 2023
1 parent 779565b commit cb4073f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
2 changes: 2 additions & 0 deletions docs/releasehistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Releases follow the `major.minor.micro` scheme recommended by [PEP440](https://w

### Behavior changes

- [PR #17XX](https://github.com/openforcefield/openff-toolkit/pull/17XX): `Molecule.enumerate_stereoisomers` now includes the input molecule in the returned list.

### Bugfixes

### New features
Expand Down
20 changes: 10 additions & 10 deletions openff/toolkit/_tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,21 +2195,21 @@ def test_enumerating_stereobonds(self, toolkit_class):

# use the default options
isomers = mol.enumerate_stereoisomers()
assert len(isomers) == 2
assert len(isomers) == 3

assert mol not in isomers
assert mol in isomers
# make sure the input molecule is only different by bond stereo
for ismol in isomers:
for isomol in isomers:
assert (
Molecule.are_isomorphic(
mol,
ismol,
isomol,
return_atom_map=False,
bond_stereochemistry_matching=False,
)[0]
is True
)
assert mol.is_isomorphic_with(ismol) is False
assert mol.is_isomorphic_with(isomol) is False

# make sure the isomers are different
assert isomers[0].is_isomorphic_with(isomers[1]) is False
Expand All @@ -2233,19 +2233,19 @@ def test_enumerating_stereocenters(self, toolkit_class):

assert len(isomers) == 2
# make sure the mol is not in the isomers and that they only differ by stereo chem
assert mol not in isomers
for ismol in isomers:
assert ismol.n_conformers != 0
assert mol in isomers
for isomol in isomers:
assert isomol.n_conformers != 0
assert (
Molecule.are_isomorphic(
mol,
ismol,
isomol,
return_atom_map=False,
atom_stereochemistry_matching=False,
)[0]
is True
)
assert mol.is_isomorphic_with(ismol) is False
assert mol.is_isomorphic_with(isomol) is False

# make sure the two isomers are different
assert isomers[0].is_isomorphic_with(isomers[1]) is False
Expand Down
6 changes: 3 additions & 3 deletions openff/toolkit/topology/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4188,7 +4188,7 @@ def enumerate_stereoisomers(
max_isomers=20,
rationalise=True,
toolkit_registry=GLOBAL_TOOLKIT_REGISTRY,
):
) -> list["Molecule"]:
"""
Enumerate the stereocenters and bonds of the current molecule.
Expand All @@ -4209,8 +4209,8 @@ def enumerate_stereoisomers(
Returns
--------
molecules: List[openff.toolkit.topology.Molecule]
A list of :class:`Molecule` instances not including the input molecule.
molecules: list[openff.toolkit.Molecule]
A list of :class:`Molecule` instances including the input molecule.
"""

Expand Down
16 changes: 6 additions & 10 deletions openff/toolkit/utils/openeye_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,13 +855,13 @@ def enumerate_stereoisomers(
undefined_only: bool = False,
max_isomers: int = 20,
rationalise: bool = True,
) -> List["Molecule"]:
) -> list["Molecule"]:
"""
Enumerate the stereocenters and bonds of the current molecule.
Parameters
----------
molecule: openff.toolkit.topology.Molecule
molecule: openff.toolkit.Molecule
The molecule whose state we should enumerate
undefined_only: bool optional, default=False
Expand All @@ -876,8 +876,8 @@ def enumerate_stereoisomers(
Returns
--------
molecules: List[openff.toolkit.topology.Molecule]
A list of openff.toolkit.topology.Molecule instances
molecules: list[openff.toolkit.Molecule]
A list of openff.toolkit.Molecule instances including the input molecule.
"""
from openeye import oechem, oeomega
Expand All @@ -900,14 +900,10 @@ def enumerate_stereoisomers(
mol = oechem.OEMol(isomer)
status = omega(mol)
if status:
isomol = self.from_openeye(mol, _cls=molecule.__class__)
if isomol != molecule:
molecules.append(isomol)
molecules.append(self.from_openeye(mol, _cls=molecule.__class__))

else:
isomol = self.from_openeye(isomer, _cls=molecule.__class__)
if isomol != molecule:
molecules.append(isomol)
molecules.append(self.from_openeye(isomer, _cls=molecule.__class__))

return molecules[:max_isomers]

Expand Down
18 changes: 11 additions & 7 deletions openff/toolkit/utils/rdkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,13 @@ def enumerate_stereoisomers(
undefined_only: bool = False,
max_isomers: int = 20,
rationalise: bool = True,
) -> List["Molecule"]:
) -> list["Molecule"]:
"""
Enumerate the stereocenters and bonds of the current molecule.
Parameters
----------
molecule: openff.toolkit.topology.Molecule
molecule: openff.toolkit.Molecule
The molecule whose state we should enumerate
undefined_only: bool optional, default=False
Expand All @@ -1299,8 +1299,8 @@ def enumerate_stereoisomers(
Returns
--------
molecules: List[openff.toolkit.topology.Molecule]
A list of openff.toolkit.topology.Molecule instances
molecules: list[openff.toolkit.Molecule]
A list of openff.toolkit.Molecule instances including the input molecule.
"""
from rdkit import Chem
Expand Down Expand Up @@ -1332,9 +1332,13 @@ def enumerate_stereoisomers(
# isomer has CIS/TRANS tags so convert back to E/Z
Chem.SetDoubleBondNeighborDirections(isomer)
Chem.AssignStereochemistry(isomer, force=True, cleanIt=True)
mol = self.from_rdkit(isomer, _cls=molecule.__class__)
if mol != molecule:
molecules.append(mol)

molecules.append(
self.from_rdkit(
isomer,
_cls=molecule.__class__,
)
)

return molecules

Expand Down

0 comments on commit cb4073f

Please sign in to comment.