4
$\begingroup$

I'd like to print the content of property matrices (i.e., the matrices shown after selecting View→Properties→X where X is one of the six options shown, including Angle properties..., Atom properties... and Bond properties...) in Avogadro, but I can't seem to find this option at Avogadro Wiki or other forms of Avogadro documentation.

e.g. this is the bond properties matrix. enter image description here

$\endgroup$
3
  • $\begingroup$ Right, it doesn't exist at the moment. Probably the easiest thing would be to allow export as text or a CSV, but I'm not sure when the next release would be. $\endgroup$ Commented May 4, 2015 at 15:14
  • $\begingroup$ I'd also like to recommend future releases include a Windows version with python terminal as the only way I can access the python terminal is via installing Avogadro 1.0.1 python win32 (i.e., the file available here internode.dl.sourceforge.net/project/avogadro/avogadro/1.0.1/…). $\endgroup$
    – Josh Pinto
    Commented May 4, 2015 at 23:05
  • $\begingroup$ Yes, but without a Windows developer, those releases will be something of second-class citizens to Mac and Linux releases, sorry. $\endgroup$ Commented May 5, 2015 at 4:18

1 Answer 1

2
$\begingroup$

I am not aware of a menu button to print these tables.

There is however a different way to get your hands on the numbers.

Avogadro features objects: molecules, bonds and atoms are instances of classes, whose properties can be read and processed by programming. The easiest way is the build-in Python-Terminal.

(Note that I'm using Avogadro 1.1.1 on Linux in German, your menus will have different labels.)

  1. In Avogadro, open a Python Terminal (In German, this is done via
    Einstellungen -> Werkzeugleisten -> Python-Terminal, which should be something like Settings -> Tool bars -> Python terminal

When run in the Python terminal of Avogradro, the following snippet writes

  • atom index
  • atomic number
  • x, y, z coordinates

for all atoms of the currently opened molecule to a csv file into an existing tmp directory in the user's home.

import os.path  
import csv

home = os.path.expanduser('~')
data_dir = 'tmp'
atom_table_name = 'atoms.csv'
atom_table_path = os.path.join(home, data_dir, atom_table_name)
# generate full path for file with atom data

with open(atom_table_path, 'wt') as fout:
    writer = csv.writer(fout)
    writer.writerow(('Index', 'Atomic number', 'X', 'Y', 'Z'))

    mol = Avogadro.molecule

    for atom in mol.atoms:
        index = atom.index + 1
        x, y, z = atom.pos
        writer.writerow((index, atom.atomicNumber, x, y, z))


EDIT

I mentioned the Python Terminal first because I didn't want to introduce too much different things at once.

Once you have played a bit with the build-in Python Terminal, you will want to go one step beyond and try a more comfortable IDE with logging, tab-completion, build-in help, etc. My suggestion is to try IPython!

With IPython (or any other IDE of your choice), you can make use of Avogadro through its API without actually running it.

Given that your data file propen.cml looks like this:

<molecule> <atomArray> <atom id="a1" elementType="C" x3="-6.736896" y3="1.198243" z3="-0.001854"/> <atom id="a2" elementType="C" x3="-5.625957" y3="2.233390" z3="-0.108371"/> <atom id="a3" elementType="H" x3="-6.748313" y3="0.730420" z3="0.988429"/> <atom id="a4" elementType="H" x3="-6.615420" y3="0.408802" z3="-0.751312"/> <atom id="a5" elementType="H" x3="-7.710837" y3="1.671184" z3="-0.163704"/> <atom id="a6" elementType="C" x3="-4.268024" y3="1.629800" z3="0.106393"/> <atom id="a7" elementType="H" x3="-5.801148" y3="3.017025" z3="0.637857"/> <atom id="a8" elementType="H" x3="-5.668681" y3="2.695849" z3="-1.101309"/> <atom id="a9" elementType="C" x3="-3.137190" y3="2.345874" z3="0.062502"/> <atom id="a10" elementType="H" x3="-4.203709" y3="0.562202" z3="0.306350"/> <atom id="a11" elementType="H" x3="-3.147760" y3="3.413685" z3="-0.133506"/> <atom id="a12" elementType="H" x3="-2.172936" y3="1.873521" z3="0.222912"/> </atomArray> <bondArray> <bond atomRefs2="a1 a2" order="1"/> <bond atomRefs2="a1 a3" order="1"/> <bond atomRefs2="a1 a4" order="1"/> <bond atomRefs2="a1 a5" order="1"/> <bond atomRefs2="a2 a6" order="1"/> <bond atomRefs2="a2 a7" order="1"/> <bond atomRefs2="a2 a8" order="1"/> <bond atomRefs2="a6 a9" order="2"/> <bond atomRefs2="a6 a10" order="1"/> <bond atomRefs2="a9 a11" order="1"/> <bond atomRefs2="a9 a12" order="1"/> </bondArray> </molecule>

you can load the CML file and iterate over the bonds to display the index numbers of the atoms in the bond and the bond length using:

import Avogadro as av

mol = av.MoleculeFile.readMolecule('propen.cml')
# don't forget to adjust the path for the data file!

for bond in mol.bonds:
    first = bond.beginAtom
    last = bond.endAtom
    print first.index, last.index, bond.length
$\endgroup$
9
  • $\begingroup$ That gave the output: Traceback (most recent call last): File "<string>", line 1, in <module> IOError: [Errno 2] No such file or directory: 'C:\\Users\\Brenton\\tmp\\atoms.csv' $\endgroup$
    – Josh Pinto
    Commented May 4, 2015 at 10:47
  • $\begingroup$ @BrentonHorne Does a tmp directory exist in your home? $\endgroup$ Commented May 4, 2015 at 11:00
  • $\begingroup$ Doesn't I'm afraid. $\endgroup$
    – Josh Pinto
    Commented May 4, 2015 at 11:44
  • $\begingroup$ @BrentonHorne I'm sorry for the confusion. I just haven't made myself clear enough :) I wanted to avoid that your home folder gets littered up with stuff. Therefore, the code snippet was programmed to write the csv to a separate directory, tmp for all the temporary stuff that can be deleted later. If you create the tmp directory manually, the script - run from within Avogadro - should work as intended :) $\endgroup$ Commented May 4, 2015 at 12:34
  • $\begingroup$ Thanks, but it appears that Avogadro still wants to be difficult, and is giving me this output: Traceback (most recent call last): File "<string>", line 5, in <module> NameError: name 'Avogadro' is not defined $\endgroup$
    – Josh Pinto
    Commented May 4, 2015 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.