def calculate_invariant_with_parities(dimensionality: orm.Int, scf_out_params: orm.Dict, par_data: orm.ArrayData) -> orm.Dict: """Calculate the z2 invariant from the parities using the output of a BandsxCalculation.""" dim = dimensionality.value parities = par_data.get_array('par') n_el = int(scf_out_params.get_dict()['number_of_electrons']) if dim == 2: x = 1 for p in parities: delta = 1 for i in range(0, n_el, 2): delta *= p[i] x *= delta if x == 1: res = {'nu': 0} elif x == -1: res = {'nu': 1} else: res = {'nu': -1} # raise exceptions.OutputParsingError( # 'Invalid result for z2 using parities') elif dim == 3: raise NotImplemented('dimensionality = 3 not implemented.') else: raise exceptions.InputValidationError( 'dimensionality must be either 2 or 3') return orm.Dict(dict=res)
def extract_z2_from_z2pack(z2pack_output_parameters: orm.Dict) -> orm.Dict: """Extract the Z2 invariant result form a z2pack calculation.""" dct = z2pack_output_parameters.get_dict() res = {} res['nu'] = dct['invariant']['Z2'] return orm.Dict(dict=res)
def _generate_inputdata(self, parameters: orm.Dict, pseudos, structure: orm.StructureData, kpoints: orm.KpointsData) -> ty.Tuple[str, list]: """Generate the input file content and list of pseudopotential files to copy. :param parameters: input parameters Dict :param pseudos: pseudopotential input namespace :param structure: input structure :param kpoints: input kpoints :returns: input file content, pseudopotential copy list """ local_copy_pseudo_list = [] # abipy has its own subclass of Pymatgen's `Structure`, so we use that pmg_structure = structure.get_pymatgen() abi_structure = AbiStructure.as_structure(pmg_structure) abi_structure = abi_structure.abi_sanitize(primitive=True) for kind in structure.get_kind_names(): pseudo = pseudos[kind] local_copy_pseudo_list.append((pseudo.uuid, pseudo.filename, f'{self._PSEUDO_SUBFOLDER}{pseudo.filename}')) # Pseudopotentials _must_ be listed in the same order as 'znucl' in the input file. # So, we need to get 'znucl' as abipy will write it then construct the appropriate 'pseudos' string. znucl = structure_to_abivars(abi_structure)['znucl'] ordered_pseudo_filenames = [pseudos[constants.elements[Z]['symbol']].filename for Z in znucl] pseudo_parameters = { 'pseudos': '"' + ', '.join(ordered_pseudo_filenames) + '"', 'pp_dirpath': f'"{self._PSEUDO_SUBFOLDER}"' } input_parameters = parameters.get_dict() # k-points are provided to abipy separately from the main input parameters, so we pop out # parameters related to the k-points shiftk = input_parameters.pop('shiftk', [0.0, 0.0, 0.0]) # NOTE: currently, only k-point mesh are supported, not k-point paths kpoints_mesh = kpoints.get_kpoints_mesh()[0] # use abipy to write the input file input_parameters = {**input_parameters, **pseudo_parameters} # give abipy the HGH_TABLE only so it won't error, but don't actually print these to file abi_input = AbinitInput( structure=abi_structure, pseudos=HGH_TABLE, abi_kwargs=input_parameters ) abi_input.set_kmesh( ngkpt=kpoints_mesh, shiftk=shiftk ) return abi_input.to_string(with_pseudos=False), local_copy_pseudo_list
def _generate_retrieve_list(self, parameters: orm.Dict, settings: dict, ) -> list: """Generate the list of files to retrieve based on the type of calculation requested in the input parameters. :param parameters: input parameters :returns: list of files to retreive """ parameters = parameters.get_dict() prefix = self.metadata.options.prefix # start with the files that should always be retrieved: stdout, .abo, and manually provided files retrieve_list = [f'{prefix}{postfix}' for postfix in ['.out']] retrieve_list += settings.pop('ADDITIONAL_RETRIEVE_LIST', []) # NOTE: pop here, we don't need this setting anymore if not settings.pop('DRY_RUN', False): # in all cases except for dry runs: o_GSR.nc retrieve_list += [f'{prefix}{postfix}' for postfix in ['o_GSR.nc']] # when moving ions: o_HIST.nc if parameters.get('ionmov', 0) > 0: retrieve_list += [f'{prefix}{postfix}' for postfix in ['o_HIST.nc']] # there may be duplicates from the ADDITIONAL_RETRIEVE_LIST setting, so clean up using set() return list(set(retrieve_list))