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

Add test to validate preservation of SDF stereochemistry #373

Merged
merged 1 commit into from
Dec 4, 2024
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
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
Loading