matminer.utils package

Submodules

matminer.utils.caching module

Provides utility functions for caching the results of expensive operations, such as determining the nearest neighbors of atoms in a structure

matminer.utils.caching.get_all_nearest_neighbors(method, structure)

Get the nearest neighbor list of a structure

Args:
method (NearNeighbor) - Method used to compute nearest neighbors structure (IStructure) - Structure to study
Returns:
Output of method.get_all_nn_info(structure)
matminer.utils.caching.get_nearest_neighbors(method, structure, site_idx)

Get the nearest neighbor list of a particular site in a structure

Args:
method (NearNeighbor) - Method used to compute nearest neighbors structure (Structure) - Structure to study site_idx (int) - Index of site to study
Returns:
Output of method.get_nn_info(structure, site_idx)

matminer.utils.conversions module

matminer.utils.data module

class matminer.utils.data.AbstractData

Bases: object

Abstract class for retrieving elemental properties

All classes must implement the get_elemental_property operation. These operations should return scalar values (ideally floats) and nan if a property does not exist

get_elemental_properties(elems, property_name)

Get elemental properties for a list of elements

Args:
elems - ([Element]) list of elements property_name - (str) property to be retrieved
Returns:
[float], properties of elements
get_elemental_property(elem, property_name)

Get a certain elemental property for a certain element.

Args:
elem - (Element) element to be assessed property_name - (str) property to be retreived
Returns:
float, property of that element
class matminer.utils.data.CohesiveEnergyData

Bases: matminer.utils.data.AbstractData

Get the cohesive energy of an element.

