def bond_connections_from_array(interactiongraph, residuemap, cutoff=0.0): # Make strength be proportional to girth of bonds graph = numpy.sqrt(numpy.absolute(interactiongraph)) # Simple min-max scaling parameters minimum = numpy.min(graph) maximum = numpy.max(graph) residues = list(residuemap.keys()) shown = [] for i in range(graph.shape[0]): for j in range(i, graph.shape[1]): # Only draw bonds if interaction strength over cutoff threshold if graph[i][j] > cutoff: resa = residues[i] resb = residues[j] shown.append(resa) shown.append(resb) a = "chain {} and resi {} and name CA".format( resa.split(':')[0], resa.split(':')[1][1:]) b = "chain {} and resi {} and name CA".format( resb.split(':')[0], resb.split(':')[1][1:]) cmd.bond(a, b) strength = 1.0 if maximum == minimum else 0.1 + (0.9 * ( (graph[i][j] - minimum) / (maximum - minimum))) cmd.set_bond("stick_radius", strength, a, b) return shown
def bond_connections(clusters, interactions): cutoff=10 ## show_list=["A:240","A:182","A:184","A:204","A:201","A:216"] # shell1=["A:240"] ## shell1=["A:204","A:240"] # shell2=["A:182","A:184","A:204","A:201","A:216"] # shell3=["A:151","A:155","A:156","A:199","A:205","A:208","A:214","A:238","A:242"] # shell4=["A:154","A:158","A:163","A:166","A:167","A:170","A:180","A:185","A:196","A:203","A:207","A:211","A:212","A:219","A:68"] # shell5=["A:135","A:136","A:149","A:160","A:162","A:164","A:171","A:173","A:174","A:178","A:192","A:197","A:200","A:206","A:222","A:230","A:235","A:236","A:237","A:26","A:29","A:66","A:69"] # shell6=["A:134","A:138","A:139","A:143","A:146","A:152","A:157","A:159","A:169","A:183","A:187","A:19","A:195","A:220","A:223","A:227","A:23","A:232","A:24","A:244","A:46","A:87","A:89","A:90","A:91"] # # show_list_wt=shell1 + shell2 + shell3 + shell4 + shell5 + shell6 # show_list_S=shell1 # show_list=shell1 # #show_list=show_list_wt # #show_list.append(shell1) # #show_list.append(shell2) # #print(show_list) for cluster in clusters: #print(cluster) for i in range(len(cluster)): for j in range(i, len(cluster)): resa = cluster[i] resb = cluster[j] # Only draw bonds if interaction strength at all present if resa in interactions: if resb in interactions[resa]: resa_=re.sub(r':\w',':',resa) resb_=re.sub(r':\w',':',resb) a = "chain {} and resi {} and name CA".format( resa_.split(':')[0], resa_.split(':')[1]) b = "chain {} and resi {} and name CA".format( resb_.split(':')[0], resb_.split(':')[1]) # if interactions[resa][resb] > cutoff and (resa in show_list or resb in show_list): if interactions[resa][resb] > cutoff: #and (resa in show_list or resb in show_list): #if resa not in show_list: # print(resa) #if resb not in show_list: # print(resb) # print(resa + " " + resb) print(a + " " + b + " " + str(interactions[resa][resb])) cmd.bond(a, b) cmd.set_bond("line_width", (interactions[resa][resb]/3), a, b) cmd.set_bond("line_color",get_color(resa,resb),a,b)
def display_graphkernel(pdb_id, pdb_path): ''' ''' # Load PDB cmd.bg_color('white') cmd.load(pdb_path + pdb_id[:-2] + '.pdb') cmd.split_chains(pdb_id[:-2]) for name in cmd.get_names('objects', 0, '(all)'): if not name.endswith(pdb_id[-1].upper()) and name.startswith( pdb_id[:4]): cmd.delete(name) else: zero_residues(name) cmd.reset() pdb_id2 = pdb_id + 'copy' cmd.create(pdb_id2, pdb_id) cmd.hide('everything', pdb_id) cmd.show_as('lines', pdb_id + ' and (name ca or name c or name n)') cmd.set('line_width', 5) cmd.set_bond('line_width', 5, pdb_id + ' and (name ca or name c or name n)') cmd.show('spheres', pdb_id + ' and name ca') cmd.set('sphere_transparency', 0.0, pdb_id + ' and name ca') cmd.set('sphere_scale', 0.5, pdb_id + ' and name ca') cmd.hide('everything', pdb_id2) cmd.show('spheres', pdb_id2 + ' and name ca') cmd.set('sphere_transparency', 0.8, pdb_id2 + ' and name ca') cmd.set('sphere_scale', code2[elem], elem + '&' + selection) #cmd.set('sphere_scale', 2, pdb_id2 + ' and name ca') data = cmd.get_coords(selection=pdb_id + ' and name ca', state=1) j = 55 cmd.set('dash_width', 1.0) cmd.set('dash_color', 'marine') for i in range(len(data)): cmd.distance('d' + str(i) + str(j), pdb_id2 + ' and name ca and res ' + str(i), pdb_id2 + ' and name ca and res ' + str(j)) cmd.hide('labels', 'd' + str(i) + str(j)) resicolor(pdb_id) resicolor(pdb_id) resicolor(pdb_id2, True)
def load_network(points, edges): with open(points, 'r') as infile: for line in infile.readlines(): field = line.strip().split() xyz = map(float, field) xyz = [10 * x for x in xyz] cmd.pseudoatom("test", elem='O', pos=xyz) with open(edges, 'r') as infile: for line in infile.readlines(): field = line.strip().split() if float(field[-1]) > 0.1: plop = cmd.bond('index %s' % field[0], 'index %s' % field[1]) cmd.set_bond('line_color', float(field[-1]), 'i. 1') cmd.show("sphere", "test") cmd.set('line_width', 5.0) return 0
def bond_connections(clusters, interactions): # Quickfix - find min and max # this filtering should be done before supplying to this function # That is, the "interactions" data should be already formatted # as a float in a way that makes it look nice with bond # stick_radius minimum = None maximum = None for cluster in clusters: for i in range(len(cluster)): for j in range(i, len(cluster)): resa = cluster[i] resb = cluster[j] if resa in interactions: if resb in interactions[resa]: strength = interactions[resa][resb][0] if minimum is None: minimum = strength else: minimum = strength if minimum > strength else minimum if maximum is None: maximum = strength else: maximum = strength if maximum < strength else maximum for cluster in clusters: for i in range(len(cluster)): for j in range(i, len(cluster)): resa = cluster[i] resb = cluster[j] # Only draw bonds if interaction strength at all present if resa in interactions: if resb in interactions[resa]: a = "chain {} and resi {} and name CA".format( resa.split(':')[0], resa.split(':')[1][1:]) b = "chain {} and resi {} and name CA".format( resb.split(':')[0], resb.split(':')[1][1:]) cmd.bond(a, b) strength = 1.0 if maximum == minimum else 0.1 + ( 0.9 * ((interactions[resa][resb][0] - minimum) / (maximum - minimum))) cmd.set_bond("stick_radius", strength, a, b)
def bond_colors_from_array(colorarray, residuemap, cutoff=0.0, colorprefix="path_"): residues = list(residuemap.keys()) colored = [] colors = {} colorindex = 0 numcolors = 0 # Expect rgb channels over first dimension for i in range(colorarray.shape[1]): for j in range(i, colorarray.shape[2]): # Only draw bonds if interaction strength over cutoff threshold resa = residues[i] resb = residues[j] colored.append((resa, resb)) a = "chain {} and resi {} and name CA".format( resa.split(':')[0], resa.split(':')[1][1:]) b = "chain {} and resi {} and name CA".format( resb.split(':')[0], resb.split(':')[1][1:]) #cmd.bond(a, b) color = tuple(colorarray[0:3, i, j]) if color not in colors: colorindex = numcolors + 1 numcolors += 1 colors[color] = colorindex cmd.set_color("{}{}".format(colorprefix, colorindex), color) else: colorindex = colors[color] colorname = "{}{}".format(colorprefix, colorindex) print("Applying color {}, named as {}, to residues {}".format( color, colorname, colored[-1])) cmd.set_bond("stick_color", colorname, a, b) print(colors) return colored, colors
def zoom_around(self, near=5, zoom=4): from pymol import cmd cmd.hide() sele = self.selector() tgt = '{} and ! name c+n+o+h'.format(sele) cmd.set_bond('stick_color', 'white', sele) cmd.set_bond('stick_radius', 0.14, sele) cmd.set('sphere_scale', 0.25, sele) cmd.show('sticks', tgt) cmd.show('spheres', tgt) cmd.select('rz-target', sele) cmd.select('rz-around', 'byres {} around {}'.format(sele, near)) cmd.deselect() cmd.show('(byres {} around {}) and ! name c+n+o+h'.format(sele, near)) cmd.show('////HOH') cmd.show('ribbon', 'byres {} expand {}'.format(sele, near)) cmd.orient(sele) cmd.zoom(sele, zoom)
from pymol import cmd cmd.bg_color('white') cmd.select('drg', 'all') cmd.set('valence', 1) cmd.set_bond('stick_radius', '0.14', 'drg', 'drg') cmd.set('sphere_scale', '0.25', 'drg') cmd.show('sticks', 'drg') cmd.show('spheres', 'drg') # output cmd.set('antialias', '2') cmd.set('direct', '0.6') cmd.set('orthoscopic', 'on') cmd.set('ray_trace_frames', '1') #cmd.ray(renderer=-1) #cmd.png('~/Downloads/charge.png', dpi=600)
cmd.load('_xyzfile.xyz') #cmd.bond('id 1', 'id 2') #cmd.bond('id 1', 'id 3') #cmd.bond('id 1', 'id 4') #cmd.set_bond ('stick_color', 'white', 'all', 'all') #cmd.set_bond ('stick_radius', -0.14, 'all', 'all') #cmd.set ('stick_ball', 1) #cmd.set ('stick_ball_ratio', -1) #cmd.set ('stick_ball_color', 'atomic') #cmd.show ('sticks', 'all') #cmd.color('black', 'id 1') #cmd.color('gray', '(name Au*)') cmd.set_bond('stick_radius', 0.1, 'all', 'all') cmd.set('sphere_scale', 0.15, 'all') cmd.show('sticks', 'all') cmd.show('spheres', 'all') cmd.set('stick_ball_color', 'atomic') cmd.color('gray20', '(name C*)') cmd.set('transparency_mode', 1) #w = 0.01 # cylinder width #l = 0.5 # cylinder length #h = 0.15 # cone hight #d = w * 1.618 # cone base diameter w = 0.03 # cylinder width l = 1.65 # cylinder length
def display_graphpool(pdb_id, pdb_path): ''' ''' # Load PDB cmd.bg_color('white') cmd.load(pdb_path + pdb_id[:-2] + '.pdb') cmd.split_chains(pdb_id[:-2]) for name in cmd.get_names('objects', 0, '(all)'): if not name.endswith(pdb_id[-1].upper()) and name.startswith( pdb_id[:4]): cmd.delete(name) else: zero_residues(name) cmd.reset() pdb_id2 = pdb_id + 'copy' cmd.create(pdb_id2, pdb_id) cmd.color('grey', pdb_id) cmd.hide('everything', pdb_id) cmd.show_as('lines', pdb_id + ' and (name ca)') cmd.set('line_width', 5) cmd.set_bond('line_width', 5, pdb_id + ' and (name ca)') cmd.show('spheres', pdb_id + ' and name ca') cmd.set('sphere_transparency', 0.0, pdb_id + ' and name ca') cmd.set('sphere_scale', 0.5, pdb_id + ' and name ca') data = cmd.get_coords(selection=pdb_id + ' and name ca', state=1) data_ = [] cmd.set('dash_color', 'marine') cmd.set('dash_width', 1.0) j = 55 for i in range(len(data)): if i % 2 == 0 and i + 1 < len(data): data[i] = np.mean(data[i:i + 2], axis=0) data[i + 1] = np.array([10000, 10000, 10000]) #cmd.distance('d'+str(i)+str(j), pdb_id + ' and name ca and res ' + str(i), pdb_id + ' and name ca and res ' + str(j)) #cmd.hide('labels', 'd'+str(i)+str(j)) cmd.color('red', pdb_id2) cmd.hide('everything', pdb_id2) cmd.show_as('lines', pdb_id2 + ' and (name ca)') cmd.set('line_width', 5) cmd.set_bond('line_width', 5, pdb_id2 + ' and (name ca)') cmd.show('spheres', pdb_id2 + ' and name ca') cmd.set('sphere_transparency', 0.0, pdb_id2 + ' and name ca') cmd.set('sphere_scale', 0.5, pdb_id2 + ' and name ca') for i in range(len(data)): if i % 2 == 0 and i + 1 < len(data): cmd.alter_state(1, pdb_id2 + ' and name ca and res ' + str(i), '(x,y,z)=' + str(tuple(data[i]))) else: cmd.hide('spheres', pdb_id2 + ' and name ca and res ' + str(i)) pdb_id3 = pdb_id + 'copy2' cmd.create(pdb_id3, pdb_id2) cmd.color('red', pdb_id3) cmd.hide('everything', pdb_id3) cmd.show_as('lines', pdb_id3 + ' and (name ca)') cmd.set('line_width', 5) cmd.set_bond('line_width', 5, pdb_id3 + ' and (name ca)') cmd.show('spheres', pdb_id3 + ' and name ca') cmd.set('sphere_transparency', 0.8, pdb_id3 + ' and name ca') for i in range(len(data)): if i % 2 == 0 and i + 1 < len(data): cmd.set('sphere_scale', np.random.uniform(1.0, 4.5), pdb_id3 + ' and name ca and res ' + str(i)) else: cmd.hide('spheres', pdb_id2 + ' and name ca and res ' + str(i))
def testSetBond(self): value = 2.3 cmd.fragment('ala') cmd.set_bond('stick_radius', value, '*', '*') v_list = cmd.get_bond('stick_radius', 'first *', '*') self.assertAlmostEqual(v_list[0][1][0][2], value)
A = AggregatTransferFromFile(fname) cmd.set_view ([ -0.480811268, 0.603387773, 0.636203885, 0.675508440, 0.717507422, -0.169974893, -0.559037924, 0.348030269, -0.752567112, -0.000127681, 0.000030167, -122.974456787, 13.921709061, -7.469791889, -4.264435768, -1086.176879883, 1332.132446289, -20.000000000]) # select only a few sample points indices = [0, 250, 500, 1000, 1999] t = np.linspace(0, A._tLength, A._tSteps)[indices] # Get values ordered by time in first index values = np.swapaxes(A.get(), 0, 1)[indices] selections = ['lab{}'.format(i + 1) for i in range(8)] for lab in selections: cmd.label(lab, '') selections = ['bcl{}'.format(i + 1) for i in range(7)] for i, val in enumerate(values): alpha = p_to_alpha(val) for n, bcl in enumerate(selections): cmd.set_bond('stick_transparency', alpha[n], bcl) cmd.refresh() cmd.ray(width, height) print('Belongs to time {}'.format(t[i] * 5.20883746)) cmd.png('../fmo_transfer_{}.png'.format(i), dpi=DPI, ray=1)
cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/O6") cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/C8") cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/C9") cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/C10") cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/O9") cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/O10") cmd.bond("/1-tess/pro/A/71/OE2", "/1-tess/lig/0/0/O11") cmd.bond("/1-tess/pro/A/73/CD", "/1-tess/lig/0/0/O8") cmd.bond("/1-tess/pro/A/73/NE", "/1-tess/lig/0/0/O8") cmd.bond("/1-tess/pro/A/73/CZ", "/1-tess/lig/0/0/O8") cmd.bond("/1-tess/pro/A/73/NH1", "/1-tess/lig/0/0/O7") cmd.bond("/1-tess/pro/A/73/NH1", "/1-tess/lig/0/0/O8") cmd.bond("/1-tess/pro/A/73/NH2", "/1-tess/lig/0/0/O8") cmd.bond("/1-tess/pro/A/73/NH2", "/1-tess/lig/0/0/O9") cmd.bond("/1-tess/pro/A/123/OD2", "/1-tess/lig/0/0/O3") cmd.set_bond("line_color", "forest", "1-tess") cmd.set_bond("line_width", 0.25, "1-tess") cmd.bond("/1-tess/pro/A/29/OG", "/1-tess/pro/A/31/CG2") cmd.bond("/1-tess/pro/A/29/OG", "/1-tess/pro/A/46/OD1") cmd.bond("/1-tess/pro/A/29/OG", "/1-tess/pro/A/52/CE1") cmd.bond("/1-tess/pro/A/29/OG", "/1-tess/pro/A/123/OD2") cmd.bond("/1-tess/pro/A/31/CG2", "/1-tess/pro/A/44/CE1") cmd.bond("/1-tess/pro/A/31/CG2", "/1-tess/pro/A/46/OD1") cmd.bond("/1-tess/pro/A/31/CG2", "/1-tess/pro/A/123/OD2") cmd.bond("/1-tess/pro/A/33/ND2", "/1-tess/pro/A/44/CE1") cmd.bond("/1-tess/pro/A/33/ND2", "/1-tess/pro/A/63/NZ") cmd.bond("/1-tess/pro/A/33/ND2", "/1-tess/pro/A/68/CZ2") cmd.bond("/1-tess/pro/A/33/ND2", "/1-tess/pro/A/123/OD2") cmd.bond("/1-tess/pro/A/44/CD2", "/1-tess/pro/A/44/NE2") cmd.bond("/1-tess/pro/A/44/CD2", "/1-tess/pro/A/59/CG1") cmd.bond("/1-tess/pro/A/44/CD2", "/1-tess/pro/A/61/CB")
if current_m != last_m or current_p != last_p: last_m = current_m last_p = current_p try: cmd.delete('my_map.2fofc') cmd.delete('my_map.fofc') cmd.load(pdbFile, 'overall_best') cmd.load_mtz(reflectionFile, prefix='my_map' ) #, amplitudes = 'unknown/unknown291019/REFM_FWT', #phases = 'unknown/unknown291019/REFM_PHWT',reso_low = 23.96, reso_high = 1.9) #cmd.map_double("my_map") cmd.map_double("my_map.2fofc") print("upload finished") cmd.hide("everything") cmd.show("sticks") cmd.set_bond('stick_radius', '0.1', 'overall_best') cmd.center() cmd.select('site', 'br. all within ' + str(radius_check) + ' of center') cmd.isomesh('map', 'my_map.2fofc', 1.0, 'site', carve=1.6) cmd.color('gray40', 'map') cmd.set('mesh_width', '0.1') cmd.bg_color('white') cmd.set("ray_trace_fog", "0")
from pymol import cmd cmd.bg_color('white') cmd.select('drg', 'all') cmd.set('valence', '1') cmd.set_bond('stick_radius', '0.14', 'drg', 'drg') cmd.set('sphere_scale', '0.25', 'drg') cmd.show('sticks', 'drg') cmd.show('spheres', 'drg') cmd.set_view ([0.987891138, -0.139472052, -0.067891687, 0.152521998, 0.793636620, 0.588958621, -0.028259384, -0.592185259, 0.805302858, 0.000017954, 0.000006792, -52.386489868, -1.638074398, -1.409737468, -0.143483341, -34.060420990, 138.833740234, 20.000000000]) charges = ["-0.103" ," 0.115" ," 0.016" ,"-0.082" ," 0.068" ,"-0.022" ,"-0.017" ," 0.017" ,"-0.001" ,"-0.051" ," 0.120" ,"-0.186" ," 0.163" ,"-0.115" ," 0.216" ,"-0.142" ," 0.130" ,"-0.294" ," 0.114" ,"-0.004" ," 0.102" ,"-0.098" ,"-0.004" ," 0.102" ,"-0.294" ," 0.114" ," 0.882" ,"-0.582" ,"-0.582" ,"-0.582"] cmd.set('label_size', '22') cmd.set('label_position', (0, 2, 2)) for i, charge in zip(range(1, 31), charges): cmd.label('id %s' % i, charge) # output cmd.set('antialias', '2') cmd.set('direct', '0.6') cmd.set('orthoscopic', 'on') cmd.set('ray_trace_frames', '1') #cmd.ray(renderer=-1) #cmd.png('~/Downloads/charge.png', dpi=600)
def visualize_path((path, freq, pdb, outfile)): nodes = path.split('=>') save_pse = True #print outfile #print freq #sys.exit() #print nodes node_color = sns.color_palette("Reds", n_colors=len(nodes)) node_color.reverse() #print node_color cmd.reinitialize() cmd.load(pdb) cmd.hide("everything") # cmd.show("ribbon") cmd.show("cartoon") #resa = re.sub(r':\w', ':', nodes[0]) (chain, resnum) = re.split(':\w', nodes[0]) a = "chain {} and resi {} and name CA".format(chain, resnum) cmd.show("spheres", a) colorname = "color" + str(0) cmd.set_color(colorname, node_color[0]) cmd.color(colorname, a) cmd.label(a, '" %s:%s" % (resi, resn)') cmd.set("label_color", "red", a) #cmd.label(a, '"%s" % (resi)') for i in range(1, len(nodes)): #resb = re.sub(r':\w', ':', nodes[i]) (chain, resnum) = re.split(':\w', nodes[i]) b = "chain {} and resi {} and name CA".format(chain, resnum) #print a,b cmd.bond(a, b) cmd.set_bond("line_width", 5, a, b) cmd.set_bond("line_color", "red", a, b) cmd.show("lines", a) cmd.show("spheres", a) cmd.show("lines", b) cmd.show("spheres", b) colorname = "color" + str(i) cmd.set_color(colorname, node_color[i]) cmd.color(colorname, b) #cmd.label(b,'" %s:%s" % (resi, resn)') cmd.label(b, '" %s%s" % (one_letter[resn],resi)') #cmd.label(b, '"%s" % (resi)') a = b #cmd.color(node_color[len)],b) #cmd.space("cmyk") cmd.set("ray_shadow", "off") #cmd.bg_color("white") #cmd.label_position([3,2,1]) cmd.set("label_position", (2, 2, 2)) sele = "chain A and resi 131 and not name H*" cmd.show("sticks", sele) norm_factor = freq[nodes[0]] node_freqs = {k: freq[k] for k in nodes} #print node_freqs #print freq[nodes] #print sorted(node_freqs.values()) node_freq_min = min(node_freqs.values()) #print node_freq_min #sys.exit() scale_cutoff = min(0.25, min(node_freqs.values()) / norm_factor) #print nodes #print node_freqs #print freq #sys.exit() for res in freq.keys(): scale = freq[res] / norm_factor #print res,freq[res],scale,scale_cutoff if scale > scale_cutoff: (chain, resnum) = re.split(':\w', res) sele = "chain {} and resi {} and name CA".format(chain, resnum) cmd.show("spheres", sele) cmd.set("sphere_scale", scale, selection=sele) if not res in nodes: #give residue not on highest freq path a different color last_color = len(nodes) - 1 #colorname="color"+str(last_color) colorname = "grey60" #color" + str(last_color) cmd.color(colorname, sele) cmd.label(sele, '" %s%s" % (one_letter[resn],resi)') cmd.util.cnc(sele) #cmd.center("chain A") cmd.deselect() ### cut below here and paste into script ### cmd.set_view([\ 0.354133159, -0.915425777, 0.191264138,\ -0.626513124, -0.384070098, -0.678214610,\ 0.694314659, 0.120348796, -0.709537089,\ -0.000188543, -0.000061929, -119.472831726,\ 33.501632690, 81.432159424, 143.041992188,\ 87.118530273, 151.834289551, -20.000000000\ ]) ### cut above here and paste into script ### #outfile="{}cluster{}-{}.png".format(outfolder,cut,freq) # if ray: # cmd.ray() # cmd.sync(10) cmd.save(outfile) cmd.sync(10) if save_pse: outfile_pse = re.sub('.png', '.pse', outfile) cmd.save(outfile_pse) cmd.sync(10)