Wednesday, January 8, 2020

software - How do I print property matrices in Avogadro?


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



Answer



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:



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

No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...