Exemple #1
0
    def test_abicomp(self):
        """Testing abicomp"""
        env = self.get_env()

        cif_paths = abidata.cif_files("al.cif", "gan.cif", "gan2.cif")
        r = env.run(self.script, "structure", cif_paths[0], cif_paths[1], cif_paths[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)
        r = env.run(self.script, "structure", cif_paths[0], cif_paths[1], cif_paths[2], self.loglevel, self.verbose,
                    "--group", expect_stderr=self.expect_stderr)

        r = env.run(self.script, "spg", cif_paths[0], cif_paths[1], cif_paths[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        r = env.run(self.script, "mp_structure", cif_paths[0], cif_paths[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        dirpath = os.path.join(abidata.dirpath, "refs", "si_ebands")
        args = [os.path.join(dirpath, p) for p in ("si_nscf_GSR.nc", "si_scf_WFK.nc")]
        r = env.run(self.script, "ebands", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        args = [os.path.join(dirpath, p) for p in ("si_scf_GSR.nc", "si_scf_WFK.nc")]
        r = env.run(self.script, "edos", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        dirpath = os.path.join(abidata.dirpath, "refs", "znse_phonons")
        args = [os.path.join(dirpath, p) for p in ("ZnSe_hex_886.out_PHBST.nc", "ZnSe_hex_886.out_PHBST.nc")]
        r = env.run(self.script, "phbands", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        #dirpath = os.path.join(abidata.dirpath, "refs", "znse_phonons")
        args = abidata.ref_files("ZnSe_hex_886.out_PHDOS.nc", "trf2_5.out_PHDOS.nc")
        r = env.run(self.script, "phdos", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        #r = env.run(self.script, "attr", "energy", args[0], args[1], self.loglevel, self.verbose,
        #            expect_stderr=self.expect_stderr)

        paths = [p.filepath for p in abidata.pseudos("14si.pspnc", "B.psp8", "Al.GGA_PBE-JTH.xml")]
        r = env.run(self.script, "pseudos", paths[0], paths[1], paths[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        test_dir = os.path.join(os.path.dirname(__file__),  "..", 'test_files')
        args = [
            os.path.join(abidata.dirpath, "refs", "znse_phonons","ZnSe_hex_qpt_DDB"),
            os.path.join(test_dir, "AlAs_444_nobecs_DDB"),
        ]

        r = env.run(self.script, "ddb", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        args = abidata.ref_files("si_g0w0ppm_nband10_SIGRES.nc",
                                 "si_g0w0ppm_nband20_SIGRES.nc",
                                 "si_g0w0ppm_nband30_SIGRES.nc")
        r = env.run(self.script, "sigres", args[0], args[1], args[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        args = abidata.ref_files("si_444_MDF.nc", "si_666_MDF.nc", "si_888_MDF.nc")
        r = env.run(self.script, "mdf", args[0], args[1], args[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)
Exemple #2
0
    def test_abicomp(self):
        """Testing abicomp"""
        env = self.get_env()

        cif_paths = abidata.cif_files("al.cif", "gan.cif", "gan2.cif")
        r = env.run(self.script, "structure", cif_paths[0], cif_paths[1], cif_paths[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)
        r = env.run(self.script, "structure", cif_paths[0], cif_paths[1], cif_paths[2], self.loglevel, self.verbose,
                    "--group", expect_stderr=self.expect_stderr)

        r = env.run(self.script, "spg", cif_paths[0], cif_paths[1], cif_paths[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        r = env.run(self.script, "mp_structure", cif_paths[0], cif_paths[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        dirpath = os.path.join(abidata.dirpath, "refs", "si_ebands")
        args = [os.path.join(dirpath, p) for p in ("si_nscf_GSR.nc", "si_scf_WFK.nc")]
        r = env.run(self.script, "ebands", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        args = [os.path.join(dirpath, p) for p in ("si_scf_GSR.nc", "si_scf_WFK.nc")]
        r = env.run(self.script, "edos", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        dirpath = os.path.join(abidata.dirpath, "refs", "znse_phonons")
        args = [os.path.join(dirpath, p) for p in ("ZnSe_hex_886.out_PHBST.nc", "ZnSe_hex_886.out_PHBST.nc")]
        r = env.run(self.script, "phbands", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        #dirpath = os.path.join(abidata.dirpath, "refs", "znse_phonons")
        args = abidata.ref_files("ZnSe_hex_886.out_PHDOS.nc", "trf2_5.out_PHDOS.nc")
        r = env.run(self.script, "phdos", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        #r = env.run(self.script, "attr", "energy", args[0], args[1], self.loglevel, self.verbose,
        #            expect_stderr=self.expect_stderr)

        paths = [p.filepath for p in abidata.pseudos("14si.pspnc", "B.psp8", "Al.GGA_PBE-JTH.xml")]
        r = env.run(self.script, "pseudos", paths[0], paths[1], paths[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        test_dir = os.path.join(os.path.dirname(__file__),  "..", 'test_files')
        args = [
            os.path.join(abidata.dirpath, "refs", "znse_phonons","ZnSe_hex_qpt_DDB"),
            os.path.join(test_dir, "AlAs_444_nobecs_DDB"),
        ]

        r = env.run(self.script, "ddb", args[0], args[1], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        args = abidata.ref_files("si_g0w0ppm_nband10_SIGRES.nc",
                                 "si_g0w0ppm_nband20_SIGRES.nc",
                                 "si_g0w0ppm_nband30_SIGRES.nc")
        r = env.run(self.script, "sigres", args[0], args[1], args[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)

        args = abidata.ref_files("si_444_MDF.nc", "si_666_MDF.nc", "si_888_MDF.nc")
        r = env.run(self.script, "mdf", args[0], args[1], args[2], self.loglevel, self.verbose,
                    expect_stderr=self.expect_stderr)
Exemple #3
0
    def test_v1qavg_robot(self):
        """Testing V1qAvgRobot."""
        files = abidata.ref_files(
            "abinitio_qpath_V1QAVG.nc",
            "interpolated_qpath_V1QAVG.nc",
        )

        with V1qAvgRobot.from_files(files[0]) as robot:
            robot.add_file("interpolated_v1qavg", files[1])
            assert len(robot) == 2
            repr(robot)
            str(robot)
            robot.to_string(verbose=2)

            interp_ncfile = robot.abifiles[1]
            assert interp_ncfile.interpolated
            assert interp_ncfile.has_maxw

            # Test matplotlib methods
            if self.has_matplotlib():
                assert robot.plot(ispden=0, vname="v1scf_avg", show=False)
                assert robot.plot_maxw(show=False) is None

                assert interp_ncfile.plot_maxw(show=False)
                assert interp_ncfile.plot_maxw_perts(scale="semilogy",
                                                     sharey=False,
                                                     fontsize=8,
                                                     show=False)

            # Test jupyter notebook creation
            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #4
0
    def test_multiplemdf_plotter(self):
        """Testing MultipleMdfPlotter."""
        mdf_paths = abidata.ref_files("si_444_MDF.nc", "si_666_MDF.nc",
                                      "si_888_MDF.nc")
        plotter = MultipleMdfPlotter()
        for f in mdf_paths:
            plotter.add_mdf_file(f, f)
        repr(plotter)
        str(plotter)
        assert plotter._can_use_basenames_as_labels()
        assert len(plotter._get_qpoints()) == 6

        if self.has_matplotlib():
            xlims, ylims = (2, 3), (1, None)
            plotter.plot(mdf_type="exc",
                         qview="avg",
                         xlims=xlims,
                         ylims=ylims,
                         show=False)
            plotter.plot(mdf_type="exc", qview="all", show=False)
            #plotter.plot_mdftypes(qview="avg", xlims=xlims, ylims=ylims, show=False)
            #plotter.plot_mdftypes(qview="all", xlims=xlims, ylims=ylims, show=False)

        if self.has_ipywidgets():
            assert plotter.ipw_select_plot() is not None
Exemple #5
0
    def test_optic_robot(self):
        """Test OpticRobot."""
        files = abidata.ref_files("gaas_444_OPTIC.nc", "gaas_888_OPTIC.nc",
                                  "gaas_121212_OPTIC.nc")
        with abilab.OpticRobot.from_files(files) as robot:
            repr(robot)
            str(robot)
            robot.to_string(verbose=2)
            assert robot.computed_components_intersection["linopt"] == [
                "xx", "zz"
            ]
            assert robot.computed_components_intersection["shg"] == [
                "xyz", "yyy"
            ]
            assert robot.computed_components_intersection["leo"] == ["xyz"]
            assert [t[2] for t in robot.sortby("nkpt")] == [10, 60, 182]

            df_params = robot.get_params_dataframe()
            self.assert_equal(df_params["nspden"].values, 1)

            # Test plot methods
            if self.has_matplotlib():
                assert robot.plot_linopt_convergence(show=False)
                assert robot.plot_shg_convergence(show=False)
                assert robot.plot_leo_convergence(show=False)
                assert robot.plot_lattice_convergence(sortby="nkpt",
                                                      hue="nspden",
                                                      show=False)

            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #6
0
    def test_a2f_robot(self):
        """Test A2fRobot."""
        files = abidata.ref_files("al_888k_161616q_A2F.nc",
                                  #"al_888k_161616q_A2F.nc",
                                  )
        with abilab.A2fRobot.from_files(files[0]) as robot:
            robot.add_file("same_a2f", files[0])
            assert len(robot) == 2
            repr(robot)
            str(robot)
            robot.to_string(verbose=2)
            #assert [t[2] for t in robot.sortby("nkpt")] == [10, 60, 182]

            df_params = robot.get_params_dataframe()
            self.assert_equal(df_params["nspden"].values, 1)

            data = robot.get_dataframe(with_geo=True)
            #assert "lambda_qcoarse" in data and "omegalog_qintp" in data

            # Mixin
            phbands_plotter = robot.get_phbands_plotter()
            data = robot.get_phbands_dataframe()
            assert "min_freq" in data
            assert np.all(data["nmodes"].values == 3)

            # Test plot methods
            if self.has_matplotlib():
                assert phbands_plotter.boxplot(show=False)

                # Test wrappers provided by RobotWithPhbands
                assert robot.combiplot_phbands(show=False)
                assert robot.gridplot_phbands(show=False)
                assert robot.boxplot_phbands(show=False)
                assert robot.combiboxplot_phbands(show=False)

                # Test A2fRobot plot methods
                assert robot.plot_lambda_convergence(sortby=None,
                                                     hue=None,
                                                     show=False)
                assert robot.plot_lambda_convergence(what="gamma",
                                                     sortby=None,
                                                     hue="nkpt",
                                                     show=False)
                assert robot.plot_a2f_convergence(show=False)
                assert robot.plot_a2f_convergence(hue="nkpt", show=False)
                assert robot.plot_a2fdata_convergence(show=False,
                                                      sortby=None,
                                                      hue="nkpt")
                assert robot.gridplot_a2f(show=False)

                #assert robot.plot_a2ftr_convergence(show=False, sortby=None, hue="nkpt")

            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #7
0
    def test_ddk_analyzer(self):
        """Testing DDK analyzer."""

        ddk_paths = abidata.ref_files(
            "gaas_444_dir1_DDK.nc",
            "gaas_444_dir2_DDK.nc",
            "gaas_444_dir3_DDK.nc",
        )

        with DdksAnalyzer(ddk_paths) as dka:
            repr(dka); str(dka)
            assert dka.to_string(verbose=2)
            assert dka.nsppol == 1 and dka.nspden == 1 and dka.nspinor == 1
Exemple #8
0
    def test_sigres_robot(self):
        """Testing SIGRES robot."""
        filepaths = abidata.ref_files(
            "si_g0w0ppm_nband10_SIGRES.nc",
            "si_g0w0ppm_nband20_SIGRES.nc",
            "si_g0w0ppm_nband30_SIGRES.nc",
        )
        assert len(filepaths) == 3

        with SigresRobot.from_files(filepaths) as robot:
            df_sk = robot.merge_dataframes_sk(spin=0, kpoint=[0, 0, 0])
            qpdata = robot.get_qpgaps_dataframe()
            if self.has_seaborn():
                robot.plot_conv_qpgap(x_vars="sigma_nband")
Exemple #9
0
    def test_aborobot(self):
        """Testing AboRobot."""
        abo_paths = abidata.ref_files("refs/si_ebands/run.abo", "refs/gs_dfpt.abo")
        with AboRobot.from_files(abo_paths) as robot:
            repr(robot); str(robot)
            assert robot.to_string(verbose=2)
            assert robot._repr_html_()
            dims = robot.get_dims_dataframe()
            df = robot.get_dataframe(with_geo=True)
            time_df = robot.get_time_dataframe()
            self.assert_equal(time_df["overall_walltime"].values, [4.0, 26.1])

            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #10
0
    def test_aborobot(self):
        """Testing AboRobot."""
        abo_paths = abidata.ref_files("refs/si_ebands/run.abo", "refs/gs_dfpt.abo")
        with AboRobot.from_files(abo_paths) as robot:
            repr(robot); str(robot)
            assert robot.to_string(verbose=2)
            assert robot._repr_html_()
            dims = robot.get_dims_dataframe()
            df = robot.get_dataframe(with_geo=True)
            time_df = robot.get_time_dataframe()
            self.assert_equal(time_df["overall_walltime"].values, [4.0, 26.1])

            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #11
0
    def test_ddk_analyzer(self):
        """Testing DDK analyzer."""

        ddk_paths = abidata.ref_files(
            "gaas_444_dir1_DDK.nc",
            "gaas_444_dir2_DDK.nc",
            "gaas_444_dir3_DDK.nc",
        )

        with DdksAnalyzer(ddk_paths) as dka:
            repr(dka)
            str(dka)
            assert dka.to_string(verbose=2)
            assert dka.nsppol == 1 and dka.nspden == 1 and dka.nspinor == 1
Exemple #12
0
    def test_phbst_robot(self):
        """Testing PHBST robot."""
        paths = abidata.ref_files("trf2_5.out_PHBST.nc", "ZnSe_hex_886.out_PHBST.nc")

        with abilab.PhbstRobot.from_files(paths) as robot:
            assert len(robot) == len(paths)
            repr(robot); str(robot)
            assert robot.to_string(verbose=2)
            df = robot.get_phbands_dataframe()
            for k in ("min_freq", "max_freq", "std_freq"):
                assert k in df

            if self.has_matplotlib():
                assert robot.plot_phdispl(qpoint=(0, 0, 0), show=False)
Exemple #13
0
    def test_phbst_robot(self):
        """Testing PHBST robot."""
        paths = abidata.ref_files("trf2_5.out_PHBST.nc", "ZnSe_hex_886.out_PHBST.nc")

        with abilab.PhbstRobot.from_files(paths) as robot:
            assert len(robot) == len(paths)
            repr(robot); str(robot)
            assert robot.to_string(verbose=2)
            df = robot.get_phbands_dataframe()
            for k in ("min_freq", "max_freq", "std_freq"):
                assert k in df

            if self.has_matplotlib():
                assert robot.plot_phdispl(qpoint=(0, 0, 0), show=False)
Exemple #14
0
    def test_a2f_robot(self):
        """Test A2fRobot."""
        files = abidata.ref_files(
                "al_888k_161616q_A2F.nc",
                #"al_888k_161616q_A2F.nc",
        )
        with abilab.A2fRobot.from_files(files[0]) as robot:
            robot.add_file("same_a2f", files[0])
            assert len(robot) == 2
            repr(robot); str(robot)
            robot.to_string(verbose=2)
            #assert [t[2] for t in robot.sortby("nkpt")] == [10, 60, 182]

            df_params = robot.get_params_dataframe()
            self.assert_equal(df_params["nspden"].values, 1)

            data = robot.get_dataframe(with_geo=True)
            assert "lambda_qcoarse" in data and "omegalog_qintp" in data

            # Mixin
            phbands_plotter = robot.get_phbands_plotter()
            data = robot.get_phbands_dataframe()
            assert "min_freq" in data
            assert np.all(data["nmodes"].values == 3)

            # Test plot methods
            if self.has_matplotlib():
                assert phbands_plotter.boxplot(show=False)

                # Test wrappers provided by RobotWithPhbands
                assert robot.combiplot_phbands(show=False)
                assert robot.gridplot_phbands(show=False)
                assert robot.boxplot_phbands(show=False)
                assert robot.combiboxplot_phbands(show=False)

                # Test A2fRobot plot methods
                assert robot.plot_lambda_convergence(sortby=None, hue=None, show=False)
                assert robot.plot_lambda_convergence(what="gamma", sortby=None, hue="nkpt", show=False)
                assert robot.plot_a2f_convergence(show=False)
                assert robot.plot_a2f_convergence(hue="nkpt", show=False)
                assert robot.plot_a2fdata_convergence(show=False, sortby=None, hue="nkpt")
                assert robot.gridplot_a2f(show=False)

                #assert robot.plot_a2ftr_convergence(show=False, sortby=None, hue="nkpt")

            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #15
0
    def test_multiplemdf_plotter(self):
        """Testing MultipleMdfPlotter."""
        mdf_paths = abidata.ref_files("si_444_MDF.nc", "si_666_MDF.nc", "si_888_MDF.nc")
        plotter = MultipleMdfPlotter()
        for f in mdf_paths:
            plotter.add_mdf_file(f, f)
        repr(plotter); str(plotter)
        assert plotter._can_use_basenames_as_labels()
        assert len(plotter._get_qpoints()) == 6

        if self.has_matplotlib():
            xlims, ylims = (2, 3), (1, None)
            plotter.plot(mdf_type="exc", qview="avg", xlims=xlims, ylims=ylims, show=False)
            plotter.plot(mdf_type="exc", qview="all", show=False)
            #plotter.plot_mdftypes(qview="avg", xlims=xlims, ylims=ylims, show=False)
            #plotter.plot_mdftypes(qview="all", xlims=xlims, ylims=ylims, show=False)

        if self.has_ipywidgets():
            assert plotter.ipw_select_plot() is not None
Exemple #16
0
    def test_optic_robot(self):
        """Test OpticRobot."""
        files = abidata.ref_files("gaas_444_OPTIC.nc", "gaas_888_OPTIC.nc", "gaas_121212_OPTIC.nc")
        with abilab.OpticRobot.from_files(files) as robot:
            repr(robot); str(robot)
            robot.to_string(verbose=2)
            assert robot.computed_components_intersection["linopt"] == ["xx", "zz"]
            assert robot.computed_components_intersection["shg"] == ["xyz", "yyy"]
            assert robot.computed_components_intersection["leo"] == ["xyz"]
            assert [t[2] for t in robot.sortby("nkpt")] == [10, 60, 182]

            df_params = robot.get_params_dataframe()
            self.assert_equal(df_params["nspden"].values, 1)

            # Test plot methods
            if self.has_matplotlib():
                assert robot.plot_linopt_convergence(show=False)
                assert robot.plot_shg_convergence(show=False)
                assert robot.plot_leo_convergence(show=False)
                assert robot.plot_lattice_convergence(sortby="nkpt", hue="nspden", show=False)

            if self.has_nbformat():
                robot.write_notebook(nbpath=self.get_tmpname(text=True))
Exemple #17
0
#!/usr/bin/env python
r"""
Multiple Bethe-Salpeter calculations
====================================

This example shows how to analyze multiple MDF files.
"""
import abipy.data as abidata
from abipy import abilab

# Read data from multiple files.
mdf_paths = abidata.ref_files("si_444_MDF.nc", "si_666_MDF.nc", "si_888_MDF.nc")
robot = abilab.MdfRobot.from_files(mdf_paths)

# Build MultipleMdfPlotter
plotter = robot.get_multimdf_plotter()

# Plot the dielectric function with excitonic effects.
plotter.plot(mdf_type="exc", qview="avg",
             title="Real and Imaginary part (averaged over q-points)", tight_layout=True)

# Plot the dielectric function computed at the RPA level with KS energies.
# Show q-point dependence.
plotter.plot(mdf_type="rpa", qview="all",
             title="Real and Imaginary part for individual q-points", tight_layout=True)

robot.close()
Exemple #18
0
#!/usr/bin/env python
r"""
Multiple Bethe-Salpeter calculations
====================================

This example shows how to analyze multiple MDF files.
"""
import abipy.data as abidata
from abipy import abilab

# Read data from multiple files.
mdf_paths = abidata.ref_files("si_444_MDF.nc", "si_666_MDF.nc",
                              "si_888_MDF.nc")
robot = abilab.MdfRobot.from_files(mdf_paths)

# Build MultipleMdfPlotter
plotter = robot.get_multimdf_plotter()

# Plot the dielectric function with excitonic effects.
plotter.plot(mdf_type="exc",
             qview="avg",
             title="Real and Imaginary part (averaged over q-points)",
             tight_layout=True)

# Plot the dielectric function computed at the RPA level with KS energies.
# Show q-point dependence.
plotter.plot(mdf_type="rpa",
             qview="all",
             title="Real and Imaginary part for individual q-points",
             tight_layout=True)
Exemple #19
0
    def test_sigres_robot(self):
        """Testing SIGRES robot."""
        filepaths = abidata.ref_files(
            "si_g0w0ppm_nband10_SIGRES.nc",
            "si_g0w0ppm_nband20_SIGRES.nc",
            "si_g0w0ppm_nband30_SIGRES.nc",
        )
        assert abilab.SigresRobot.class_handles_filename(filepaths[0])
        assert len(filepaths) == 3

        with abilab.SigresRobot.from_files(filepaths, abspath=True) as robot:
            assert robot.start is None
            start = robot.trim_paths(start=None)
            assert robot.start == start
            for p, _ in robot.items():
                assert p == os.path.relpath(p, start=start)

            assert robot.EXT == "SIGRES"
            repr(robot); str(robot)
            assert robot.to_string(verbose=2)
            assert robot._repr_html_()

            df_params = robot.get_params_dataframe()
            self.assert_equal(df_params["nsppol"].values, 1)

            label_ncfile_param = robot.sortby("nband")
            assert [t[2] for t in label_ncfile_param] == [10, 20, 30]
            label_ncfile_param = robot.sortby(lambda ncfile: ncfile.ebands.nband, reverse=True)
            assert [t[2] for t in label_ncfile_param] == [30, 20, 10]

            df_sk = robot.merge_dataframes_sk(spin=0, kpoint=[0, 0, 0])
            qpdata = robot.get_qpgaps_dataframe(with_geo=True)

            # Test plotting methods.
            if self.has_matplotlib():
                assert robot.plot_qpgaps_convergence(plot_qpmks=False, sortby=None, hue=None, show=False)
                assert robot.plot_qpgaps_convergence(plot_qpmks=True, sortby="nband", hue="ecuteps", show=False)

                assert robot.plot_qpdata_conv_skb(spin=0, kpoint=(0, 0, 0), band=3, show=False)
                assert robot.plot_qpdata_conv_skb(spin=0, kpoint=(0, 0, 0), band=5,
                        sortby="sigma_nband", hue="ecuteps", show=False)
                with self.assertRaises(TypeError):
                    robot.plot_qpdata_conv_skb(spin=0, kpoint=(0, 0, 0), band=5,
                            sortby="sigma_nband", hue="fooecueps", show=False)

                # Test plot_qpfield_vs_e0
                assert robot.plot_qpfield_vs_e0("qpeme0", sortby=None, hue=None, e0="fermie",
                        colormap="viridis", show=False)
                assert robot.plot_qpfield_vs_e0("ze0", itemp=1, sortby="ebands.nkpt", hue="scr_nband",
                        colormap="viridis", show=False)

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

            robot.pop_label(os.path.relpath(filepaths[0], start=start))
            assert len(robot) == 2
            robot.pop_label("foobar")
            new2old = robot.change_labels(["hello", "world"], dryrun=True)
            assert len(new2old) == 2 and "hello" in new2old

            new2old = robot.remap_labels(lambda af: af.filepath, dryrun=False)
            assert len(new2old) == 2
            assert all(key == abifile.filepath for key, abifile in robot.items())
Exemple #20
0
#!/usr/bin/env python
r"""
DDK.nc
======

This example shows how to analyze DDK.nc files 
containing the velocity matrix elements.
"""
from abipy.abilab import abiopen
import abipy.data as abidata

# Here we use the DDK.nc files shipped with abipy.
# Replace ddk_paths with the paths to your files.
ddk_paths = abidata.ref_files(
    "gaas_444_dir1_DDK.nc",
    "gaas_444_dir2_DDK.nc",
    "gaas_444_dir3_DDK.nc",
)

from abipy.electrons.ddk import DdksAnalyzer

with DdksAnalyzer(ddk_paths) as van:
    print(van)
    #ddk_doses = van.get_doses(method="gaussian", step=0.1, width=0.2)
    #ddk_doses.plot()
    #ddk_doses.plot_with_ebands(ebands_kpath)
Exemple #21
0
    def test_sigres_robot(self):
        """Testing SIGRES robot."""
        filepaths = abidata.ref_files(
            "si_g0w0ppm_nband10_SIGRES.nc",
            "si_g0w0ppm_nband20_SIGRES.nc",
            "si_g0w0ppm_nband30_SIGRES.nc",
        )
        assert abilab.SigresRobot.class_handles_filename(filepaths[0])
        assert len(filepaths) == 3

        with abilab.SigresRobot.from_files(filepaths, abspath=True) as robot:
            assert robot.start is None
            start = robot.trim_paths(start=None)
            assert robot.start == start
            for p, _ in robot.items():
                assert p == os.path.relpath(p, start=start)

            assert robot.EXT == "SIGRES"
            repr(robot)
            str(robot)
            assert robot.to_string(verbose=2)
            assert robot._repr_html_()

            df_params = robot.get_params_dataframe()
            self.assert_equal(df_params["nsppol"].values, 1)

            label_ncfile_param = robot.sortby("nband")
            assert [t[2] for t in label_ncfile_param] == [10, 20, 30]
            label_ncfile_param = robot.sortby(
                lambda ncfile: ncfile.ebands.nband, reverse=True)
            assert [t[2] for t in label_ncfile_param] == [30, 20, 10]

            df_sk = robot.merge_dataframes_sk(spin=0, kpoint=[0, 0, 0])
            qpdata = robot.get_qpgaps_dataframe(with_geo=True)

            # Test plotting methods.
            if self.has_matplotlib():
                assert robot.plot_qpgaps_convergence(plot_qpmks=False,
                                                     sortby=None,
                                                     hue=None,
                                                     show=False)
                assert robot.plot_qpgaps_convergence(plot_qpmks=True,
                                                     sortby="nband",
                                                     hue="ecuteps",
                                                     show=False)

                assert robot.plot_qpdata_conv_skb(spin=0,
                                                  kpoint=(0, 0, 0),
                                                  band=3,
                                                  show=False)
                assert robot.plot_qpdata_conv_skb(spin=0,
                                                  kpoint=(0, 0, 0),
                                                  band=5,
                                                  sortby="sigma_nband",
                                                  hue="ecuteps",
                                                  show=False)
                with self.assertRaises(TypeError):
                    robot.plot_qpdata_conv_skb(spin=0,
                                               kpoint=(0, 0, 0),
                                               band=5,
                                               sortby="sigma_nband",
                                               hue="fooecueps",
                                               show=False)

                # Test plot_qpfield_vs_e0
                assert robot.plot_qpfield_vs_e0("qpeme0",
                                                sortby=None,
                                                hue=None,
                                                e0="fermie",
                                                colormap="viridis",
                                                show=False)
                assert robot.plot_qpfield_vs_e0("ze0",
                                                itemp=1,
                                                sortby="ebands.nkpt",
                                                hue="scr_nband",
                                                colormap="viridis",
                                                show=False)

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

            robot.pop_label(os.path.relpath(filepaths[0], start=start))
            assert len(robot) == 2
            robot.pop_label("foobar")
            new2old = robot.change_labels(["hello", "world"], dryrun=True)
            assert len(new2old) == 2 and "hello" in new2old

            new2old = robot.remap_labels(lambda af: af.filepath, dryrun=False)
            assert len(new2old) == 2
            assert all(key == abifile.filepath
                       for key, abifile in robot.items())