Skip to content

Commit

Permalink
BandCenter and IntersticeDistribution: init MagpieData at insta…
Browse files Browse the repository at this point in the history
…nce level rather than per sample (#897)
  • Loading branch information
ml-evs committed May 26, 2023
1 parent a3da199 commit f622439
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions matminer/featurizers/composition/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class BandCenter(BaseFeaturizer):
- Band center
"""

magpie_data = MagpieData()
deml_data = DemlData()

def featurize(self, comp):
"""
(Rough) estimation of absolution position of band center using
Expand All @@ -222,8 +225,8 @@ def featurize(self, comp):
gmean = 1.0
sumamt = sum(comp.get_el_amt_dict().values())
for el, amt in comp.get_el_amt_dict().items():
first_ioniz = DemlData().get_elemental_property(Element(el), "first_ioniz") / 1000
elec_aff = MagpieData().get_elemental_property(Element(el), "ElectronAffinity")
first_ioniz = self.deml_data.get_elemental_property(Element(el), "first_ioniz") / 1000
elec_aff = self.magpie_data.get_elemental_property(Element(el), "ElectronAffinity")
gmean *= (0.5 * (first_ioniz + elec_aff) / 96.48) ** (amt / sumamt)
return [gmean]

Expand Down
5 changes: 3 additions & 2 deletions matminer/featurizers/site/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, cutoff=6.5, interstice_types=None, stats=None, radius_type="M
raise ValueError("interstice_types only support sub-list of " "['dist', 'area', 'vol']")
self.stats = ["mean", "std_dev", "minimum", "maximum"] if stats is None else stats
self.radius_type = radius_type
self.data_source = MagpieData()

def featurize(self, struct, idx):
"""
Expand All @@ -78,9 +79,9 @@ def featurize(self, struct, idx):
nn_coords = np.array([nn["site"].coords for nn in n_w])

# Get center atom's radius and its nearest neighbors' radii
center_r = MagpieData().get_elemental_properties([struct[idx].specie], self.radius_type)[0] / 100
center_r = self.data_source.get_elemental_properties([struct[idx].specie], self.radius_type)[0] / 100
nn_els = [nn["site"].specie for nn in n_w]
nn_rs = np.array(MagpieData().get_elemental_properties(nn_els, self.radius_type)) / 100
nn_rs = np.array(self.data_source.get_elemental_properties(nn_els, self.radius_type)) / 100

# Get indices of atoms forming the simplices of convex hull
convex_hull_simplices = ConvexHull(nn_coords).simplices
Expand Down

0 comments on commit f622439

Please sign in to comment.