Beispiel #1
0
 def deserialize(self, version, context):
     quaternion = Quaternion()
     x = context.read_float()
     y = context.read_float()
     z = context.read_float()
     w = context.read_float()
     quaternion.set(x, y, z, w)
     return quaternion
 def make_menu(self):
     self.menu = nanome.ui.Menu()
     self.menu_position = Vector3()
     self.menu_rotation = Quaternion()
     self.menu_scale = Vector3()
     self.last = time.time()
     self.outstanding = True
     self.update_menu(self.menu)
     self.request_menu_transform(0, lambda _1, _2, _3: None)
     self.set_menu_transform(0, self.menu_position, self.menu_rotation,
                             self.menu_scale)
     self.request_menu_transform(0, self.check_menu_stats)
 def received(self, head_position, head_rotation, left_controller_position,
              left_controller_rotation, right_controller_position,
              right_controller_rotation):
     self.head_complex.position = self.workspace_matrix * head_position
     new_rotation = self.workspace_matrix * Matrix.from_quaternion(
         head_rotation)
     self.head_complex.rotation = Quaternion.from_matrix(new_rotation)
     self.left_complex.position = self.workspace_matrix * left_controller_position
     new_rotation = self.workspace_matrix * Matrix.from_quaternion(
         left_controller_rotation)
     self.left_complex.rotation = Quaternion.from_matrix(new_rotation)
     self.right_complex.position = self.workspace_matrix * right_controller_position
     new_rotation = self.workspace_matrix * Matrix.from_quaternion(
         right_controller_rotation)
     self.right_complex.rotation = Quaternion.from_matrix(new_rotation)
     self.update_structures_shallow(
         [self.head_complex, self.left_complex, self.right_complex])
     self.request_controller_transforms(self.received)
Beispiel #4
0
 def __init__(self):
     super(_Complex, self).__init__()
     #Molecular
     self._name = "complex"
     self._index_tag = 0
     self._split_tag = ""
     self._remarks = {}
     #Rendering
     self._boxed = False
     self._locked = False
     self._visible = True
     self._computing = False
     self._current_frame = 0
     self._selected = False  #selected on live
     self._surface_dirty = False
     self._surface_refresh_rate = -1.0  # Not used yet, future auto surface refresh
     self._box_label = ""
     #Transform
     self._position = Vector3(0, 0, 0)
     self._rotation = Quaternion(0, 0, 0, 0)
     self._molecules = []
     self._parent = None
Beispiel #5
0
def create_complex():
    val = struct.Complex()
    val.index = 1000
    val._molecules = [struct.Molecule(), create_molecule(), struct.Molecule(), create_molecule()]
    val.boxed = True
    val.visible = False
    val.computing = False
    val.set_current_frame(0)
    val.name = "COMPLEX_NAME"
    val._remarks = dict([("key1", "val1"), ("key2","val2"),("key3", "val3"), ("key4","val4")])
    val.position = Vector3(1,2,3)
    val.rotation = Quaternion(1,2,3,4)
    return val
def random_quaternion():
    #double x,y,z, u,v,w, s
    x = rand_float(-1, 1)
    y = rand_float(-1, 1)
    z = x * x + y * y
    while (z > 1):
        x = rand_float(-1, 1)
        y = rand_float(-1, 1)
        z = x * x + y * y
    u = rand_float(-1, 1)
    v = rand_float(-1, 1)
    w = u * u + v * v
    while (w > 1):
        u = rand_float(-1, 1)
        v = rand_float(-1, 1)
        w = u * u + v * v
    s = math.sqrt((1 - z) / w)
    return Quaternion(x, y, s * u, s * v)
