Hi Steve,
The SimpleSession.oslMap() call is not available in Chimera 1.1846. There is something similar SimpleSession.modelMap which can be used to emulate oslMap(). I successfully restored an EMANimator session in Chimera 1.1846 after defining in the IDLE shell:
def osl_map(model_id_string): id = int(model_id_string[1:]) import SimpleSession # modelMap is a dictionary mapping (id,subid) to a list of models. m = SimpleSession.modelMap[(id, 0)][0] return '#%d' % m.id import SimpleSession SimpleSession.oslMap = osl_map
You can use this trick to open your existing session files. I suggest you change your EMANimator session saving code to make it immune from these SimpleSession API changes. Then you might open old session files as above, and save them in the improved format.
Unfortunately the SimpleSession state saving is tricky because of the need for backwards compatibility. I do not know which SimpleSession APIs are guaranteed to exist in all future Chimera versions. To deal with this in my volume viewer session code, I do not put any SimpleSession calls in the actual session file. Instead I save all state data in dictionaries and tuples and such, and then call a restore routine in the volume viewer module. That routine then uses whatever SimpleSession calls are needed (like oslMap). This way I can adapt the session restore code without modifying any session files.
Another suggestion is to put all your session file code in a function and after that call the function in a try / except block.
def restore_volume_viewer(): volume_viewer_state = {...} VolumeViewer.session.restore_volume_state(volume_viewer_state) try: restore_volume_viewer() except: reportRestoreError('Error restoring volume viewer')
This minimizes namespace polution in the session file, and will allow other parts of the session restore to work if your part fails.
I played with EMANimator last week and figured it all out I think. I was amazed you figured out the SimpleSession stuff for saving state.
Tom
----------- Here's an example of volume viewer session file code.
def restore_volume_viewer(): volume_viewer_state = \ { 'adjust_camera': 0, 'auto_show_subregion': 0, 'box_padding': '0', 'class': 'Volume_Dialog_State', 'data_cache_size': '32', 'data_panel_shown': 0, 'data_set_states': [ { 'class': 'Data_Set_State', 'data_region_state': [ { 'class': 'Data_Region_State', 'component_display_parameters': [ { 'class': 'Component_Display_Parameters_State', 'default_rgba': ( 1, 1, 1, 1, ), 'hidden': 0, 'solid_brightness_factor': 1.0, 'solid_colors': [ ( 1, 1, 1, 1, ), ( 1, 1, 1, 1, ), ], 'solid_levels': [ ( 2.8447514853193487, 0, ), ( 3.5993542671203613, 1, ), ], 'surface_brightness_factor': 1.0, 'surface_colors': [ ( 1.0, 1.0, 1.0, 1.0, ), ], 'surface_levels': [ 2.4433076821628106, ], 'transparency_depth': 0.047138079248299998, 'transparency_factor': 0.0, 'version': 1, }, ], 'name': '', 'region': ( [ 0, 0, 0, ], [ 49, 49, 49, ], [ 1, 1, 1, ], ), 'region_list': { 'class': 'Region_List_State', 'current_index': 0, 'named_regions': [ ], 'region_list': [ ( ( 0, 0, 0, ), ( 49, 49, 49, ), ), ], 'version': 1, }, 'rendering_options': { 'bt_correction': 0, 'class': 'Rendering_Options_State', 'colormap_size': 256, 'dim_transparency': 0, 'flip_normals': 1, 'line_thickness': 1, 'linear_interpolation': 1, 'maximum_intensity_projection': 0, 'mesh_lighting': 1, 'minimal_texture_memory': 0, 'outline_box_rgb': ( 1, 1, 1, ), 'show_outline_box': 0, 'smooth_lines': 0, 'two_sided_lighting': 1, 'use_2d_textures': 1, 'use_colormap': 1, 'version': 1, }, 'representation': 'surface', 'solid_model': None, 'surface_model': { 'active': 1, 'class': 'Model_State', 'display': 1, 'id': 0, 'name': 'groel.mrc', 'osl_identifier': '#0', 'subid': 0, 'version': 2, 'xform': { 'class': 'Xform_State', 'rotation_angle': 1.538469230769508, 'rotation_axis': ( 0.5773502691895197, 0.5773502691895197, 0.5773502691895197, ), 'translation': ( 0.0, 0.0, 0.0, ), 'version': 1, }, }, 'version': 2, }, ], 'data_state': { 'available_subsamplings': {}, 'class': 'Data_State', 'file_type': 'mrc', 'path': '/usr/local/src/chimera-demos/volume/examples/groel.mrc', 'version': 1, 'xyz_origin': [ -24.5, -24.5, -24.5, ], 'xyz_step': [ 1.0, 1.0, 1.0, ], }, 'name': 'groel.mrc', 'version': 1, }, ], 'display_panel_shown': 1, 'focus_region_name': '', 'geometry': '537x358+200+633', 'immediate_update': 1, 'is_visible': 1, 'limit_voxel_count': 1, 'no_colormap_multi_component_data': 1, 'options_panel_shown': 0, 'region_panel_shown': 0, 'representation': 'surface', 'selectable_subregions': 0, 'show_atom_box_button': 0, 'show_bounds': 0, 'show_named_regions': 0, 'show_on_open': 1, 'subregion_button': 'button 2', 'version': 4, 'voxel_limit': '1', 'voxel_limit_for_open': '1', } import VolumeViewer.session VolumeViewer.session.restore_volume_state(volume_viewer_state)
try: restore_volume_viewer() except: reportRestoreError('Error restoring volume viewer')
Thanks for the tip on a workaround for the oslMap problem in the new version. I must say this sort of API change is really irritating. It took me quite a lot of time and effort to get that osl code to work in the first place, and I'm not really looking forward to redoing it. It would be really nice if some level of backwards compatibility were insured. I understand your suggestion about not putting oslMap calls into my session files, but at the time I had no reason to expect the API to change, and I based my code on reading parts of the existing chimera code. I still have no concrete feel for what parts of the API might be stable and what parts might not. Sorry for the rant, just feeling a little frustrated...
---------------------------------------------------------------------------- Steven Ludtke, PhD | Baylor College of Medicine sludtke@bcm.tmc.edu | Asst. Professor & Co-Director stevel@alumni.caltech.edu | National Center For Macromolecular Imaging V: (713)798-6989 | Dept of Biochemistry and Mol. Biol. instant messenger: sludtke42 | http://ncmi.bcm.tmc.edu/~stevel | * Thought is the arrow of time *
The points that Tom make in his message are all good. In the 1700 release, SimpleSession needed the original source files to restore molecular models, and therefore the only way to restore attributes was to use OSL identifiers to map to restored atoms, bonds, etc. Chimera's OSL lookup code is complex and therefore slowish, especially when used massively like this. Also, OSLs don't always uniquely identify atoms (some small molecules have all their carbons named 'C' for instance). The 1864 release embeds the molecular info in the session file and uses some tricks to create a mapping between the Python id before saving and the corresponding object after restoring. With OSLs bypassed, the restore process is much faster. Going the whole nine yards, we eliminated oslMap (a necessary evil at the time) and replaced it with modelMap.
Assuming that EMANimator is using a ChimeraExtension.py to register itself in the tools menu, you can leverage the osl_map() trick that Tom wrote about to make your sessions always restore -- without using IDLE. In your ChimeraExtension.py add something like this:
def fixRestore(): def osl_map(model_id_string): ... body of the osl_map function that Tom wrote import SimpleSession SimpleSession.oslMap = osl_map
import chimera chimera.registerPostGraphicsFunc(fixRestore)
This will cause the fixRestore function to be called before command line files are processed.
Eric Pettersen UCSF Computer Graphics Lab pett@cgl.ucsf.edu http://www.cgl.ucsf.edu
On Wednesday, October 22, 2003, at 09:50 AM, Thomas Goddard wrote:
Hi Steve,
The SimpleSession.oslMap() call is not available in Chimera 1.1846. There is something similar SimpleSession.modelMap which can be used to emulate oslMap(). I successfully restored an EMANimator session in Chimera 1.1846 after defining in the IDLE shell:
def osl_map(model_id_string): id = int(model_id_string[1:]) import SimpleSession # modelMap is a dictionary mapping (id,subid) to a list of models. m = SimpleSession.modelMap[(id, 0)][0] return '#%d' % m.id import SimpleSession SimpleSession.oslMap = osl_map
You can use this trick to open your existing session files. I suggest you change your EMANimator session saving code to make it immune from these SimpleSession API changes. Then you might open old session files as above, and save them in the improved format.
Unfortunately the SimpleSession state saving is tricky because of the need for backwards compatibility. I do not know which SimpleSession APIs are guaranteed to exist in all future Chimera versions. To deal with this in my volume viewer session code, I do not put any SimpleSession calls in the actual session file. Instead I save all state data in dictionaries and tuples and such, and then call a restore routine in the volume viewer module. That routine then uses whatever SimpleSession calls are needed (like oslMap). This way I can adapt the session restore code without modifying any session files.
Another suggestion is to put all your session file code in a function and after that call the function in a try / except block.
def restore_volume_viewer(): volume_viewer_state = {...} VolumeViewer.session.restore_volume_state(volume_viewer_state) try: restore_volume_viewer() except: reportRestoreError('Error restoring volume viewer')
This minimizes namespace polution in the session file, and will allow other parts of the session restore to work if your part fails.
I played with EMANimator last week and figured it all out I think. I was amazed you figured out the SimpleSession stuff for saving state.
Tom
Here's an example of volume viewer session file code.
def restore_volume_viewer(): volume_viewer_state = \ { 'adjust_camera': 0, 'auto_show_subregion': 0, 'box_padding': '0', 'class': 'Volume_Dialog_State', 'data_cache_size': '32', 'data_panel_shown': 0, 'data_set_states': [ { 'class': 'Data_Set_State', 'data_region_state': [ { 'class': 'Data_Region_State', 'component_display_parameters': [ { 'class': 'Component_Display_Parameters_State', 'default_rgba': ( 1, 1, 1, 1, ), 'hidden': 0, 'solid_brightness_factor': 1.0, 'solid_colors': [ ( 1, 1, 1, 1, ), ( 1, 1, 1, 1, ), ], 'solid_levels': [ ( 2.8447514853193487, 0, ), ( 3.5993542671203613, 1, ), ], 'surface_brightness_factor': 1.0, 'surface_colors': [ ( 1.0, 1.0, 1.0, 1.0, ), ], 'surface_levels': [ 2.4433076821628106, ], 'transparency_depth': 0.047138079248299998, 'transparency_factor': 0.0, 'version': 1, }, ], 'name': '', 'region': ( [ 0, 0, 0, ], [ 49, 49, 49, ], [ 1, 1, 1, ], ), 'region_list': { 'class': 'Region_List_State', 'current_index': 0, 'named_regions': [ ], 'region_list': [ ( ( 0, 0, 0, ), ( 49, 49, 49, ), ), ], 'version': 1, }, 'rendering_options': { 'bt_correction': 0, 'class': 'Rendering_Options_State', 'colormap_size': 256, 'dim_transparency': 0, 'flip_normals': 1, 'line_thickness': 1, 'linear_interpolation': 1, 'maximum_intensity_projection': 0, 'mesh_lighting': 1, 'minimal_texture_memory': 0, 'outline_box_rgb': ( 1, 1, 1, ), 'show_outline_box': 0, 'smooth_lines': 0, 'two_sided_lighting': 1, 'use_2d_textures': 1, 'use_colormap': 1, 'version': 1, }, 'representation': 'surface', 'solid_model': None, 'surface_model': { 'active': 1, 'class': 'Model_State', 'display': 1, 'id': 0, 'name': 'groel.mrc', 'osl_identifier': '#0', 'subid': 0, 'version': 2, 'xform': { 'class': 'Xform_State', 'rotation_angle': 1.538469230769508, 'rotation_axis': ( 0.5773502691895197, 0.5773502691895197, 0.5773502691895197, ), 'translation': ( 0.0, 0.0, 0.0, ), 'version': 1, }, }, 'version': 2, }, ], 'data_state': { 'available_subsamplings': {}, 'class': 'Data_State', 'file_type': 'mrc', 'path': '/usr/local/src/chimera-demos/volume/examples/groel.mrc', 'version': 1, 'xyz_origin': [ -24.5, -24.5, -24.5, ], 'xyz_step': [ 1.0, 1.0, 1.0, ], }, 'name': 'groel.mrc', 'version': 1, }, ], 'display_panel_shown': 1, 'focus_region_name': '', 'geometry': '537x358+200+633', 'immediate_update': 1, 'is_visible': 1, 'limit_voxel_count': 1, 'no_colormap_multi_component_data': 1, 'options_panel_shown': 0, 'region_panel_shown': 0, 'representation': 'surface', 'selectable_subregions': 0, 'show_atom_box_button': 0, 'show_bounds': 0, 'show_named_regions': 0, 'show_on_open': 1, 'subregion_button': 'button 2', 'version': 4, 'voxel_limit': '1', 'voxel_limit_for_open': '1', } import VolumeViewer.session VolumeViewer.session.restore_volume_state(volume_viewer_state)
try: restore_volume_viewer() except: reportRestoreError('Error restoring volume viewer')
Chimera-dev mailing list Chimera-dev@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-dev
participants (3)
-
Eric Pettersen
-
Steve Ludtke
-
Thomas Goddard