Here's an example using OBPairData for an OBAtom:

C:\Users\Noel>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybel
>>> ob = pybel.ob
>>> mol = pybel.readstring("smi", "CC(=O)Cl")
>>> m = mol.OBMol
>>>
>>> ###### Set Data for an OBAtom######
...
>>> atom = m.GetAtom(1)
>>> pairdata = ob.OBPairData()
>>> print dir(pairdata)
['Clone', 'GetAttribute', 'GetDataType', 'GetOrigin', 'GetValue', 'SetAttribute'
, 'SetOrigin', 'SetValue', '__class__', '__delattr__', '__dict__', '__doc__', '_
_format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str_
_', '__subclasshook__', '__swig_destroy__', '__weakref__', 'this', 'thisown']
>>> pairdata.SetAttribute("my atom name")
>>> pairdata.SetValue("methyl")
>>> atom.CloneData(pairdata)
>>>
>>> ###### Retrieve Data ######
...
>>> atom = m.GetAtom(1)
>>> pairdata = ob.toPairData(atom.GetData("my atom name"))
>>> print pairdata.GetAttribute(), pairdata.GetValue()
my atom name methyl
>>>
>>> ###### Retrieve data if you have several PairData with the name Attribute 
>>> ######
...
>>> print [x.GetValue() for x in atom.GetAllData(ob.PairData) if 
>>> x.GetAttribute() == "my atom name"]
['methyl']
>>>


On 23 May 2012 11:44, Hitesh Patel <hiteshpatel...@gmail.com> wrote:
> Hello,
>
> I am using openbabel through python API.
> I want to add some generic data to Atoms, bonds and also whole molecules and
> then Access this data.
> I found this class ( http://openbabel.org/api/2.3/generic_data.shtml ) but,
> was not able to figure out how to use it in Python API. Can anyone help ?
> Thanks..
>
> Regards,
> -Hitesh
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to