Esempio n. 1
0
 def asuToUnitCell(self, asu_contents, compact=True):
     """
     :param asu_contents: the molecules in the asymmetric unit, usually
                          obtained from :func:~MMTK.PDB.PDBConfiguration.createAll().
     :param compact: if True, all molecules images are shifted such that
                     their centers of mass lie inside the unit cell.
     :type compact: bool
     :returns: a collection containing all molecules in the unit cell,
               obtained by copying and moving the molecules from the
               asymmetric unit according to the crystallographic
               symmetry operations.
     :rtype: :class:~MMTK.Collections.Collection
     """
     unit_cell_contents = Collections.Collection()
     for symop in self.cs_transformations:
         transformation = symop.asLinearTransformation()
         rotation = transformation.tensor
         translation = transformation.vector
         image = copy.deepcopy(asu_contents)
         for atom in image.atomList():
             atom.setPosition(symop(atom.position()))
         if compact:
             cm = image.centerOfMass()
             cm_fr = self.to_fractional(cm)
             cm_fr = Vector(cm_fr[0] % 1., cm_fr[1] % 1., cm_fr[2] % 1.) \
                     - Vector(0.5, 0.5, 0.5)
             cm = self.from_fractional(cm_fr)
             image.translateTo(cm)
         unit_cell_contents.addObject(image)
     return unit_cell_contents
Esempio n. 2
0
def setConfiguration(object,
                     pdb_residues,
                     map='pdbmap',
                     alt='pdb_alternative',
                     atom_map=None,
                     toplevel=True):
    defined = 0
    if hasattr(object, 'is_protein'):
        i = 0
        for chain in object:
            l = len(chain)
            defined += setConfiguration(chain, pdb_residues[i:i + l], map, alt,
                                        atom_map, False)
            i = i + l
    elif hasattr(object, 'is_chain'):
        for i in range(len(object)):
            defined += setConfiguration(object[i], pdb_residues[i:i + 1], map,
                                        alt, atom_map, False)
    elif hasattr(object, map):
        pdbmap = getattr(object, map)
        try:
            altmap = getattr(object, alt)
        except AttributeError:
            altmap = {}
        nres = len(pdb_residues)
        if len(pdbmap) != nres:
            raise IOError('PDB configuration does not match object ' +
                          object.fullName())
        for i in range(nres):
            defined += setResidueConfiguration(object, pdb_residues[i],
                                               pdbmap[i], altmap, atom_map)
    elif Collections.isCollection(object):
        nres = len(pdb_residues)
        if len(object) != nres:
            raise IOError('PDB configuration does not match object ' +
                          object.fullName())
        for i in range(nres):
            defined += setConfiguration(object[i], [pdb_residues[i]], map, alt,
                                        atom_map, False)
    else:
        try:
            name = object.fullName()
        except AttributeError:
            try:
                name = object.name
            except AttributeError:
                name = '???'
        raise IOError('PDB configuration does not match object ' + name)

    if toplevel and defined < object.numberOfAtoms():
        name = '[unnamed object]'
        try:
            name = object.fullName()
        except:
            pass
        if name: name = ' in ' + name
        Utility.warning( ` object.numberOfAtoms() - defined ` + ' atom(s)' +
                         name + ' were not assigned (new) positions.')
    return defined
Esempio n. 3
0
 def backbone(self):
     """
     :returns: the sugar and phosphate groups
     :rtype: :class:~MMTK.ChemicalObjects.Group
     """
     bb = self.sugar
     if hasattr(self, 'phosphate'):
         bb = Collections.Collection([bb, self.phosphate])
     return bb
Esempio n. 4
0
 def __init__(self, system, grid_size, values):
     self.system = system
     if isinstance(grid_size, tuple):
         self.box, self.field, self.points, self.colors = grid_size
     else:
         if values.data_rank != 1:
             raise TypeError("data not a particle variable")
         self.box = Collections.PartitionedAtomCollection(grid_size, system)
         self._setField(values)
Esempio n. 5
0
 def sidechains(self):
     """
     :returns: the sidechain groups of all residues in all chains
     :rtype: :class:~MMTK.Collections.Collection
     """
     rlist = Collections.Collection([])
     for m in self.molecules:
         if isPeptideChain(m):
             rlist = rlist + m.sidechains()
     return rlist
