| 11 | | {{{chimera.OpenModels.addRemoveHandler(func, data)}}} can 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. |
| | 11 | ==== openState attribute (from FAQ) ==== |
| | 12 | |
| | 13 | Get the OpenState attributes of a model: {{{chimera.openModels.openState(id: int, subid: int)}}} |
| | 14 | |
| | 15 | 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. |
| | 16 | |
| | 17 | ==== 'Active' models ==== |
| | 18 | |
| | 19 | {{{ |
| | 20 | # |
| | 21 | # Working with a specific active model: |
| | 22 | # openState(id: int, subid: int) |
| | 23 | modelID = chimera.openModels.listIds()[0] |
| | 24 | model_openState = chimera.openModels.openState(*modelID) |
| | 25 | if model_openState.active: |
| | 26 | # do something useful with it |
| | 27 | print model_openState.xform |
| | 28 | # |
| | 29 | # looping over all open-active models |
| | 30 | # |
| | 31 | if chimera.openModels.hasActiveModels(): |
| | 32 | om = chimera.openModels.list(all=True) |
| | 33 | for m in om: |
| | 34 | if m.openState.active: |
| | 35 | # do something useful with it |
| | 36 | print m.openState.xform |
| | 37 | # |
| | 38 | # Setting 'active' models: |
| | 39 | # chimera.openModels.setActive(id: int, active: bool) |
| | 40 | # |
| | 41 | chimera.openModels.setActive(modelID[0], False) |
| | 42 | model_openState.active |
| | 43 | # False |
| | 44 | chimera.openModels.setActive(modelID[0], True) |
| | 45 | model_openState.active |
| | 46 | # True |
| | 47 | |
| | 48 | }}} |
| | 49 | |
| | 50 | |
| | 51 | === Integrity Checking === |
| | 52 | |
| | 53 | 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. |
| | 54 | |
| | 55 | 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. |
| | 56 | |