Skip to content

Commit

Permalink
Fix undefined stereo crash (#73)
Browse files Browse the repository at this point in the history
* add failing test

* allow_undefined_stereo=True

* add data file

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ntBre and pre-commit-ci[bot] authored Oct 18, 2024
1 parent ce588da commit ee6d0dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion yammbs/_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def from_qcarchive_dataset(
store = cls(database_name)

for qm_molecule in tqdm(dataset.qm_molecules, desc="Storing molecules"):
molecule = Molecule.from_mapped_smiles(qm_molecule.mapped_smiles)
molecule = Molecule.from_mapped_smiles(qm_molecule.mapped_smiles, allow_undefined_stereo=True)
molecule.add_conformer(Quantity(qm_molecule.coordinates, "angstrom"))

molecule_record = MoleculeRecord.from_molecule(molecule)
Expand Down
1 change: 1 addition & 0 deletions yammbs/_tests/data/qcsubmit/undefined_stereo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":78,"mapped_smiles":"[H:44][c:14]1[c:15]([c:9]([n:10][c:11]([c:13]1[c:16]2[c:17]([c:18]([c:19]3[c:27]([n:28]2)[C:22]4([C:23]([C:24]([C:25]([C:26]4([H:57])[H:58])([H:55])[H:56])([H:53])[H:54])([H:51])[H:52])[C:21]([N:20]3[H:48])([H:49])[H:50])[H:47])[H:46])[C:12]([H:41])([H:42])[H:43])[N:7]5[C:8]([C@@:3]([C:4]([C:5]([C:6]5([H:37])[H:38])([H:35])[H:36])([H:33])[H:34])([H:32])[O:2][C:1]([H:29])([H:30])[H:31])([H:39])[H:40])[H:45]","coordinates":[-6.614268036880124,4.456207459786618,-1.341378083620013,-6.944040644557649,4.896985480707009,-0.0321711332506204,-6.444871798757717,6.190885538746901,0.3138457115939391,-6.910109365722674,6.471185481455593,1.7500437183114648,-5.8450990048874125,6.0559420823466255,2.7852942726496255,-4.989742401925721,4.885972380703976,2.2978224496729793,-4.283276955430979,5.2700821549845145,1.0679564038929545,-4.913472043560803,6.271275135148229,0.21758616291180655,-3.250167334691708,4.481385096607622,0.6105247321806675,-2.9880754602875332,3.366712764534656,1.3141183518197672,-2.016862100596807,2.525014617348596,0.9215759682180756,-1.8053066242316396,1.353799666743747,1.8558792368170767,-1.248562260238222,2.741659426035192,-0.24048208271700333,-1.482730900681324,3.9499491674283527,-0.9272640451920855,-2.4669463358075117,4.8305697832272045,-0.5198691269511165,-0.19886371591388274,1.8286895526266878,-0.7517885439250372,-0.33408482674632417,0.4296337715181365,-0.7394908870613991,0.6690119841948912,-0.39794163960372186,-1.2614371431436922,1.7968244145248562,0.22723631669387692,-1.786874743344694,2.9265155508356604,-0.30158802048339556,-2.4279656119445634,3.943853993256628,0.7779888560889352,-2.474070144050786,3.115249155456596,2.0942329131796957,-2.461919334965928,3.8446512132419093,3.2808760318138552,-1.815356746054012,4.802289189806944,3.791977821134112,-2.9112000721369258,4.113383893392354,3.438687620814614,-4.2631566527186,2.849294709061164,2.6253772968437405,-3.8935436465184083,1.845989519955214,1.633145300200686,-1.7778651580622125,0.8971314751211618,2.419006111094175,-1.2976781858065471,-5.55521026760495,4.181752918410091,-1.4318112173728834,-7.222471084845204,3.5693659432462796,-1.5340884327549515,-6.852756656609021,5.2219175904061705,-2.0957814925435754,-6.865547171295155,6.9348241469784675,-0.3822622386739246,-7.840337123981729,5.9163501477340015,1.901947675560634,-7.14588269871083,7.5348778865528585,1.8599956585564845,-5.183386688718684,6.902628489038825,3.00379312822094,-6.320571927150533,5.778938684769644,3.7314308708433312,-5.611717118466408,3.999835806326504,2.1198507284391424,-4.2456579429459325,4.612931866834503,3.048219593532459,-4.6069107651368215,7.293787691641958,0.48825328654147915,-4.605154347948515,6.117724778247074,-0.8168819742279978,-2.4444746529483776,0.506398738321376,1.5798689165877466,-0.7701000990055278,1.0052188232393493,1.8560215685849537,-2.0891295887038615,1.6566881545940846,2.8661349186175187,-0.8591211029641558,4.186468404851633,-1.7840962101639792,-2.5984286809115633,5.774690848401762,-1.0362956524367304,-1.2400995478542995,-0.018848567252613056,-0.3485613393918707,0.5532555804067856,-1.479262444118538,-1.2624609549610737,3.2600902477170295,-1.1914839957436465,-2.0732852912485398,4.596134831412953,0.7408047840305226,-1.5887452364555423,4.566240209336126,0.6764929641473706,-3.3673863232775614,4.355174411894247,3.006617647287081,-0.8865962896302875,3.095453419503858,4.0391837701220235,-1.565077962341484,5.769186405876664,3.28246902643983,-2.835560445665501,5.0027699601904985,4.862826194438583,-2.811412084103287,4.786458357439516,2.852251124877859,-4.896558593990077,3.8498945992866562,4.334019552870256,-4.833834407099973,1.970763631814464,3.277701870552373,-3.8537435588962854,2.6289204888563065,1.8178790594606908,-4.598412320947505],"qcarchive_id":36955004,"final_energy":-746095.5770292078}
23 changes: 22 additions & 1 deletion yammbs/_tests/unit_tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from yammbs import MoleculeStore
from yammbs.checkmol import ChemicalEnvironment
from yammbs.exceptions import DatabaseExistsError
from yammbs.inputs import QCArchiveDataset
from yammbs.inputs import QCArchiveDataset, QCArchiveMolecule
from yammbs.models import MMConformerRecord, QMConformerRecord


Expand Down Expand Up @@ -58,6 +58,27 @@ def test_from_qcarchive_dataset(small_qcsubmit_collection):
assert len(MoleculeStore(db)) == len(store)


def test_from_qcarchive_dataset_undefined_stereo():
"""Test loading from YAMMBS's QCArchive model with undefined stereochemistry"""
db = "foo.sqlite"

ds = QCArchiveDataset(
qm_molecules=[
QCArchiveMolecule.model_validate_json(
open(get_data_file_path("_tests/data/qcsubmit/undefined_stereo.json", "yammbs")).read(),
),
],
)
with temporary_cd():
store = MoleculeStore.from_qcarchive_dataset(ds, db)

# Sanity check molecule deduplication
assert len(store.get_smiles()) == len({*store.get_smiles()})

# Ensure a new object can be created from the same database
assert len(MoleculeStore(db)) == len(store)


def test_do_not_overwrite(small_qcsubmit_collection):
with tempfile.NamedTemporaryFile(suffix=".sqlite") as file:
with pytest.raises(DatabaseExistsError, match="already exists."):
Expand Down

0 comments on commit ee6d0dc

Please sign in to comment.