Difference between revisions of "Movie fade"

From PyMOLWiki
Jump to navigation Jump to search
m (remove empty filename label)
Line 1: Line 1:
 
{{Infobox script-repo
 
{{Infobox script-repo
 
|type      = Python Module
 
|type      = Python Module
|filename  =
 
 
|author    = [[User:Inchoate|Jason Vertrees]]
 
|author    = [[User:Inchoate|Jason Vertrees]]
 
|license  = [http://www.opensource.org/licenses/BSD-2-Clause BSD]
 
|license  = [http://www.opensource.org/licenses/BSD-2-Clause BSD]

Revision as of 16:55, 24 February 2013

Type Python Module
Download
Author(s) Jason Vertrees
License BSD

Overview

This script will help fade in and out settings in a movie. Just specify the setting, it's initial value at an initial frame and it's ending value and frame. For example, to fade in sticks from fully transparent to fully opaque across 60 frames do,

movie_fade stick_transparency, 1, 1., 60, 0.

For help, type,

# syntax

movie_fade ?

# usage

help movie_fade


import math
#
# Movie fades work great, when there is only one mdo command
# per frame.  mdo does NOT save a stack of commands per frame
# as one might thing it just consistently updates itself.
#
def mStore(frame, theCommand):
	print "Storing %s into frame %d" % (theCommand, frame)
	if len(stored.mdoCache)<frame:
		diff = frame - len(stored.mdoCache)
		for x in range(diff): stored.mdoCache.append("")
	stored.mdoCache[frame-1] = stored.mdoCache[frame-1] + ";" + theCommand

def mRunCache():
	for f in range(len(stored.mdoCache)):
		cmd.mdo(f+1, stored.mdoCache[f])

def mClearCache():
	for f in range(len(stored.mdoCache)):
		cmd.mdo(f+1, "")
	stored.mdoCache = []

def movie_fade( setting, startFrame, startVal, endFrame, endVal, smoothing="linear"):
	"""fades and smooth transitions"""

	try:
		from pymol import stored
		stored.mdoCache
	except AttributeError:
		print "mdoCache not found, creating new."
		stored.mdoCache = []

	startFrame = float(startFrame)
	endFrame   = float(endFrame)
	startVal   = float(startVal)
	endVal     = float(endVal)
	frameRange = math.fabs(endFrame-startFrame)

	# boundary conditions to control the stricly <
	# aspect of the range function
	if startFrame<endFrame: endFrame = endFrame + 1.
	if startFrame>endFrame: endFrame = endFrame - 1.

	for fr in range(int(startFrame), int(endFrame)):
		fracV2 = float((fr-startFrame)/frameRange)
		fracV1 = 1.0 - fracV2
	
		totalIntensity = fracV1 * startVal + fracV2 * endVal
		if len(string.split(setting,','))==1:
			mStore(fr,  "set %s, %1.3f, quiet=1" % (setting, totalIntensity))
		else:
			(s1,s2) = string.split(setting,',')
			mStore(fr,  "set %s, %1.3f, %s, quiet=0" % (s1.strip('"'), totalIntensity, s2.strip('"')))
	mRunCache()
cmd.extend("movie_fade", movie_fade)
cmd.extend("movie_fade_clear_cache", mClearCache)