コード例 #1
0
ファイル: sketch.py プロジェクト: woutersmet/Zeosummer
    def replace(self, gl_object):
        if not gl_object.get_fixed():
            state = gl_object.__getstate__()
            state.pop("name", None)
            state.pop("transformation", None)
            new = self.get_new(gl_object.transformation.t)

            if(self.current_object == "Fragment"): #fragments are inserted at frames - have no refs
                target_object = new.children[1]
            else:
                target_object = new
            for reference in gl_object.references[::-1]:
                if not reference.check_target(target_object):
                    return
            parent = gl_object.parent
            import copy
            primitive.Add(new, parent)
            if(self.current_object == "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()
                    rotation.set_rotation_properties(angle,axis,False)
                    primitive.Transform(new, rotation)
                else:
                    bond1 = None
                # tranlsation
                translation = Translation()
                pos_old = new.children[1].get_frame_relative_to(parent).t
                pos_new = gl_object.transformation.t
                translation.t = 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()
                    translation.t = -direction1/old_length*(new_length-old_length)
                    primitive.Transform(new, translation)

            for reference in gl_object.references[::-1]:
                reference.set_target(target_object)
            primitive.Delete(gl_object)
            if(self.current_object == "Fragment"):
                primitive.Delete(new.children[0])
                # get rid of frame
                UnframeAbsolute = context.application.plugins.get_action("UnframeAbsolute")
                UnframeAbsolute([new])
コード例 #2
0
ファイル: molecule.py プロジェクト: woutersmet/Zeo_thesis
    def do(self):
        cache = context.application.cache

        graph = create_molecular_graph(cache.nodes)
        parent = cache.node

        Frame = context.application.plugins.get_node("Frame")
        for group in graph.independent_nodes:
            atoms = [graph.molecule.atoms[i] for i in group]
            new_positions = self.calc_new_positions(group, atoms, graph, parent)
            frame = Frame(name=chemical_formula(atoms)[1])
            primitive.Add(frame, parent, index=0)
            for node, atom in zip(group, atoms):
                primitive.Move(atom, frame)
                new_position = new_positions[node]
                translation = Translation()
                translation.t = atom.get_parentframe_up_to(parent).vector_apply_inverse(new_position)
                primitive.SetProperty(atom, "transformation", translation)
            for atom in atoms:
                # take a copy of the references since they are going to be
                # refreshed (changed and reverted) during the loop.
                for reference in copy.copy(atom.references):
                    referent = reference.parent
                    if referent.parent != frame:
                        has_to_move = True
                        for child in referent.children:
                            if child.target.parent != frame:
                                has_to_move = False
                                break
                        if has_to_move:
                            primitive.Move(referent, frame)
コード例 #3
0
ファイル: geometry.py プロジェクト: woutersmet/Zeosummer
def coords_to_zeobuilder(org_coords, opt_coords, atoms, parent, graph=None):
    if graph == None:
        atomgroups = [numpy.arange(len(atoms))]
    else:
        atomgroups = graph.independent_nodes

    for group in atomgroups:
        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 = numpy.dot(group_opt, transf.r.transpose()) + transf.t

        # Put coordinates of guessed geometry back into Zeobuilder model
        for i,atomindex in enumerate(group):
            translation = Translation()
            atom = graph.molecule.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.vector_apply_inverse(group_opt[i])

            translation = Translation()
            translation.t = opt_pos - org_pos
            primitive.Transform(atom, translation)
コード例 #4
0
ファイル: geometry.py プロジェクト: woutersmet/Zeo_thesis
def coords_to_zeobuilder(org_coords, opt_coords, atoms, parent):
    # Transform the guessed geometry as to overlap with the original geometry
    transf = superpose(org_coords, opt_coords)
    opt_coords = numpy.dot(opt_coords, transf.r.transpose()) + transf.t

    # Put coordinates of guess geometry back into Zeobuilder model
    for i in xrange(len(atoms)):
        translation = Translation()
        atom = atoms[i]
        # Make sure atoms in subframes are treated properly
        transf = atom.parent.get_frame_relative_to(parent)
        org_pos = atom.transformation.t
        opt_pos = transf.vector_apply_inverse(opt_coords[i])
        translation.t = opt_pos - org_pos
        primitive.Transform(atom, translation)
コード例 #5
0
ファイル: center_align.py プロジェクト: woutersmet/Zeo_thesis
 def do(self):
     cache = context.application.cache
     for node in cache.nodes:
         translation = Translation()
         child_translations = []
         translated_children = []
         for child in node.children:
             if isinstance(child, GLTransformationMixin) and isinstance(child.transformation, Translation):
                 if child.get_fixed():
                     translated_children = []
                     break
                 translated_children.append(child)
                 child_translations.append(child.transformation)
         if len(translated_children) > 0:
             translation.t = calculate_center(child_translations)
             CenterAlignBase.do(self, node, translated_children, translation)
コード例 #6
0
ファイル: molecule.py プロジェクト: woutersmet/Zeo_thesis
    def do(self):
        cache = context.application.cache
        for node in cache.nodes:
            translation = Translation()

            translated_children = []
            for child in node.children:
                if isinstance(child, GLTransformationMixin) and isinstance(child.transformation, Translation):
                    if child.get_fixed():
                        translated_children = []
                        break
                    translated_children.append(child)
            if len(translated_children) == 0:
                continue

            mass, com = compute_center_of_mass(yield_particles(node))
            if mass == 0.0:
                continue

            translation.t = com
            CenterAlignBase.do(self, node, translated_children, translation)
コード例 #7
0
ファイル: transform.py プロジェクト: woutersmet/Zeo_thesis
    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().vector_apply_inverse(absolute_inversion_center)
                for victim in victims:
                    translation = Translation()
                    translation.t = 2 * (local_inversion_center - victim.transformation.t)
                    primitive.Transform(victim, translation)

        # Apply an inversion rotation where possible
        r = Rotation()
        r.inversion_rotation()
        for victim in cache.rotated_nodes:
            primitive.Transform(victim, r, after=False)
コード例 #8
0
ファイル: center_align.py プロジェクト: woutersmet/Zeo_thesis
 def do(self):
     cache = context.application.cache
     translation = Translation()
     translation.t = copy.deepcopy(cache.node.transformation.t)
     CenterAlignBase.do(self, cache.parent, cache.translated_neighbors, translation)