dear avogadro users and developers,
i am trying to use the python bindings in Avogadro 1.0.3 to read and
display molecules bypassing openbabel. as a first step i tried to build
an extension that reads a tinker xyz file. it reads and generates all
atoms fine, but when I try to add bonds, even in the first call
bond = mol.addBond()
(with mol = glwidget.molecule) Avogadro dies with a segfault.
Is there anything seriously wrong in doing that? my interpretation is
that a segfault should not happen from the scripting interface.
any hints/comments highly appreciated.
as rationale:
in a longer term research project (python wrapped dl_poly) we consider
using Avogadro as a graphical frontend due to its python extensions. in
order to test this possibility i want to use it to visualize MD
trajectories stored via h5py in the hdf5 format. reading ascii tinker
files is just to understand the way Avogadro handles molecule data.
--
PD Dr. Rochus Schmid
Lehrstuhl für Anorganische Chemie II
Organometallics and Materials Chemistry
Ruhr-Universität Bochum
D-44780 Bochum
Tel.: ++49(234) 32 24166
Fax: ++49(234) 32 14174
Email: [email protected]
http://www.rochusschmid.de
15 molden generated tinker .xyz (mm3 param.)
1 C 0.000000 0.000000 0.000000 2 2 6 12
2 C 0.000000 0.000000 1.400000 2 1 3 7
3 C 1.212436 0.000000 2.100000 2 2 4 8
4 C 2.424871 0.000000 1.400000 2 3 5 9
5 C 2.424871 0.000000 0.000000 2 4 6 10
6 C 1.212436 0.000000 -0.700000 2 1 5 11
7 H -0.943102 0.000000 1.944500 5 2
8 H 1.212436 0.000000 3.189000 5 3
9 H 3.367973 0.000000 1.944500 5 4
10 H 3.367973 0.000000 -0.544500 5 5
11 H 1.212436 0.000000 -1.789000 5 6
12 C -1.255737 0.000000 -0.725000 1 1 13 14 15
13 H -2.083464 0.000000 -0.017335 5 12
14 H -1.313424 0.889165 -1.351082 5 12
15 H -1.313424 -0.889165 -1.351082 5 12
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from numpy import *
import Avogadro
from string import *
# add more here ...
PSE = ["x","h","he","li","be","b","c","n","o","f","ne"]
# always use 'Extension' for class name
class Extension(QObject):
def __init__(self):
QObject.__init__(self)
def name(self):
return "xyz_read"
def description(self):
return "Extension for reading tinker xyz files"
def actions(self):
actions = []
action = QAction(self)
action.setText("open tinker xyz")
actions.append(action)
return actions
def menuPath(self, action):
return "Scripts"
def performAction(self, action, glwidget):
if action.text() == "open tinker xyz":
self.read_tinker_xyz(glwidget)
return None
def read_tinker_xyz(self, glwidget):
formats = ["*.xyz"]
fname = unicode(QFileDialog.getOpenFileName(None,
"MolViewer - Open File", ".",
"Mol files (%s)" % " ".join(formats)))
fxyz = open(fname, "r")
fline = split(fxyz.readline())
natoms = atoi(fline[0])
mol = glwidget.molecule
bondlist = []
for i in xrange(natoms):
fline = split(fxyz.readline())
print fline
elem = fline[1]
xyz = array(map(atof,fline[2:5]),"d")
atom = mol.addAtom()
atom.atomicNumber = PSE.index(lower(elem))
atom.pos = xyz
cnct = map(atoi, fline[5:])
for aj in cnct:
j = aj-1
if j>i: bondlist.append([i,j])
bond = mol.addBond()
# for b in bonds:
# bond = mol.addBond()
# bond.setAtoms(b)
fxyz.close()
return
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Avogadro-Discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/avogadro-discuss