Usage¶
Logging¶
element_coder uses the loguru for logging. By default, logging from element_coder is disabled to not interfere with your logs.
However, you can easily customize the logging:
import sys
from loguru import logger
# enable element_coder logging
logger.enable("element_coder")
# define the logging level
LEVEL = "INFO || DEBUG || WARNING || etc."
# set the handler
# for logging to stdout
logger.add(sys.stdout, level=LEVEL)
# or for logging to a file
logger.add("my_log_file.log", level=LEVEL, enqueue=True)
In many cases, however, you might find it convenient to simply call enable_logging()
from element_coder.utils import enable_logging
enable_logging()
which will enable logging with sane defaults (i.e. logging to stderr
for INFO
and WARNING
levels).
Numerically encode an Element.
- encode(element, property)[source]¶
Numerically encode an element.
- Parameters:
- Raises:
ValueError – If element is not of type str or pymatgen.core.Element
- Returns:
Numerical encoding of element.
- Return type:
Examples
>>> encode("Fe", "mod_pettifor") 70
Decode an elemental encoding.
- decode(encoding, property, metric='euclidean')[source]¶
Decode an elemental encoding.
- Parameters:
encoding (Union[int, float, np.ndarray]) – Numerical encoding of an element
property (str) – Property that was used for encoding, e.g. “mod_pettifor”
metric (Union[str, callable] optional) – Metric to measure distance between (noisy) input encoding and tabulated encodings. If a string, the distance function can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘jensenshannon’, ‘kulsinski’, ‘kulczynski1’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’. Defaults to “euclidean”.
- Returns:
Element symbol
- Return type:
Examples
>>> decode(80, "mod_pettifor") 'Tl'
- decode_many(encoding, property, metric='euclidean')[source]¶
Decode a collecgtio of elemental encodings.
- Parameters:
encoding (ArrayLike) – Numerical encodings of elements
property (str) – Property that was used for encoding, e.g. “mod_pettifor”
metric (Union[str, callable] optional) – Metric to measure distance between (noisy) input encoding and tabulated encodings. If a string, the distance function can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘jensenshannon’, ‘kulsinski’, ‘kulczynski1’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’. Defaults to “euclidean”.
- Returns:
Numpy array of element symbols
- Return type:
np.array
Examples
>>> decode([80, 90], "mod_pettifor") ['Tl', 'Sb']