Exemplo n.º 1
0
from pymatviz import ptable_heatmap, spacegroup_hist
from tqdm import tqdm

# %%
tqdm.pandas()
(dielectric := load_dataset("matbench_dielectric"))

# %%
dielectric.hist(column="n", bins=50, log=True)
plt.savefig("dielectric-last-dos-peak-hist.pdf")

# %%
dielectric["volume"] = dielectric.structure.apply(lambda cryst: cryst.volume)
dielectric["formula"] = dielectric.structure.apply(lambda cryst: cryst.formula)

ptable_heatmap(dielectric.formula, log=True)
plt.title("Elemental prevalence in the Matbench dieletric dataset")
plt.savefig("dielectric-elements-log.pdf")

# %%
dielectric[["sg_symbol", "sg_number"]] = dielectric.progress_apply(
    lambda row: row.structure.get_space_group_info(),
    axis=1,
    result_type="expand")

dielectric["crystal_system"] = dielectric.structure.progress_apply(
    lambda struct: SpacegroupAnalyzer(struct).get_crystal_system())

dielectric[["sg_symbol", "sg_number", "crystal_system", "volume",
            "formula"]].to_csv("additional-df-cols.csv", index=False)
Exemplo n.º 2
0
https://hackingmaterials.lbl.gov/matminer/dataset_summary.html
"""


# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from pymatviz import ptable_heatmap


# %%
(boltztrap_mp := load_dataset("boltztrap_mp"))


# %%
ptable_heatmap(boltztrap_mp.formula, log=True)
plt.title("Elemental prevalence in the BoltzTraP MP dataset")
plt.savefig("boltztrap_mp-elements-log.pdf")


# %%
ptable_heatmap(boltztrap_mp.sort_values("pf_n").tail(100).formula)
plt.title("Elemental prevalence of top 100 n-type powerfactors in BoltzTraP MP dataset")
plt.savefig("boltztrap_mp-elements-top-100-nPF.pdf")


# %%
boltztrap_mp.hist(bins=50, log=True, layout=[2, 3], figsize=[18, 8])
plt.suptitle("BoltzTraP MP")
plt.savefig("boltztrap_mp-hists.pdf")
Exemplo n.º 3
0
from pymatviz import ptable_heatmap, spacegroup_hist
from tqdm import tqdm

# %%
tqdm.pandas()
(jdft2d := load_dataset("matbench_jdft2d"))

# %%
jdft2d.hist(column="exfoliation_en", bins=50, log=True)
plt.savefig("jdft2d-last-dos-peak-hist.pdf")

# %%
jdft2d["volume"] = jdft2d.structure.apply(lambda cryst: cryst.volume)
jdft2d["formula"] = jdft2d.structure.apply(lambda cryst: cryst.formula)

ptable_heatmap(jdft2d.formula, log=True)
plt.title("Elemental prevalence in the Matbench Jarvis DFT 2D dataset")
plt.savefig("jdft2d-elements-log.pdf")

# %%
jdft2d[["sg_symbol", "sg_number"]] = jdft2d.progress_apply(
    lambda row: row.structure.get_space_group_info(),
    axis=1,
    result_type="expand")

jdft2d["crystal_system"] = jdft2d.structure.progress_apply(
    lambda struct: SpacegroupAnalyzer(struct).get_crystal_system())

jdft2d[["sg_symbol", "sg_number", "crystal_system", "volume",
        "formula"]].to_csv("additional-df-cols.csv", index=False)
Exemplo n.º 4
0
range; remaining compositions were assigned values based on the closest experimental
value to the mean experimental value for that composition among all reports.

To get likely MP IDs for each chemical formula, see https://git.io/JmpVe:

Likely mp-ids were chosen from among computed materials in the MP database
(version 2021.03) that were 1) not marked 'theoretical', 2) had structures matching at
least one ICSD material, and 3) were within 200 meV of the DFT-computed stable energy
hull (e_above_hull < 0.2 eV). Among these candidates, we chose the mp-id with the lowest
e_above_hull.

https://ml.materialsproject.org/projects/matbench_expt_gap
"""

# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from pymatviz import ptable_heatmap

# %%
expt_gap = load_dataset("matbench_expt_gap")

