def _init(self): # construct PDB map and alternative names type = self.type if not hasattr(type, 'pdbmap'): pdb_dict = {} type.pdbmap = [(type.symbol, pdb_dict)] offset = 0 for g in type.groups: for name, atom in g.pdbmap[0][1].items(): pdb_dict[name] = Database.AtomReference(atom.number + \ offset) offset = offset + len(g.atoms) if not hasattr(type, 'pdb_alternative'): alt_dict = {} for g in type.groups: if hasattr(g, 'pdb_alternative'): for key, value in g.pdb_alternative.items(): alt_dict[key] = value setattr(type, 'pdb_alternative', alt_dict)
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
def getReference(self, atom): if atom.__class__ is Database.AtomReference: return atom return Database.AtomReference(self.atoms.index(atom))