Beispiel #7
0
class _Complex(_Base):
    @classmethod
    def _create(cls):
        return cls()

    def __init__(self):
        super(_Complex, self).__init__()
        #Molecular
        self._name = "complex"
        self._index_tag = 0
        self._split_tag = ""
        self._remarks = {}
        #Rendering
        self._boxed = False
        self._locked = False
        self._visible = True
        self._computing = False
        self._current_frame = 0
        self._selected = False  #selected on live
        self._surface_dirty = False
        self._surface_refresh_rate = -1.0  # Not used yet, future auto surface refresh
        self._box_label = ""
        #Transform
        self._position = Vector3(0, 0, 0)
        self._rotation = Quaternion(0, 0, 0, 0)
        self._molecules = []
        self._parent = None

    def _add_molecule(self, molecule):
        self._molecules.append(molecule)
        molecule._parent = self

    def _remove_molecule(self, molecule):
        self._molecules.remove(molecule)
        molecule._parent = None

    def _set_molecules(self, molecules):
        self._molecules = molecules
        for molecule in molecules:
            molecule._parent = self

    @Logs.deprecated()
    def get_atom_iterator(self):
        iterator = _Complex.AtomIterator(self)
        return iter(iterator)

    class AtomIterator(object):
        def __init__(self, complex):
            self._complex = complex

        def __iter__(self):
            self._molecule = iter(self._complex._molecules)
            self._update_iter()
            return self

        def __next__(self):
            while True:
                try:
                    return next(self._chainAtom)
                except StopIteration:
                    self._update_iter()

        def _update_iter(self):
            while True:
                molecule = next(self._molecule)
                try:
                    self._chainAtom = molecule.get_atom_iterator()
                    break
                except StopIteration:
                    pass

    def _shallow_copy(self, target=None):
        if target == None:
            complex = _Complex._create()
        else:
            complex = target
        #Molecular
        complex._name = self._name
        complex._index_tag = self._index_tag
        complex._split_tag = self._split_tag
        complex._remarks = self._remarks
        #Rendering
        complex._boxed = self._boxed
        complex._locked = self._locked
        complex._visible = self._visible
        complex._computing = self._computing
        complex._current_frame = self._current_frame
        complex._selected = self._selected
        complex._surface_dirty = self._surface_dirty
        complex._surface_refresh_rate = self._surface_refresh_rate
        complex._box_label = self._box_label
        #Transform
        complex._position = self._position.get_copy()
        complex._rotation = self._rotation.get_copy()
        return complex

    def _deep_copy(self):
        return _helpers._copy._deep_copy_complex(self)

    def _convert_to_conformers(self, force_conformers=None):
        result = _helpers._conformer_helper.convert_to_conformers(self, None)
        return result

    def _convert_to_frames(self):
        result = _helpers._conformer_helper.convert_to_frames(self)
        return result

    def __copy_received_complex(self, new_complex):
        if new_complex != None:
            new_complex._shallow_copy(self)
            self._molecules = new_complex._molecules
Beispiel #8
0
def create_workspace():
    workspace = struct.Workspace()
    workspace.complexes = [struct.Complex(), create_complex(), struct.Complex(), create_complex()]
    workspace.position = Vector3(1,2,3)
    workspace.rotation = Quaternion(1,2,3,4)
    return workspace
