wiki:ChimeraAnimationTasks

Version 15 (modified by Darren Weber, 15 years ago) ( diff )

--

Resources

State Parameters and Transitions

Need to identify all the possible state parameters that can be changed between two states. All of those parameters need to be retained, probably in some form of immutable data type (tuple) within a dictionary for easy access to several parameter groups (viewer, volumes, surfaces, models, labels, etc.). Some of the elements in a state may have shared spatial parameters (e.g., molecular surfaces, molecules, and atoms may share a common spatial transform).

State Parameters: Categories

  • Elements
    • 2D Labels
    • Models (Molecules, Atoms)
    • Surfaces
    • Volumes
    • Selections
  • Display State
    • Hidden
    • Active for Motion
  • Spatial
    • Camera
    • Model Geometry (Center of Rotation, Xform, etc.)
    • Clipping Planes
  • Lighting
    • Background
    • Directional Lights
  • Surfacing
    • Textures
    • Materials (Color, Specular reflection, etc.)
    • Transparency
  • Rendering
    • Model and ribbon styles
    • Motion Blur

State Parameters: initial work based on savepos and reset

The savepos/reset functionality works with a tuple:

#
# savepos returns a tuple of various parameters (my comments added)
#
        return (
            chimera.viewer.scaleFactor, #cam
            chimera.viewer.viewSize, #cam
            cam.center, #cam
            cam.nearFar, #cam
            cam.focal, #cam
            xforms, # spatial/geometry
            clips, # per-model clipping
            chimera.openModels.cofrMethod, # spatial/geometry
            cofr, # spatial/geometry
            chimera.viewer.clipping #cam
        )

Parameter Access Methods

Something like this gains access to a lot of view parameters:

for n in dir(chimera.viewer):
    print n, eval('type(chimera.viewer.%s)' % n)

Some tips in the programming FAQ are useful (esp, items 4, 5, 7-10).

Attributes: To Copy or Not to Copy, that is the question!

From the FAQ, item (7): Some attributes return a copy of an object.

>>> xf = model.openState.xform	# xf is a copy of the model's Xform matrix.
>>> xf.zRotate(45)		# This will not rotate the model.

>>> c = model.atoms[0].color	# c is the MaterialColor object for the atom
>>> c.ambientDiffuse = (1,0,0)	# The Atom color changes immediately to red.

Some Chimera objects returned as attributes are always copies, some are always references to the uncopied object. Objects that are always copied include Xform, Vector, Point, Sphere, Element, MolResId, Coord, .... Objects that are never copied include Atom, Bond, PseudoBond, CoordSet, Molecule, Residue, RibbonStyle, .... Object that can be copied have a __copy__ method. In order to know if an object type is passed by value is to look at the Chimera C++ header files. Classes without a WrapPy base class are always copied. This base class is part of the C++ to Python interface generation.

Color and Material Attributes

See http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_ColorWellUI.html

Also need a function for color interpolations (linear may suffice). This may be a simple function to interpolate each component of the RGBA tuple from stateA to stateB over N frames (the range of values is between 0-1, so it's a floating point interpolation).

Get a PDB molecule to play with:

chimera.runCommand('open 2por')
om = chimera.openModels.list(all=True)
por2 = om[1]

Exploring color properties:

>>> por2.color
<_chimera.MaterialColor object at 0x3d50dc8>
>>> por2.color.name()
u'_openColor00'
>>> por2.color.rgba()
(1.0, 1.0, 1.0, 1.0)
>>> por2.color.ambientDiffuse
(1.0, 1.0, 1.0)
>>> por2.color.isTranslucent()
False
>>> por2.color.opacity
1.0

Chimera material attributes are collected with color attributes.

# chimera.Material object
>>> por2.color.material
<_chimera.Material object at 0x2fd7c60>
>>> por2.color.material.name()  # material name (unicode str)
u'default'
>>> por2.color.material.shininess
30.0
>>> por2.color.material.specular
(0.85, 0.85, 0.85)
>>> por2.color.material.opacity
1.0
>>> por2.color.material.ambientDiffuse
(1.0, 1.0, 1.0)
>>> por2.color.material.isTexture()
False
>>> por2.color.material.isTranslucent()
False

openState attributes

Get the OpenState attributes of a model: chimera.openModels.openState(id: int, subid: int)

From the FAQ, item (10): The openState attribute of a Model controls whether that model is active for motion ('.active'), and contains the model's transformation matrix ('.xform') and center of rotation ('.cofr'). Since some models must move in synchrony (e.g. a molecule and its surface), OpenState instances may be shared among multiple models. If you create a model that needs a shared openState with another model, then when adding your model to the list of open models with chimera.openModels.add(), you should use the 'sameAs' keyword to specify the other model.

'Active' models

#
# Working with a specific active model:
# openState(id: int, subid: int)
modelID = chimera.openModels.listIds()[0]
model_openState = chimera.openModels.openState(*modelID)
if model_openState.active:
    # do something useful with it
    print model_openState.xform
    print model_openState.xform.getRotation()
    print model_openState.xform.getTranslation()
#
# looping over all open-active models
#
if chimera.openModels.hasActiveModels():
    om = chimera.openModels.list(all=True)
    for m in om:
        if m.openState.active:
            # do something useful with it
            print m.openState.xform
#
# Setting 'active' models:
# chimera.openModels.setActive(id: int, active: bool)
#
chimera.openModels.setActive(modelID[0], False)
model_openState.active
# False
chimera.openModels.setActive(modelID[0], True)
model_openState.active
# True

openState.xform

>>> dir(model_openState.xform)
['__class__', '__copy__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'apply', 'coordFrame', 'getCoordFrame', 'getOpenGLMatrix', 'getRotation', 'getTranslation', 'identity', 'inverse', 'invert', 'isIdentity', 'lookAt', 'makeOrthogonal', 'multiply', 'premultiply', 'rotate', 'rotation', 'translate', 'translation', 'xRotate', 'xRotation', 'xform', 'yRotate', 'yRotation', 'zAlign', 'zRotate', 'zRotation']

>>> help(model_openState.xform)
Help on Xform object:

...

Integrity Checking

Take a look at the code for chimera.update.checkForChanges(). This may be helpful in checking the validity of state parameters and in automatically detecting changes for transitions.

Also, chimera.openModels.addRemoveHandler(func, data) might be used to add a trigger handler when removing models. This might be useful in the creation of a state instance as a way to maintain integrity or validity of the saved state. It may depend on whether the state instance keeps a reference or a copy of models in the saved state. For efficiency, it is better to keep a reference. For validity, it could be better to keep a copy. Perhaps a copy is required only when a model is removed, so the copy action could be triggered then. If a state instance that is registered as a handler is deleted, then call chimera.openModels.deleteRemoveHandler(handler) to delete the trigger handler.

Transforms

Molecular morphing

For example, morphing of 3por to 2por, see http://molmovdb.mbb.yale.edu/cgi-bin/morph.cgi?ID=009069-29776

This is probably handled already in Chimera. Should it be some kind of transition parameter for the animation extension?

Note: See TracWiki for help on using the wiki.