Beispiel #1
0
    def OnClick(self, event):
        p = self.dos_panel.GetParams()
        if p.step == 1234:
            awx.tetris_game()

        try:
            edos = self.bands.get_dos(step=p.step, width=p.width)
        except:
            awx.showErrorMessage(self)
            return

        tot_dos, tot_idos = edos.dos_idos()
        label = "$\sigma = %s, step = %s$" % (p.width, p.step)

        plotframe = None
        if self.replot_checkbox.GetValue() and len(self._pframes):
            plotframe = self._pframes[-1]

        if plotframe is None:
            plotframe = PlotFrame(parent=self)
            plotframe.plot(tot_dos.mesh, tot_dos.values, label=label, draw_legend=True)
            plotframe.Show()
            self._pframes.append(plotframe)
        else:
            plotframe.oplot(tot_dos.mesh, tot_dos.values, label=label, draw_legend=True)
Beispiel #2
0
 def OnClick(self, event):
     p = self.jdos_panel.GetParams()
     try:
         self.bands.plot_jdosvc(vrange=p.vrange, crange=p.crange, step=p.step, width=p.width,
                                cumulative=p.cumulative)
     except:
         awx.showErrorMessage(self)
Beispiel #3
0
def show_task_log_events(parent, task):
    file = task.log_file

    if file.exists:
        AbinitEventsFrame(parent, file.path).Show()
    else:
        awx.showErrorMessage(parent=parent, message="Log file %s does not exist" % file.path)
Beispiel #4
0
def show_task_main_events(parent, task):
    file = task.output_file

    if file.exists:
        AbinitEventsFrame(parent, file.path).Show()
    else:
        awx.showErrorMessage(parent=parent, message="Output file %s does not exist" % file.path)
Beispiel #5
0
def show_timer(parent, task):
    """Show timing data of the k."""
    try:
        frame = AbinitTimerFrame(parent, task.output_file.path)
        frame.Show()
    except awx.Error as exc:
        awx.showErrorMessage(parent, str(exc)) 
Beispiel #6
0
    def OnTerminal(self, event):
        """Open a new terminal and ssh to the remote host."""
        cluster = self.GetSelectedCluster() 
        if cluster is None: return

        def open_terminal():
            """Try to figure which terminal is available."""
            retcode = 1

            if retcode and which("gnome-terminal") is not None:
                retcode = os.system("gnome-terminal -e 'ssh %s -X'" % cluster.hostname)

            if retcode and which("konsole") is not None:
                retcode = os.system("konsole -e 'ssh %s -X'" % cluster.hostname)

            # This does not work
            #retcode = os.system('open -a Terminal -n --args %s -X" % cluster.hostname")
                
            if retcode: # Fallback to xterm.
                retcode = os.system("xterm -e ssh %s -X" % cluster.hostname)

            return retcode

        # FIXME: Fix possible problem when the user tries to close the GUI 
        # with active terminals (maintain a list of treads and prevent the user from closing the GUI if threads?)
        try:
            thread = awx.WorkerThread(self, target=open_terminal)
            thread.start()
        except:
            awx.showErrorMessage(self)
Beispiel #7
0
def showAbinitTimerFrame(parent, filepath):
    """Open a dialog reporting file stats."""
    try:
        frame = AbinitTimerFrame(parent, filepath)
        frame.Show()
    except awx.Error as exc:
        awx.showErrorMessage(parent, str(exc))
Beispiel #8
0
    def onOpenButton(self, event):
        wcard = self.getWildCard()
        smode = self.getSelectionMode()
        print("wcard", wcard, "smode", smode)

        # Find the filepaths according to smode.
        filepaths = []

        if smode == "Selected Workflow":
            work = self.viewer.GetSelectedWork()
            for task in work:
                filepaths.extend(task.outdir.list_filepaths(wildcard=wcard))

        elif smode == "Entire Flow":
            for work in self.viewer.flow:
                for task in work:
                    filepaths.extend(task.outdir.list_filepaths(wildcard=wcard))

        else:
            return awx.showErrorMessage(self, "Wrong value of smode: %s" % smode)

        if not filepaths: 
            return awx.showErrorMessage(self, "Cannot find any file matching the specified shell pattern")

        print("filepaths", filepaths)

        # Get the viewer class associated to these files, build the frame and show it.
        frame_class = frameclass_from_filepath(filepaths[0])
        if frame_class is None: return
        frame_class(self, filepaths).Show()
