def test_miedema_all(self): df = pd.DataFrame({ "composition": [ Composition("TiZr"), Composition("Mg10Cu50Ca40"), Composition("Fe2O3") ] }) miedema = Miedema(struct_types='all') self.assertTrue(miedema.precheck(df["composition"].iloc[0])) self.assertFalse(miedema.precheck(df["composition"].iloc[-1])) self.assertAlmostEqual(miedema.precheck_dataframe(df, "composition"), 2 / 3) # test precheck for oxidation-state decorated compositions df = CompositionToOxidComposition(return_original_on_error=True).\ featurize_dataframe(df, 'composition') self.assertTrue(miedema.precheck(df["composition_oxid"].iloc[0])) self.assertFalse(miedema.precheck(df["composition_oxid"].iloc[-1])) self.assertAlmostEqual( miedema.precheck_dataframe(df, "composition_oxid"), 2 / 3) mfps = miedema.featurize_dataframe(df, col_id="composition") self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][0], -0.003445022152) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][0], 0.0707658836300) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][1], -0.235125978427) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][1], -0.164541848271) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][1], -0.05280843311) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_inter'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_amor'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_min'][2]), True) # make sure featurization works equally for compositions with or without # oxidation states mfps = miedema.featurize_dataframe(df, col_id="composition_oxid") self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][0], -0.003445022152) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][0], 0.0707658836300) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][0], 0.03663599755)
def test_miedema_all(self): df = pd.DataFrame({ "composition": [ Composition("TiZr"), Composition("Mg10Cu50Ca40"), Composition("Fe2O3") ] }) miedema = Miedema(struct_types='all') self.assertFalse(miedema.precheck(df["composition"].iloc[-1])) self.assertAlmostEqual(miedema.precheck_dataframe(df, "composition"), 2 / 3) mfps = miedema.featurize_dataframe(df, col_id="composition") self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][0], -0.003445022152) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][0], 0.0707658836300) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][1], -0.235125978427) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][1], -0.164541848271) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][1], -0.05280843311) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_inter'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_amor'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_min'][2]), True)
def test_miedema_all(self): df = pd.DataFrame({"composition": [Composition("TiZr"), Composition("Mg10Cu50Ca40"), Composition("Fe2O3")]}) miedema = Miedema(struct_types='all') mfps = miedema.featurize_dataframe(df, col_id="composition") self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][0], -0.003445022152) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][0], 0.0707658836300) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_inter'][1], -0.235125978427) self.assertAlmostEqual(mfps['Miedema_deltaH_amor'][1], -0.164541848271) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][1], -0.05280843311) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_inter'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_amor'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_min'][2]), True)
def _generate_pairwise_features(self): """Generates features for each bonding pair. Column labels contain a prefix "pairwise_feature {}", where the string in parethesis is either "bcc_tet1", "bcc_tet2", or "tet1_tet2". """ # initializes requested matminer featurizers feat_element_property = PairwiseElementProperty( data_source='deml', features=[ 'atom_radius', 'electronegativity', 'first_ioniz', 'col_num', 'row_num', 'molar_vol', 'heat_fusion', 'melting_point', 'GGAU_Etot', 'mus_fere', 'FERE correction' ], stats=['difference', 'mean']) feat_miedema = Miedema(struct_types=['inter', 'amor']) # generates freatures for each bonding pair for bonding_pair in ['bcc_tet1', 'bcc_tet2', 'tet1_tet2']: # gets the string composition of the bonding pairs composition_index = 'pairwise_composition {}'.format(bonding_pair) composition = self.memory[[composition_index]] # adds ElementProperty features features = feat_element_property.featurize_dataframe( df=composition, col_id=composition_index, inplace=False).drop( labels=composition_index, axis=1).add_prefix( prefix='pairwise_feature {} '.format(bonding_pair)) self.memory = concat([self.memory, features], axis=1) # gets the pymatgen.Composition of the bonding pairs composition[composition_index] = [ Composition(i) for i in composition[composition_index] ] # adds Miedema features features = feat_miedema.featurize_dataframe( df=composition, col_id=composition_index, inplace=False).drop( labels=composition_index, axis=1).add_prefix( prefix='pairwise_feature {} '.format(bonding_pair)) self.memory = concat([self.memory, features], axis=1)
def test_miedema_ss(self): df = pd.DataFrame({ "composition": [ Composition("TiZr"), Composition("Mg10Cu50Ca40"), Composition("Fe2O3") ] }) miedema = Miedema(struct_types='ss', ss_types=['min', 'fcc', 'bcc', 'hcp', 'no_latt']) mfps = miedema.featurize_dataframe(df, col_id="composition") self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_fcc'][0], 0.04700027066) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_bcc'][0], 0.08327522653) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_hcp'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_no_latt'][0], 0.036635998) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][1], -0.05280843311) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_fcc'][1], 0.03010575174) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_bcc'][1], -0.05280843311) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_hcp'][1], 0.03010575174) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_no_latt'][1], -0.0035781359) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_min'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_fcc'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_bcc'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_hcp'][2]), True) self.assertAlmostEqual( math.isnan(mfps['Miedema_deltaH_ss_no_latt'][2]), True)
def test_miedema_ss(self): df = pd.DataFrame({"composition": [Composition("TiZr"), Composition("Mg10Cu50Ca40"), Composition("Fe2O3")]}) miedema = Miedema(struct_types='ss', ss_types=['min', 'fcc', 'bcc', 'hcp', 'no_latt']) mfps = miedema.featurize_dataframe(df, col_id="composition") self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_fcc'][0], 0.04700027066) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_bcc'][0], 0.08327522653) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_hcp'][0], 0.03663599755) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_no_latt'][0], 0.036635998) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_min'][1], -0.05280843311) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_fcc'][1], 0.03010575174) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_bcc'][1], -0.05280843311) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_hcp'][1], 0.03010575174) self.assertAlmostEqual(mfps['Miedema_deltaH_ss_no_latt'][1], -0.0035781359) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_min'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_fcc'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_bcc'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_hcp'][2]), True) self.assertAlmostEqual(math.isnan(mfps['Miedema_deltaH_ss_no_latt'][2]), True)
def AddFeatures(df): # Add features by Matminer from matminer.featurizers.conversions import StrToComposition df = StrToComposition().featurize_dataframe(df, "formula") from matminer.featurizers.composition import ElementProperty ep_feat = ElementProperty.from_preset(preset_name="magpie") df = ep_feat.featurize_dataframe( df, col_id="composition" ) # input the "composition" column to the featurizer from matminer.featurizers.conversions import CompositionToOxidComposition from matminer.featurizers.composition import OxidationStates df = CompositionToOxidComposition().featurize_dataframe(df, "composition") os_feat = OxidationStates() df = os_feat.featurize_dataframe(df, "composition_oxid") from matminer.featurizers.composition import ElectronAffinity ea_feat = ElectronAffinity() df = ea_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.composition import BandCenter bc_feat = BandCenter() df = bc_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.composition import CohesiveEnergy ce_feat = CohesiveEnergy() df = ce_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.composition import Miedema m_feat = Miedema() df = m_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.composition import TMetalFraction tmf_feat = TMetalFraction() df = tmf_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.composition import ValenceOrbital vo_feat = ValenceOrbital() df = vo_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.composition import YangSolidSolution yss_feat = YangSolidSolution() df = yss_feat.featurize_dataframe(df, "composition_oxid", ignore_errors=True) from matminer.featurizers.structure import GlobalSymmetryFeatures # This is the border between compositional features and structural features. Comment out the following featurizers to use only compostional features. gsf_feat = GlobalSymmetryFeatures() df = gsf_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import StructuralComplexity sc_feat = StructuralComplexity() df = sc_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import ChemicalOrdering co_feat = ChemicalOrdering() df = co_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import MaximumPackingEfficiency mpe_feat = MaximumPackingEfficiency() df = mpe_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import MinimumRelativeDistances mrd_feat = MinimumRelativeDistances() df = mrd_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import StructuralHeterogeneity sh_feat = StructuralHeterogeneity() df = sh_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import SiteStatsFingerprint from matminer.featurizers.site import AverageBondLength from pymatgen.analysis.local_env import CrystalNN bl_feat = SiteStatsFingerprint( AverageBondLength(CrystalNN(search_cutoff=20))) df = bl_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.site import AverageBondAngle ba_feat = SiteStatsFingerprint( AverageBondAngle(CrystalNN(search_cutoff=20))) df = ba_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.site import BondOrientationalParameter bop_feat = SiteStatsFingerprint(BondOrientationalParameter()) df = bop_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.site import CoordinationNumber cn_feat = SiteStatsFingerprint(CoordinationNumber()) df = cn_feat.featurize_dataframe(df, "structure", ignore_errors=True) from matminer.featurizers.structure import DensityFeatures df_feat = DensityFeatures() df = df_feat.featurize_dataframe(df, "structure", ignore_errors=True) return (df)