Esempio n. 1
0
 def set_transformation(self, transformation, init=False):
     if not transformation.__class__ == self.Transformation:
         # create an object of the proper type and take only the attributes
         # of interest.
         if isinstance(transformation, Translation):
             t = transformation.t
         else:
             t = None
         if isinstance(transformation, Rotation):
             r = transformation.r
         else:
             r = None
         if self.Transformation == Translation:
             if t is None:
                 transformation = Translation.identity()
             else:
                 transformation = Translation(t)
         elif self.Transformation == Rotation:
             if r is None:
                 transformation = Rotation.identity()
             else:
                 transformation = Rotation(r)
         else:  # self.Transformation == Complete:
             if r is None:
                 r = numpy.identity(3, float)
             if t is None:
                 t = numpy.zeros(3, float)
             transformation = Complete(r, t)
     self.transformation = transformation
     if not init:
         self.invalidate_transformation_list()
Esempio n. 2
0
    def do(self):
        cache = context.application.cache
        for node in cache.nodes:
            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(iter_particles(node))
            if mass == 0.0:
                continue

            tensor = compute_inertia_tensor(iter_particles(node), com)
            transformation = Complete(align_rotation_matrix(tensor), com)
            CenterAlignBase.do(self, node, translated_children, transformation)
Esempio n. 3
0
 def update_gui(self):
     if self.status is not None:
         self.la_num_iter.set_text("%i" % self.status.step)
         self.la_rms_error.set_text(
             express_measure(
                 numpy.sqrt(self.status.value / self.num_springs),
                 "Length"))
         self.progress_bar.set_text("%i%%" %
                                    int(self.status.progress * 100))
         self.progress_bar.set_fraction(self.status.progress)
         for state_index, frame, variable in zip(
                 self.state_indices, self.involved_frames,
                 self.minimize.root_expression.state_variables):
             if isinstance(variable, iterative.var.Frame):
                 r, t = variable.extract_state(state_index,
                                               self.status.state)
                 frame.set_transformation(Complete(r, t))
             elif isinstance(variable, iterative.var.Translation):
                 t = variable.extract_state(state_index, self.status.state)
                 new_transformation = frame.transformation.copy_with(t=t)
                 frame.set_transformation(new_transformation)
         context.application.main.drawing_area.queue_draw()
Esempio n. 4
0
    def endElement(self, name):
        if name == "zml_file": return
        # now that we have gatherd all information of this tag, create an appropriate object

        # first find the tags involved in this operation
        current_tag = self.hierarchy[-1][-1]
        child_tags = []
        if not current_tag.being_processed:
            current_tag = self.hierarchy[-2][-1]
            child_tags = self.hierarchy[-1]

        # do it
        if name == "str": current_tag.value = str(current_tag.content)
        elif name == "float": current_tag.value = float(current_tag.content)
        elif name == "int": current_tag.value = int(current_tag.content)
        elif name == "bool":
            temp = current_tag.content.lower().strip()
            if temp == 'true': current_tag.value = True
            else: current_tag.value = False
        elif name == "list": current_tag.value = [tag.value for tag in child_tags]
        elif name == "dict": current_tag.value = dict((tag.label, tag.value) for tag in child_tags)
        elif name == "tuple": current_tag.value = tuple(tag.value for tag in child_tags)
        elif name == "shape":
            current_tag.value = tuple(int(item) for item in current_tag.content.split())
        elif name == "cells":
            current_tag.value = numpy.array([eval(item) for item in current_tag.content.split()])
        elif name == "array":
            child_dict = dict((tag.name, tag.value) for tag in child_tags)
            current_tag.value = numpy.reshape(child_dict["cells"], child_dict["shape"])
        elif name == "grid":
            current_tag.value = numpy.reshape(numpy.array([eval(item) for item in current_tag.content.split()]), (int(current_tag.attributes["rows"]), int(current_tag.attributes["cols"]), -1))
        elif name == "binary":
            current_tag.value = StringIO.StringIO()
            current_tag.content.seek(0)
            base64.decode(current_tag.content, current_tag.value)
        elif name == "translation":
            current_tag.value = Translation(child_tags[0].value)
        elif name == "rotation":
            current_tag.value = Rotation(child_tags[0].value)
        elif name == "transformation":
            child_dict = dict((tag.label, tag.value) for tag in child_tags)
            current_tag.value = Complete(
                child_dict["rotation_matrix"],
                child_dict["translation_vector"],
            )
        elif name == "unit_cell":
            child_dict = dict((tag.label, tag.value) for tag in child_tags)
            current_tag.value = UnitCell(
                child_dict["matrix"],
                child_dict["active"],
            )
        elif name == "expression":
            current_tag.value = Expression(current_tag.content)
        elif name == "reference":
            current_tag.value = None
            referent_tag = self.hierarchy[-3][-1]
            target_ids = self.target_ids.get(referent_tag)
            if target_ids is None:
                target_ids = []
                self.target_ids[referent_tag] = target_ids
            target_ids.append(int(current_tag.attributes["to"]))
        elif name == "model_object":
            Class = context.application.plugins.get_node(str(current_tag.attributes["class"]))
            current_tag.state = dict((tag.label, tag.value) for tag in child_tags)
            current_tag.value = Class()
            self.model_object_tags[int(current_tag.attributes["id"])] = current_tag
        else: pass

        # close the door
        current_tag.content = None
        current_tag.close()
        if len(child_tags) > 0: self.hierarchy.pop()