Re: [Rdkit-discuss] using the errors
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: Greg L. <gre...@gm...> - 2009-10-28 19:21:31
|
Hi,
2009/10/28 Christian de Bouillé <amb...@wa...>:
>
> When dealing with a sdf with molecule giving error
> Could you explain how to deal with the error
>
> Taking your example
> m = Chem.MolFromMolFile('data/invalid.mol')
> m is None cannot be used
> The same with try except
>
> I would like the process is not stopped by error
> but taking the exception
When the RDKit reads a molecule that it cannot process, it returns
None. The only time you should see an exception is if you try to read
from a file that does not exist. The best way to do with this when
dealing with a set of molecules is to check for None and skip those
failing molecules. There are some examples of this in the Getting
Started in Python document.
The standard pattern is something like this for reading from an SD file:
supplier = Chem.SDMolSupplier('filename.sdf')
for mol in supplier:
if mol is None: continue
[do something with the molecule]
for a mol file, you can just check:
m = Chem.MolFromMolFile('data/invalid.mol')
if m is None:
print 'bad molecule!'
else:
[ do something with the molecule]
I hope this helps,
-greg
|