Skip to content

Commit ba6d651

Browse files
committed
fix mendeleev related errros
1 parent b07230d commit ba6d651

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

src/lobsterpy/cli.py

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

88
import argparse
99
import json
10-
import warnings
1110
from math import log, sqrt
1211
from pathlib import Path
1312

@@ -20,20 +19,7 @@
2019

2120
from lobsterpy.cohp.analyze import Analysis
2221
from lobsterpy.cohp.describe import Description
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-
22+
from lobsterpy.featurize.core import FeaturizeIcoxxlist
3723
from lobsterpy.featurize.utils import get_file_paths
3824
from lobsterpy.plotting import (
3925
BWDFPlotter,

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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
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
1318
from monty.dev import requires
1419
from monty.os.path import zpath
@@ -131,7 +136,8 @@ def get_structure_path(lobster_path: Path) -> Path:
131136

132137

133138
@requires(
134-
"mendeleev", "get_reduced_mass requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`."
139+
element is not None,
140+
"get_reduced_mass requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`.",
135141
)
136142
def get_reduced_mass(atom_pair: list[str]) -> float:
137143
"""
@@ -141,15 +147,13 @@ def get_reduced_mass(atom_pair: list[str]) -> float:
141147
142148
:return: reduced mass
143149
"""
144-
from mendeleev import element
145-
146150
atom1 = element(atom_pair[0])
147151
atom2 = element(atom_pair[1])
148152
return (atom1.atomic_weight * atom2.atomic_weight) / (atom1.atomic_weight + atom2.atomic_weight)
149153

150154

151155
@requires(
152-
"mendeleev",
156+
element is not None,
153157
"get_electronegativities requires mendeleev. Reinstall package with `pip install lobsterpy[featurizer]`.",
154158
)
155159
def get_electronegativities(atom_pair: list[str]) -> list[float]:
@@ -160,8 +164,6 @@ def get_electronegativities(atom_pair: list[str]) -> list[float]:
160164
161165
:return: list of Allen electronegativities
162166
"""
163-
from mendeleev import element
164-
165167
atom1 = element(atom_pair[0])
166168
atom2 = element(atom_pair[1])
167169
return [atom1.electronegativity_allen(), atom2.electronegativity_allen()]

0 commit comments

Comments
 (0)