def abl(*files, **kwargs): MdsPymol.reset(options) if 'optionsFile' in kwargs: execfile(kwargs['optionsFile'], globals(), locals()) for file in files: print "Processing file '%s'." % file fileOptions = perMapOptions.get(file, {}) # Add a CGO prefix if we have multiple files and a prefix was not given. if len(files) > 1 and 'cgo prefix' not in fileOptions: basename, _ = os.path.splitext(os.path.basename(file)) fileOptions['cgo prefix'] = basename + '_' mapOptions = defaultMapOptions.copy() restrictedUpdate(mapOptions, fileOptions) ACmap(file, mapOptions) # Process global options. cmd.clip('far', -20.0) #cmd.clip('near', 100.0) if options['axes compute']: Axes(options) if options['base grid compute']: BaseGrid(options) if options['view']: cmd.set_view(options['view']) if options['ray']: cmd.ray() if options['png file']: cmd.png(options['png file']) if options['quit']: cmd.quit()
def carve(selection='(all)', cut_range="5", view_key=None): cut_range = cut_range.split(":") try: cut_range = [int(n) for n in cut_range] except ValueError as e: msg = f"Malformed range {cut_range}" e.message = msg raise e # First align to principal axes princ_align(selection) cachedir = Path.home() / "mjtadema_pymol_cache" if len(cut_range) == 1: # symmetrically cut with thickness t t = cut_range[0] cut_select = f"{selection} and (y > {-t} and y < {t})" cmd.orient(cut_select) cmd.clip('slab', t * 2, cut_select) if view_key is not None: cmd.view(view_key, 'store') elif len(cut_range) == 2: # cut from start to end raise NotImplementedError("Didn't get to asymmetric cuts yet") pass else: # panic raise ValueError("range can be at most 2 integers")
def set_initial_representations(self): """General settings for PyMOL""" self.standard_settings() cmd.set('dash_gap', 0) # Show not dashes, but lines for the pliprofiler cmd.set('ray_shadow', 0) # Turn on ray shadows for clearer ray-traced images cmd.set('cartoon_color', 'mylightblue') # Set clipping planes for full view cmd.clip('far', -1000) cmd.clip('near', 1000)
def z(): print "translate or rotate about the z axis" print "F1 = translate positive" print "F2 = translate negative" print "F3 = rotate positive" print "F4 = rotate negative" cmd.set_key('F1', cmd.translate, ("[0,0,1]", "protein")) cmd.set_key('F2', cmd.translate, ("[0,0,-1]", "protein")) cmd.set_key('F3', cmd.rotate, ('z', 1, "protein")) cmd.set_key('F4', cmd.rotate, ('z', -1, "protein")) cmd.clip("atoms", 5, "all") cmd.set("depth_cue", 0)
def focus(self): self.manager.m = self if self.manager.prevm: cmd.hide('sticks',self.manager.prevm.rdes.sel()) if self.manager.prevm: cmd.color('green',self.manager.prevm.rdes.sel()+" and elem C") fr = self.rnat.obj+" and name n+ca+c and resi %i-%i"%(self.rnat.resi-10,self.rnat.resi+10) to = self.rdes.obj+" and name n+ca+c and resi %i-%i"%(self.rdes.resi-10,self.rdes.resi+10) cmd.align(fr,to) cmd.show('sticks',self.rdes.sel()) cmd.color('white',self.rdes.sel()+" and elem C") cmd.center(self.rdes.sel()) v = list(cmd.get_view()) v[11] = -80.0 cmd.set_view(tuple(v)) cmd.clip('slab',50,self.rdes.sel())
def load_range(begin, end): begin = int(begin) begin = begin - 1 end = int(end) cmd.reinitialize() cmd.bg_color('grey50') getoutput('ls | grep \".pdb\" > pdb_list') pdb_list = open('pdb_list', 'r') pdb_list = fcn('pdb_list') getoutput('ls | grep \".pdb\" > pdb_list') pdb_list = open('pdb_list', 'r') pdb_list = fcn('pdb_list') for i in range(begin, end): cmd.load(pdb_list[i]) cmd.disable(pdb_list[i][:15]) preset.publication('all and not hetatm') cmd.show('spheres', 'hetatm') cmd.clip("atoms", 5, "all") cmd.set("depth_cue", 0)
def testClip(self): for a in "xyz": cmd.turn(a, random.random() * 10 - 5) cmd.move(a, random.random() * 10 - 5) v = cmd.get_view() cmd.clip("near", -5) self.assertAlmostEqual(v[15] + 5, cmd.get_view()[15], delta=1e-3) cmd.clip("far", 10) self.assertAlmostEqual(v[16] - 10, cmd.get_view()[16], delta=1e-3) cmd.clip("move", -15) a = cmd.get_view() self.assertAlmostEqual(v[15], a[15] - 20, delta=1e-3) self.assertAlmostEqual(v[16], a[16] - 5, delta=1e-3) cmd.clip("slab", 20) v = cmd.get_view() self.assertAlmostEqual(v[16] - v[15], 20.0, delta=1e-3) cmd.pseudoatom() cmd.clip("atoms", 5, "all") v = cmd.get_view() self.assertAlmostEqual(v[16] - v[15], 10.0, delta=1e-3)
def prepare_pymol(): cmd.clip("near", 100000) cmd.clip("slab", 100000) cmd.clip("far", -100000) cmd.show("spheres") cmd.unpick() util.cbc()
def reinitPymol(self, pdb): if len(self.pdb) == 4 and self.pdb == re.match('[a-zA-Z0-9]*', self.pdb).group(0): cmd.delete(self.pdb) if len(pdb) == 4 and pdb == re.match('[a-zA-Z0-9]*', pdb).group(0): self.pdb = pdb cmd.fetch(self.pdb, async=0) if self.editMolecule: cmd.hide('everything', 'all') cmd.show('cartoon', 'all') # color each chain differently if self.editMolecule: util.cbc() # set origin at camera if self.naturalRotation: self.setOriginAtCamera() # move slab away to give a comfortable viewing area cmd.clip('move', 10)
def initPymol(self): # set stereo mode cmd.set('stereo_mode', 3) cmd.stereo() # get rid of gui cmd.set('internal_gui', 0) # set resolution to HD for rift cmd.viewport(1920, 1080) # full screen? if self.fullscreen: cmd.full_screen('on') # load pdb if len(self.pdb) == 4 and self.pdb == re.match('[a-zA-Z0-9]*', self.pdb).group(0): cmd.fetch(self.pdb, async=0) if self.editMolecule == True: cmd.hide('everything', 'all') cmd.show('cartoon', 'all') # color each chain differently if self.editMolecule: util.cbc() # set origin at camera if self.naturalRotation: self.setOriginAtCamera() # move slab away to give a comfortable viewing area cmd.clip('move', 10) # jiggle the camera to deal with blank screen error cmd.move('z', .0001)
def prepare_pymol(): cmd.set("ray_trace_color", "black") cmd.set("ray_trace_gain", 0) cmd.set("ray_trace_mode", 3) cmd.set("depth_cue", 0) cmd.clip("near", 100000) cmd.clip("slab", 100000) cmd.clip("far", -100000) cmd.hide("all") util.cbc() cmd.show('surface') cmd.bg_color("black") cmd.zoom("all", buffer=2.0) # buffer might help clipping problem cmd.center("all") cmd.deselect()
def noclip(): print "noclip!" cmd.clip("near",100) cmd.clip("far",-100)
def read_moestr(contents, object, state=0, finish=1, discrete=1, quiet=1, zoom=-1, _self=cmd): moestr = contents name = object import sys if sys.version_info[0] > 2 and isinstance(moestr, bytes): moestr = moestr.decode() cmd = _self mr = MOEReader() mr.appendFromStr(moestr) split_chains = cmd.get_setting_int("moe_separate_chains") cmd.group(name) if hasattr(mr, 'system'): have_valences = 0 chain_count = 0 cmd.set_color("_aseg0", [1.0, 1.0, 1.0]) aseg_color = cmd.get_color_index("_aseg0") aseg_flag = 0 aseg_rep = {} model = Indexed() molecule = mr.system['molecule'] if 'atoms' in molecule: n_atom = molecule['atoms'] model.atom = [Atom() for x in range(n_atom)] residues = {} chains = {} for columns, data in molecule['attr']: for row in data: cur_atom = None for key, value in zip(columns, row): key = key[0] if key == 'ID': ID = value else: aProp = _atom_prop_map.get(key, None) if aProp != None: setattr(model.atom[ID - 1], aProp, value) else: xyz = _atom_coord_map.get(key, None) if xyz != None: coord = list(model.atom[ID - 1].coord) coord[xyz] = value model.atom[ID - 1].coord = coord elif key in _atom_vis_map: atom = model.atom[ID - 1] if hasattr(atom, 'visible'): visible = atom.visible else: visible = _default_visible if key == 'aBondLook': if value == 'cylinder': atom.visible = 0x00000001 | visible elif value == 'line': atom.visible = 0x00000080 | visible elif value == 'none': atom.visible = -129 & Visible # 0xFFFFFF7F elif key == 'aNucleusLook': if value == 'sphere': atom.visible = 0x00000002 | visible elif value == 'small-sphere': # need to set sphere_scale=0.2 for these atoms atom.visible = 0x00000002 | visible atom.sphere_scale = 0.2 elif value == 'point': # nonbonded atom.visible = 0x00000800 | visible elif value == 'none': atom.visible = -2067 & visible # 0xFFFFF7ED elif key == 'aHidden': atom.visible = 0 atom.hidden = 1 if hasattr( atom, 'hidden' ): # be sure that hidden atoms aren't shown atom.visible = 0 elif key in _atom_color_map: if key == 'aRGB': model.atom[ID - 1].trgb = value elif key == 'aColorBy': model.atom[ID - 1].aColorBy = value elif key in _atom_label_map: atom = model.atom[ID - 1] if hasattr(atom, 'label_dict'): atom.label_dict[key] = None else: atom.label_dict = {key: None} elif key in _residue_prop_map: resi_dict = residues.get(ID, {}) resi_dict[key] = value residues[ID] = resi_dict elif key in _chain_prop_map: chain_dict = chains.get(ID, {}) if ID not in chains: chain_count = chain_count + 1 chain_dict['count'] = chain_count chain_dict[key] = value chains[ID] = chain_dict chn_keys = list(chains.keys()) chn_keys.sort() res_keys = list(residues.keys()) res_keys.sort() # map chain properties onto residues chn_resi = 0 ch_colors = copy.deepcopy(_ch_colors) unique_chain_names = {} for chn_idx in chn_keys: chain_dict = chains[chn_idx] cName = make_valid_name(chain_dict.get('cName', '')) segi = cName[0:4] chain = cName[-1:] if not len(cName): if 'count' in chain_dict: cName = "chain_" + str(chain_dict['count']) else: cName = str(chn_idx) if cName not in unique_chain_names: unique_chain_names[cName] = cName else: cnt = 2 while (cName + "_" + str(cnt)) in unique_chain_names: cnt = cnt + 1 newCName = cName + "_" + str(cnt) unique_chain_names[newCName] = cName cName = newCName chain_dict['chain_color'] = ch_colors[0] ch_colors = ch_colors[1:] + [ch_colors[0]] cResCount = chain_dict.get('cResidueCount', 0) for res_idx in range(chn_resi, chn_resi + cResCount): resi_dict = residues[res_keys[res_idx]] resi_dict['chain'] = chain resi_dict['segi'] = segi resi_dict['cName'] = cName resi_dict['chain_dict'] = chain_dict chn_resi = chn_resi + cResCount # map residue properties onto atoms res_atom = 0 for res_idx in res_keys: resi_dict = residues[res_idx] rRibbonMode = resi_dict.get('rRibbonMode', 'none') rAtomCount = resi_dict['rAtomCount'] rType = resi_dict.get('rType', '') if rAtomCount > 0: for at_idx in range(res_atom, res_atom + rAtomCount): atom = model.atom[at_idx] setattr( atom, 'resi', string.strip( str(resi_dict.get('rUID', '')) + resi_dict.get('rINS', ''))) setattr(atom, 'resn', resi_dict.get('rName', '')) setattr(atom, 'chain', resi_dict.get('chain', '')) setattr(atom, 'segi', resi_dict.get('segi', '')) setattr(atom, 'custom', resi_dict.get('cName', '')) # add labels if hasattr(atom, 'label_dict'): label = '' label_dict = atom.label_dict if 'aLabelElement' in label_dict: label = atom.symbol if 'aLabelRes' in label_dict: if len(label): label = label + "," label = label + atom.resn + "_" + atom.resi if 'aLabelName' in label_dict: if len(label): label = label + "." label = label + atom.name atom.label = label if rType not in ['none', 'heme']: atom.hetatm = 0 # all normal atoms else: atom.flags = 0x02000000 # hetatom or ligand -- ignore when surfacing if rRibbonMode != 'none': if hasattr(atom, 'visible'): visible = atom.visible else: visible = _default_visible rRibbonColorBy = resi_dict['rRibbonColorBy'] repeat = 1 while repeat: repeat = 0 if rRibbonColorBy in ['rgb', 'r:rgb' ]: # handled automatically pass elif rRibbonColorBy == 'chain': chain_dict = resi_dict['chain_dict'] cColorBy = chain_dict['cColorBy'] if cColorBy == 'rgb': cColorBy = 'c:rgb' rRibbonColorBy = cColorBy repeat = 1 rRibbon_color = 0 rRibbon_trgb = 0xFFFFFF # default -- white # now color ribbon if rRibbonColorBy == 'r:rgb': rRibbon_trgb = resi_dict.get('rRGB', 0xFFFFFF) elif rRibbonColorBy == 'rgb': rRibbon_trgb = resi_dict.get( 'rRibbonRGB', 0xFFFFFF) elif rRibbonColorBy == 'c:rgb': chain_dict = resi_dict['chain_dict'] rRibbon_trgb = chain_dict.get('cRGB', 0xFFFFFF) elif rRibbonColorBy == 'r:aseg': rRibbon_trgb = None rRibbon_color = aseg_color aseg_flag = 1 elif rRibbonColorBy == 'tempfactor': pass # TO DO elif rRibbonColorBy == 'c:number': # per chain colors rRibbon_trgb = chain_dict['chain_color'] if rRibbonMode in ['line', 'trace']: atom.visible = 0x00000040 | visible # PyMOL ribbon if rRibbon_trgb != None: atom.ribbon_trgb = rRibbon_trgb else: atom.ribbon_color = rRibbon_color aseg_rep['ribbon'] = 1 else: atom.visible = 0x00000020 | visible # PyMOL cartoon if rRibbon_trgb != None: atom.cartoon_trgb = rRibbon_trgb else: atom.cartoon_color = rRibbon_color aseg_rep['cartoon'] = 1 if hasattr(atom, 'label'): if hasattr(atom, 'visible'): visible = atom.visible else: visible = _default_visible atom.visible = 0x00000028 | visible # labels if not hasattr(atom, 'aColorBy'): atom.aColorBy = 'element' if hasattr(atom, 'aColorBy'): aColorBy = atom.aColorBy repeat = 1 while repeat: repeat = 0 if aColorBy == 'ribbon': aColorBy = resi_dict.get('rRibbonColorBy') if aColorBy == 'rgb': aColorBy = 'rib:rgb' else: repeat = 1 # TO DO still need to handle "cartoon_color", "ribbon_color" elif aColorBy == 'element': if hasattr(atom, 'trgb'): del atom.trgb elif aColorBy in ['rgb', 'a:rgb' ]: # handled automatically pass elif aColorBy == 'residue': rColorBy = resi_dict.get('rColorBy') if rColorBy == 'rgb': rColorBy = 'r:rgb' aColorBy = rColorBy repeat = 1 elif aColorBy == 'chain': chain_dict = resi_dict['chain_dict'] cColorBy = chain_dict['cColorBy'] if cColorBy == 'rgb': cColorBy = 'c:rgb' aColorBy = cColorBy repeat = 1 # now color atom... if aColorBy == 'r:rgb': atom.trgb = resi_dict.get('rRGB', 0xFFFFFF) elif aColorBy == 'rib:rgb': atom.trgb = resi_dict.get('rRibbonRGB', 0xFFFFFF) elif aColorBy == 'c:rgb': chain_dict = resi_dict['chain_dict'] atom.trgb = chain_dict.get('cRGB', 0xFFFFFF) elif aColorBy == 'r:aseg': pass # TO DO elif aColorBy == 'tempfactor': pass # TO DO elif aColorBy == 'c:number': # per chain colors atom.trgb = chain_dict['chain_color'] res_atom = res_atom + rAtomCount bond_list = molecule.get('bond', []) for bond in bond_list: new_bond = Bond() new_bond.index = [bond[0] - 1, bond[1] - 1] if len(bond) > 2: new_bond.order = bond[2] if bond[2] == 2: # work around .MOE bug with triple bonds if model.atom[new_bond.index[0]].hybridization == 'sp': if model.atom[new_bond.index[1]].hybridization == 'sp': new_bond.order = 3 have_valences = 1 model.bond.append(new_bond) if 'ViewOrientationY' in mr.system: vy = mr.system['ViewOrientationY'] vz = mr.system['ViewOrientationZ'] pos = mr.system['ViewLookAt'] scale = mr.system['ViewScale'] vx = cpv.cross_product(vy, vz) m = [cpv.normalize(vx), cpv.normalize(vy), cpv.normalize(vz)] m = cpv.transpose(m) asp_rat = 0.8 # MOE default (versus 0.75 for PyMOL) cmd.set("field_of_view", 25.0) fov = float(cmd.get("field_of_view")) window_height = scale * asp_rat dist = (0.5 * window_height) / math.atan(3.1415 * (0.5 * fov) / 180.0) new_view = tuple(m[0] + m[1] + m[2] + [0.0, 0.0, -dist] + pos + [dist * 0.5, dist * 1.5, 0.0]) cmd.set_view(new_view) zoom = 0 cmd.set("auto_color", 0) cmd.set_color("carbon", [0.5, 0.5, 0.5]) # default MOE grey obj_name = name + ".system" if split_chains < 0: # by default, don't split chains if over 50 objects would be created if len(unique_chain_names) > 50: split_chains = 0 if not split_chains: cmd.load_model(model, obj_name, state=state, finish=finish, discrete=discrete, quiet=quiet, zoom=zoom) obj_name_list = [obj_name] else: cmd.load_model(model, obj_name, state=state, finish=finish, discrete=discrete, quiet=1, zoom=zoom) obj_name_list = [] system_name = obj_name for chain in unique_chain_names.keys(): obj_name = name + "." + chain obj_name_list.append(obj_name) cmd.select("_moe_ext_tmp", "custom %s" % chain, domain=system_name) cmd.extract(obj_name, "_moe_ext_tmp", quiet=quiet, zoom=0) # cmd.extract(obj_name,system_name+" and text_type %s"%chain,quiet=quiet) cmd.delete("_moe_ext_tmp") if not cmd.count_atoms(system_name): cmd.delete(system_name) else: obj_name_list.append(system_name) cmd.order(name + ".*", sort=1) for obj_name in obj_name_list: cmd.set("stick_radius", 0.1, obj_name) cmd.set("line_width", 2.0, obj_name) cmd.set("label_color", "white", obj_name) cmd.set("nonbonded_size", 0.05, obj_name) # temporary workaround... if have_valences: # if this MOE file has valences, then show em! cmd.set("valence", 1, obj_name) cmd.set("stick_valence_scale", 1.25, obj_name) if aseg_flag: cmd.dss(obj_name) if 'cartoon' in aseg_rep: cmd.set("cartoon_color", "red", obj_name + " and cartoon_color _aseg0 and ss h") cmd.set("cartoon_color", "yellow", obj_name + " and cartoon_color _aseg0 and ss s") cmd.set( "cartoon_color", "cyan", obj_name + " and cartoon_color _aseg0 and not ss h+s") if 'ribbon' in aseg_rep: cmd.set("ribbon_color", "red", obj_name + " and ribbon_color _aseg0 and ss h" ) # need selection op ribbon_color cmd.set("ribbon_color", "yellow", obj_name + " and ribbon_color _aseg0 and ss s") cmd.set( "ribbon_color", "cyan", obj_name + " and ribbon_color _aseg0 and not ss h+s") if 'ViewZFront' in mr.system: moe_front = mr.system['ViewZFront'] moe_width = mr.system['ViewZWidth'] extent = cmd.get_extent( name) # will this work with groups? TO DO: check! dx = (extent[0][0] - extent[1][0]) dy = (extent[0][1] - extent[1][1]) dz = (extent[0][2] - extent[1][2]) half_width = 0.5 * math.sqrt(dx * dx + dy * dy + dz * dz) cmd.clip("atoms", 0.0, name) cur_view = cmd.get_view() center = (cur_view[-3] + cur_view[-2]) * 0.5 # center of clipping slab front = center - half_width back = center + half_width width = half_width * 2 new_view = tuple( list(cur_view[0:15]) + [ front + width * moe_front, front + width * (moe_front + moe_width), 0.0 ]) cmd.set_view(new_view) if 'graphics' in mr.system: cgo_cnt = 1 lab_cnt = 1 unique_cgo_names = {} for graphics in mr.system['graphics']: cgo = [] for gvertex in graphics.get('gvertex', []): vrt = gvertex[0] seg_list = gvertex[1]['seg'] idx = gvertex[1]['idx'] len_idx = len(idx) if not cmd.is_list(seg_list): seg_list = [seg_list] * (len_idx / seg_list) last_seg = None ix_start = 0 for seg in seg_list: if seg != last_seg: if last_seg != None: cgo.append(END) if seg == 3: cgo.extend([BEGIN, TRIANGLES]) elif seg == 2: cgo.extend([BEGIN, LINES]) elif seg == 1: cgo.extend([BEGIN, POINTS]) ix_stop = seg + ix_start if seg == 3: for s in idx[ix_start:ix_stop]: v = vrt[s - 1] cgo.extend([ COLOR, (0xFF & (v[0] >> 16)) / 255.0, (0xFF & (v[0] >> 8)) / 255.0, (0xFF & (v[0])) / 255.0 ]) if len(v) > 4: cgo.extend([NORMAL, v[4], v[5], v[6]]) cgo.extend([VERTEX, v[1], v[2], v[3]]) elif seg == 2: for s in idx[ix_start:ix_stop]: v = vrt[s - 1] cgo.extend([ COLOR, (0xFF & (v[0] >> 16)) / 255.0, (0xFF & (v[0] >> 8)) / 255.0, (0xFF & (v[0])) / 255.0 ]) if len(v) > 4: cgo.extend([NORMAL, v[4], v[5], v[6]]) cgo.extend([VERTEX, v[1], v[2], v[3]]) elif seg == 1: for s in idx[ix_start:ix_stop]: v = vrt[s - 1] cgo.extend([ COLOR, (0xFF & (v[0] >> 16)) / 255.0, (0xFF & (v[0] >> 8)) / 255.0, (0xFF & (v[0])) / 255.0 ]) if len(v) > 4: cgo.extend([NORMAL, v[4], v[5], v[6]]) cgo.extend([VERTEX, v[1], v[2], v[3]]) ix_start = ix_stop last_seg = seg if last_seg != None: cgo.append(END) for gtext in graphics.get('gtext', []): lab_name = name + ".label_%02d" % lab_cnt exists = 0 for entry in gtext: exists = 1 cmd.pseudoatom(lab_name, pos=[ float(entry[1]), float(entry[2]), float(entry[3]) ], color="0x%06x" % entry[0], label=entry[4]) if exists: cmd.set('label_color', -1, lab_name) lab_cnt = lab_cnt + 1 # TO DO -- via CGO's? if len(cgo): cgo_name = name + "." + make_valid_name( graphics.get('GTitle', 'graphics')) if cgo_name not in unique_cgo_names: unique_cgo_names[cgo_name] = cgo_name else: cnt = 2 while cgo_name + "_" + str(cnt) in unique_cgo_names: cnt = cnt + 1 new_name = cgo_name + "_" + str(cnt) unique_cgo_names[new_name] = new_name cgo_name = new_name cmd.load_cgo(cgo, cgo_name, state=state, quiet=quiet, zoom=0) cgo_cnt = cgo_cnt + 1 cmd.set("two_sided_lighting", 1) # global setting... cmd.set("cgo_line_width", 2, cgo_name) if 'GTransparency' in graphics: g_trans = graphics['GTransparency'] if len(g_trans) >= 2: if g_trans[0] != 0: cmd.set('cgo_transparency', '%1.6f' % (g_trans[0] / 255.0), cgo_name) cmd.set('transparency_global_sort') if 'meter' in mr.system: meter_name = name + ".meter" exists = 0 for meter_block in mr.system['meter']: if meter_block[0][0:2] == ['type', 'atoms']: for meter in meter_block[1]: (type, atoms) = meter[0:2] arg = tuple([meter_name] + list( map(lambda x, o=name: o + " and id " + str(x - 1), atoms))) getattr(cmd, type)(*arg) exists = 1 if exists: cmd.color("green", meter_name) # print mr.system['meter'] elif hasattr(mr, 'feature'): model = Indexed() cols = mr.feature[0] rows = mr.feature[1] col = {} cnt = 0 for a in cols: col[a] = cnt cnt = cnt + 1 for row in rows: atom = Atom() atom.coord = [row[col['x']], row[col['y']], row[col['z']]] atom.vdw = row[col['r']] atom.custom = row[col['expr']] model.atom.append(atom) obj_name = name + ".feature" cmd.load_model(model, obj_name, state=state, finish=finish, discrete=discrete, quiet=quiet, zoom=zoom) rank = 1 for row in rows: cmd.color("0x%06x" % row[col['color']], obj_name + " & id %d" % (rank - 1)) rank = rank + 1 cmd.show("mesh", obj_name) cmd.set("min_mesh_spacing", 0.55, obj_name) cmd.label(obj_name, "' '+custom") cmd.set("label_color", "yellow", obj_name) else: print(dir(mr))
2.0, # Radius 1.0, (1.0 + math.sin(aa)) / 2.0, (1.0 + math.cos(aa)) / 2.0, # RGB Color 1 0.3, (1.0 + math.cos(aa)) / 2.0, 0.5, # RGB Color 2 ]) # load this state into the PyMOL object cmd.load_cgo(obj, 'cgo03', a + 1) # this zooms out a bit more than usual cmd.reset() cmd.zoom('cgo03', 3.0) # this moves the rear clipping plane back a bit cmd.clip('far', -12.0) # give us a nice view cmd.turn('z', 30) cmd.turn('x', -60) # start the movie cmd.mplay()
def get_dude_image(entry, mol, original = True): data_folder = 'Data/' father_folder = data_folder + 'PNG_' + str(original) + '/' if not os.path.exists(father_folder): os.mkdir(father_folder) folder = father_folder + entry + '/' if not os.path.exists(folder): os.mkdir(folder) mol_name = mol[:-5] folder += mol_name + '/' if not os.path.exists(folder): os.mkdir(folder) docking_folder = entry if original: docking_folder += '/actives_Dock/poses/' else: docking_folder += '/decoys_Dock2/poses/' file_name = entry + '/rec.pdb' xtal = docking_folder + mol steps = 3 step_angle = 360.0 / steps pixels = 100 num_rand = 9 pymol.finish_launching() cmd.delete('all') cmd.load(file_name, 'protein') cmd.load(xtal, mol_name) cmd.select('lig', mol_name) obj_name = mol_name delete_hetero('lig') cmd.remove('hydrogen') if cmd.count_atoms('lig') == 0: os.rmdir(folder) return 0 cmd.select('rec', 'br. lig around 4 and poly') cmd.hide("all") cmd.color('white', 'rec') cmd.color('green', 'lig') cmd.util.cnc("all") cmd.show("sticks", 'lig') #Show H bonds cmd.set('h_bond_cutoff_center', 3.5) cmd.distance('hbonds', 'lig', 'rec', mode=2) cmd.hide('labels') #Show double bonds #cmd.set('valence', 1, obj_name) cmd.orient('lig') cmd.zoom('lig', 3) #Slab move -5 cmd.clip('move', -5) cmd.set('ray_opaque_background', 0) cmd.set('ray_shadows', 0) for show in ['sticks']:#['surface', 'sticks']: #Set transparency # tra = 0 # if show == 'surface': # tra = 0.5 # cmd.set('transparency', tra) cmd.show(show, 'rec') refresh() for x in range(steps): for y in range(steps): refresh() cmd.png(folder + show + '_' + str(x) + '_' + str(y) + '.png', pixels, pixels) refresh() cmd.turn('y', step_angle) refresh() cmd.turn('x', step_angle) refresh() cmd.hide(show, 'rec') refresh() return 1
cmd.alter("name Hice", "vdw=0.8000") cmd.alter("name Oice", "vdw=1.6000") cmd.alter("name Ccod", "vdw=1.7000") cmd.alter("name Ocod", "vdw=1.6000") cmd.select("protein", "all and not hetatm") cmd.select("surface", "hetatm and not resn doc") cmd.disable("surface") cmd.disable("protein") cmd.show("cartoon") cmd.set("cartoon_fancy_helices", 1) cmd.spectrum("count", selection="(protein)&e. c") #preset.publication("protein") cmd.show("spheres", "surface") cmd.clip("atoms", 5, "all") cmd.select("prot_int", "protein w. 5 of surface") cmd.disable('prot_int') cmd.select("surf_int", "surface w. 5 of protein") cmd.disable('surf_int') cmd.hide("everything", "surface") cmd.show("spheres", "surf_int") cmd.show("sticks", "((byres (prot_int))&(!(n;c,o,h|(n. n&!r. pro))))") cmd.space('cmyk') cmd.bg_color('black') cmd.select("BackBone", "name c+ca+o+n") cmd.select("SC_Carbon", "elem c and not BackBone") cmd.color("grey60", "SC_Carbon") cmd.disable('SC_Carbon') ############## OSTEOCALCIN STUFF ############### cmd.color("red", "name OE11")
def noclip(): """Sets clipping to nearly infinity.""" cmd.clip('near', 99999999) cmd.clip('far', -99999999)
# counter label pdb_list = [ "HETATM%5d C UNK 1 %8.3f%8.3f%8.3f 1.00 10.00\n"%(c,2.0,0,2.0), ] cmd.read_pdbstr(string.join(pdb_list,''),'lab1',c,discrete=1) cmd.label("(lab1 and id %d)"%c,"'frame %d %6.3f'"%(c,math.sin(a/10.0))) cmd.hide("nonbonded","lab1") # axes labels pdb_list = [ "HETATM 1 X UNK 1 %8.3f%8.3f%8.3f 1.00 10.00\n"%(3.2,0,0), "HETATM 2 Y UNK 2 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,3.2,0), "HETATM 3 Z UNK 3 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,0,3.2),] cmd.read_pdbstr(string.join(pdb_list,''),'lab2') cmd.hide('(lab2)') cmd.label('lab2','name') cmd.color('white','lab2') cmd.zoom('cgo01') cmd.clip('far',-5) cmd.mplay()
def get_image(ind, pdb_name, mol, chain, res, original = True): data_folder = 'Data/' father_folder = data_folder + 'PNG_' + str(original) + '/' #if not os.path.exists(father_folder): # os.mkdir(father_folder) folder = father_folder + ind + '_' + pdb_name + '/' if not os.path.exists(folder): os.mkdir(folder) ugly_id = 'cand4' true_id = 'cand1' docking_folder = 'RosettaDock/' file_name = docking_folder + ind + '_' + pdb_name + '/rec1.pdb' ugly_rec = docking_folder + ind + '_' + pdb_name + '/rec4.pdb' ugly_name = docking_folder + ind + '_' + pdb_name + '/' + ugly_id + '.mol2' xtal = docking_folder + ind + '_' + pdb_name + '/' + true_id + '.mol2' steps = 3 step_angle = 360.0 / steps pixels = 100 num_rand = 9 #This is done for negative of random rotation in the pocket '''if not original: fake_rotation = [] for _ in range(3): fake_rotation.append(random.random() * 360)''' pymol.finish_launching() cmd.delete('all') if original: cmd.load(file_name, 'protein') else: if not os.path.exists(ugly_rec): os.rmdir(folder) return 0 cmd.load(ugly_rec, 'protein') cmd.load(xtal) #cmd.select('lig', 'resn ' + mol + ' and chain ' + chain + ' and resi ' + res) cmd.select('lig', true_id) obj_name = true_id if not original: if not os.path.exists(ugly_name): os.rmdir(folder) return 0 cmd.load(ugly_name) cmd.select('lig', ugly_id) obj_name = ugly_id delete_hetero('lig') cmd.remove('hydrogen') if cmd.count_atoms('lig') == 0: os.rmdir(folder) return 0 #cmd.select('rec', 'not lig') cmd.select('rec', 'br. lig around 4 and poly') cmd.hide("all") cmd.color('white', 'rec') cmd.color('green', 'lig') cmd.util.cnc("all") cmd.show("sticks", 'lig') #Show H bonds cmd.set('h_bond_cutoff_center', 3.5) cmd.distance('hbonds', 'lig', 'rec', mode=2) cmd.hide('labels') #Show double bonds #cmd.set('valence', 1, obj_name) cmd.orient('lig') cmd.zoom('lig', 3) #Slab move -5 cmd.clip('move', -5) cmd.set('ray_opaque_background', 0) cmd.set('ray_shadows', 0) #This is done for negative of random rotation in the pocket '''if not original: cmd.rotate('x', fake_rotation[0], 'lig') cmd.rotate('y', fake_rotation[1], 'lig') cmd.rotate('z', fake_rotation[2], 'lig')''' #Transperent surface '''cmd.set('surface_carve_cutoff', 4.5) cmd.set('surface_carve_selection', 'lig') cmd.set('surface_carve_normal_cutoff', -0.1) cmd.set('surface_color', 'white') cmd.set('surface_type', 3) cmd.set('transparency', 0.5)''' for show in ['sticks']:#['surface', 'sticks']: #Set transparency # tra = 0 # if show == 'surface': # tra = 0.5 # cmd.set('transparency', tra) cmd.show(show, 'rec') refresh() for x in range(steps): for y in range(steps): refresh() cmd.png(folder + show + '_' + str(x) + '_' + str(y) + '.png', pixels, pixels) refresh() cmd.turn('y', step_angle) refresh() cmd.turn('x', step_angle) refresh() '''for x in range(num_rand): refresh() for ax in ['x', 'y', 'z']: cmd.turn(ax, random.random() * 360) refresh() cmd.png(folder + show + '_' + str(x) + '.png', pixels, pixels) refresh()''' cmd.hide(show, 'rec') refresh() return 1
c=0 for a in xrange(0,100): cluster.MD_step() balls = [] for i in xrange(0,cluster.N): balls.extend([COLOR, 1.0, 1.0, 1.0, SPHERE, cluster.particles[i].x, cluster.particles[i].y, cluster.particles[i].z, 0.5,]) obj = axes + balls cmd.load_cgo(obj,'cgo01',c) c = c + 1 pdb_list = [ "HETATM 1 X UNK 1 %8.3f%8.3f%8.3f 1.00 10.00\n"%(3.2,0,0), "HETATM 2 Y UNK 2 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,3.2,0), "HETATM 3 Z UNK 3 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,0,3.2), ] cmd.read_pdbstr(string.join(pdb_list,''),'lab2') cmd.hide('(lab2)') cmd.label('lab2','name') cmd.color('white','lab2') #cmd.zoom('cgo01') cmd.clip('far',-5)
5.0, 15+math.sin(aa)*10, -5.0, # XYZ 1 25.0, 15+math.sin(aa)*10, -5.0, # XYZ 2 2.0, # Radius 1.0, (1.0+math.sin(aa))/2.0,(1.0+math.cos(aa))/2.0, # RGB Color 1 0.3, (1.0+math.cos(aa))/2.0, 0.5, # RGB Color 2 ] ) # load this state into the PyMOL object cmd.load_cgo(obj,'cgo03',a+1) # this zooms out a bit more than usual cmd.reset() cmd.zoom('cgo03',3.0) # this moves the rear clipping plane back a bit cmd.clip('far',-12.0) # give us a nice view cmd.turn('z',30) cmd.turn('x',-60) # start the movie cmd.mplay()