Re: [Rdkit-discuss] FeatureRequest: Properties of Mol to be written out to SDF by SDWriter
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: JP <jea...@in...> - 2011-08-02 17:26:37
|
Thanks Greg for this -- I must be doing something silly in my code
because your example works fine...
I'll have a look.
<:( - embarrassed>
Jean-Paul Ebejer
Early Stage Researcher
On 2 August 2011 16:33, Greg Landrum <gre...@gm...> wrote:
> Dear JP,
>
> On Tue, Aug 2, 2011 at 11:36 AM, JP <jea...@in...> wrote:
>> I would just like to re-iterate how useful and nice (and expected
>> behaviour) it would be if when I have a mol instance with properties
>> (which I painstakingly computed) and the .write() method in SDWriter
>> actually writes them to file.
>> I know there is a SetProps method ... but why do I have to do this
>> everytime? Can it be a default? Or an optional parameter in the
>> SDWriter constructor e.g. "writeProps=True" ?
>
> By default an SDWriter should write out all properties of a molecule
> that have not been flagged as "computed" when you call mol.SetProp().
> Here's an example:
>
> [1]>>> from rdkit import Chem
>
> [2]>>> m = Chem.MolFromSmiles('c1ccccc1')
>
> [3]>>> m.SetProp('_Name','benzene')
>
> [4]>>> m.SetProp('Prop1','4')
>
> [9]>>> m2 = Chem.MolFromSmiles('c1ccccc1C')
>
> [10]>>> m2.SetProp('_Name','toluene')
>
> [11]>>> m2.SetProp('Prop2','5')
>
> [12]>>> w = Chem.SDWriter('test.sdf')
>
> [13]>>> w.write(m)
>
> [14]>>> w.write(m2)
>
> [15]>>> w.close()
>
> [16]>>> !cat test.sdf
> benzene
> RDKit
>
> 6 6 0 0 0 0 0 0 0 0999 V2000
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 1 2 2 0
> 2 3 1 0
> 3 4 2 0
> 4 5 1 0
> 5 6 2 0
> 6 1 1 0
> M END
>> <Prop1> (1)
> 4
>
> $$$$
> toluene
> RDKit
>
> 7 7 0 0 0 0 0 0 0 0999 V2000
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
> 1 2 2 0
> 2 3 1 0
> 3 4 2 0
> 4 5 1 0
> 5 6 2 0
> 6 7 1 0
> 6 1 1 0
> M END
>> <Prop2> (2)
> 5
>
> $$$$
>
> [17]>>>
>
> If you're seeing different behavior, and you are using SetProp without
> the optional third argument set to True, then I'd love to see some
> sample code, because it's a bug.
>
>> Related discussion:
>> http://www.mail-archive.com/rdk...@li.../msg01712.html
>
> That was a different request: the question was how to write a
> compressed SD file from the RDKit without first generating a standard
> SD file.
>
> -greg
>
|