[chimera-dev] Re: Chimera and lighting

Thomas Goddard goddard at cgl.ucsf.edu
Wed Oct 22 09:50:47 PDT 2003


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')



More information about the Chimera-dev mailing list