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

Clear conformers before adding ones for analysis #29

Merged
merged 5 commits into from
Mar 22, 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
18 changes: 18 additions & 0 deletions yammbs/_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,21 @@ def tiny_cache() -> CachedResultCollection:
def diphenylvinylbenzene():
"""Return 1,2-diphenylvinylbenzene"""
return Molecule.from_smiles("c1ccc(cc1)C=C(c2ccccc2)c3ccccc3")


@pytest.fixture()
def allicin():
"""Return allicin, inspired by PQR"""
return Molecule.from_smiles(
"C=CCSS(=O)CC=C",
allow_undefined_stereo=True,
)


@pytest.fixture()
def conformers(allicin):
other_allicin = Molecule(allicin)

other_allicin.generate_conformers(n_conformers=10)

return other_allicin.conformers
72 changes: 71 additions & 1 deletion yammbs/_tests/unit_tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,77 @@
import pytest
from openff.toolkit import Molecule

from yammbs.analysis import get_internal_coordinate_rmsds
from yammbs.analysis import get_internal_coordinate_rmsds, get_rmsd, get_tfd


class TestAnalysis:
def test_rmsd(self, allicin, conformers):
# Passing the same conformers should return 0.0
last_last = get_rmsd(
molecule=allicin,
reference=conformers[-1],
target=conformers[-1],
)

assert last_last == 0.0

first_last = get_rmsd(
molecule=allicin,
reference=conformers[0],
target=conformers[-1],
)

assert isinstance(first_last, float)

first_second = get_rmsd(
molecule=allicin,
reference=conformers[0],
target=conformers[1],
)

assert first_second != first_last

last_first = get_rmsd(
molecule=allicin,
reference=conformers[-1],
target=conformers[0],
)

assert last_first == first_last

def test_tfd(self, allicin, conformers):
# Passing the same conformers should return 0.0
last_last = get_tfd(
molecule=allicin,
reference=conformers[-1],
target=conformers[-1],
)

assert last_last == 0.0

first_last = get_tfd(
molecule=allicin,
reference=conformers[0],
target=conformers[-1],
)

assert isinstance(first_last, float)

first_second = get_tfd(
molecule=allicin,
reference=conformers[0],
target=conformers[1],
)

assert first_second != first_last

last_first = get_tfd(
molecule=allicin,
reference=conformers[-1],
target=conformers[0],
)

assert last_first == first_last


class TestInternalCoordinateRMSD:
Expand Down
17 changes: 10 additions & 7 deletions yammbs/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ def get_rmsd(
from openff.units import Quantity, unit

molecule1 = Molecule(molecule)
molecule2 = Molecule(molecule)

for molecule in (molecule1, molecule2):
if molecule.conformers is not None:
molecule.conformers.clear()

molecule1.add_conformer(Quantity(reference, unit.angstrom))

molecule2 = Molecule(molecule)
molecule2.add_conformer(Quantity(target, unit.angstrom))

# oechem appears to not support named arguments, but it's hard to tell
Expand Down Expand Up @@ -210,8 +215,6 @@ def _rdmol(
molecule: Molecule,
conformer: Array,
):
from copy import deepcopy

from openff.units import Quantity, unit

# TODO: Do we need to remap indices?
Expand All @@ -236,11 +239,11 @@ def _rdmol(

molecule.remap(mapping_dict=atom_map)

molecule = deepcopy(molecule)
molecule = Molecule(molecule)
if molecule.conformers is not None:
molecule.conformers.clear()

molecule.add_conformer(
Quantity(conformer, unit.angstrom),
)
molecule.add_conformer(Quantity(conformer, unit.angstrom))

return molecule.to_rdkit()

Expand Down