This demo provides a quick introduction to the power and simplicity of the MDTools module.

Loading MDTools

To load the MDTools module, use the command import md.

Python 1.3 (October 13 1995) [C]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import md
MDTools 0.54 beta (3/11/96) by James Phillips.  md.help() for more info.

Using MDTools

The following is based on interactive use. In a Python script, input would not be seen and the print command would be needed to see test representations of objects and return values.

Load a Molecule

First we will load a molecule from a pair of pdb and psf files. What we are really doing is creating a new Molecule object from the given files. From now on we can perform most tasks by using this object's methods.

>>> almol = md.Molecule(pdb='alanin.pdb',psf='alanin.psf')
REMARK FILENAME="/usr/people/nonella/xplor/benchmark1/ALANIN.PDB"
REMARK PARAM11.PRO ( from PARAM6A )
REMARK ===========
REMARK PROTEIN PARAMETERS:
REMARK PEPTIDE GEOMETRY FROM RAMACHANDRAN ET AL BBA 359:298 (1974)
REMARK TORSIONS FROM HAGLER ET AL JACS 98:4600 (1976)
REMARK LENNARD-JONES NONBONDED PARAMETERS WITH SPECIAL TREATMENT OF 1:4
REMARK CARBON-CARBON INTERACTIONS: JORGENSON ET. AL.
REMARK                           JACS 103:3976-3985 WITH 1-4 RC=1.80/0.1
REMARK DATE:16-Feb-89  11:21:32       created by user: nonella
REMARKS FILENAME="/usr/people/nonella/xplor/benchmark1/ALANIN.PSF"
REMARKS PARAM11.PRO ( from PARAM6A )
REMARKS ===========
REMARKS PROTEIN PARAMETERS:
REMARKS PEPTIDE GEOMETRY FROM RAMACHANDRAN ET AL BBA 359:298 (1974)
REMARKS TORSIONS FROM HAGLER ET AL JACS 98:4600 (1976)
REMARKS LENNARD-JONES NONBONDED PARAMETERS WITH SPECIAL TREATMENT OF 1:4
REMARKS CARBON-CARBON INTERACTIONS: JORGENSON ET. AL.
REMARKS                           JACS 103:3976-3985 WITH 1-4 RC=1.80/0.1
REMARKS
REMARKS DATE:16-Feb-89  11:21:29       created by user: nonella

Inspect a Molecule

Now we can print out various properties of the molecule.

>>> almol
< Molecule with 1 segments, 12 residues, and 66 atoms >
>>> almol.cgeom()
Coord(4.626863636364,5.36,4.105863636364)
>>> almol.tcharge()
-8.32667268468e-17
>>> almol.tmass()
783.8861
>>> almol.cmass()
Coord(4.810672723627,5.306472581029,4.220194354511)
>>> almol.rgyration()
5.496844174319
>>> almol.phipsi()
[(None, None), (-57.038520148009, -46.900302315552), (-57.043920005484, -47.021795175375), (-57.030478038158, -46.974531922263), (-56.960901332562, -46.970048991722), (-57.026928674924, -46.990459515855), (-57.064266190145, -46.891735804193), (-57.089235864915, -46.946010618505), (-57.077154064709, -46.996909544687), (-56.971657139764, -47.09269848728), (-56.929460192714, -47.004412525989), (None, None)]

We can perform similar calculations on individual residues.

>>> almol.residues[3].cmass()
Coord(0.596913960644,4.910430676528,3.554582521444)
>>> almol.residues[5].phipsi()
(-57.026928674924, -46.990459515855)

Load a DCD File

Frames (sets of coordinates) can be saved internally and loaded from DCD files.

>>> aldcd = md.DCD('alanin.dcd')
REMARKS FILENAME=/home/jim/Research/alanin/alanin.dcd CREATED BY NAMD
REMARKS DATE: 08/08/95 CREATED BY USER: jim
>>> aldcd
< DCD alanin.dcd with 104 frames of 66 atoms (0 fixed) >
>>> almol.saveframe()
>>> almol.getframe(aldcd[35])
>>> almol.cmass()
Coord(7.496042057769,6.153280394392,2.655104887051)
>>> almol.loadframe()

Transform Coordinates

We can set up coordinate transformations and apply then to arbitrary sets of atoms. Here we shift the center of mass of the molecule first to the origin and then one angstrom along the x axis.

>>> t = md.Trans(shift=almol.cmass())
>>> md.Trans(shift=(1,0,0))(t)
>>> t
< Trans ((1.0,0.0,0.0,-3.810672723627), (0.0,1.0,0.0,-5.306472581029), (0.0,0.0,1.0,-4.220194354511), (0.0,0.0,0.0,1.0)) >
>>> t(almol)
>>> almol.cmass()
Coord(1.0,1.62252079353e-15,2.42924900931e-15)

Now we will rotate about the z axis and save the result to a pdb file.

>>> md.Trans(axis=(0,0,1),angle=90)(almol)
>>> almol.cmass()
Coord(-1.53187717378e-15,1.0,2.42924900931e-15)
>>> almol.writepdb('foo.pdb')

Make a Selection

Selections of atoms or residues are made using user-supplied functions. Here we select only carbon-alpha atoms. This creates an atom-selection object which then behaves similarly to any other group of atoms.

>>> ca = almol.asel(lambda a: a.name=='CA')
>>> ca
< ASel with 12 atoms >
>>> ca.cmass()
Coord(0.200162441256,0.822239225706,-0.160105530101)
>>> ca.tmass()
160.26

We could, for example, select only backbone atoms, or only half of the residues (creating a residue-selection object).

>>> almol.asel(lambda a: a.name in md.backbone).cmass()
Coord(0.114916249354,1.180189659275,0.076747546353)
>>> al2 = almol.rsel(lambda r: r.id > 6)
>>> al2
< RSel with 6 residues and 33 atoms >

Use a Selection

Note that changing the coordinates of a molecule (by transformations or loading a frame) changes the coordinates of a selection, and vice-versa, because both objects refer to the same atoms (and residues).

>>> print al2.cmass()
Coord(1.061584211684,4.394206771046,2.516369902353)
>>> almol.getframe(aldcd[100])
>>> print al2.cmass()
Coord(9.897853204826,0.611663114015,-1.065932873355)