Repository: kjappelbaum/element-coder (language: python)

Issue:
implement `get_range` 
for https://github.com/sparks-baird/xtal2png/issues/80 

- given a list of elements, provide a range of the given encoding


Discussion / hints:
I interpreted this as "encode the elements and then take the min and max as lower and upper bounds, respectively." Is that correct?
yea, it would follow the way matminer does it: Look at a bunch of structures, extract the elements you have in there, and then for the selected element encoding return the range. 

Fix patch:
diff --git a/src/element_coder/utils.py b/src/element_coder/utils.py
new file mode 100644
index 0000000..3e98903
--- /dev/null
+++ b/src/element_coder/utils.py
@@ -0,0 +1,24 @@
+"""Utilities for `element_coder`."""
+from typing import Iterable, Union
+
+from pymatgen.core import Element
+
+from .encode import encode
+
+
+def get_range(elements: Iterable[Union[str, Element, int]], property: str = "Z"):
+    """Get the range of a property for a list of elements.
+
+    Args:
+        elements (Iterable[Union[str, Element, int]]): List of elements.
+        property (str): Property that was used for encoding, e.g. "mod_pettifor"
+
+    Returns:
+        Tuple[float, int, np.ndarray]: Numerical encoding of element.
+
+    Examples:
+        >>> get_range(["Fe", "Tl", "Pb", "U", "Zn"], "mod_pettifor")
+        (70, 74)
+    """
+    encodings = [encode(element, property) for element in elements]
+    return min(encodings), max(encodings)


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 0000000..2f2a5b9
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,15 @@
+"""Testing the utils module."""
+from pymatgen.core import Element
+
+from element_coder.utils import get_range
+
+
+def test_get_range():
+    """Esnure that we get the correct range."""
+    minimum, maximum = get_range(["H", "He", "Li"], property="atomic")
+    assert minimum == 0
+    assert maximum == 2
+
+    minimum, maximum = get_range([1, Element("He"), "Li"], property="atomic")
+    assert minimum == 0
+    assert maximum == 2