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)
def _convert(self, cut3d_input, workdir=None): """ Internal function to run a conversion using cut3d. """ workdir = os.path.abspath(tempfile.mkdtemp() if workdir is None else workdir) outfile, converted_file = Cut3D().cut3d(cut3d_input, workdir) return converted_file
def _convert(self, cut3d_input, workdir=None): """ Internal function to run a conversion using cut3d. """ workdir = tempfile.mkdtemp() if workdir is None else workdir # local import to avoid circular references from abipy.flowtk import Cut3D outfile, converted_file = Cut3D().cut3d(cut3d_input, workdir) return converted_file
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