Skip to content

Commit

Permalink
Backport tests from PR #373. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Dec 4, 2024
1 parent 36fef25 commit b29e428
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Convert/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,36 @@ def test_molecule_rename():

# Make sure the name is correct.
assert mol._sire_object.name().value() == "smiles:[C@@H](C(F)(F)F)(OC(F)F)Cl"


@pytest.mark.parametrize("lig", ["2dd", "2hh", "2ii", "2s", "2x"])
def test_sdf_stereo(lig):
"""
Test that SDF stereochemistry is correctly preserved when converting
to RDKit format via Sire.
"""

import tempfile

from rdkit import Chem
from tests.conftest import url

# Load the molecule.
mol = BSS.IO.readMolecules(f"{url}/lig_{lig}.sdf")[0]

with tempfile.NamedTemporaryFile() as f:
# Write the molecule to a temporary file.
BSS.IO.saveMolecules(f.name, mol, "sdf")

# Load the molecule using RDKit.
rdmol = Chem.SDMolSupplier(f"{f.name}.sdf")[0]

# Convert the molecule using Sire.
rdmol_sire = BSS.Convert.toRDKit(mol)

# Get the SMILES strings.
smiles = Chem.CanonSmiles(Chem.MolToSmiles(rdmol))
smiles_sire = Chem.CanonSmiles(Chem.MolToSmiles(rdmol_sire))

# Check that the SMILES strings are the same.
assert smiles == smiles_sire
33 changes: 33 additions & 0 deletions tests/Sandpit/Exscientia/Convert/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,36 @@ def test_molecule_rename():

# Make sure the name is correct.
assert mol._sire_object.name().value() == "smiles:[C@@H](C(F)(F)F)(OC(F)F)Cl"


@pytest.mark.parametrize("lig", ["2dd", "2hh", "2ii", "2s", "2x"])
def test_sdf_stereo(lig):
"""
Test that SDF stereochemistry is correctly preserved when converting
to RDKit format via Sire.
"""

import tempfile

from rdkit import Chem
from tests.conftest import url

# Load the molecule.
mol = BSS.IO.readMolecules(f"{url}/lig_{lig}.sdf")[0]

with tempfile.NamedTemporaryFile() as f:
# Write the molecule to a temporary file.
BSS.IO.saveMolecules(f.name, mol, "sdf")

# Load the molecule using RDKit.
rdmol = Chem.SDMolSupplier(f"{f.name}.sdf")[0]

# Convert the molecule using Sire.
rdmol_sire = BSS.Convert.toRDKit(mol)

# Get the SMILES strings.
smiles = Chem.CanonSmiles(Chem.MolToSmiles(rdmol))
smiles_sire = Chem.CanonSmiles(Chem.MolToSmiles(rdmol_sire))

# Check that the SMILES strings are the same.
assert smiles == smiles_sire

0 comments on commit b29e428

Please sign in to comment.