def builder(residues, bonds, mol_name): """Using the list generated by read_input connects monosacharides in a single oligosaccharide""" cmd.set('suspend_updates', 'on') cmd.feedback('disable', 'executive', 'actions') every_object = cmd.get_object_list('all') if mol_name in every_object: cmd.delete(mol_name) every_object.remove(mol_name) if every_object: sel = 'not (' + ' or '.join(every_object) + ') and' else: sel = '' for i in range(0, len(residues)): res_name = residues[i] cmd.load(os.path.join(path, 'db_glycans', '%s.pdb' % res_name)) cmd.set_name(res_name, i) #rename object (necessary to avoid repeating names) cmd.alter(i, 'resi = %s' % i) #name residues for further referencing cmd.sort(i) for i in range(0, len(bonds)): resi_i, resi_j, atom_i, atom_j = bonds[i][0], bonds[i][2], bonds[i][ 4], bonds[i][5] if atom_i > atom_j: cmd.remove('%s (resi %s and name O%s+H%so)' % (sel, resi_j, atom_j, atom_j)) cmd.remove('%s (resi %s and name H%so)' % (sel, resi_i, atom_i)) cmd.fuse('%s (resi %s and name O%s)' % (sel, resi_i, atom_i), '%s (resi %s and name C%s)' % (sel, resi_j, atom_j), mode=2) else: cmd.remove('%s (resi %s and name O%s+H%so)' % (sel, resi_i, atom_i, atom_i)) cmd.remove('%s (resi %s and name H%so)' % (sel, resi_j, atom_j)) cmd.fuse('%s (resi %s and name C%s)' % (sel, resi_i, atom_i), '%s (resi %s and name O%s)' % (sel, resi_j, atom_j), mode=2) cmd.delete('%s' % i) cmd.copy(mol_name, '%s' % resi_j) cmd.delete('%s' % resi_j) for i in range(0, len(bonds)): set_phi(mol_name, bonds[i], -60) set_psi(mol_name, bonds[i], 120) cmd.delete('pk1') cmd.delete('pk2') cmd.delete('pkbond') cmd.delete('pkmol') if babel: fast_min(mol_name, 5000) minimize(mol_name) else: fast_min(mol_name, 5000) cmd.feedback('enable', 'executive', 'actions') cmd.set('suspend_updates', 'off')
def apply(self): ''' Permanently applies the mutation upon the selected residue Overrides method from Wizard class ''' cmd = self.cmd if self._status == Status.NO_SELECTION: return #Remove all atoms that are not in the sugar/phosphate group #Needed for non-canonical bases cmd.select("_tmp_sele_invert", "(none)") for a in self._sugar_phos_atoms: cmd.select("_tmp_sele_invert", "_tmp_sele_invert | (%s & name %s)" % (SRC_SELE, a)) cmd.select("_tmp_sele_invert", "%s and not _tmp_sele_invert" % SRC_SELE) cmd.remove("_tmp_sele_invert") try: new_name = cmd.get_object_list(SRC_SELE)[0] except IndexError: print(" Mutagenesis: object not found.") return frag_name_three = self._mode_labels[self.mode] frag_name_one = self._base3_to_1[frag_name_three.lower()] # FUSE cmd.fuse( "%s & name %s" % (FRAG_NAME, self._frag_N_atom_name), "/%s/%s/%s/%s & name %s" % (new_name, self._stored.identifiers[0], self._stored.identifiers[1], self._stored.identifiers[2], self._src_Cp_atom_name), 1) #Check to see if DNA dnaPrefix = '' if cmd.count_atoms("%s & name O2'" % SRC_SELE) == 0: dnaPrefix = 'D' cmd.alter( "/%s/%s/%s/%s" % (new_name, self._stored.identifiers[0], self._stored.identifiers[1], self._stored.identifiers[2]), "(resn) = '%s%s'" % (dnaPrefix, frag_name_one.upper()), space=self._space) cmd.unpick() self.clear()
def builder(residues, bonds, mol_name): """Using the list generated by read_input connects monosacharides in a single oligosaccharide""" cmd.set('suspend_updates', 'on') cmd.feedback('disable', 'executive', 'actions') every_object = cmd.get_object_list('all') if mol_name in every_object: cmd.delete(mol_name) every_object.remove(mol_name) if every_object: sel = 'not (' + ' or '.join(every_object) + ') and' else: sel = '' for i in range(0, len(residues)): res_name = residues[i] cmd.load(os.path.join(path, 'db_glycans', '%s.pdb' % res_name)) cmd.set_name(res_name, i) #rename object (necessary to avoid repeating names) cmd.alter(i, 'resi = %s' % i) #name residues for further referencing cmd.sort(i) for i in range(0, len(bonds)): resi_i, resi_j, atom_i, atom_j = bonds[i][0], bonds[i][2], bonds[i][4], bonds[i][5] if atom_i > atom_j: cmd.remove('%s (resi %s and name O%s+H%so)' % (sel, resi_j, atom_j, atom_j)) cmd.remove('%s (resi %s and name H%so)' % (sel, resi_i, atom_i)) cmd.fuse('%s (resi %s and name O%s)' % (sel, resi_i, atom_i), '%s (resi %s and name C%s)' % (sel, resi_j, atom_j), mode=2) else: cmd.remove('%s (resi %s and name O%s+H%so)' % (sel, resi_i, atom_i, atom_i)) cmd.remove('%s (resi %s and name H%so)' % (sel, resi_j, atom_j)) cmd.fuse('%s (resi %s and name C%s)' % (sel, resi_i, atom_i), '%s (resi %s and name O%s)' % (sel, resi_j, atom_j), mode=2) cmd.delete('%s' % i) cmd.copy(mol_name, '%s' % resi_j) cmd.delete('%s' % resi_j) for i in range(0, len(bonds)): set_phi(mol_name, bonds[i], -60) set_psi(mol_name, bonds[i], 120) cmd.delete('pk1') cmd.delete('pk2') cmd.delete('pkbond') cmd.delete('pkmol') if babel: fast_min(mol_name, 5000) minimize(mol_name) else: fast_min(mol_name, 5000) cmd.feedback('enable', 'executive', 'actions') cmd.set('suspend_updates', 'off')
def attach_amino_acid(selection,amino_acid,phi,psi): if not selection in cmd.get_names("selections"): if amino_acid in cmd.get_names("objects"): print " Error: an object with than name already exists" raise QuietException cmd.fragment(amino_acid) if cmd.get_setting_legacy("auto_remove_hydrogens"): cmd.remove("(hydro and %s)"%amino_acid) if cmd.count_atoms("((%s) and name c)"%amino_acid,quiet=1): cmd.edit("((%s) and name c)"%amino_acid) else: cmd.fragment(amino_acid,tmp_editor) if cmd.count_atoms("((%s) and elem n)"%selection,quiet=1): cmd.select(tmp_ed_save,"(%s)"%selection) cmd.iterate("(%s)"%selection,"stored.resv=resv") stored.resi = str(stored.resv-1) cmd.alter(tmp_editor,"resi=stored.resi") cmd.fuse("(%s and name C)"%(tmp_editor),"(pk1)",2) if cmd.get_setting_legacy("auto_remove_hydrogens"): cmd.remove("(pkmol and hydro)") cmd.set_dihedral("(name ca and neighbor pk2)", "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0) cmd.set_geometry("pk2",3,3) # make nitrogen planer cmd.select(tpk1,"pk2") cmd.select(tpk2,"pk1") if amino_acid[0:3]!='pro': cmd.set_dihedral( # PHI "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C "(name ca and neighbor "+tpk1+")", # CA tpk1, # N tpk2, # C phi) cmd.set_dihedral( # PSI (n-1) tpk1, # N tpk2, # C "(name ca and neighbor "+tpk2+")", # CA "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C psi) cmd.delete(tpk1) cmd.delete(tpk2) sele = ("(name N and (byres neighbor %s) and not (byres %s))"% (tmp_ed_save,tmp_ed_save)) if cmd.count_atoms(sele,quiet=1): cmd.edit(sele) cmd.delete(tmp_ed_save) elif cmd.count_atoms("((%s) and elem c)"%selection,quiet=1): cmd.select(tmp_ed_save,"(%s)"%selection) cmd.iterate("(%s)"%selection,"stored.resv=resv") stored.resi = str(stored.resv+1) cmd.alter(tmp_editor,"resi=stored.resi") cmd.fuse("(%s and name N)"%(tmp_editor),"(pk1)",2) if cmd.get_setting_legacy("auto_remove_hydrogens"): cmd.remove("(pkmol and hydro)") cmd.set_dihedral("(name ca and neighbor pk2)", "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0) cmd.set_geometry("pk1",3,3) # make nitrogen planar cmd.select(tpk1,"pk1") cmd.select(tpk2,"pk2") if amino_acid[0:3]!='pro': cmd.set_dihedral( # PHI tpk2, # C tpk1, # N "(name ca and neighbor "+tpk1+")", # CA "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C phi) cmd.set_dihedral( # PSI (n-1) "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C "(name ca and neighbor "+tpk2+")", # CA tpk2, # C tpk1, # N psi) cmd.delete(tpk1) cmd.delete(tpk2) sele = ("(name C and (byres neighbor %s) and not (byres %s))"% (tmp_ed_save,tmp_ed_save)) if cmd.count_atoms(sele,quiet=1): cmd.edit(sele) cmd.delete(tmp_ed_save) elif cmd.count_atoms("((%s) and elem h)"%selection,quiet=1): print " Error: please pick a nitrogen or carbonyl carbon to grow from." cmd.delete(tmp_editor) raise QuietException cmd.delete(tmp_editor)
def add_missing_atoms(selection='all', cycles=200, quiet=1): ''' DESCRIPTION Mutate those residues to themselves which have missing atoms SEE ALSO stub2ala ''' from collections import defaultdict from chempy import fragments cycles, quiet = int(cycles), int(quiet) reference = { 'ALA': set(['CB']), 'ARG': set(['CB', 'CG', 'NE', 'CZ', 'NH1', 'NH2', 'CD']), 'ASN': set(['CB', 'CG', 'OD1', 'ND2']), 'ASP': set(['CB', 'CG', 'OD1', 'OD2']), 'CYS': set(['CB', 'SG']), 'GLN': set(['CB', 'CG', 'CD', 'NE2', 'OE1']), 'GLU': set(['CB', 'CG', 'OE2', 'CD', 'OE1']), 'GLY': set([]), 'HIS': set(['CE1', 'CB', 'CG', 'CD2', 'ND1', 'NE2']), 'ILE': set(['CB', 'CD1', 'CG1', 'CG2']), 'LEU': set(['CB', 'CG', 'CD1', 'CD2']), 'LYS': set(['CB', 'CG', 'NZ', 'CE', 'CD']), 'MET': set(['CB', 'CG', 'CE', 'SD']), 'PHE': set(['CE1', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']), 'PRO': set(['CB', 'CG', 'CD']), 'SER': set(['OG', 'CB']), 'THR': set(['CB', 'OG1', 'CG2']), 'TRP': set(['CZ2', 'CB', 'CG', 'CH2', 'CE3', 'CD1', 'CD2', 'CZ3', 'NE1', 'CE2']), 'TYR': set(['CE1', 'OH', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']), 'VAL': set(['CB', 'CG1', 'CG2']), } namedsele = cmd.get_unused_name('_') cmd.select(namedsele, selection, 0) namelists = defaultdict(list) cmd.iterate('(%s) and polymer' % namedsele, 'namelists[model,segi,chain,resn,resi,resv].append(name)', space=locals()) sele_dict = defaultdict(list) tmp_name = cmd.get_unused_name('_') for key, namelist in namelists.items(): resn = key[3] if resn not in reference: if not quiet: print(' Unknown residue: + ' + resn) continue if not reference[resn].issubset(namelist): try: frag = fragments.get(resn.lower()) for a in frag.atom: a.segi = key[1] a.chain = key[2] a.resi = key[4] a.resi_number = key[5] cmd.load_model(frag, tmp_name, 1, zoom=0) skey = '/%s/%s/%s/%s`%s' % key[:5] cmd.remove(skey + ' and not name N+C+O+OXT+CA') cmd.align(tmp_name, skey + ' and name N+C+CA', cycles=0) cmd.remove(tmp_name + ' and (name N+C+O+CA or hydro)') cmd.fuse('name CB and ' + tmp_name, 'name CA and ' + skey, move=0) if resn == 'PRO': cmd.bond(skey + '/N', skey + '/CD') cmd.unpick() cmd.delete(tmp_name) sele_dict[key[0]].append(skey) if not quiet: print(' Mutated ' + skey) except: print(' Mutating ' + skey + ' failed') for model in sele_dict: cmd.sort(model) sculpt_relax(' '.join(sele_dict[model]), 0, 0, model, cycles) cmd.delete(namedsele)
def add_missing_atoms(selection='all', cycles=200, quiet=1): ''' DESCRIPTION Mutate those residues to themselves which have missing atoms SEE ALSO stub2ala ''' from collections import defaultdict from chempy import fragments cycles, quiet = int(cycles), int(quiet) reference = { 'ALA': set(['CB']), 'ARG': set(['CB', 'CG', 'NE', 'CZ', 'NH1', 'NH2', 'CD']), 'ASN': set(['CB', 'CG', 'OD1', 'ND2']), 'ASP': set(['CB', 'CG', 'OD1', 'OD2']), 'CYS': set(['CB', 'SG']), 'GLN': set(['CB', 'CG', 'CD', 'NE2', 'OE1']), 'GLU': set(['CB', 'CG', 'OE2', 'CD', 'OE1']), 'GLY': set([]), 'HIS': set(['CE1', 'CB', 'CG', 'CD2', 'ND1', 'NE2']), 'ILE': set(['CB', 'CD1', 'CG1', 'CG2']), 'LEU': set(['CB', 'CG', 'CD1', 'CD2']), 'LYS': set(['CB', 'CG', 'NZ', 'CE', 'CD']), 'MET': set(['CB', 'CG', 'CE', 'SD']), 'PHE': set(['CE1', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']), 'PRO': set(['CB', 'CG', 'CD']), 'SER': set(['OG', 'CB']), 'THR': set(['CB', 'OG1', 'CG2']), 'TRP': set(['CZ2', 'CB', 'CG', 'CH2', 'CE3', 'CD1', 'CD2', 'CZ3', 'NE1', 'CE2']), 'TYR': set(['CE1', 'OH', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']), 'VAL': set(['CB', 'CG1', 'CG2']), } namedsele = cmd.get_unused_name('_') cmd.select(namedsele, selection, 0) namelists = defaultdict(list) cmd.iterate('(%s) and polymer' % namedsele, 'namelists[model,segi,chain,resn,resi,resv].append(name)', space=locals()) sele_dict = defaultdict(list) tmp_name = cmd.get_unused_name('_') for key, namelist in namelists.items(): resn = key[3] if resn not in reference: if not quiet: print(' Unknown residue:', resn) continue if not reference[resn].issubset(namelist): try: frag = fragments.get(resn.lower()) for a in frag.atom: a.segi = key[1] a.chain = key[2] a.resi = key[4] a.resi_number = key[5] cmd.load_model(frag, tmp_name, 1, zoom=0) skey = '/%s/%s/%s/%s`%s' % key[:5] cmd.remove(skey + ' and not name N+C+O+OXT+CA') cmd.align(tmp_name, skey + ' and name N+C+CA', cycles=0) cmd.remove(tmp_name + ' and (name N+C+O+CA or hydro)') cmd.fuse('name CB and ' + tmp_name, 'name CA and ' + skey, move=0) if resn == 'PRO': cmd.bond(skey + '/N', skey + '/CD') cmd.unpick() cmd.delete(tmp_name) sele_dict[key[0]].append(skey) if not quiet: print(' Mutated ', skey) except: print(' Mutating', skey, 'failed') for model in sele_dict: cmd.sort(model) sculpt_relax(' '.join(sele_dict[model]), 0, 0, model, cycles) cmd.delete(namedsele)
def test_fuse(self): cmd.fragment('ala') cmd.fragment('gly') cmd.fuse("gly and elem N", "ala and elem O") self.assertEqual(17, cmd.count_atoms('ala'))
def attach_amino_acid(selection,amino_acid,phi,psi): if not selection in cmd.get_names("selections"): if amino_acid in cmd.get_names("objects"): print " Error: an object with than name already exists" raise QuietException cmd.fragment(amino_acid) if cmd.get_setting_legacy("auto_remove_hydrogens"): cmd.remove("(hydro and %s)"%amino_acid) if cmd.count_atoms("((%s) and name c)"%amino_acid,quiet=1): cmd.edit("((%s) and name c)"%amino_acid) else: cmd.fragment(amino_acid,tmp_editor) if cmd.count_atoms("((%s) and elem n)"%selection,quiet=1): cmd.select(tmp_ed_save,"(%s)"%selection) cmd.iterate("(%s)"%selection,"stored.resv=resv") stored.resi = str(stored.resv-1) cmd.alter(tmp_editor,"resi=stored.resi") cmd.fuse("(%s and name C)"%(tmp_editor),"(pk1)",2) if cmd.get_setting_legacy("auto_remove_hydrogens"): cmd.remove("(pkmol and hydro)") cmd.set_dihedral("(name ca and neighbor pk2)", "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0) cmd.set_geometry("pk2",3,3) # make nitrogen planer # if ss: cmd.select(tpk1,"pk2") cmd.select(tpk2,"pk1") if amino_acid[0:3]!='pro': cmd.set_dihedral( # PHI "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C "(name ca and neighbor "+tpk1+")", # CA tpk1, # N tpk2, # C phi) cmd.set_dihedral( # PSI (n-1) tpk1, # N tpk2, # C "(name ca and neighbor "+tpk2+")", # CA "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C psi) cmd.delete(tpk1) cmd.delete(tpk2) sele = ("(name N and (byres neighbor %s) and not (byres %s))"% (tmp_ed_save,tmp_ed_save)) if cmd.count_atoms(sele,quiet=1): cmd.edit(sele) cmd.delete(tmp_ed_save) elif cmd.count_atoms("((%s) and elem c)"%selection,quiet=1): cmd.select(tmp_ed_save,"(%s)"%selection) cmd.iterate("(%s)"%selection,"stored.resv=resv") stored.resi = str(stored.resv+1) cmd.alter(tmp_editor,"resi=stored.resi") cmd.fuse("(%s and name N)"%(tmp_editor),"(pk1)",2) if cmd.get_setting_legacy("auto_remove_hydrogens"): cmd.remove("(pkmol and hydro)") cmd.set_dihedral("(name ca and neighbor pk2)", "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0) cmd.set_geometry("pk1",3,3) # make nitrogen planer # if ss: cmd.select(tpk1,"pk1") cmd.select(tpk2,"pk2") if amino_acid[0:3]!='pro': cmd.set_dihedral( # PHI tpk2, # C tpk1, # N "(name ca and neighbor "+tpk1+")", # CA "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C phi) cmd.set_dihedral( # PSI (n-1) "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C "(name ca and neighbor "+tpk2+")", # CA tpk2, # C tpk1, # N psi) cmd.delete(tpk1) cmd.delete(tpk2) sele = ("(name C and (byres neighbor %s) and not (byres %s))"% (tmp_ed_save,tmp_ed_save)) if cmd.count_atoms(sele,quiet=1): cmd.edit(sele) cmd.delete(tmp_ed_save) elif cmd.count_atoms("((%s) and elem h)"%selection,quiet=1): print " Error: please pick a nitrogen or carbonyl carbon to grow from." cmd.delete(tmp_editor) raise QuietException cmd.delete(tmp_editor)
ligand_name = file.split('_')[0] loaded_ligs.append(ligand_name) cmd.load('ligs/' + file, ligand_name) #select the ligand atomes of the original ligand to align with target_atom1 = 'RA95_target and name C3' target_atom2 = 'RA95_target and name C4' target_atom3 = 'RA95_target and name C5' #select the ligand atomes of the new ligand to align with and align the selected atoms of old and new ligand for ligand in loaded_ligs: mobile_atom1 = ligand + ' and name CL1' mobile_atom2 = ligand + ' and name CL' mobile_atom3 = ligand + ' and name CL2' cmd.pair_fit(mobile_atom1, target_atom1, mobile_atom2, target_atom2, mobile_atom3, target_atom3) #remove old ligand cmd.remove('RA95_target and resn PEN') #build bond between Lys83 and the new ligand and generate pdb file for ligand in loaded_ligs: cmd.copy('RA95_' + ligand, 'RA95_target') cmd.fuse(ligand + ' and name CL', 'RA95_' + ligand + ' and resn LYX and name NZ', '3') cmd.bond('RA95_' + ligand + ' and resn LYX and name NZ', 'RA95_' + ligand + ' and name CL') cmd.alter('RA95_' + ligand + ' and resn ' + ligand, 'segi="B"') cmd.sort('RA95_' + ligand) cmd.save('RA95_' + ligand + '.pdb', 'RA95_' + ligand, '0')