Having some problems using OBMol.GetData(int). First of
all, the API doesn't describe what this does. I expect
that it extracts the data fields one by one in some
arbitary order. However, it doesn't appear to be able
to do this.
Here is an example. The attached test file has two
fields: 'NSC' and 'Molecular weight'. GetData(int)
finds the 'NSC' field without any problems but not the
'Molecular weight'. In addition, it finds a 'Comment'
field but I guess this is a good thing.
Python code
from openbabel import *
obconversion = OBConversion()
obconversion.SetInFormat("sdf")
obmol = OBMol()
notatend = obconversion.ReadFile(obmol,"test.sdf")
print "Using obmol.GetData(string)"
for field in ["NSC","Molecular weight"]:
data = obmol.GetData(field)
print "The value of '%s' is '%s'" %
(data.GetAttribute(),data.GetValue())
print "\nUsing obmol.GetData(int)"
for i in range(100):
data = obmol.GetData(i)
if data:
print "i=%d: the value of '%s' is '%s'" %
(i,data.GetAttribute(),data.Ge
tValue())
print "\nUsing obmol.GetData()"
print obmol.GetData()
Output
Using obmol.GetData(string)
The value of 'NSC' is '1'
The value of 'Molecular weight' is '122.03677944'
Using obmol.GetData(int)
i=1: the value of 'NSC' is '1'
i=3: the value of 'Comment' is 'CORINA 2.61 0041
25.10.2001'
Using obmol.GetData()
<swig object="" of="" type="" 'std::vector\<openbabel::obgenericdata="" *,std::allocator\<open="" babel::obgenericdata="" *=""> > *' at 0x815a634></swig>
End of output
Regards
Noel
Test SD file
Logged In: YES
user_id=21420
I've added a comment to the documentation -- the use of the "unsigned int
type" parameter is to allow access based on data type, defined in the
OBGenericDataType namespace:
http://openbabel.sourceforge.net/api/
namespaceOpenBabel_1_1OBGenericDataType.shtml
If you access data by this means, you are current only going to get one item
(i.e., the first matched) for OBPairData. If you think there should be a better
way to do this, we'll need some sort of API change in 2.1 -- please feel free to
comment on the mailing list.
In short, I'm closing this bug -- I've fixed the documentation and the call is
doing what it's supposed to do. Whether there should be alternative access
methods is another subject.
Cheers,
-Geoff
Logged In: YES
user_id=850620
So...I should submit the same bug report again but with a
different emphasis?
Logged In: YES
user_id=1312539
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).