Fleur tools/utility
Structure Data util
Collection of utility routines dealing with StructureData objects
- aiida_fleur.tools.StructureData_util.adjust_calc_para_to_structure(parameter, structure, add_atom_base_lists=True, write_new_kind_names=False)[source]
Adjust calculation parameters for inpgen to a given structure with several kinds
Rules: 1. Only atom lists are changed in the parameter node 2. If at least one atomlist of a certain element is in parameter all kinds with this elements will have atomlists in the end 3. For a certain kind which has no atom list yet and at least one list with such an element exists it gets the parameters from the atom list with the lowest number (while atom<atom0<atom1) 4. Atom lists with ids are preserved
- Parameters
parameter – aiida.orm.Dict node containing calc parameters
structure – aiida.orm.StructureData node containing a crystal structure
add_atom_base_lists – Bool (default True), if the atom base lists should be added or not
- Returns
new aiida.orm.Dict with new calc_parameters
- aiida_fleur.tools.StructureData_util.adjust_film_relaxation(structure, suggestion, scale_as=None, bond_length=None, last_layer_factor=0.85, first_layer_factor=0.85)[source]
Tries to optimize interlayer distances. Can be used before RelaxWC to improve its behaviour. Works only for films having no z-reflection symmetry, for other films check out the adjust_sym_film_relaxation
- Parameters
structure – ase film structure which will be adjusted
suggestion – dictionary containing average bond length between different elements, is is basically the result of
request_average_bond_length()
scale_as – an element name, for which the El-El bond length will be enforced. It is can be helpful to enforce the same interlayer distance in the substrate, i.e. adjust deposited film interlayer distances only.
bond_length – a float that sets the bond length for scale_as element
hold_layers – this parameters sets the number of layers that will be marked via the certain label. The label is reserved for future use in the relaxation WC: all the atoms marked with the label will not be relaxed.
last_layer_factor – a float factor to which interlayer distance between last and second last layers is multiplied
first_layer_factor – a float factor to which interlayer distance between first and second layers is multiplied
- aiida_fleur.tools.StructureData_util.adjust_sym_film_relaxation(structure, suggestion, scale_as=None, bond_length=None, last_layer_factor=0.85, ILD=None)[source]
Tries to optimize interlayer distances. Can be used before RelaxWC to improve its behaviour. Works only for films having z-reflection symmetry, for other films check out the adjust_film_relaxation
- Parameters
structure – ase film structure which will be adjusted
suggestion – dictionary containing average bond length between different elements, is is basically the result of
request_average_bond_length()
scale_as – an element name, for which the El-El bond length will be enforced. It is can be helpful to enforce the same interlayer distance in the substrate, i.e. adjust deposited film interlayer distances only.
bond_length – a float that sets the bond length for scale_as element
hold_layers – this parameters sets the number of layers that will be marked via the certain label. The label is reserved for future use in the relaxation WC: all the atoms marked with the label will not be relaxed.
last_layer_factor – a float factor to which interlayer distance between last and second last layers is multiplied
- aiida_fleur.tools.StructureData_util.break_symmetry(structure, atoms=None, site=None, pos=None, new_kinds_names=None, add_atom_base_lists=True, parameterdata=None)[source]
This routine introduces different ‘kind objects’ in a structure and names them that inpgen will make different species/atomgroups out of them. If nothing specified breaks ALL symmetry (i.e. every atom gets their own kind)
- Parameters
structure – StructureData
atoms – python list of symbols, exp: [‘W’, ‘Be’]. This would make for all Be and W atoms their own kinds.
site – python list of integers, exp: [1, 4, 8]. This would create for atom 1, 4 and 8 their own kinds.
pos – python list of tuples of 3, exp [(0.0, 0.0, -1.837927), …]. This will create a new kind for the atom at that position. Be carefull the number given has to match EXACTLY the position in the structure.
parameterdata – Dict node, containing calculation_parameters, however, this only works well if you prepare already a node for containing the atom lists from the symmetry breaking, or lists without ids.
add_atom_base_lists – Bool (default True), if the atom base lists should be added or not
- Returns
StructureData, a AiiDA crystal structure with new kind specification.
- Returns
DictData, a AiiDA dict with new parameters for inpgen.
- aiida_fleur.tools.StructureData_util.break_symmetry_wf(structure, wf_para, parameterdata=None)[source]
This is the calcfunction of the routine break_symmetry, which introduces different ‘kind objects’ in a structure and names them that inpgen will make different species/atomgroups out of them. If nothing specified breaks ALL symmetry (i.e. every atom gets their own kind)
- Parameters
structure – StructureData
wf_para –
ParameterData which contains the keys atoms, sites, pos (see below)
- ’atoms’:
python list of symbols, exp: [‘W’, ‘Be’]. This would make for all Be and W atoms their own kinds.
- ’site’:
python list of integers, exp: [1, 4, 8]. This would create for atom 1, 4 and 8 their own kinds.
- ’pos’:
python list of tuples of 3, exp [(0.0, 0.0, -1.837927), …]. This will create a new kind for the atom at that position. Be carefull the number given has to match EXACTLY the position in the structure.
parameterdata – AiiDa ParameterData
- Returns
StructureData, a AiiDA crystal structure with new kind specification.
- aiida_fleur.tools.StructureData_util.center_film(structure)[source]
Centers a film at z=0
- Parameters
structure – AiiDA structure
- Returns
AiiDA structure
- aiida_fleur.tools.StructureData_util.center_film_wf(structure)[source]
Centers a film at z=0, keeps the provenance in the database
- Parameters
structure – AiiDA structure
- Returns
AiiDA structure
- aiida_fleur.tools.StructureData_util.check_structure_para_consistent(parameter, structure, verbose=True)[source]
Check if the given calculation parameters for inpgen match to a given structure
If parameter contains atom lists which do not fit to any kind in the structure, false is returned This knows how the FleurinputgenCalculation prepares structures.
- Parameters
parameter – aiida.orm.Dict node containing calc parameters
structure – aiida.orm.StructureData node containing a crystal structure
- Returns
Boolean, True if parameter is consistent to structure
- aiida_fleur.tools.StructureData_util.create_all_slabs(initial_structure, miller_index, min_slab_size_ang, min_vacuum_size=0, bonds=None, tol=0.001, max_broken_bonds=0, lll_reduce=False, center_slab=False, primitive=False, max_normal_search=1, symmetrize=False)[source]
- Returns
a dictionary of structures
- aiida_fleur.tools.StructureData_util.create_manual_slab_ase(lattice='fcc', miller=None, directions=None, host_symbol='Fe', latticeconstant=4.0, size=(1, 1, 5), replacements=None, decimals=8, pop_last_layers=0)[source]
Wraps ase.lattice lattices generators to create a slab having given lattice vectors directions.
- Parameters
lattice – ‘fcc’ and ‘bcc’ are supported. Set the host lattice of a slab.
miller – a list of directions of planes forming the primitive unit cell
directions – a list of directions of lattice vectors
symbol – a string specifying the atom type
latticeconstant – the lattice constant of a structure
size – a 3-element tuple that sets supercell size. For instance, use (1,1,5) to set 5 layers of a slab.
replacements – a dict of type {INT: STRING}, where INT is the layer number to be replaced (counting from lowest z-coordinate layers, INT=1 for the first layer INT=-1 for the last one) and STRING is the element name.
decimals – sets the rounding of atom positions. See numpy.around.
pop_last_layers – specifies how many layers to remove. Sometimes one does not want to use the integer number of unit cells along z, extra layers can be removed. Layers are removed in order from highest to lowest z-coordinate.
- Return structure
an ase-lattice representing a slab with replaced atoms
- aiida_fleur.tools.StructureData_util.create_slap(initial_structure, miller_index, min_slab_size, min_vacuum_size=0, lll_reduce=False, center_slab=False, primitive=False, max_normal_search=1, reorient_lattice=True)[source]
wraps the pymatgen slab generator
- aiida_fleur.tools.StructureData_util.define_AFM_structures(structure, lattice, directions, host_symbol, replacements, latticeconstant, size, decimals=8, pop_last_layers=0, AFM_name='FM', magnetic_layers=1, sym_film=False)[source]
Create
- aiida_fleur.tools.StructureData_util.find_equi_atoms(structure)[source]
This routine uses spglib and ASE to provide informations of all equivivalent atoms in the cell.
- Parameters
structure – AiiDA StructureData
- Returns
equi_info_symbol, list of lists [‘element’: site_indexlist, …] len(equi_info_symbol) = number of symmetryatomtypes and n_equi_info_symbol, dict {‘element’: numberequiatomstypes}
- aiida_fleur.tools.StructureData_util.find_primitive_cell(structure)[source]
uses spglib find_primitive to find the primitive cell
- Parameters
sructure – AiiDA structure data
- Returns
list of new AiiDA structure data
- aiida_fleur.tools.StructureData_util.find_primitive_cell_wf(structure)[source]
uses spglib find_primitive to find the primitive cell :param structure: AiiDa structure data
- Returns
list of new AiiDa structure data
- aiida_fleur.tools.StructureData_util.find_primitive_cells(uuid_list)[source]
uses spglib find_primitive to find the primitive cell :param uuid_list: list of structureData uuids, or pks
- Returns
list of new AiiDa structure datas
- aiida_fleur.tools.StructureData_util.get_all_miller_indices(structure, highestindex)[source]
wraps the pymatgen function get_symmetrically_distinct_miller_indices for an AiiDa structure
- aiida_fleur.tools.StructureData_util.get_atomtype_site_symmetry(struc)[source]
Get the local site symmetry symbols for each atomtype
Uses pymatgen SpaceGroupAnalyzer
- Parameters
struc – StructureData to analyse
- Returns
list of the site symmetry symbols for each atomtype (In the order they appear in the StructureData)
- aiida_fleur.tools.StructureData_util.get_layers(structure, z_coordinate_window=8)[source]
Extracts atom positions and their types belonging to the same layer Removes any information related to kind specie.
- Parameters
structure – ase lattice or StructureData which represents a slab
number – the layer number. Note, that layers will be sorted according to z-position
z_coordinate_window – sets the maximal difference between 2 atoms that will be considered in the same layer. it is an interger, which sets how z-coordinates will be rounded. For instance, z_coordinate_window = 2 means that first z-coordinates will be rounded up to 2 digits after the dot and than grouped.
- Return layer, layer_z_positions
layer is a list of tuples, the first element of which is atom positions and the second one is atom type. layer_z_position is a sorted list of all layer positions
- aiida_fleur.tools.StructureData_util.get_spacegroup(structure)[source]
- Parameters
structure – AiiDA StructureData
- Returns
the spacegroup (spglib class) of a given AiiDA structure
- aiida_fleur.tools.StructureData_util.has_z_reflection(structure)[source]
Checks if a structure has z-reflection symmetry
- aiida_fleur.tools.StructureData_util.is_primitive(structure)[source]
Checks if a structure is primitive or not, :param structure: AiiDA StructureData :return: True if the structure can not be anymore refined. prints False if the structure can be futher refined.
- aiida_fleur.tools.StructureData_util.is_structure(structure)[source]
Test if the given input is a StructureData node, by object, id, or pk :param structure: AiiDA StructureData :return: if yes returns a StructureData node in all cases, if no returns None
- aiida_fleur.tools.StructureData_util.magnetic_slab_from_relaxed(relaxed_structure, orig_structure, total_number_layers, num_relaxed_layers, z_coordinate_window=3, shift=(0, 0))[source]
Transforms a structure that was used for interlayer distance relaxation to a structure that can be further used for magnetic calculations.
Usually one uses a slab having z-reflection symmetry e.g. A-B1-B2-B3-B2-B1-A where A is a magnetic element (Fe, Ni, Co, Cr) and B is a substrate. However, further magnetic calculations are done using assymetric slab A-B1-B2-B3-B4-B5-B6-B7-B8. The function uses A-B1, B1-B2 etc. iterlayer distances for constraction of assymetric relaxed film.
The function works as follows: it constructs a new StructureData object taking x and y positions from the orig_structure and z positions from relax_structure for first num_relaxed_interlayers. Then it appends orig_structure slab to the bottom it a way the total number of layers is total_number_layers.
- Parameters
relaxed_structure – Structure which is the output of Relax WorkChain. In thin function it is assumed to have inversion or at least z-reflection symmetry.
orig_structure – The host structure slab having the lattice perioud corresponding to the bulk structure of the substrate.
total_number_layers – the total number of layers to produce
num_relaxed_layers – the number of top layers to adjust according to relaxed_struct
tolerance_decimals – sets the rounding of atom positions. See numpy.around.
- Return magn_structure
Resulting assymetric structure with adjusted interlayer distances for several top layers.
- aiida_fleur.tools.StructureData_util.mark_atoms(structure, condition, kind_id='99999')[source]
Marks atom where sites fullfill the given condition with a given id The resulting kind name for these atoms is element-kind_id
condition is a callable taking the site and kind as arguments
- aiida_fleur.tools.StructureData_util.mark_fixed_atoms(structure, hold_layers=None)[source]
Marks atom in layers, that should be fixed in the relaxation. Uses reserved 49999 label
- aiida_fleur.tools.StructureData_util.move_atoms_incell(structure, vector)[source]
moves all atoms in a unit cell by a given vector
- Parameters
structure – AiiDA structure
vector – tuple of 3, or array
- Returns
AiiDA structure
- aiida_fleur.tools.StructureData_util.move_atoms_incell_wf(structure, wf_para)[source]
moves all atoms in a unit cell by a given vector
- Parameters
structure – AiiDA structure
wf_para – AiiDA Dict node with vector: tuple of 3, or array (currently 3 AiiDA Floats to make it a wf, In the future maybe a list or vector if AiiDa basetype exists)
- Returns
AiiDA stucture
- aiida_fleur.tools.StructureData_util.replace_element(inp_structure, replace_dict, replace_all=None)[source]
Replaces the given element with the element_replacement, but keeps the structure the same. If there are more than one site they are either all replaced or a list with one replacement at a time is returned. Keeps the provenance in the database.
- Parameters
inp_structure – a StructureData node (pk, or uuid)
replace_dict – Dict of elements to replace. Replacement is done according to the symbols
replace_all – bool determines wether to replace all occurrences of the element at once Otherwise a list, with one occurence replaced at a time
- Returns
Dict with new StructureData nodes with replaced elements, which is/are linked to input Structure and None if inp_structure was not a StructureData
- Example usage:
This example replaces all Neodymium atoms with Yttrium replace_element(structure,Dict(dict={‘Nd’:’Y’}),replace_all=Bool(True))
- aiida_fleur.tools.StructureData_util.replace_elementf(inp_structure, replace_dict, replace_all)[source]
Replaces the site according to replace_dict (symbols), but keeps the structure the same. If there are more than one site they are either all replaced or a list with one replacement at a time is returned. DOES NOT keep the provenance in the database.
- Parameters
inp_structure – a StructureData node (pk, or uuid)
replace_dict – Dict of elements to replace. Replacement is done according to the symbols
replace_all – bool determines wether to replace all occurrences of the element at once Otherwise a list, with one occurence replaced at a time
- Returns
New StructureData node or list of new StructureData nodes with replaced elements, which is/are linked to input Structure and None if inp_structure was not a StructureData
- aiida_fleur.tools.StructureData_util.request_average_bond_length(first_bin, second_bin, user_api_key, ignore_second_bin=False)[source]
Requests MaterialsProject to estimate thermal average bond length between given elements. Also requests information about lattice constants of fcc and bcc structures.
- Parameters
first_bin – element list to calculate the average bond length only combinations of AB are calculated, where A belongs to first_bin, B belongs to second_bin.
second_bin – element list, see main_elements
user_api_key – user API key from materialsproject
ignore_second_bin – if True, the second bin is ignored and all possible combinations from the first one are constructed.
- Returns
bond_data, a dict containing obtained lattice constants.
- aiida_fleur.tools.StructureData_util.request_average_bond_length_store(first_bin, second_bin, user_api_key, ignore_second_bin=False)[source]
Requests MaterialsProject to estimate thermal average bond length between given elements. Also requests information about lattice constants of fcc and bcc structures. Stores the result in the Database. Notice that this is not a calcfunction! Therefore, the inputs are not stored and the result node is unconnected.
- Parameters
first_bin – element list to calculate the average bond length only combinations of AB, AA and BB are calculated, where A belongs to first_bin, B belongs to second_bin.
second_bin – element list, see main_elements
user_api_key – user API key from materialsproject
ignore_second_bin – if True, the second bin is ignored and all possible combinations from the first one are constructed.
- Returns
bond_data, a dict containing obtained lattice constants.
- aiida_fleur.tools.StructureData_util.rescale(inp_structure, scale)[source]
Rescales a crystal structures Volume, atoms stay at their same relative postions, therefore the absolute postions change. Keeps the provenance in the database.
- Parameters
inp_structure – a StructureData node (pk, or uuid)
scale – float scaling factor for the cell
- Returns
New StructureData node with rescalled structure, which is linked to input Structure and None if inp_structure was not a StructureData
- aiida_fleur.tools.StructureData_util.rescale_nowf(inp_structure, scale)[source]
Rescales a crystal structures Volume, atoms stay at their same relative postions, therefore the absolute postions change. DOES NOT keep the provenance in the database.
- Parameters
inp_structure – a StructureData node (pk, or uuid)
scale – float scaling factor for the cell
- Returns
New StructureData node with rescalled structure, which is linked to input Structure and None if inp_structure was not a StructureData
- aiida_fleur.tools.StructureData_util.simplify_kind_name(kind_name)[source]
Simplifies the kind name string. Example: “W-1” -> “W”, “Iron (Fe)” -> “Fe”
- aiida_fleur.tools.StructureData_util.sort_atoms_z_value(structure)[source]
Resorts the atoms in a structure by there Z-value
- Parameters
structure – AiiDA structure
- Returns
AiiDA structure
- aiida_fleur.tools.StructureData_util.supercell(inp_structure, n_a1, n_a2, n_a3)[source]
Creates a super cell from a StructureData node. Keeps the provenance in the database.
- Parameters
StructureData – a StructureData node (pk, or uuid)
scale – tuple of 3 AiiDA integers, number of cells in a1, a2, a3, or if cart =True in x,y,z
- Returns
StructureData Node with supercell
- aiida_fleur.tools.StructureData_util.supercell_ncf(inp_structure, n_a1, n_a2, n_a3)[source]
Creates a super cell from a StructureData node. Does NOT keeps the provenance in the database.
- Parameters
StructureData – a StructureData node (pk, or uuid)
scale – tuple of 3 AiiDA integers, number of cells in a1, a2, a3, or if cart=True in x,y,z
- Returns
StructureData Node with supercell
XML utility
This module defines XML modifying functions, that require an aiida node as input
- aiida_fleur.tools.xml_aiida_modifiers.set_kpointsdata_f(xmltree: Union[lxml.etree._Element, lxml.etree._ElementTree], schema_dict: masci_tools.io.parsers.fleur_schema.schema_dict.InputSchemaDict, kpointsdata_uuid: aiida.orm.nodes.data.array.kpoints.KpointsData | int | str, name: Optional[str] = None, switch: bool = False, kpoint_type: Literal['path', 'mesh', 'tria', 'tria-bulk', 'spex-mesh'] = 'path') Union[lxml.etree._Element, lxml.etree._ElementTree] [source]
This function creates a kpoint list in the inp.xml from a
KpointsData
Node If no weights are given the weight is distibuted equally along the kpoints- Parameters
xmltree – an xmltree that represents inp.xml
schema_dict – InputSchemaDict containing all information about the structure of the input
kpointsdata_uuid – node identifier or
KpointsData
node to be written intoinp.xml
name – str name to give the newly entered kpoint list (only MaX5 or later)
switch – bool if True the entered kpoint list will be used directly (only Max5 or later)
kpoint_type – str of the type of kpoint list given (mesh, path, etc.) only Max5 or later
- Returns
xmltree with entered kpoint list
Parameter utility
General Parameter
This contains code snippets and utility useful for dealing with parameter data nodes commonly used by the fleur plugin and workflows
- aiida_fleur.tools.dict_util.clean_nones(dict_to_clean)[source]
Recursively remove all keys which values are None from a nested dictionary return the cleaned dictionary
- Parameters
dict_to_clean – (dict): python dictionary to remove keys with None as value
- Returns
dict, cleaned dictionary
- aiida_fleur.tools.dict_util.clear_dict_empty_lists(to_clear_dict)[source]
Removes entries from a nested dictionary which are empty lists.
param to_clear_dict dict: python dictionary which should be ‘compressed’ return new_dict dict: compressed python dict version of to_clear_dict
Hints: recursive
- aiida_fleur.tools.dict_util.dict_merger(dict1, dict2)[source]
Merge recursively two nested python dictionaries and if key is in both digionaries tries to add the entries in both dicts. (merges two subdicts, adds lists, strings, floats and numbers together!)
- Parameters
dict1 – dict
dict2 – dict
- Return dict
Merged dict
- aiida_fleur.tools.dict_util.extract_elementpara(parameter_dict, element)[source]
- Parameters
parameter_dict – python dict, parameter node for inpgen
element – string, i.e ‘W’
- Returns
python dictionary, parameter node which contains only the atom parameters for the given element
- aiida_fleur.tools.dict_util.recursive_merge(left: Dict[str, Any], right: Dict[str, Any]) Dict[str, Any] [source]
Recursively merge two dictionaries into a single dictionary.
keys in right override keys in left!
- Parameters
left – first dictionary.
right – second dictionary.
- Returns
the recursively merged dictionary.
Merge Parameter
This module, contains a method to merge Dict nodes used by the FLEUR inpgen. This might also be of interest for other all-electron codes
- aiida_fleur.tools.merge_parameter.merge_parameter(Dict1, Dict2, overwrite=True, merge=True)[source]
Merges two Dict nodes. Additive: uses all namelists of both. If they have a namelist in common. Dict2 will overwrite the namelist of Dict. If this is not wanted. set overwrite = False. Then attributes of both will be added, but attributes from Dict1 won’t be overwritten.
- Parameters
Dict1 – AiiDA Dict Node
Dict2 – AiiDA Dict Node
overwrite – bool, default True
merge – bool, default True
returns: AiiDA Dict Node
#TODO be more carefull how to merge ids in atom namelists, i.e species labels
Corehole/level utility
Contains helper functions to create core-holes in Fleur input files from AiiDA data nodes.
- aiida_fleur.tools.create_corehole.create_corehole_para(structure, kind, econfig, species_name='corehole', parameterdata=None)[source]
This methods sets of electron configurations for a kind or position given, make sure to break the symmetry for this position/kind beforehand, otherwise you will create several coreholes.
- Parameters
structure – StructureData
kind – a string with the kind_name (TODO: alternative the kind object)
econfig – string, e.g. econfig = “[Kr] 5s2 4d10 4f13 | 5p6 5d5 6s2” to set, i.e. the corehole
- Returns
a Dict node
In this module you find methods to parse/extract corelevel shifts from an out.xml file of FLEUR.
- aiida_fleur.tools.extract_corelevels.clshifts_to_be(coreleveldict, reference_dict, warn=False)[source]
This methods converts corelevel shifts to binding energies, if a reference is given. These can than be used for plotting.
- Params reference_dict
An example:
reference_dict = {'W' : {'4f7/2' : [124], '4f5/2' : [102]}, 'Be' : {'1s': [117]}}
- Params coreleveldict
An example:
coreleveldict = {'W' : {'4f7/2' : [0.4, 0.3, 0.4 ,0.1], '4f5/2' : [0, 0.3, 0.4, 0.1]}, 'Be' : {'1s': [0, 0.2, 0.4, 0.1, 0.3]}
- aiida_fleur.tools.extract_corelevels.convert_to_float(value_string, parser_info=None)[source]
Tries to make a float out of a string. If it can’t it logs a warning and returns True or False if convertion worked or not.
- Parameters
value_string – a string
- Returns value
the new float or value_string: the string given
- Retruns
True or False
- aiida_fleur.tools.extract_corelevels.extract_corelevels(outxmlfile, options=None)[source]
Extracts corelevels out of out.xml files
- Params outxmlfile
path to out.xml file
- Parameters
options – A dict: ‘iteration’ : X/’all’
- Returns corelevels
A list of the form:
[atomtypes][spin][dict={atomtype : '', corestates : list_of_corestates}] [atomtypeNumber][spin]['corestates'][corestate number][attribute] get corelevel energy of first atomtype, spin1, corelevels[0][0]['corestates'][i]['energy']
- Example of output
[[{'atomtype': ' 1', 'corestates': [{'energy': -3.6489930627, 'j': ' 0.5', 'l': ' 0', 'n': ' 1', 'weight': 2.0}], 'eigenvalue_sum': ' -7.2979861254', 'kin_energy': ' 13.4757066163', 'spin': '1'}], [{'atomtype': ' 2', 'corestates': [{'energy': -3.6489930627, 'j': ' 0.5', 'l': ' 0', 'n': ' 1', 'weight': 2.0}], 'eigenvalue_sum': ' -7.2979861254', 'kin_energy': ' 13.4757066163', 'spin': '1'}]]
- aiida_fleur.tools.extract_corelevels.parse_state_card(corestateNode, iteration_node, parser_info=None)[source]
Parses the ONE core state card
- Params corestateNode
an etree element (node), of a fleur output corestate card
- Params iteration_node
an etree element, iteration node
- Params jspin
integer 1 or 2
- Returns
a pythondict of type:
{'eigenvalue_sum' : eigenvalueSum, 'corestates': states, 'spin' : spin, 'kin_energy' : kinEnergy, 'atomtype' : atomtype}
You find the usual binding_energy for all elements in the periodic table.
- aiida_fleur.tools.element_econfig_list.convert_fleur_config_to_econfig(fleurconf_str, keep_spin=False)[source]
‘[Kr] (4d3/2) (4d5/2) (4f5/2) (4f7/2)’ -> ‘[Kr] 4d10 4f14’, or ‘[Kr] 4d3/2 4d5/2 4f5/2 4f7/2’
# for now only use for coreconfig, it will fill all orbitals, since it has no information on the filling.
- aiida_fleur.tools.element_econfig_list.econfigstr_hole(econfigstr, corelevel, highesunoccp, htype='valence')[source]
# ‘1s2 | 2s2’ , ‘1s2’ , ‘2p0’ -> ‘1s1 | 2s2 2p1’
- Param
string
- Param
string
- Param
string
- Returns
string
- aiida_fleur.tools.element_econfig_list.get_coreconfig(element, full=False)[source]
returns the econfiguration as a string of an element.
- Param
element string
- Param
full, bool (econfig without [He]…)
- Returns
string
- Note
Be careful with base strings…
- aiida_fleur.tools.element_econfig_list.get_econfig(element, full=False)[source]
returns the econfiguration as a string of an element.
- Params element
element string
- Params full
a bool (econfig without [He]…)
- Returns
a econfig string
- aiida_fleur.tools.element_econfig_list.get_spin_econfig(fulleconfigstr)[source]
converts and econfig string to a full spin econfig 1s2 2s2 2p6’ - > ‘1s1/2 2s1/2 2p1/2 2p3/2’
- aiida_fleur.tools.element_econfig_list.get_state_occ(econfigstr, corehole='', valence='', ch_occ=1.0)[source]
finds out all not full occupied states and returns a dictionary of them return a dict i.e corehole ‘4f 5/2’ ch_occ full or fractional corehole occupation? valence: orbital sting ‘5d’, is to adjust the charges for fractional coreholes To that orbital occupation ch_occ - 1 will be added.
Common aiida utility
In here we put all things util (methods, code snipets) that are often useful, but not yet in AiiDA itself. So far it contains:
export_extras import_extras delete_nodes (FIXME) delete_trash (FIXME) create_group
- aiida_fleur.tools.common_aiida.create_group(name, nodes, description=None, add_if_exist=False)[source]
Creates a group for a given node list.
!!! Now aiida-core has these functionality, use it from there instead!!! So far this is only an AiiDA verdi command.
- Params name
string name for the group
- Params nodes
list of AiiDA nodes, pks, or uuids
- Params description
optional string that will be stored as description for the group
- Returns
the group, AiiDa group
Usage example:
group_name = 'delta_structures_gustav' nodes_to_group_pks =[2142, 2084] create_group(group_name, nodes_to_group_pks, description='delta structures added by hand. from Gustavs inpgen files')
- aiida_fleur.tools.common_aiida.export_extras(nodes, filename='node_extras.txt')[source]
Writes uuids and extras of given nodes to a json-file. This is useful for import/export because currently extras are lost. Therefore this can be used to save and restore the extras via
import_extras()
.- Param
nodes: list of AiiDA nodes, pks, or uuids
- Param
filename, string where to store the file and its name
example use: .. code-block:: python
node_list = [120,121,123,46] export_extras(node_list)
- aiida_fleur.tools.common_aiida.get_nodes_from_group(group, return_format='uuid')[source]
Returns a list of pk or uuid of a nodes in a given group. Since 1.1.0, this function does !!! Now aiida-core has these functionality, use it from there instead!!!
not load a group using the label or any other identification. Use Group.objects.get(filter=ID) to pre-load this, available filters are: id, uuid, label, type_string, time, description, user_id.
- aiida_fleur.tools.common_aiida.import_extras(filename)[source]
Reads in node uuids and extras from a file (most probably generated by
export_extras()
) and applies them to nodes in the DB.This is useful for import/export because currently extras are lost. Therefore this can be used to save and restore the extras on the nodes.
- Param
filename, string what file to read from (has to be json format)
example use: import_extras(‘node_extras.txt’)
Reading in Cif files
In this module you find a method (read_cif_folder) to read in all .cif files from a folder and store the structures in the database.
- aiida_fleur.tools.read_cif_folder.read_cif_folder(path='/home/docs/checkouts/readthedocs.org/user_builds/aiida-fleur/checkouts/latest/docs/source', recursive=True, store=False, log=False, comments='', extras='', logfile_name='read_cif_folder_logfile')[source]
Method to read in cif files from a folder and its subfolders. It can convert them into AiiDA structures and store them.
defaults input parameter values are: path=”.”, recursive=True, store=False, log=False, comments=’’, extras=’’
- Params
path: Path to the dictionary with the files (default, where this method is called)
- Params
recursive: bool, If True: looks aso in subfolders, if False: just given dir
- Params
store: bool, if True: stores structures in database
- Params
log: bool, if True, writes a logfile with information (pks, and co)
- Params
comments: string: comment to add to the structures
- Params
extras: dir/string/arb: extras added to the structures stored in the db
IO routines
Here we collect IO routines and their utility, for writting certain things to files, or post process files. For example collection of data or database evaluations, for other people.
Common utitlity for fleur workchains
In here we put all things (methods) that are common to workflows AND depend on AiiDA classes, therefore can only be used if the dbenv is loaded. Util that does not depend on AiiDA classes should go somewhere else.
- aiida_fleur.tools.common_fleur_wf.calc_time_cost_function(natom, nkpt, kmax, nspins=1)[source]
Estimates the cost of simulating a single iteration of a system
- aiida_fleur.tools.common_fleur_wf.calc_time_cost_function_total(natom, nkpt, kmax, niter, nspins=1)[source]
Estimates the cost of simulating a all iteration of a system
- aiida_fleur.tools.common_fleur_wf.cost_ratio(total_costs, walltime_sec, ncores)[source]
Estimates if simulation cost matches resources
- aiida_fleur.tools.common_fleur_wf.determine_favorable_reaction(reaction_list, workchain_dict)[source]
Finds out with reaction is more favorable by simple energy standpoints
# TODO check physics reaction list: list of reaction strings workchain_dict = {‘Be12W’ : uuid_wc or output, ‘Be2W’ : uuid, …}
return dictionary that ranks the reactions after their enthalpy
TODO: refactor aiida part out of this, leaving an aiida independent part and one more universal
- aiida_fleur.tools.common_fleur_wf.find_last_submitted_calcjob(restart_wc)[source]
Finds the last CalcJob submitted in a higher-level workchain and returns it’s uuid
- aiida_fleur.tools.common_fleur_wf.find_last_submitted_workchain(restart_wc)[source]
Finds the last WorkChain submitted in a higher-level workchain and returns it’s uuid
- aiida_fleur.tools.common_fleur_wf.find_nested_process(wc_node, p_class)[source]
This function finds all nested child processes of p_class
- aiida_fleur.tools.common_fleur_wf.get_inputs_fleur(code, remote, fleurinp, options, label='', description='', settings=None, add_comp_para=None)[source]
Assembles the input dictionary for Fleur Calculation. Does not check if a user gave correct input types, it is the work of FleurCalculation to check it.
- Parameters
code – FLEUR code of Code type
remote – remote_folder from the previous calculation of RemoteData type
fleurinp – FleurinpData object representing input files
options – calculation options that will be stored in metadata
label – a string setting a label of the CalcJob in the DB
description – a string setting a description of the CalcJob in the DB
settings – additional settings of Dict type
add_comp_para – dict with extra keys controlling the behaviour of the parallelization of the FleurBaseWorkChain
Example of use:
inputs_build = get_inputs_inpgen(structure, inpgencode, options, label, description, params=params) future = self.submit(inputs_build)
- aiida_fleur.tools.common_fleur_wf.get_inputs_inpgen(structure, inpgencode, options, label='', description='', settings=None, params=None, **kwargs)[source]
Assembles the input dictionary for Fleur Calculation.
- Parameters
structure – input structure of StructureData type
inpgencode – inpgen code of Code type
options – calculation options that will be stored in metadata
label – a string setting a label of the CalcJob in the DB
description – a string setting a description of the CalcJob in the DB
params – input parameters for inpgen code of Dict type
Example of use:
inputs_build = get_inputs_inpgen(structure, inpgencode, options, label, description, params=params) future = self.submit(inputs_build)
- aiida_fleur.tools.common_fleur_wf.get_kpoints_mesh_from_kdensity(structure, kpoint_density)[source]
params: structuredata, Aiida structuredata params: kpoint_density
returns: tuple (mesh, offset) returns: kpointsdata node
- aiida_fleur.tools.common_fleur_wf.get_mpi_proc(resources)[source]
Determine number of total processes from given resource dict
- aiida_fleur.tools.common_fleur_wf.optimize_calc_options(nodes, mpi_per_node, omp_per_mpi, use_omp, mpi_omp_ratio, fleurinpData=None, kpts=None, sacrifice_level=0.9, only_even_MPI=False, forbid_single_mpi=False)[source]
Makes a suggestion on parallelisation setup for a particular fleurinpData. Only the total number of k-points is analysed: the function suggests ideal k-point parallelisation + OMP parallelisation (if required). Note: the total number of used CPUs per node will not exceed mpi_per_node * omp_per_mpi.
Sometimes perfect parallelisation is terms of idle CPUs is not what used wanted because it can harm MPI/OMP ratio. Thus the function first chooses first top parallelisations in terms of total CPUs used (bigger than sacrifice_level * maximal_number_CPUs_possible). Then a parallelisation which is the closest to the MPI/OMP ratio is chosen among them and returned.
- Parameters
nodes – maximal number of nodes that can be used
mpi_per_node – an input suggestion of MPI tasks per node
omp_per_mpi – an input suggestion for OMP tasks per MPI process
use_omp – False if OMP parallelisation is not needed
mpi_omp_ratio – requested MPI/OMP ratio
fleurinpData – FleurinpData to extract total number of kpts from
kpts – the total number of kpts
sacrifice_level – sets a level of performance sacrifice that a user can afford for better MPI/OMP ratio.
only_even_MPI – if set to True, the function does not set MPI to an odd number (if possible)
forbid_single_mpi – if set to True, the configuration 1 node 1 MPI per node will be forbidden
- Returns nodes, MPI_tasks, OMP_per_MPI, message
first three are parallelisation info and the last one is an exit message.
- aiida_fleur.tools.common_fleur_wf.performance_extract_calcs(calcs)[source]
Extracts some runtime and system data from given fleur calculations
- Params calcs
list of calculation nodes/pks/or uuids. Fleur calc specific
- Returns data_dict
dictionary, dictionary of arrays with the same length, from with a panda frame can be created.
Note: Is not the fastest for many calculations > 1000.
- aiida_fleur.tools.common_fleur_wf.test_and_get_codenode(codenode, expected_code_type)[source]
Pass a code node and an expected code (plugin) type. Check that the code exists, is unique, and return the Code object.
- Parameters
codenode – the name of the code to load (in the form label@machine)
expected_code_type – a string with the plugin that is expected to be loaded. In case no plugins exist with the given name, show all existing plugins of that type
- Returns
a Code object
In here we put all things (methods) that are common to workflows AND DO NOT depend on AiiDA classes, therefore can be used without loading the dbenv. Util that does depend on AiiDA classes should go somewhere else.
- aiida_fleur.tools.common_fleur_wf_util.balance_equation(equation_string, allow_negativ=False, allow_zero=False, eval_linear=True)[source]
Method that balances a chemical equation.
param equation_string: string (with ‘->’) param allow_negativ: bool, default False, allows for negative coefficients for the products.
return string: balanced equation
balance_equation(“C7H16+O2 -> CO2+H2O”)) balance_equation(“Be12W->Be22W+Be12W”) balance_equation(“Be12W->Be12W”)
have to be intergers everywhere in the equation, factors and formulas
1*C7H16+11*O2 ->7* CO2+8*H2O None 1*Be12W->1*Be12W #TODO The solver better then what we need. Currently if system is over #”Be12W->Be2W+W+Be” solves to {a: 24, b: -d/2 + 144, c: d/2 - 120}-> FAIL-> None # The code fails in the later stage, but this solution should maybe be used.
code adapted from stack exchange (the messy part): https://codegolf.stackexchange.com/questions/8728/balance-chemical-equations
- aiida_fleur.tools.common_fleur_wf_util.calc_stoi(unitcellratios, formulas, error_ratio=None)[source]
Calculate the Stoichiometry with errors from a given unit cell ratio, formulas.
Example: calc_stoi([10, 1, 7], [‘Be12Ti’, ‘Be17Ti2’, ‘Be2’], [0.1, 0.01, 0.1]) ({‘Be’: 12.583333333333334, ‘Ti’: 1.0}, {‘Be’: 0.12621369924887876, ‘Ti’: 0.0012256517540566825}) calc_stoi([10, 1, 7], [‘Be12Ti’, ‘Be17Ti2’, ‘Be2’]) ({‘Be’: 12.583333333333334, ‘Ti’: 1.0}, {})
- aiida_fleur.tools.common_fleur_wf_util.check_eos_energies(energylist)[source]
Checks if there is an abnormality in the total energies from the Equation of states. i.e. if one point has a larger energy then its two neighbors
- Parameters
energylist – list of floats
- Returns nnormalies
integer
- aiida_fleur.tools.common_fleur_wf_util.convert_eq_to_dict(equationstring)[source]
Converts an equation string to a dictionary convert_eq_to_dict(‘1*Be12Ti->10*Be+1*Be2Ti+5*Be’) -> {‘products’: {‘Be’: 15, ‘Be2Ti’: 1}, ‘educts’: {‘Be12Ti’: 1}}
- aiida_fleur.tools.common_fleur_wf_util.convert_formula_to_formula_unit(formula)[source]
Converts a formula to the smallest chemical formula unit ‘Be4W2’ -> ‘Be2W’
- aiida_fleur.tools.common_fleur_wf_util.convert_frac_formula(formula, max_digits=3)[source]
Converts a formula with fractions to a formula with integer factors only
Be0.5W0.5 -> BeW
- Parameters
formula – str, crystal formula i.e. Be2W, Be0.2W0.7
max_digits – int default=3, number of digits after which fractions will be cut off
- Returns
string
- aiida_fleur.tools.common_fleur_wf_util.determine_convex_hull(formation_en_grid)[source]
Wraps the pyhull packge implementing the qhull algo for our purposes. For now only for 2D phase diagrams Adds the points [1.0, 0.0] and [0.0, 1.0], because in material science these are always there.
- Params
formation_en_grid: list of points in phase space [[x, formation_energy]]
- Returns
a hul datatype
- aiida_fleur.tools.common_fleur_wf_util.determine_formation_energy(struc_te_dict, ref_struc_te_dict)[source]
This method determines the formation energy. E_form = E(A_xB_y) - x*E(A) - y*E(B)
- Params struc_te_dict
python dictionary in the form of {‘formula’ : total_energy} for the compound(s)
- Params ref_struc_te_dict
python dictionary in the form of {‘formula’ : total_energy per atom, or per unit cell} for the elements (if the formula of the elements contains a number the total energy is divided by that number)
- Returns
list of floats, dict {formula : eform, ..} units energy/per atom, energies have some unit as energies given
- aiida_fleur.tools.common_fleur_wf_util.determine_reactions(formula, available_data)[source]
Determines and balances theoretical possible reaction. Stoichiometry ‘Be12W’, [Be12W, Be2W, Be, W, Be22W] -> [[Be22W+Be2W], [Be12W], [Be12+W],…]
- Params formula
string, given educts (left side of equation)
- Params available_data
list of strings of compounds (products), from which all possibilities will be constructed
- aiida_fleur.tools.common_fleur_wf_util.get_atomprocent(formula)[source]
This converts a formula to a dictionary with element : atomprocent example converts ‘Be24W2’ to {‘Be’: 24/26, ‘W’ : 2/26}, also BeW to {‘Be’ : 0.5, ‘W’ : 0.5} :params: formula: string :returns: a dict, element : atomprocent
# Todo alternative with structuredata
- aiida_fleur.tools.common_fleur_wf_util.get_enhalpy_of_equation(reaction, formenergydict)[source]
calculate the enthalpy per atom of a given reaction from the given data.
param reaction: string param fromenergydict: dictionary that contains the {compound: formationenergy per atom}
# TODO check if physics is right
- aiida_fleur.tools.common_fleur_wf_util.get_natoms_element(formula)[source]
Converts ‘Be24W2’ to {‘Be’: 24, ‘W’ : 2}, also BeW to {‘Be’ : 1, ‘W’ : 1}
- aiida_fleur.tools.common_fleur_wf_util.inpgen_dict_set_mesh(inpgendict, mesh)[source]
params: python dict, used for inpgen parameterdata node params: mesh either as returned by kpointsdata or tuple of 3 integers
returns: python dict, used for inpgen parameterdata node