def process_molecule_mae(file_header, mol, suspend_undo): global already_processed global undo_each_molecule tot = [] tot.extend(file_header) tot.extend(mol) molstr = string.join(tot,'') nameorig, mdl = read_mae_model(molstr) name = nameorig.strip() if name in already_processed: return True already_processed = set(already_processed | set([name])) tmpname = "_temp_%s" % name cmd.delete(tmpname) try: cmd.load_model(mdl, tmpname) natoms = cmd.count_atoms(tmpname) except: return False if undo_each_molecule: cmd.push_undo( "( %s )" % name, just_coordinates=0) cmd.set("suspend_undo", 1, updates=0) cmd.remove(name) cmd.create(name, tmpname, copy_properties=True) cmd.set_title(name, -1, "") cmd.delete(tmpname) if undo_each_molecule: cmd.set("suspend_undo", suspend_undo, updates=0) cmd.push_undo("", just_coordinates=0, finish_undo=1) return True
def process_molecule_sdf(mol, suspend_undo): global already_processed global undo_each_molecule nameorig = mol[0] name = nameorig.strip() if name in already_processed: return True already_processed = set(already_processed | set([name])) tmpname = "_temp_%s" % name molstr = string.join(mol,'') cmd.delete(tmpname) try: importing.read_sdfstr(molstr, tmpname,object_props='*') natoms = cmd.count_atoms(tmpname) except: return False if undo_each_molecule: cmd.push_undo( "( %s )" % name, just_coordinates=0) cmd.set("suspend_undo", 1, updates=0) cmd.remove(name) print "before cmd.create(): using copy_properties=True" cmd.create(name, tmpname, copy_properties=True) cmd.set_title(name, -1, "") cmd.delete(tmpname) if undo_each_molecule: cmd.set("suspend_undo", suspend_undo, updates=0) cmd.push_undo("", just_coordinates=0, finish_undo=1) return True
def deepshifts_load(index, objname=None, host='localhost', port=7000, atom_props=None): ''' deepshifts_load(index, objname=None, host='localhost', port=7000) ''' # get data req = requests.get('http://{}:{}/index/{}?fmt=proteindatabank'.format( host, port, index)) data = req.json() # load object if objname is None: objname = 'obj-' + str(index) cmd.read_pdbstr(data['request'], objname) cmd.set_title(objname, 1, data['energy'][0]) # load properties if atom_props is None: atom_props = '' props = {p: data[p] for p in atom_props.split() if p in data} for prop, values in props.iteritems(): #for n,value in enumerate(values): # selection = 'id %d in %s'%(n, objname) # cmd.set_atom_property(prop, value, selection) cmd.iterate(objname, 'p["{}"]=l.pop(0)'.format(prop), space={'l': values}) pprint.pprint(data)
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file,'pdb') cmd.set_title('pdb',1,os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.show_as("ribbon") cmd.refresh() cmd.show_as("sticks") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n>1: cmd.rewind() sys.__stderr__.write(file+"\n") sys.__stderr__.flush() for a in range(1,n+1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file, 'pdb') cmd.set_title('pdb', 1, os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.show_as("ribbon") cmd.refresh() cmd.show_as("sticks") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n > 1: cmd.rewind() sys.__stderr__.write(file + "\n") sys.__stderr__.flush() for a in range(1, n + 1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file,'pdb') cmd.set_title('pdb',1,os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.zoom('center',16) cmd.label("polymer and (name ca or elem P)","'//%s/%s/%s`%s/%s'%(segi,chain,resn,resi,name)") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n>1: cmd.rewind() sys.__stderr__.write(file+"\n") sys.__stderr__.flush() for a in range(1,n+1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def create_model(self, name=None): """Creates PyMOL object connected with current structure (adds entry to Registry)""" if name is None: name = self.derived_from.name + "_" + \ self.__class__.__name__[ :4].lower() + str(Registry.get_next_number()) Registry.add(self, name, 0, structure_flag=True) cmd.read_pdbstr(self.create_pdbstring(enumerate_atoms=True, transformed=True).read(), name, state=1) # pylint: disable=protected-access cmd.set_title(name, 0, "PD")
def load(): global last1, last2 list = glob("pdb/*/*") list = map(lambda x: (random.random(), x), list) list.sort() list = map(lambda x: x[1], list) l = len(list) c = 0 for file in list: c = c + 1 try: cmd.set("suspend_updates", "1") cmd.delete('pdb') print file, last1, last2, c, "of", l last2 = last1 last1 = file cmd.load(file, 'pdb') cmd.set_title('pdb', 1, os.path.split(file)[-1]) cmd.rewind() # cmd.refresh() # cmd.hide() cmd.show('cartoon') cmd.color('auto', 'ss h') cmd.color('auto', 'ss s') cmd.orient('pdb') cmd.color('auto', 'organic and elem c') cmd.show('spheres', 'organic') cmd.move('z', -50.0) sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() finally: cmd.set("suspend_updates", "0") if cmd.count_atoms(): start = time.time() if n > 1: while (time.time() - start) < cycle_time: for a in range(1, n + 1): cmd.refresh() cmd.frame(a) cmd.move('z', 2) cmd.turn('y', 1) time.sleep(0.025) sys.__stderr__.write(" %d of %d" % (c, l)) sys.__stderr__.write("\n") sys.__stderr__.flush() else: cmd.refresh() while (time.time() - start) < cycle_time: for a in range(1, n + 1): time.sleep(0.05) cmd.move('z', 1.0) cmd.turn('y', 1)
def load(): global last1, last2 list = glob("pdb/*/*") list = map(lambda x: (random.random(), x), list) list.sort() list = map(lambda x: x[1], list) l = len(list) c = 0 for file in list: c = c + 1 try: cmd.set("suspend_updates", "1") cmd.delete("pdb") print file, last1, last2, c, "of", l last2 = last1 last1 = file cmd.load(file, "pdb") cmd.set_title("pdb", 1, os.path.split(file)[-1]) cmd.rewind() # cmd.refresh() # cmd.hide() cmd.show("cartoon") cmd.color("auto", "ss h") cmd.color("auto", "ss s") cmd.orient("pdb") cmd.color("auto", "organic and elem c") cmd.show("spheres", "organic") cmd.move("z", -50.0) sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() finally: cmd.set("suspend_updates", "0") if cmd.count_atoms(): start = time.time() if n > 1: while (time.time() - start) < cycle_time: for a in range(1, n + 1): cmd.refresh() cmd.frame(a) cmd.move("z", 2) cmd.turn("y", 1) time.sleep(0.025) sys.__stderr__.write(" %d of %d" % (c, l)) sys.__stderr__.write("\n") sys.__stderr__.flush() else: cmd.refresh() while (time.time() - start) < cycle_time: for a in range(1, n + 1): time.sleep(0.05) cmd.move("z", 1.0) cmd.turn("y", 1)
def testGetTitle(self): cmd.fragment('gly', 'm1') cmd.create('m1', 'm1', 1, 2) title = cmd.get_title('m1', 1) self.assertEqual(title, '') cmd.set_title('m1', 1, 'foo bar') title = cmd.get_title('m1', 1) self.assertEqual(title, 'foo bar') title = cmd.get_title('m1', 2) self.assertEqual(title, '') cmd.set_title('m1', 2, 'second state') title = cmd.get_title('m1', 2) self.assertEqual(title, 'second state')
def wrapped_load_structure(self, code, *args, **kwargs): """Wrapped load_structure method: loads structures from databases or from local copy of PDB file. Creates PyMOL objects and returns a list of PyDesc structures connected with those objects. Arguments: code -- str, pdb code; check PyDesc documentation for more information. """ list_of_structures = current_load_structure(self, code, *args, **kwargs) for structure_index, structure_obj in enumerate(list_of_structures): cmd.read_pdbstr(structure_obj.create_pdbstring(transformed=False).read(), structure_obj.name, state=structure_index + 1) # pylint: disable=protected-access Registry.add(structure_obj, structure_obj.name, structure_index + 1, structure_flag=True) cmd.set_title(structure_obj.name, structure_index + 1, "PD") return list_of_structures
def load(): cmd.set("valence") cmd.unset("auto_zoom") cmd.zoom("center",100) r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file,'pdb') cmd.set_title('pdb',1,os.path.split(file)[-1]) cmd.refresh() except: traceback.print_exc()
def show(self, point_name, color_segments=True): # pylint: disable=redefined-outer-name # color_segments is a patch-method, not a function, so it is not covered """Creates PyMOL visualisation of descriptor. Argiment: point_name -- name of the atom or pseudoatom to be joined with dashes in pymol. color_segments -- initially set to True, if so - calls descriptors method color_segments. """ # CREATING PYMOL OBJECTS for contact in self.contacts: try: obj_name = self.derived_from.name except AttributeError: obj_name = 'PyDesc_obj' central_name = "%s_%s_%i_cent" % (obj_name, point_name, self.central_element.central_monomer.ind) centers_name = "%s_%s_%i" % (obj_name, point_name, self.central_element.central_monomer.ind) distances_name = "%s_desc_%i_%s" % (obj_name, self.central_element.central_monomer.ind, point_name) cmd.pseudoatom(central_name, pos=list(getattr(self.central_element.central_monomer, point_name).get_coord(self.trt_matrix))) for i, element in enumerate(contact.elements): if element != self.central_element: try: cmd.pseudoatom(centers_name, pos=getattr(element.central_monomer, point_name).get_coord(self.trt_matrix)) except AttributeError: # for mers without proper attribute that are incorporated pass cmd.pseudoatom('temp_desc_dist%i' % i, pos=getattr(element.central_monomer, point_name).get_coord(self.trt_matrix)) cmd.distance(distances_name, 'temp_desc_dist0', 'temp_desc_dist1') cmd.delete('temp_desc_dist0') cmd.delete('temp_desc_dist1') cmd.hide("labels", distances_name) cmd.color("tv_orange", distances_name) # CREATING PYDESC OBJECTS for item in [central_name, centers_name]: item_structure = SupportingStructure(item, self.derived_from) Registry.add(item_structure, item) cmd.set_title(item, 0, "PD") temp_selection = self.select() temp_selection.select(self.derived_from, name="temporary__pydesc_selection") Registry.delete(temp_selection) cmd.orient("temporary__pydesc_selection") cmd.delete("temporary__pydesc_selection") if color_segments is True: self.color_segments()
def testGetModel(self): ''' Test coordinates and "reference" coordinates with various transformations. ''' # create two-state object # displace state 1, will do tests on state 2 cmd.fragment('ala', 'm1') cmd.create('m1', 'm1', 1, 2) cmd.translate([1, 2, 3], 'm1', 1) # prepare state 2 title = 'Alanin' cmd.set_title('m1', 2, title) cmd.reference(state=2) # with original coordinates m = cmd.get_model(state=2) a = m.atom[0] # title self.assertEqual(title, m.molecule.title) # bonds (covering count, indices and order) self.assertEqual( set(tuple(sorted(b.index)) + (b.order, ) for b in m.bond), set([(0, 1, 1), (0, 5, 1), (1, 2, 1), (1, 4, 1), (1, 6, 1), (2, 3, 2), (4, 7, 1), (4, 8, 1), (4, 9, 1)])) # expect equal coord and ref_coord coord = [-0.67689997, -1.23029995, -0.49050000] self.assertArrayEqual(a.ref_coord, coord, delta=1e-4) self.assertArrayEqual(a.coord, coord, delta=1e-4) # modify ttt cmd.set_object_ttt('m1', [ 0, 1, 0, 0, -1, 0, 0, 5, 0, 0, 1, 0, 0, 3, 0, 1, ]) # no state! API flaw, TTT object are not per state m = cmd.get_model('m1', state=2) a = m.atom[0] # ttt should affect both equally coord = [1.769700050354004, 5.6768999099731445, -0.49050000309944153] self.assertArrayEqual(a.ref_coord, coord, delta=1e-4) self.assertArrayEqual(a.coord, coord, delta=1e-4) # modify coords cmd.translate([10, 0, 0], state=2) m = cmd.get_model('m1', state=2) a = m.atom[0] # no effect of ref_coord ref = coord coord = [11.769700050354004, 5.6768999099731445, -0.49050000309944153] self.assertArrayEqual(a.ref_coord, ref, delta=1e-4) self.assertArrayEqual(a.coord, coord, delta=1e-4) # modify coords by alignment cmd.fragment('ala', 'm2') cmd.rotate('x', 90, 'm2') cmd.align('m1', 'm2', mobile_state=2) m = cmd.get_model('m1', state=2) a = m.atom[0] # no effect of ref_coord coord = [3.490499973297119, 5.6768999099731445, -1.230299949645996] self.assertArrayEqual(a.ref_coord, ref, delta=1e-4) self.assertArrayEqual(a.coord, coord, delta=1e-4)
def do_library(self): cmd = self.cmd pymol = cmd._pymol if not ( (cmd.count_atoms("(%s) and name n" % src_sele) == 1) and (cmd.count_atoms("(%s) and name c" % src_sele) == 1) and (cmd.count_atoms("(%s) and name o" % src_sele) == 1) ): self.clear() return 1 cmd.feedback("push") cmd.feedback("disable", "selector", "everythin") cmd.feedback("disable", "editor", "actions") self.prompt = ["Loading rotamers..."] pymol.stored.name = "residue" cmd.iterate("first (%s)" % src_sele, 'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi') self.res_text = pymol.stored.name cmd.select("_seeker_hilight", src_sele) auto_zoom = cmd.get_setting_text("auto_zoom") cmd.set("auto_zoom", "0", quiet=1) cmd.frame(0) cmd.delete(frag_name) if self.auto_center: cmd.center(src_sele, animate=-1) self.lib_mode = self.mode if self.lib_mode == "current": pymol.stored.resn = "" cmd.iterate("(%s and n;ca)" % src_sele, "stored.resn=resn") rot_type = _rot_type_xref.get(pymol.stored.resn, pymol.stored.resn) if (self.c_cap != "none") or (self.n_cap != "none") or (self.hyd != "auto"): self.lib_mode = rot_type # force fragment-based load else: cmd.create(frag_name, src_sele, 1, 1) if self.c_cap == "open": cmd.remove("%s and name OXT" % frag_name) if self.lib_mode != "current": rot_type = self.lib_mode frag_type = self.lib_mode if (self.n_cap == "posi") and (frag_type[0:3] != "NT_"): if not (cmd.count_atoms("elem c & !(%s) & (bto. (n;n & (%s))) &! r. ace" % (src_sele, src_sele))): # use N-terminal fragment frag_type = "NT_" + frag_type if (self.c_cap == "nega") and (frag_type[0:3] != "CT_"): if not (cmd.count_atoms("elem n & !(%s) & (bto. (n;c & (%s))) & !r. nme+nhh" % (src_sele, src_sele))): # use C-terminal fragment frag_type = "CT_" + frag_type if rot_type[0:3] in ["NT_", "CT_"]: rot_type = rot_type[3:] rot_type = _rot_type_xref.get(rot_type, rot_type) cmd.fragment(string.lower(frag_type), frag_name) # trim off hydrogens if self.hyd == "none": cmd.remove("(" + frag_name + " and hydro)") elif self.hyd == "auto": if cmd.count_atoms("(" + src_sele + ") and hydro") == 0: cmd.remove("(" + frag_name + " and hydro)") # copy identifying information cmd.iterate("(%s and n;ca)" % src_sele, "stored.chain=chain") cmd.alter("(%s)" % frag_name, "chain=stored.chain") cmd.iterate("(%s and n;ca)" % src_sele, "stored.resi=resi") cmd.alter("(%s)" % frag_name, "resi=stored.resi") cmd.iterate("(%s and n;ca)" % src_sele, "stored.segi=segi") cmd.alter("(%s)" % frag_name, "segi=stored.segi") cmd.iterate("(%s and n;ca)" % src_sele, "stored.ss=ss") cmd.alter("(%s)" % frag_name, "ss=stored.ss") # move the fragment if (cmd.count_atoms("(%s and n;cb)" % frag_name) == 1) and ( cmd.count_atoms("(%s and n;cb)" % src_sele) == 1 ): cmd.pair_fit( "(%s and n;ca)" % frag_name, "(%s and n;ca)" % src_sele, "(%s and n;cb)" % frag_name, "(%s and n;cb)" % src_sele, "(%s and n;c)" % frag_name, "(%s and n;c)" % src_sele, "(%s and n;n)" % frag_name, "(%s and n;n)" % src_sele, ) else: cmd.pair_fit( "(%s and n;ca)" % frag_name, "(%s and n;ca)" % src_sele, "(%s and n;c)" % frag_name, "(%s and n;c)" % src_sele, "(%s and n;n)" % frag_name, "(%s and n;n)" % src_sele, ) # fix the carbonyl position... cmd.iterate_state(1, "(%s and n;o)" % src_sele, "stored.list=[x,y,z]") cmd.alter_state(1, "(%s and n;o)" % frag_name, "(x,y,z)=stored.list") if cmd.count_atoms("(%s and n;oxt)" % src_sele): cmd.iterate_state(1, "(%s and n;oxt)" % src_sele, "stored.list=[x,y,z]") cmd.alter_state(1, "(%s and n;oxt)" % frag_name, "(x,y,z)=stored.list") elif cmd.count_atoms("(%s and n;oxt)" % frag_name): # place OXT if no template exists angle = cmd.get_dihedral( "(%s and n;n)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;c)" % frag_name, "(%s and n;o)" % frag_name, ) cmd.protect("(%s and n;o)" % frag_name) cmd.set_dihedral( "(%s and n;n)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;c)" % frag_name, "(%s and n;oxt)" % frag_name, 180.0 + angle, ) cmd.deprotect(frag_name) # fix the hydrogen position (if any) if cmd.count_atoms("(elem h and bound_to (n;n and (%s)))" % frag_name) == 1: if cmd.count_atoms("(elem h and bound_to (n;n and (%s)))" % src_sele) == 1: cmd.iterate_state(1, "(elem h and bound_to (n;n and (%s)))" % src_sele, "stored.list=[x,y,z]") cmd.alter_state(1, "(elem h and bound_to (n;n and (%s)))" % frag_name, "(x,y,z)=stored.list") elif cmd.select(tmp_sele1, "(n;c and bound_to (%s and e;n))" % src_sele) == 1: # position hydro based on location of the carbonyl angle = cmd.get_dihedral( "(%s and n;c)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;n)" % frag_name, tmp_sele1 ) cmd.set_dihedral( "(%s and n;c)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;n)" % frag_name, "(%s and n;h)" % frag_name, 180.0 + angle, ) cmd.delete(tmp_sele1) # add c-cap (if appropriate) if self.c_cap in ["amin", "nmet"]: if not cmd.count_atoms("elem n & !(%s) & (bto. (n;c & (%s))) & !r. nme+nhh" % (src_sele, src_sele)): if cmd.count_atoms("n;c & (%s)" % (frag_name)) == 1: if self.c_cap == "amin": editor.attach_amino_acid("n;c & (%s)" % (frag_name), "nhh") elif self.c_cap == "nmet": editor.attach_amino_acid("n;c & (%s)" % (frag_name), "nme") if cmd.count_atoms("hydro & bound_to (n;n & bound_to (n;c & (%s)))" % frag_name): cmd.h_fix("n;n & bound_to (n;c & (%s))" % frag_name) # trim hydrogens if self.hyd == "none": cmd.remove("(" + frag_name + " and hydro)") elif self.hyd == "auto": if cmd.count_atoms("(" + src_sele + ") and hydro") == 0: cmd.remove("(" + frag_name + " and hydro)") # add n-cap (if appropriate) if self.n_cap in ["acet"]: if not cmd.count_atoms("elem c & !(%s) & (bto. (n;n & (%s))) & !r. ace " % (src_sele, src_sele)): if cmd.count_atoms("n;n & (%s)" % (frag_name)) == 1: if self.n_cap == "acet": editor.attach_amino_acid("n;n & (%s)" % (frag_name), "ace") if cmd.count_atoms("hydro & bound_to (n;n & bound_to (n;c & (%s)))" % frag_name): cmd.h_fix("n;n & (%s)" % frag_name) # trim hydrogens if self.hyd == "none": cmd.remove("(" + frag_name + " and hydro)") elif self.hyd == "auto": if cmd.count_atoms("(" + src_sele + ") and hydro") == 0: cmd.remove("(" + frag_name + " and hydro)") cartoon = cmd.count_atoms("(%s and n;ca and rep cartoon)" % src_sele) > 0 sticks = cmd.count_atoms("(%s and n;ca and rep sticks)" % src_sele) > 0 cmd.delete(obj_name) key = rot_type lib = None if self.dep == "dep": try: result = cmd.phi_psi("%s" % src_sele) if len(result) == 1: (phi, psi) = result[result.keys()[0]] (phi, psi) = (int(10 * round(phi / 10)), int(10 * (round(psi / 10)))) key = (rot_type, phi, psi) if not self.dep_library.has_key(key): (phi, psi) = (int(20 * round(phi / 20)), int(20 * (round(psi / 20)))) key = (rot_type, phi, psi) if not self.dep_library.has_key(key): (phi, psi) = (int(60 * round(phi / 60)), int(60 * (round(psi / 60)))) key = (rot_type, phi, psi) lib = self.dep_library.get(key, None) except: pass if lib == None: key = rot_type lib = self.ind_library.get(key, None) if (lib != None) and self.dep == "dep": print " Mutagenesis: no phi/psi, using backbone-independent rotamers." if lib != None: state = 1 for a in lib: cmd.create(obj_name, frag_name, 1, state) if state == 1: cmd.select(mut_sele, "(byres (%s like %s))" % (obj_name, src_sele)) if rot_type == "PRO": cmd.unbond("(%s & name N)" % mut_sele, "(%s & name CD)" % mut_sele) for b in a.keys(): if b != "FREQ": cmd.set_dihedral( "(%s & n;%s)" % (mut_sele, b[0]), "(%s & n;%s)" % (mut_sele, b[1]), "(%s & n;%s)" % (mut_sele, b[2]), "(%s & n;%s)" % (mut_sele, b[3]), a[b], state=state, ) else: cmd.set_title(obj_name, state, "%1.1f%%" % (a[b] * 100)) if rot_type == "PRO": cmd.bond("(%s & name N)" % mut_sele, "(%s & name CD)" % mut_sele) state = state + 1 cmd.delete(frag_name) print " Mutagenesis: %d rotamers loaded." % len(lib) if self.bump_check: cmd.delete(bump_name) cmd.create( bump_name, "(((byobj %s) within 6 of (%s and not name n+c+ca+o+h+ha)) and (not (%s)))|(%s)" % (src_sele, mut_sele, src_sele, mut_sele), singletons=1, ) cmd.color("gray50", bump_name + " and elem c") cmd.set("seq_view", 0, bump_name, quiet=1) cmd.hide("everything", bump_name) if (cmd.select(tmp_sele1, "(n;N and (%s in (neighbor %s)))" % (bump_name, src_sele)) == 1) and ( cmd.select(tmp_sele2, "(n;C and (%s in %s))" % (bump_name, mut_sele)) == 1 ): cmd.bond(tmp_sele1, tmp_sele2) if (cmd.select(tmp_sele1, "(n;C and (%s in (neighbor %s)))" % (bump_name, src_sele)) == 1) and ( cmd.select(tmp_sele2, "(n;N and (%s in %s))" % (bump_name, mut_sele)) == 1 ): cmd.bond(tmp_sele1, tmp_sele2) cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.protect("%s and not (%s in (%s and not name n+c+ca+o+h+ha))" % (bump_name, bump_name, mut_sele)) cmd.sculpt_activate(bump_name) cmd.show("cgo", bump_name) # draw the bumps cmd.set("sculpt_vdw_vis_mode", 1, bump_name) state = 1 for a in lib: cmd.sculpt_iterate(bump_name, state=state) state = state + 1 cmd.delete(mut_sele) else: cmd.create(obj_name, frag_name, 1, 1) print " Mutagenesis: no rotamers found in library." cmd.set("seq_view", 0, obj_name, quiet=1) pymol.util.cbaw(obj_name) cmd.hide("(" + obj_name + ")") cmd.show(self.rep, obj_name) cmd.show("lines", obj_name) # neighbor always show lines if cartoon: cmd.show("cartoon", obj_name) if sticks: cmd.show("sticks", obj_name) cmd.set("auto_zoom", auto_zoom, quiet=1) cmd.delete(frag_name) cmd.frame(0) cmd.unpick() cmd.feedback("pop")
def apply(self): cmd = self.cmd pymol = cmd._pymol if self.status == 1: # find the name of the object which contains the selection new_name = None obj_list = cmd.get_names("objects") for a in obj_list: if cmd.get_type(a) == "object:molecule": if cmd.count_atoms("(%s and %s)" % (a, src_sele)): new_name = a break src_frame = cmd.get_state() if new_name == None: print " Mutagenesis: object not found." else: auto_zoom = cmd.get_setting_text("auto_zoom") cmd.set("auto_zoom", "0", quiet=1) if self.lib_mode != "current": # create copy w/o residue cmd.create(tmp_obj1, "(%s and not %s)" % (new_name, src_sele)) # remove existing c-cap in copy (if any) cmd.remove("byres (name N and (%s in (neighbor %s)) and resn nme,nhh)" % (tmp_obj1, src_sele)) # remove existing n-cap in copy (if any) cmd.remove("byres (name C and (%s in (neighbor %s)) and resn ace)" % (tmp_obj1, src_sele)) # save copy for bonded atom reference cmd.create(tmp_obj3, new_name) # transfer the selection to copy cmd.select(src_sele, "(%s in %s)" % (tmp_obj3, src_sele)) # create copy with mutant in correct frame cmd.create(tmp_obj2, obj_name, src_frame, 1) cmd.set_title(tmp_obj2, 1, "") cmd.delete(new_name) # create the merged molecule cmd.create(new_name, "(%s or %s)" % (tmp_obj1, tmp_obj2), 1) # only one state in merged object... # now connect them cmd.select(mut_sele, "(byres (%s like %s))" % (new_name, src_sele)) # bond N+0 to C-1 if (cmd.select(tmp_sele1, "(name C and (%s in (neighbor %s)))" % (new_name, src_sele)) == 1) and ( cmd.select(tmp_sele2, "((%s in %s) and n;N)" % (mut_sele, tmp_obj2)) == 1 ): cmd.bond(tmp_sele1, tmp_sele2) cmd.set_geometry(tmp_sele1, 3, 3) # make amide planer cmd.set_geometry(tmp_sele2, 3, 3) # make amide planer # bond C+0 to N+1 if (cmd.select(tmp_sele1, "(name N and (%s in (neighbor %s)))" % (new_name, src_sele)) == 1) and ( cmd.select(tmp_sele2, "((%s in %s) and n;C)" % (mut_sele, tmp_obj2)) == 1 ): cmd.bond(tmp_sele1, tmp_sele2) cmd.set_geometry(tmp_sele1, 3, 3) # make amide planer cmd.set_geometry(tmp_sele2, 3, 3) # make amide planer cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) # fix N-H hydrogen position (if any exists) cmd.h_fix("(name N and bound_to (%s in %s and n;H))" % (new_name, tmp_obj2)) # now transfer selection back to the modified object cmd.delete(tmp_obj1) cmd.delete(tmp_obj2) cmd.delete(tmp_obj3) self.clear() # and return to frame 1 cmd.frame(1) cmd.refresh_wizard() else: # create copy with conformation in correct state cmd.create(tmp_obj2, obj_name, src_frame, 1) # remove existing c-cap in copy (if any) cmd.remove("byres (name N and (%s in (neighbor %s)) and resn nme,nhh)" % (new_name, src_sele)) cmd.remove("(%s) and name OXT" % src_sele) # remove existing n-cap in copy (if any) cmd.remove("byres (name C and (%s in (neighbor %s)) and resn ace)" % (new_name, src_sele)) # save existing conformation on undo stack # cmd.edit("((%s in %s) and name ca)"%(new_name,src_sele)) cmd.push_undo("(" + src_sele + ")") # modify the conformation cmd.update(new_name, tmp_obj2) # cmd.unpick() cmd.delete(tmp_obj2) self.clear() # and return to frame 1 cmd.frame(1) cmd.refresh_wizard() cmd.set("auto_zoom", auto_zoom, quiet=1)
def symexpcell(prefix='mate', object=None, a=0, b=0, c=0): ''' DESCRIPTION Creates all symmetry-related objects for the specified object that occur with their bounding box center within the unit cell. USAGE symexpcell prefix, object, [a, b, c] ARGUMENTS prefix = string: prefix of new objects object = string: object for which to create symmetry mates a, b, c = integer: create neighboring cell {default: 0,0,0} SEE ALSO symexp ''' import numpy from pymol import xray if object is None: object = cmd.get_object_list()[0] sym = cmd.get_symmetry(object) cell_edges = sym[0:3] cell_angles = sym[3:6] spacegroup = sym[6] basis = cellbasis(cell_angles, cell_edges) basis = numpy.matrix(basis) extent = cmd.get_extent(object) center = sum(numpy.array(extent)) * 0.5 center = numpy.matrix(center.tolist() + [1.0]).T center_cell = basis.I * center spacegroup = xray.space_group_map.get(spacegroup, spacegroup) i = 0 matrices = xray.sg_sym_to_mat_list(spacegroup) for mat in matrices: i += 1 mat = numpy.matrix(mat) shift = -numpy.floor(numpy.array(mat * center_cell)[0:3, 0]) shift = shift.flatten().astype(int) shift += [a, b, c] mat[0:3, 3] += shift.reshape((3, 1)) mat = basis * mat * basis.I mat_list = list(mat.flat) name = '%s%d' % (prefix, i) cmd.create(name, object) cmd.transform_object(name, mat_list, 0) cmd.set_title(name, 1, "{}_{}{}{}".format(i, *(shift + 5).tolist())) if len(matrices) > 1: cmd.color(i + 1, name)
def do_library(self): cmd=self.cmd pymol=cmd._pymol if not ((cmd.count_atoms("(%s) and name N"%src_sele)==1) and (cmd.count_atoms("(%s) and name C"%src_sele)==1) and (cmd.count_atoms("(%s) and name O"%src_sele)==1)): self.clear() return 1 cmd.feedback("push") cmd.feedback("disable","selector","everythin") cmd.feedback("disable","editor","actions") self.prompt = [ 'Loading rotamers...'] self.bump_scores = [] state_best = 0 pymol.stored.name = 'residue' cmd.iterate("first (%s)"%src_sele,'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi') self.res_text = pymol.stored.name cmd.select("_seeker_hilight",src_sele) auto_zoom = cmd.get_setting_text('auto_zoom') cmd.set('auto_zoom',"0",quiet=1) cmd.frame(0) cmd.delete(frag_name) if self.auto_center: cmd.center(src_sele,animate=-1) self.lib_mode = self.mode if self.lib_mode=="current": pymol.stored.resn="" cmd.iterate("(%s & name CA)"%src_sele,"stored.resn=resn") rot_type = _rot_type_xref.get(pymol.stored.resn,pymol.stored.resn) if (self.c_cap!='none') or (self.n_cap!='none') or (self.hyd != 'auto'): self.lib_mode = rot_type # force fragment-based load else: cmd.create(frag_name,src_sele,1,1) if self.c_cap=='open': cmd.remove("%s and name OXT"%frag_name) if self.lib_mode!='current': rot_type = self.lib_mode frag_type = self.lib_mode if (self.n_cap == 'posi') and (frag_type[0:3]!='NT_'): if not ( cmd.count_atoms( "elem C & !(%s) & (bto. (name N & (%s))) &! resn ACE"% (src_sele,src_sele))): # use N-terminal fragment frag_type ="NT_"+frag_type if (self.c_cap == 'nega') and (frag_type[0:3]!='CT_'): if not ( cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele))): # use C-terminal fragment frag_type ="CT_"+frag_type if rot_type[0:3] in [ 'NT_', 'CT_' ]: rot_type = rot_type[3:] rot_type = _rot_type_xref.get(rot_type, rot_type) cmd.fragment(frag_type.lower(), frag_name, origin=0) # trim off hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # copy identifying information cmd.alter("?%s & name CA" % src_sele, "stored.identifiers = (segi, chain, resi, ss, color)", space=self.space) cmd.alter("?%s" % frag_name, "(segi, chain, resi, ss) = stored.identifiers[:4]", space=self.space) # move the fragment if ((cmd.count_atoms("(%s & name CB)"%frag_name)==1) and (cmd.count_atoms("(%s & name CB)"%src_sele)==1)): cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name CB)"%frag_name, "(%s & name CB)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) else: cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) # fix the carbonyl position... cmd.iterate_state(1,"(%s & name O)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name O)"%frag_name,"(x,y,z)=stored.list") if cmd.count_atoms("(%s & name OXT)"%src_sele): cmd.iterate_state(1,"(%s & name OXT)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name OXT)"%frag_name,"(x,y,z)=stored.list") elif cmd.count_atoms("(%s & name OXT)"%frag_name): # place OXT if no template exists angle = cmd.get_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name O)"%frag_name) cmd.protect("(%s & name O)"%frag_name) cmd.set_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name OXT)"%frag_name,180.0+angle) cmd.deprotect(frag_name) # fix the hydrogen position (if any) if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%frag_name)==1: if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%src_sele)==1: cmd.iterate_state(1,"(hydro and bound_to (name N & (%s)))"%src_sele, "stored.list=[x,y,z]") cmd.alter_state(1,"(hydro and bound_to (name N & (%s)))"%frag_name, "(x,y,z)=stored.list") elif cmd.select(tmp_sele1,"(name C & bound_to (%s and elem N))"%src_sele)==1: # position hydro based on location of the carbonyl angle = cmd.get_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, tmp_sele1) cmd.set_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, "(%s & name H)"%frag_name,180.0+angle) cmd.delete(tmp_sele1) # add c-cap (if appropriate) if self.c_cap in [ 'amin', 'nmet' ]: if not cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele)): if cmd.count_atoms("name C & (%s)"%(frag_name))==1: if self.c_cap == 'amin': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nhh') elif self.c_cap == 'nmet': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nme') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & bound_to (name C & (%s))"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # add n-cap (if appropriate) if self.n_cap in [ 'acet' ]: if not cmd.count_atoms("elem C & !(%s) & (bto. (name N & (%s))) & !resn ACE "% (src_sele,src_sele)): if cmd.count_atoms("name N & (%s)"%(frag_name))==1: if self.n_cap == 'acet': editor.attach_amino_acid("name N & (%s)"%(frag_name), 'ace') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & (%s)"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") cartoon = (cmd.count_atoms("(%s & name CA & rep cartoon)"%src_sele)>0) sticks = (cmd.count_atoms("(%s & name CA & rep sticks)"%src_sele)>0) cmd.delete(obj_name) key = rot_type lib = None if self.dep == 'dep': try: result = cmd.phi_psi("%s"%src_sele) if len(result)==1: (phi,psi) = list(result.values())[0] (phi,psi) = (int(10*round(phi/10)),int(10*(round(psi/10)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(20*round(phi/20)),int(20*(round(psi/20)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(60*round(phi/60)),int(60*(round(psi/60)))) key = (rot_type,phi,psi) lib = self.dep_library.get(key,None) except: pass if lib is None: key = rot_type lib = self.ind_library.get(key,None) if (lib is not None) and self.dep == 'dep': print(' Mutagenesis: no phi/psi, using backbone-independent rotamers.') if lib is not None: state = 1 for a in lib: cmd.create(obj_name,frag_name,1,state) if state == 1: cmd.select(mut_sele,"(byres (%s like %s))"%(obj_name,src_sele)) if rot_type=='PRO': cmd.unbond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) for b in a.keys(): if b!='FREQ': cmd.set_dihedral("(%s & n;%s)"%(mut_sele,b[0]), "(%s & n;%s)"%(mut_sele,b[1]), "(%s & n;%s)"%(mut_sele,b[2]), "(%s & n;%s)"%(mut_sele,b[3]), a[b],state=state) else: cmd.set_title(obj_name,state,"%1.1f%%"%(a[b]*100)) if rot_type=='PRO': cmd.bond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) state = state + 1 cmd.delete(frag_name) print(" Mutagenesis: %d rotamers loaded."%len(lib)) if self.bump_check: cmd.delete(bump_name) cmd.create(bump_name, "(((byobj %s) within 6 of (%s and not name N+C+CA+O+H+HA)) and (not (%s)))|(%s)"% (src_sele,mut_sele,src_sele,mut_sele),singletons=1) cmd.color("gray50",bump_name+" and elem C") cmd.set("seq_view",0,bump_name,quiet=1) cmd.hide("everything",bump_name) if ((cmd.select(tmp_sele1, "(name N & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2, "(name C & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) if ((cmd.select(tmp_sele1,"(name C & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2,"(name N & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.protect("%s and not (%s in (%s and not name N+C+CA+O+H+HA))"% (bump_name,bump_name,mut_sele)) cmd.sculpt_activate(bump_name) cmd.show("cgo",bump_name) # draw the bumps cmd.set("sculpt_vdw_vis_mode",1,bump_name) state = 1 score_best = 1e6 for a in lib: score = cmd.sculpt_iterate(bump_name, state, 1) self.bump_scores.append(score) if score < score_best: state_best = state score_best = score state = state + 1 cmd.delete(mut_sele) else: cmd.create(obj_name,frag_name,1,1) print(" Mutagenesis: no rotamers found in library.") cmd.set("seq_view",0,obj_name,quiet=1) pymol.util.cbaw(obj_name) cmd.hide("("+obj_name+")") cmd.show(self.rep,obj_name) cmd.show('lines',obj_name) #neighbor always show lines if cartoon: cmd.show("cartoon",obj_name) if sticks: cmd.show("sticks",obj_name) cmd.set('auto_zoom',auto_zoom,quiet=1) cmd.delete(frag_name) cmd.frame(state_best) cmd.unpick() cmd.feedback("pop")
def apply(self): cmd=self.cmd if self.status==1: # find the name of the object which contains the selection src_frame = cmd.get_state() try: new_name = cmd.get_object_list(src_sele)[0] except IndexError: print(" Mutagenesis: object not found.") return if True: auto_zoom = cmd.get_setting_text('auto_zoom') cmd.set('auto_zoom',"0",quiet=1) if self.lib_mode!="current": # create copy with mutant in correct frame state = cmd.get_object_state(new_name) cmd.create(tmp_obj2, obj_name, src_frame, state) cmd.set_title(tmp_obj2, state, '') cmd.color(self.stored.identifiers[4], "?%s & elem C" % tmp_obj2) cmd.alter(tmp_obj2, 'ID = -1') # select backbone connection atoms cmd.select(tmp_sele1, 'neighbor ?%s' % (src_sele), 0) # remove residue and neighboring c-cap/n-cap (if any) cmd.remove("?%s | byres (?%s & " "(name N & resn NME+NHH | name C & resn ACE))" % (src_sele, tmp_sele1)) # create the merged molecule cmd.create(new_name, "?%s | ?%s" % (new_name, tmp_obj2), state, state) # now connect them cmd.select(tmp_sele2, '/%s/%s/%s/%s' % ((new_name,) + self.stored.identifiers[:3])) cmd.bond('?%s & name C' % (tmp_sele1), '?%s & name N' % (tmp_sele2), quiet=1) cmd.bond('?%s & name N' % (tmp_sele1), '?%s & name C' % (tmp_sele2), quiet=1) cmd.set_geometry('(?%s | ?%s) & name C+N' % (tmp_sele1, tmp_sele2), 3, 3) # make amide planer # fix N-H hydrogen position (if any exists) cmd.h_fix('?%s & name N' % (tmp_sele2)) # delete temporary objects/selections cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.delete(tmp_obj2) self.clear() # and return to frame 1 cmd.frame(1) cmd.refresh_wizard() else: # create copy with conformation in correct state cmd.create(tmp_obj2,obj_name,src_frame,1) # remove existing c-cap in copy (if any) cmd.remove("byres (name N and (%s in (neighbor %s)) and resn NME+NHH)"% (new_name,src_sele)) cmd.remove("(%s) and name OXT"%src_sele) # remove existing n-cap in copy (if any) cmd.remove("byres (name C and (%s in (neighbor %s)) and resn ACE)"% (new_name,src_sele)) # save existing conformation on undo stack # cmd.edit("((%s in %s) and name ca)"%(new_name,src_sele)) cmd.push_undo("("+src_sele+")") # modify the conformation cmd.update(new_name,tmp_obj2) # cmd.unpick() cmd.delete(tmp_obj2) self.clear() # and return to frame 1 cmd.frame(1) cmd.refresh_wizard() cmd.set('auto_zoom',auto_zoom,quiet=1)
def test_set_title(self): text = 'foo' cmd.pseudoatom('m1') cmd.set_title('m1', 1, text) self.assertEqual(cmd.get_title('m1', 1), text)
def do_library(self): cmd=self.cmd pymol=cmd._pymol if not ((cmd.count_atoms("(%s) and name N"%src_sele)==1) and (cmd.count_atoms("(%s) and name C"%src_sele)==1) and (cmd.count_atoms("(%s) and name O"%src_sele)==1)): self.clear() return 1 cmd.feedback("push") cmd.feedback("disable","selector","everythin") cmd.feedback("disable","editor","actions") self.prompt = [ 'Loading rotamers...'] self.bump_scores = [] state_best = 0 pymol.stored.name = 'residue' cmd.iterate("first (%s)"%src_sele,'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi') self.res_text = pymol.stored.name cmd.select("_seeker_hilight",src_sele) auto_zoom = cmd.get_setting_text('auto_zoom') cmd.set('auto_zoom',"0",quiet=1) cmd.frame(0) cmd.delete(frag_name) if self.auto_center: cmd.center(src_sele,animate=-1) self.lib_mode = self.mode if self.lib_mode=="current": pymol.stored.resn="" cmd.iterate("(%s & name CA)"%src_sele,"stored.resn=resn") rot_type = _rot_type_xref.get(pymol.stored.resn,pymol.stored.resn) if (self.c_cap!='none') or (self.n_cap!='none') or (self.hyd != 'auto'): self.lib_mode = rot_type # force fragment-based load else: cmd.create(frag_name,src_sele,1,1) if self.c_cap=='open': cmd.remove("%s and name OXT"%frag_name) if self.lib_mode!='current': rot_type = self.lib_mode frag_type = self.lib_mode if (self.n_cap == 'posi') and (frag_type[0:3]!='NT_'): if not ( cmd.count_atoms( "elem C & !(%s) & (bto. (name N & (%s))) &! resn ACE"% (src_sele,src_sele))): # use N-terminal fragment frag_type ="NT_"+frag_type if (self.c_cap == 'nega') and (frag_type[0:3]!='CT_'): if not ( cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele))): # use C-terminal fragment frag_type ="CT_"+frag_type if rot_type[0:3] in [ 'NT_', 'CT_' ]: rot_type = rot_type[3:] rot_type = _rot_type_xref.get(rot_type, rot_type) cmd.fragment(frag_type.lower(), frag_name, origin=0) # trim off hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # copy identifying information cmd.alter("?%s & name CA" % src_sele, "stored.identifiers = (segi, chain, resi, ss, color)", space=self.space) cmd.alter("?%s" % frag_name, "(segi, chain, resi, ss) = stored.identifiers[:4]", space=self.space) # move the fragment if ((cmd.count_atoms("(%s & name CB)"%frag_name)==1) and (cmd.count_atoms("(%s & name CB)"%src_sele)==1)): cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name CB)"%frag_name, "(%s & name CB)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) else: cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) # fix the carbonyl position... cmd.iterate_state(1,"(%s & name O)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name O)"%frag_name,"(x,y,z)=stored.list") if cmd.count_atoms("(%s & name OXT)"%src_sele): cmd.iterate_state(1,"(%s & name OXT)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name OXT)"%frag_name,"(x,y,z)=stored.list") elif cmd.count_atoms("(%s & name OXT)"%frag_name): # place OXT if no template exists angle = cmd.get_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name O)"%frag_name) cmd.protect("(%s & name O)"%frag_name) cmd.set_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name OXT)"%frag_name,180.0+angle) cmd.deprotect(frag_name) # fix the hydrogen position (if any) if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%frag_name)==1: if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%src_sele)==1: cmd.iterate_state(1,"(hydro and bound_to (name N & (%s)))"%src_sele, "stored.list=[x,y,z]") cmd.alter_state(1,"(hydro and bound_to (name N & (%s)))"%frag_name, "(x,y,z)=stored.list") elif cmd.select(tmp_sele1,"(name C & bound_to (%s and elem N))"%src_sele)==1: # position hydro based on location of the carbonyl angle = cmd.get_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, tmp_sele1) cmd.set_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, "(%s & name H)"%frag_name,180.0+angle) cmd.delete(tmp_sele1) # add c-cap (if appropriate) if self.c_cap in [ 'amin', 'nmet' ]: if not cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele)): if cmd.count_atoms("name C & (%s)"%(frag_name))==1: if self.c_cap == 'amin': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nhh') elif self.c_cap == 'nmet': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nme') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & bound_to (name C & (%s))"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # add n-cap (if appropriate) if self.n_cap in [ 'acet' ]: if not cmd.count_atoms("elem C & !(%s) & (bto. (name N & (%s))) & !resn ACE "% (src_sele,src_sele)): if cmd.count_atoms("name N & (%s)"%(frag_name))==1: if self.n_cap == 'acet': editor.attach_amino_acid("name N & (%s)"%(frag_name), 'ace') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & (%s)"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") cartoon = (cmd.count_atoms("(%s & name CA & rep cartoon)"%src_sele)>0) sticks = (cmd.count_atoms("(%s & name CA & rep sticks)"%src_sele)>0) cmd.delete(obj_name) key = rot_type lib = None if self.dep == 'dep': try: result = cmd.phi_psi("%s"%src_sele) if len(result)==1: (phi,psi) = list(result.values())[0] (phi,psi) = (int(10*round(phi/10)),int(10*(round(psi/10)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(20*round(phi/20)),int(20*(round(psi/20)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(60*round(phi/60)),int(60*(round(psi/60)))) key = (rot_type,phi,psi) lib = self.dep_library.get(key,None) except: pass if lib == None: key = rot_type lib = self.ind_library.get(key,None) if (lib!= None) and self.dep == 'dep': print(' Mutagenesis: no phi/psi, using backbone-independent rotamers.') if lib != None: state = 1 for a in lib: cmd.create(obj_name,frag_name,1,state) if state == 1: cmd.select(mut_sele,"(byres (%s like %s))"%(obj_name,src_sele)) if rot_type=='PRO': cmd.unbond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) for b in a.keys(): if b!='FREQ': cmd.set_dihedral("(%s & n;%s)"%(mut_sele,b[0]), "(%s & n;%s)"%(mut_sele,b[1]), "(%s & n;%s)"%(mut_sele,b[2]), "(%s & n;%s)"%(mut_sele,b[3]), a[b],state=state) else: cmd.set_title(obj_name,state,"%1.1f%%"%(a[b]*100)) if rot_type=='PRO': cmd.bond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) state = state + 1 cmd.delete(frag_name) print(" Mutagenesis: %d rotamers loaded."%len(lib)) if self.bump_check: cmd.delete(bump_name) cmd.create(bump_name, "(((byobj %s) within 6 of (%s and not name N+C+CA+O+H+HA)) and (not (%s)))|(%s)"% (src_sele,mut_sele,src_sele,mut_sele),singletons=1) cmd.color("gray50",bump_name+" and elem C") cmd.set("seq_view",0,bump_name,quiet=1) cmd.hide("everything",bump_name) if ((cmd.select(tmp_sele1, "(name N & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2, "(name C & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) if ((cmd.select(tmp_sele1,"(name C & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2,"(name N & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.protect("%s and not (%s in (%s and not name N+C+CA+O+H+HA))"% (bump_name,bump_name,mut_sele)) cmd.sculpt_activate(bump_name) cmd.show("cgo",bump_name) # draw the bumps cmd.set("sculpt_vdw_vis_mode",1,bump_name) state = 1 score_best = 1e6 for a in lib: score = cmd.sculpt_iterate(bump_name, state, 1) self.bump_scores.append(score) if score < score_best: state_best = state score_best = score state = state + 1 cmd.delete(mut_sele) else: cmd.create(obj_name,frag_name,1,1) print(" Mutagenesis: no rotamers found in library.") cmd.set("seq_view",0,obj_name,quiet=1) pymol.util.cbaw(obj_name) cmd.hide("("+obj_name+")") cmd.show(self.rep,obj_name) cmd.show('lines',obj_name) #neighbor always show lines if cartoon: cmd.show("cartoon",obj_name) if sticks: cmd.show("sticks",obj_name) cmd.set('auto_zoom',auto_zoom,quiet=1) cmd.delete(frag_name) cmd.frame(state_best) cmd.unpick() cmd.feedback("pop")
def apply(self): cmd=self.cmd pymol=cmd._pymol if self.status==1: # find the name of the object which contains the selection new_name = None obj_list = cmd.get_names('objects') for a in obj_list: if cmd.get_type(a)=="object:molecule": if cmd.count_atoms("(%s and %s)"%(a,src_sele)): new_name = a break src_frame = cmd.get_state() if new_name==None: print " Mutagenesis: object not found." else: auto_zoom = cmd.get_setting_text('auto_zoom') cmd.set('auto_zoom',"0",quiet=1) if self.lib_mode!="current": # create copy w/o residue cmd.create(tmp_obj1,"(%s and not %s)"%(new_name,src_sele)) # remove existing c-cap in copy (if any) cmd.remove("byres (name N and (%s in (neighbor %s)) and resn nme,nhh)"% (tmp_obj1,src_sele)) # remove existing n-cap in copy (if any) cmd.remove("byres (name C and (%s in (neighbor %s)) and resn ace)"% (tmp_obj1,src_sele)) # save copy for bonded atom reference cmd.create(tmp_obj3,new_name) # transfer the selection to copy cmd.select(src_sele,"(%s in %s)"%(tmp_obj3,src_sele)) # create copy with mutant in correct frame cmd.create(tmp_obj2,obj_name,src_frame,1) cmd.set_title(tmp_obj2,1,'') cmd.delete(new_name) # create the merged molecule cmd.create(new_name,"(%s or %s)"%(tmp_obj1,tmp_obj2),1) # only one state in merged object... # now connect them cmd.select(mut_sele,"(byres (%s like %s))"%(new_name,src_sele)) # bond N+0 to C-1 if ((cmd.select(tmp_sele1, "(name C and (%s in (neighbor %s)))"% (new_name,src_sele)) == 1) and (cmd.select(tmp_sele2, "((%s in %s) and n;N)"% (mut_sele,tmp_obj2)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) cmd.set_geometry(tmp_sele1,3,3) # make amide planer cmd.set_geometry(tmp_sele2,3,3) # make amide planer # bond C+0 to N+1 if ((cmd.select(tmp_sele1, "(name N and (%s in (neighbor %s)))"% (new_name,src_sele)) == 1) and (cmd.select(tmp_sele2,"((%s in %s) and n;C)"% (mut_sele,tmp_obj2)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) cmd.set_geometry(tmp_sele1,3,3) # make amide planer cmd.set_geometry(tmp_sele2,3,3) # make amide planer cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) # fix N-H hydrogen position (if any exists) cmd.h_fix("(name N and bound_to (%s in %s and n;H))"%(new_name,tmp_obj2)) # now transfer selection back to the modified object cmd.delete(tmp_obj1) cmd.delete(tmp_obj2) cmd.delete(tmp_obj3) self.clear() # and return to frame 1 cmd.frame(1) cmd.refresh_wizard() else: # create copy with conformation in correct state cmd.create(tmp_obj2,obj_name,src_frame,1) # remove existing c-cap in copy (if any) cmd.remove("byres (name N and (%s in (neighbor %s)) and resn nme,nhh)"% (new_name,src_sele)) cmd.remove("(%s) and name OXT"%src_sele) # remove existing n-cap in copy (if any) cmd.remove("byres (name C and (%s in (neighbor %s)) and resn ace)"% (new_name,src_sele)) # save existing conformation on undo stack # cmd.edit("((%s in %s) and name ca)"%(new_name,src_sele)) cmd.push_undo("("+src_sele+")") # modify the conformation cmd.update(new_name,tmp_obj2) # cmd.unpick() cmd.delete(tmp_obj2) self.clear() # and return to frame 1 cmd.frame(1) cmd.refresh_wizard() cmd.set('auto_zoom',auto_zoom,quiet=1)