Changing atom color from python console, etc

Hello,

(first time here)

  1. Is there a way to change the color of atoms from the python console…?
    (that’s my main question, but includes sub-questions as well)

Let’s start in Avogadro’s python console…

import Avogadro

now we have

Avogadro.molecules

which is a Avogadro.Molecule object, preloaded by the program

Avogadro.molecules.atoms[1]

… that is the first atom in the system. How do I change its color?

The thing is that I could probably figure this all out by myself, but
the python console
of Avogadro - sorry for the expression - slightly sucks. I mean for example:

at=Avogadro.molecules.atoms[1]

Now consider

dir(at)

Does not give any list of methods or variables of the object “at”. This
makes it difficult
to “play around” (thats the way I learn, at least) with the methods, etc.

It would be ideal to do these things from the “ipython” console as it
gives you the available methods by simply pressing
the tabulator. I tried the following things in ipython:


In [1]: import Avogadro

In [2]: Avogadro.molecules
Out[2]: <Avogadro.MoleculeList at 0x30d1130>

In [12]: Avogadro.Molecule.atoms. [[ I PRESS THE TABULATOR ]]
Avogadro.Molecule.atoms.deleter Avogadro.Molecule.atoms.fdel
Avogadro.Molecule.atoms.fget Avogadro.Molecule.atoms.fset
Avogadro.Molecule.atoms.getter Avogadro.Molecule.atoms.setter

In [12]: mymol=Avogadro.Molecule()

RuntimeError Traceback (most recent call last)
in ()
----> 1 mymol=Avogadro.Molecule()

RuntimeError: This class cannot be instantiated from Python

Is there a way to read in a coordinate file from the ipython console,
using some method of the Avogadro class…?

This would facilitate the learning process …
… and reduce the amount of spam I am sending to this mailing list.

  1. I am not able to change the color of the hydrogen bonds either… I go
    to hydrogen bonds => hydrogen bond settings => colors => custom color
    … i change it to black … nothing happens (its still ugly yellow).

Can I change this manually, i.e. like in question (1) ?

  1. In general, I am interested in the following…

a) Read a coordinate file to avogadro (btw, why doesn’t it recognize
“.xmol” extension - its the same things as “.xyz” ?)
b) Meanwhile, manipulate that coordinate file with my custom python
scripts to study various things … (outside avogadro)
c) Color / draw bonds on the avogadro view, say, my own custom hydrogen
bonds, etc.
… for this purpose, I need to connect somehow to all the methods
and variables of avogadro via python

Regards,

Sampsa

P. S. I am using Avogadro 1.0.3

… that is the first atom in the system. How do I change its color?

Colors in Avogadro 1.0.x are defined by a color plugin, not the atom. In Avogadro 1.1.x, there’s a new property:

atom.setCustomColorName(“red”)

http://avogadro.cc/api/dev/classAvogadro_1_1Atom.html

dir(at)

Does not give any list of methods or variables of the object “at”. This
makes it difficult to “play around” (thats the way I learn, at least) with the methods, etc.

I think this is a limitation of Boost::Python which is currently used for the Python interface.

Is there a way to read in a coordinate file from the ipython console,
using some method of the Avogadro class…?

You probably want Avogadro.MoleculeFile.readMolecule()
http://avogadro.cc/api/dev/classAvogadro_1_1MoleculeFile.html

  1. I am not able to change the color of the hydrogen bonds either… I go
    to hydrogen bonds => hydrogen bond settings => colors => custom color
    … i change it to black … nothing happens (its still ugly yellow).

Ooh, that’s weird. I can certainly address that for Avogadro 1.1.x, but not

  1. In general, I am interested in the following…

a) Read a coordinate file to avogadro (btw, why doesn’t it recognize
“.xmol” extension - its the same things as “.xyz” ?)

Avogadro recognizes extensions used through Open Babel. No one has ever suggested that Open Babel recognize .xmol. I’ve certainly never seen one “in the wild,” although I’ve seen many flavors of “.xyz” files.

b) Meanwhile, manipulate that coordinate file with my custom python
scripts to study various things … (outside avogadro)

Right.

c) Color / draw bonds on the avogadro view, say, my own custom hydrogen
bonds, etc.

At the moment, I’m not sure the hydrogen bond engine is sufficient for that, but it’s a good feature request… mark various pairs of atoms as hydrogen bonds. There have been proposals for recognizing various “zero order” bonds to save to files (e.g., CML and SDF).

Please feel free to spam. I don’t think the Python interface is getting enough exercise and it should definitely be able to do what you’re describing. That was the whole point.

Thanks,
-Geoff