# %%
expt_gap.hist(column="gap expt", bins=50, log=True)
plt.savefig("expt_gap_hist.pdf")

# %%
ptable_heatmap(expt_gap.composition, log=True)
plt.title("Elemental prevalence in the Matbench experimental band gap dataset")
plt.savefig("expt_gap-elements-log.pdf")
Exemplo n.º 5
0
"""

# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from pymatviz import ptable_heatmap

# %%
mp_gap = load_dataset("matbench_mp_gap")

# %%
mp_gap.hist(column="gap pbe", bins=50, log=True)
plt.xlabel("eV")
plt.savefig("pbe_gap_hist.pdf")

# %%
mp_gap["volume/atom"] = mp_gap.structure.apply(
    lambda cryst: cryst.volume / cryst.num_sites)
mp_gap["num_sites"] = mp_gap.structure.apply(lambda cryst: cryst.num_sites)

mp_gap["formula"] = mp_gap.structure.apply(lambda cryst: cryst.formula)

# %%
ptable_heatmap(mp_gap.formula, log=True)
plt.title("Elemental prevalence in the Matbench MP band gap dataset")
plt.savefig("mp_gap-elements-log.pdf")

# %%
mp_gap.hist(column="volume/atom", bins=50, log=True)
plt.savefig("volume_per_atom_hist.pdf")
Exemplo n.º 6
0
Extensive column descriptions and metadata at
https://hackingmaterials.lbl.gov/matminer/dataset_summary.html#ricci-boltztrap-mp-tabular.
"""

# %%
import matplotlib.pyplot as plt
import pandas as pd
from matminer.datasets import load_dataset
from pymatviz import ptable_heatmap, spacegroup_hist

# %%
carrier_transport = load_dataset("ricci_boltztrap_mp_tabular")

# %%
ptable_heatmap(carrier_transport.pretty_formula.dropna(), log=True)
plt.title("Elemental prevalence in the Ricci Carrier Transport dataset")
plt.savefig("carrier-transport-elements-log.pdf")

# %%
carrier_transport.hist(bins=50, log=True, figsize=[30, 16])
plt.tight_layout()
plt.suptitle("Ricci Carrier Transport Dataset", y=1.05)
plt.savefig("carrier-transport-hists.pdf")

# %%
carrier_transport[["S.p [µV/K]", "S.n [µV/K]"]].hist(bins=50,
                                                     log=True,
                                                     figsize=[18, 8])
