Example #1
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()
Example #2
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()
Example #3
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()
Example #4
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()
Example #5
0
    def anacompare_phdos(self, nqsmalls, asr=2, chneut=1, dipdip=1, dos_method="tetra", ngqpt=None, 
                         num_cpus=None, stream=sys.stdout): 
        """
        Args:
            nqsmalls: List of integers defining the q-mesh for the DOS. Each integer gives 
            the number of divisions to be used to sample the smallest reciprocal lattice vector.
            asr, chneut, dipdp: Anaddb input variable. See official documentation.
            dos_method: Technique for DOS computation in  Possible choices: "tetra", "gaussian" or "gaussian:0.001 eV".
                In the later case, the value 0.001 eV is used as gaussian broadening
            ngqpt: Number of divisions for the q-mesh in the DDB file. Auto-detected if None (default)
            num_cpus: Number of CPUs (threads) used to parallellize the calculation of the DOSes. Autodetected if None.
            stream: File-like object used for printing.

        Return:
            `namedtuple` with the following attributes:

                phdoses: List of :class:`PhononDos` objects
                plotter: :class:`PhononDosPlotter` object. Use plotter.plot() to visualize the results.
        """
        num_cpus = get_ncpus() if num_cpus is None else num_cpus
        if num_cpus <= 0: num_cpus = 1
        num_cpus = min(num_cpus, len(nqsmalls))

        # TODO: anaget_phdos
        def do_work(nqsmall):
            _, phdos_file = self.anaget_phbst_and_phdos_files(
                nqsmall=nqsmall, ndivsm=1, asr=asr, chneut=chneut, dipdip=dipdip, dos_method=dos_method, ngqpt=ngqpt)
            return phdos_file.phdos                                                                                          

        if num_cpus == 1:
            # Sequential version
            phdoses = [do_work(nqs) for nqs in nqsmalls]

        else:
            # Threads
            print("Computing %d phonon DOS with %d threads" % (len(nqsmalls), num_cpus) )
            phdoses = [None] * len(nqsmalls)

            def worker():
                while True:
                    nqsm, phdos_index = q.get()
                    phdos = do_work(nqsm)
                    phdoses[phdos_index] = phdos
                    q.task_done()

            from threading import Thread
            try:
                from Queue import Queue # py2k
            except ImportError:
                from queue import Queue # py3k

            q = Queue()
            for i in range(num_cpus):
                 t = Thread(target=worker)
                 t.daemon = True
                 t.start()

            for i, nqsmall in enumerate(nqsmalls):
                q.put((nqsmall, i))

            # block until all tasks are done
            q.join()       
    
        # Compute relative difference wrt last phonon DOS. Be careful because the DOSes may be defined 
        # on different frequency meshes ==> spline on the mesh of the last DOS. 
        last_mesh, converged = phdoses[-1].mesh, False
        for i, phdos in enumerate(phdoses[:-1]):
            splined_dos = phdos.spline_on_mesh(last_mesh)
            abs_diff = (splined_dos - phdoses[-1]).abs()
            print(" Delta(Phdos[%d] - Phdos[%d]) / Phdos[%d]: %f" % 
                (i, len(phdoses)-1, len(phdoses)-1, abs_diff.integral().values[-1]), file=stream)

        # Fill the plotter.
        plotter = PhononDosPlotter()
        for nqsmall, phdos in zip(nqsmalls, phdoses):
            plotter.add_phdos(label="nqsmall %d" % nqsmall, phdos=phdos)

        return dict2namedtuple(phdoses=phdoses, plotter=plotter)
Example #6
0
    def test_phdos_plotter(self):
        """Testing PhononDosPlotter."""
        phdos_paths = 2 * [abidata.ref_file("trf2_5.out_PHDOS.nc")]

        plotter = PhononDosPlotter()
        plotter.add_phdos("AlAs", phdos_paths[0])
        plotter.add_phdos("Same-AlAs", phdos_paths[1])
        repr(plotter); str(plotter)
        assert len(plotter.phdos_list) == 2

        if self.has_matplotlib():
            assert plotter.combiplot(show=True)
            assert plotter.gridplot(show=True)
            assert plotter.plot_harmonic_thermo()

        if self.has_ipywidgets():
            assert plotter.ipw_select_plot() is not None
            assert plotter.ipw_harmonic_thermo() is not None

        if self.has_nbformat():
            plotter.write_notebook(nbpath=self.get_tmpname(text=True))
Example #7
0
    def test_phdos_plotter(self):
        """Testing PhononDosPlotter."""
        phdos_paths = 2 * [abidata.ref_file("trf2_5.out_PHDOS.nc")]

        plotter = PhononDosPlotter()
        plotter.add_phdos("AlAs", phdos_paths[0])
        plotter.add_phdos("Same-AlAs", phdos_paths[1])
        repr(plotter)
        str(plotter)
        assert len(plotter.phdos_list) == 2

        if self.has_matplotlib():
            assert plotter.combiplot(show=True)
            assert plotter.gridplot(show=True)
            assert plotter.plot_harmonic_thermo()

        if self.has_ipywidgets():
            assert plotter.ipw_select_plot() is not None
            assert plotter.ipw_harmonic_thermo() is not None

        if self.has_nbformat():
            plotter.write_notebook(nbpath=self.get_tmpname(text=True))