| | 93 | See also the [http://www.cgl.ucsf.edu/chimera/docs/UsersGuide/bild.html Chimera BILD] commands. |
| | 94 | |
| | 95 | ==== 'Active' models ==== |
| | 96 | |
| | 97 | {{{ |
| | 98 | #!python |
| | 99 | # |
| | 100 | # Working with a specific active model: |
| | 101 | # openState(id: int, subid: int) |
| | 102 | modelID = chimera.openModels.listIds()[0] |
| | 103 | model_openState = chimera.openModels.openState(*modelID) |
| | 104 | if model_openState.active: |
| | 105 | # do something useful with it |
| | 106 | print model_openState.xform |
| | 107 | print model_openState.xform.getRotation() |
| | 108 | print model_openState.xform.getTranslation() |
| | 109 | # |
| | 110 | # looping over all open-active models |
| | 111 | # |
| | 112 | if chimera.openModels.hasActiveModels(): |
| | 113 | om = chimera.openModels.list(all=True) |
| | 114 | for m in om: |
| | 115 | if m.openState.active: |
| | 116 | # do something useful with it |
| | 117 | print m.openState.xform |
| | 118 | # |
| | 119 | # Setting 'active' models: |
| | 120 | # chimera.openModels.setActive(id: int, active: bool) |
| | 121 | # |
| | 122 | chimera.openModels.setActive(modelID[0], False) |
| | 123 | model_openState.active |
| | 124 | # False |
| | 125 | chimera.openModels.setActive(modelID[0], True) |
| | 126 | model_openState.active |
| | 127 | # True |
| | 128 | |
| | 129 | }}} |
| | 130 | |
| | 131 | |
| 102 | | ==== Color ==== |
| | 141 | ==== Representations ==== |
| | 142 | |
| | 143 | Each atom in a molecule has a drawMode attribute, with possible values: 0 = 'dot', 1 = 'sphere', 2 = 'endcap', 3 = 'ball'. These values can be compared with the equivalent 'enum' values in chimera.Atom, i.e.: |
| | 144 | |
| | 145 | {{{ |
| | 146 | #!python |
| | 147 | >>> chimera.Atom.Dot |
| | 148 | 0 |
| | 149 | >>> chimera.Atom.Sphere |
| | 150 | 1 |
| | 151 | >>> chimera.Atom.EndCap |
| | 152 | 2 |
| | 153 | >>> chimera.Atom.Ball |
| | 154 | 3 |
| | 155 | }}} |
| | 156 | |
| | 157 | {{{ |
| | 158 | #!python |
| | 159 | molecules = chimera.openModels.list(modelTypes=[chimera.Molecule]) |
| | 160 | for m in molecules: |
| | 161 | for a in m.atoms: |
| | 162 | print a.drawMode == chimera.Atom.Sphere |
| | 163 | }}} |
| | 164 | |
| | 165 | |
| | 166 | ==== Color and Material Attributes ==== |
| | 167 | |
| | 168 | See [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_ColorWellUI.html Main_ColorWellUI example]. |
| 169 | | ==== Representations ==== |
| 170 | | |
| 171 | | Each atom in a molecule has a drawMode attribute, with possible values: 0 = 'dot', 1 = 'sphere', 2 = 'endcap', 3 = 'ball'. These values can be compared with the equivalent 'enum' values in chimera.Atom, i.e.: |
| 172 | | |
| 173 | | {{{ |
| 174 | | #!python |
| 175 | | >>> chimera.Atom.Dot |
| 176 | | 0 |
| 177 | | >>> chimera.Atom.Sphere |
| 178 | | 1 |
| 179 | | >>> chimera.Atom.EndCap |
| 180 | | 2 |
| 181 | | >>> chimera.Atom.Ball |
| 182 | | 3 |
| 183 | | }}} |
| 184 | | |
| 185 | | {{{ |
| 186 | | #!python |
| 187 | | molecules = chimera.openModels.list(modelTypes=[chimera.Molecule]) |
| 188 | | for m in molecules: |
| 189 | | for a in m.atoms: |
| 190 | | print a.drawMode == chimera.Atom.Sphere |
| 191 | | }}} |
| 192 | | |
| 193 | | |
| 194 | | === Parameter Access Methods === |
| 195 | | |
| 196 | | Something like this gains access to a lot of view parameters: |
| 197 | | {{{ |
| 198 | | #!python |
| 199 | | for n in dir(chimera.viewer): |
| 200 | | print n, eval('type(chimera.viewer.%s)' % n) |
| 201 | | }}} |
| 202 | | |
| 203 | | Some tips in the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html programming FAQ] are useful (esp, items 4, 5, 7-10). |
| 204 | | |
| 205 | | ==== Attributes: To Copy or Not to Copy, that is the question! ==== |
| 206 | | |
| 207 | | From the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html FAQ], item (7): Some attributes return a copy of an object. |
| 208 | | {{{ |
| 209 | | #!python |
| 210 | | >>> xf = model.openState.xform # xf is a copy of the model's Xform matrix. |
| 211 | | >>> xf.zRotate(45) # This will not rotate the model. |
| 212 | | |
| 213 | | >>> c = model.atoms[0].color # c is the MaterialColor object for the atom |
| 214 | | >>> c.ambientDiffuse = (1,0,0) # The Atom color changes immediately to red. |
| 215 | | }}} |
| 216 | | |
| 217 | | 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. |
| 218 | | |
| 219 | | |
| 220 | | |
| 221 | | ==== Color and Material Attributes ==== |
| 222 | | |
| 223 | | See http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_ColorWellUI.html |
| 224 | | |
| 225 | | 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). |
| | 235 | |
| | 236 | |
| | 287 | === Parameter Access Methods === |
| | 288 | |
| | 289 | Something like this gains access to a lot of view parameters: |
| | 290 | {{{ |
| | 291 | #!python |
| | 292 | for n in dir(chimera.viewer): |
| | 293 | print n, eval('type(chimera.viewer.%s)' % n) |
| | 294 | }}} |
| | 295 | |
| | 296 | Some tips in the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html programming FAQ] are useful (esp, items 4, 5, 7-10). |
| | 297 | |
| | 298 | ==== Attributes: To Copy or Not to Copy, that is the question! ==== |
| | 299 | |
| | 300 | From the [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html FAQ], item (7): Some attributes return a copy of an object. |
| | 301 | {{{ |
| | 302 | #!python |
| | 303 | >>> xf = model.openState.xform # xf is a copy of the model's Xform matrix. |
| | 304 | >>> xf.zRotate(45) # This will not rotate the model. |
| | 305 | |
| | 306 | >>> c = model.atoms[0].color # c is the MaterialColor object for the atom |
| | 307 | >>> c.ambientDiffuse = (1,0,0) # The Atom color changes immediately to red. |
| | 308 | }}} |
| | 309 | |
| | 310 | 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. |
| | 311 | |
| | 312 | |
| 283 | | |
| 284 | | ==== 'Active' models ==== |
| 285 | | |
| 286 | | {{{ |
| 287 | | #!python |
| 288 | | # |
| 289 | | # Working with a specific active model: |
| 290 | | # openState(id: int, subid: int) |
| 291 | | modelID = chimera.openModels.listIds()[0] |
| 292 | | model_openState = chimera.openModels.openState(*modelID) |
| 293 | | if model_openState.active: |
| 294 | | # do something useful with it |
| 295 | | print model_openState.xform |
| 296 | | print model_openState.xform.getRotation() |
| 297 | | print model_openState.xform.getTranslation() |
| 298 | | # |
| 299 | | # looping over all open-active models |
| 300 | | # |
| 301 | | if chimera.openModels.hasActiveModels(): |
| 302 | | om = chimera.openModels.list(all=True) |
| 303 | | for m in om: |
| 304 | | if m.openState.active: |
| 305 | | # do something useful with it |
| 306 | | print m.openState.xform |
| 307 | | # |
| 308 | | # Setting 'active' models: |
| 309 | | # chimera.openModels.setActive(id: int, active: bool) |
| 310 | | # |
| 311 | | chimera.openModels.setActive(modelID[0], False) |
| 312 | | model_openState.active |
| 313 | | # False |
| 314 | | chimera.openModels.setActive(modelID[0], True) |
| 315 | | model_openState.active |
| 316 | | # True |
| 317 | | |
| 318 | | }}} |