plt.suptitle(
    "Ricci Carrier Transport dataset histograms for n- and p-type Seebeck coefficients"
Exemplo n.º 7
0
"""Stats for the matbench_steels dataset.

Input: Chemical formula.
Target variable: Experimentally measured steel yield strengths in MPa.
Entries: 312

https://ml.materialsproject.org/projects/matbench_steels
"""

# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from pymatviz import ptable_heatmap

# %%
steels = load_dataset("matbench_steels")

# %%
steels.hist(column="yield strength", bins=50)
plt.savefig("steels-yield-strength-hist.pdf")

# %%
ptable_heatmap(steels.composition, log=True)
plt.title("Elemental prevalence in the Matbench steels dataset")
plt.savefig("steels-elements-log.pdf")
Exemplo n.º 8
0
tqdm.pandas()

# %%
tqdm.pandas()
phonons = load_dataset("matbench_phonons")

# %%
phonons.hist(column="last phdos peak", bins=50)
plt.savefig("phonons-last-dos-peak-hist.pdf")

# %%
phonons["formula"] = phonons.structure.apply(lambda cryst: cryst.formula)
phonons["volume"] = phonons.structure.apply(lambda cryst: cryst.volume)

ptable_heatmap(phonons.formula, log=True)
plt.title("Elemental prevalence in the Matbench phonons dataset")
plt.savefig("phonons-elements-log.pdf")

# %%
mpr = MPRester()
phonons["likely_mp_ids"] = phonons.structure.progress_apply(mpr.find_structure)

# %%
ax = phonons.likely_mp_ids.apply(len).value_counts().plot(kind="bar", log=True)
annotate_bar_heights()
plt.savefig("likely_mp_ids_lens.png", dpi=200)


# %% where there are several mp_ids, pick the one with lowest energy above convex hull
def get_e_above_hull(mp_id: str) -> float:
Exemplo n.º 9
0
formation energy more than 3.0eV and those containing noble gases.
Retrieved April 2, 2019.

https://ml.materialsproject.org/projects/matbench_mp_e_form
"""


# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from pymatviz import ptable_heatmap


# %%
mp_e_form = load_dataset("matbench_mp_e_form")


# %%
mp_e_form.hist(column="e_form", bins=50, log=True)
plt.savefig("mp_e_form_hist.pdf")


# %%
mp_e_form["formula"] = mp_e_form.structure.apply(lambda struct: struct.formula)


# %%
ptable_heatmap(mp_e_form.formula, log=True)
plt.title("Elemental prevalence in the Matbench formation energy dataset")
plt.savefig("mp_e_form-elements-log.pdf")
Exemplo n.º 10
0
# %%
structure.make_supercell([2, 2, 2])
view = nv.show_pymatgen(structure)
view.add_unitcell()
structure.get_primitive_structure()
view

# %%
log_gvrh["volume"] = log_gvrh.structure.apply(lambda struct: struct.volume)

log_gvrh.hist(column="volume", bins=50, log=True)

# %%
log_gvrh["formula"] = log_gvrh.structure.apply(lambda struct: struct.formula)

ptable_heatmap(log_gvrh.formula, log=True)
plt.title("Elemental prevalence in the Matbench bulk/shear modulus datasets")
plt.savefig("log_gvrh-elements-log.pdf")

# %% getting space group symbols and numbers for 10,987 structures takes about 4 min
print("getting spacegroups for log_gvrh")
log_gvrh[["sg_symbol", "sg_number"]] = log_gvrh.progress_apply(
    lambda row: row.structure.get_space_group_info(),
    axis=1,
    result_type="expand")

print("getting crystal systems for log_gvrh")
log_gvrh["crystal_system"] = log_gvrh.structure.progress_apply(
    lambda struct: SpacegroupAnalyzer(struct).get_crystal_system())

log_gvrh[["sg_symbol", "sg_number", "crystal_system", "volume",
Exemplo n.º 11
0
def test_ptable_heatmap(glasses, glass_elem_counts, df_ptable):
    ax = ptable_heatmap(glasses)
    assert isinstance(ax, Axes)

    ptable_heatmap(glasses, log=True)

    # custom color map
    ptable_heatmap(glasses, log=True, cmap="summer")

    # heat_labels normalized to total count
    ptable_heatmap(glasses, heat_labels="fraction")
    ptable_heatmap(glasses, heat_labels="percent")

    # without heatmap values
    ptable_heatmap(glasses, heat_labels=None)
    ptable_heatmap(glasses, log=True, heat_labels=None)

    # element properties as heatmap values
    ptable_heatmap(df_ptable.atomic_mass)

    # element properties as heatmap values
    ptable_heatmap(df_ptable.atomic_mass, text_color=("red", "blue"))

    # custom max color bar value
    ptable_heatmap(glasses, cbar_max=1e2)
    ptable_heatmap(glasses, log=True, cbar_max=1e2)

    # element counts
    ptable_heatmap(glass_elem_counts)

    with pytest.raises(ValueError) as exc_info:
        ptable_heatmap(glasses, log=True, heat_labels="percent")

    assert exc_info.type is ValueError
    assert "Combining log color scale" in exc_info.value.args[0]
Exemplo n.º 12
0
from pymatviz import annotate_bar_heights, ptable_heatmap, spacegroup_hist
from tqdm import tqdm

# %%
tqdm.pandas()
perovskites = load_dataset("matbench_perovskites")

# %%
perovskites.hist(column="e_form", bins=50)
plt.savefig("perovskites-e_form-hist.pdf")

# %%
perovskites["formula"] = perovskites.structure.apply(
    lambda cryst: cryst.formula)

ptable_heatmap(perovskites.formula, log=True)
plt.title("Elemental prevalence in the Matbench perovskites dataset")
plt.savefig("perovskites-elements-log.pdf")

# %%
perovskites["volume"] = perovskites.structure.apply(
    lambda struct: struct.volume)

perovskites.hist(column="volume", bins=50, log=True)

# %%
mpr = MPRester()
perovskites["likely_mp_ids"] = perovskites.structure.progress_apply(
    mpr.find_structure)

# %%