Skip to content

Commit

Permalink
add new utils functions to featurize module
Browse files Browse the repository at this point in the history
  • Loading branch information
naik-aakash committed Sep 10, 2024
1 parent b722b16 commit 328f315
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/lobsterpy/featurize/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pathlib import Path

from mendeleev import element
from monty.os.path import zpath


Expand Down Expand Up @@ -91,3 +92,40 @@ def get_structure_path(lobster_path: Path) -> Path:
return gz_file_path

raise Exception


def get_reduced_mass(atom_pair: list[str]) -> float:
"""
Compute reduced mass between a pair of atoms.
:param atom_pair: list of atomic species symbols in string
:return: reduced mass
"""
atom1 = element(atom_pair[0])
atom2 = element(atom_pair[1])
return (atom1.atomic_weight * atom2.atomic_weight) / (atom1.atomic_weight + atom2.atomic_weight)


def get_electronegativities(atom_pair: list[str]) -> list[float]:
"""
Get allen electronegativities for a pair of atoms.
:param atom_pair: list of atomic species symbols in string
:return: list of allen electronegativities
"""
atom1 = element(atom_pair[0])
atom2 = element(atom_pair[1])
return [atom1.electronegativity_allen(), atom2.electronegativity_allen()]


def sort_dict_by_value(input_dict: dict[str, float]) -> dict:
"""
Sort dictionary by values.
:param input_dict: input dictionary
:return: sorted dictionary
"""
return dict(sorted(input_dict.items(), key=lambda item: item[1]))

0 comments on commit 328f315

Please sign in to comment.