def __init__( self, structure, pseudos, pseudo_dir=None, comment=None, abi_args=None, abi_kwargs=None, ): """ Args: structure: Parameters defining the crystalline structure. Accepts |Structure| object file with structure (CIF, netcdf file, ...) or dictionary with ABINIT geo variables. pseudos: Pseudopotentials to be used for the calculation. Accepts: string or list of strings with the name of the pseudopotential files, list of |Pseudo| objects or |PseudoTable| object. pseudo_dir: Name of the directory where the pseudopotential files are located. ndtset: Number of datasets. comment: Optional string with a comment that will be placed at the beginning of the file. abi_args: list of tuples (key, value) with the initial set of variables. Default: Empty abi_kwargs: Dictionary with the initial set of variables. Default: Empty """ # Internal dict with variables. we use an ordered dict so that # variables will be likely grouped by `topics` when we fill the input. abi_args = [] if abi_args is None else abi_args for key, value in abi_args: self._check_varname(key) abi_kwargs = {} if abi_kwargs is None else abi_kwargs for key in abi_kwargs: self._check_varname(key) args = list(abi_args)[:] args.extend(list(abi_kwargs.items())) self._vars = dict(args) self.set_structure(structure) if pseudo_dir is not None: pseudo_dir = os.path.abspath(pseudo_dir) if not os.path.exists(pseudo_dir): raise self.Error(f"Directory {pseudo_dir} does not exist") pseudos = [ os.path.join(pseudo_dir, p) for p in list_strings(pseudos) ] try: self._pseudos = PseudoTable.as_table( pseudos).get_pseudos_for_structure(self.structure) except ValueError as exc: raise self.Error(str(exc)) if comment is not None: self.set_comment(comment)
def num_valence_electrons(structure, pseudos): """ Returns the number of valence electrons. Args: pseudos: List of |Pseudo| objects or list of filenames. """ nval, table = 0, PseudoTable.as_table(pseudos) for site in structure: pseudo = table.pseudo_with_symbol(site.specie.symbol) nval += pseudo.Z_val return int(nval) if int(nval) == nval else nval
def num_valence_electrons(self, pseudos): """ Returns the number of valence electrons. Args: pseudos: List of :class:`Pseudo` objects or list of filenames. """ nval, table = 0, PseudoTable.as_table(pseudos) for site in self: pseudo = table.pseudo_with_symbol(site.species_string) nval += pseudo.Z_val return nval