예제 #1
0
 def default_parameters(cls):
     result = Parameters()
     result.filter_atom1 = Expression()
     result.filter_bond12 = Expression()
     result.filter_atom2 = Expression()
     result.filter_bond23 = Expression()
     result.filter_atom3 = Expression()
     return result
예제 #2
0
    def fn():
        context.application.model.file_open("test/input/precursor.zml")
        context.application.main.select_nodes(
            [context.application.model.universe])

        parameters = Parameters()
        parameters.filter_atom1 = Expression()
        parameters.filter_bond12 = Expression()
        parameters.filter_atom2 = Expression()

        DistributionBondLengths = context.application.plugins.get_action(
            "DistributionBondLengths")
        assert DistributionBondLengths.analyze_selection(parameters)
        DistributionBondLengths(parameters)
예제 #3
0
    def fn():
        context.application.model.file_open("test/input/precursor.zml")
        context.application.main.select_nodes(
            context.application.model.universe.children)

        ScanForConnections = context.application.plugins.get_action(
            "ScanForConnections")
        rotation2 = Rotation.from_properties(1 * numpy.pi, [0, 1, 0], False)

        parameters = ScanForConnections.default_parameters()
        parameters.connect_description1 = (
            Expression(
                "isinstance(node, Atom) and node.number == 8 and node.num_bonds() == 1"
            ),
            Expression("node.get_radius()"),
        )
        parameters.repulse_description1 = (
            Expression(
                "isinstance(node, Atom) and (node.number == 8 or node.number == 14)"
            ),
            Expression("node.get_radius()*1.5"),
        )
        parameters.action_radius = 4 * angstrom
        parameters.hit_tolerance = 0.1 * angstrom
        parameters.rotation2 = rotation2

        assert ScanForConnections.analyze_selection(parameters)
        ScanForConnections(parameters)

        # Try to save the result to file an open it again.
        context.application.model.file_save("test/output/tmp.zml")
        FileNew = context.application.plugins.get_action("FileNew")
        FileNew()
        context.application.model.file_open("test/output/tmp.zml")

        # Do some consistency tests on the connection scanner results:
        for quality, transformation, pairs, inverse_pairs in context.application.model.folder.children[
                0].get_connections():
            assert_arrays_almost_equal(transformation.r, rotation2.r)
            assert len(pairs) >= 2
            if len(inverse_pairs) > 0:
                assert len(pairs) == len(inverse_pairs)
예제 #4
0
 def __init__(self):
     self.atom_expression = Expression()
     FieldsDialogSimple.__init__(
         self, "Neighbor shells",
         fields.faulty.Expression(
             label_text="Atom expression (atom, graph)",
             attribute_name="atom_expression",
             history_name="atom_expression",
             width=250,
             height=150,
         ), (("Evaluate", RESPONSE_EVALUATE), ("Select", RESPONSE_SELECT),
             (gtk.STOCK_SAVE, RESPONSE_SAVE),
             (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)))
예제 #5
0
    def default_parameters(cls):
        rotation2 = Rotation.from_properties(0.0, [1, 0, 0], False)

        result = Parameters()
        result.connect_description1 = (Expression("True"),
                                       Expression("node.get_radius()"))
        result.repulse_description1 = (Expression("True"),
                                       Expression("node.get_radius()"))
        result.connect_description2 = (Expression("True"),
                                       Expression("node.get_radius()"))
        result.repulse_description2 = (Expression("True"),
                                       Expression("node.get_radius()"))
        result.action_radius = 7 * angstrom
        result.distance_tolerance = 0.1 * angstrom
        result.hit_tolerance = 0.1 * angstrom
        result.allow_inversions = True
        result.minimum_triangle_size = 0.1 * angstrom
        result.rotation_tolerance = 0.05
        result.rotation2 = Undefined(rotation2)
        return result
예제 #6
0
    def init_tree_view(self):
        self.filter_active = False
        self.filter_expression = Expression("True")

        # tree related widgets:
        self.tree_view = gtk.TreeView(context.application.model)
        self.sw_nodes.add(self.tree_view)
        self.tree_view.set_headers_visible(False)
        self.tree_view.connect("button-press-event",
                               self.on_tree_view_button_press_event)
        self.tree_view.connect("row-collapsed", self.on_row_collapsed)

        self.tree_selection = self.tree_view.get_selection()
        self.tree_selection.set_mode(gtk.SELECTION_MULTIPLE)
        self.tree_selection.set_select_function(self.select_path)

        column = gtk.TreeViewColumn("")
        renderer_text = gtk.CellRendererText()
        column.pack_start(renderer_text, expand=False)

        def cell_data_func(column, cell, model, iter):
            cell.set_property("text", model.get_path(iter)[-1])

        column.set_cell_data_func(renderer_text, cell_data_func)
        self.tree_view.append_column(column)

        renderer_pixbuf = gtk.CellRendererPixbuf()
        self.column = gtk.TreeViewColumn()
        self.column.pack_start(renderer_pixbuf, expand=False)

        def render_icon(column, cell, model, iter):
            cell.set_property('pixbuf', model.get_value(iter, 0).icon)

        self.column.set_cell_data_func(renderer_pixbuf, render_icon)

        renderer_text = gtk.CellRendererText()
        self.column.pack_start(renderer_text, expand=False)

        def render_name(column, cell, model, iter):
            cell.set_property('text', model.get_value(iter, 0).get_name())

        self.column.set_cell_data_func(renderer_text, render_name)
        self.tree_view.append_column(self.column)
        self.tree_view.set_expander_column(self.column)
