Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optical spectra from refractiveindex.info as composite features #1

Merged
merged 17 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion matminer/featurizers/composition/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from matminer.featurizers.composition.alloy import Miedema, WenAlloys, YangSolidSolution
from matminer.featurizers.composition.composite import ElementProperty, Meredig
from matminer.featurizers.composition.composite import ElementProperty, Meredig, RefractiveIndex
from matminer.featurizers.composition.element import (
BandCenter,
ElementFraction,
Expand Down
39 changes: 37 additions & 2 deletions matminer/featurizers/composition/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MatscholarElementData,
MEGNetElementData,
PymatgenData,
OpticalData
)


Expand Down Expand Up @@ -43,9 +44,10 @@ class ElementProperty(BaseFeaturizer):
(these must be supported by data_source)
stats (list of strings): a list of weighted statistics to compute to for each
property (see PropertyStats for available stats)
optical_args: list of arguments for the optical data
"""

def __init__(self, data_source, features, stats):
def __init__(self, data_source, features, stats, **optical_args):
if data_source == "pymatgen":
self.data_source = PymatgenData()
elif data_source == "magpie":
Expand All @@ -56,6 +58,8 @@ def __init__(self, data_source, features, stats):
self.data_source = MatscholarElementData()
elif data_source == "megnet_el":
self.data_source = MEGNetElementData()
elif data_source == "refractive_index":
self.data_source = OpticalData(**optical_args)
else:
self.data_source = data_source

Expand All @@ -65,7 +69,7 @@ def __init__(self, data_source, features, stats):
self.pstats = PropertyStats()

@classmethod
def from_preset(cls, preset_name):
def from_preset(cls, preset_name, **optical_args):
"""
Return ElementProperty from a preset string
Args:
Expand Down Expand Up @@ -154,6 +158,11 @@ def from_preset(cls, preset_name):
stats = ["minimum", "maximum", "range", "mean", "std_dev"]
features = MEGNetElementData().prop_names

elif preset_name == "refractive_index":
data_source = "refractive_index"
stats = ["minimum", "maximum", "range", "mean", "std_dev", "mode"]
features = OpticalData(**optical_args).prop_names

else:
raise ValueError("Invalid preset_name specified!")

Expand Down Expand Up @@ -327,3 +336,29 @@ def citations(self):

def implementors(self):
return ["Amalie Trewartha"]


class RefractiveIndex(ElementProperty):
gbrunin marked this conversation as resolved.
Show resolved Hide resolved
gbrunin marked this conversation as resolved.
Show resolved Hide resolved
"""
Class to calculate features based on optical properties,
taken from https://www.refractiveindex.info
gbrunin marked this conversation as resolved.
Show resolved Hide resolved
"""

@classmethod
def from_preset(cls, **optical_args):
data_source = OpticalData(**optical_args)
features = data_source.prop_names
stats = ["minimum", "maximum", "range", "mean", "std_dev", "mode"]
gbrunin marked this conversation as resolved.
Show resolved Hide resolved
return cls(data_source, features, stats)

def citations(self):
davidwaroquiers marked this conversation as resolved.
Show resolved Hide resolved
citation = ["@misc{rii,"
"author = {Mikhail N. Polyanskiy},"
"title = {Refractive index database},"
"howpublished = {https://refractiveindex.info},"
"note = {Accessed on 2022-06-30}}"
]
return citation

def implementors(self):
return ["Matgenix"]
gbrunin marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion matminer/featurizers/composition/tests/test_composite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
import unittest

from matminer.featurizers.composition.composite import ElementProperty, Meredig
from matminer.featurizers.composition.composite import ElementProperty, Meredig, RefractiveIndex
from matminer.featurizers.composition.tests.base import CompositionFeaturesTest


Expand Down Expand Up @@ -88,6 +88,12 @@ def test_fere_corr(self):
self.assertAlmostEqual(df_fere_corr["DemlData mean FERE correction"][0], 0.077146274)
self.assertAlmostEqual(df_fere_corr["DemlData std_dev FERE correction"][0], 0.270209766)

def test_elem_optical(self):
df_elem = RefractiveIndex.from_preset().featurize_dataframe(self.df, col_id="composition")
df_elem = ElementProperty.from_preset("refractive_index").featurize_dataframe(self.df, col_id="composition")
self.assertAlmostEqual(df_elem["OpticalData mean n_400.0"].iloc[0], 1.6864762491106)
self.assertAlmostEqual(df_elem["OpticalData range k_760.0"].iloc[1], 5.13858582260221)
self.assertAlmostEqual(df_elem["OpticalData maximum R_720.0"].iloc[0], 0.567571902137101)

if __name__ == "__main__":
unittest.main()
Loading