class ControllerTrackingPlugin(nanome.PluginInstance):
    def start(self):
        self.make_tracking_atoms()
        self.make_menu()
        import time
        time.sleep(5)
        Logs.debug("requesting complexes")
        self.request_complex_list(self.connect_complexes)

    def make_menu(self):
        self.menu = nanome.ui.Menu()
        self.menu_position = Vector3()
        self.menu_rotation = Quaternion()
        self.menu_scale = Vector3()
        self.last = time.time()
        self.outstanding = True
        self.update_menu(self.menu)
        self.request_menu_transform(0, lambda _1, _2, _3: None)
        self.set_menu_transform(0, self.menu_position, self.menu_rotation,
                                self.menu_scale)
        self.request_menu_transform(0, self.check_menu_stats)

    def check_menu_stats(self, pos, rot, scale):
        self.outstanding = False
        if not self.menu_position.equals(pos) or not self.menu_rotation.equals(
                rot) or not self.menu_scale.equals(scale):
            Logs.error("Menu not where it should be!")
            Logs.error(self.menu_position, pos)
            Logs.error(self.menu_rotation, rot)
            Logs.error(self.menu_scale, scale)
        else:
            Logs.debug("passed menu check")

    def update(self):
        if self.outstanding == False:
            curr = time.time()
            if curr - self.last > 3:
                self.outstanding = True
                self.last = curr
                self.menu_position = rand_pos()
                self.menu_rotation = random_quaternion()
                self.menu_scale = rand_scale()
                self.set_menu_transform(0, self.menu_position,
                                        self.menu_rotation, self.menu_scale)
                self.request_menu_transform(0, self.check_menu_stats)
        return super().update()

    def make_tracking_atoms(self):
        workspace = Workspace()
        self.world_matrix = workspace.get_workspace_to_world_matrix()
        self.workspace_matrix = workspace.get_world_to_workspace_matrix()
        self.head_complex = self.build_simple_complex("head",
                                                      nanome.util.Color.Red())
        self.left_complex = self.build_simple_complex("left",
                                                      nanome.util.Color.Blue())
        self.right_complex = self.build_simple_complex(
            "right", nanome.util.Color.Green())
        workspace.add_complex(self.head_complex)
        workspace.add_complex(self.left_complex)
        workspace.add_complex(self.right_complex)
        Logs.debug("sending a workspace")
        self.update_workspace(workspace)

    def connect_complexes(self, complexes):
        Logs.debug("received some complexes", len(complexes))
        for complex in complexes:
            if complex.name == "head":
                self.head_complex = complex
            elif complex.name == "left":
                self.left_complex = complex
            elif complex.name == "right":
                self.right_complex = complex
        self.request_controller_transforms(self.received)

    def build_simple_complex(self, name, color):
        new_complex = Complex()
        new_complex.name = name
        new_molecule = Molecule()
        new_chain = Chain()
        new_residue = Residue()
        new_atom1 = Atom()
        new_atom2 = Atom()
        new_bond = Bond()
        new_complex.add_molecule(new_molecule)
        new_molecule.add_chain(new_chain)
        new_chain.add_residue(new_residue)
        new_residue.add_atom(new_atom1)
        new_residue.add_atom(new_atom2)
        new_residue.add_bond(new_bond)
        new_bond.atom1 = new_atom1
        new_bond.atom2 = new_atom2
        new_atom2.position = Vector3(0, 0, 1)
        new_atom1.atom_color = color
        new_atom2.atom_color = color
        return new_complex

    def received(self, head_position, head_rotation, left_controller_position,
                 left_controller_rotation, right_controller_position,
                 right_controller_rotation):
        self.head_complex.position = self.workspace_matrix * head_position
        new_rotation = self.workspace_matrix * Matrix.from_quaternion(
            head_rotation)
        self.head_complex.rotation = Quaternion.from_matrix(new_rotation)
        self.left_complex.position = self.workspace_matrix * left_controller_position
        new_rotation = self.workspace_matrix * Matrix.from_quaternion(
            left_controller_rotation)
        self.left_complex.rotation = Quaternion.from_matrix(new_rotation)
        self.right_complex.position = self.workspace_matrix * right_controller_position
        new_rotation = self.workspace_matrix * Matrix.from_quaternion(
            right_controller_rotation)
        self.right_complex.rotation = Quaternion.from_matrix(new_rotation)
        self.update_structures_shallow(
            [self.head_complex, self.left_complex, self.right_complex])
        self.request_controller_transforms(self.received)

    def __init__(self):
        pass
Beispiel #10
0
 def __init__(self):
     self._position = Vector3()
     self._rotation = Quaternion()
     self._scale = Vector3(0.02,0.02,0.02)
     self._complexes = []