Beispiel #9
0
    def OnClick(self, event):
        p = self.dos_panel.GetParams()
        if p.step == 1234:
            awx.tetris_game()

        try:
            edos = self.bands.get_edos(step=p.step, width=p.width)
        except:
            awx.showErrorMessage(self)
            return

        tot_dos, tot_idos = edos.dos_idos()
        label = "$\sigma = %s, step = %s$" % (p.width, p.step)

        plotframe = None
        if self.replot_checkbox.GetValue() and len(self._pframes):
            plotframe = self._pframes[-1]

        if plotframe is None:
            plotframe = PlotFrame(parent=self)
            plotframe.plot(tot_dos.mesh,
                           tot_dos.values,
                           label=label,
                           draw_legend=True)
            plotframe.Show()
            self._pframes.append(plotframe)
        else:
            plotframe.oplot(tot_dos.mesh,
                            tot_dos.values,
                            label=label,
                            draw_legend=True)
Beispiel #10
0
def show_timer(parent, task):
    """Show timing data of the k."""
    try:
        frame = AbinitTimerFrame(parent, task.output_file.path)
        frame.Show()
    except awx.Error as exc:
        awx.showErrorMessage(parent, str(exc)) 
Beispiel #11
0
    def onOpenButton(self, event):
        wcard = self.getWildCard()
        smode = self.getSelectionMode()
        print("wcard", wcard, "smode", smode)

        # Find the filepaths according to smode.
        filepaths = []

        if smode == "Selected Workflow":
            work = self.viewer.GetSelectedWork()
            for task in work:
                filepaths.extend(task.outdir.list_filepaths(wildcard=wcard))

        elif smode == "Entire Flow":
            for work in self.viewer.flow:
                for task in work:
                    filepaths.extend(task.outdir.list_filepaths(wildcard=wcard))

        else:
            return awx.showErrorMessage(self, "Wrong value of smode: %s" % smode)

        if not filepaths: 
            return awx.showErrorMessage(self, "Cannot find any file matching the specified shell pattern")

        print("filepaths", filepaths)

        # Get the viewer class associated to these files, build the frame and show it.
        frame_class = frameclass_from_filepath(filepaths[0])
        if frame_class is None: return
        frame_class(self, filepaths).Show()
Beispiel #12
0
    def onVisualizeSKB(self, event):
        """
        Calls the visualizer to visualize the specified wavefunction.
        Use the approach described in http://wiki.wxpython.org/LongRunningTasks                                
        to make the Gui responsive one can use 
        """
        #print("in new" ,event.skb)
        spin, kpoint, band = event.skb

        visu_name = self.GetVisualizer()
        if visu_name == "None": return

        self.statusbar.PushStatusText(
            "Visualizing wavefunction (spin=%d, kpoint=%s, band=%d)" %
            (spin, kpoint, band))
        try:
            visu = self.wfk.visualize_ur2(spin,
                                          kpoint,
                                          band,
                                          visu_name=visu_name)

            thread = awx.WorkerThread(self, target=visu)
            thread.start()

        except:
            awx.showErrorMessage(self)
Beispiel #13
0
def showAbinitTimerFrame(parent, filepath):
    """Open a dialog reporting file stats."""
    try:
        frame = AbinitTimerFrame(parent, filepath)
        frame.Show()
    except awx.Error as exc:
        awx.showErrorMessage(parent, str(exc))