Data is extracted from KnowledgeDoor Cohesive Energy Handbook online (http://www.knowledgedoor.com/2/elements_handbook/cohesive_energy.html), which in turn got the data from Introduction to Solid State Physics, 8th Edition, by Charles Kittel (ISBN 978-0-471-41526-8), 2005.

__init__()

Initialize self. See help(type(self)) for accurate signature.

get_elemental_property(elem, property_name='cohesive energy')
Args:
elem: (Element) Element of interest property_name (str): unused, always returns cohesive energy
Returns:
(float): cohesive energy of the element
class matminer.utils.data.DemlData

Bases: matminer.utils.data.OxidationStateDependentData, matminer.utils.data.OxidationStatesMixin

Class to get data from Deml data file. See also: A.M. Deml, R. O’Hayre, C. Wolverton, V. Stevanovic, Predicting density functional theory total energies and enthalpies of formation of metal-nonmetal compounds by linear regression, Phys. Rev. B - Condens. Matter Mater. Phys. 93 (2016).

__init__()

Initialize self. See help(type(self)) for accurate signature.

get_charge_dependent_property(element, charge, property_name)

Retrieve a oxidation-state dependent elemental property

Args:
element - (Element), Target element charge - (int), Oxidation state property_name - (string), name of property
Return:
(float) - Value of property
get_elemental_property(elem, property_name)

Get a certain elemental property for a certain element.

Args:
elem - (Element) element to be assessed property_name - (str) property to be retreived
Returns:
float, property of that element
get_oxidation_states(elem)

Retrieve the possible oxidation states of an element

Args:
elem - (Element), Target element
Returns:
[int] - oxidation states
class matminer.utils.data.MagpieData

Bases: matminer.utils.data.AbstractData, matminer.utils.data.OxidationStatesMixin

Class to get data from Magpie files. See also: L. Ward, A. Agrawal, A. Choudhary, C. Wolverton, A general-purpose machine learning framework for predicting properties of inorganic materials, Npj Comput. Mater. 2 (2016) 16028.

__init__()

Initialize self. See help(type(self)) for accurate signature.

get_elemental_property(elem, property_name)

Get a certain elemental property for a certain element.

Args:
elem - (Element) element to be assessed property_name - (str) property to be retreived
Returns:
float, property of that element
get_oxidation_states(elem)

Retrieve the possible oxidation states of an element

Args:
elem - (Element), Target element
Returns:
[int] - oxidation states
class matminer.utils.data.MixingEnthalpy

Bases: object

Values of \Delta H^{max}_{AB} for different pairs of elements.

Based on the Miedema model. Tabulated by:
A. Takeuchi, A. Inoue, Classification of Bulk Metallic Glasses by Atomic Size Difference, Heat of Mixing and Period of Constituent Elements and Its Application to Characterization of the Main Alloying Element. Mater. Trans. 46, 2817–2829 (2005).
__init__()

Initialize self. See help(type(self)) for accurate signature.

get_mixing_enthalpy(elemA, elemB)

Get the mixing enthalpy between different elements

Args:
elemA (Element): An element elemB (Element): Second element
Returns:
(float) mixing enthalpy, nan if pair is not in a table
class matminer.utils.data.OxidationStateDependentData

Bases: matminer.utils.data.AbstractData

Abstract class that also includes oxidation-state-dependent properties

get_charge_dependent_property(element, charge, property_name)

Retrieve a oxidation-state dependent elemental property

Args:
element - (Element), Target element charge - (int), Oxidation state property_name - (string), name of property
Return:
(float) - Value of property
get_charge_dependent_property_from_specie(specie, property_name)

Retrieve a oxidation-state dependent elemental property

Args:
specie - (Specie), Specie of interest property_name - (string), name of property
Return:
(float) - Value of property
class matminer.utils.data.OxidationStatesMixin

Bases: object

Abstract class interface for retrieving the oxidation states of each element

get_oxidation_states(elem)

Retrieve the possible oxidation states of an element

Args:
elem - (Element), Target element
Returns:
[int] - oxidation states
class matminer.utils.data.PymatgenData(use_common_oxi_states=True)

Bases: matminer.utils.data.OxidationStateDependentData, matminer.utils.data.OxidationStatesMixin

Class to get data from pymatgen. See also: S.P. Ong, W.D. Richards, A. Jain, G. Hautier, M. Kocher, S. Cholia, et al., Python Materials Genomics (pymatgen): A robust, open-source python library for materials analysis, Comput. Mater. Sci. 68 (2013) 314-319.

__init__(use_common_oxi_states=True)

Initialize self. See help(type(self)) for accurate signature.

get_charge_dependent_property(element, charge, property_name)

Retrieve a oxidation-state dependent elemental property

Args:
element - (Element), Target element charge - (int), Oxidation state property_name - (string), name of property
Return:
(float) - Value of property
get_elemental_property(elem, property_name)

Get a certain elemental property for a certain element.

Args:
elem - (Element) element to be assessed property_name - (str) property to be retreived
Returns:
float, property of that element
get_oxidation_states(elem)

Get the oxidation states of an element

Args:

elem - (Element) target element common - (boolean), whether to return only the common oxidation states,

or all known oxidation states
Returns:
[int] list of oxidation states

matminer.utils.flatten_dict module

matminer.utils.flatten_dict.flatten_dict(nested_dict, lead_key=None, unwind_arrays=True)

Helper function to flatten nested dictionary, recursively walks through nested dictionary to get keys corresponding to dot-notation keys, e. g. converts {“a”: {“b”: 1, “c”: 2}} to {“a.b”: 1, “a.c”: 2}

Args:

nested_dict ({}): nested dictionary to flatten unwind_arrays (bool): whether to flatten lists/tuples

with numerically indexed dot notation, defaults to True
lead_key (str): string to append to front of all keys,
used primarily for recursion
Returns:
non-nested dictionary

matminer.utils.io module

This module defines functions for writing and reading matminer related objects

matminer.utils.io.load_dataframe_from_json(filename)

Load pandas dataframe from a json file.

Automatically decodes and instantiates pymatgen objects in the dataframe.

Args:
filename (str): Path to json file. Can be a compressed file (gz and bz2)
are supported.
Returns:
(Pandas.DataFrame): A pandas dataframe.
matminer.utils.io.store_dataframe_as_json(dataframe, filename, compression=None, orient='split')

Store pandas dataframe as a json file.

Automatically encodes pymatgen objects as dictionaries.

Args:

dataframe (Pandas.Dataframe): A pandas dataframe. filename (str): Path to json file. compression (str or None): A compression mode. Valid options are “gz”,

“bz2”, and None. Defaults to None. If the filename does not end in with the correct suffix it will be added automatically.
orient (str): Determines the format in which the dictionary data is
stored. This takes the same set of arguments as the orient option in pandas.DataFrame.to_dict() function. ‘split’ is recommended as it is relatively space efficient and preserves the dtype of the index.

matminer.utils.kernels module

matminer.utils.kernels.gaussian_kernel

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C:

@staticmethod def f(arg1, arg2, …):

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

matminer.utils.kernels.laplacian_kernel

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C:

@staticmethod def f(arg1, arg2, …):

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

matminer.utils.pipeline module

class matminer.utils.pipeline.DropExcluded(excluded)

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

Transformer for removing unwanted columns from a dataframe. Passes back the remaining columns.

Helper class for making sklearn pipelines with matminer.

Args:
excluded (list of labels): A list of column labels to drop from the dataframe
__init__(excluded)

Initialize self. See help(type(self)) for accurate signature.

fit(x, y=None)
transform(df)
class matminer.utils.pipeline.ItemSelector(label)

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

A utility for extracting a column from a DataFrame in a sklearn pipeline, for example in a FeatureUnion pipeline to featurize a dataset.

Helper class for making sklearn pipelines with matminer.

See (http://scikit-learn.org/stable/auto_examples/hetero_feature_union.html)

Args:
label : The label of the column to select.
__init__(label)

Initialize self. See help(type(self)) for accurate signature.

fit(x, y=None)
transform(dataframe)

matminer.utils.utils module

matminer.utils.utils.homogenize_multiindex(df, default_key, coerce=False)

Homogenizes a dataframe column index to a 2-level multiindex.

Args:

df (pandas DataFrame): A dataframe default_key (str): The key to use when a single Index must be converted

to a 2-level index. This key is then used as a parent of all keys present in the original 1-level index.
coerce (bool): If True, try to force a 2+ level multiindex to a 2-level
multiindex.
Returns:
df (pandas DataFrame): A dataframe with a 2-layer multiindex.
matminer.utils.utils.is_notebook()

Check if python is running in an interactive notebook.

Adapted from: https://stackoverflow.com/questions/47211324/check-if-module-is-running-in-jupyter-or-not

Module contents