def makeMovie(numClusts, frameRate): real = int(numClusts)+1; fr = int(frameRate) movieSetup = "1 x" + str(real*fr) cmd.mset(movieSetup) #Load in all the system data. for x in range(0, real): # load the next system. clustName = "system-" + str(x) system = clustName + ".xyz" cmd.load(system) # Set the sphere scale and view cmd.set("sphere_scale","0.5","all") #Set the right view cmd.set_view("0.910306633, -0.382467061, 0.158301696, 0.326706469, 0.898694992, 0.292592257, -0.254171938, -0.214630708, 0.943043232, 0.000000000, 0.000000000, -99.425979614, 10.461934090, 13.087766647, 11.786855698, 80.009132385, 118.842796326, -20.000000000") #Set all the frame data for x in range(0, real): # set the current frame. frameNum = (x*fr)+1 cmd.frame(frameNum) clustName = "system-" + str(x) movieState = "hide; show spheres, " + clustName cmd.mdo(frameNum,movieState) cmd.mview("store") cmd.mview("reinterpolate") cmd.mplay()
def testGetMovieLocked(self): self.assertEqual(cmd.get_movie_locked(), 0) cmd.mset('1x1') cmd.mdo(1, 'cmd.color("blue")') s = cmd.get_session() cmd.set_session(s) self.assertEqual(cmd.get_movie_locked(), 1) cmd.set('security', 0) cmd.set_session(s) self.assertEqual(cmd.get_movie_locked(), 0)
def peak_tour(selection="mol", zbuff="6", framespermove=45, stallframes=5): # zbuff is how far to stand back from the selection # framespermove is how many frames to spend at each peak of the selection # stallframes is how many frames to linger, unmoving before proceeding to next peak framespermove = int(framespermove) stallframes = int(stallframes) # clear various movie memories, frames, caches cmd.do("mclear") cmd.do("mvClear") cmd.do("mset") cmd.do("frame 1") # fetch model to find how many waypoints we will be visiting model = cmd.get_model(selection).atom stopovers = len(model) # set up some landmarks within our visit to each peak so can divvy up the rotation # or other movements easily for waypoints in range(stopovers): startframe = (waypoints) * framespermove + 1 + ( waypoints) * stallframes mark1 = int(startframe + framespermove / 8) mark2 = int(startframe + framespermove * 3 / 8) mark3 = int(startframe + framespermove / 2) mark4 = int(startframe + framespermove * 5 / 8) mark5 = int(startframe + framespermove * 7 / 8) endframe = startframe + framespermove # This section describes whatever "dance" you want to do at each waypoint # you can use the mark1-5 defined above to divvy up the time at this waypoint # in this case it's 90 degree turn on y and x at each frame lit1 = "mvSinturn %s-%s,y,90" % (startframe, mark3) cmd.do(lit1) lit2 = "mvSinturn %s-%s,x,90" % (mark3, endframe) cmd.do(lit2) cmd.do("movie") # once you've defined the movie with "movie" (above) can then do the mdo # commands to set the views at various points to be sure we go from one atom # to the next. These mdo commands would be wiped out if the "movie" or "mset" # commands were run after they are for waypoints in range(stopovers): startframe = (waypoints) * framespermove + 1 + ( waypoints) * stallframes endframe = startframe + framespermove zoomview = "zoom /%s///%s/, %s" % (selection, model[waypoints].resi, zbuff) cmd.mdo(startframe + 1, zoomview)
def chain_pull(): cmd.mstop cmd.mclear coor = { 2:'[0,0,0]', 3:'[75,0,0]', 4:'[0,75,0]', 5:'[0,0,75]', 6:'[-75,0,0]', 7:'[0,-75,0]', 8:'[0,0,-75]', 9:'[75,75,0]', 10:'[-75,-75,0]', 11:'[0,75,75]', 12:'[0,-75,-75]', 13:'[75,0,75]', 14:'[-75,0,-75]', 15:'[75,75,75]', 16:'[-75,-75,-75]', 17:'[75,-75,0]', 18:'[-75,75,0]', 19:'[0,75,-75]', 20:'[0,-75,75]', 21:'[75,0,-75]', 22:'[-75,0,75]', 23:'[75,75,-75]', 24:'[75,-75,75]', 25:'[-75,75,75]', 26:'[-75,-75,75]',27:'[75,-75,-75]',28:'[-75,-75,-75]'} chainPullList = chain_contact() if chainPullList == False: return False chainPullLen = len(chainPullList) frames = 1+chainPullLen+172+chainPullLen+172 cmd.mset('1','%s'%frames) i = chainPullLen+2 for h in range(2,i): print 'translate %s,%s'%(coor[h],chainPullList[h-2]) cmd.mdo(h,'translate %s,%s'%(coor[h],chainPullList[h-2])) cmd.mdo(i,'zoom all') util.mroll(i+1,i+171,1) i += 172 for g in range(i,chainPullLen+i): c = coor[(g-i)+2].replace('7','-7').replace('--','-') cmd.mdo(g,'translate %s,%s'%(c,chainPullList[g-i])) g = chainPullLen+i cmd.mdo(g,'zoom all') util.mroll(g+1,g+171,1)
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 make_all(): #make the whole movie global views global frames global models #first get total number of frames ftot = 0 i = 0 setcommand = "" for nframes in frames[:-1]: ftot += nframes if models.has_key(i): setcommand += " " + models[i] + " " else: setcommand += " 1 x%i" % nframes i += 1 #initialize movie #cmd.mset("1 x%i" % ftot) #cmd.mset("1 x50 1 -30 30 x20") cmd.mset( setcommand ) #loop through views start_view = views[0][:] i = 0 first_frame = 1 for view in views[1:]: end_view = view[:] if settings.has_key(i): movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] ) elif fades.has_key(i): movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] ) else: movs.animate_transition( start_view, end_view, frames[i], first_frame ) #add an action if actions.has_key(i): mdo_cmd = actions[i]#+";set_view ("+str( views[i] )+")" print mdo_cmd cmd.mdo(first_frame, mdo_cmd) first_frame += frames[i] i += 1 start_view = end_view[:] cmd.frame(1)
def make_all(): #make the whole movie global views global frames global models #first get total number of frames ftot = 0 setcommand = "" for i, nframes in enumerate(frames[:-1]): ftot += nframes if i in models: setcommand += " " + models[i] + " " else: setcommand += " 1 x%i" % nframes #initialize movie #cmd.mset("1 x%i" % ftot) #cmd.mset("1 x50 1 -30 30 x20") cmd.mset(setcommand) #loop through views start_view = views[0][:] first_frame = 1 for i, view in enumerate(views[1:]): end_view = view[:] if i in settings: movs.animate_transition(start_view, end_view, frames[i], first_frame, settings[i]) elif i in fades: movs.animate_transition(start_view, end_view, frames[i], first_frame, fades[i]) else: movs.animate_transition(start_view, end_view, frames[i], first_frame) #add an action if i in actions: mdo_cmd = actions[i] #+";set_view ("+str( views[i] )+")" print mdo_cmd cmd.mdo(first_frame, mdo_cmd) first_frame += frames[i] start_view = end_view[:] cmd.frame(1)
def make_all(): # make the whole movie global views global frames global models # first get total number of frames ftot = 0 setcommand = "" for i, nframes in enumerate(frames[:-1]): ftot += nframes if i in models: setcommand += " " + models[i] + " " else: setcommand += " 1 x%i" % nframes # initialize movie # cmd.mset("1 x%i" % ftot) # cmd.mset("1 x50 1 -30 30 x20") cmd.mset(setcommand) # loop through views start_view = views[0][:] first_frame = 1 for i, view in enumerate(views[1:]): end_view = view[:] if i in settings: movs.animate_transition(start_view, end_view, frames[i], first_frame, settings[i]) elif i in fades: movs.animate_transition(start_view, end_view, frames[i], first_frame, fades[i]) else: movs.animate_transition(start_view, end_view, frames[i], first_frame) # add an action if i in actions: mdo_cmd = actions[i] # +";set_view ("+str( views[i] )+")" print mdo_cmd cmd.mdo(first_frame, mdo_cmd) first_frame += frames[i] start_view = end_view[:] cmd.frame(1)
def testMpng(self, modal): import glob, os shape2 = (100, 100) cmd.mset("1x4") cmd.mdo(1, 'bg_color red') cmd.mdo(3, 'bg_color blue') with testing.mkdtemp() as dirname: cmd.mpng(os.path.join(dirname, 'image'), width=shape2[0], height=shape2[1]) filenames = glob.glob(os.path.join(dirname, 'image*.png')) filenames.sort() self.assertEqual(4, len(filenames)) img = self.get_imagearray(filenames[0]) self.assertEqual(img.shape[:2], shape2) self.assertImageHasColor('red', img) img = self.get_imagearray(filenames[-1]) self.assertEqual(img.shape[:2], shape2) self.assertImageHasColor('blue', img)
def test_mdo(self): self._load_example() cmd.mset('1x3') cmd.mdo(1, 'disable m1') cmd.mdo(2, 'enable m1') cmd.mdo(3, 'enable g1') with testing.mkdtemp() as tempdir: # export prefix = os.path.join(tempdir, 'frame') cmd.mpng(prefix, width=100, height=100) img = self.get_imagearray(prefix + '0001.png') self.assertImageHasNotColor('red', img) self.assertImageHasColor('blue', img) img = self.get_imagearray(prefix + '0002.png') self.assertImageHasNotColor('red', img) self.assertImageHasColor('blue', img) img = self.get_imagearray(prefix + '0003.png') self.assertImageHasColor('red', img) self.assertImageHasColor('blue', img)
def reps(self,cleanup=0): rep_list = [ "lines","sticks","spheres","surface","mesh","dots","ribbon","cartoon" ] try: if not cleanup: cmd.disable() cmd.set("suspend_updates",1,quiet=1) cmd.load("$PYMOL_DATA/demo/pept.pdb","rep1") cmd.alter("rep1///1-5+8-13/","ss='S'") cmd.cartoon("auto") cmd.hide("everything","rep1") for a in range(2,9): cmd.create("rep%d"%a,"rep1") for x, y in enumerate(rep_list, 1): cmd.show(x, "rep%d" % y) cmd.reset() cmd.zoom("rep1",24) util.cbay("rep2") util.cbac("rep3") util.cbas("rep4") util.cbab("rep5") util.cbaw("rep6") util.cbay("rep8") cmd.set("suspend_updates",0,quiet=1) scale=0.5 for b in range(1,20): cmd.set("suspend_updates",0,quiet=1) cmd.refresh() cmd.set("suspend_updates",1,quiet=1) xt=-3.2 yt=1.6 for a in range(1,5): cmd.translate([xt*scale,yt*scale,0],object="rep%d"%a,camera=0) xt=xt+2 yt=-yt xt=-3.2 for a in range(5,9): cmd.translate([xt*scale,yt*scale,0],object="rep%d"%a,camera=0) xt=xt+2 for a in range(1,9): cmd.origin("rep%d"%a,object="rep%d"%a) cmd.mset("1") st = ' '.join(map(lambda x,y:"rotate angle=-3,object=rep%d,axis=%s;"%(x,y),list(range(1,9)), ['x','y','x','y','x','y','x','y'])) cmd.mdo(1,st) cmd.set("suspend_updates",0,quiet=1) cmd.mplay() cgo = [] axes = [[4.5,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]] c = 1 for a in rep_list: ext = cmd.get_extent("rep%d"%c) pos = [(ext[0][0]+ext[1][0])/2, (ext[0][1]+ext[1][1])/2+14, (ext[0][2]+ext[1][2])/2] c = c + 1 pos[0]=pos[0]-(measure_text(plain,a,axes)/2) wire_text(cgo,plain,pos,a,axes) cmd.set("cgo_line_width",1.5) cmd.set("auto_zoom",0) cmd.load_cgo(cgo,'reps') cmd.set("auto_zoom",1) else: cmd.delete("rep*") cmd.mset() cmd.mstop() except: traceback.print_exc()
def surface_cartoon(): glb.update() cmd.mstop() cmd.mclear() cmd.mset('1', '60') cmd.hide('everything') objects = cmd.get_names('all') glb.procolor(None,show_all=('cartoon','surface')) cmd.set("cartoon_fancy_helices", "1") cmd.set("cartoon_fancy_sheets", "1") cmd.mdo(1,'set transparency = 0.75, all;') cmd.mdo(2,'set transparency = 0.7, all;') cmd.mdo(3,'set transparency = 0.65, all;') cmd.mdo(4,'set transparency = 0.6, all;') cmd.mdo(5,'set transparency = 0.55, all;') cmd.mdo(6,'set transparency = 0.5, all;') cmd.mdo(7,'set transparency = 0.45, all;') cmd.mdo(8,'set transparency = 0.4, all;') cmd.mdo(9,'set transparency = 0.35, all;') cmd.mdo(10,'set transparency = 0.3, all;') cmd.mdo(11,'set transparency = 0.25, all;') cmd.mdo(12,'set transparency = 0.2, all;') cmd.mdo(13,'set transparency = 0.15, all;') cmd.mdo(14,'set transparency = 0.1, all;') cmd.mdo(15,'set transparency = 0.05, all;') cmd.mdo(16,'set transparency = 0, all;') cmd.mdo(17,'set transparency = 0, all;') cmd.mdo(19,'set transparency = 0, all;') cmd.mdo(20,'set transparency = 0, all;') cmd.mdo(21,'set transparency = 0, all;') cmd.mdo(22,'set transparency = 0, all;') cmd.mdo(23,'set transparency = 0, all;') cmd.mdo(24,'set transparency = 0, all;') cmd.mdo(25,'set transparency = 0, all;') cmd.mdo(26,'set transparency = 0, all;') cmd.mdo(27,'set transparency = 0, all;') cmd.mdo(28,'set transparency = 0, all;') cmd.mdo(29,'set transparency = 0.05, all;') cmd.mdo(30,'set transparency = 0.1, all;') cmd.mdo(31,'set transparency = 0.15, all;') cmd.mdo(32,'set transparency = 0.2, all;') cmd.mdo(33,'set transparency = 0.25, all;') cmd.mdo(34,'set transparency = 0.3, all;') cmd.mdo(35,'set transparency = 0.35, all;') cmd.mdo(36,'set transparency = 0.4, all;') cmd.mdo(37,'set transparency = 0.45, all;') cmd.mdo(38,'set transparency = 0.5, all;') cmd.mdo(39,'set transparency = 0.55, all;') cmd.mdo(40,'set transparency = 0.6, all;') cmd.mdo(41,'set transparency = 0.65, all;') cmd.mdo(42,'set transparency = 0.7, all;') cmd.mdo(43,'set transparency = 0.75, all;') cmd.mdo(44,'set transparency = 0.8, all;') cmd.mdo(45,'set transparency = 0.85, all;') cmd.mdo(46,'set transparency = 0.9, all;') cmd.mdo(47,'set transparency = 0.9, all;') cmd.mdo(48,'set transparency = 0.9, all;') cmd.mdo(49,'set transparency = 0.85, all;') cmd.mdo(50,'set transparency = 0.85, all;') cmd.mdo(51,'set transparency = 0.85, all;') cmd.mdo(52,'set transparency = 0.85, all;') cmd.mdo(53,'set transparency = 0.85, all;') cmd.mdo(54,'set transparency = 0.85, all;') cmd.mdo(55,'set transparency = 0.85, all;') cmd.mdo(56,'set transparency = 0.85, all;') cmd.mdo(57,'set transparency = 0.85, all;') cmd.mdo(58,'set transparency = 0.85, all;') cmd.mdo(59,'set transparency = 0.85, all;') cmd.mdo(60,'set transparency = 0.8, all;')
def show_transition(start_index=0, end_index=0): #show the transition from the current view to the next view global frames global views global cur_index global actions global models if( start_index == 0 and end_index == 0 ): if cur_index >= len(views)-1: print "Current view is last in sequence." return start_index=cur_index end_index=cur_index+1 else: start_index = int(start_index) end_index = int(end_index) ftot = 0 setcommand = "" i = start_index for nframes in frames[start_index:end_index]: #ftot += nframes if models.has_key(i): setcommand += " " + models[i] + " " else: setcommand += " 1 x%i" % nframes i += 1 # cmd.mset("1 x%i" % ftot) cmd.mset( setcommand ) start_frame = 1 #first do all actions that happen up to this point to make sure #things look the way they should first_action = "" for i in range( 0, start_index ): if actions.has_key(i): first_action += actions[i] + ';' #print "Executing %s from actions %d" % (actions[i],i) #cmd.do( actions[i] ) if settings.has_key(i): settingName, selection, startVal, endVal = settings[i] action = "set %s, %f, %s;" % (settingName, endVal, selection) first_action += action #print "Executing %s from settings %d" % (action,i) #cmd.do( action ) if fades.has_key(i): startVisSelection, endVisSelection, sticksOnly = fades[i] action = "set stick_transparency, 0, %s; set stick_transparency, 1, %s;" % (endVisSelection, startVisSelection) first_action += action #print "Executing %s from fades %d" % (action, i) #cmd.do( action ) for i in range( start_index, end_index ): if settings.has_key(i): movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] ) elif fades.has_key(i): movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] ) else: movs.animate_transition( views[i], views[i+1], frames[i], start_frame ) #add an action if start_frame == 1: mdo_cmd = first_action if actions.has_key(i): mdo_cmd += actions[i]+";" #mdo_cmd += "set_view("+str(views[i])+")" print mdo_cmd cmd.mdo(start_frame, mdo_cmd) elif actions.has_key(i): mdo_cmd = actions[i]+";set_view("+str(views[i])+")" cmd.mdo(start_frame, mdo_cmd) #print mdo_cmd start_frame += frames[i] cmd.frame(1) cmd.mplay()
def surface_stick(): '''surface over stick movie''' glb.update() cmd.mstop() cmd.mclear() cmd.mset() cmd.mset('1', '60') glb.procolor(None,show_all=('sticks','surface')) cmd.mdo(1,'set transparency = 0.75, all;') cmd.mdo(2,'set transparency = 0.7, all;') cmd.mdo(3,'set transparency = 0.65, all;') cmd.mdo(4,'set transparency = 0.6, all;') cmd.mdo(5,'set transparency = 0.55, all;') cmd.mdo(6,'set transparency = 0.5, all;') cmd.mdo(7,'set transparency = 0.45, all;') cmd.mdo(8,'set transparency = 0.4, all;') cmd.mdo(9,'set transparency = 0.35, all;') cmd.mdo(10,'set transparency = 0.3, all;') cmd.mdo(11,'set transparency = 0.25, all;') cmd.mdo(12,'set transparency = 0.2, all;') cmd.mdo(13,'set transparency = 0.15, all;') cmd.mdo(14,'set transparency = 0.1, all;') cmd.mdo(15,'set transparency = 0.05, all;') cmd.mdo(16,'set transparency = 0, all;') cmd.mdo(17,'set transparency = 0, all;') cmd.mdo(19,'set transparency = 0, all;') cmd.mdo(20,'set transparency = 0, all;') cmd.mdo(21,'set transparency = 0, all;') cmd.mdo(22,'set transparency = 0, all;') cmd.mdo(23,'set transparency = 0, all;') cmd.mdo(24,'set transparency = 0, all;') cmd.mdo(25,'set transparency = 0, all;') cmd.mdo(26,'set transparency = 0, all;') cmd.mdo(27,'set transparency = 0, all;') cmd.mdo(28,'set transparency = 0, all;') cmd.mdo(29,'set transparency = 0.05, all;') cmd.mdo(30,'set transparency = 0.1, all;') cmd.mdo(31,'set transparency = 0.15, all;') cmd.mdo(32,'set transparency = 0.2, all;') cmd.mdo(33,'set transparency = 0.25, all;') cmd.mdo(34,'set transparency = 0.3, all;') cmd.mdo(35,'set transparency = 0.35, all;') cmd.mdo(36,'set transparency = 0.4, all;') cmd.mdo(37,'set transparency = 0.45, all;') cmd.mdo(38,'set transparency = 0.5, all;') cmd.mdo(39,'set transparency = 0.55, all;') cmd.mdo(40,'set transparency = 0.6, all;') cmd.mdo(41,'set transparency = 0.65, all;') cmd.mdo(42,'set transparency = 0.7, all;') cmd.mdo(43,'set transparency = 0.75, all;') cmd.mdo(44,'set transparency = 0.8, all;') cmd.mdo(45,'set transparency = 0.85, all;') cmd.mdo(46,'set transparency = 0.9, all;') cmd.mdo(47,'set transparency = 0.9, all;') cmd.mdo(48,'set transparency = 0.9, all;') cmd.mdo(49,'set transparency = 0.85, all;') cmd.mdo(50,'set transparency = 0.85, all;') cmd.mdo(51,'set transparency = 0.85, all;') cmd.mdo(52,'set transparency = 0.85, all;') cmd.mdo(53,'set transparency = 0.85, all;') cmd.mdo(54,'set transparency = 0.85, all;') cmd.mdo(55,'set transparency = 0.85, all;') cmd.mdo(56,'set transparency = 0.85, all;') cmd.mdo(57,'set transparency = 0.85, all;') cmd.mdo(58,'set transparency = 0.85, all;') cmd.mdo(59,'set transparency = 0.85, all;') cmd.mdo(60,'set transparency = 0.8, all;')
def movsetz(event): a = int(scriptent.get()) +1 scriptent.delete(0,100000) scriptent.insert(0,a) cmd.mdo( scriptent.get(), "move z," + entmz.get())
def show_transition(start_index=0, end_index=0): #show the transition from the current view to the next view global frames global views global cur_index global actions global models if start_index == 0 and end_index == 0: if cur_index >= len(views) - 1: print "Current view is last in sequence." return start_index = cur_index end_index = cur_index + 1 else: start_index = int(start_index) end_index = int(end_index) ftot = 0 setcommand = "" i = start_index for nframes in frames[start_index:end_index]: #ftot += nframes if i in models: setcommand += " " + models[i] + " " else: setcommand += " 1 x%i" % nframes i += 1 # cmd.mset("1 x%i" % ftot) cmd.mset(setcommand) start_frame = 1 #first do all actions that happen up to this point to make sure #things look the way they should first_action = "" for i in range(start_index): if i in actions: first_action += actions[i] + ';' #print "Executing %s from actions %d" % (actions[i],i) #cmd.do( actions[i] ) if i in settings: settingName, selection, startVal, endVal = settings[i] action = "set %s, %f, %s;" % (settingName, endVal, selection) first_action += action #print "Executing %s from settings %d" % (action,i) #cmd.do( action ) if i in fades: startVisSelection, endVisSelection, sticksOnly = fades[i] action = "set stick_transparency, 0, %s; set stick_transparency, 1, %s;" % ( endVisSelection, startVisSelection) first_action += action #print "Executing %s from fades %d" % (action, i) #cmd.do( action ) for i in range(start_index, end_index): if i in settings: movs.animate_transition(views[i], views[i + 1], frames[i], start_frame, settings[i]) elif i in fades: movs.animate_transition(views[i], views[i + 1], frames[i], start_frame, fades[i]) else: movs.animate_transition(views[i], views[i + 1], frames[i], start_frame) #add an action if start_frame == 1: mdo_cmd = first_action if i in actions: mdo_cmd += actions[i] + ";" #mdo_cmd += "set_view("+str(views[i])+")" print mdo_cmd cmd.mdo(start_frame, mdo_cmd) elif i in actions: mdo_cmd = actions[i] + ";set_view(" + str(views[i]) + ")" cmd.mdo(start_frame, mdo_cmd) #print mdo_cmd start_frame += frames[i] cmd.frame(1) cmd.mplay()
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ): #print "Views" #print start_view,'\n',end_view cview = start_view[:] cmd.set_view( start_view ) #get initial and final quaternions for interpolation #print start_view[0:9] #get quaternions qstart = rmat2quat( start_view[0:9] ) qend = rmat2quat( end_view[0:9] ) #test for long way vs. short way if( quatdotprod( qstart,qend ) < 0 ): qstart = [-q for q in qstart] axan_start = quat2axisangle( qstart ) axan_end = quat2axisangle( qend ) axan_cur = axan_start[:] frame_start = first_frame frame_end = frame_start + nframes doFade = 0 doSetting = 0 if len( settings ) == 4: settingName, selection, startVal, endVal = settings settingStep = (endVal-startVal)/float(nframes) print "Setting step ", settingStep doSetting = 1 elif len( settings ) == 3: startVisSelection, endVisSelection, sticksOnly = settings settingStep = 1.0/float(nframes) doFade = 1 for f in range( frame_start , frame_end): #get rotmat #using angle axis for i in range(0,4): axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes newmat = axisangle2rmat( axan_cur ) #print cview for i in range(0,9): cview[i] = newmat[i] mdo_cmd = "set_view ([" for i in range(0,18): if( i>8 ): cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes mdo_cmd += "%12.7f,"% cview[i] mdo_cmd = mdo_cmd[:-1]+"])" if doSetting: val = float(f-frame_start)*settingStep + startVal print val; mdo_cmd += "; set %s, %f, %s" % (settingName, val, selection) print mdo_cmd; #print "mdo ", mdo_cmd if doFade: val = float(f-frame_start)*settingStep otherVal = 1.0 - val mdo_cmd += "; set stick_transparency, %f, %s; set stick_transparency, %f, %s" % ( val, startVisSelection, otherVal, endVisSelection ) if not sticksOnly: #comment out surface transparency interpolation due to problem with transparent sticks in front of #transparent surfaces (get black holes) # mdo_cmd += "; set transparency, %f, %s; set transparency, %f, %s" % ( val, startVisSelection, otherVal, endVisSelection ) mdo_cmd += "; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s" % ( val, startVisSelection, otherVal, endVisSelection ) cmd.mdo(f,mdo_cmd)
def flash_chain(chainID, frame, initialColor, afterColor): cmd.mdo(frame, 'show cartoon, chain %s'%chainID) cmd.mdo(frame+7, 'color %s, chain %s'%(afterColor,chainID)) cmd.mdo(frame+14, 'color %s, chain %s'%(initialColor,chainID)) cmd.mdo(frame+21, 'color %s, chain %s'%(afterColor,chainID)) cmd.mdo(frame+28, 'color %s, chain %s'%(initialColor,chainID)) cmd.mdo(frame+35, 'color %s, chain %s'%(afterColor,chainID)) cmd.mdo(frame+42, 'color %s, chain %s'%(initialColor,chainID)) cmd.mdo(frame+49, 'color %s, chain %s'%(afterColor,chainID))
def tursetxyzmovsetxyz(event): a = int(scriptent.get()) +1 scriptent.delete(0,100000) scriptent.insert(0,a) cmd.mdo( scriptent.get(), "turn x, %s; turn y, %s; turn z, %s; move x, %s; move y, %s; move z, %s" % (enttx.get(),entty.get(),enttz.get(),entmx.get(),entmy.get(),entmz.get()))
def movsetxyz(event): a = int(scriptent.get()) +1 scriptent.delete(0,100000) scriptent.insert(0,a) cmd.mdo( scriptent.get(), "move x, %s; move y, %s; move z, %s" % (entmx.get(),entmy.get(),entmz.get()))
def tursetz(event): a = int(scriptent.get()) +1 scriptent.delete(0,100000) scriptent.insert(0,a) cmd.mdo( scriptent.get(), "turn z," + enttz.get())
def animate_transition(start_view, end_view, nframes, first_frame, settings=[]): #print "Views" #print start_view,'\n',end_view cview = start_view[:] cmd.set_view(start_view) #get initial and final quaternions for interpolation #print start_view[0:9] #get quaternions qstart = rmat2quat(start_view[0:9]) qend = rmat2quat(end_view[0:9]) #test for long way vs. short way if quatdotprod(qstart, qend) < 0: qstart = [-q for q in qstart] axan_start = quat2axisangle(qstart) axan_end = quat2axisangle(qend) axan_cur = axan_start[:] frame_start = first_frame frame_end = frame_start + nframes doFade = 0 doSetting = 0 if len(settings) == 4: settingName, selection, startVal, endVal = settings settingStep = (endVal - startVal) / float(nframes) print "Setting step ", settingStep doSetting = 1 elif len(settings) == 3: startVisSelection, endVisSelection, sticksOnly = settings settingStep = 1.0 / float(nframes) doFade = 1 for f in range(frame_start, frame_end): #get rotmat #using angle axis for i in range(4): axan_cur[i] = axan_cur[i] + (axan_end[i] - axan_start[i]) / nframes newmat = axisangle2rmat(axan_cur) #print cview for i in range(9): cview[i] = newmat[i] mdo_cmd = "set_view ([" for i in range(18): if i > 8: cview[i] = cview[i] + (end_view[i] - start_view[i]) / nframes mdo_cmd += "%12.7f," % cview[i] mdo_cmd = mdo_cmd[:-1] + "])" if doSetting: val = float(f - frame_start) * settingStep + startVal print val mdo_cmd += "; set %s, %f, %s" % (settingName, val, selection) print mdo_cmd #print "mdo ", mdo_cmd if doFade: val = float(f - frame_start) * settingStep otherVal = 1.0 - val mdo_cmd += "; set stick_transparency, %f, %s; set stick_transparency, %f, %s" % ( val, startVisSelection, otherVal, endVisSelection) if not sticksOnly: #comment out surface transparency interpolation due to problem with transparent sticks in front of #transparent surfaces (get black holes) # mdo_cmd += "; set transparency, %f, %s; set transparency, %f, %s" % ( val, startVisSelection, otherVal, endVisSelection ) mdo_cmd += "; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s" % ( val, startVisSelection, otherVal, endVisSelection) cmd.mdo(f, mdo_cmd)
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()
for line in f.readlines(): # Read in radius if line.startswith('REMARK RADIUS'): radius = float(line.split()[3]) break # Load the sphere cmd.load(args.sphere, 'sphere') # Format the size of the sphere - may need to adjust settings later cmd.hide('everything', 'sphere') cmd.show('spheres', 'sphere') cmd.alter('sphere', 'vdw={}'.format(radius)) cmd.rebuild() cmd.set('sphere_color', 'grey90', 'sphere') cmd.set('sphere_transparency', '0.5', 'sphere') # Format the trajectory to show the waters within the GCMC sphere as sticks if args.trajectory is not None: cmd.hide('everything', 'resn HOH') # Hide waters first... n_frames = cmd.count_states() cmd.mset('1 -{}'.format(n_frames)) for f in range(1, n_frames + 1): # Need to write a command to update the movie to show GCMC waters as sticks movie_command = ( "hide sticks, resn HOH;" "sele gcmcwats, resn SPH around {} and (resn HOH and name O), state={};" "sele gcmcwats, byres gcmcwats;" "show sticks, gcmcwats;").format(radius, f) cmd.mdo(f, movie_command)
def reps(self, cleanup=0): rep_list = [ "lines", "sticks", "spheres", "surface", "mesh", "dots", "ribbon", "cartoon" ] try: if not cleanup: cmd.disable() cmd.set("suspend_updates", 1, quiet=1) cmd.load("$PYMOL_DATA/demo/pept.pdb", "rep1") cmd.alter("rep1///1-5+8-13/", "ss='S'") cmd.cartoon("auto") cmd.hide("everything", "rep1") for a in range(2, 9): cmd.create("rep%d" % a, "rep1") for x, y in enumerate(rep_list, 1): cmd.show(x, "rep%d" % y) cmd.reset() cmd.zoom("rep1", 24) util.cbay("rep2") util.cbac("rep3") util.cbas("rep4") util.cbab("rep5") util.cbaw("rep6") util.cbay("rep8") cmd.set("suspend_updates", 0, quiet=1) scale = 0.5 for b in range(1, 20): cmd.set("suspend_updates", 0, quiet=1) cmd.refresh() cmd.set("suspend_updates", 1, quiet=1) xt = -3.2 yt = 1.6 for a in range(1, 5): cmd.translate([xt * scale, yt * scale, 0], object="rep%d" % a, camera=0) xt = xt + 2 yt = -yt xt = -3.2 for a in range(5, 9): cmd.translate([xt * scale, yt * scale, 0], object="rep%d" % a, camera=0) xt = xt + 2 for a in range(1, 9): cmd.origin("rep%d" % a, object="rep%d" % a) cmd.mset("1") st = ' '.join( map( lambda x, y: "rotate angle=-3,object=rep%d,axis=%s;" % (x, y), list(range(1, 9)), ['x', 'y', 'x', 'y', 'x', 'y', 'x', 'y'])) cmd.mdo(1, st) cmd.set("suspend_updates", 0, quiet=1) cmd.mplay() cgo = [] axes = [[4.5, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]] c = 1 for a in rep_list: ext = cmd.get_extent("rep%d" % c) pos = [(ext[0][0] + ext[1][0]) / 2, (ext[0][1] + ext[1][1]) / 2 + 14, (ext[0][2] + ext[1][2]) / 2] c = c + 1 pos[0] = pos[0] - (measure_text(plain, a, axes) / 2) wire_text(cgo, plain, pos, a, axes) cmd.set("cgo_line_width", 1.5) cmd.set("auto_zoom", 0) cmd.load_cgo(cgo, 'reps') cmd.set("auto_zoom", 1) else: cmd.delete("rep*") cmd.mset() cmd.mstop() except: traceback.print_exc()
cmd.do('set all_states,0') cmd.set('two_sided_lighting', 'on') cmd.set('transparency', '0.2') cmd.load('../data/origins.pdb', 'origins') cmd.load('../data/v_origins.pdb', 'v_origins') cmd.show('nb_spheres', 'origins') cmd.show('nb_spheres', 'v_origins') load_trajectory = $load_trajectory if load_trajectory: cmd.load("../data/trajectory.pdb", "structure", discrete=1) cmd.dss("structure") else: cmd.load('../data/$pdb_representant', 'structure') cmd.hide('lines', 'structure') cmd.show('cartoon', 'structure') cmd.color('gray', 'structure') cmd.mset("1 -%d" % cmd.count_states()) for frame in range(1,cmd.count_states()+1): cmd.mdo(frame, "computeSpheres(" + str(frame) + ")") cmd.frame(1)
def testMdo(self): self.prep_movie() cmd.fragment("ala") cmd.mdo(5, "delete *") cmd.frame(5) self.assertEquals(len(cmd.get_names()), 0)
def Ligand_Pull(): glb.update() cmd.mstop() cmd.mclear() cmd.mset('1', '442') cmd.hide('everything') cmd.remove('resn HOH') cmd.color('green', 'all') objects = cmd.get_names('all') if 'ligands' in objects: cmd.set('stick_radius', '0.3') glb.procolor('ligands around 6','sticks','cpk','cartoon') glb.procolor('ligands','spheres','orange',None) cmd.set("cartoon_fancy_helices", "1") cmd.set("cartoon_fancy_sheets", "1") cmd.set('cartoon_transparency', '0.5') cmd.zoom() cmd.orient() cmd.mdo(1,'orient') cmd.mdo(2,'translate [2,0,0],ligands;') cmd.mdo(3,'translate [2,0,0],ligands;') cmd.mdo(4,'translate [2,0,0],ligands;') cmd.mdo(5,'translate [2,0,0],ligands;') cmd.mdo(6,'translate [2,0,0],ligands;') cmd.mdo(7,'translate [2,0,0],ligands;') cmd.mdo(8,'translate [2,0,0],ligands;') cmd.mdo(9,'translate [2,0,0],ligands;') cmd.mdo(10,'translate [2,0,0],ligands;') cmd.mdo(11,'translate [2,0,0],ligands;') cmd.mdo(12,'translate [2,0,0],ligands;') cmd.mdo(13,'translate [2,0,0],ligands;') cmd.mdo(14,'translate [2,0,0],ligands;') cmd.mdo(15,'translate [2,0,0],ligands;') cmd.mdo(16,'translate [2,0,0],ligands;') cmd.mdo(17,'translate [2,0,0],ligands;') cmd.mdo(18,'translate [2,0,0],ligands;') cmd.mdo(19,'translate [2,0,0],ligands;') cmd.mdo(20,'translate [2,0,0],ligands;') cmd.mdo(21,'translate [2,0,0],ligands;') cmd.mdo(22,'translate [2,0,0],ligands;') cmd.mdo(23,'translate [2,0,0],ligands;') cmd.mdo(24,'translate [2,0,0],ligands;') cmd.mdo(25,'translate [2,0,0],ligands;') cmd.mdo(26,'translate [2,0,0],ligands;') cmd.mdo(27,'translate [2,0,0],ligands;') cmd.mdo(28,'translate [2,0,0],ligands;') cmd.mdo(29,'translate [2,0,0],ligands;') cmd.mdo(30,'translate [2,0,0],ligands;') cmd.mdo(31,'translate [2,0,0],ligands;') cmd.mdo(32,'translate [2,0,0],ligands;') cmd.mdo(33,'translate [2,0,0],ligands;') cmd.mdo(34,'translate [2,0,0],ligands;') cmd.mdo(35,'translate [2,0,0],ligands;') cmd.mdo(36,'translate [2,0,0],ligands;') cmd.mdo(37,'translate [2,0,0],ligands;') cmd.mdo(38,'translate [2,0,0],ligands;') cmd.mdo(39,'translate [2,0,0],ligands;') cmd.mdo(40,'translate [2,0,0],ligands;') cmd.mdo(41,'translate [2,0,0],ligands;') cmd.mdo(42,'orient') cmd.util.mroll('42','222','1') cmd.mdo(223,'translate [-2,0,0],ligands;') cmd.mdo(224,'translate [-2,0,0],ligands;') cmd.mdo(225,'translate [-2,0,0],ligands;') cmd.mdo(226,'translate [-2,0,0],ligands;') cmd.mdo(227,'translate [-2,0,0],ligands;') cmd.mdo(228,'translate [-2,0,0],ligands;') cmd.mdo(229,'translate [-2,0,0],ligands;') cmd.mdo(230,'translate [-2,0,0],ligands;') cmd.mdo(231,'translate [-2,0,0],ligands;') cmd.mdo(232,'translate [-2,0,0],ligands;') cmd.mdo(233,'translate [-2,0,0],ligands;') cmd.mdo(234,'translate [-2,0,0],ligands;') cmd.mdo(235,'translate [-2,0,0],ligands;') cmd.mdo(236,'translate [-2,0,0],ligands;') cmd.mdo(237,'translate [-2,0,0],ligands;') cmd.mdo(238,'translate [-2,0,0],ligands;') cmd.mdo(239,'translate [-2,0,0],ligands;') cmd.mdo(240,'translate [-2,0,0],ligands;') cmd.mdo(241,'translate [-2,0,0],ligands;') cmd.mdo(242,'translate [-2,0,0],ligands;') cmd.mdo(243,'translate [-2,0,0],ligands;') cmd.mdo(244,'translate [-2,0,0],ligands;') cmd.mdo(245,'translate [-2,0,0],ligands;') cmd.mdo(246,'translate [-2,0,0],ligands;') cmd.mdo(247,'translate [-2,0,0],ligands;') cmd.mdo(248,'translate [-2,0,0],ligands;') cmd.mdo(249,'translate [-2,0,0],ligands;') cmd.mdo(250,'translate [-2,0,0],ligands;') cmd.mdo(251,'translate [-2,0,0],ligands;') cmd.mdo(252,'translate [-2,0,0],ligands;') cmd.mdo(253,'translate [-2,0,0],ligands;') cmd.mdo(254,'translate [-2,0,0],ligands;') cmd.mdo(255,'translate [-2,0,0],ligands;') cmd.mdo(256,'translate [-2,0,0],ligands;') cmd.mdo(257,'translate [-2,0,0],ligands;') cmd.mdo(258,'translate [-2,0,0],ligands;') cmd.mdo(259,'translate [-2,0,0],ligands;') cmd.mdo(260,'translate [-2,0,0],ligands;') cmd.mdo(261,'translate [-2,0,0],ligands;') cmd.mdo(262,'translate [-2,0,0],ligands;') cmd.mdo(263,'orient') cmd.util.mroll('264','442','1') else: showinfo('No ligands','There are no ligands in this PDB.')
def testMdo(self): self.prep_movie() cmd.fragment("ala") cmd.mdo(5,"delete *") cmd.frame(5) self.assertEquals(len(cmd.get_names()),0)
def movie(): """Creates the movie and plays it.""" cmd.frame(1) # reset frame counter nFrames = mv.maxframe # compile list of molecule states states = [] for n in range(nFrames): states.append(mv.getState(n + 1)) # compile mset command string "1 2 3 4 x3 5" from state list [1,2,3,4,4,4,5] statelist = "" n = 0 count = 0 while n < nFrames: actual = states[n] next = 0 if n < nFrames - 1: next = states[n + 1] if next == actual: count = count + 1 else: if count > 0: statelist = statelist + "%s x%i " % (actual, count + 1) else: statelist = statelist + "%s " % (actual) count = 0 n = n + 1 # Specify movie length print "creating movie with %i frames." % (nFrames) # cmd.mset("1 x%i"%(nFrames)) # earlier, without state support cmd.mset(statelist) # create empty frame-2do-lists do = ["zero frame is unused"] for i in range(nFrames): do.append("") # push all movie commands to the 2do-list for m in mv.movie: do[m[0]] = do[m[0]] + m[2] + ";" # check for png output and raytracing: if mv.pngPath != "": i = 1 while i <= nFrames: num = str(i) null = "0000" num = null[0:4 - len(num)] + num # create numbered file names if mv.ray: do[i] = do[i] + "ray;" do[i] = do[i] + "png %spymol%s.png;" % (mv.pngPath, num) i = 1 + 1 nFrames = nFrames + 1 do.append("mstop") # now let action happen in the frames i = 1 while i <= nFrames: cmd.mdo(i, do[i]) i = i + 1