Exemplo n.º 1
0
    def test_ncread_density(self):
        """Read density from NC example data files"""
        assert abidata.DEN_NCFILES

        for path in abidata.DEN_NCFILES:
            print("Reading DEN file %s " % path)

            # Read data directly from file.
            with ETSF_Reader(path) as r:
                nelect_file = r.read_value("number_of_electrons")

            # Compute nelect from data.
            den = Density.from_file(path)
            print(den)
            structure = den.structure
            rhor_tot = den.total_rhor
            rhog_tot = den.total_rhog
            nelect_calc = den.get_nelect().sum()

            # Diff between nelect computed and the one written on file.
            self.assert_almost_equal(nelect_calc, nelect_file)
            self.assert_almost_equal(rhog_tot[0,0,0] * structure.volume, nelect_file)

            if self.which("xcrysden") is not None:
                # Export data in xsf format.
                visu = den.export(".xsf")
                self.assertTrue(callable(visu))

            # Test CUBE files.
            _, tmp_cubefile = tempfile.mkstemp(text=True)
            den.export_to_cube(tmp_cubefile)
            total_den = Density.from_cube(tmp_cubefile)
            assert total_den.structure == den.structure
            assert abs(total_den.get_nelect().sum() - nelect_file) < 1e-3
Exemplo n.º 2
0
    def test_ncread_density(self):
        """Read density from NC example data files"""
        assert abidata.DEN_NCFILES

        for path in abidata.DEN_NCFILES:
            print("Reading DEN file %s " % path)

            # Read data directly from file.
            with ETSF_Reader(path) as r:
                nelect_file = r.read_value("number_of_electrons")

            # Compute nelect from data.
            den = Density.from_file(path)
            print(den)
            structure = den.structure
            rhor_tot = den.total_rhor
            rhog_tot = den.total_rhog
            nelect_calc = den.get_nelect().sum()

            # Diff between nelect computed and the one written on file.
            self.assert_almost_equal(nelect_calc, nelect_file)
            self.assert_almost_equal(rhog_tot[0,0,0] * structure.volume, nelect_file)

            if self.which("xcrysden") is not None:
                # Export data in xsf format.
                visu = den.export(".xsf")
                self.assertTrue(callable(visu))

            # Test CUBE files.
            _, tmp_cubefile = tempfile.mkstemp(text=True)
            den.export_to_cube(tmp_cubefile)
            total_den = Density.from_cube(tmp_cubefile)
            assert total_den.structure == den.structure
            assert abs(total_den.get_nelect().sum() - nelect_file) < 1e-3
Exemplo n.º 3
0
    def test_ncread_density(self):
        """Read density from NC example data files"""
        assert DEN_NCFILES

        for filename in DEN_NCFILES:
            print("Reading file %s " % filename)

            # Read data directly from file.
            with ETSF_Reader(filename) as r:
                nelect_file = r.read_value("number_of_electrons")

            # Compute nelect from data.
            den = Density.from_file(filename)
            print(den)
            den.get_rhor_tot()
            den.get_rhog_tot()
            nelect_calc = den.get_nelect().sum()

            # Diff between nelect computed and the one written on file.
            self.assert_almost_equal(nelect_calc, nelect_file)
            visu = den.export(".xsf")
Exemplo n.º 4
0
    def visualize(self, *args, **kwargs):
        # TODO Here I have to decide if this method should be defined
        # in a subclass of Launcher e.g GSLauncher or in the base class
        from .utils import find_file
        what_visualize = kwargs.get("what_visualize", "crystal")

        visualizer = abipy_env.get_uservar("visualizer", kwargs)

        # Find the correct output file
        out_files = self.odat_files()
        gsfname = find_file(out_files, "GSR")

        if gsfname is None:
            raise RuntimeError("Cannot find GSR file among " % out_files)

        if what_visualize == "crystal":

            structure = Structure.from_file(gsfname)
            structure.visualize(visualizer)()

        elif what_visualize == "density":
            raise NotImplementedError("den_fname?")

            density = Density.from_file(den_fname)
            density.visualize(visualizer)()

        elif what_visualize in [
                "electrons",
                "fermisurface",
        ]:
            from ..electrons import ElectronBands
            energies = ElectronBands.from_file(gsfname)

            if what_visualize == "electrons": energies.plot()
            if what_visualize == "fermisurface":
                raise RuntimeError("No hanlder found for fermisurface")
                #visu = energies.visualize(self, visualizer, structure)
                #visu()
        else:
            raise RuntimeError("No handler found for %s" % what_visualize)
Exemplo n.º 5
0
    def visualize(self, *args, **kwargs):
        # TODO Here I have to decide if this method should be defined
        # in a subclass of Launcher e.g GSLauncher or in the base class
        from .utils import find_file
        what_visualize = kwargs.get("what_visualize", "crystal")

        visualizer = abipy_env.get_uservar("visualizer", kwargs)

        # Find the correct output file
        out_files = self.odat_files() 
        gsfname = find_file(out_files, "GSR")
                                                                          
        if gsfname is None:
            raise RuntimeError("Cannot find GSR file among " % out_files)



        if what_visualize == "crystal":

            structure = Structure.from_file(gsfname)
            structure.visualize(visualizer)()

        elif what_visualize == "density":
            raise NotImplementedError("den_fname?")

            density = Density.from_file(den_fname)
            density.visualize(visualizer)()

        elif what_visualize in ["electrons", "fermisurface",]:
            from ..electrons import ElectronBands
            energies = ElectronBands.from_file(gsfname)

            if what_visualize == "electrons": energies.plot()
            if what_visualize == "fermisurface":
                raise RuntimeError("No hanlder found for fermisurface")
                #visu = energies.visualize(self, visualizer, structure)
                #visu()
        else:
            raise RuntimeError("No handler found for %s" % what_visualize)