Esempio n. 6
0
 def backbone(self):
     """
     :returns: the peptide groups of all residues in all chains
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     rlist = Collections.Collection([])
     for m in self.molecules:
         if isPeptideChain(m):
             rlist = rlist + m.backbone()
     return rlist
Esempio n. 7
0
 def residues(self):
     """
     :returns: all residues in all chains
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     rlist = Collections.Collection([])
     for m in self.molecules:
         if isPeptideChain(m):
             rlist = rlist + m.residues()
     return rlist
Esempio n. 8
0
 def residuesOfType(self, *types):
     """
     :param types: residue type codes
     :type types: str
     :returns: a collection that contains all residues whose type
               (residue code) is contained in types
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     types = [t.lower() for t in types]
     rlist = [r for r in self.groups if r.type.symbol.lower() in types]
     return Collections.Collection(rlist)
Esempio n. 9
0
def setConfiguration(object, pdb_residues,
                     map = 'pdbmap', alt = 'pdb_alternative',
                     atom_map = None, toplevel = True):
    defined = 0
    if hasattr(object, 'is_protein'):
        i = 0
        for chain in object:
            l = len(chain)
            defined += setConfiguration(chain, pdb_residues[i:i+l],
                                        map, alt, atom_map, False)
            i = i + l
    elif hasattr(object, 'is_chain'):
        for i in range(len(object)):
            defined += setConfiguration(object[i], pdb_residues[i:i+1],
                                        map, alt, atom_map, False)
    elif hasattr(object, map):
        pdbmap = getattr(object, map)
        try: altmap = getattr(object, alt)
        except AttributeError: altmap = {}
        nres = len(pdb_residues)
        if len(pdbmap) != nres:
            raise IOError('PDB configuration does not match object ' +
                           object.fullName())
        for i in range(nres):
            defined += setResidueConfiguration(object, pdb_residues[i],
                                               pdbmap[i], altmap, atom_map)
    elif Collections.isCollection(object):
        nres = len(pdb_residues)
        if len(object) != nres:
            raise IOError('PDB configuration does not match object ' +
                           object.fullName())
        for i in range(nres):
            defined += setConfiguration(object[i], [pdb_residues[i]],
                                        map, alt, atom_map, False)
    else:
        try:
            name = object.fullName()
        except AttributeError:
            try:
                name = object.name
            except AttributeError:
                name = '???'
        raise IOError('PDB configuration does not match object ' + name)
              
    if toplevel and defined < object.numberOfAtoms():
        name = '[unnamed object]'
        try:
            name = object.fullName()
        except: pass
        if name: name = ' in ' + name
        Utility.warning(`object.numberOfAtoms()-defined` + ' atom(s)' + name +
                        ' were not assigned (new) positions.')
    return defined
Esempio n. 10
0
 def sidechains(self):
     """
     :returns: the sidechain groups of all residues
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     sidechains = Collections.Collection()
     for r in self.groups:
         try:
             sidechains.addObject(r.sidechain)
         except AttributeError:
             pass
     return sidechains
Esempio n. 11
0
 def backbone(self):
     """
     :returns: the peptide groups of all residues
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     backbone = Collections.Collection()
     for r in self.groups:
         try:
             backbone.addObject(r.peptide)
         except AttributeError:
             pass
     return backbone
Esempio n. 12
0
 def backbone(self):
     """
     :returns: the sugar and phosphate groups of all nucleotides
     :rtype: :class:~MMTK.Collections.Collection
     """
     bb = Collections.Collection([])
     for residue in self.groups:
         try:
             bb.addObject(residue.phosphate)
         except AttributeError:
             pass
         bb.addObject(residue.sugar)
     return bb
Esempio n. 13
0
 def residuesOfType(self, *types):
     """
     :param types: a sequence of residue codes (one- or three-letter)
     :type types: sequence of str
     :returns: all residues whose type (one- or three-letter code)
               is contained in types
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     rlist = Collections.Collection([])
     for m in self.molecules:
         if isPeptideChain(m):
             rlist = rlist + apply(m.residuesOfType, types)
     return rlist
