Exemple #1
0
    def __init__(self, queue, signal_queue, vbox, window, rotations="", show_unit_cell=True, show_bonds=False):

        threading.Thread.__init__(self)
        self.image_queue = queue
        self.signal_queue = signal_queue
        self.configured = False
        self.ui = FakeUI.__init__(self)
        self.images = Images()
        self.images.initialize([ase.atoms.Atoms()])
        self.killed = False
        self.paused = False

        self.vbox = vbox
        self.window = window

        self.vbox.connect("scroll-event", self.scroll_event)
        self.window.connect("key-press-event", self.on_key_press)
        View.__init__(self, self.vbox, rotations)
        Status.__init__(self, self.vbox)
        self.vbox.show()

        if os.name == "posix":
            self.live_plot = True
        else:
            self.live_plot = False

        self.drawing_area.realize()
        self.scale = 10.0
        self.center = np.array([8, 8, 8])
        self.set_colors()
        self.set_coordinates(0)
        self.center = np.array([0, 0, 0])

        self.tofs = get_tof_names()

        # history tracking arrays
        self.times = []
        self.tof_hist = []
        self.occupation_hist = []

        # prepare diagrams
        self.data_plot = plt.figure()
        # plt.xlabel('$t$ in s')
        self.tof_diagram = self.data_plot.add_subplot(211)
        self.tof_diagram.set_yscale("log")
        # self.tof_diagram.get_yaxis().get_major_formatter().set_powerlimits(
        # (3, 3))
        self.tof_plots = []
        for tof in self.tofs:
            self.tof_plots.append(self.tof_diagram.plot([], [], label=tof)[0])

        self.tof_diagram.legend(loc="lower left")
        self.tof_diagram.set_ylabel("TOF in $\mathrm{s}^{-1}\mathrm{site}^{-1}$")
        self.occupation_plots = []
        self.occupation_diagram = self.data_plot.add_subplot(212)
        for species in sorted(settings.representations):
            self.occupation_plots.append(self.occupation_diagram.plot([], [], label=species)[0])
        self.occupation_diagram.legend(loc=2)
        self.occupation_diagram.set_xlabel("$t$ in s")
        self.occupation_diagram.set_ylabel("Coverage")
Exemple #2
0
    def __init__(self, images=None, rotations='', show_bonds=False, expr=None):

        if not isinstance(images, Images):
            images = Images(images)

        self.images = images
        self.observers = []

        self.config = read_defaults()
        if show_bonds:
            self.config['show_bonds'] = True

        menu = self.get_menu_data()

        self.window = ui.ASEGUIWindow(close=self.exit,
                                      menu=menu,
                                      config=self.config,
                                      scroll=self.scroll,
                                      scroll_event=self.scroll_event,
                                      press=self.press,
                                      move=self.move,
                                      release=self.release,
                                      resize=self.resize)

        View.__init__(self, rotations)
        Status.__init__(self)

        self.subprocesses = []  # list of external processes
        self.movie_window = None
        self.vulnerable_windows = []
        self.simulation = {}  # Used by modules on Calculate menu.
        self.module_state = {}  # Used by modules to store their state.

        self.arrowkey_mode = self.ARROWKEY_SCAN
        self.move_atoms_mask = None

        self.set_frame(len(self.images) - 1, focus=True)

        # Used to move the structure with the mouse
        self.prev_pos = None
        self.last_scroll_time = time()
        self.orig_scale = self.scale

        if len(self.images) > 1:
            self.movie()

        if expr is None:
            expr = self.config['gui_graphs_string']

        if expr is not None and expr != '' and len(self.images) > 1:
            self.plot_graphs(expr=expr, ignore_if_nan=True)
