utils#

Utility functions

Functions

convert_conc_from_weight_to_cm3

Convert concentration of dopand from weight % (common experimental data) to cm^-3.

decode_object_from_json

Build MSONable object from json file or string.

format_composition

Format composition with latex syntax.

get_charge_from_computed_entry

Get charge of vasp calculation from ComputedEntry object.

get_object_feature

Get value of attribute or method of a generic Object.

get_object_from_json

Build class object from json file or string.

save_object_as_json

Save class object as json string or file.

select_objects

Select objects from a list based on different criteria.

sort_objects

Sort objects based on a list of features (attributes or methods of the objects, or functions)

convert_conc_from_weight_to_cm3(c_weight, target_el, composition, bulk_volume=None, bulk_structure=None)[source]#

Convert concentration of dopand from weight % (common experimental data) to cm^-3.

Parameters:
  • c_weight (float) – Defect concentration in weight %.

  • target_el (str) – Symbol of target element.

  • composition (Composition) – Composition of the material, uses only list of elements.

  • bulk_volume (float) – Volume of bulk cell in A°^3.

  • bulk_structure (Structure) – If bulk_volume is not provided, use the Structure object of bulk material to optain the cell volume.

Returns:

conc – Concentration in cm-3^.

Return type:

float

decode_object_from_json(path_or_string)[source]#

Build MSONable object from json file or string.

Parameters:

path_or_string (str) – If an existing path to a file is given the object is constructed reading the json file. Otherwise it will be read as a string.

Return type:

Decoded object.

format_composition(string, all_math=False)[source]#

Format composition with latex syntax.

get_charge_from_computed_entry(entry)[source]#

Get charge of vasp calculation from ComputedEntry object. Subtracts the total valence electrons from potcar to ‘NELECT’ value

get_object_feature(obj, feature)[source]#

Get value of attribute or method of a generic Object. If feature is a single method only the string with the method’s name is required. If the target feature is stored in a dictionary (or dict of dictionaries), a list of this format needs to be provided: [“method_name”,key1,key2,…].

This will identify the value of Object.method[key1][key2][…] .

Parameters:
  • obj (object) – Generic object.

  • feature (str or list) – Method or attribute of class for which the value is needed.

Return type:

Object feature.

get_object_from_json(object_class, path_or_string)[source]#

Build class object from json file or string. The class must posses the ‘from_dict’ method.

Parameters:
  • object_class (class) – Class of the object to decode.

  • path_or_string (str) – If an existing path to a file is given the object is constructed reading the json file. Otherwise it will be read as a string.

Return type:

Decoded object.

save_object_as_json(object, path, sanitize=False, cls=<class 'monty.json.MontyEncoder'>)[source]#

Save class object as json string or file. The class must posses the as_dict method.

Parameters:
  • object (object) – Generic object. Must posses the as_dict method.

  • path (str) – Path to the destination file. If None a string is exported.

Returns:

d – If path is not set a string is returned.

Return type:

str

select_objects(objects, mode='and', exclude=False, functions=None, **kwargs)[source]#

Select objects from a list based on different criteria. Returns a list of objects.

Parameters:
  • objects (list) – List of objects.

  • mode (str) – Filtering mode, possibilities are: ‘and’ and ‘or’. The default is ‘and’.

  • exclude (bool) – Exclude the entries satisfying the criteria instead of selecting them. The default is False.

  • functions (list) – Functions containing criteria. The functions must take the object as the argument and return a bool.

  • kwargs (dict) – Keys are methods/attributes the objects have. Values contain the criteria. To address more than one condition relative to the same attribute, use lists or tuples (e.g. charge=[0,1]).

Returns:

output_objects – List with selected objects.

Return type:

list

sort_objects(objects, features, reverse=False)[source]#

Sort objects based on a list of features (attributes or methods of the objects, or functions)

Parameters:
  • objects (list) – List of objects to sort.

  • features (list) – List of features to sort by. Can be a function that takes the object as argument or an attribute (see get_object_feature).

  • reverse (bool) – Reverse order.

Returns:

sorted_objects – Sorted objects.

Return type:

list