Exemple #1
0
 def test_elem(self):
     df_elem = ElementProperty().featurize_dataframe(self.df,
                                                     col_id="composition")
     self.assertAlmostEqual(df_elem["minimum Number"][0], 8)
     self.assertAlmostEqual(df_elem["maximum Number"][0], 26)
     self.assertAlmostEqual(df_elem["range Number"][0], 18)
     self.assertAlmostEqual(df_elem["mean Number"][0], 15.2)
     self.assertAlmostEqual(df_elem["avg_dev Number"][0], 8.64)
     self.assertAlmostEqual(df_elem["mode Number"][0], 8)
Exemple #2
0
 def test_fere_corr(self):
     df_fere_corr = ElementProperty(features=["FERE correction"],
                                    stats=["minimum", "maximum", "range", "mean", "std_dev"],
                                    data_source="deml")\
         .featurize_dataframe(self.df, col_id="composition")
     self.assertAlmostEqual(df_fere_corr["minimum FERE correction"][0], -0.15213431610903)
     self.assertAlmostEqual(df_fere_corr["maximum FERE correction"][0], 0.23)
     self.assertAlmostEqual(df_fere_corr["range FERE correction"][0], 0.382134316)
     self.assertAlmostEqual(df_fere_corr["mean FERE correction"][0], 0.077146274)
     self.assertAlmostEqual(df_fere_corr["std_dev FERE correction"][0], 0.270209766)
Exemple #3
0
 def test_elem_deml(self):
     df_elem_deml = ElementProperty("deml").featurize_dataframe(
         self.df, col_id="composition")
     self.assertAlmostEqual(df_elem_deml["minimum atom_num"][0], 8)
     self.assertAlmostEqual(df_elem_deml["maximum atom_num"][0], 26)
     self.assertAlmostEqual(df_elem_deml["range atom_num"][0], 18)
     self.assertAlmostEqual(df_elem_deml["mean atom_num"][0], 15.2)
     self.assertAlmostEqual(df_elem_deml["std_dev atom_num"][0], 8.81816307)
     #Charge dependent property
     self.assertAlmostEqual(df_elem_deml["minimum magn_moment"][0], 0)
     self.assertAlmostEqual(df_elem_deml["maximum magn_moment"][0], 5.2)
     self.assertAlmostEqual(df_elem_deml["range magn_moment"][0], 5.2)
     self.assertAlmostEqual(df_elem_deml["mean magn_moment"][0], 2.08)
     self.assertAlmostEqual(df_elem_deml["std_dev magn_moment"][0],
                            2.547469332)
    def __init__(self,
                 cation_site=None,
                 site_ox_lim={
                     'A': [0, 10],
                     'B': [0, 10],
                     'X': [-10, 0]
                 },
                 site_base_ox={
                     'A': 2,
                     'B': 4,
                     'X': -2
                 },
                 ordered_formulas=False,
                 A_site_occupancy=1,
                 anions=None):

        if cation_site is None and ordered_formulas is False:
            raise ValueError(
                'Either cation sites must be assigned, or formulas must be ordered. Otherwise site assignments can not be determined'
            )

        self.cation_site = cation_site
        self.site_ox_lim = site_ox_lim
        self.site_base_ox = site_base_ox
        self.ordered_formulas = ordered_formulas
        self.A_site_occupancy = A_site_occupancy
        self.anions = anions

        #matminer featurizers
        self.ValenceOrbital = ValenceOrbital()
        self.AtomicOrbitals = AtomicOrbitalsMod()
        self.CohesiveEnergy = CohesiveEnergy()
        #custom ElementProperty featurizer
        elemental_properties = [
            'BoilingT', 'MeltingT', 'BulkModulus', 'ShearModulus', 'Row',
            'Column', 'Number', 'MendeleevNumber', 'SpaceGroupNumber',
            'Density', 'MolarVolume', 'FusionEnthalpy', 'HeatVaporization',
            'NsUnfilled', 'NpUnfilled', 'NdUnfilled', 'NfUnfilled',
            'Polarizability', 'ThermalConductivity'
        ]
        self.ElementProperty = ElementProperty(
            data_source='magpie',
            features=elemental_properties,
            stats=["mean", "std_dev", "range"])

        self.check_matminer_featurizers()
        self.featurize_options = {}
