def _setupChain(self, circular, properties, conf): 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): 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) if properties.has_key('position'): self.translateTo(properties['position']) del properties['position'] self.addProperties(properties)
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: peptide_old = self.bonds.bondsOf(r_old.peptide.N) self.bonds.remove(peptide_old[0]) if n < len(self.groups) - 1: peptide_old = self.bonds.bondsOf(r_old.peptide.C) self.bonds.remove(peptide_old[0]) 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 __init__(self, blueprint, _memo=None, **properties): if blueprint is not None: # blueprint is None when called from MoleculeFactory ChemicalObject.__init__(self, blueprint, _memo) properties = copy.copy(properties) CompositeChemicalObject.__init__(self, properties) self.bonds = Bonds.BondList(self.bonds)
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 __init__(self, atoms, **properties): self.atoms = list(atoms) self.parent = None 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 replaceResidue(self, r_old, r_new): """Replaces residue |r_old|, which must be a residue object that is part of the chain, by the residue object |r_new|.""" 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 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]) 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]) 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 addGroup(self, group, bond_atom_pairs): for a1, a2 in bond_atom_pairs: o1 = a1.topLevelChemicalObject() o2 = a2.topLevelChemicalObject() if not (o1 == self and o2 == group) \ and not(o2 == self and o1 == 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 string.lower(cys1.symbol) == 'cyx': cys_ss1 = cys1 else: cys_ss1 = cys1._makeCystine() self.replaceResidue(cys1, cys_ss1) cys2 = b[1] if string.lower(cys2.symbol) == '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, 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 = {} for i in range(len(self.chains)): c = self.chains[i] sub_chain = SubChain(self, self.groups[c[1]:c[2]], c[0]) sub_chain.version_spec = c[3] for g in sub_chain.groups: g.parent = sub_chain self.chains[i] = sub_chain
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)