def restore_state(self): from ColorZone import color_zone from SessionUtil import string_to_array, float32 czt = self.color_zone_table for surface_id_subid, (points, colors, distance) in czt.items(): from SimpleSession import modelMap from _surface import SurfaceModel surfaces = [ s for s in modelMap.get(surface_id_subid, []) if isinstance(s, SurfaceModel) ] if surfaces: # TODO: If more than one surface may get wrong one. surface = surfaces[0] if self.version >= 2: npoints = string_to_array(points, float32, 3) ncolors = string_to_array(colors, float32, 4) else: from numpy import array, single as floatc npoints = array(points, floatc) ncolors = array(colors, floatc) color_zone(surface, npoints, ncolors, distance, auto_update=True) else: from chimera import replyobj replyobj.info( 'Warning: Could not restore color zone on surface model\n\twith id %d.%d because that surface was not restored.\n' % surface_id_subid)
def deformatPosition(pos): xfDict = {} for molId, xfData in pos[5].items(): mid, subid = molId trData, rotData = xfData xf = chimera.Xform.translation(*trData) xf.rotate(*rotData) xfDict[(mid+modelOffset, subid)] = xf try: from chimera.misc import KludgeWeakWrappyDict clipDict = KludgeWeakWrappyDict("Model") except ImportError: from weakref import WeakKeyDictionary clipDict = WeakKeyDictionary() for clipID, clipInfo in pos[6].items(): mid, subid, className = clipID models = [m for m in modelMap.get((mid, subid), []) if m.__class__.__name__ == className] if not models: continue useClip, ox, oy, oz, nx, ny, nz, useThick, thickness = clipInfo if useClip: origin = chimera.Point(ox, oy, oz) normal = chimera.Vector(nx, ny, nz) plane = chimera.Plane(origin, normal) else: plane = chimera.Plane() for m in models: clipDict[m] = (useClip, plane, useThick, thickness) return pos[:5] + (xfDict, clipDict) + pos[7:]
def restore_frozen_models(self, scale_bar_dialog): frozen_models = [] if self.frozen_models: if isinstance(self.frozen_models[0], basestring): from SimpleSession import oslMap model_ids = [] for id in self.frozen_models: try: new_id = oslMap(id) except: new_id = id model_ids.append(new_id) id_to_model = {} import chimera for m in chimera.openModels.list(all = 1): id_to_model[m.oslIdent()] = m for id in model_ids: if id_to_model.has_key(id): frozen_models.append(id_to_model[id]) else: from SimpleSession import modelMap for id in self.frozen_models: frozen_models.extend(modelMap.get(id, [])) scale_bar_dialog.frozen_model_list = frozen_models
def restore_frozen_models(self, scale_bar_dialog): frozen_models = [] if self.frozen_models: if isinstance(self.frozen_models[0], basestring): from SimpleSession import oslMap model_ids = [] for id in self.frozen_models: try: new_id = oslMap(id) except: new_id = id model_ids.append(new_id) id_to_model = {} import chimera for m in chimera.openModels.list(all=1): id_to_model[m.oslIdent()] = m for id in model_ids: if id_to_model.has_key(id): frozen_models.append(id_to_model[id]) else: from SimpleSession import modelMap for id in self.frozen_models: frozen_models.extend(modelMap.get(id, [])) scale_bar_dialog.frozen_model_list = frozen_models
def restore_state(self): import SurfaceColor for surface_id_subid, (color_state, caps_only) in self.coloring_table.items(): from SimpleSession import modelMap from _surface import SurfaceModel slist = [s for s in modelMap.get(surface_id_subid, []) if isinstance(s, SurfaceModel)] if len(slist) > 0: surface = slist[0] color_source = color_state.create_color_source() SurfaceColor.color_surface(surface, color_source, caps_only, auto_update = True) else: from chimera import replyobj replyobj.info('Warning: Could not restore surface color on surface model\n\twith id %d.%d because that surface was not restored.\n' % surface_id_subid) # Update gui to show settings from restored session. if self.version >= 2: if self.coloring_table: if self.is_visible: from gui import surface_color_dialog d = surface_color_dialog(create = True) if self.geometry: from SessionUtil import set_window_position set_window_position(d.toplevel_widget, self.geometry) d.surface_menu_cb() d.enter()
def restore_state(self): import SurfaceColor for surface_id_subid, (color_state, caps_only) in self.coloring_table.items(): from SimpleSession import modelMap from _surface import SurfaceModel slist = [ s for s in modelMap.get(surface_id_subid, []) if isinstance(s, SurfaceModel) ] if len(slist) > 0: surface = slist[0] color_source = color_state.create_color_source() SurfaceColor.color_surface(surface, color_source, caps_only, auto_update=True) else: from chimera import replyobj replyobj.info( 'Warning: Could not restore surface color on surface model\n\twith id %d.%d because that surface was not restored.\n' % surface_id_subid) # Update gui to show settings from restored session. if self.version >= 2: if self.coloring_table: if self.is_visible: from gui import surface_color_dialog d = surface_color_dialog(create=True) if self.geometry: from SessionUtil import set_window_position set_window_position(d.toplevel_widget, self.geometry) d.surface_menu_cb() d.enter()
def restore_state(self): from ColorZone import color_zone from SessionUtil import string_to_array, float32 czt = self.color_zone_table for surface_id_subid, (points, colors, distance) in czt.items(): from SimpleSession import modelMap from _surface import SurfaceModel surfaces = [s for s in modelMap.get(surface_id_subid, []) if isinstance(s, SurfaceModel)] if surfaces: # TODO: If more than one surface may get wrong one. surface = surfaces[0] if self.version >= 2: npoints = string_to_array(points, float32, 3) ncolors = string_to_array(colors, float32, 4) else: from numpy import array, single as floatc npoints = array(points, floatc) ncolors = array(colors, floatc) color_zone(surface, npoints, ncolors, distance, auto_update = True) else: from chimera import replyobj replyobj.info('Warning: Could not restore color zone on surface model\n\twith id %d.%d because that surface was not restored.\n' % surface_id_subid)
def id_to_model(id): model = None if isinstance(id, tuple) and len(id) == 3: from SimpleSession import modelMap mlist = [m for m in modelMap.get(id[:2], []) if m.name == id[2]] if len(mlist) == 1: model = mlist[0] else: global id_to_model_failed id_to_model_failed.add(id) elif not id is None: from SimpleSession import idLookup model = idLookup(id) return model
def restore_state(self): from numpy import array from SurfaceZone import surface_zone from SessionUtil import string_to_array, floatc for surface_id_subid, (points, distance) in self.zone_table.items(): from SimpleSession import modelMap from _surface import SurfaceModel surfs = [s for s in modelMap.get(surface_id_subid, []) if isinstance(s,SurfaceModel)] if surfs: if self.version >= 2: npoints = string_to_array(points, floatc, 3) else: npoints = array(points, floatc) surface_zone(surfs[0], npoints, distance, auto_update = True) else: from chimera import replyobj replyobj.info('Warning: Could not restore surface zone on surface model\n\twith id %d.%d because that surface was not restored.\n' % surface_id_subid)