Hi Noel,

Your answers solved my problem. Thank you!

Xianghai

On Fri, Jan 26, 2018 at 7:42 AM, Noel O'Boyle <baoille...@gmail.com> wrote:

> Hi there,
>
> Regarding 1, yes, but have you instead considered using a Python
> dictionary or list to store the information? If I were you, I would avoid
> crossing over to C++ to store this information.
>
> Regarding 2, see https://openbabel.org/docs/dev/UseTheLibrary/PythonDoc.
> html#accessing-obpairdata-obunitcell-and-other-obgenericdata.
> Essentially, toPairData() does the cast.
>
> Regarding 3, the number of lone pairs can be deduced from the atomic
> number and the valence so we don't need to track the number of lone pairs.
>
> Regards,
> - Noel
>
> On 25 January 2018 at 01:43, Xianghai Sheng <xsh...@ucmerced.edu> wrote:
>
>> Dear developers,
>>
>> I was wondering what is the proper way to use OBPairData in python. For
>> example, I want to store an OBPairData with attribute 'nLonePair' in an
>> OBAtom. I managed to do this with the following code but don't know if it
>> is the best way.
>>
>>             d = ob.OBPairData()
>>             d.SetAttribute('nLonePair')
>>             nLonePair = 2
>>             d.SetValue(str(nLonePair))
>>             atom.CloneData(d)
>>
>> I wanted to use atom.SetData() as I found in the document
>> <http://openbabel.org/dev-api/classOpenBabel_1_1OBGenericData.shtml#ac9527475c246fadbbab63a35376fd5fe>but
>> an error shows up saying OBAtom does not have attribute SetData. So I used
>> CloneData instead, which seems to do the job.
>>
>> Now I want to retrieve the value of the OBPairData. In C++ I would do
>> things like
>>             pairData = (OBPairData*)atom.GetData('nLonePair')
>>             nLonePair = pairData.GetValue()
>> However, when in python I do
>>             pairData = openbabel.OBPairData(atom.GetData('nLonePair')),
>> an error shows up saying __init__() takes exactly 1 argument (2 given). I
>> checked the swig file openbabel.py and OBPairData.__init__() does take
>> 'self' as the only argument. The problem is that atom.GetData() returns a
>> OBGenericData type which, without converting to an OBPairData type, doesn't
>> allow a GetValue() method afaik.
>>
>> To sum up,
>> 1. Is my way of storing an OBPairData in an atom correct?
>> 2. How do I retrieve the value of an OBPairData in python?
>> 3. Just by the way, is there anything in openbabel/pybel that keeps track
>> of the number of lone pairs in an atom?
>>
>> Thank you in advance,
>> Xianghai
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> OpenBabel-discuss mailing list
>> OpenBabel-discuss@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>>
>>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to