Exemple #3
0
    def __init__(self,
                 images=None,
                 rotations='',
                 show_unit_cell=True,
                 show_bonds=False):

        # Try to change into directory of file you are viewing
        try:
            os.chdir(os.path.split(sys.argv[1])[0])
        # This will fail sometimes (e.g. for starting a new session)
        except:
            pass

        if not images:
            images = Images()
            images.initialize([Atoms()])

        self.images = images

        self.config = read_defaults()

        menu = self.get_menu_data(show_unit_cell, show_bonds)

        self.window = ui.ASEGUIWindow(close=self.exit,
                                      menu=menu,
                                      config=self.config,
                                      scroll=self.scroll,
                                      scroll_event=self.scroll_event,
                                      press=self.press,
                                      move=self.move,
                                      release=self.release,
                                      resize=self.resize)

        View.__init__(self, rotations)
        Status.__init__(self)

        self.graphs = []  # list of matplotlib processes
        self.graph_wref = []  # list of weakrefs to Graph objects
        self.movie_window = None
        self.vulnerable_windows = []
        self.simulation = {}  # Used by modules on Calculate menu.
        self.module_state = {}  # Used by modules to store their state.
        self.arrowkey_mode = self.ARROWKEY_SCAN
        self.move_atoms_mask = None
Exemple #4
0
    def __init__(self, images=None,
                 rotations='',
                 show_unit_cell=True,
                 show_bonds=False):

        # Try to change into directory of file you are viewing
        try:
            os.chdir(os.path.split(sys.argv[1])[0])
        # This will fail sometimes (e.g. for starting a new session)
        except:
            pass

        if not images:
            images = Images()
            images.initialize([Atoms()])

        self.images = images

        self.config = read_defaults()

        menu = self.get_menu_data(show_unit_cell, show_bonds)

        self.window = ui.ASEGUIWindow(self.exit, menu, self.config,
                                      self.scroll,
                                      self.scroll_event,
                                      self.press, self.move, self.release,
                                      self.resize)

        View.__init__(self, rotations)
        Status.__init__(self)

        self.graphs = []  # list of matplotlib processes
        self.graph_wref = []  # list of weakrefs to Graph objects
        self.movie_window = None
        self.vulnerable_windows = []
        self.simulation = {}  # Used by modules on Calculate menu.
        self.module_state = {}  # Used by modules to store their state.
        self.moving = False
        self.move_atoms_mask = None
Exemple #5
0
    def __init__(self,
                 queue,
                 signal_queue,
                 vbox,
                 window,
                 rotations='',
                 show_unit_cell=True,
                 show_bonds=False):

        threading.Thread.__init__(self)
        self.image_queue = queue
        self.signal_queue = signal_queue
        self.configured = False
        self.ui = FakeUI.__init__(self)
        self.images = Images()
        self.aseGui = GUI()
        #self.aseGui.images.initialize([ase.atoms.Atoms()])
        self.images.initialize([ase.atoms.Atoms()])
        self.killed = False
        self.paused = False

        self.vbox = vbox
        self.window = window

        self.vbox.connect('scroll-event', self.scroll_event)
        self.window.connect('key-press-event', self.on_key_press)
        rotations = '0.0x,0.0y,0.0z'  #[3,3,3]#np.zeros(3)
        self.config = {
            'force_vector_scale': None,
            'velocity_vector_scale': None,
            'swap_mouse': False
        }
        View.__init__(self, rotations)
        Status.__init__(self)
        self.vbox.show()

        if os.name == 'posix':
            self.live_plot = True
        else:
            self.live_plot = False

        #self.drawing_area.realize()
        self.scaleA = 3.0
        self.center = np.array([8, 8, 8])
        #self.set_colors()
        #self.set_coordinates(0)
        self.center = np.array([0, 0, 0])

        self.tofs = get_tof_names()

        # history tracking arrays
        self.times = []
        self.tof_hist = []
        self.occupation_hist = []

        # prepare diagrams
        self.data_plot = plt.figure()
        #plt.xlabel('$t$ in s')
        self.tof_diagram = self.data_plot.add_subplot(211)
        self.tof_diagram.set_yscale('log')
        #self.tof_diagram.get_yaxis().get_major_formatter().set_powerlimits(
        #(3, 3))
        self.tof_plots = []
        for tof in self.tofs:
            self.tof_plots.append(self.tof_diagram.plot([], [], label=tof)[0])

        self.tof_diagram.legend(loc='lower left')
        self.tof_diagram.set_ylabel(
            'TOF in $\mathrm{s}^{-1}\mathrm{site}^{-1}$')
        self.occupation_plots = []
        self.occupation_diagram = self.data_plot.add_subplot(212)
        for species in sorted(settings.representations):
            self.occupation_plots.append(
                self.occupation_diagram.plot([], [], label=species)[0], )
        self.occupation_diagram.legend(loc=2)
        self.occupation_diagram.set_xlabel('$t$ in s')
        self.occupation_diagram.set_ylabel('Coverage')
