예제 #1
0
 def do(self):
     cache = context.application.cache
     for old_parent in cache.nodes:
         for child in old_parent.children:
             if isinstance(child, GLTransformationMixin):
                 primitive.Transform(child, old_parent.transformation)
     UnframeRelative.do(self)
예제 #2
0
 def do(self):
     victim = context.application.cache.node
     Frame = context.application.plugins.get_node("Frame")
     frame = Frame(name="Frame of " + victim.name)
     primitive.Add(frame, victim.parent, index=victim.get_index())
     primitive.Transform(frame, victim.transformation)
     primitive.Move(victim, frame)
     primitive.SetProperty(victim, "transformation",
                           victim.Transformation())
예제 #3
0
 def do(self):
     node = context.application.cache.node
     destination = context.application.cache.drag_destination
     if isinstance(node, GLTransformationMixin):
         transformation = destination.get_frame_relative_to(node.parent)
         primitive.Transform(node, transformation.inv)
     primitive.Move(node,
                    destination,
                    new_index=self.parameters.child_index)
예제 #4
0
    def do(self):
        cache = context.application.cache

        # Translate where possible, if necessary
        translated_nodes = cache.translated_nodes
        if len(translated_nodes) > 0:
            if isinstance(cache.last, GLTransformationMixin) and \
               isinstance(cache.last.transformation, Translation):
                absolute_inversion_center = cache.last.get_absolute_frame().t
            else:
                absolute_inversion_center = numpy.zeros(3, float)
            victims_by_parent = list_by_parent(cache.transformed_nodes)
            for parent, victims in victims_by_parent.iteritems():
                local_inversion_center = parent.get_absolute_frame(
                ).inv * absolute_inversion_center
                for victim in victims:
                    translation = Translation(
                        2 * (local_inversion_center - victim.transformation.t))
                    primitive.Transform(victim, translation)

        # Apply an inversion rotation where possible
        inversion = Rotation(-numpy.identity(3, float))
        for victim in cache.rotated_nodes:
            primitive.Transform(victim, inversion, after=False)
예제 #5
0
    def do(self):
        universe = context.application.cache.node
        # first make sure the cell is right handed
        if numpy.linalg.det(
                universe.cell.matrix) < 0 and universe.cell.active.sum() == 3:
            new_matrix = universe.cell.matrix.copy()
            temp = new_matrix[:, 0].copy()
            new_matrix[:, 0] = new_matrix[:, 1]
            new_matrix[:, 1] = temp
            new_cell = UnitCell(new_matrix, universe.cell.active)
            primitive.SetProperty(universe, "cell", new_cell)

        # then rotate the unit cell box to the normalized frame:
        rotation = universe.cell.alignment_a
        for child in context.application.cache.transformed_children:
            primitive.Transform(child, rotation)
        new_cell = UnitCell(numpy.dot(rotation.r, universe.cell.matrix),
                            universe.cell.active)
        primitive.SetProperty(universe, "cell", new_cell)
예제 #6
0
    def get_new(self, position):
        if self.current_object == "Fragment":
            filename = context.get_share_filename('fragments/%s.cml' %
                                                  self.current_fragment)
            molecule = load_cml(filename)[0]

            Frame = context.application.plugins.get_node("Frame")
            new = Frame(name=self.current_fragment)

            load_filter = context.application.plugins.get_load_filter('cml')
            load_filter.load_molecule(new, molecule)
        else:
            NewClass = context.application.plugins.get_node(
                self.current_object)
            new = NewClass()
            if self.current_object == "Atom":
                new.set_number(self.atom_number)
                new.set_name(periodic[self.atom_number].symbol)

        translation = Translation(position)
        primitive.Transform(new, translation)
        return new
예제 #7
0
def coords_to_zeobuilder(org_coords, opt_coords, atoms, parent, graph=None):
    if graph == None:
        groups = [numpy.arange(len(atoms))]
    else:
        # if the molecular graph has disconnected islands, then each independent
        # part is treated seperately in the loop below
        groups = graph.independent_vertices

    for group in groups:
        group_org = org_coords[group]
        group_opt = opt_coords[group]
        # Transform the guessed geometry as to overlap with the original geometry
        transf = superpose(group_org, group_opt)
        group_opt = transf * group_opt

        # Put coordinates of guessed geometry back into Zeobuilder model
        for i, atomindex in enumerate(group):
            atom = atoms[atomindex]
            # Make sure atoms in subframes are treated properly
            transf = atom.parent.get_frame_relative_to(parent)
            org_pos = atom.transformation.t
            opt_pos = transf.inv * group_opt[i]

            primitive.Transform(atom, Translation(opt_pos - org_pos))