예제 #7
0
 def fn():
     FileNew = context.application.plugins.get_action("FileNew")
     FileNew()
     context.application.main.select_nodes([context.application.model.folder])
     AddFolder = context.application.plugins.get_action("AddFolder")
     assert AddFolder.analyze_selection()
     AddFolder()
     context.application.main.select_nodes([context.application.model.folder])
     AddNotes = context.application.plugins.get_action("AddNotes")
     assert AddNotes.analyze_selection()
     AddNotes()
     context.application.main.select_nodes([context.application.model.folder])
     SelectChildrenByExpression = context.application.plugins.get_action("SelectChildrenByExpression")
     parameters = Parameters()
     parameters.recursive = SelectChildrenByExpression.SELECT_PLAIN
     parameters.expression = Expression("isinstance(node, Folder)")
     assert SelectChildrenByExpression.analyze_selection(parameters)
     SelectChildrenByExpression(parameters)
     assert context.application.model.folder.children[0].selected
     assert not context.application.model.folder.children[1].selected
예제 #8
0
    def __init__(self):
        GladeWrapper.__init__(self, "plugins/molecular/gui.glade", "wi_sketch",
                              "window")
        self.window.hide()
        self.init_callbacks(self.__class__)
        self.init_proxies([
            "cb_object", "cb_vector", "cb_erase_filter",
            "bu_edit_erase_filter", "la_current", "bu_set_atom", "cb_bondtype",
            "hbox_atoms", "hbox_quickpicks", "hbox_fragments", "la_fragment",
            "cb_fragment"
        ])

        self.erase_filter = Expression("True")
        #Initialize atom number - this can be changed anytime with the edit_atom_number dialog
        self.atom_number = 6

        # Initialize the GUI
        #  1) common parts of the comboboxes
        def render_icon(column, cell, model, iter):
            if model.get_value(iter, 0) == "Fragment":
                cell.set_property(
                    "pixbuf",
                    context.application.plugins.get_node("Atom").icon)
            else:
                cell.set_property(
                    "pixbuf",
                    context.application.plugins.get_node(
                        model.get_value(iter, 0)).icon)

        #  2) fill the objects combo box
        self.object_store = gtk.ListStore(str)
        self.object_store.append(["Atom"])
        self.object_store.append(["Fragment"])
        self.object_store.append(["Point"])
        self.object_store.append(["Sphere"])
        self.object_store.append(["Box"])
        self.cb_object.set_model(self.object_store)

        renderer_pixbuf = gtk.CellRendererPixbuf()
        self.cb_object.pack_start(renderer_pixbuf, expand=False)
        self.cb_object.set_cell_data_func(renderer_pixbuf, render_icon)
        renderer_text = gtk.CellRendererText()
        self.cb_object.pack_start(renderer_text, expand=True)
        self.cb_object.add_attribute(renderer_text, "text", 0)

        self.cb_object.set_active(0)

        #  3) fill the vector combo box
        self.vector_store = gtk.ListStore(str)
        self.vector_store.append(["Bond"])
        self.vector_store.append(["Arrow"])
        self.vector_store.append(["Spring"])
        self.cb_vector.set_model(self.vector_store)

        renderer_pixbuf = gtk.CellRendererPixbuf()
        self.cb_vector.pack_start(renderer_pixbuf, expand=False)
        self.cb_vector.set_cell_data_func(renderer_pixbuf, render_icon)
        renderer_text = gtk.CellRendererText()
        self.cb_vector.pack_start(renderer_text, expand=True)
        self.cb_vector.add_attribute(renderer_text, "text", 0)

        self.cb_vector.set_active(0)

        # 4) fill the bond type combo box
        self.bondtype_store = gtk.ListStore(str, int)
        self.bondtype_store.append(["Single bond", BOND_SINGLE])
        self.bondtype_store.append(["Double bond", BOND_DOUBLE])
        self.bondtype_store.append(["Triple bond", BOND_TRIPLE])
        self.bondtype_store.append(["Hybrid bond", BOND_HYBRID])
        self.bondtype_store.append(["Hydrogen bond", BOND_HYDROGEN])
        self.cb_bondtype.set_model(self.bondtype_store)

        #no icons like the others, just text here
        renderer_text = gtk.CellRendererText()
        self.cb_bondtype.pack_start(renderer_text, expand=True)
        self.cb_bondtype.add_attribute(renderer_text, "text", 0)

        self.cb_bondtype.set_active(0)

        # register quick pick config setting
        config = context.application.configuration
        config.register_setting(
            "sketch_quickpicks",
            [6, 7, 8, 9, 10, 11],
            DialogFieldInfo(
                "Sketch tool", (0, 2),
                fields.faulty.IntegerList(
                    label_text="Quick pick atoms (applies after restart)",
                    attribute_name="sketch_quickpicks",
                )),
        )

        # 5)create the "quick pick" atom buttons
        for index in xrange(len(config.sketch_quickpicks)):
            atomnumber = config.sketch_quickpicks[index]
            bu_element = gtk.Button("")
            bu_element.set_label("%s" % periodic[atomnumber].symbol)
            bu_element.connect("clicked", self.on_bu_element_clicked, index)
            # add to hbox
            self.hbox_quickpicks.pack_start(bu_element)
            bu_element.show()

        # 6)fill the fragment combo box with filenames from share/fragments
        fragment_dir = context.get_share_filename('fragments')
        self.fragment_store = gtk.ListStore(str)
        for filename in sorted(os.listdir(fragment_dir)):
            # Ignore subfolders and files with extension other than cml
            if os.path.isdir(os.path.join(fragment_dir,
                                          filename)) or filename[-3:] != 'cml':
                continue
            self.fragment_store.append([filename[:-4]])
        self.cb_fragment.set_model(self.fragment_store)

        renderer_text = gtk.CellRendererText()
        self.cb_fragment.pack_start(renderer_text, expand=True)
        self.cb_fragment.add_attribute(renderer_text, "text", 0)
        self.cb_fragment.set_active(0)
