Skip to content

Commit b07230d

Browse files
committed
make dependencies optional
1 parent 73775f5 commit b07230d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/lobsterpy/cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import argparse
99
import json
10+
import warnings
1011
from math import log, sqrt
1112
from pathlib import Path
1213

@@ -19,7 +20,20 @@
1920

2021
from lobsterpy.cohp.analyze import Analysis
2122
from lobsterpy.cohp.describe import Description
22-
from lobsterpy.featurize.core import FeaturizeIcoxxlist
23+
24+
try:
25+
from lobsterpy.featurize.core import FeaturizeIcoxxlist
26+
27+
except ModuleNotFoundError:
28+
FeaturizeIcoxxlist = None
29+
warnings.warn(
30+
"plot-bwdf action is not available as the "
31+
"dependencies needed for the featurize module is not installed. "
32+
"To enable this action reinstall the package with "
33+
"`pip install lobsterpy[featurizer]` command.",
34+
stacklevel=1,
35+
)
36+
2337
from lobsterpy.featurize.utils import get_file_paths
2438
from lobsterpy.plotting import (
2539
BWDFPlotter,

src/lobsterpy/featurize/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from warnings import warn
1111

1212
import numpy as np
13-
from mendeleev import element
13+
from monty.dev import requires
1414
from monty.os.path import zpath
1515

1616
POSCAR_WARNING = (
@@ -130,6 +130,9 @@ def get_structure_path(lobster_path: Path) -> Path:
130130
raise Exception
131131

132132

133+
@requires(
134+
"mendeleev", "get_reduced_mass requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`."
135+
)
133136
def get_reduced_mass(atom_pair: list[str]) -> float:
134137
"""
135138
Compute reduced mass between a pair of atoms.
@@ -138,11 +141,17 @@ def get_reduced_mass(atom_pair: list[str]) -> float:
138141
139142
:return: reduced mass
140143
"""
144+
from mendeleev import element
145+
141146
atom1 = element(atom_pair[0])
142147
atom2 = element(atom_pair[1])
143148
return (atom1.atomic_weight * atom2.atomic_weight) / (atom1.atomic_weight + atom2.atomic_weight)
144149

145150

151+
@requires(
152+
"mendeleev",
153+
"get_electronegativities requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`.",
154+
)
146155
def get_electronegativities(atom_pair: list[str]) -> list[float]:
147156
"""
148157
Get Allen electronegativities for a pair of atoms.
@@ -151,6 +160,8 @@ def get_electronegativities(atom_pair: list[str]) -> list[float]:
151160
152161
:return: list of Allen electronegativities
153162
"""
163+
from mendeleev import element
164+
154165
atom1 = element(atom_pair[0])
155166
atom2 = element(atom_pair[1])
156167
return [atom1.electronegativity_allen(), atom2.electronegativity_allen()]

0 commit comments

Comments
 (0)