Dear Marshall,
On Wed, Mar 4, 2009 at 7:01 PM, Marshall Levesque
<[email protected]> wrote:
>
> I have written a script to automate converting compounds from a 2D SD file
> into a 3D, optimized SD file. With the compounds I'm testing with, I get a
> hangup in python that has to be killed. I'm wondering if it has anything to
> do with this bug you listed:
>
> - UFF optimization not terminating when atoms are on top of each other
> (issue 2378119)
>
> Here is the code I'm trying to run:
>
> ############
> import Chem
> from Chem import AllChem
> suppl = Chem.SDMolSupplier('original65cmpds.sdf')
>
> max = len(suppl)
>
> for i in range(0, max):
> AllChem.EmbedMolecule(suppl[i])
> AllChem.UFFOptimizeMolecule(suppl[i])
> print i
>
> w = Chem.SDWriter('output.sdf')
> for mol in suppl: w.write(mol)
> ##########
There are two things going on here.
The first is, indeed, a bug in the optimizer that causes it to get
stuck in some circumstances. I will track this down.
However, even if this bug were not present, the code above would not
behave the way you expect. When you ask an SDMolSupplier for a
particular object, it parses the corresponding part of the SD file and
returns a *new* object, so the calls to EmbedMolecule(),
UFFOptimizeMolecule(), and w.write() in your code above are all
working on different objects. Here's a simple demonstration:
[4]>>> suppl = Chem.SDMolSupplier('original65cmpds.sdf')
[5]>>> ma = suppl[0]
[6]>>> mb = suppl[0]
[7]>>> ma is mb
Out[7] False
[8]>>> ma
Out[8] <rdkit.Chem.rdchem.Mol object at 0xa72b02c>
[9]>>> mb
Out[9] <rdkit.Chem.rdchem.Mol object at 0xa72b09c>
notice that ma and mb are pointing to different pieces of memory
(that's what the "at 0x...." things indicate).
Here's a version of your script that does what you want, and that doesn't hang:
##########
suppl = Chem.SDMolSupplier('original65cmpds.sdf')
mols = []
for i,mol in enumerate(suppl):
print 'embed: ',i
AllChem.EmbedMolecule(mol)
print 'optimize: ',i
AllChem.UFFOptimizeMolecule(mol)
mols.append(mol)
w = Chem.SDWriter('output.sdf')
for mol in mols: w.write(mol)
##########
Regards,
-greg