The MolKit package provides classes to read molecules in a number of file formats (PDB, Mol2 ...) and build a tree-like hierarchical structure reproducing the molecule's internal structure.
For instance, a protein molecule is represented using the following four levels:
protein
chain
residue
atom
The number of levels can be modified. For instance, we have added a level between chains and residues to represent the secondary structure of the protein. All nodes in that tree-structure can be extended dynamically, i.e. to add a property like a radius to an instance of an atom called "A", one simply assigns the value to a member data of the atom: A.radius = 1.7. This structure allowing to extend dynamically any node and perform all kinds of selections has proven the be very powerful and provides a high-level interface to the molecule.
The following code instantiates a Protein object and builds its representation from a PDB file. Several selection and manipulation illustrate some of the basic capabilities of these classes:


>>> from MolKit.protein import Protein
>>> from MolKit.pdbParser import PdbParser
>>> ### create a parser object with a filename
>>> parser = PdbParser('1crn.pdb')
>>> ### the method parse of the parser read parse the file and returns a ProteinSet
>>> proteins = parser.parse()
>>> proteins
ProteinSet instance holding 1 Protein
>>> protein = proteins[0]
>>> ### You can also use the Read function of the MolKit packages to parse a
>>> ### file. That will choose the parser corresponding to the file format
>>> ### as long as one has been implemented. PdbParser, PdbqParser, Mol2Parser,
>>> ### PQRParser and PdbqsParser already exist.
>>> from MolKit import Read
>>> proteins = Read('1crn.pdb')
>>>
>>> ### Once the protein is loaded we can operate on that structure
>>> ### TreeNodeSets behave like Python arrays
>>> residues8Trhough15 = protein.chains[0].residues[8:16]
>>> allAtoms = protein.chains.residues.atoms
>>> print residues8Trhough15
ResidueSet instance holding 8 Residue
>>>
>>> ### select all atoms with their name in list bbnames:
>>> bbnames = ['N', 'CA', 'C', 'O']
>>> backBone = allAtoms.get(lambda x, names=bbnames: x.name in names)
>>>
>>> ### perform boolean operations over set:
>>> sideChains = allAtoms - backBone
>>>
>>> ### add new members on the fly to any object or set of objects:
>>> ### here we add a member called "bb" to all atoms and set it to 1
>>> ### for backbone atoms and 0 for side chain atoms
>>> allAtoms.bb = 0
>>> backBone.bb = 1
>>>
>>> ### build bonds using atomic distances
>>> protein.buildBondsByDistance()








Sophie Coon, February 2001, (sophiec@scripps.edu)