Classes, their methods, and functions in MDTools for Python

Class Structure

Inheritance is essential to the design of MDTools. The volume of source code is rather evenly distributed among the different levels of the class hierarcy, with the root classes being the most complex in most cases. An understanding of the class structure will aid your use of MDTools because of the common methods many classes inherit.

  • HomoCoord - homogeneous coordinate (x,y,z,W)
    • Vector - magnitude and direction in space (W is 0)
    • Coord - position in space (W is 1)
      • Atom - atomic properties plus links to residue, segment, and molecule
  • AtomGroup - collection of atoms, uses frames, calculates physical averages
    • ASel - generated from an AtomGroup by a selection function
    • Residue - residue properties plus links to segment and molecule
    • ResidueGroup - collection of residues
      • RSel - generated from a ResidueGroup by a selection function
      • Segment - segment properties plus link to molecule
      • SegmentGroup - collection of segments
        • Molecule - pdb and psf file handling ability
  • Trans - (homogeneous) coordinate transformation
  • DCD - dcd file reading ability
    • DCDWrite - writing ability (deals with fixed atoms)
  • Data - fancy data structure for columns of numbers, does simple calculations, generates plots
    • NAMDOutput - reads NAMD output, converts timestep to time

Methods and Functions

The documentation for the specific methods and functions listed here will improve, but for now an inspection of the quite legible source code (an important reason for choosing Python) should suffice to answer any specific questions. The __init__ method is called when an object is created by its class. All other methods of the form __foo__ correspond to operators and built-in functions such as len().

def xyplotfunction(filename):
def pdbdisplayfunction(filename):
angledefault = 'deg'
# HomoCoord class hierarcy:
def HomoCoord_downcast(x,y,z,W):
class HomoCoord:
        def __init__(self,x,y,z,W):
        def __add__(s,o):
        def __sub__(s,o):
        def __neg__(s):
        def __mul__(s,a):
        def __rmul__(s,a):
        def __div__(s,a):
        def __len__(self):
        def __getitem__(s,i):
class Vector(HomoCoord):
        def __init__(self,x,y,z):
        def __abs__(s):
        def __mul__(s,o):
        def __mod__(s,o):
        def unit(s):
class Coord(HomoCoord):
        def __init__(self,x,y,z):
        def set(s,o):
def dist(a,b):
def distsq(a,b):
def angle(a,b,c,x1=angledefault,x2=angledefault):
class Atom(Coord):
        def __init__(self):
# AtomGroup class hierarcy:
class AtomGroup:
        def __init__(self):
        def tmass(self):
        def tcharge(self):
        def cgeom(self):
        def cmass(self):
        def rgyration(self):
        def saveframe(self,key=None):
        def loadframe(self,key=None):
        def delframe(self,key=None):
        def getframe(self,frame):
        def getmolframe(self,frame):
        def putframe(self,frame):
        def asel(self,func):
class Residue(AtomGroup):
        def __init__(self):
        def buildrefs(self):
        def __getitem__(self,name):
        def rotate(self,angle,units=angledefault):
        def phipsi(self,units=angledefault):
class ASel(AtomGroup):
        def __init__(self,base,func):
class ResidueGroup(AtomGroup):
        def __init__(self):
        def buildlists(self):
        def phipsi(self,units=angledefault):
        def rsel(self,func):
class RSel(ResidueGroup):
        def __init__(self,base,func):
class Segment(ResidueGroup):
        def __init__(self):
        def buildrefs(self):
class SegmentGroup(ResidueGroup):
        def __init__(self):
        def buildlists(self):
class Molecule(SegmentGroup):
        def __init__(self,pdb=None,psf=None):
        def buildrefs(self):
        def writepdb(self,pdbfile=None):
        def display(self,file=None):
# Trans class hierarcy:
class Trans:
        def __init__(self,shift=(0.,0.,0.),center=(0.,0.,0.),
                     axis=(0.,0.,1.),angle=0.,units=angledefault):
        def __call__(self,coord):
# DCD class hierarcy:
class DCD:
        def __init__(self,dcdfile):
        def __getitem__(self,fn):
        def aselfree(self,mol):
        def __len__(self):
        def __del__(self):
class DCDWrite(DCD):
        def __init__(self,dcdfile,atoms,free=None,**header):
        def append(self):
# Data class hierarchy
class Data:
        def __init__(self,fields,data=[]):
        def __getitem__(self,key):
        def __getslice__(self,i,j):
        def __len__(self):
        def append(self,rec):
        def addfield(self,name,args,func):
        def addindex(self,offset=0,name='index'):
        def filter(self,args,func):
        def average(self,args,func=lambda x:x,zero=0.):
        def deviation(self,args,func=lambda x:x,zero=0.):
        def plot(self,args=None,file=None):
        def list(self,args=None,file=None,titles=1):
class NAMDOutput(Data):
        def __init__(self,namdfile,fields=('TS','TEMP')):
        def append(self,namdfile):
        def addtime(self):
        def plot(self,args=None,file=None):