Re: [Rdkit-discuss] How to set property (e.g. energy) for each conformer?
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
From: JP <jea...@in...> - 2011-05-24 08:53:31
|
Interesting hack. Well played. Thanks. On 24 May 2011 04:44, Greg Landrum <gre...@gm...> wrote: > On Mon, May 23, 2011 at 12:28 PM, JP <jea...@in...> wrote: >> How do you set a property (e.g. energy) for each conformer (instead of >> per molecule) ? >> >> What I am looking for is >> SetProp( (Mol)self, confId, (str)key, (str)val [, (bool)computed=False]) >> >> I want to write these values in an .sdf file. > > There's currently no way to associate properties with a particular conformer. > The most straightforward way to approximate this would be to combine > the values into one hidden property and then pull them out and set > them as the energy property before writing the SDF. > > Something like this (not tested): > > # setting properties: > if mol.HasProp("_ConfEnergies"): > mol.SetProp("_ConfEnergies","%s|%d:%.4f"%(mol.GetProp("_ConfEnergies"),confId,confEnergy) > > # writing to the SDWriter writer : > confEs={} > vs = [x.split(":") for x in mol.GetProp("_ConfEnergies").split('|')] > for id,e in vs: > confEs[int(id)]=e > > for conf in mol.GetConformers: > mol.SetProp("Energy",confEs[conf.GetId()] > writer.write(mol) > > Hope this helps, > -greg > |