Exemple #5
0
	def __init__(self,radius_type='ionic_radius',normalize_formula=False):
		self.radius_type = radius_type
		self.normalize_formula = normalize_formula
		self.ValenceOrbital = ValenceOrbital()
		self.AtomicOrbitals = AtomicOrbitalsMod()
		self.CohesiveEnergy = CohesiveEnergy()
		self.BandCenter = BandCenter()
		self.ValenceOrbitalEnergy = ValenceOrbitalEnergy()
		#custom ElementProperty featurizer
		elemental_properties = ['BoilingT', 'MeltingT',
			'BulkModulus', 'ShearModulus', 
			'Row', 'Column', 'Number', 'MendeleevNumber', 'SpaceGroupNumber',
			'Density','MolarVolume',
			'FusionEnthalpy','HeatVaporization',
			'Polarizability', 
			'ThermalConductivity']
		self.ElementProperty = ElementProperty(data_source='magpie',features=elemental_properties,
						  stats=["mean", "std_dev"])
		#check matminer featurizers
		self.check_matminer_featurizers()
df['poisson_ratio']=df[["elasticity.K_VRH","elasticity.G_VRH"]].apply(lambda x:(3*x["elasticity.K_VRH"]-2*x["elasticity.G_VRH"])/(6*x["elasticity.K_VRH"]+2*x["elasticity.G_VRH"]),axis=1)
from matminer.featurizers.conversions import StrToComposition
df = StrToComposition().featurize_dataframe(df, "pretty_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")
dataset = PymatgenData()
descriptors = ['row', 'group', 'atomic_mass',
               'atomic_radius', 'boiling_point', 'melting_point', 'X']
stats = ["mean", "std_dev"]
ep = ElementProperty(data_source=dataset, features=descriptors, stats=stats)
df = ep.featurize_dataframe(df, "composition")
#Remove NaN values
df = df.dropna()

#y = df['elasticity.K_VRH'].values
y=df['Tensile Strength, Yield'].values
excluded = ["elasticity.G_VRH", "elasticity.K_VRH",  "pretty_formula", 'volume','nsites','spacegroup.symbol','e_above_hull','Tensile Strength, Yield','Elongation at Break ','Tensile Strength,Ultimate',
            "poisson_ratio", "composition", "composition_oxid"]#"elastic_anisotropy"
X = df.drop(excluded, axis=1)
print("There are {} possible descriptors:\n\n{}".format(X.shape[1], X.columns.values))
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
import numpy as np
lr = LinearRegression()
lr.fit(X, y)
}

# define valid magpie featueres
# https://github.com/hackingmaterials/
# matminer/blob/master/matminer/featurizers/
# composition.py
features = [
    "Number", "MendeleevNumber", "AtomicWeight", "MeltingT", "Column", "Row",
    "CovalentRadius", "Electronegativity", "NsValence", "NpValence",
    "NdValence", "NfValence", "NValence", "NsUnfilled", "NpUnfilled",
    "NdUnfilled", "NfUnfilled", "NUnfilled", "GSvolume_pa", "GSbandgap",
    "GSmagmom", "SpaceGroupNumber"
]

# initialize matminer featurizer
elemprop = ElementProperty('magpie', features, ['mean'])

# featurize each element, getting the element propertie in a list
X = {}
valid_symbols = list(elem_dict.values())[1:98]
for symbol in valid_symbols:
    comp = pymatgen.Composition(symbol)
    x_i = elemprop.featurize(comp)
    X[symbol] = x_i

# rename element properties to match magpie features
X = pd.DataFrame(X).T
X.columns = features

# fill missing features with the median from each column
for column in X: