Partial Charge Setting

The best place to discuss coding is the avogadro-devel list.

I thought about adding a mechanism to explicitly set partial charges before the 1.0 release. I’m probably going to regret that – although I’ll certainly add it for the next major release (v1.2).

The workaround would be to grab the underlying OBMol and set the partial charges on each atom.

You can set all sorts of arbitrary attributes/properties on primitives in Avogadro. Of course, whether anything recognizes them is another matter.

Hope that helps,
-Geoff

On Nov 17, 2009, at 8:44 AM, Ian Kirker wrote:

Not quite sure if this list or avogadro-devel is the place for this, but
I’ve been trying to make an Extension to let me paste in charges off the
clipboard (using the SetPartialCharge method) and it all seems to work
correctly except for the actual charges turning up in Avogadro.

I had a look in the Python terminal, and it seems this call isn’t included
in the Avogadro primitive version of the Atom class, but didn’t raise any
sort of error when I called it from the script. Having a further look
around the classes I couldn’t find a way to properly set partial charges.
I tried setting the attribute on the atom objects directly, which seemed
to have no effect on the atoms in the GUI, although this did work from the
Python terminal. Looking at the molecule object, there seems to be a call
on there which recalculates them, which I imagine I might have to override
somehow.

So, does anyone know whether there’s a proper way to set partial charges
from an extension like this?

Many thanks,
-Ian

(A simpler version of what I’m doing is below - I’ve also tried it using
iterators rather than pop():slight_smile:

def pasteCharges(self, glwidget):
charges = list()
mol = glwidget.molecule
atomList = mol.atoms

  ... (some text processing to get the charges)

  # Pop elements off the lists until one is empty
  while (len(atomList)!=0) and (len(chargeList)!=0):
    thisAtom = atomList.pop()
    thisCharge = chargeList.pop()

    thisAtom.SetPartialCharge(thisCharge) # One way suggested by the  

OB Atom object
thisAtom.partialCharge = thisCharge # Suggested by the Atom object help
from the terminal


Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
avogadro-discuss List Signup and Options

Hi,

The real problem is that there is a property in molecule
(Molecule::m_invalidPartialCharges) that would need to be set from
python. While this isn’t possible directly, this is set when
Molecule::calculatePartialCharges is called (together with the atom’s
partialCharge). A second call would do nothing. This function gets
called from Atom::partialCharge.

To get around this, you could call molecule.calculatePartialCharges()
before actually assigning the atom.partialCharge property for each
atom.

note: the atom.partialCharge = … is the correct way as indicated in
the python module’s documentation

Cheers,
Tim

On Tue, Nov 17, 2009 at 5:12 PM, Geoffrey Hutchison
geoff.hutchison@gmail.com wrote:

The best place to discuss coding is the avogadro-devel list.

I thought about adding a mechanism to explicitly set partial charges before the 1.0 release. I’m probably going to regret that – although I’ll certainly add it for the next major release (v1.2).

The workaround would be to grab the underlying OBMol and set the partial charges on each atom.

You can set all sorts of arbitrary attributes/properties on primitives in Avogadro. Of course, whether anything recognizes them is another matter.

Hope that helps,
-Geoff

On Nov 17, 2009, at 8:44 AM, Ian Kirker wrote:

Not quite sure if this list or avogadro-devel is the place for this, but
I’ve been trying to make an Extension to let me paste in charges off the
clipboard (using the SetPartialCharge method) and it all seems to work
correctly except for the actual charges turning up in Avogadro.

I had a look in the Python terminal, and it seems this call isn’t included
in the Avogadro primitive version of the Atom class, but didn’t raise any
sort of error when I called it from the script. Having a further look
around the classes I couldn’t find a way to properly set partial charges.
I tried setting the attribute on the atom objects directly, which seemed
to have no effect on the atoms in the GUI, although this did work from the
Python terminal. Looking at the molecule object, there seems to be a call
on there which recalculates them, which I imagine I might have to override
somehow.

So, does anyone know whether there’s a proper way to set partial charges
from an extension like this?

Many thanks,
-Ian

(A simpler version of what I’m doing is below - I’ve also tried it using
iterators rather than pop():slight_smile:

def pasteCharges(self, glwidget):
charges = list()
mol = glwidget.molecule
atomList = mol.atoms

  ... (some text processing to get the charges)

  # Pop elements off the lists until one is empty
  while (len(atomList)!=0) and (len(chargeList)!=0):
    thisAtom = atomList.pop()
    thisCharge = chargeList.pop()

    thisAtom.SetPartialCharge(thisCharge) # One way suggested by the

OB Atom object
thisAtom.partialCharge = thisCharge # Suggested by the Atom object help
from the terminal


Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
avogadro-discuss List Signup and Options


Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

Thanks both of you for the help.

Man, am I sheepish - it turns out a mistake I’d made was preventing the
code setting the partialCharge property directly from executing at all. It
seems to work now, at least for the labels.

I’ve stuck a call to calculatePartialCharges in, though this doesn’t seem
to change whether it works on labelling (I’ve not checked, but I’d suspect
the label engine has to call this method anyway) I’m guessing it might for
other things.

Geoff, did the workaround you suggested require a shift to C++? I didn’t
seem to be able to do anything with the OBMol property of the molecule
object, and checking the type gave a PySwigObject with no properties and
no relevant methods.

Thanks again,
-Ian (will check his code more thoroughly next time, sorry…)

On Tue, 17 Nov 2009 17:43:13 -0000, Tim Vandermeersch
tim.vandermeersch@gmail.com wrote:

Hi,

The real problem is that there is a property in molecule
(Molecule::m_invalidPartialCharges) that would need to be set from
python. While this isn’t possible directly, this is set when
Molecule::calculatePartialCharges is called (together with the atom’s
partialCharge). A second call would do nothing. This function gets
called from Atom::partialCharge.

To get around this, you could call molecule.calculatePartialCharges()
before actually assigning the atom.partialCharge property for each
atom.

note: the atom.partialCharge = … is the correct way as indicated in
the python module’s documentation

Cheers,
Tim

On Tue, Nov 17, 2009 at 5:12 PM, Geoffrey Hutchison
geoff.hutchison@gmail.com wrote:

The best place to discuss coding is the avogadro-devel list.

I thought about adding a mechanism to explicitly set partial charges
before the 1.0 release. I’m probably going to regret that – although
I’ll certainly add it for the next major release (v1.2).

The workaround would be to grab the underlying OBMol and set the
partial charges on each atom.

You can set all sorts of arbitrary attributes/properties on primitives
in Avogadro. Of course, whether anything recognizes them is another
matter.

Hope that helps,
-Geoff

On Nov 17, 2009, at 8:44 AM, Ian Kirker wrote:

Not quite sure if this list or avogadro-devel is the place for this,
but
I’ve been trying to make an Extension to let me paste in charges off
the
clipboard (using the SetPartialCharge method) and it all seems to work
correctly except for the actual charges turning up in Avogadro.

I had a look in the Python terminal, and it seems this call isn’t
included
in the Avogadro primitive version of the Atom class, but didn’t raise
any
sort of error when I called it from the script. Having a further look
around the classes I couldn’t find a way to properly set partial
charges.
I tried setting the attribute on the atom objects directly, which
seemed
to have no effect on the atoms in the GUI, although this did work from
the
Python terminal. Looking at the molecule object, there seems to be a
call
on there which recalculates them, which I imagine I might have to
override
somehow.

So, does anyone know whether there’s a proper way to set partial
charges
from an extension like this?

Many thanks,
-Ian

(A simpler version of what I’m doing is below - I’ve also tried it
using
iterators rather than pop():slight_smile:

def pasteCharges(self, glwidget):
charges = list()
mol = glwidget.molecule
atomList = mol.atoms

  ... (some text processing to get the charges)

  # Pop elements off the lists until one is empty
  while (len(atomList)!=0) and (len(chargeList)!=0):
    thisAtom = atomList.pop()
    thisCharge = chargeList.pop()

    thisAtom.SetPartialCharge(thisCharge) # One way suggested by

the
OB Atom object
thisAtom.partialCharge = thisCharge # Suggested by the Atom
object help
from the terminal


Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
avogadro-discuss List Signup and Options


Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

Geoff, did the workaround you suggested require a shift to C++? I didn’t seem to be able to do anything with the OBMol property of the molecule object, and checking the type gave a PySwigObject with no properties and no relevant methods.

I didn’t realize you were coding in Python (or that Tim had hacked partial charges into the Python interface). I thought you were discussing C++.

I believe the bug with PySwigObject is fixed in the 1.0 stable development code, which will be shortly released as 1.0.1.

Cheers,
-Geoff