Пример #1
0
 def _command_handler(self, value):
     _debug_print("command handler: %s: %s" % (type(value), value))
     answer = {
         "status": True,  # Success!
         "command": str(value),
     }
     from chimera2 import cli
     try:
         from chimera2.trackchanges import track
         cmd = cli.Command(value, final=True)
         cmd.error_check()
         answer["command"] = cmd.current_text
         result = []
         try:
             track.block()
             info = cmd.execute()
         finally:
             track.release()
         if isinstance(info, str):
             result.append(["info", info])
         if client_data:
             result.extend(client_data)
             client_data.clear()
         answer["client_data"] = result
     except cli.UserError as e:
         answer["status"] = False
         answer["error"] = str(e)
     except Exception:
         import traceback
         answer["status"] = False
         answer["error"] = traceback.format_exc()
     return answer
Пример #2
0
 def cmd_window_size(self, width: int, height: int):
     from chimera2.trackchanges import track
     # assume 18 inches from screen
     dist_in = 18
     height_in = height / self.physicalDotsPerInch()
     import math
     track.block()
     self.main_view.fov = 2 * math.atan2(height_in, dist_in)
     self.main_view.viewport = width, height
     track.release()
Пример #3
0
 def process_command(self, text):
     from chimera2 import cli
     from chimera2.trackchanges import track
     try:
         track.block()
         self.command.parse_text(text, final=True)
         info = self.command.execute()
         if isinstance(info, str):
             self.status(info)
     except cli.UserError as e:
         self.status(str(e))
     except Exception:
         import traceback
         traceback.print_exc()
Пример #4
0
def init_chimerax():
    # initialize chimerax internals
    #   -- setup graphics to generate JSON
    #   -- register all commands
    #
    # Supported tags include:
    #	"llgr"	-- for llgr JSON format data
    #	...
    global main_view
    from chimera2 import scene
    scene.set_glsl_version('webgl')
    import llgr
    llgr.set_output('json')
    from chimera2 import io, commands
    io.initialize_formats()
    commands.register()
    # TODO: set HOME to home directory of authenticated user, so ~/ works

    #
    # Augment JSON converter to support additional types
    #
    from webapp_server import register_json_converter

    # TODO: figure how to automate this
    register_json_converter(llgr.AttributeInfo, llgr.AttributeInfo.json)
    register_json_converter(llgr.Enum, lambda x: x.value)
    from chimera2 import math3d
    register_json_converter(math3d.BBox, lambda x: {
        'llb': x.llb,
        'urf': x.urf
    })
    import numpy
    # This handles math3d Points and Vectors as well
    register_json_converter(numpy.ndarray, list)

    # register data handlers
    from chimera2.trackchanges import track
    track.add_handler(scene.View, update_client_data)

    #
    track.block()  # block so main_view is assigned before tracking is done
    main_view = scene.View()
    scene.reset()
    track.release()
Пример #5
0
 def process_command(self, text=""):
     from chimera2 import cli
     from chimera2.trackchanges import track
     try:
         track.block()
         if not text:
             text = self.command.current_text
         self.command.parse_text(text, final=True)
         info = self.command.execute()
         if isinstance(info, str):
             self.status(info)
     except cli.UserError as e:
         self.status(str(e))
     except Exception:
         # TODO: report error
         import traceback
         traceback.print_exc()
     finally:
         track.release()