Re: [Rdkit-discuss] How to trap the exceptions in RDKit?
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: Greg L. <gre...@gm...> - 2010-10-23 04:41:15
|
Dear Robert,
On Sat, Oct 23, 2010 at 1:53 AM, Robert DeLisle <rkd...@gm...> wrote:
>
> The easiest trap is simply this:
>
> if (m is None):
> #error handling code
>
> The problem that I have had is that this will effectively skip bad molecules, but in a large SD file, it is difficult to find out which molecules they were.
>
> sd = Chem.SDMolSupplier("test.sdf")
>
> for m in sd:
> if m is None:
> #how do I get more information about the broken molecules?
> else:
> #do the normal stuff.
>
My solution to this is normally to use this pattern:
#--------------
sd = Chem.SDMolSupplier("test.sdf")
errf = file('failures.sdf","w+")
for i,m in enumerate(sd):
if m is None:
errf.write(sd.GetItemText(i)
continue
else:
# process the molecule.
#--------------
This doesn't tell you what went wrong (that information is,
unfortunately, not current accessible), but it does at least collect
all the "bad" molecules in one place so you can look at them later
(using some other software, of course).
Best Regards,
-greg
|