Esempio n. 14
0
 def _findSSBridges(self, molecules):
     molecules = filter(lambda m: hasattr(m, 'is_peptide_chain'), molecules)
     cys = Collections.Collection([])
     for m in molecules:
         if m.version_spec['model'] != 'calpha':
             cys = cys + m.residuesOfType('cys') + m.residuesOfType('cyx')
     s = cys.map(lambda r: r.sidechain.S_gamma)
     ns = len(s)
     ss = []
     for i in xrange(ns-1):
         for j in xrange(i+1,ns):
             r1 = s[i].position()
             r2 = s[j].position()
             if r1 and r2 and (r1-r2).length() < self._ss_bond_max:
                 ss.append((cys[i], cys[j]))
     return ss
Esempio n. 15
0
 def createAll(self, molecule_names = None, permit_undefined=True):
     """
     :returns: a collection containing all objects contained in the
               PDB file, i.e. the combination of the objects
               returned by :func:~MMTK.PDB.PDBConfiguration.createPeptideChains,
               :func:~MMTK.PDB.PDBConfiguration.createNucleotideChains,
               and :func:~MMTK.PDB.PDBConfiguration.createMolecules.
               The parameters have the same meaning as for
               :func:~MMTK.PDB.PDBConfiguration.createMolecules.
     :rtype: :class:~MMTK.Collectionc.Collection
     """
     collection = Collections.Collection()
     peptide_chains = self.createPeptideChains()
     if peptide_chains:
         import Proteins
         collection.addObject(Proteins.Protein(peptide_chains))
     nucleotide_chains = self.createNucleotideChains()
     collection.addObject(nucleotide_chains)
     molecules = self.createMolecules(molecule_names, permit_undefined)
     collection.addObject(molecules)
     return collection
Esempio n. 16
0
 def residues(self):
     """
     :returns: a collection containing all residues
     :rtype: :class:`~MMTK.Collections.Collection`
     """
     return Collections.Collection(self.groups)
Esempio n. 17
0
 def bases(self):
     """
     :returns: the base groups of all nucleotides
     :rtype: :class:~MMTK.Collections.Collection
     """
     return Collections.Collection([r.base for r in self.groups])
Esempio n. 18
0
 def createMolecules(self, names = None, permit_undefined=True):
     """
     :param names: If a list of molecule names (as defined in the
                   chemical database) and/or PDB residue names,
                   only molecules mentioned in this list will be
                   constructed. If a dictionary, it is used to map
                   PDB residue names to molecule names. With the
                   default (None), only water molecules are
                   built.
     :type names: list
     :param permit_undefined: If False, an exception is raised
                              when a PDB residue is encountered for
                              which no molecule name is supplied
                              in names. If True, an AtomCluster
                              object is constructed for each unknown
                              molecule.
     :returns: a collection of :class:~MMTK.ChemicalObjects.Molecule objects,
               one for each molecule in the PDB file. Each PDB residue not 
               describing an amino acid or nucleotide residue is considered a
               molecule.
     :rtype: :class:~MMTK.Collections.Collection
     """
     collection = Collections.Collection()
     mol_dicts = [molecule_names]
     if type(names) == type({}):
         mol_dicts.append(names)
         names = None
     for name in self.molecules.keys():
         full_name = None
         for dict in mol_dicts:
             full_name = dict.get(name, None)
         if names is None or name in names or full_name in names:
             if full_name is None and not permit_undefined:
                 raise ValueError("no definition for molecule " + name)
             for molecule in self.molecules[name]:
                 if full_name:
                     m = ChemicalObjects.Molecule(full_name)
                     setConfiguration(m, [molecule])
                 else:
                     pdbdict = {}
                     atoms = []
                     i = 0
                     for atom in molecule:
                         aname = atom.name
                         while aname[0] in string.digits:
                             aname = aname[1:] + aname[0]
                         try:
                             element = atom['element'].strip()
                             a = ChemicalObjects.Atom(element, name = aname)
                         except KeyError:
                             try:
                                 a = ChemicalObjects.Atom(aname[:2].strip(),
                                                          name = aname)
                             except IOError:
                                 a = ChemicalObjects.Atom(aname[:1],
                                                          name = aname)
                         a.setPosition(atom.position)
                         atoms.append(a)
                         pdbdict[atom.name] = Database.AtomReference(i)
                         i += 1
                     m = ChemicalObjects.AtomCluster(atoms, name = name)
                     if len(pdbdict) == len(molecule):
                         # pdbmap is correct only if the AtomCluster has
                         # unique atom names
                         m.pdbmap = [(name, pdbdict)]
                     setConfiguration(m, [molecule])
                 collection.addObject(m)
     return collection