def replaceResidue(self, r_old, r_new): for a in r_old.atoms: self.atoms.remove(a) obsolete_bonds = [] for b in self.bonds: if b.a1 in r_old.atoms or b.a2 in r_old.atoms: obsolete_bonds.append(b) for b in obsolete_bonds: self.bonds.remove(b) n = self.groups.index(r_old) if n > 0: for b in self.bonds.bondsOf(r_old.peptide.N): self.bonds.remove(b) if n < len(self.groups)-1: for b in self.bonds.bondsOf(r_old.peptide.C): self.bonds.remove(b) PeptideChain.replaceResidue(self.part_of, r_old, r_new) self.groups[n] = r_new self.atoms.extend(r_new.atoms) self.bonds.extend(r_new.bonds) if n > 0: self.bonds.append(Bonds.Bond((self.groups[n-1].peptide.C, self.groups[n].peptide.N))) if n < len(self.groups)-1: self.bonds.append(Bonds.Bond((self.groups[n].peptide.C, self.groups[n+1].peptide.N)))
def _setupChain(self, circular, properties, conf): self.atoms = [] self.bonds = [] for g in self.groups: self.atoms.extend(g.atoms) self.bonds.extend(g.bonds) for i in range(len(self.groups)-1): link1 = self.groups[i].chain_links[1] link2 = self.groups[i+1].chain_links[0] self.bonds.append(Bonds.Bond((link1, link2))) if circular: link1 = self.groups[-1].chain_links[1] link2 = self.groups[0].chain_links[0] self.bonds.append(Bonds.Bond((link1, link2))) self.bonds = Bonds.BondList(self.bonds) self.parent = None self.type = None self.configurations = {} try: self.name = properties['name'] del properties['name'] except KeyError: self.name = '' if conf: conf.applyTo(self) try: self.translateTo(properties['position']) del properties['position'] except KeyError: pass self.addProperties(properties)
def __init__(self, m, ident, owner): from MMTK import Bonds self.chimeraMolecule = m self.needParmchk = set([]) self.frcmod = None self.atomMap = owner.atomMap self.name = m.name self.parent = None self.type = None self.groups = [] for r in m.residues: v = self._findStandardResidue(r) if v is None: self._makeNonStandardResidue(r) else: self._makeStandardResidue(r, *v) atoms = [] bonds = [] for g in self.groups: atoms.extend(g.atoms) bonds.extend(g.bonds) from chimera import Bond for b in m.bonds: if b.display == Bond.Never: continue a0, a1 = b.atoms if a0.residue is a1.residue: continue mb = Bonds.Bond((self.atomMap[a0], self.atomMap[a1])) bonds.append(mb) self.atoms = atoms self.bonds = Bonds.BondList(bonds) if self.needParmchk: self._runParmchk(ident, owner.getTempDir())
def replaceResidue(self, r_old, r_new): """ :param r_old: the residue to be replaced (must be part of the chain) :type r_old: Residue :param r_new: the residue that replaces r_old :type r_new: Residue """ n = self.groups.index(r_old) for a in r_old.atoms: self.atoms.remove(a) obsolete_bonds = [] for b in self.bonds: if b.a1 in r_old.atoms or b.a2 in r_old.atoms: obsolete_bonds.append(b) for b in obsolete_bonds: self.bonds.remove(b) r_old.parent = None self.atoms.extend(r_new.atoms) self.bonds.extend(r_new.bonds) r_new.sequence_number = n + 1 if r_old.name.startswith(r_old.symbol): r_new.name = r_new.symbol + r_old.name[len(r_old.symbol):] else: r_new.name = r_new.symbol + ` n + 1 ` r_new.parent = self self.groups[n] = r_new if n > 0: peptide_old = self.bonds.bondsOf(r_old.peptide.N) if peptide_old: self.bonds.remove(peptide_old[0]) if not (self.groups[n - 1].isCTerminus() or self.groups[n].isNTerminus()): # ConnectedChain objects can have N/C-terminal # residues inside the (virtual) chain, so the # test is necessary. self.bonds.append( Bonds.Bond((self.groups[n - 1].peptide.C, self.groups[n].peptide.N))) if n < len(self.groups) - 1: peptide_old = self.bonds.bondsOf(r_old.peptide.C) if peptide_old: self.bonds.remove(peptide_old[0]) if not (self.groups[n].isCTerminus() or self.groups[n + 1].isNTerminus()): self.bonds.append( Bonds.Bond((self.groups[n].peptide.C, self.groups[n + 1].peptide.N))) if isinstance(self.parent, ChemicalObjects.Complex): self.parent.recreateAtomList() universe = self.universe() if universe is not None: universe._changed(True)
def __init__(self, chains=None): if chains is not None: self.chains = [] self.groups = [] self.atoms = [] self.bonds = Bonds.BondList([]) self.chain_names = [] self.model = chains[0].model version_spec = chains[0].version_spec for c in chains: if c.version_spec['model'] != version_spec['model']: raise ValueError("mixing chains of different model: " + c.version_spec['model'] + "/" + version_spec['model']) ng = len(self.groups) self.chains.append((c.name, ng, ng+len(c.groups), c.version_spec)) self.groups.extend(c.groups) self.atoms.extend(c.atoms) self.bonds.extend(c.bonds) try: name = c.name except AttributeError: name = '' self.chain_names.append(name) for g in self.groups: g.parent = self self.name = '' self.parent = None self.type = None self.configurations = {}
def __init__(self, chain, groups, name = ''): self.groups = groups self.atoms = [] self.bonds = [] for g in self.groups: self.atoms = self.atoms + g.atoms self.bonds = self.bonds + g.bonds for i in range(len(self.groups)-1): self.bonds.append(Bonds.Bond((self.groups[i].sugar.O_3, self.groups[i+1].phosphate.P))) self.bonds = Bonds.BondList(self.bonds) self.name = name self.parent = chain.parent self.type = None self.configurations = {} self.part_of = chain
def __init__(self, chain=None, groups=None, name = ''): if chain is not None: self.groups = groups self.atoms = [] self.bonds = [] for g in self.groups: self.atoms.extend(g.atoms) self.bonds.extend(g.bonds) for i in range(len(self.groups)-1): link1 = self.groups[i].chain_links[1] link2 = self.groups[i+1].chain_links[0] self.bonds.append(Bonds.Bond((link1, link2))) self.bonds = Bonds.BondList(self.bonds) self.name = name self.model = chain.model self.parent = chain.parent self.type = None self.configurations = {} self.part_of = chain
def makeChemicalObjects(self, template, top_level): self.groups[template.name].locked = True if top_level: if template.attributes.has_key('sequence'): object = ChemicalObjects.ChainMolecule(None) else: object = ChemicalObjects.Molecule(None) else: object = ChemicalObjects.Group(None) object.atoms = [] object.bonds = Bonds.BondList([]) object.groups = [] object.type = self.groups[template.name] object.parent = None child_objects = [] for child in template.children: if isinstance(child, GroupTemplate): group = self.makeChemicalObjects(child, False) object.groups.append(group) object.atoms.extend(group.atoms) object.bonds.extend(group.bonds) group.parent = object child_objects.append(group) else: atom = ChemicalObjects.Atom(child.element) object.atoms.append(atom) atom.parent = object child_objects.append(atom) for name, index in template.names.items(): setattr(object, name, child_objects[index]) child_objects[index].name = name for name, value in template.attributes.items(): path = name.split('.') setattr(self.namePath(object, path[:-1]), path[-1], value) for atom1, atom2 in template.bonds: atom1 = self.namePath(object, atom1) atom2 = self.namePath(object, atom2) object.bonds.append(Bonds.Bond((atom1, atom2))) for name, vector in template.positions.items(): path = name.split('.') self.namePath(object, path).setPosition(vector) return object
def addGroup(self, group, bond_atom_pairs): for a1, a2 in bond_atom_pairs: o1 = a1.topLevelChemicalObject() o2 = a2.topLevelChemicalObject() if set([o1, o2]) != set([self, group]): raise ValueError("bond %s-%s outside object" % (str(a1), str(a2))) self.groups.append(group) self.atoms = self.atoms + group.atoms group.parent = self self.clearBondAttributes() for a1, a2 in bond_atom_pairs: self.bonds.append(Bonds.Bond((a1, a2))) for b in group.bonds: self.bonds.append(b)
def _addSSBridges(self, bonds): for b in bonds: cys1 = b[0] if cys1.symbol.lower() == 'cyx': cys_ss1 = cys1 else: cys_ss1 = cys1._makeCystine() self.replaceResidue(cys1, cys_ss1) cys2 = b[1] if cys2.symbol.lower() == 'cyx': cys_ss2 = cys2 else: cys_ss2 = cys2._makeCystine() self.replaceResidue(cys2, cys_ss2) self.bonds.append(Bonds.Bond((cys_ss1.sidechain.S_gamma, cys_ss2.sidechain.S_gamma)))
def __init__(self, atoms, **properties): """ :param atoms: a list of atoms in the cluster :type atoms: list :keyword position: the position of the center of mass of the cluster :type position: Scientific.Geometry.Vector :keyword name: a name given to the cluster :type name: str """ self.atoms = list(atoms) self.parent = None self.name = '' self.type = None for a in self.atoms: if a.parent is not None: raise ValueError(repr(a) + ' is part of ' + repr(a.parent)) a.parent = self if a.name != '': setattr(self, a.name, a) properties = copy.copy(properties) CompositeChemicalObject.__init__(self, properties) self.bonds = Bonds.BondList([])
def __init__(self, molecule_spec, _memo=None, **properties): """ :param molecule_spec: a string (not case sensitive) that specifies the molecule name in the chemical database :type molecule_spec: str :keyword position: the position of the center of mass of the molecule :type position: Scientific.Geometry.Vector :keyword name: a name given to the molecule :type name: str :keyword configuration: the name of a configuration listed in the database definition of the molecule, which is used to initialize the atom positions. If no configuration is specified, the configuration named "default" will be used, if it exists. Otherwise the atom positions are undefined. :type configuration: str """ if molecule_spec is not None: # molecule_spec is None when called from MoleculeFactory ChemicalObject.__init__(self, molecule_spec, _memo) properties = copy.copy(properties) CompositeChemicalObject.__init__(self, properties) self.bonds = Bonds.BondList(self.bonds)
def __init__(self, blueprint, _memo=None, **properties): ChemicalObject.__init__(self, blueprint, _memo) properties = copy.copy(properties) CompositeChemicalObject.__init__(self, properties) self.bonds = Bonds.BondList(self.bonds)