Exemple #6
0
    def __init__(self, images,
                 rotations='',
                 show_unit_cell=True,
                 show_bonds=False):
        # Try to change into directory of file you are viewing
        try:
            os.chdir(os.path.split(sys.argv[1])[0])
        # This will fail sometimes (e.g. for starting a new session)
        except:
            pass
        self.images = images
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        # self.window.set_icon(gtk.gdk.pixbuf_new_from_file('guiase.png'))
        self.window.set_position(gtk.WIN_POS_CENTER)
        # self.window.connect("destroy", lambda w: gtk.main_quit())
        self.window.connect('delete_event', self.exit)
        vbox = gtk.VBox()
        self.window.add(vbox)
        if gtk.pygtk_version < (2, 12):
            self.set_tip = gtk.Tooltips().set_tip

        actions = gtk.ActionGroup("Actions")
        actions.add_actions([
            ('FileMenu', None, _('_File')),
            ('EditMenu', None, _('_Edit')),
            ('ViewMenu', None, _('_View')),
            ('ToolsMenu', None, _('_Tools')),
            # TRANSLATORS: Set up (i.e. build) surfaces, nanoparticles, ...
            ('SetupMenu', None, _('_Setup')),
            ('CalculateMenu', None, _('_Calculate')),
            ('HelpMenu', None, _('_Help')),
            ('Open', gtk.STOCK_OPEN, _('_Open'), '<control>O',
             _('Create a new file'), self.open),
            ('New', gtk.STOCK_NEW, _('_New'), '<control>N',
             _('New ase.gui window'), lambda widget: os.system('ase-gui &')),
            ('Save', gtk.STOCK_SAVE, _('_Save'), '<control>S',
             _('Save current file'), lambda x: save_dialog(self)),
            ('Quit', gtk.STOCK_QUIT, _('_Quit'), '<control>Q', _('Quit'),
             self.exit),
            ('SelectAll', None, _('Select _all'), None, '', self.select_all),
            ('Invert', None, _('_Invert selection'), None, '',
             self.invert_selection),
            ('SelectConstrained', None, _('Select _constrained atoms'), None,
             '', self.select_constrained_atoms),
            ('SelectImmobile', None, _('Select _immobile atoms'), '<control>I',
             '', self.select_immobile_atoms),
            ('Copy', None, _('_Copy'), '<control>C',
             _('Copy current selection and its orientation to clipboard'),
             self.copy_atoms),
            ('Paste', None, _('_Paste'), '<control>V',
             _('Insert current clipboard selection'), self.paste_atoms),
            ('Modify', None, _('_Modify'), '<control>Y',
             _('Change tags, moments and atom types of the selected atoms'),
             self.modify_atoms),
            ('AddAtoms', None, _('_Add atoms'), '<control>A',
             _('Insert or import atoms and molecules'), self.add_atoms),
            ('DeleteAtoms', None, _('_Delete selected atoms'), 'BackSpace',
             _('Delete the selected atoms'), self.delete_selected_atoms),
            ('First', gtk.STOCK_GOTO_FIRST, _('_First image'), 'Home', '',
             self.step),
            ('Previous', gtk.STOCK_GO_BACK, _('_Previous image'), 'Page_Up',
             '', self.step),
            ('Next', gtk.STOCK_GO_FORWARD, _('_Next image'), 'Page_Down', '',
             self.step),
            ('Last', gtk.STOCK_GOTO_LAST, _('_Last image'), 'End', '',
             self.step),
            ('ShowLabels', None, _('Show _Labels')),
            ('HideAtoms', None, _('Hide selected atoms'), None, '',
             self.hide_selected),
            ('ShowAtoms', None, _('Show selected atoms'), None, '',
             self.show_selected),
            ('QuickInfo', None, _('Quick Info ...'), None, '',
             self.quick_info_window),
            ('Repeat', None, _('Repeat ...'), None, '', self.repeat_window),
            ('Rotate', None, _('Rotate ...'), None, '', self.rotate_window),
            ('Colors', None, _('Colors ...'), 'C', '', self.colors_window),
            # TRANSLATORS: verb
            ('Focus', gtk.STOCK_ZOOM_FIT, _('Focus'), 'F', '', self.focus),
            ('ZoomIn', gtk.STOCK_ZOOM_IN, _('Zoom in'), 'plus', '', self.zoom),
            ('ZoomOut', gtk.STOCK_ZOOM_OUT, _('Zoom out'), 'minus', '',
             self.zoom),
            ('ChangeView', None, _('Change View')),
            ('ResetView', None, _('Reset View'), 'equal', '', self.reset_view),
            ('xyPlane', None, _('\'xy\' Plane'), 'z', '', self.set_view),
            ('yzPlane', None, _('\'yz\' Plane'), 'x', '', self.set_view),
            ('zxPlane', None, _('\'zx\' Plane'), 'y', '', self.set_view),
            ('yxPlane', None, _('\'yx\' Plane'), '<alt>z', '', self.set_view),
            ('zyPlane', None, _('\'zy\' Plane'), '<alt>x', '', self.set_view),
            ('xzPlane', None, _('\'xz\' Plane'), '<alt>y', '', self.set_view),
            ('a2a3Plane', None, _('\'a2 a3\' Plane'), '1', '', self.set_view),
            ('a3a1Plane', None, _('\'a3 a1\' Plane'), '2', '', self.set_view),
            ('a1a2Plane', None, _('\'a1 a2\' Plane'), '3', '', self.set_view),
            ('a3a2Plane', None, _('\'a3 a2\' Plane'), '<alt>1', '',
             self.set_view),
            ('a1a3Plane', None, _('\'a1 a3\' Plane'), '<alt>2', '',
             self.set_view),
            ('a2a1Plane', None, _('\'a2 a1\' Plane'), '<alt>3', '',
             self.set_view),
            ('Settings', gtk.STOCK_PREFERENCES, _('Settings ...'), None, '',
             self.settings),
            ('VMD', None, _('VMD'), None, '', self.external_viewer),
            ('RasMol', None, _('RasMol'), None, '', self.external_viewer),
            ('XMakeMol', None, _('xmakemol'), None, '', self.external_viewer),
            ('Avogadro', None, _('avogadro'), None, '', self.external_viewer),
            ('Graphs', None, _('Graphs ...'), None, '', self.plot_graphs),
            ('Movie', None, _('Movie ...'), None, '', self.movie),
            ('EModify', None, _('Expert mode ...'), '<control>E', '',
             self.execute),
            ('Constraints', None, _('Constraints ...'), None, '',
             self.constraints_window),
            ('RenderScene', None, _('Render scene ...'), None, '',
             self.render_window),
            ('NEB', None, _('NE_B'), None, '', self.NEB),
            ('BulkModulus', None, _('B_ulk Modulus'), None, '',
             self.bulk_modulus),
            ('Bulk', None, _('_Bulk Crystal'), None,
             _("Create a bulk crystal with arbitrary orientation"),
             self.bulk_window),
            ('Surface', None, _('_Surface slab'), None,
             _("Create the most common surfaces"), self.surface_window),
            ('Nanoparticle', None, _('_Nanoparticle'), None,
             _("Create a crystalline nanoparticle"), self.nanoparticle_window),
            ('Nanotube', None, _('Nano_tube'), None, _("Create a nanotube"),
             self.nanotube_window),
            ('Graphene', None, _('Graphene'), None,
             _("Create a graphene sheet or nanoribbon"), self.graphene_window),
            ('SetCalculator', None, _('Set _Calculator'), None,
             _("Set a calculator used in all calculation modules"),
             self.calculator_window),
            ('EnergyForces', None, _('_Energy and Forces'), None,
             _("Calculate energy and forces"), self.energy_window),
            ('Minimize', None, _('Energy _Minimization'), None,
             _("Minimize the energy"), self.energy_minimize_window),
            ('Scaling', None, _('Scale system'), None,
             _("Deform system by scaling it"), self.scaling_window),
            ('About', None, _('_About'), None, None, self.about),
            ('Webpage', gtk.STOCK_HELP, _('Webpage ...'), None, None, webpage),
            ('Debug', None, _('Debug ...'), None, None, self.debug)
        ])
        actions.add_toggle_actions([
            ('ShowUnitCell', None, _('Show _unit cell'), '<control>U', 'Bold',
             self.toggle_show_unit_cell,
             show_unit_cell > 0), ('ShowAxes', None, _('Show _axes'), None,
                                   'Bold', self.toggle_show_axes, True),
            ('ShowBonds', None, _('Show _bonds'), '<control>B', 'Bold',
             self.toggle_show_bonds,
             show_bonds), ('ShowVelocities', None, _('Show _velocities'),
                           '<control>G', 'Bold', self.toggle_show_velocities,
                           False), ('ShowForces', None, _('Show _forces'),
                                    '<control>F', 'Bold',
                                    self.toggle_show_forces, False),
            ('MoveAtoms', None, _('_Move atoms'), '<control>M', 'Bold',
             self.toggle_move_mode,
             False), ('RotateAtoms', None, _('_Rotate atoms'), '<control>R',
                      'Bold', self.toggle_rotate_mode,
                      False), ('OrientAtoms', None, _('Orien_t atoms'),
                               '<control>T', 'Bold', self.toggle_orient_mode,
                               False)
        ])
        actions.add_radio_actions(
            (('NoLabel', None, _('_None'), None, None, 0),
             ('AtomIndex', None, _('Atom _Index'), None, None, 1),
             ('MagMom', None, _('_Magnetic Moments'), None, None, 2),
             ('Element', None, _('_Element Symbol'), None, None, 3)), 0,
            self.show_labels)
        self.ui = ui = gtk.UIManager()
        ui.insert_action_group(actions, 0)
        self.window.add_accel_group(ui.get_accel_group())

        ui.add_ui_from_string(ui_info)

        vbox.pack_start(ui.get_widget('/MenuBar'), False, False, 0)

        View.__init__(self, vbox, rotations)
        Status.__init__(self, vbox)
        vbox.show()
        # self.window.set_events(gtk.gdk.BUTTON_PRESS_MASK)
        self.window.connect('key-press-event', self.scroll)
        self.window.connect('scroll_event', self.scroll_event)
        self.window.show()
        self.graphs = []  # list of matplotlib processes
        self.graph_wref = []  # list of weakrefs to Graph objects
        self.movie_window = None
        self.vulnerable_windows = []
        self.simulation = {}  # Used by modules on Calculate menu.
        self.module_state = {}  # Used by modules to store their state.
