Skip to content

Commit f39992b

Browse files
authored
Defer MPRester import to allow it to act more like an optional dependency (#906)
1 parent 29f13fd commit f39992b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

matminer/featurizers/composition/thermo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Composition featurizers for thermodynamic properties.
33
"""
44

5-
from pymatgen.ext.matproj import MPRester
65

76
from matminer.featurizers.base import BaseFeaturizer
87
from matminer.utils.data import CohesiveEnergyData
@@ -40,6 +39,8 @@ def featurize(self, comp, formation_energy_per_atom=None):
4039
formation_energy_per_atom = formation_energy_per_atom or None
4140

4241
if not formation_energy_per_atom:
42+
from pymatgen.ext.matproj import MPRester
43+
4344
# Get formation energy of most stable structure from MP
4445
if self.mapi_key:
4546
struct_lst = MPRester(self.mapi_key).get_data(comp.reduced_formula)
@@ -98,6 +99,7 @@ def featurize(self, comp):
9899
Args:
99100
comp: (str) compound composition, eg: "NaCl"
100101
"""
102+
from pymatgen.ext.matproj import MPRester
101103

102104
# Get formation energy of most stable structure from MP
103105
with MPRester(self.mapi_key) if self.mapi_key else MPRester() as mpr:

matminer/featurizers/conversions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from monty.json import MontyDecoder
1313
from pymatgen.core.composition import Composition
1414
from pymatgen.core.structure import IStructure
15-
from pymatgen.ext.matproj import MPRester
1615
from pymatgen.io.ase import AseAtomsAdaptor
1716

1817
from matminer.featurizers.base import BaseFeaturizer
@@ -566,6 +565,9 @@ class CompositionToStructureFromMP(ConversionFeaturizer):
566565
"""
567566

568567
def __init__(self, target_col_id="structure", overwrite_data=False, mapi_key=None):
568+
569+
from pymatgen.ext.matproj import MPRester
570+
569571
super().__init__(target_col_id, overwrite_data)
570572
if mapi_key:
571573
self.mpr = MPRester(mapi_key)

0 commit comments

Comments
 (0)