This is a read-only mirror of pymolwiki.org

Difference between revisions of "Movie fade"

From PyMOL Wiki
Jump to navigation Jump to search
m (fix imports)
m (2 revisions)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{Infobox script-repo
 
{{Infobox script-repo
 
|type      = Python Module
 
|type      = Python Module
|author    = [[User:Inchoate|Jason Vertrees]]
+
|filename  = movie_fade.py
|license  = [http://www.opensource.org/licenses/BSD-2-Clause BSD]
+
|author    = [[User:Inchoate|Jason Vertrees]] and [[User:Speleo3|Thomas Holder]]
 +
|license  = BSD-2-Clause
 
}}
 
}}
  
= 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.
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,
+
 
 +
== Usage ==
 +
movie_fade setting, startFrame, startVal, endFrame, endVal [, selection ]
 +
 
 +
== Examples ==
 +
To fade in sticks from fully transparent to fully opaque across 60 frames do:
  
 
<source lang="python">
 
<source lang="python">
 +
mset 1x60
 
movie_fade stick_transparency, 1, 1., 60, 0.
 
movie_fade stick_transparency, 1, 1., 60, 0.
 
</source>
 
</source>
  
For help, type,
+
More complex example which involves camera motion:
 +
 
 
<source lang="python">
 
<source lang="python">
# syntax
+
fetch 1rx1, async=0
 +
as cartoon
 +
show surface
 +
mset 1x80
 +
movie.roll
 +
movie_fade transparency,  1, 0., 40, 1.
 +
movie_fade transparency, 41, 1., 80, 0.
 +
</source>
  
movie_fade ?
+
'''Example file:'''
 
 
# usage
 
 
 
help movie_fade
 
</source>
 
  
 +
[[Image:Movie fade example.gif|300px|thumb|Result]]
  
 
<source lang="python">
 
<source lang="python">
from pymol import cmd, stored
+
import movie_fade
import string
 
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():
+
fetch 1hpv, async=0
for f in range(len(stored.mdoCache)):
+
orient
cmd.mdo(f+1, stored.mdoCache[f])
 
  
def mClearCache():
+
#format
for f in range(len(stored.mdoCache)):
+
bg black
cmd.mdo(f+1, "")
+
show_as cartoon
stored.mdoCache = []
+
color marine, ss s
 +
color red, ss h
 +
color white, ss l+""
 +
show sticks, resn 478
 +
util.cbao resn 478
 +
set surface_color, white, 1hpv
 +
show surface
  
def movie_fade( setting, startFrame, startVal, endFrame, endVal, smoothing="linear"):
+
#movie
"""fades and smooth transitions"""
+
mset 1x120
 +
movie_fade transparency,1, 0, 60, 1, 1hpv
 +
movie_fade transparency,61, 1, 120, 0, 1hpv
 +
</source>
  
try:
+
== See Also ==
from pymol import stored
 
stored.mdoCache
 
except AttributeError:
 
print "mdoCache not found, creating new."
 
stored.mdoCache = []
 
  
startFrame = float(startFrame)
+
* [[mdo]]
endFrame  = float(endFrame)
+
* [[mappend]]
startVal  = float(startVal)
+
* [[set]]
endVal    = float(endVal)
+
* [[Movie_color_fade|movie_color_fade]]
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)
 
</source>
 
  
 
[[Category:Script_Library]]
 
[[Category:Script_Library]]
 
[[Category:UI_Scripts]]
 
[[Category:UI_Scripts]]

Latest revision as of 02:46, 3 April 2017

Type Python Module
Download movie_fade.py
Author(s) Jason Vertrees and Thomas Holder
License BSD-2-Clause
This code has been put under version control in the project Pymol-script-repo

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.

Usage

movie_fade setting, startFrame, startVal, endFrame, endVal [, selection ]

Examples

To fade in sticks from fully transparent to fully opaque across 60 frames do:

mset 1x60
movie_fade stick_transparency, 1, 1., 60, 0.

More complex example which involves camera motion:

fetch 1rx1, async=0
as cartoon
show surface
mset 1x80
movie.roll
movie_fade transparency,  1, 0., 40, 1.
movie_fade transparency, 41, 1., 80, 0.

Example file:

Result
import movie_fade

fetch 1hpv, async=0
orient

#format
bg black
show_as cartoon
color marine, ss s
color red, ss h
color white, ss l+""
show sticks, resn 478
util.cbao resn 478
set surface_color, white, 1hpv
show surface

#movie
mset 1x120
movie_fade transparency,1, 0, 60, 1, 1hpv
movie_fade transparency,61, 1, 120, 0, 1hpv

See Also