Exemple #7
0
    def __init__(self, config, images=None, element_colors=None):
        """Initialise the GUI.

        Parameters
        ----------
        config: ViewConfig
            initial configuration settings
        images : ase.gui.images.Images
            list of ase.Atoms, with some settings for visualisations (mainly radii)
        element_colors: list[tuple]
            hex colour for each atomic number (defaults to 'jmol' scheme)

        """
        if not isinstance(images, Images):
            images = Images(images)

        self.images = images
        self.observers = []

        self.config = attr.asdict(config)

        # aliases required by ui.ASEGUIWindow
        self.config["gui_foreground_color"] = self.config["canvas_color_foreground"]
        self.config["gui_background_color"] = self.config["canvas_color_background"]
        self.config["swap_mouse"] = self.config["gui_swap_mouse"]

        menu = self.get_menu_data()

        self.window = ui.ASEGUIWindow(
            close=self.exit,
            menu=menu,
            config=self.config,
            scroll=self.scroll,
            scroll_event=self.scroll_event,
            press=self.press,
            move=self.move,
            release=self.release,
            resize=self.resize,
        )
        # used by ``View.update_labels``
        label_sites = {"index": 1, "magmom": 2, "element": 3, "charge": 4}.get(
            self.config["atom_label_by"], 0
        )
        if not self.config["atom_show_label"]:
            label_sites = 0
        self.window["show-labels"] = label_sites

        View.__init__(self, self.config["rotations"])
        if element_colors:
            self.colors = dict(enumerate(element_colors))

        self.subprocesses = []  # list of external processes
        self.movie_window = None
        self.vulnerable_windows = []
        self.simulation = {}  # Used by modules on Calculate menu.
        self.module_state = {}  # Used by modules to store their state.

        self.arrowkey_mode = self.ARROWKEY_SCAN
        self.move_atoms_mask = None

        self.set_frame(len(self.images) - 1, focus=True)

        # Used to move the structure with the mouse
        self.prev_pos = None
        self.last_scroll_time = self.t0 = time()
        self.orig_scale = self.scale

        self.xy = None

        if len(self.images) > 1:
            self.movie()