Conversion between atomic numbers and element symbols¶
Utility functions for various tasks.
-
class
flare.utils.element_coder.
NumpyEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶ Special json encoder for numpy types for serialization use as
json.loads(… cls = NumpyEncoder)
or:
json.dumps(… cls = NumpyEncoder)
Thanks to StackOverflow users karlB and fnunnari, who contributed this from: https://stackoverflow.com/a/47626762
-
flare.utils.element_coder.
Z_to_element
(Z: int) → str¶ Maps atomic numbers Z to element name, e.g. 1->”H”.
Parameters: Z – Atomic number corresponding to element. Returns: One or two-letter name of element.
-
flare.utils.element_coder.
element_to_Z
(element: str) → int¶ Returns the atomic number Z associated with an elements 1-2 letter name. Returns the same integer if an integer is passed in.
Parameters: element – Returns:
-
flare.utils.element_coder.
inject_user_definition
(element: str, Z: int)¶ Allow user-defined element. The definition will override the default ones from the periodic table.
Example:
>>> import flare.utils >>> import flare.utils.element_coder as ec >>> ec.inject_user_definition('C1', 6) >>> ec.inject_user_definition('C2', 7) >>> ec.inject_user_definition('H1', 1) >>> ec.inject_user_definition('H2', 2)
This block should be executed before any other flare modules are imported. And user has to be very careful to not let Z overlap with other elements in the system
Parameters: - element (str) – string symbol of the element
- Z (int) – corresponding Z