Hi,

Geoffrey, thanks for your reply.

The Avogadro version in the (ubuntu) repos is unfortunately 1.0.x…

So, I installed manually the latest 1.1 version. There was a dependency
hell of all sort
of packages not mentioned anywhere (qttools5-dev-tools …), but never
mind, I got through it.

I started Avogadro 1.1., however, the python console was not available
anywhere … although it should
be installed by default?

After opening some menus, Avogadro froze up and I got …

QStackedLayout::setCurrentWidget: Widget 0x1f5b550 not contained in stack
libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area
*** Error in `avogadro’: realloc(): invalid next size:
0x000000000403fd40 ***

So in the end I have already spent an hour and a half in just trying to
change the color of a single atom … :wink:

… I guess I’ll give up on Avogadro for the moment. Seems like a great
program though.

How is it with Avogadro 2… is there any python support yet … ?

Regards,

S.

On 02/17/2014 10:51 PM, Geoffrey Hutchison wrote:

… that is the first atom in the system. How do I change its color?
Colors in Avogadro 1.0.x are defined by a color plugin, not the atom. In Avogadro 1.1.x, there’s a new property:

atom.setCustomColorName(“red”)

Avogadro: Avogadro::Atom Class Reference

dir(at)
Does not give any list of methods or variables of the object “at”. This
makes it difficult to “play around” (thats the way I learn, at least) with the methods, etc.
I think this is a limitation of Boost::Python which is currently used for the Python interface.

Is there a way to read in a coordinate file from the ipython console,
using some method of the Avogadro class…?
You probably want Avogadro.MoleculeFile.readMolecule()
Avogadro: Avogadro::MoleculeFile Class Reference

  1. I am not able to change the color of the hydrogen bonds either… I go
    to hydrogen bonds => hydrogen bond settings => colors => custom color
    … i change it to black … nothing happens (its still ugly yellow).
    Ooh, that’s weird. I can certainly address that for Avogadro 1.1.x, but not
  1. In general, I am interested in the following…

a) Read a coordinate file to avogadro (btw, why doesn’t it recognize
“.xmol” extension - its the same things as “.xyz” ?)
Avogadro recognizes extensions used through Open Babel. No one has ever suggested that Open Babel recognize .xmol. I’ve certainly never seen one “in the wild,” although I’ve seen many flavors of “.xyz” files.

b) Meanwhile, manipulate that coordinate file with my custom python
scripts to study various things … (outside avogadro)
Right.

c) Color / draw bonds on the avogadro view, say, my own custom hydrogen
bonds, etc.
At the moment, I’m not sure the hydrogen bond engine is sufficient for that, but it’s a good feature request… mark various pairs of atoms as hydrogen bonds. There have been proposals for recognizing various “zero order” bonds to save to files (e.g., CML and SDF).

Please feel free to spam. I don’t think the Python interface is getting enough exercise and it should definitely be able to do what you’re describing. That was the whole point.

Thanks,
-Geoff

Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk


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

Dear List (and Geoffrey),

Finally, I went through the python module depencies and installed
Avogadro 1.1…

On 02/17/2014 10:51 PM, Geoffrey Hutchison wrote:

… that is the first atom in the system. How do I change its color?
Colors in Avogadro 1.0.x are defined by a color plugin, not the atom. In Avogadro 1.1.x, there’s a new property:

atom.setCustomColorName(“red”)

Avogadro: Avogadro::Atom Class Reference

Ok, In the python console (and in Avogadro 1.1.x) I try:

import Avogadro

Avogadro.molecule.atoms[0]

Avogadro.molecule.atoms[0].setCustomColorName(“blue”)

Traceback (most recent call last):

File “”, line 1, in

AttributeError: ‘Atom’ object has no attribute ‘setCustomColorName’


Playing around in ipython …


In [15]: import Avogadro

In [16]:

In [16]: mol=Avogadro.MoleculeFile.readMolecule(“resumen.xyz”)

In [17]:

In [17]: dir(mol.atoms[0])
Out[17]:
[‘class’,
delattr’,
dict’,
doc’,
format’,
getattribute’,
hash’,
init’,
module’,
new’,
reduce’,
reduce_ex’,
repr’,
setattr’,
sizeof’,
str’,
subclasshook’,
weakref’,
‘atomicNumber’,
‘bond’,
‘bonds’,
‘forceVector’,
‘formalCharge’,
‘id’,
‘index’,
‘isHydrogen’,
‘neighbors’,
‘partialCharge’,
‘pos’,
‘residue’,
‘residueId’,
‘type’,
‘update’,
‘valence’]


Regards,

Sampsa