-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
255 additions
and
0 deletions.
There are no files selected for viewing
255 changes: 255 additions & 0 deletions
255
mpcontribs-portal/notebooks/contribs.materialsproject.org/ForbiddenTransitions.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9c8832b8-74a3-440f-88ac-dc47e94519c3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"\n", | ||
"from mpcontribs.client import Client\n", | ||
"from pathlib import Path\n", | ||
"from monty.serialization import loadfn\n", | ||
"from flatten_dict import unflatten\n", | ||
"from math import isnan" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7289934b-ce05-4856-95e6-6a67f1d4dd82", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"data_dir = Path(\"/Users/patrick/GoogleDriveLBNL/My Drive/MaterialsProject/gitrepos/mpcontribs-data/ForbiddenTransitions\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3c85f007-0634-4cad-ae86-f4c897545a42", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df_path = data_dir / \"2022_Woods-Robinson_properties-df_mpcontribs\"\n", | ||
"df = pd.read_pickle(df_path)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c584d2d4-1ec3-4e00-9ea2-b3b0af4beb1b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ba0a3ffb-d992-4346-8efc-9bb197910ef3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"columns_map = {\n", | ||
" # root level\n", | ||
" \"Materials Project ID (mpid)\": {\"name\": \"identifier\", \"description\": \"Materials Project ID as of May 30, 2023\"},\n", | ||
" \"Formula\": {\"name\": \"formula\", \"description\": \"Chemical formula (from pretty_formula on MP)\"},\n", | ||
" # info\n", | ||
" \"Space group\": {\"name\": \"info.spacegroup\", \"description\": \"Space group symbol from MP\"},\n", | ||
" \"# ICSD entries\": {\"name\": \"info.numICSDs\", \"unit\": \"\", \"description\": \"Number of ICSD entries that structure-match to this compound (queried from the Materials Project)\"},\n", | ||
" \"Calculation origin\": {\"name\": \"info.origin\", \"description\": \"The source of the calculation; note that some of these calculations derive from Fabini et al. 2019 (10.1021/acs.chemmater.8b04542) and the associated MPContribs data set)\"},\n", | ||
" # chemical properties\n", | ||
" \"$t_\\mathrm{IPR}^\\mathrm{d}$\": {\"name\": \"properties.chemical.IPR\", \"description\": \"Inverse participation ratio of the direct VBM and CBM states, used as a proxy for localization of states at the band edges (a high IPR indicates strong localization), as defined by Wegner in 1980 (10.1007/BF01325284) and implemented by Xiong, et al. in 2023 (10.1126/sciadv.adh8617) (see manuscript for details)\"},\n", | ||
" \"$σ^\\mathrm{d}$\": {\"name\": \"properties.chemical.sigma\", \"unit\": \"\", \"description\": \"Orbital similarity of the direct VBM and CBM states, derived from the dominant contributors to the density of states at the direct VBM and CBM to describe the similarity of CB-edge and VB-edge orbital contributions (see manuscript for details)\"},\n", | ||
" # other properties\n", | ||
" \"$E_\\mathrm{hull}$ (eV/at.)\": {\"name\": \"properties.other.hull\", \"unit\": \"eV/atom\", \"description\": \"Energy above the convex hull, computed using GGA (or GGA+U when appropriate) and MP compatability scheme\"},\n", | ||
" \"Synthesized?\": {\"name\": \"properties.other.synthesized\", \"description\": \"Whether a given compound has been synthesized in any form (queried from the Materials Project)\"},\n", | ||
" # optical properties\n", | ||
" \"$E_\\mathrm{G}^\\mathrm{GGA}$ (eV)\": {\"name\": \"properties.optical.bandgaps.GGA\", \"unit\": \"eV\", \"description\": \"Fundamental band gap computed using GGA (or GGA+U when appropriate)\"},\n", | ||
" \"$E_\\mathrm{G}^\\mathrm{d,GGA}$ (eV)\": {\"name\": \"properties.optical.bandgaps.GGA|d\", \"unit\": \"eV\", \"description\": \"Direct band gap computed using GGA (or GGA+U when appropriate)\"},\n", | ||
" \"$E_\\mathrm{G}^\\mathrm{da,GGA}$ (eV)\": {\"name\": \"properties.optical.bandgaps.GGA|da\", \"unit\": \"eV\", \"description\": \"Direct allowed band gap computed using GGA (or GGA+U when appropriate), defined as the energy at which dipole transition matrix elements become significant (see manuscript for details)\"},\n", | ||
" \"$E_\\mathrm{edge}^\\mathrm{da,GGA}$ (eV)\": {\"name\": \"properties.optical.energy|edge.GGA|da\", \"unit\": \"eV\", \"description\": \"Absorption edge energy, defined as the approximate energy at which the absorption coefficient rises to 1e4 cm-1 and becomes significant (see manuscript for details)\"},\n", | ||
" \"$Δ^\\mathrm{d,GGA}$\": {\"name\": \"properties.optical.delta.GGA|d\", \"unit\": \"\", \"description\": \"Forbidden energy difference, defined as the energy difference between the direct band gap and direct allowed band gap, such that a value greater than zero indicates the presence of forbidden or weak transitions\"},\n", | ||
" \"$Δ_\\mathrm{edge}^\\mathrm{d,GGA}$\": {\"name\": \"properties.optical.delta|edge.GGA|d\", \"unit\": \"\", \"description\": \"Edge energy difference, defined as defined as the energy difference between the direct band gap and the absorption edge energy\"},\n", | ||
" \"$α_\\mathrm{avg.vis}^\\mathrm{GGA}$ (cm$^{-1}$)\": {\"name\": \"properties.optical.alpha|vis\", \"unit\": \"cm⁻¹\", \"description\": \"Average GGA absorption coefficient in the visible regime, using an empirical gap correction from Morales et al. 2017 (10.1021/acs.jpcc.7b07421) (see manuscript for details; caution that this should be recalculated if using a scissor shift!)\"},\n", | ||
" \"Optical type\": {\"name\": \"properties.optical.type\", \"description\": \"Optical type categorization (OT 1\\u20134), following the classification outlined by Yu and Zunger in 2012 (10.1103/PhysRevLett.108.068701)\"},\n", | ||
" # transport properties\n", | ||
" \"$m^*_\\mathrm{e}$\": {\"name\": \"properties.transport.effmass.electron\", \"unit\": \"mₑ\", \"description\": \"Electron effective mass, computed using the BoltzTraP2 package assuming dopings of 10^18 cm-3 (see manuscript for details)\"},\n", | ||
" \"$m^*_\\mathrm{h}$\": {\"name\": \"properties.transport.effmass.hole\", \"unit\": \"mₑ\", \"description\": \"Hole effective mass, computed using the BoltzTraP2 package assuming dopings of 10^18 cm-3 (see manuscript for details)\"},\n", | ||
"}\n", | ||
"\n", | ||
"legend = {v[\"name\"]: v[\"description\"] for v in columns_map.values()}\n", | ||
"legend[\"tables.corrected\"] = \"Absorption coefficient computed with the IPA and a GGA functional, using the empirical gap correction from Morales et al. 2017 (10.1021/acs.jpcc.7b07421) (see manuscript for details)\"\n", | ||
"legend[\"tables.uncorrected\"] = \"Absorption coefficient computed with the IPA and a GGA functional (without any empirical gap correction as in alpha; see manuscript for details)\"\n", | ||
"\n", | ||
"columns = {v[\"name\"]: v.get(\"unit\") for v in columns_map.values() if v[\"name\"] not in [\"identifier\", \"formula\"]}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c6c64a6b-287f-4798-acfd-bf0ddffea5cf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spectra = loadfn(data_dir / \"2022_Woods-Robinson_absorption-coeff_mpcontribs.json.gz\")\n", | ||
"len(spectra)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d4e6c4d4-c682-4633-bec2-f5ee0f7dfb59", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"contributions = []\n", | ||
"\n", | ||
"for record in df.to_dict(\"records\"):\n", | ||
" clean = {}\n", | ||
" for k, v in record.items():\n", | ||
" if not isinstance(v, str) and isnan(v):\n", | ||
" continue\n", | ||
" \n", | ||
" key = columns_map[k][\"name\"]\n", | ||
" unit = columns_map[k].get(\"unit\")\n", | ||
" val = v\n", | ||
" if isinstance(v, bool):\n", | ||
" val = \"Yes\" if v else \"No\"\n", | ||
" elif unit:\n", | ||
" val = f\"{v} {unit}\"\n", | ||
" \n", | ||
" clean[key] = val\n", | ||
"\n", | ||
" contrib = {\"identifier\": clean.pop(\"identifier\"), \"formula\": clean.pop(\"formula\"), \"tables\": []}\n", | ||
" contrib[\"data\"] = unflatten(clean, splitter=\"dot\")\n", | ||
"\n", | ||
" spectrum = spectra.get(contrib[\"identifier\"])\n", | ||
" if spectrum:\n", | ||
" spectrum.pop(\"mpid\", None)\n", | ||
" spectrum.pop(\"formula\", None)\n", | ||
" table = pd.DataFrame(data=spectrum).rename(\n", | ||
" columns={\"energy\": \"energy [eV]\", \"alpha\": \"α\", \"alpha_uncorr\": \"α|uncorrected\"}\n", | ||
" ).set_index(\"energy [eV]\")\n", | ||
" table.attrs = {\n", | ||
" \"name\": \"absorption coefficients\",\n", | ||
" \"title\": \"Energy-dependent Absorption Coefficients\",\n", | ||
" \"labels\": {\n", | ||
" \"value\": \"absorption coefficient [cm⁻¹]\",\n", | ||
" \"variable\": \"method\"\n", | ||
" }\n", | ||
" }\n", | ||
" contrib[\"tables\"].append(table)\n", | ||
" \n", | ||
" contributions.append(contrib)\n", | ||
"\n", | ||
"len(contributions)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0a0d2ea1-17d1-47ed-aa83-0c4c7f2360ea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"client = Client(project=\"ForbiddenTransitions\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "328f710b-5bf3-4190-817b-2a74c71222a9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# client.update_project({\"other\": legend})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cda277f3-5843-4947-a765-1bda29216432", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# client.delete_contributions()\n", | ||
"# client.init_columns(columns)\n", | ||
"client.submit_contributions(contributions[150:1000])\n", | ||
"client.init_columns(columns)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "126468dd-daac-422a-a90d-06bc86261c36", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"client.available_query_params(startswith=\"data__properties__optical\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "42dbb834-9dcb-4d79-9060-9eb47c63b621", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"query = {\n", | ||
" \"data__properties__other__synthesized__exact\": \"Yes\",\n", | ||
" \"data__properties__optical__type__contains\": \"ia\",\n", | ||
" \"data__properties__optical__bandgaps__GGA__value__gt\": 3\n", | ||
"}\n", | ||
"client.count(query=query)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7d2bc022-6620-4e0d-a9e2-f9199d8c1169", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"contribs = client.query_contributions(query=query, fields=[\"identifier\", \"data.properties.other\"], paginate=True)\n", | ||
"contribs[\"data\"][0][\"data\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ad41806b-e44e-4f69-aacf-170edd9c7f00", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"contribs = client.download_contributions(query=query, include=[\"tables\"])\n", | ||
"contribs[0][\"tables\"][0] # DataFrame" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |