Skip to content

Commit d3b3f21

Browse files
authored
Merge pull request #383 from naik-aakash/fix_cli
Fix optional dependencies related errors
2 parents 73775f5 + ba6d651 commit d3b3f21

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/lobsterpy/featurize/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
import numpy as np
1616
import pandas as pd
17-
from mendeleev import element
17+
18+
try:
19+
from mendeleev import element
20+
except ImportError:
21+
element = None
22+
from monty.dev import requires
1823
from numpy import ndarray
1924
from pymatgen.core.structure import Structure
2025
from pymatgen.electronic_structure.cohp import CompleteCohp
@@ -875,6 +880,10 @@ def get_summarized_coxx_df(
875880
return df
876881

877882

883+
@requires(
884+
element is not None,
885+
"FeaturizeCharges requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`.",
886+
)
878887
class FeaturizeCharges:
879888
"""
880889
Class to compute Ionicity from CHARGE.lobster data.

src/lobsterpy/featurize/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
from typing import NamedTuple
1010
from warnings import warn
1111

12+
try:
13+
from mendeleev import element
14+
except ImportError:
15+
element = None
16+
1217
import numpy as np
13-
from mendeleev import element
18+
from monty.dev import requires
1419
from monty.os.path import zpath
1520

1621
POSCAR_WARNING = (
@@ -130,6 +135,10 @@ def get_structure_path(lobster_path: Path) -> Path:
130135
raise Exception
131136

132137

138+
@requires(
139+
element is not None,
140+
"get_reduced_mass requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`.",
141+
)
133142
def get_reduced_mass(atom_pair: list[str]) -> float:
134143
"""
135144
Compute reduced mass between a pair of atoms.
@@ -143,6 +152,10 @@ def get_reduced_mass(atom_pair: list[str]) -> float:
143152
return (atom1.atomic_weight * atom2.atomic_weight) / (atom1.atomic_weight + atom2.atomic_weight)
144153

145154

155+
@requires(
156+
element is not None,
157+
"get_electronegativities requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`.",
158+
)
146159
def get_electronegativities(atom_pair: list[str]) -> list[float]:
147160
"""
148161
Get Allen electronegativities for a pair of atoms.

0 commit comments

Comments
 (0)