def images_spin(images, sweep, axis): global imagecount global ray global filename global ximage global yimage print "... Images %s - %s:" % (imagecount, imagecount + images - 1) print "Writing %s images turning about %s axis by %s degrees per image" % \ (images, axis, sweep/images) #cycle over images for i in range(0, images): #move camera cmd.turn(axis, sweep / images) # turn each image the fraction of the total spin #print image cmd.png("images/%s_%04d" % (filename, imagecount), ray=ray) #increment imagecounter print "cycle %s, image %s" % (i + 1, imagecount) imagecount = imagecount + 1 cmd.refresh()
def images_screw(images, distance, sweep, axis): global imagecount global ray global filename global ximage global yimage print "... Images %s - %s:" % (imagecount, imagecount + images - 1) print "Writing %s images moving along %s axis by %s Angstrom" % \ (images, axis, distance/images) print " and rotating %s degrees per image" % (sweep / images) for i in range(0, images): #cycle for number of images # transformations cmd.move(axis, distance / images) cmd.turn(axis, sweep / images) #print image cmd.png("images/%s_%04d" % (filename, imagecount), ray=ray) #increment imagecounter imagecount = imagecount + 1 cmd.refresh()
def testScene(self): cmd.fragment('ala', 'm1') cmd.fragment('gly', 'm2') cmd.create('m2', 'm2', 1, 2) cmd.create('m2', 'm2', 1, 3) cmd.create('m2', 'm2', 1, 4) # store cmd.show_as('sticks', 'm1') cmd.show_as('spheres', 'm2') cmd.color('blue', 'm1') cmd.color('yellow', 'm2') view_001 = cmd.get_view() cmd.scene('new', 'store', 'hello world') # store cmd.frame(3) cmd.show_as('lines') cmd.color('red') cmd.turn('x', 45) view_002 = cmd.get_view() cmd.scene('new', 'store') # we actually don't know the auto naming counter # self.assertEqual(cmd.get_scene_list(), ['001', '002']) names = cmd.get_scene_list() # recall cmd.scene(names[0], 'recall', animate=0) self.assertArrayEqual(view_001, cmd.get_view(), delta=1e-3) self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('color blue')) self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('rep sticks')) self.assertEqual(cmd.count_atoms('m2'), cmd.count_atoms('color yellow')) self.assertEqual(cmd.count_atoms('m2'), cmd.count_atoms('rep spheres')) self.assertNotEqual(cmd.get_wizard(), None) self.assertEqual(cmd.get_state(), 1) # recall cmd.scene(names[1], 'recall', animate=0) self.assertArrayEqual(view_002, cmd.get_view(), delta=1e-3) self.assertEqual(0, cmd.count_atoms('color blue')) self.assertEqual(0, cmd.count_atoms('rep sticks')) self.assertEqual(cmd.count_atoms(), cmd.count_atoms('color red')) self.assertEqual(cmd.count_atoms(), cmd.count_atoms('rep lines')) self.assertEqual(cmd.get_wizard(), None) self.assertEqual(cmd.get_state(), 3) # with movie (not playing) it must not recall the state cmd.mset('1-4') cmd.frame(1) cmd.scene(names[1], 'recall', animate=0) self.assertEqual(cmd.get_state(), 1) # rename and delete cmd.scene('F2', 'store') cmd.scene(names[0], 'rename', new_key='F1') cmd.scene(names[1], 'delete') self.assertEqual(cmd.get_scene_list(), ['F1', 'F2'])
def testView(self): cmd.turn('x', 30) a = cmd.get_view() cmd.view('A', 'store') cmd.turn('y', 30) self.assertNotEqual(a, cmd.get_view()) cmd.view('A', 'recall', animate=0) self.assertEqual(a, cmd.get_view())
def dump_rep(name): if 'PYMOL_GIT_MOD' in os.environ: import shutil try: shutil.copytree( os.path.join(os.environ['PYMOL_GIT_MOD'], 'pymol2glmol', 'js'), os.path.join(os.getcwd(), 'js')) except OSError: pass names = cmd.get_session()['names'] cmd.set('pdb_retain_ids', 1) ret = '' for obj in names: if (obj == None): continue if (obj[2] == 0): # not visible continue if (obj[1] == 0 and obj[4] == 1 and obj[0] == name): ret += parseObjMol(obj) if (obj[1] == 0 and obj[4] == 4): # currently all dist objects are exported ret += parseDistObj(obj) cmd.turn('z', 180) view = cmd.get_view() cmd.turn('z', 180) cx = -view[12] cy = -view[13] cz = -view[14] cameraZ = -view[11] - 150 fov = float(cmd.get("field_of_view")) fogStart = float(cmd.get("fog_start")) slabNear = view[15] + view[11] slabFar = view[16] + view[11] ret += "\nview:%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f" % \ (cx, cy, cz, cameraZ, slabNear, slabFar, fogStart, fov) for i in range(9): ret += ",%.3f" % view[i] bgcolor = cmd.get_setting_tuple('bg_rgb')[1] ret += "\nbgcolor:%02x%02x%02x" % (int(255 * float(bgcolor[0])), \ int(255 * float(bgcolor[1])), int(255 * float(bgcolor[2]))) if 'PYMOL_GIT_MOD' in os.environ: template = open(os.path.join(os.environ['PYMOL_GIT_MOD'], 'pymol2glmol', 'imported.html')).read().\ replace("###INCLUDE_PDB_FILE_HERE###", cmd.get_pdbstr(name)).\ replace('###INCLUDE_REPRESENTATION_HERE###', ret) else: template = open('imported.html').read().\ replace("###INCLUDE_PDB_FILE_HERE###", cmd.get_pdbstr(name)).\ replace('###INCLUDE_REPRESENTATION_HERE###', ret) f = open(name + '.html', 'w') f.write(template) f.close()
def additional_camera(): # Add a rotation to the global view cmd.scene('001', animate=0) cmd.turn('y', -40) cmd.mview('store', 80) cmd.turn('y', 40) cmd.mview('store', 140) # Add panning to the close-up cmd.scene('002', animate=0) cmd.move('x', 5) cmd.mview('store', 320)
def zoom_to_ligand(self): """Zoom in too ligand and its interactions.""" cmd.center(self.ligname) cmd.orient(self.ligname) cmd.turn('x', 110) # If the ligand is aligned with the longest axis, aromatic rings are hidden if 'AllBSRes' in cmd.get_names("selections"): cmd.zoom('%s or AllBSRes' % self.ligname, 3) else: if self.object_exists(self.ligname): cmd.zoom(self.ligname, 3) cmd.origin(self.ligname)
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 test_add_scenes(self): cmd.fragment('gly', 'm1') cmd.scene('001', 'store') cmd.turn('x', 90) cmd.scene('002', 'store') movie.add_scenes() self.assertEqual(cmd.count_frames(), 615) cmd.mset() movie.add_scenes(['001', '002'], pause=3) self.assertEqual(cmd.count_frames(), 315) cmd.mset() movie.add_scenes('["001", "002"]') # string self.assertEqual(cmd.count_frames(), 615)
def testReset(self): # view v = cmd.get_view() cmd.turn('x', 10) cmd.move('y', 10) self.assertNotEqual(v, cmd.get_view()) cmd.reset() self.assertEqual(v, cmd.get_view()) # object cmd.pseudoatom("m1") x = cmd.get_object_matrix("m1") cmd.translate([1, 2, 3], object="m1") self.assertNotEqual(x, cmd.get_object_matrix("m1")) cmd.reset("m1") self.assertEqual(x, cmd.get_object_matrix("m1"))
def testReset(self): # view v = cmd.get_view() cmd.turn('x', 10) cmd.move('y', 10) self.assertNotEqual(v, cmd.get_view()) cmd.reset() self.assertEqual(v, cmd.get_view()) # object cmd.pseudoatom("m1") x = cmd.get_object_matrix("m1") cmd.translate([1,2,3], object="m1") self.assertNotEqual(x, cmd.get_object_matrix("m1")) cmd.reset("m1") self.assertEqual(x, cmd.get_object_matrix("m1"))
def testMove(self): for a in "xyz": cmd.turn(a, random.random() * 10 - 5) cmd.move(a, random.random() * 10 - 5) v = list(cmd.get_view()) d = (2,4,6) cmd.move("x", d[0]) cmd.move("y", d[1]) cmd.move("z", d[2]) m = cmd.get_view() v[9] += d[0] v[10] += d[1] v[11] += d[2] v[15] -= d[2] v[16] -= d[2] self.assertArrayEqual(v, m, delta=1e-3)
def testMove(self): for a in "xyz": cmd.turn(a, random.random() * 10 - 5) cmd.move(a, random.random() * 10 - 5) v = list(cmd.get_view()) d = (2, 4, 6) cmd.move("x", d[0]) cmd.move("y", d[1]) cmd.move("z", d[2]) m = cmd.get_view() v[9] += d[0] v[10] += d[1] v[11] += d[2] v[15] -= d[2] v[16] -= d[2] self.assertArrayEqual(v, m, delta=1e-3)
def highlight_chains(): cmd.mstop() cmd.mclear() cmd.mset() glb.update() colors = ['blue', 'orange', 'silver', 'green', 'yellow', 'purple', 'brightorange', 'lightblue', 'lightorange', 'pink', 'forest', 'firebrick', 'paleyellow', 'salmon', 'ruby', 'wheat', 'lightmagenta', 'nitblue'] chains = [] numChains = 0 objects = cmd.get_names('all') for obj in objects: split = obj.split('Chain-') if len(split) == 2: chains.append(split[1]) numChains += 1 numFrames = (numChains*200)+70 cmd.mset('1', numFrames) cmd.mdo(1,'color red, all; hide cartoon, all') cmd.orient() cmd.mview('store', '1') colorCount = 0 frameCount = 1 for i in chains: cmd.orient('chain ' + i) cmd.mview('store', frameCount+59) cmd.mview('store', frameCount+115) flash_chain(i, frameCount+59, 'red', colors[colorCount]) cmd.orient() cmd.turn('x', '270') cmd.turn('y', '180') cmd.mview('store', frameCount+150) cmd.mview('store', frameCount+170) colorCount += 1 frameCount += 200 if(frameCount > numFrames-100): cmd.orient() cmd.mdo(numFrames,'mstop') cmd.mview('store', (numChains*200)+70) cmd.mview('interpolate') cmd.show('ribbon') cmd.color('red', 'all')
def testChromadepth(self): cmd.viewport(100, 100) self.ambientOnly() cmd.set('use_shaders') cmd.set('chromadepth') cmd.set('orthoscopic') cmd.pseudoatom(pos=(0, 0, -5)) cmd.pseudoatom(pos=(0, 0, 5)) cmd.color('gray') cmd.show_as('spheres') cmd.zoom() cmd.turn('y', 20) img = self.get_imagearray() self.assertImageHasColor('blue', img) self.assertImageHasColor('red', img)
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 ray(self,cleanup=0): if not cleanup: cmd.set("suspend_updates",1,quiet=1) cmd.disable() cmd.delete("ray") cmd.set("sphere_scale",1.0) cmd.load("$PYMOL_DATA/demo/il2.pdb","ray") cmd.remove("(ray and hydro)") cmd.hide("lines","ray") cmd.show("spheres","ray") cmd.orient("ray") cmd.turn("x",90) util.ray_shadows('heavy') cmd.mstop() cmd.rock(0) cmd.set("suspend_updates",0,quiet=1) cmd.refresh() cmd.do("ray") else: cmd.delete("ray")
def ray(self,cleanup=0): if not cleanup: cmd.set("suspend_updates",1,quiet=1) cmd.disable() cmd.delete("ray") cmd.set("sphere_mode",5) cmd.set("sphere_scale",1.0) cmd.load("$PYMOL_DATA/demo/il2.pdb","ray") cmd.remove("(ray and hydro)") cmd.hide("lines","ray") cmd.show("spheres","ray") cmd.orient("ray") cmd.turn("x",90) util.ray_shadows('heavy') cmd.mstop() cmd.rock(0) cmd.set("suspend_updates",0,quiet=1) cmd.refresh() cmd.do("ray") else: cmd.delete("ray")
def images_spin_3ax(images, sweep): global imagecount global ray global filename global ximage global yimage print "... Images %s - %s:" % (imagecount, imagecount + images - 1) print "Writing %s images turning about:" % images print " x axis by %s degrees," % (sweep[0] / images) print " y axis by %s degrees, and" % (sweep[1] / images) print " z axis by %s degrees per image" % (sweep[2] / images) #cycle over number of images for i in range(0, images): # transformations cmd.turn("x", sweep[0] / images) cmd.turn("y", sweep[1] / images) cmd.turn("z", sweep[2] / images) #print image cmd.png("images/%s_%04d" % (filename, imagecount), ray=ray) #increment imagecounter imagecount = imagecount + 1 cmd.refresh()
def render_to_file(fname, top=True, side=True, vesicle=False, zoom_obj="pbcbox", zoom_distance=10): fname = os.path.splitext(fname)[0] cmd.reset() cmd.zoom(zoom_obj, zoom_distance) if vesicle: cmd.turn("z", -90) cmd.move("y", -50) if top: cmd.ray("2048") cmd.png("%s_top.png" % fname) if side: cmd.turn("x", -90) if vesicle: cmd.move("y", 150) cmd.ray("2048") cmd.png("%s_side.png" % fname) cmd.reset() cmd.zoom(zoom_obj, zoom_distance) if vesicle: cmd.turn("z", -90) cmd.move("y", -50)
def images_spin3_slide3(images, distance, sweep): global imagecount global ray global filename global ximage global yimage print "... Images %s - %s:" % (imagecount, imagecount + images - 1) print "Writing %s images turning about:" % images print " x axis by %s degrees, then" % (sweep[0] / images) print " y axis by %s degrees, and" % (sweep[1] / images) print " z axis by %s degrees per image," % (sweep[2] / images) print " while moving along:" print " x axis by %s Angstrom," % (distance[0] / images) print " y axis by %s Angstrom, and" % (distance[1] / images) print " z axis by %s Angstrom per image" % (distance[2] / images) for i in range(0, images): #cycle for number of images # transformations cmd.turn("x", sweep[0] / images) cmd.turn("y", sweep[1] / images) cmd.turn("z", sweep[2] / images) cmd.move("x", distance[0] / images) cmd.move("y", distance[1] / images) cmd.move("z", distance[2] / images) #print image cmd.png("images/%s_%04d" % (filename, imagecount), ray=ray) #increment imagecounter imagecount = imagecount + 1 cmd.refresh()
def view_rotate(angle_in_deg, axis, base_name, number_of_frames=25, frameno_offset=0): angle_chunk = float(angle_in_deg) / number_of_frames # no rotation in the first frame last_frame = frameno_offset cmd.png(base_name + str(last_frame).zfill(3), width=1920, height=1080, ray=True) last_frame += 1 for frameno in range(number_of_frames): cmd.turn(axis, angle_chunk) # turn turns the camera rather than the object cmd.png(base_name + str(last_frame).zfill(3), width=1920, height=1080, ray=True) last_frame += 1 return last_frame
def testBackfaceLighting(self, use_shader, has_normal, two_sided_lighting, backface_cull, cgo_lighting, back): viewport = (50, 50) cmd.viewport(*viewport) objname = 'simpletri' obj = [] if has_normal: # specifies a normal obj.extend([NORMAL, 0., 0., 1.]) obj.extend([ BEGIN, TRIANGLES, COLOR, 1.0, 0., 0., VERTEX, 0.0, 0.0, 0.0, VERTEX, 1.0, 0.0, 0.0, VERTEX, 0.0, 1.0, 0.0, END ]) cmd.load_cgo(obj, objname, 1) cmd.set('use_shader', use_shader) cmd.set('two_sided_lighting', two_sided_lighting) cmd.set('backface_cull', backface_cull) cmd.set('cgo_lighting', cgo_lighting, objname) cmd.set('depth_cue', 0) cmd.set('antialias', 0) cmd.set('light_count', 1) if back: cmd.turn("y", 180) # to see the images # cmd.png("%d__%d_%d_%d_%d_%d_%d_test.png" % (back and backface_cull, use_shader, has_normal, two_sided_lighting, backface_cull, cgo_lighting, back)) img = self.get_imagearray(width=viewport[0], height=viewport[1]) if not two_sided_lighting and not backface_cull and cgo_lighting and back: # this is where a shaded back side is rendered redmask = (img[:, :, 0] > 0) self.assertTrue((img[:, :, 0][redmask] < 255).any() and (img[:, :, 1:3][redmask] == 0).all()) elif back and backface_cull: self.assertImageHasNotColor('red', img=img) else: self.assertImageHasColor('red', img=img)
def turns(): while 1: time.sleep(random.random()*0.05) cmd.turn('x',random.random()*10-5) time.sleep(random.random()*0.05) cmd.turn('y',random.random()*10-5) time.sleep(random.random()*0.05) cmd.turn('z',random.random()*10-5)
def turns(): while 1: time.sleep(random.random() * 0.05) cmd.turn('x', random.random() * 10 - 5) time.sleep(random.random() * 0.05) cmd.turn('y', random.random() * 10 - 5) time.sleep(random.random() * 0.05) cmd.turn('z', random.random() * 10 - 5)
def visualize(self): # load pdb into pymol and set up view self.initPymol() # TODO: check if this is necessary self.initCamera() # listen ... while True: # Rift support self.ocudump.getPose() #print ocudump.pose [pitch (x), yaw (z), roll (y)] pose = self.ocudump.pose # calculate head rotation xRot = pose[0] - self.previousOrientation[0] yRot = pose[1] - self.previousOrientation[1] zRot = pose[2] - self.previousOrientation[2] # update view cmd.turn('x', xRot * self.rotationScaling) cmd.turn('y', yRot * self.rotationScaling) cmd.turn('z', zRot * self.rotationScaling) # rift head tracking if self.ocudump.positionTracked: # move head if sensor detects head motion # not tested cmd.move('x', pose[3] - self.previousPosition[0]) cmd.move('y', pose[4] - self.previousPosition[1]) cmd.move('z', pose[5] - self.previousPosition[2]) # update camera for "natural rotation" if self.naturalRotation: self.setOriginAtCamera() # record previous pose for accurate rotation diff self.previousOrientation = pose[0:3] time.sleep(1 / float(self.trackingRefresh))
def testTurn(self): cmd.turn('z', 90) v = cmd.get_view() self.assertArrayEqual(v[:9], [0., 1., 0., -1., 0., 0., 0., 0., 1.], delta=1e-3)
#cmd.show('ribbon') #cmd.show('surface') cmd.hide('everything','resn hoh') cmd.color('green','all') cmd.bg_color('white') cmd.set('ray_trace_fog',0) cmd.set('stick_transparency',0.2) #cmd.set('transparency',0.8) cmd.set('sphere_scale', 0.4) cmd.set('stick_radius', 0.3) cmd.set('label_position', (1,2,1)) cmd.set('label_color', 'black') cmd.set('label_size', 10) cmd.set('label_font_id', 7) cmd.turn('y',90) #load ghosts and display G = pickle.load(open(ghostsfile,'r')) #create color index for source residues i=0 for r in G: for p in G[r].keys(): if 'pK' in p: s = G[r][p] if not s in sourceclrs: sourceclrs[s] = colors[i] i+=1 if i>=len(colors): i=0 def draw(G):
# -c from pymol import cmd print "BEGIN-LOG" print cmd.set_key('F1', lambda: cmd.turn('x', 10)) print cmd.set_key('F12', lambda: cmd.turn('x', 10)) print cmd.set_key('left', lambda: cmd.turn('x', 10)) print cmd.set_key('right', lambda: cmd.turn('x', 10)) print cmd.set_key('pgup', lambda: cmd.turn('x', 10)) print cmd.set_key('pgdn', lambda: cmd.turn('x', 10)) print cmd.set_key('home', lambda: cmd.turn('x', 10)) print cmd.set_key('insert', lambda: cmd.turn('x', 10)) print cmd.set_key('ALT-A', lambda: cmd.turn('y', 10)) print cmd.set_key('CTRL-C', lambda: cmd.turn('z', 10)) print cmd.set_key('SHFT-F1', lambda: cmd.turn('z', 10)) print cmd.set_key('ALT-F1', lambda: cmd.turn('y', 10)) print cmd.set_key('CTRL-F8', lambda: cmd.move('x', 1)) print "END-LOG"
if show_conformers: cmd.load( '/Users/choderaj/github/foldingathome/covid-moonshot/perses-figure/test.mol2', 'conformers') cmd.load( '/Users/choderaj/github/foldingathome/covid-moonshot/perses-figure/boronic_ester_enumeration_for_chodera_lab_FEP-permuted-dockscores-x10789.sdf', 'conformer') cmd.set('all_states', 1) # DEBUG #cmd.load('nucleophilic_displacement_enumeration_for_FEP-sorted-x10789.mol2') #cmd.load('sprint1-winners.mol2') cmd.viewport(720, 720) cmd.orient('N3-ligand') cmd.turn('z', -90) # TODO: Shift camera instead cmd.turn('y', +20) # TODO: Shift camera instead cmd.zoom('N3-ligand') #cmd.clip('far', -10) cmd.move('y', +1) cmd.show('sticks', 'not hydrogen and *-ligand') # Hide all fragments cmd.deselect() cmd.disable('aminopyridines-*') cmd.disable('quinolones-*') cmd.disable('benzotriazoles-*') cmd.disable('fragment-*')
0.3, 0.3, 1.0, # RGB Color 1 0.3, 0.3, 1.0, # RGB Color 2 ] ) obj.extend( [ CONE, 0.0, 0.0, scale, # XYZ 1 0.0, 0.0, scale * 1.2, # XYZ 2 0.3 * scale, # Radius 1 0.0, # Radius 2 0.3, 0.3, 1.0, # RGB Color 1 0.3, 0.3, 1.0, # RGB Color 2 1.0, 1.0, # Caps 1 & 2 ] ) cmd.load_cgo(obj,'cgo_axes') # rotate the view cmd.turn('y',-45) cmd.turn('x',30) # zoom out a bit cmd.zoom('all', 2) # move the read clipping plane back a bit to brighten things up cmd.clip('far',-5)
self.norm[2 * a][2] = 0.0 self.norm[2 * a + 1][0] = self.norm[2 * a][0] self.norm[2 * a + 1][1] = self.norm[2 * a][1] self.norm[2 * a + 1][2] = self.norm[2 * a][2] def __call__(self): glColor3f(1.0, 1.0, 1.0) glVertexPointer(3, GL_FLOAT, 0, self.vert) glNormalPointer(GL_FLOAT, 0, self.norm) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_COLOR_ARRAY) glDrawArrays(GL_TRIANGLE_STRIP, 0, 126) def get_extent(self): return [[0.0, 0.0, -1.0], [6.3, 1.0, 1.0]] # load it into PyMOL cmd.load_callback(myCallback(), "gl02") # give us a nice view cmd.turn("z", 20) cmd.turn("y", 20) cmd.turn("x", 20)
def showCorr(self,ar): try: cmd.reinitialize() self.multiListBox1.focus() cmd.load(self.Ref,object="obj1") self.index=ar[0] self.selection_row=self.multiListBox1.get(self.index) self.selection_data=self.selection_row[0] self.rank=self.selection_data[0] self.zincId=self.selection_data[1] #Empty box2 self.multiListBox2.delete(0,END) file_type=".mol2" result_Filename=self.rank+ "_" +self.zincId+file_type log.info("Filename:'%s'" %result_Filename) i=0 j=0 k=0 line=() #timestamp_Folder=os.path.join(resultsFolder,timestamp_Done) file_Mol=os.path.join(self.timestamp_Folder,result_Filename) print file_Mol self.ref=() self.tar=() try: fh=open(file_Mol,"r") #handle possible exceptions cmd.load(file_Mol,object="obj2") except IOError: tkMessageBox.showinfo("No data found", "The result molecules were not written to the output") for block in iter(lambda: fh.readline(), ""): if i==1: if j==1: if not block=='\n': k=k+1 line=block.split() self.ref=self.ref+(line[1],) self.tar=self.tar+ (line[3],) self.multiListBox2.insert(END,*line) else: i=0 j=0 if "LiSiCA RESULTS" in block: i=1 if i==1: if "--------------" in block: j=1 log.info("Displayed the atom correspondence of the selected atom") if self.dimension.get()==2: cmd.set("grid_mode",value=1) cmd.set("grid_slot",value=1,selection="obj1") cmd.set("grid_slot",value=2,selection="obj2") cmd.align("obj1","obj2") elif self.dimension.get()==3: selection=[] for idx, item in enumerate(self.ref): selection.append("'obj1////" + self.ref[idx] + "'") selection.append("'obj2////" + self.tar[idx] + "'") fitCode="cmd.pair_fit(" + ",".join(selection) + ")" exec fitCode in globals(), locals() else: log.error("Dimension value is wrong") cmd.orient() cmd.turn("z", 90) except: pass
def pubimage_tmblr(*argumenthere, **kwd): '''Takes an image with the specified properties. The properties should be entered in the following order: ray_trace_mode, antialias, ray width, ray height, bg_color If not specified, then the properties default to ray_trace_mode (int 1-3) --> 3 antialias (int 0-2) --> 2 raynum1, raynum2 (int) --> ray 1200, 1200 bg_color (string) --> white ''' # The following is for debugging: # argumenthere[0] (int 1-3) --> ray_trace_mode (int) # argumenthere[1] (int 0-2) --> antialias (int) # argumenthere[2], argumenthere[3] (int) --> ray num1, num2 (int) # argumenthere[4] (string) --> bg_color (string) global iternum #Setting ray_trace_mode try: cmd.set('ray_trace_mode', value=int(argumenthere[0]), selection='', state=0, updates=1, log=0, quiet=1) except IndexError: cmd.set('ray_trace_mode', 3) #Setting antialias try: cmd.set('antialias', int(argumenthere[1]), selection='', state=0, updates=1, log=0, quiet=1) except IndexError: cmd.set('antialias', 2) #Setting bg_color try: cmd.bg_color(argumenthere[4]) except IndexError: cmd.bg_color('white') #CENTER IMAGE TAKING AND ROTATION #Ray the image try: cmd.ray(width=int(argumenthere[2]), height=int(argumenthere[3]), antialias=-1, angle=0.0, shift=0.0, renderer=-1, quiet=1, async=0) except IndexError: cmd.ray(width=1200, height=1200) #Save the Image try: cmd.png('molecule' + str(iternum) + 'center.png') except IndexError: cmd.png('molecule' + str(iternum) + 'center.png') cmd.turn('x', 90.0) #TOP-DOWN IMAGE TAKING AND ROTATION #Ray the image try: cmd.ray(width=int(argumenthere[2]), height=int(argumenthere[3]), antialias=-1, angle=0.0, shift=0.0, renderer=-1, quiet=1, async=0) except IndexError: cmd.ray(width=1200, height=1200) #Save the Image try: cmd.png('molecule' + str(iternum) + 'topdown.png') except IndexError: cmd.png('molecule' + str(iternum) + 'topdown.png') cmd.turn('x', -180.0) #BOTTOM-UP IMAGE TAKING AND ROTATION #Ray the image try: cmd.ray(width=int(argumenthere[2]), height=int(argumenthere[3]), antialias=-1, angle=0.0, shift=0.0, renderer=-1, quiet=1, async=0) except IndexError: cmd.ray(width=1200, height=1200) #Save the Image try: cmd.png('molecule' + str(iternum) + 'bottomup.png') except IndexError: cmd.png('molecule' + str(iternum) + 'bottomup.png') cmd.turn('x', 90.0) cmd.turn('y', 90.0) #LEFT IMAGE TAKING AND ROTATION #Ray the image try: cmd.ray(width=int(argumenthere[2]), height=int(argumenthere[3]), antialias=-1, angle=0.0, shift=0.0, renderer=-1, quiet=1, async=0) except IndexError: cmd.ray(width=1200, height=1200) #Save the Image try: cmd.png('molecule' + str(iternum) + 'left.png') except IndexError: cmd.png('molecule' + str(iternum) + 'left.png') cmd.turn('y', -180.0) #RIGHT IMAGE TAKING AND ROTATION #Ray the image try: cmd.ray(width=int(argumenthere[2]), height=int(argumenthere[3]), antialias=-1, angle=0.0, shift=0.0, renderer=-1, quiet=1, async=0) except IndexError: cmd.ray(width=1200, height=1200) #Save the Image try: cmd.png('molecule' + str(iternum) + 'right.png') except IndexError: cmd.png('molecule' + str(iternum) + 'right.png') cmd.turn('y', 90.0) iternum += 1
# -c from pymol import cmd print "BEGIN-LOG" print cmd.set_key('F1',lambda :cmd.turn('x',10)) print cmd.set_key('F12',lambda :cmd.turn('x',10)) print cmd.set_key('left',lambda :cmd.turn('x',10)) print cmd.set_key('right',lambda :cmd.turn('x',10)) print cmd.set_key('pgup',lambda :cmd.turn('x',10)) print cmd.set_key('pgdn',lambda :cmd.turn('x',10)) print cmd.set_key('home',lambda :cmd.turn('x',10)) print cmd.set_key('insert',lambda :cmd.turn('x',10)) print cmd.set_key('ALT-A',lambda :cmd.turn('y',10)) print cmd.set_key('CTRL-C',lambda :cmd.turn('z',10)) print cmd.set_key('SHFT-F1', lambda :cmd.turn('z',10)) print cmd.set_key('ALT-F1', lambda :cmd.turn('y',10)) print cmd.set_key('CTRL-F8', lambda :cmd.move('x',1)) print "END-LOG"
def growProtein(): cmd.mstop() cmd.mclear() cmd.mset() glb.update() objects = cmd.get_names('all') if 'protein' in objects: cmd.bg_color('black') # create the objects to be used in this movie cmd.create('helix', 'ss h and protein') cmd.create('sheets', 'ss s and protein') cmd.create('surface', objects[0]) cmd.mset('1', '1400') # dna and rna will be represented as sticks # to make them stand out from the protein if 'dna' in objects: glb.procolor('dna','sticks','cpk',None) if 'rna' in objects: glb.procolor('rna','sticks','cpk',None) # coloring the protein and secondary structures cmd.color('white', 'protein') cmd.color('purple', 'helix') cmd.color('teal', 'sheets') cmd.cartoon('loop', 'protein') cmd.cartoon('automatic', 'helix') cmd.cartoon('automatic', 'sheets') cmd.hide('all') cmd.show('cartoon', 'protein') #cmd.mdo(1,'hide cartoon, helix; hide cartoon, sheets;') cmd.util.mrock('2', '200', '90', '1', '1') cmd.mdo(201,'show cartoon, helix;') cmd.util.mrock('202', '400', '90', '1', '1') cmd.mdo(401,'show cartoon, sheets;') cmd.util.mrock('402', '600', '90', '1', '1') if 'ligands' in objects: cmd.color('hotpink', 'ligands') cmd.mdo(600, 'show spheres, ligands; show sticks, ligands;'+ ' set sphere_transparency = 0.5, ligands;') cmd.util.mroll('601', '800', '1', axis = "x") cmd.color('blue', 'surface') cmd.mview('store', '800') cmd.turn('z', 180) cmd.mview('store' , '1000') cmd.turn('z', 180) cmd.mdo(800, 'show surface, surface; '+ 'set transparency = 0.8, surface;') cmd.mdo(850,'set transparency = 0.7, surface;') cmd.mdo(900,'set transparency = 0.6, surface;') cmd.mdo(950,'set transparency = 0.5, surface;') cmd.mdo(1000,'set transparency = 0.4, surface;') cmd.mdo(1050,'set transparency = 0.3, surface;') cmd.mdo(1100,'set transparency = 0.2, surface;') cmd.mdo(1150,'set transparency = 0.1, surface;') cmd.mdo(1200,'set transparency = 0.0, surface;') cmd.mview('store', '1200') cmd.util.mrock('1201', '1399', '180', '1', '1') cmd.hide('everything', 'surface') cmd.hide('everything', 'helix') cmd.hide('everything', 'sheets') cmd.reset() cmd.orient() cmd.mdo(1400,'hide everything, all; show cartoon, protein;') cmd.mdo(1400,'mstop') cmd.mview('interpolate') cmd.rewind()
import os from pymol import cmd def produce_frame(): name = '/tmp/frame.png' cmd.png(name, ray=True, width=1920, height=1080) with open(name, 'rb') as frame: os.write(produce_frame.pipe, frame.read()) os.remove(name) produce_frame.pipe = os.open('my_pipe', os.O_WRONLY) #Rotate 90 degrees in x over 90 frames for i in range(90): cmd.turn('x', 1) produce_frame() #Rotate 360 degrees in y over 360 frames for i in range(360): cmd.turn('y', 1) produce_frame() #Rotate -90 degrees in x over 90 frames for i in range(90): cmd.turn('x', -1) produce_frame() os.close(produce_frame.pipe)
self.norm[2 * a + 1][0] = self.norm[2 * a][0] self.norm[2 * a + 1][1] = self.norm[2 * a][1] self.norm[2 * a + 1][2] = self.norm[2 * a][2] def __call__(self): glColor3f(1.0, 1.0, 1.0) glVertexPointer(3, GL_FLOAT, 0, self.vert) glNormalPointer(GL_FLOAT, 0, self.norm) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_COLOR_ARRAY) glDrawArrays(GL_TRIANGLE_STRIP, 0, 126) def get_extent(self): return [[0.0, 0.0, -1.0], [6.3, 1.0, 1.0]] # load it into PyMOL for b in range(0, 63): cmd.load_callback(myCallback(b), 'gl03', b + 1) # give us a nice view cmd.turn('z', 20) cmd.turn('y', 20) cmd.turn('x', 20) cmd.mplay()
""" A script that will execute a 360 degree spin of the structure, ray-tracing the structure at each interval and saving the image. """ from pymol import cmd import os.path FRAMES = 360 # How many frames to spread the spin over AXIS = 'y' # The axis about which to spin OUTPUT = 'turn_ray_images' # The output directory for images RAY_X = 1920 # The x-dimension of the image, 0 will use current window size RAY_Y = 1080 # The y-dimension of the image, 0 will use current window size os.mkdir(OUTPUT) for i in xrange(FRAMES): cmd.turn(AXIS, 360.0 / FRAMES) cmd.ray(width=RAY_X, height=RAY_Y) frame_name = '{0}.png'.format(str(i).zfill(4)) cmd.png(os.path.join(os.getcwd(), OUTPUT, frame_name))
self.norm[2*a+1][1]=self.norm[2*a][1] self.norm[2*a+1][2]=self.norm[2*a][2] def __call__(self): glColor3f(1.0,1.0,1.0) glVertexPointer(3,GL_FLOAT, 0,self.vert) glNormalPointer(GL_FLOAT,0,self.norm) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_COLOR_ARRAY) glDrawArrays(GL_TRIANGLE_STRIP,0,126) def get_extent(self): return [[0.0,0.0,-1.0], [6.3,1.0,1.0]] # load it into PyMOL for b in range(0,63): cmd.load_callback(myCallback(b),'gl03',b+1) # give us a nice view cmd.turn('z',20) cmd.turn('y',20) cmd.turn('x',20) cmd.mplay()
def showCorr(self, ar): try: cmd.reinitialize() self.multiListBox1.focus() cmd.load(self.Ref, object="obj1") self.index = ar[0] self.selection_row = self.multiListBox1.get(self.index) self.selection_data = self.selection_row[0] self.rank = self.selection_data[0] self.zincId = self.selection_data[1] #Empty box2 self.multiListBox2.delete(0, END) file_type = ".mol2" result_Filename = self.rank + "_" + self.zincId + file_type log.info("Filename:'%s'" % result_Filename) i = 0 j = 0 k = 0 line = () #timestamp_Folder=os.path.join(resultsFolder,timestamp_Done) file_Mol = os.path.join(self.timestamp_Folder, result_Filename) print file_Mol self.ref = () self.tar = () try: fh = open(file_Mol, "r") #handle possible exceptions cmd.load(file_Mol, object="obj2") except IOError: tkMessageBox.showinfo( "No data found", "The result molecules were not written to the output") for block in iter(lambda: fh.readline(), ""): if i == 1: if j == 1: if not block == '\n': k = k + 1 line = block.split() self.ref = self.ref + (line[1], ) self.tar = self.tar + (line[3], ) self.multiListBox2.insert(END, *line) else: i = 0 j = 0 if "LiSiCA RESULTS" in block: i = 1 if i == 1: if "--------------" in block: j = 1 log.info("Displayed the atom correspondence of the selected atom") if self.dimension.get() == 2: cmd.set("grid_mode", value=1) cmd.set("grid_slot", value=1, selection="obj1") cmd.set("grid_slot", value=2, selection="obj2") cmd.align("obj1", "obj2") elif self.dimension.get() == 3: selection = [] for idx, item in enumerate(self.ref): selection.append("'obj1////" + self.ref[idx] + "'") selection.append("'obj2////" + self.tar[idx] + "'") fitCode = "cmd.pair_fit(" + ",".join(selection) + ")" exec fitCode in globals(), locals() else: log.error("Dimension value is wrong") cmd.orient() cmd.turn("z", 90) except: pass
def testTurn(self): cmd.turn('z', 90) v = cmd.get_view() self.assertArrayEqual(v[:9], [0.,1.,0.,-1.,0.,0.,0.,0.,1.], delta=1e-3)
setup_pymol() cmd.load('../../input-files/Cathepsin.pdb') # Load the PDB file initial_representations() set_up_scenes() scenes_to_frames() # Apart from moving between scenes, independent camera movements can be added to the animation # One of them, the zoom (cmd.zoom) was already used # Two other movements are rotation (cmd.turn) and panning (cmd.move) # Let's add a rotation to the global view and a panning to the close-up to make them more interesting cmd.scene( '001', animate=0 ) # Select the first scene again (we need the camera view as a starting point) cmd.turn('y', -40) # Turn the camera 40 degrees left around the y-axis cmd.mview('store', 80) # Store the changed view/assign it to frame 60 cmd.turn( 'y', 40) # Turn the camera 40 degrees in the other direction around the y-axis cmd.mview('store', 140) # Assign the view to frame 120 cmd.scene('002', animate=0) # Select the second scene cmd.move('x', 5) # Move along the x-axis cmd.mview('store', 320) # Assign the view to frame 320 # Rewind and turn off ray-tracing cmd.rewind() # Rewind the movie to frame 1 cmd.set('ray_trace_frames', 0) # Turn ray-tracing for frames off # Running the script, you should now see the additional camera movements additional to the scene transitions
def FocalBlur(aperture=2.0, samples=10, ray=0, width=0, height=0): ''' DESCRIPTION Creates fancy figures by introducing a focal blur to the image. The object at the origin will be in focus. AUTHOR Jarl Underhaug University of Bergen jarl_dot_underhaug_at_gmail_dot_com Updates by Jason Vertrees and Thomas Holder USAGE FocalBlur aperture=float, samples=int, ray=0/1, width=int, height=int EXAMPELS FocalBlur aperture=1, samples=100 FocalBlur aperture=2, samples=100, ray=1, width=600, height=400 ''' # Formalize the parameter types ray = (ray in ("True", "true", 1, "1")) aperture, samples = float(aperture), int(samples) width, height = int(width), int(height) # Create a temporary directory tmpdir = mkdtemp() # Get the orientation of the protein and the light light = cmd.get('light')[1:-1] light = [float(s) for s in light.split(',')] view = cmd.get_view() # Rotate the protein and the light in order to create the blur for frame in range(samples): # Angles to rotate protein and light # Populate angles as Fermat's spiral theta = frame * pi * 110.0 / 144.0 radius = 0.5 * aperture * sqrt(frame / float(samples - 1)) x = cos(theta) * radius y = sin(theta) * radius xr = x / 180.0 * pi yr = y / 180.0 * pi # Rotate the protein cmd.turn('x', x) cmd.turn('y', y) # Rotate the light ly = light[1] * cos(xr) - light[2] * sin(xr) lz = light[2] * cos(xr) + light[1] * sin(xr) lx = light[0] * cos(yr) + lz * sin(yr) lz = lz * cos(yr) - lx * sin(yr) cmd.set('light', [lx, ly, lz]) curFile = "%s/frame-%04d.png" % (tmpdir, frame) print("Created frame %i/%i (%0.0f%%)" % (frame + 1, samples, 100 * (frame + 1) / samples)) # Save the image to temporary directory if ray: cmd.ray(width, height) cmd.png(curFile) else: cmd.png(curFile, quiet=1) # Create the average/blured image try: avg = Image.blend(avg, Image.open(curFile), 1.0 / (frame + 1)) except: avg = Image.open(curFile) # Return the protein and the light to the original orientation cmd.set('light', light) cmd.set_view(view) # Load the blured image avg.save('%s/avg.png' % (tmpdir)) cmd.load('%s/avg.png' % (tmpdir)) # Delete the temporary files rmtree(tmpdir)
cmd.mview('store', 250) cmd.mview('store', 400) setup_pymol() cmd.load('../../input-files/Cathepsin.pdb') # Load the PDB file initial_representations() set_up_scenes() scenes_to_frames() # Apart from moving between scenes, independent camera movements can be added to the animation # One of them, the zoom (cmd.zoom) was already used # Two other movements are rotation (cmd.turn) and panning (cmd.move) # Let's add a rotation to the global view and a panning to the close-up to make them more interesting cmd.scene('001', animate=0) # Select the first scene again (we need the camera view as a starting point) cmd.turn('y', -40) # Turn the camera 40 degrees left around the y-axis cmd.mview('store', 80) # Store the changed view/assign it to frame 60 cmd.turn('y', 40) # Turn the camera 40 degrees in the other direction around the y-axis cmd.mview('store', 140) # Assign the view to frame 120 cmd.scene('002', animate=0) # Select the second scene cmd.move('x', 5) # Move along the x-axis cmd.mview('store', 320) # Assign the view to frame 320 # Rewind and turn off ray-tracing cmd.rewind() # Rewind the movie to frame 1 cmd.set('ray_trace_frames', 0) # Turn ray-tracing for frames off # Running the script, you should now see the additional camera movements additional to the scene transitions # Note that there are also transitions back to original scene 001 and scene 002 views after the movements
def make_figure(output='', mode='',size=900,opaque='transparent'): """ AUTHOR Martin Christen DESCRIPTION "make_figure" creates publication-quality figures of the current scene. It understands several predefined "modes" and sizes. USAGE make_figure filename [, mode] [, size (default=900 pixels)] [,opaque] ARGUMENTS mode = string: type of desired figure (single, fb, sides, stereo or -nothing-) size = integer: size of the figure in pixels OR # panels (if <= 12) opaque = specify an opaque background. By default, the script makes the background transparent. EXAMPLES make_figure output make_figure output, single, 975, opaque make_figure output, fb, 2 make_figure output, sides,4 make_figure output, stereo NOTES "single" mode makes a single 300 dpi figure "fb" mode makes TWO 300 dpi figure ("front" and "back", rotating by 180 degrees about y) "sides" mode makes FOUR 300 dpi figures ("front" "left" "right" and back, rotating by 90 degrees clockwise about y) "stereo" generates two 300 dpi, 750 px figures ("L" and "R", to be combined as a stereo image) If you specify the stereo mode, the size argument is IGNORED. If no mode argument is given, the script generates quick figures for general use: TWO figures (front and back) at 300 x 300 px, 72 dpi. Size is interpreted as pixels, except if the number is ridiculously small (<=12), in which case the script as "number of panels" to make. Edit the script manually to define corresponding values. """ #define sizes here (in pixels) panel1 = 1800 panel2 = 1350 panel3 = 900 panel4 = 900 panel5 = 750 panel6 = 750 panel7 = 675 panel8 = 675 panel9 = 600 panel10 = 585 panel11 = 585 panel12 = 585 #verify size is an integer number and convert to pixels size = int(size) if size > 12: pixels = size elif size == 1: pixels = panel1 elif size == 2: pixels = panel2 elif size == 3: pixels = panel3 elif size == 4: pixels = panel4 elif size == 5: pixels = panel5 elif size == 6: pixels = panel6 elif size == 7: pixels = panel7 elif size == 8: pixels = panel8 elif size == 9: pixels = panel9 elif size == 10: pixels = panel10 elif size == 11: pixels = panel11 elif size == 3: pixels = panel12 #change background cmd.unset('opaque_background') if opaque == 'opaque': cmd.set('opaque_background') #apply mode if output == '': print 'no output filename defined\n' print 'try: \'make_figure filename\'' return -1 # abort if no output file name given if mode =='': cmd.set('surface_quality',1) cmd.set('opaque_background') cmd.png(output+"_back_quick",300,300,dpi=72) cmd.turn('y',180) cmd.png(output+"_front_quick",300,300,dpi=72) cmd.turn('y',180) cmd.set('surface_quality',0) # make front and back figures for quick mode elif mode == 'single': cmd.set('surface_quality',1) cmd.set('ray_shadow',0) cmd.ray(pixels, pixels) cmd.png(output, dpi=300) cmd.set('surface_quality',0) # make a figure for single mode elif mode == 'fb': cmd.set('surface_quality',1) cmd.set('ray_shadow',0) cmd.ray(pixels, pixels) cmd.png(output+"_front", dpi=300) cmd.turn('y',180) cmd.ray(pixels, pixels) cmd.png(output+"_back", dpi=300) cmd.turn('y',180) cmd.set('surface_quality',0) # make front and back figures for single mode elif mode == 'sides': cmd.set('surface_quality',1) cmd.set('ray_shadow',0) cmd.ray(pixels, pixels) cmd.png(output+"_1", dpi=300) cmd.turn('y',90) cmd.ray(pixels, pixels) cmd.png(output+"_2", dpi=300) cmd.turn('y',90) cmd.ray(pixels, pixels) cmd.png(output+"_3", dpi=300) cmd.turn('y',90) cmd.ray(pixels, pixels) cmd.png(output+"_4", dpi=300) cmd.turn('y',90) cmd.set('surface_quality',0) # make front and back figures for single mode elif mode == 'stereo': cmd.set('surface_quality',1) cmd.set('ray_shadow',0) cmd.ray(750, 750, angle=-3) cmd.png(output+"_R", dpi=300) cmd.ray(750, 750, angle=3) cmd.png(output+"_L", dpi=300)
lloc=lhand.point rloc=rhand.point # Distance between hands on each axis x=lloc[0]-rloc[0] y=lloc[1]-rloc[1] z=lloc[2]-rloc[2] # Degrees to turn horizontally or vertically hor=degrees(round(atan2(z, x), 2))-acchor ver=degrees(round(atan2(x, y), 2))-accver acchor+=hor accver+=ver cmd.turn('y', hor) cmd.turn('z', ver) # Zoom selection handist=sqrt(x*x + y*y + z*z) # print handist zomh=handist/5-acczom # print zomh cmd.move('z', zomh) acczom+=zomh # Refresh screen and wait for next iteration cmd.refresh() time.sleep(0.05)
cmd.set('transparency', 0.65) cmd.set('surface_mode', 3) cmd.set('surface_color', 'white') #cmd.show('lines', '(not hydrogen) within 5 of ligand') #cmd.show('surface', 'tcr') # Create one-to-one mapping between states and frames. cmd.mset("1 -%d" % cmd.count_states()) # Zoom viewport #cmd.zoom('complex') #cmd.orient('complex') cmd.zoom('ligand') cmd.orient('ligand') cmd.turn('x', -90) # Render movie frame_prefix = 'frames/frame' cmd.set('ray_trace_frames', 1) cmd.set('ray_trace_frames', 0) # DEBUG for iteration in range(niterations): print "rendering frame %04d / %04d" % (iteration+1, niterations) cmd.frame(iteration+1) cmd.set('stick_transparency', float(ncfile.variables['states'][iteration, replica]) / float(nstates-1)) cmd.png(frame_prefix + '%04d.png' % (iteration), ray=True) #cmd.mpng(frame_prefix, iteration+1, iteration+1) #cmd.load_model(model, 'complex') cmd.set('ray_trace_frames', 0)
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()