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 kpt_crop(kpoints: orm.KpointsData, centers: orm.ArrayData, radii: orm.ArrayData, anticrop: orm.Bool) -> orm.KpointsData: kpt_cryst = kpoints.get_kpoints_mesh(print_list=True) cell = kpoints.cell recipr = recipr_base(cell) centers = centers.get_array('centers') centers = centers.dot(recipr) radii = radii.get_array('radii') kpt, wgt = _kpt_crop(kpt_cryst, recipr, centers=centers, radii=radii, anticrop=anticrop.value) res = orm.KpointsData() res.set_cell(cell) res.set_kpoints(kpt, cartesian=True, weights=wgt) return res
def get_force_constants(force_constants: orm.ArrayData) -> str: """Get the force constants in text format :param force_constants: Array with the information needed for the force constants :type force_constants: orm.ArrayData :return: force constants in text :rtype: str """ force_constants = force_constants.get_array('force_constants') fc_shape = force_constants.shape fc_txt = '%4d\n' % (fc_shape[0]) for i in range(fc_shape[0]): for j in range(fc_shape[1]): fc_txt += '%4d%4d\n' % (i + 1, j + 1) for vec in force_constants[i][j]: fc_txt += ('%22.15f' * 3 + '\n') % tuple(vec) return fc_txt