예제 #9
0
    def fn():
        context.application.model.file_open("test/input/precursor.zml")
        context.application.main.select_nodes(
            context.application.model.universe.children)

        ScanForConnections = context.application.plugins.get_action(
            "ScanForConnections")

        parameters = ScanForConnections.default_parameters()
        parameters.connect_description1 = (
            Expression(
                "isinstance(node, Atom) and node.number == 8 and node.num_bonds() == 1"
            ),
            Expression("node.get_radius()"),
        )
        parameters.repulse_description1 = (
            Expression(
                "isinstance(node, Atom) and (node.number == 8 or node.number == 14)"
            ),
            Expression("node.get_radius()*1.5"),
        )
        parameters.action_radius = 4 * angstrom
        parameters.hit_tolerance = 0.1 * angstrom
        parameters.allow_inversions = True
        parameters.minimum_triangle_size = 0.1 * angstrom
        parameters.rotation2 = Undefined()

        assert ScanForConnections.analyze_selection(parameters)
        ScanForConnections(parameters)

        # Try to save the result to file an open it again.
        context.application.model.file_save("test/output/tmp.zml")
        FileNew = context.application.plugins.get_action("FileNew")
        FileNew()
        context.application.model.file_open("test/output/tmp.zml")

        # Do some consistency tests on the connection scanner results:
        scan_results = context.application.model.folder.children[0]
        for quality, transformation, pairs, inverse_pairs in scan_results.get_connections(
        ):
            assert len(pairs) >= 3
            if len(inverse_pairs) > 0:
                assert len(pairs) == len(inverse_pairs)

        # Test for the first case that the indicated atom pairs are indeed
        # overlapping.
        context.application.main.select_nodes([scan_results])
        ShowConscanResultsWindow = context.application.plugins.get_action(
            "ShowConscanResultsWindow")
        assert ShowConscanResultsWindow.analyze_selection()
        ShowConscanResultsWindow()
        csrw = ShowConscanResultsWindow.conscan_results_window
        csrw.tree_selection.select_path(0)
        action = CustomAction("Apply connection")
        csrw.apply_normal()
        action.finish()
        quality, transformation, pairs, inverse_pairs = scan_results.connections[
            0]
        for atom1, atom2 in pairs:
            f1 = atom1().get_absolute_frame()
            f2 = atom2().get_absolute_frame()
            d = numpy.linalg.norm(f1.t - f2.t)
            assert d < 1e-5
        csrw.window.hide()
예제 #10
0
 def default_parameters(cls):
     result = Parameters()
     result.expression = Expression()
     result.recursive = cls.SELECT_PLAIN
     return result
예제 #11
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()