Beispiel #14
0
    def OnComparePhbands(self, event):
        """Plot multiple phonon bands"""

        dialog = ewx.BandsCompareDialog(self, self.phbands_filepaths)
        if dialog.ShowModal() == wx.ID_CANCEL: return

        try:
            selected = dialog.GetSelectedIndices()

        except:
            awx.showErrorMessage(self)

        plotter = PhononBandsPlotter()
        # for path, phbands in zip(self.phbands_filepaths, self.phbands_list):
        #     label = os.path.relpath(path)
        #     plotter.add_phbands(label, phbands)

        for i in selected:
            label = os.path.relpath(self.phbands_filepaths[i])
            plotter.add_phbands(label, self.phbands_list[i])

        try:
            print(plotter.bands_statdiff())
        except:
            pass
        plotter.plot()
Beispiel #15
0
    def AppendFilepath(self, abspath):
        """Add a file to the panel."""
        if self.HasAbsPath(abspath):
            awx.showErrorMessage(self,
                                 message="%s is already in the list" % abspath)

        return self._AppendFilepath(abspath)
Beispiel #16
0
def show_task_log(parent, task):
    """Show the log file of the task."""
    file = task.log_file

    if file.exists:
        frame_from_filepath(parent, file.path).Show()
    else:
        awx.showErrorMessage(parent=parent, message="Output file %s does not exist" % file.path)
Beispiel #17
0
 def OnMenuSelection(self, event):
     title = self.menu_title_by_id[event.GetId()]
     callback = self._get_callback(title)
     #print("Calling callback %s on task %s" % (callback, self.task))
     try:
         callback(self.parent, self.task)
     except:
         awx.showErrorMessage(parent=self.parent)
Beispiel #18
0
def show_task_main_events(parent, task):
    """Show the events reported in the main output file."""
    file = task.output_file

    if file.exists:
        AbinitEventsFrame(parent, file.path).Show()
    else:
        awx.showErrorMessage(parent=parent, message="Output file %s does not exist" % file.path)
Beispiel #19
0
def show_task_log_events(parent, task):
    """Show the events reported in the log file."""
    file = task.log_file

    if file.exists:
        AbinitEventsFrame(parent, file.path).Show()
    else:
        awx.showErrorMessage(parent=parent, message="Log file %s does not exist" % file.path)
Beispiel #20
0
 def OnMenuSelection(self, event):
     title = self.menu_title_by_id[event.GetId()]
     callback = self._get_callback(title)
     #print("Calling callback %s on target %s" % (callback, self.target))
     try:
         callback(parent=self.parent, filepath=self.target)
     except:
         awx.showErrorMessage(parent=self.parent)
Beispiel #21
0
def show_task_log(parent, task):
    file = task.log_file

    if file.exists:
        frame = viewerframe_from_filepath(parent, file.path)
        frame.Show()
    else:
        awx.showErrorMessage(parent=parent, message="Output file %s does not exist" % file.path)
Beispiel #22
0
def show_task_log(parent, task):
    """Show the log file of the task."""
    file = task.log_file

    if file.exists:
        frame_from_filepath(parent, file.path).Show()
    else:
        awx.showErrorMessage(parent=parent, message="Output file %s does not exist" % file.path)
Beispiel #23
0
    def OnMenuSelection(self, event):
        """Call the callback selected in the popupmenu."""
        title = self.menu_title_by_id[event.GetId()]
        callback = self.MENU_TITLES[title]

        try:
            callback(parent=self.parent, *self.cb_args, **self.cb_kwargs)
        except:
            awx.showErrorMessage(parent=self)
Beispiel #24
0
    def OnMenuSelection(self, event):
        title = self.menu_title_by_id[event.GetId()]
        callback = self._get_callback(title)

        #print("Calling callback %s with cluster %s and flow %s" % (callback, self.cluster, self.flow))
        try:
            callback(self.parent, self.cluster, self.flow, self.flows_db)
        except:
            awx.showErrorMessage(parent=self.parent)
Beispiel #25
0
    def OnPlotKSwithQPmarkers(self, event):
        """Plot KS energies with QPState markers."""
        if self.sigres is None: return

        band_range = (self.sigres.min_gwbstart, self.sigres.max_gwbstop)
        try:
            BandsWithMarkersPlotFrame(self, self.sigres.ebands, band_range=band_range).Show()
        except awx.Error as exc:
            awx.showErrorMessage(self)
Beispiel #26
0
    def OnFermiSurface(self, event):
        """Visualize the Fermi surface with Xcrysden."""
        try:
            visu = self.ebands.export_bxsf(".bxsf")

            thread = awx.WorkerThread(self, target=visu)
            thread.start()

        except Exception:
            awx.showErrorMessage(self)
Beispiel #27
0
    def OnPlotKSwithQPmarkers(self, event):
        """Plot KS energies with QPState markers."""
        if self.active_sigres is None: return
        sigres = self.active_sigres

        band_range = (sigres.min_gwbstart, sigres.max_gwbstop)
        try:
            EbandsWithMarkersPlotFrame(self, sigres.ebands, band_range=band_range).Show()
        except:
            awx.showErrorMessage(self)
Beispiel #28
0
    def onPlotPhbandsWithDos(self, event):
        """Plot phonon bands with DOS"""

        try:
            if not self.phdos:
                awx.showErrorMessage(self, message="PHDOS data should be loaded using the menu Phband->Add phdos data")
            else:
                self.phbands.plot_with_phdos(self.phdos)
        except:
            awx.showErrorMessage(self)
Beispiel #29
0
 def OnClick(self, event):
     p = self.jdos_panel.GetParams()
     try:
         self.bands.plot_ejdosvc(vrange=p.vrange,
                                 crange=p.crange,
                                 step=p.step,
                                 width=p.width,
                                 cumulative=p.cumulative)
     except:
         awx.showErrorMessage(self)
Beispiel #30
0
    def read_file(self, filepath):
        self.statusbar.PushStatusText("Reading %s" % filepath)

        try:
            flow = abilab.AbinitFlow.pickle_load(filepath)
            self.AddFileToHistory(filepath)
            return flow
        except:
            awx.showErrorMessage(self)
            return None
Beispiel #31
0
 def OnFermiSurface(self, event):
     """Visualize the Fermi surface with Xcrysden."""
     try:
         visu = self.ebands.export_bxsf(".bxsf")
                                                                                         
         thread = awx.WorkerThread(self, target=visu)
         thread.start()
                                                                                         
     except Exception:
         awx.showErrorMessage(self)
Beispiel #32
0
    def read_file(self, filepath):
        self.statusbar.PushStatusText("Reading %s" % filepath)

        try:
            flow = abilab.AbinitFlow.pickle_load(filepath)
            self.AddFileToHistory(filepath)
            return flow
        except:
            awx.showErrorMessage(self)
            return None
Beispiel #33
0
    def onPlotPhbandsWithDos(self, event):
        """Plot phonon bands with DOS"""

        try:
            if not self.phdos:
                awx.showErrorMessage(self, message="PHDOS data should be loaded using the menu Phband->Add phdos data")
            else:
                self.phbands.plot_with_phdos(self.phdos)
        except:
            awx.showErrorMessage(self)
Beispiel #34
0
    def OnFitButton(self, event):
        model = self.model_choice.GetStringSelection()

        try:
            eos = EOS(eos_name=model)
            fit = eos.fit(self.volumes, self.energies, vol_unit=self.vol_unit, ene_unit=self.ene_unit)
            print(fit)
            fit.plot()

        except:
            awx.showErrorMessage(self)
Beispiel #35
0
    def OnStructureVisualize(self, event):
        """"Call the visualizer to visualize the crystalline structure."""
        appname = self._id2visuname[event.GetId()]

        try:
            visu = self.structure.visualize(appname=appname)
            thread = awx.WorkerThread(self, target=visu)
            thread.start()

        except Exception:
            awx.showErrorMessage(self)
Beispiel #36
0
    def OnVisualizeStructure(self, event):
        """"Call visualizer to visualize the crystalline structure."""
        if self.wfk is None: return

        visualizer = self.GetVisualizer()
        self.statusbar.PushStatusText("Visualizing crystal structure with %s" % visualizer)
        try:
            visu = self.wfk.visualize_structure_with(visualizer)
            visu()
        except:
            awx.showErrorMessage(self)
Beispiel #37
0
    def OnFitButton(self, event):
        model = self.model_choice.GetStringSelection()

        try:
            eos = EOS(eos_name=model)
            fit = eos.fit(self.volumes, self.energies, vol_unit=self.vol_unit, ene_unit=self.ene_unit)
            print(fit)
            fit.plot()

        except:
            awx.showErrorMessage(self)
Beispiel #38
0
 def read_file(self, filepath):
     """Open netcdf file, create new tab and save the file in the history."""
     self.statusbar.PushStatusText("Reading %s" % filepath)
     try:
         self.addFileTab(self, filepath)
         # don't know why but this does not work!
         self.notebook.Refresh()
         self.notebook.SetSelection(self.notebook.GetPageCount())
         self.AddFileToHistory(filepath)
     except:
         awx.showErrorMessage(self)
Beispiel #39
0
    def OnStructureVisualize(self, event):
        """"Call the visualizer to visualize the crystalline structure."""
        appname = self._id2visuname[event.GetId()]

        try:
            visu = self.structure.visualize(appname=appname)
            thread = awx.WorkerThread(self, target=visu)
            thread.start()

        except Exception:
            awx.showErrorMessage(self)
Beispiel #40
0
 def read_file(self, filepath):
     """Open netcdf file, create new tab and save the file in the history."""
     self.statusbar.PushStatusText("Reading %s" % filepath)
     try:
         self.addFileTab(self, filepath)
         # don't know why but this does not work!
         self.notebook.Refresh()
         self.notebook.SetSelection(self.notebook.GetPageCount())
         self.AddFileToHistory(filepath)
     except:
         awx.showErrorMessage(self)
Beispiel #41
0
 def OnPhbandsDos(self, event):
     """Open Frame for the computation of the DOS."""
     if not self.phdos:
         awx.showErrorMessage(self, message="PHDOS data should be loaded using the menu Phband->Add phdos data")
     else:
         plotter = PhononDosPlotter()
         try:
             label = os.path.relpath(self.active_phdos_file.filepath)
             plotter.add_phdos(label, self.phdos)
         except:
             awx.showErrorMessage(self)
         plotter.plot()
Beispiel #42
0
    def OnCompareButton(self, event):
        selected_files = self.panel.GetSelectedFilepaths()

        choice = self.plotter_cbox.GetValue()

        try:
            if choice == "ebands":
                plotter = ElectronBandsPlotter()

                for filepath in selected_files:
                    plotter.add_ebands_from_file(filepath)

                plotter.plot()

            elif choice == "edos":
                # Open dialog to ask the user the DOS parameters.
                dos_dialog = ElectronDosDialog(None)

                if dos_dialog.ShowModal() == wx.ID_OK:
                    p = dos_dialog.GetParams()

                    plotter = ElectronDosPlotter()

                    for filepath in selected_files:
                        plotter.add_edos_from_file(filepath, **p)

                    plotter.plot()

                dos_dialog.Destroy()

            elif choice == "mdf":
                plotter = MdfPlotter()

                for filepath in selected_files:
                    plotter.add_mdf_from_file(filepath, mdf_type="exc")

                plotter.plot()

            elif choice == "sigres":
                plotter = SigresPlotter()

                plotter.add_files(selected_files)

                plotter.plot_qpgaps()
                #plotter.plot_qpenes()

            else:
                awx.showErrorMessage(
                    self,
                    message="No function registered for choice %s" % choice)

        except Exception:
            awx.showErrorMessage(self)
Beispiel #43
0
    def OnComparePhdos(self, event):
        """Plot multiple phonon DOSes"""

        plotter = PhononDosPlotter()
        for path, phdos in zip(self.phdos_filepaths, self.phdos_list):
            try:
                label = os.path.relpath(path)
                plotter.add_phdos(label, phdos)
            except:
                awx.showErrorMessage(self)

        plotter.plot()
