Hi Torsten,

ff.Setup(..) initializes an internal OBMol object that is used for the 
forcefield calculations. In order to copy the internal charges to your 
external object "mol" you need to call ff.GetPartialCharges(mol). (see 
forcefield.cpp)
Similar functions exist for the coordinates, conformers, etc 
(ff.GetCoordinates(mol), ff.GetConformers(mol), ff.GetAtomTypes(mol)).
The charges are then stored in the atom data "FFPartialCharge", see 
below how you can access it.
atom.GetPartialCharges always yields the Gasteiger charges if I recall 
correctly.

--
import pybel as pb
import openbabel as op
import sys

def get_partial_charges(mol,nr_atoms):
      """
      Return a list of all partial charges of the atoms
      according to the current force field. List has the
      same order as the atoms in the molecule.
      """
      return [float(atom.GetData("FFPartialCharge").GetValue()) for atom 
in op.OBMolAtomIter(mol)]

for forcefield in pb.forcefields:
      mol = pb.readfile("xyz","test.xyz").next().OBMol
      ff = op.OBForceField.FindForceField(forcefield)
      if not ff.Setup(mol):
          print >> sys.stderr, "Force field "+ff.Description()+" could 
not be set-up correctly."
      else:
          ff.GetPartialCharges(mol)
          print get_partial_charges(mol, mol.NumAtoms())
--

Best regards
Andreas

-------- Original-Nachricht --------
Betreff: [Open Babel] Determination of partial charges - no difference 
between force fields?
Von: Torsten Sachse <torsten.sac...@uni-jena.de>
An: openbabel-discuss@lists.sourceforge.net
Datum: 28.09.2015 15:15
> Dear all,
>
> First off: sorry if you receive this email twice. I was unsure about the exact
> list address to sent it to.
>
> I seem to have a strange problem. I try to determine the partial charges of a
> molecule using the different force fields (code below, [1]) using the python
> interface. However, I always seem to get the exact same partial charges
> irrespective of the force field in use. Now I am wondering whether that was to
> be expected. I would think that different force fields yield different partial
> charges. The energies I get are vastly diferent, though.
>
> I appreciate any hints about what I am doing wrong here. It does not matter
> which molecule I choose, the result is always the same.
>
> Thanks in advance,
> Torsten
>
> [1]:
> import pybel as pb
> import openbabel as op
> import sys
>
> def get_partial_charges(mol,nr_atoms):
>       """
>       Return a list of all partial charges of the atoms
>       according to the current force field. List has the
>       same order as the atoms in the molecule.
>       """
>       a=op.OBAtom()
>       partialcharges=[0.0]*nr_atoms
>       for idx in range(1,nr_atoms+1):
>           a = mol.GetAtom(idx)
>           partialcharges[idx-1] = a.GetPartialCharge()
>       return partialcharges
>
> for forcefield in pb.forcefields:
>       mol = pb.readfile("xyz","test.xyz").next().OBMol
>       ff = op.OBForceField.FindForceField(forcefield)
>       if  ff.Setup(mol) == 0:
>           print >> sys.stderr, "Force field "+ff.Description()+" could not be 
> set-up correctly."
>       else:
>           print get_partial_charges(mol,mol.NumAtoms())
>
> ------------------------------------------------------------------------------
> _______________________________________________
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


------------------------------------------------------------------------------
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to