| 10 | | |
| 11 | | |
| 12 | | === State Parameters: Categories === |
| 13 | | |
| 14 | | * Elements |
| 15 | | * 2D Labels |
| 16 | | * Models (Molecules, Atoms) |
| 17 | | * Surfaces |
| 18 | | * Volumes |
| 19 | | * Selections |
| 20 | | * Display State |
| 21 | | * Hidden |
| 22 | | * Active for Motion |
| 23 | | * Spatial |
| 24 | | * Camera |
| 25 | | * Model Geometry (Center of Rotation, Xform, etc.) |
| 26 | | * Clipping Planes |
| 27 | | * Lighting |
| 28 | | * Background |
| 29 | | * Directional Lights |
| 30 | | * Surfacing |
| 31 | | * Textures |
| 32 | | * Materials (Color, Specular reflection, etc.) |
| 33 | | * Transparency |
| 34 | | * Rendering |
| 35 | | * Model and ribbon styles |
| 36 | | * Motion Blur |
| 37 | | |
| 38 | | |
| 39 | | === State Parameters: initial work based on {{{savepos}}} and {{{reset}}} === |
| 40 | | |
| 41 | | The savepos/reset functionality works with a tuple: |
| 42 | | {{{ |
| 43 | | # |
| 44 | | # savepos returns a tuple of various parameters (my comments added) |
| 45 | | # |
| 46 | | return ( |
| 47 | | chimera.viewer.scaleFactor, #cam |
| 48 | | chimera.viewer.viewSize, #cam |
| 49 | | cam.center, #cam |
| 50 | | cam.nearFar, #cam |
| 51 | | cam.focal, #cam |
| 52 | | xforms, # spatial/geometry |
| 53 | | clips, # per-model clipping |
| 54 | | chimera.openModels.cofrMethod, # spatial/geometry |
| 55 | | cofr, # spatial/geometry |
| 56 | | chimera.viewer.clipping #cam |
| 57 | | ) |
| 58 | | }}} |
| 59 | | |
| 60 | | |
| 61 | | |
| 62 | | === Parameter Access Methods === |
| 63 | | |
| 64 | | Something like this gains access to a lot of view parameters: |
| 65 | | {{{ |
| 66 | | for n in dir(chimera.viewer): |
| 67 | | print n, eval('type(chimera.viewer.%s)' % n) |
| 68 | | }}} |
| 69 | | |
| 70 | | Some tips in the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html programming FAQ] are useful (esp, items 4, 5, 7-10). |
| 71 | | |
| 72 | | |
| 73 | | |
| 74 | | ==== Attributes: To Copy or Not to Copy, that is the question! ==== |
| 75 | | |
| 76 | | From the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html FAQ], item (7): Some attributes return a copy of an object. |
| 77 | | {{{ |
| 78 | | >>> xf = model.openState.xform # xf is a copy of the model's Xform matrix. |
| 79 | | >>> xf.zRotate(45) # This will not rotate the model. |
| 80 | | |
| 81 | | >>> c = model.atoms[0].color # c is the MaterialColor object for the atom |
| 82 | | >>> c.ambientDiffuse = (1,0,0) # The Atom color changes immediately to red. |
| 83 | | }}} |
| 84 | | |
| 85 | | 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. |
| 86 | | |
| 87 | | |
| 88 | | |
| 89 | | ==== Color and Material Attributes ==== |
| 90 | | |
| 91 | | See http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_ColorWellUI.html |
| 92 | | |
| 93 | | 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). |
| 94 | | |
| 95 | | Get a PDB molecule to play with: |
| 96 | | {{{ |
| 97 | | chimera.runCommand('open 2por') |
| 98 | | om = chimera.openModels.list(all=True) |
| 99 | | por2 = om[1] |
| 100 | | }}} |
| 101 | | |
| 102 | | Exploring color properties: |
| 103 | | {{{ |
| 104 | | >>> por2.color |
| 105 | | <_chimera.MaterialColor object at 0x3d50dc8> |
| 106 | | >>> por2.color.name() |
| 107 | | u'_openColor00' |
| 108 | | >>> por2.color.rgba() |
| 109 | | (1.0, 1.0, 1.0, 1.0) |
| 110 | | >>> por2.color.ambientDiffuse |
| 111 | | (1.0, 1.0, 1.0) |
| 112 | | >>> por2.color.isTranslucent() |
| 113 | | False |
| 114 | | >>> por2.color.opacity |
| 115 | | 1.0 |
| 116 | | }}} |
| 117 | | |
| 118 | | Chimera material attributes are collected with color attributes. |
| 119 | | {{{ |
| 120 | | # chimera.Material object |
| 121 | | >>> por2.color.material |
| 122 | | <_chimera.Material object at 0x2fd7c60> |
| 123 | | >>> por2.color.material.name() # material name (unicode str) |
| 124 | | u'default' |
| 125 | | >>> por2.color.material.shininess |
| 126 | | 30.0 |
| 127 | | >>> por2.color.material.specular |
| 128 | | (0.85, 0.85, 0.85) |
| 129 | | >>> por2.color.material.opacity |
| 130 | | 1.0 |
| 131 | | >>> por2.color.material.ambientDiffuse |
| 132 | | (1.0, 1.0, 1.0) |
| 133 | | >>> por2.color.material.isTexture() |
| 134 | | False |
| 135 | | >>> por2.color.material.isTranslucent() |
| 136 | | False |
| 137 | | }}} |
| 138 | | |
| 139 | | |
| 140 | | |
| 141 | | ==== openState attributes ==== |
| 142 | | |
| 143 | | Get the !OpenState attributes of a model: {{{chimera.openModels.openState(id: int, subid: int)}}} |
| 144 | | |
| 145 | | From the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html 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. |
| 146 | | |
| 147 | | |
| 148 | | |
| 149 | | ==== 'Active' models ==== |
| 150 | | |
| 151 | | {{{ |
| 152 | | # |
| 153 | | # Working with a specific active model: |
| 154 | | # openState(id: int, subid: int) |
| 155 | | modelID = chimera.openModels.listIds()[0] |
| 156 | | model_openState = chimera.openModels.openState(*modelID) |
| 157 | | if model_openState.active: |
| 158 | | # do something useful with it |
| 159 | | print model_openState.xform |
| 160 | | print model_openState.xform.getRotation() |
| 161 | | print model_openState.xform.getTranslation() |
| 162 | | # |
| 163 | | # looping over all open-active models |
| 164 | | # |
| 165 | | if chimera.openModels.hasActiveModels(): |
| 166 | | om = chimera.openModels.list(all=True) |
| 167 | | for m in om: |
| 168 | | if m.openState.active: |
| 169 | | # do something useful with it |
| 170 | | print m.openState.xform |
| 171 | | # |
| 172 | | # Setting 'active' models: |
| 173 | | # chimera.openModels.setActive(id: int, active: bool) |
| 174 | | # |
| 175 | | chimera.openModels.setActive(modelID[0], False) |
| 176 | | model_openState.active |
| 177 | | # False |
| 178 | | chimera.openModels.setActive(modelID[0], True) |
| 179 | | model_openState.active |
| 180 | | # True |
| 181 | | |
| 182 | | }}} |
| 183 | | |
| 184 | | |
| 185 | | |
| 186 | | ==== openState.xform ==== |
| 187 | | |
| 188 | | {{{ |
| 189 | | |
| 190 | | >>> dir(model_openState.xform) |
| 191 | | ['__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'] |
| 192 | | |
| 193 | | >>> help(model_openState.xform) |
| 194 | | Help on Xform object: |
| 195 | | |
| 196 | | ... |
| 197 | | |
| 198 | | }}} |
| | 9 | * [wiki:ChimeraProgrammingResources Programming resources], including commonly used modules for access to molecular data attributes |
| | 10 | * [wiki:ChimeraAnimationState Animation State Parameters] |