Beispiel #44
0
 def _visualize_skb(self, spin, kpoint, band):
     """Calls the visualizer to visualize the specified wavefunction."""
     # To make the Gui responsive one can use the approach described in 
     # http://wiki.wxpython.org/LongRunningTasks
     #visualizer = self.GetVisualizer()
     self.statusbar.PushStatusText("Visualizing wavefunction (spin=%d, kpoint=%s, band=%d)" % (spin, kpoint, band))
     try:
         visu = self.wfk.export_ur2(".xsf", spin, kpoint, band)
         #visu = self.wfk.visualize_ur2_with(spin, kpoint, bands, visualizer)
         visu()
     except:
         awx.showErrorMessage(self)
Beispiel #45
0
 def OnPhbandsDos(self, event):
     """Open Frame for the computation of the DOS."""
     if not self.phdos:
         awx.showErrorMessage(self, message="PHDOS data should be loaded using the menu Phband->Add phdos data")
     else:
         plotter = PhononDosPlotter()
         try:
             label = os.path.relpath(self.active_phdos_file.filepath)
             plotter.add_phdos(label, self.phdos)
         except:
             awx.showErrorMessage(self)
         plotter.plot()
Beispiel #46
0
    def OnComparePhdos(self, event):
        """Plot multiple phonon DOSes"""

        plotter = PhononDosPlotter()
        for path, phdos in zip(self.phdos_filepaths, self.phdos_list):
            try:
                label = os.path.relpath(path)
                plotter.add_phdos(label, phdos)
            except:
                awx.showErrorMessage(self)

        plotter.plot()
Beispiel #47
0
    def wrapper(*args, **kwargs):
        wait = wx.BusyInfo("Contacting host...")

        try:
            result = func(*args, **kwargs)
        except Exception as exc:
            result = exc
        finally:
            del wait
            if isinstance(result, Exception):
                awx.showErrorMessage(args[0], message=straceback(color=None))
            else:
                return result
Beispiel #48
0
    def OnCompareButton(self, event):
        selected_files = self.panel.GetSelectedFilepaths()

        choice = self.plotter_cbox.GetValue()

        try:
            if choice == "ebands":
                plotter = ElectronBandsPlotter()

                for filepath in selected_files:
                    plotter.add_ebands_from_file(filepath)

                plotter.plot()

            elif choice == "edos":
                # Open dialog to ask the user the DOS parameters.
                dos_dialog = ElectronDosDialog(None)

                if dos_dialog.ShowModal() == wx.ID_OK:
                    p = dos_dialog.GetParams()

                    plotter = ElectronDosPlotter()

                    for filepath in selected_files:
                        plotter.add_edos_from_file(filepath, **p)

                    plotter.plot()

                dos_dialog.Destroy()

            elif choice == "mdf":
                plotter = MdfPlotter()

                for filepath in selected_files:
                    plotter.add_mdf_from_file(filepath, mdf_type="exc")

                plotter.plot()

            elif choice == "sigres":
                plotter = SigresPlotter()

                plotter.add_files(selected_files)

                plotter.plot_qpgaps()
                #plotter.plot_qpenes()

            else:
                awx.showErrorMessage(self, message="No function registered for choice %s" % choice)

        except Exception:
            awx.showErrorMessage(self)
Beispiel #49
0
    def _visualize_skb(self, spin, kpoint, band):
        """Calls the visualizer to visualize the specified wavefunction."""
        # To make the Gui responsive one can use the approach described in
        # http://wiki.wxpython.org/LongRunningTasks
        appname = self.GetVisualizer()
        if appname == "None": return

        self.statusbar.PushStatusText("Visualizing wavefunction (spin=%d, kpoint=%s, band=%d)" % (spin, kpoint, band))
        try:
            visu = self.wfk.visualize_ur2(spin, kpoint, band, appname=appname)
            thread = awx.WorkerThread(self, target=visu)
            thread.start()

        except:
            awx.showErrorMessage(self)
