def __init__(self, data_source, features, stats): if data_source == "pymatgen": self.data_source = PymatgenData() elif data_source == "magpie": self.data_source = MagpieData() elif data_source == "deml": self.data_source = DemlData() else: self.data_source = data_source self.features = features self.stats = stats
class ElectronAffinity(BaseFeaturizer): """ Calculate average electron affinity times formal charge of anion elements. Note: The formal charges must already be computed before calling `featurize`. Generates average (electron affinity*formal charge) of anions. """ def __init__(self): self.data_source = DemlData() def featurize(self, comp): """ Args: comp: (Composition) Composition to be featurized Returns: avg_anion_affin (single-element list): average electron affinity*formal charge of anions """ # Check if oxidation states have been computed if not has_oxidation_states(comp): raise ValueError('Composition lacks oxidation states') # Get the species and fractions species, fractions = zip(*comp.items()) # Determine which species are anions anions, fractions = zip(*[(s, f) for s, f in zip(species, fractions) if s.oxi_state < 0]) # Compute the electron_affinity*formal_charge for each anion electron_affin = [ self.data_source.get_elemental_property(s.element, "electron_affin") * s.oxi_state for s in anions ] # Compute the average affinity avg_anion_affin = PropertyStats.mean(electron_affin, fractions) return [avg_anion_affin] def feature_labels(self): return ["avg anion electron affinity"] def citations(self): citation = [ "@article{deml_ohayre_wolverton_stevanovic_2016, title={Predicting density " "functional theory total energies and enthalpies of formation of metal-nonmetal " "compounds by linear regression}, volume={47}, DOI={10.1002/chin.201644254}, " "number={44}, journal={ChemInform}, author={Deml, Ann M. and Ohayre, Ryan and " "Wolverton, Chris and Stevanovic, Vladan}, year={2016}}"] return citation def implementors(self): return ["Jiming Chen", "Logan Ward"]
class TestDemlData(TestCase): """Tests for the DemlData Class""" def setUp(self): self.data_source = DemlData() def test_get_property(self): self.assertAlmostEqual( -4.3853, self.data_source.get_elemental_property(Element("Bi"), "mus_fere"), 4) self.assertEqual( 59600, self.data_source.get_elemental_property(Element("Li"), "electron_affin")) self.assertAlmostEqual( 2372300, self.data_source.get_elemental_property(Element("He"), "first_ioniz")) self.assertAlmostEqual( sum([2372300, 5250500]), self.data_source.get_charge_dependent_property_from_specie( Specie("He", 2), "total_ioniz")) self.assertAlmostEqual( 18.6, self.data_source.get_charge_dependent_property_from_specie( Specie("V", 3), "xtal_field_split")) def test_get_oxidation(self): self.assertEqual([1], self.data_source.get_oxidation_states(Element("Li")))
def __init__(self, data_source, features, stats): if data_source == "pymatgen": self.data_source = PymatgenData() elif data_source == "magpie": self.data_source = MagpieData() elif data_source == "deml": self.data_source = DemlData() elif data_source == "matscholar_el": self.data_source = MatscholarElementData() elif data_source == "megnet_el": self.data_source = MEGNetElementData() else: self.data_source = data_source self.features = features self.stats = stats # Initialize stats computer self.pstats = PropertyStats()
class TestDemlData(TestCase): """Tests for the DemlData Class""" def setUp(self): self.data_source = DemlData() def test_get_property(self): self.assertAlmostEqual(-4.3853, self.data_source.get_elemental_property(Element("Bi"), "mus_fere"), 4) self.assertEqual(59600, self.data_source.get_elemental_property(Element("Li"), "electron_affin")) self.assertAlmostEqual(2372300, self.data_source.get_elemental_property(Element("He"), "first_ioniz")) self.assertAlmostEqual(sum([2372300,5250500]), self.data_source.get_charge_dependent_property_from_specie(Specie("He", 2), "total_ioniz")) self.assertAlmostEqual(18.6, self.data_source.get_charge_dependent_property_from_specie(Specie("V", 3), "xtal_field_split")) def test_get_oxidation(self): self.assertEqual([1], self.data_source.get_oxidation_states(Element("Li")))
def __init__(self): self.data_source = DemlData()
def setUp(self): self.data_source = DemlData()
def __init__(self, data_source=DemlData(), stats=None): self.data_source = data_source if stats == None: self.stats = ["minimum", "maximum", "range", "mean", "std_dev"] else: self.stats = stats
class ElementProperty(BaseFeaturizer): """ Class to calculate elemental property attributes. To initialize quickly, use the from_preset() method. Parameters: data_source (AbstractData or str): source from which to retrieve element property data (or use str for preset: "pymatgen", "magpie", or "deml") features (list of strings): List of elemental properties to use (these must be supported by data_source) stats (string): a list of weighted statistics to compute to for each property (see PropertyStats for available stats) """ def __init__(self, data_source, features, stats): if data_source == "pymatgen": self.data_source = PymatgenData() elif data_source == "magpie": self.data_source = MagpieData() elif data_source == "deml": self.data_source = DemlData() else: self.data_source = data_source self.features = features self.stats = stats @staticmethod def from_preset(preset_name): """ Return ElementProperty from a preset string Args: preset_name: (str) can be one of "magpie", "deml", or "matminer" Returns: """ if preset_name == "magpie": data_source = "magpie" features = [ "Number", "MendeleevNumber", "AtomicWeight", "MeltingT", "Column", "Row", "CovalentRadius", "Electronegativity", "NsValence", "NpValence", "NdValence", "NfValence", "NValance", "NsUnfilled", "NpUnfilled", "NdUnfilled", "NfUnfilled", "NUnfilled", "GSvolume_pa", "GSbandgap", "GSmagmom", "SpaceGroupNumber" ] stats = ["minimum", "maximum", "range", "mean", "avg_dev", "mode"] elif preset_name == "deml": data_source = "deml" stats = ["minimum", "maximum", "range", "mean", "std_dev"] features = [ "atom_num", "atom_mass", "row_num", "col_num", "atom_radius", "molar_vol", "heat_fusion", "melting_point", "boiling_point", "heat_cap", "first_ioniz", "total_ioniz", "electronegativity", "formal_charge", "xtal_field_split", "magn_moment", "so_coupling", "sat_magn", "electric_pol", "GGAU_Etot", "mus_fere" ] elif preset_name == "matminer": data_source = "pymatgen" stats = ["minimum", "maximum", "range", "mean", "std_dev"] features = [ "X", "row", "group", "block", "atomic_mass", "atomic_radius", "mendeleev_no", "electrical_resistivity", "velocity_of_sound", "thermal_conductivity", "melting_point", "bulk_modulus", "coefficient_of_linear_thermal_expansion" ] else: raise ValueError("Invalid preset_name specified!") return ElementProperty(data_source, features, stats) def featurize(self, comp): """ Get elemental property attributes Args: comp: Pymatgen composition object Returns: all_attributes: Specified property statistics of features """ all_attributes = [] for attr in self.features: elem_data = self.data_source.get_property(comp, attr) for stat in self.stats: all_attributes.append(PropertyStats().calc_stat( elem_data, stat)) return all_attributes def feature_labels(self): labels = [] for attr in self.features: for stat in self.stats: labels.append("%s %s" % (stat, attr)) return labels def citations(self): if self.data_source == "magpie": citation = ( "@article{ward_agrawal_choudary_wolverton_2016, title={A general-purpose " "machine learning framework for predicting properties of inorganic materials}, " "volume={2}, DOI={10.1038/npjcompumats.2017.28}, number={1}, journal={npj " "Computational Materials}, author={Ward, Logan and Agrawal, Ankit and Choudhary, " "Alok and Wolverton, Christopher}, year={2016}}") elif self.data_source == "deml": citation = ( "@article{deml_ohayre_wolverton_stevanovic_2016, title={Predicting density " "functional theory total energies and enthalpies of formation of metal-nonmetal " "compounds by linear regression}, volume={47}, DOI={10.1002/chin.201644254}, " "number={44}, journal={ChemInform}, author={Deml, Ann M. and Ohayre, Ryan and " "Wolverton, Chris and Stevanovic, Vladan}, year={2016}}") elif self.data_source == "pymatgen": citation = ( "@article{Ong2013, author = {Ong, Shyue Ping and Richards, William Davidson and Jain, Anubhav and Hautier, " "Geoffroy and Kocher, Michael and Cholia, Shreyas and Gunter, Dan and Chevrier, Vincent L. and Persson, " "Kristin A. and Ceder, Gerbrand}, doi = {10.1016/j.commatsci.2012.10.028}, issn = {09270256}, " "journal = {Computational Materials Science}, month = {feb}, pages = {314--319}, " "publisher = {Elsevier B.V.}, title = {{Python Materials Genomics (pymatgen): A robust, open-source python " "library for materials analysis}}, url = {http://linkinghub.elsevier.com/retrieve/pii/S0927025612006295}, " "volume = {68}, year = {2013} } ") return citation def implementors(self): return ["Jiming Chen", "Logan Ward", "Anubhav Jain"]
def setUp(self): self.data_source = DemlData()