Re: [Open Babel] netcharge of a molecule

2018-01-26 Thread Andrew Dalke
On Jan 26, 2018, at 07:27, Sundar  wrote:
> How to calculate the net charge of a molecule in openbabel?

The OBMolecule object has a method called "GetTotalCharge()":

  
http://openbabel.org/api/2.3.0/classOpenBabel_1_1OBMol.shtml#ab78d46b60f04702fa6f450ef6f8dae62


Or, if you are using the pybel interface, use the '.charge' attribute:

>>> import pybel
>>> mol = pybel.readstring("smi", "[NH4+]")
>>> mol.charge
1

Or, if you want it from the command-line, you can use the 'report' output 
format and look for the line starting "TOTAL CHARGE"

% echo "[NH4+]" | obabel -ismi - -oreport - | grep "^TOTAL CHARGE"
1 molecule converted
TOTAL CHARGE: 1



Andrew
da...@dalkescientific.com



--
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


[Open Babel] Using OBPairData in python

2018-01-26 Thread Xianghai Sheng
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
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


Re: [Open Babel] Using OBPairData in python

2018-01-26 Thread Noel O'Boyle
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  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
> 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


[Open Babel] Error in file conversion

2018-01-26 Thread Sundar
Dear all,

I see that when I convert a file from sdf to pdb or pdbqt. Obabel guesses a
few atoms as ALA (could be an amino acid Alanine).
Does anyone know any possible cause?

Attached are the files.

Thanks,
Jubilant


443884.sdf
Description: Binary data


443884.pdb
Description: Protein Databank data


443884.pdbqt
Description: Binary data
--
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