[MMTK] Constructing molecules
Konrad Hinsen
hinsen@cnrs-orleans.fr
Tue, 7 Aug 2001 11:50:38 +0200
To illustrate what I wrote about constructing molecules "from scratch",
here is a simple example. The class MyMolecule expects a name, a list
of atoms (element/position pairs), and a list of bonds (pairs of atom
indices). The resulting object can be used just like standard molecule
objects, but due to the lack of force field parameters, they cannot
be used in energy calculations.
Konrad.
----------------------------------------------------------------------
from MMTK import *
from MMTK import Bonds
class MyMolecule(Molecule):
def __init__(self, name, atoms, bonds):
self.atoms = []
self.bonds = []
self.groups = []
self.name = name
for element, position in atoms:
self.atoms.append(Atom(element, position = position))
for i1, i2 in bonds:
self.bonds.append(Bonds.Bond((self.atoms[i1], self.atoms[i2])))
self.bonds = Bonds.BondList(self.bonds)
self.parent = None # top-level object
self.type = None # no database type
h2 = MyMolecule('h2',
[('h', Vector(0., 0., -0.05)), ('h', Vector(0., 0., 0.05))],
[(0, 1)])
h2.writeToFile('test.pdb')
----------------------------------------------------------------------
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron | Fax: +33-2.38.63.15.17
45071 Orleans Cedex 2 | Deutsch/Esperanto/English/
France | Nederlands/Francais
-------------------------------------------------------------------------------