Beispiel #50
0
    def ReadWfkFile(self, filepath):
        """Read the WFK file and build the UI."""
        self.statusbar.PushStatusText("Reading %s" % filepath)

        try:
            wfkfile = abiopen(filepath)
            #if not isinstance(wfkfile, WFK_File):
            #    awx.showErrorMessage(self, message="%s is not a valid WFK File" % filepath)
            #    return

            self.wfk = wfkfile
            self.BuildUi()
            self.statusbar.PushStatusText("WFK file %s loaded" % filepath)

        except Exception:
            awx.showErrorMessage(self)
Beispiel #51
0
    def GetNamelist(self):
        """
        Build and returns a string with whe &CONTROL Fortran NAMELIST.
        """
        ecut_list = self.ecut_linspace.getValues()
        if len(ecut_list) <= 1:
            return awx.showErrorMessage(self, message="Ecut list is empty or contains only one item!")
        step = ecut_list[1] - ecut_list[0]

        d = OrderedDict(
            tasks="'" + self.task_choice.GetStringSelection() + "'",
            fftalgs=",".join(str(v) for v in self.fftalgs.GetValues()),
            ncalls=self.ncalls_ctrl.GetValue(),
            max_nthreads=self.max_nthreads_ctrl.GetValue(),
            ndat=self.ndat_ctrl.GetValue(),
            necut=len(ecut_list),
            ecut_arth="%s, %s" % (ecut_list[0], step)
        )

        namelist = ["&CONTROL"]
        for k, v in d.items():
            namelist.append(k + " = " + str(v) + ",")
        namelist.append("/")

        return "\n".join(namelist)
Beispiel #52
0
    def GetNamelist(self):
        """
        Build and returns a string with whe &CONTROL Fortran NAMELIST.
        """
        ecut_list = self.ecut_linspace.getValues()
        if len(ecut_list) <= 1:
            return awx.showErrorMessage(
                self, message="Ecut list is empty or contains only one item!")
        step = ecut_list[1] - ecut_list[0]

        d = OrderedDict(
            tasks="'" + self.task_choice.GetStringSelection() + "'",
            fftalgs=",".join(str(v) for v in self.fftalgs.GetValues()),
            ncalls=self.ncalls_ctrl.GetValue(),
            max_nthreads=self.max_nthreads_ctrl.GetValue(),
            ndat=self.ndat_ctrl.GetValue(),
            necut=len(ecut_list),
            ecut_arth="%s, %s" % (ecut_list[0], step))

        namelist = ["&CONTROL"]
        for k, v in d.items():
            namelist.append(k + " = " + str(v) + ",")
        namelist.append("/")

        return "\n".join(namelist)
Beispiel #53
0
    def OnCompareEdos(self, event):
        """Plot multiple electron DOSes"""
        # Open dialog to get DOS parameters.
        dialog = ewx.ElectronDosDialog(self)
        if dialog.ShowModal() == wx.ID_CANCEL: return 
        dos_params = dialog.GetParams()

        plotter = ElectronDosPlotter()
        for path, ebands in zip(self.ebands_filepaths, self.ebands_list):
            try:
                edos = ebands.get_edos(**dos_params)
                label = os.path.relpath(path)
                plotter.add_edos(label, edos)
            except:
                awx.showErrorMessage(self)

        plotter.plot()
Beispiel #54
0
    def onPlotEbandsWithDos(self, event):
        """Plot electron bands with DOS. Requires the specification of two files."""
        # Open dialog to get files and DOS parameters.
        dialog = ewx.EbandsDosDialog(self, self.ebands_filepaths)
        if dialog.ShowModal() == wx.ID_CANCEL: return 

        try:
            dos_params = dialog.getEdosParams()
            ipath, idos = dialog.getBandsDosIndex()

            ebands_path = self.ebands_list[ipath]
            ebands_mesh = self.ebands_list[idos]

            edos = ebands_mesh.get_edos(**dos_params)
            ebands_path.plot_with_edos(edos)
        except:
            awx.showErrorMessage(self)
