Hi Mike, The usual incantation when working with suppliers, and this is shown in a lot of sample code, is to check to see if the molecule that is returned is None (which indicates a problem processing it). The simple way to do this, and to report the error molecules to stdout (you can change this) is:
for i,mol in enumerate(supplier): if mol is None: print(supplier.GetItemText(i)) continue do_whatever_you_want(mol) If you're using the [] notation to retrieve a molecule from the supplier (as in your example above), you just need to do a check like: mol = suppl[0] if mol is None: there_is_a_problem() else: do_whatever_you_want() -greg On Tue, Sep 24, 2019 at 4:53 PM <mi...@novadatasolutions.co.uk> wrote: > Hello RDKit gurus, > > > > I've found an interesting issue with V2000 SDF files which have a carbon > marked as "Either or unmarked stereocentre", a 3 in the atom-block. > > > > The enclosed molecule throws these errors – note also that the word > “begining" is spelt wrong in the stderr. > > > > Is there a way to “try-catch” when I run these commands, as the program > crashes when it hits a molecule it can not pass. > > suppl = Chem.SDMolSupplier(‘sdf_file.sdf’) > > Chem.MolTo-whatever(suppl[x]) > > > > So that if a molecule fails here it can be sent to sdterr? > > > > Thanks, > > mike > > > > Python command line: > > > > **** > > Pre-condition Violation > > bad dir > > Violation occurred on line 1755 in file > /opt/conda/conda-bld/rdkit_1561471048963/work/Code/GraphMol/Chirality.cpp > > Failed Expression: dir == Bond::ENDUPRIGHT || dir == Bond::ENDDOWNRIGHT > > **** > > > > [14:34:59] Unexpected error hit on line 317044 > > [14:34:59] ERROR: moving to the begining of the next molecule > > Traceback (most recent call last): > > File "AllChem_prop.py", line 178, in <module> > > main() > > File "AllChem_prop.py", line 170, in main > > calc_values = calc_SDF(file_names) > > File "AllChem_prop.py", line 105, in calc_SDF > > orig = Chem.MolToSmiles(suppl[i]) > > Boost.Python.ArgumentError: Python argument types in > > rdkit.Chem.rdmolfiles.MolToSmiles(NoneType) > > did not match C++ signature: > > MolToSmiles(RDKit::ROMol mol, bool isomericSmiles=True, bool > kekuleSmiles=False, int rootedAtAtom=-1, bool canonical=True, bool > allBondsExplicit=False, bool allHsExplicit=False, bool doRandom=False) > > > > > > > > Jupyter-notebook > > > > ArgumentError Traceback (most recent call last) > > <ipython-input-400-56f3f05e3048> in <module> > > 1 suppl = Chem.SDMolSupplier('enamine_fail_3.sdf') > > ----> 2 Chem.MolToSmiles(suppl[0],kekuleSmiles=True) > > 3 Chem.rdDepictor.Compute2DCoords(suppl[0]) > > 4 Draw.MolToImage(suppl[0], size=(300, 300)) > > > > ArgumentError: Python argument types in > > rdkit.Chem.rdmolfiles.MolToSmiles(NoneType) > > did not match C++ signature: > > MolToSmiles(RDKit::ROMol mol, bool isomericSmiles=True, bool > kekuleSmiles=False, int rootedAtAtom=-1, bool canonical=True, bool > allBondsExplicit=False, bool allHsExplicit=False, bool doRandom=False) > > > > > > > > > > > > Dr Mike Mazanetz, FRSC > > Director > > > > Honorary Lecturer > > School of Natural and Computing Sciences > > University of Aberdeen > > > > +44 (0) 141 533 0930 > > +44 (0) 7780 672509 > > mi...@novadatasolutions.co.uk > > www.novadatasolutions.co.uk > > skype michael.mazanetz > > > > NovaData Solutions Ltd. > > PO Box 639 > > Abingdon-on-Thames > > Oxfordshire > > OX14 9JD > > United Kingdom > > > > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss