From 72f6bf57fae17298dfd67f7c1612b890467f6d38 Mon Sep 17 00:00:00 2001 From: Josh Horton Date: Tue, 3 Dec 2024 17:17:34 +0000 Subject: [PATCH] add warning --- gufe/components/smallmoleculecomponent.py | 4 ++++ gufe/tests/test_smallmoleculecomponent.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gufe/components/smallmoleculecomponent.py b/gufe/components/smallmoleculecomponent.py index 019212e3..3727f7bf 100644 --- a/gufe/components/smallmoleculecomponent.py +++ b/gufe/components/smallmoleculecomponent.py @@ -2,6 +2,7 @@ # For details, see https://github.com/OpenFreeEnergy/gufe import logging +import warnings # openff complains about oechem being missing, shhh logger = logging.getLogger("openff.toolkit") @@ -282,6 +283,9 @@ def _from_dict(cls, d: dict): try: a.SetHybridization(_INT_TO_HYBRIDIZATION[atom[7]]) except IndexError: + warnings.warn("The atom hybridization data was not found and has been set to unspecified. This can be" + " fixed by recreating the SmallMoleculeComponent from the rdkit molecule after running " + "sanitization.") pass em.AddAtom(a) diff --git a/gufe/tests/test_smallmoleculecomponent.py b/gufe/tests/test_smallmoleculecomponent.py index 2e64623c..e224227d 100644 --- a/gufe/tests/test_smallmoleculecomponent.py +++ b/gufe/tests/test_smallmoleculecomponent.py @@ -361,7 +361,8 @@ def test_from_dict_missing_hybridization(self, phenol): # remove the hybridization atomic info which should be at index 7 new_atoms.append(tuple([atom_info for i, atom_info in enumerate(atom) if i != 7])) phenol_dict["atoms"] = new_atoms - new_phenol = SmallMoleculeComponent.from_dict(phenol_dict) + with pytest.warns(match="The atom hybridization data was not found and has been set to unspecified."): + new_phenol = SmallMoleculeComponent.from_dict(phenol_dict) # they should be different objects due to the missing hybridization info assert new_phenol != phenol # make sure the rdkit objects are different