== State Parameters and Transitions == 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 [http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html programming FAQ] are useful (esp, items 4, 5, 7-10). ==== openState attribute (from FAQ) ==== Get the OpenState attributes of a model: {{{chimera.openModels.openState(id: int, subid: int)}}} 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 # # 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 }}} === 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.