Exemple #1
0
    def get_hirshfeld(self, structure, all_el_dens_paths=None, fhi_all_el_path=None, workdir=None):
        """
        Runs cut3d to get the Hirshfeld charges. Requires all-electron density files, so at least one source
        should be specified (all_el_dens_paths or fhi_all_el_path)

        Args:
            structure: a Structure object representing the structure used to generate the density
            all_el_dens_paths: a list of paths to the all-electron density files correspinding to the elements defined
                in the abinit input.
            fhi_all_el_path: path to the folder containing the fhi all-electron density files that will be used
                to automatically determine the path of the required densities.
            workdir: directory where cut3d is executed.

        Returns:
            (HirshfeldCharges) the calculated Hirshfeld charges.
        """
        if all_el_dens_paths is None and fhi_all_el_path is None:
            raise ValueError("At least one source of all electron densities should be provided.")
        if all_el_dens_paths is not None and fhi_all_el_path is not None:
            raise ValueError("all_el_dens_paths and fhi_all_el_path are mutually exclusive.")

        if all_el_dens_paths is not None:
            cut3d_input = Cut3DInput.hirshfeld(self.filepath, all_el_dens_paths)
        else:
            cut3d_input = Cut3DInput.hirshfeld_from_fhi_path(self.filepath, structure, fhi_all_el_path)

        workdir = os.path.abspath(tempfile.mkdtemp() if workdir is None else workdir)

        cut3d = Cut3D()
        outfile, converted_file = cut3d.cut3d(cut3d_input, workdir)

        from abipy.electrons.charges import HirshfeldCharges
        return HirshfeldCharges.from_cut3d_outfile(structure=structure, filepath=cut3d.stdout_fname)
Exemple #2
0
    def get_cube(self, out_filepath, workdir=None):
        """
        Runs cut3d to convert the density to the cube format

        Args:
            out_filepath: path to the file that should be produced by cut3D, if required. At this stage it would be
                safer to use just the file name, as using an absolute or relative path may fail depending on the compiler.
            workdir: directory where cut3d is executed.

        Returns:
            (CubeFile) the converted file as a CubeFile object.
        """
        return CubeFile(self._convert(cut3d_input=Cut3DInput.den_to_cube(self.filepath, out_filepath),
                                      workdir=workdir))
Exemple #3
0
    def get_xsf(self, out_filepath, shift=None, workdir=None):
        """
        Runs cut3d to convert the density to the xsf format

        Args:
            out_filepath: path to the file that should be produced by cut3D, if required. At this stage it would be
                safer to use just the file name, as using an absolute or relative path may fail depending on
                the compiler.
            shift: a list of three integers defining the shift along the x, y, z axis. None if no shift is required.
            workdir: directory where cut3d is executed.

        Returns:
            (string) path to the converted file.
        """
        return self._convert(cut3d_input=Cut3DInput.den_to_xsf(self.filepath,
                             output_filepath=out_filepath, shift=shift), workdir=workdir)
Exemple #4
0
    def get_density(self, workdir=None):
        """
        Invoke cut3d to produce a netcdf file with the density, read the file and return Density object.

        Args:
            workdir: directory in which cut3d is executed.
        """
        workdir = os.path.abspath(tempfile.mkdtemp() if workdir is None else workdir)
        output_filepath = os.path.join(workdir, "field_CUT3DDENPOT.nc")
        # FIXME Converters with nspden > 1 won't work since cut3d asks for the ispden index.
        cut3d_input = Cut3DInput(infile_path=self.filepath, output_filepath=output_filepath,
                                 options=[15, output_filepath, 0, 0])

        outfile, _ = Cut3D().cut3d(cut3d_input, workdir)
        with Cut3dDenPotNcFile(output_filepath) as nc:
            assert nc.field.is_density_like and nc.field.netcdf_name == "density"
            return nc.field
Exemple #5
0
    def get_3d_formatted(self, out_filepath, workdir=None):
        """
        Runs cut3d to convert the density to the 3D formatted format

        Args:
            out_filepath: path to the file that should be produced by cut3D, if required. At this stage it would be
                safer to use just the file name, as using an absolute or relative path may fail depending on
                the compiler.
            workdir: directory where cut3d is executed.

        Returns:
            (string) path to the converted file.
        """
        from abipy.abio.inputs import Cut3DInput
        return self._convert(cut3d_input=Cut3DInput.den_to_3d_indexed(
            self.filepath, out_filepath),
                             workdir=workdir)