Re: [Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files
Hi. Yes this works for me as per the RDKit docs. But I need to pipe it to a file, any suggestions? Thanks. Mike Get Outlook for Android On Tue, Sep 24, 2019 at 10:28 PM +0100, "Lukas Pravda" wrote: Hi Mike, The following code works for me: import sys from io import StringIO from rdkit import Chem saved_std_err = sys.stderr log = sys.stderr = StringIO() Chem.WrapLogs() # do whatever you want with rdkit whatever_used_to_be_printed_by_rdkit_in_console_as_str = log.getvalue() sys.stderr = saved_std_err This populated the stream in memory, if you replace StringIO with FileIO I think you can directly redirect it to file, but have not tested that. Let me know if this works for you. Lukas From: Date: Tuesday, 24 September 2019 at 16:52 To: RDKIT mailing list Subject: [Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files Hi Rdkit forum, Easy question, perhaps difficult to answer… I’ve been reading a lot of support messages, many a very old about how to get warnings (only visible at the cmd line) to be send to files. I can get error messages sent, but not warnings. The type I’m trying to capture are – which I can see when I run code at the cmd line, but not in jupyter-notebook. “charges were rearranged” “Omitted undefined stereo” Ideally I’d like to run the code in jupyter-notebook and also at the cmd line with python script.py etc and get the warnings into a file. Can you provide me with a simple example as to how to do this? Thanks, mike 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
Re: [Rdkit-discuss] Problems with SMILES using MolFromSmiles
A carboxylate has to be represented as C(=O)[O-]. Use ...[OH] for an uncharged carboxyl. Similarly, a tetravalent aliphatic N has to be given a + charge. -P. On Tue, Sep 24, 2019 at 9:15 PM Scalfani, Vincent wrote: > Dear Navid, > > > > RDKit rejects tetravalent Nitrogen by default. This thread below may help. > It shows how to load the SMILES with sanitization off, then perform a > partial sanitization. > > > > https://sourceforge.net/p/rdkit/mailman/message/32589379/ > > > > Vin > > > > > > > > *From:* Navid Shervani-Tabar > *Sent:* Tuesday, September 24, 2019 6:55 PM > *To:* RDKit Discuss > *Subject:* [Rdkit-discuss] Problems with SMILES using MolFromSmiles > > > > Hello, > > > > I have noticed that RDKit have some problems with some SMILES when trying > to use MolFromSmiles. With further attention, I have noticed that all of > these SMILES include nitrogen atoms. Some examples include: > > > > [NH3]CCC(=O)[O] > NC(=[NH2])C(=O)[O] > NC(=[NH2])[CH2].C(=O)=O > CNC(=[NH2])C(=O)[O] > CNC(=[NH2])C(=O)[O] > C[C@@H](C[NH3])C(=O)[O] > > > > I was wondering if there is a way to fix this issue and study those > molecules. Thanks! > > > > Best, > > Navid > ___ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > -- -P. Sent from a cell phone. Pls forgive brvty and m1$tea@ks. ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] Problems with SMILES using MolFromSmiles
Dear Navid, RDKit rejects tetravalent Nitrogen by default. This thread below may help. It shows how to load the SMILES with sanitization off, then perform a partial sanitization. https://sourceforge.net/p/rdkit/mailman/message/32589379/ Vin From: Navid Shervani-Tabar Sent: Tuesday, September 24, 2019 6:55 PM To: RDKit Discuss Subject: [Rdkit-discuss] Problems with SMILES using MolFromSmiles Hello, I have noticed that RDKit have some problems with some SMILES when trying to use MolFromSmiles. With further attention, I have noticed that all of these SMILES include nitrogen atoms. Some examples include: [NH3]CCC(=O)[O] NC(=[NH2])C(=O)[O] NC(=[NH2])[CH2].C(=O)=O CNC(=[NH2])C(=O)[O] CNC(=[NH2])C(=O)[O] C[C@@H](C[NH3])C(=O)[O] I was wondering if there is a way to fix this issue and study those molecules. Thanks! Best, Navid ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] Problems with SMILES using MolFromSmiles
Hello, I have noticed that RDKit have some problems with some SMILES when trying to use MolFromSmiles. With further attention, I have noticed that all of these SMILES include nitrogen atoms. Some examples include: [NH3]CCC(=O)[O] NC(=[NH2])C(=O)[O] NC(=[NH2])[CH2].C(=O)=O CNC(=[NH2])C(=O)[O] CNC(=[NH2])C(=O)[O] C[C@@H](C[NH3])C(=O)[O] I was wondering if there is a way to fix this issue and study those molecules. Thanks! Best, Navid ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] Issue with Chirality
Dear All, One question why this is not working ? def mol3D(mol): tot = AllChem.EmbedMolecule(mol) try: X = AllChem.Get3DDistanceMatrix(mol) except: print('err') print(tot) n = mol.GetNumAtoms() X = np.zeros(n,n) return X mol = Chem.MolFromSmiles('CC[C@H](C)O') X = mol3D(mol) Result: err -1 --- ValueErrorTraceback (most recent call last) in mol3D(mol) 3 try: > 4 X = AllChem.Get3DDistanceMatrix(mol) 5 except: ValueError: Bad Conformer Id During handling of the above exception, another exception occurred: Thanks in advance, Guillaume *** DISCLAIMER This email and any files transmitted with it, including replies and forwarded copies (which may contain alterations) subsequently transmitted from Firmenich, are confidential and solely for the use of the intended recipient. The contents do not represent the opinion of Firmenich except to the extent that it relates to their official business. *** ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files
Hi Mike, The following code works for me: import sys from io import StringIO from rdkit import Chem saved_std_err = sys.stderr log = sys.stderr = StringIO() Chem.WrapLogs() # do whatever you want with rdkit whatever_used_to_be_printed_by_rdkit_in_console_as_str = log.getvalue() sys.stderr = saved_std_err This populated the stream in memory, if you replace StringIO with FileIO I think you can directly redirect it to file, but have not tested that. Let me know if this works for you. Lukas From: Date: Tuesday, 24 September 2019 at 16:52 To: RDKIT mailing list Subject: [Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files Hi Rdkit forum, Easy question, perhaps difficult to answer… I’ve been reading a lot of support messages, many a very old about how to get warnings (only visible at the cmd line) to be send to files. I can get error messages sent, but not warnings. The type I’m trying to capture are – which I can see when I run code at the cmd line, but not in jupyter-notebook. “charges were rearranged” “Omitted undefined stereo” Ideally I’d like to run the code in jupyter-notebook and also at the cmd line with python script.py etc and get the warnings into a file. Can you provide me with a simple example as to how to do this? Thanks, mike 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
Re: [Rdkit-discuss] Fwd: errors with stereoisomers
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 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 > > 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) > > in > > 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
[Rdkit-discuss] Fwd: errors with stereoisomers
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 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) in 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 enamine_fail_3.sdf Description: chemical/mdl-sdfile ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files
Hi Rdkit forum, Easy question, perhaps difficult to answer… I’ve been reading a lot of support messages, many a very old about how to get warnings (only visible at the cmd line) to be send to files. I can get error messages sent, but not warnings. The type I’m trying to capture are – which I can see when I run code at the cmd line, but not in jupyter-notebook. “charges were rearranged” “Omitted undefined stereo” Ideally I’d like to run the code in jupyter-notebook and also at the cmd line with python script.py etc and get the warnings into a file. Can you provide me with a simple example as to how to do this? Thanks, mike 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