Beispiel #55
0
    def _visualize_skb(self, spin, kpoint, band):
        """Calls the visualizer to visualize the specified wavefunction."""
        # To make the Gui responsive one can use the approach described in
        # http://wiki.wxpython.org/LongRunningTasks
        appname = self.GetVisualizer()
        if appname == "None": return

        self.statusbar.PushStatusText(
            "Visualizing wavefunction (spin=%d, kpoint=%s, band=%d)" %
            (spin, kpoint, band))
        try:
            visu = self.wfk.visualize_ur2(spin, kpoint, band, appname=appname)
            thread = awx.WorkerThread(self, target=visu)
            thread.start()

        except:
            awx.showErrorMessage(self)
Beispiel #56
0
    def OnNetcdf_NcView(self, event):
        """Call ncview in an subprocess."""
        if which("ncview") is None:
            return awx.showErrorMessage(self, "Cannot find ncview in $PATH")

        for path in self.nc_filepaths:
            def target():
                os.system("ncview %s" % path)

            thread = awx.WorkerThread(self, target=target)
            thread.start()
Beispiel #57
0
def yaml_manager_dialog(parent):
    """
    Open a dialog that allows the user to select a YAML file with the taskmanager.
    Returns the new manager or None if the user clicked CANCEL or the specifed file is not valid.
    """
    dialog = wx.FileDialog(parent, message="Choose a taskmanager.yml file", defaultDir=os.getcwd(),
                           wildcard="YAML files (*.yml)|*.yml",
                           style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
                                                                                                          
    # Show the dialog and retrieve the user response. 
    # If it is the OK response, process the data.
    if dialog.ShowModal() == wx.ID_CANCEL: return None
    filepath = dialog.GetPath()
    dialog.Destroy()

    try:
        return abilab.TaskManager.from_file(filepath)
    except:
        awx.showErrorMessage(parent)
        return None
Beispiel #58
0
    def OnConvert(self, event):
        try:
            fvalue = float(self.from_textctrl.GetValue())
        except:
            awx.showErrorMessage(self)
            return

        from_unit = self.from_unit_choice.GetValue()
        if from_unit == "foo":
            from abipy.gui.awx.eggs import Puzzle
            return Puzzle(self)

        ufloat = units.FloatWithUnit(fvalue, from_unit)
        to_unit = self.to_unit_choice.GetValue()

        try:
            conversion = ufloat.to(to_unit)
            print(ufloat, conversion)
            self.to_textctrl.SetValue(str(float(conversion)))

        except:
            awx.showErrorMessage(self)
Beispiel #59
0
    def OnStartFitButton(self, event):
        """Callback that start the generation of the scissors."""
        num_domains = int(self.numdomains_ctrl.GetValue())

        build_dialog = ScissorsParamsDialog(self, self.nsppol, num_domains,
                                            self.e0min, self.e0max)

        if build_dialog.ShowModal() == wx.ID_OK:
            # Get the parameters of the scissors.
            p = build_dialog.GetScissorBuilderParams()
            #logger.info("scissor params", p)

            # Try the fit.
            fitok = True
            try:
                self.scissors_builder.build(p.domains_spin, p.bounds_spin)
            except:
                awx.showErrorMessage(self)
                fitok = False

            # Plot the results and save the current contents in the file.
            if fitok:
                self.scissors_builder.plotfit()

                if awx.askUser(self, "Save data?"):
                    saveFileDialog = wx.FileDialog(
                        self, "Save pickle file", "", "",
                        "Pickle files (*.pickle)|*.pickle",
                        wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

                    if saveFileDialog.ShowModal() == wx.ID_OK:
                        savefile = saveFileDialog.GetPath()
                        #logger.info("About to save in %s" % savefile)
                        self.scissors_builder.save_data(savefile)

                    saveFileDialog.Destroy()

        build_dialog.Destroy()