예제 #8
0
 def do(self):
     cache = context.application.cache
     old_parent_transformation = cache.parent.transformation
     for node in cache.transformed_nodes:
         primitive.Transform(node, old_parent_transformation)
     OneLevelHigherRelative.do(self)
예제 #9
0
 def do(self, parent, transformed_children, transformation):
     if isinstance(parent,
                   GLTransformationMixin) and not parent.get_fixed():
         primitive.Transform(parent, transformation, after=False)
     for child in transformed_children:
         primitive.Transform(child, transformation.inv)
예제 #10
0
    def replace(self, gl_object):
        if not gl_object.get_fixed():
            new = self.get_new(gl_object.transformation.t)

            # select a target object, i.e. the one the will be connected with
            # the bonds/vectors/... of the replaced object
            if (self.current_object == "Fragment"):
                # fragments are inserted as frames
                # take atom with index 1 as target
                target_object = new.children[1]
            else:
                target_object = new
            # check if all connections to the replaced object are applicable
            # to the new object. if not, then do not perform the replacement
            # and return early.
            for reference in gl_object.references[::-1]:
                if not reference.check_target(target_object):
                    return
            # add the new object
            parent = gl_object.parent
            primitive.Add(new, parent)

            if (self.current_object == "Fragment"):
                # Fix the rotation and translation of the molecular fragment.
                # Rotation
                Bond = context.application.plugins.get_node("Bond")
                if len(gl_object.references) == 1 and isinstance(
                        gl_object.references[0].parent, Bond):
                    bond1 = gl_object.references[0].parent
                    direction1 = bond1.shortest_vector_relative_to(parent)
                    if bond1.children[0].target != gl_object:
                        direction1 *= -1
                    bond2 = new.children[0].references[0].parent
                    direction2 = bond2.shortest_vector_relative_to(parent)
                    if bond2.children[0].target != target_object:
                        direction2 *= -1
                    axis = numpy.cross(direction2, direction1)
                    if numpy.linalg.norm(axis) < 1e-8:
                        axis = random_orthonormal(direction1)
                    angle = compute_angle(direction1, direction2)
                    rotation = Rotation.from_properties(angle, axis, False)
                    primitive.Transform(new, rotation)
                else:
                    bond1 = None
                # Tranlsation
                pos_old = new.children[1].get_frame_relative_to(parent).t
                pos_new = gl_object.transformation.t
                translation = Translation(pos_new - pos_old)
                primitive.Transform(new, translation)
                if bond1 != None:
                    # bond length
                    old_length = numpy.linalg.norm(direction1)
                    new_length = bonds.get_length(
                        new.children[1].number,
                        bond1.get_neighbor(gl_object).number)
                    translation = Translation(-direction1 / old_length *
                                              (new_length - old_length))
                    primitive.Transform(new, translation)

            # let the references to the replaced object point to the new object
            for reference in gl_object.references[::-1]:
                try:
                    primitive.SetTarget(reference, target_object)
                except primitive.PrimitiveError:
                    primitive.Delete(reference.parent)
            # delete the replaced object
            primitive.Delete(gl_object)
            if (self.current_object == "Fragment"):
                # Delete the first atom in the fragment
                primitive.Delete(new.children[0])
                # Unframe the fragment
                UnframeAbsolute = context.application.plugins.get_action(
                    "UnframeAbsolute")
                UnframeAbsolute([new])
예제 #11
0
 def immediate_do(self):
     primitive.Transform(context.application.cache.node,
                         self.parameters.transformation)
예제 #12
0
    def do(self):
        transformation = Complete.about_axis(self.parameters.center, numpy.pi,
                                             self.parameters.normal, True)

        for victim in context.application.cache.translated_nodes:
            primitive.Transform(victim, transformation)
예제 #13
0
 def do(self):
     for victim in context.application.cache.translated_nodes:
         primitive.Transform(victim, self.parameters.translation)
예제 #14
0
 def do(self):
     transformation = self.parameters.center * self.parameters.rotation * self.parameters.center.inv
     for victim in context.application.cache.transformed_nodes:
         primitive.Transform(victim, transformation)
예제 #15
0
 def do(self):
     primitive.Transform(context.application.cache.node,
                         self.parameters.rotation,
                         after=False)