-
-
Save onepunchdan/4c1054d3d7a396d407d652f79db76b8f to your computer and use it in GitHub Desktop.
pbx_stable_entry.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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "pbx_stable_entry.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyMnKVMFA5XbpTq19FcwBSDs", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/onepunchdan/4c1054d3d7a396d407d652f79db76b8f/pbx_stable_entry.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NuJwmt4PmRUl", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 987 | |
}, | |
"outputId": "883141ff-b97b-48af-fe2e-6f18ed7313fe" | |
}, | |
"source": [ | |
"!pip install pymatgen" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Collecting pymatgen\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/01/82/5802c2a0014c57e9de11ab46718edf1f3f3d9e449c86f378819ec3dd540f/pymatgen-2020.3.2.tar.gz (2.6MB)\n", | |
"\u001b[K |████████████████████████████████| 2.6MB 5.0MB/s \n", | |
"\u001b[?25hRequirement already satisfied: numpy>=1.14.3 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.17.5)\n", | |
"Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from pymatgen) (2.21.0)\n", | |
"Collecting ruamel.yaml>=0.15.6\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/a6/92/59af3e38227b9cc14520bf1e59516d99ceca53e3b8448094248171e9432b/ruamel.yaml-0.16.10-py2.py3-none-any.whl (111kB)\n", | |
"\u001b[K |████████████████████████████████| 112kB 51.8MB/s \n", | |
"\u001b[?25hCollecting monty>=3.0.2\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/b1/a4/d57b127ad2103ebc1a21a9c6379abc10d5f57f5d92cac86532c15a43818f/monty-3.0.2-py3-none-any.whl (61kB)\n", | |
"\u001b[K |████████████████████████████████| 61kB 8.8MB/s \n", | |
"\u001b[?25hRequirement already satisfied: scipy>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.4.1)\n", | |
"Collecting pydispatcher>=2.0.5\n", | |
" Downloading https://files.pythonhosted.org/packages/cd/37/39aca520918ce1935bea9c356bcbb7ed7e52ad4e31bff9b943dfc8e7115b/PyDispatcher-2.0.5.tar.gz\n", | |
"Requirement already satisfied: tabulate in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.8.6)\n", | |
"Collecting spglib>=1.9.9.44\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/2c/95/a9da9b1c7f176347cd268c9d618535194d796f0e3d1c5566738bd2fe3dd9/spglib-1.14.1.post0-cp36-cp36m-manylinux2010_x86_64.whl (287kB)\n", | |
"\u001b[K |████████████████████████████████| 296kB 54.7MB/s \n", | |
"\u001b[?25hRequirement already satisfied: networkx>=2.2 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (2.4)\n", | |
"Requirement already satisfied: matplotlib>=1.5 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (3.1.3)\n", | |
"Requirement already satisfied: palettable>=3.1.1 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (3.3.0)\n", | |
"Requirement already satisfied: sympy in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.1.1)\n", | |
"Requirement already satisfied: pandas<1.0 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.25.3)\n", | |
"Requirement already satisfied: dataclasses>=0.6 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.7)\n", | |
"Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (3.0.4)\n", | |
"Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (1.24.3)\n", | |
"Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (2.8)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (2019.11.28)\n", | |
"Collecting ruamel.yaml.clib>=0.1.2; platform_python_implementation == \"CPython\" and python_version < \"3.9\"\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/53/77/4bcd63f362bcb6c8f4f06253c11f9772f64189bf08cf3f40c5ccbda9e561/ruamel.yaml.clib-0.2.0-cp36-cp36m-manylinux1_x86_64.whl (548kB)\n", | |
"\u001b[K |████████████████████████████████| 552kB 44.6MB/s \n", | |
"\u001b[?25hRequirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx>=2.2->pymatgen) (4.4.1)\n", | |
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (1.1.0)\n", | |
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (2.6.1)\n", | |
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (2.4.6)\n", | |
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (0.10.0)\n", | |
"Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.6/dist-packages (from sympy->pymatgen) (1.1.0)\n", | |
"Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas<1.0->pymatgen) (2018.9)\n", | |
"Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver>=1.0.1->matplotlib>=1.5->pymatgen) (45.2.0)\n", | |
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib>=1.5->pymatgen) (1.12.0)\n", | |
"Building wheels for collected packages: pymatgen, pydispatcher\n", | |
" Building wheel for pymatgen (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for pymatgen: filename=pymatgen-2020.3.2-cp36-cp36m-linux_x86_64.whl size=3482672 sha256=7ce135377de0f0ffc864686bdf240705d7be32411a9d0adff573fc7dc0cec16b\n", | |
" Stored in directory: /root/.cache/pip/wheels/ae/bd/ee/fc00e534c39ca4646bb87f17af30388cef5d6f23741f007aaf\n", | |
" Building wheel for pydispatcher (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for pydispatcher: filename=PyDispatcher-2.0.5-cp36-none-any.whl size=11515 sha256=473eda18c478214e4d3db10120aadecab891137ce3cc82c9940f2f64ebada56b\n", | |
" Stored in directory: /root/.cache/pip/wheels/88/99/96/cfef6665f9cb1522ee6757ae5955feedf2fe25f1737f91fa7f\n", | |
"Successfully built pymatgen pydispatcher\n", | |
"Installing collected packages: ruamel.yaml.clib, ruamel.yaml, monty, pydispatcher, spglib, pymatgen\n", | |
"Successfully installed monty-3.0.2 pydispatcher-2.0.5 pymatgen-2020.3.2 ruamel.yaml-0.16.10 ruamel.yaml.clib-0.2.0 spglib-1.14.1.post0\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RUMqFcmImhso", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"\n", | |
"from getpass import getpass\n", | |
"from pymatgen import MPRester, Composition\n", | |
"from pymatgen.analysis.pourbaix_diagram import PourbaixDiagram, PourbaixPlotter, MultiEntry\n", | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import matplotlib.pyplot as plt" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "0LOAai9PmiU7", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 36 | |
}, | |
"outputId": "36d8b68d-f59f-42bf-f7cf-37cc9b8b7d8b" | |
}, | |
"source": [ | |
"apikey = getpass()" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"··········\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "MIUYPdvUmlYx", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"r = MPRester(api_key=apikey)\n", | |
"\n", | |
"ids = [\"mp-504747\"]\n", | |
"\n", | |
"features = [\n", | |
" \"material_id\",\n", | |
" \"pretty_formula\",\n", | |
" \"unit_cell_formula\",\n", | |
" \"energy\",\n", | |
" \"energy_per_atom\",\n", | |
" \"nsites\",\n", | |
" \"elements\",\n", | |
" \"nelements\",\n", | |
" \"formation_energy_per_atom\",\n", | |
" \"e_above_hull\",\n", | |
" \"band_gap\",\n", | |
"]\n", | |
"\n", | |
"results = r.query(criteria={\"task_ids\": {\"$in\": ids}}, properties=features)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "FHZEArYcnXIW", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 226 | |
}, | |
"outputId": "3b5ad780-47ad-4af0-a8e5-96795d055c72" | |
}, | |
"source": [ | |
"results[0]" | |
], | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"{'band_gap': 0.0,\n", | |
" 'e_above_hull': 0.015648529230769093,\n", | |
" 'elements': ['Cu', 'O', 'V'],\n", | |
" 'energy': -82.61259564,\n", | |
" 'energy_per_atom': -6.354815049230769,\n", | |
" 'formation_energy_per_atom': -1.669922047692307,\n", | |
" 'material_id': 'mp-504747',\n", | |
" 'nelements': 3,\n", | |
" 'nsites': 13,\n", | |
" 'pretty_formula': 'V2Cu3O8',\n", | |
" 'unit_cell_formula': {'Cu': 3.0, 'O': 8.0, 'V': 2.0}}" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 8 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "w_aY_-tJm1Iw", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 36 | |
}, | |
"outputId": "1ba5d274-738b-483a-f798-32a867f4868a" | |
}, | |
"source": [ | |
"comp = Composition(results[0]['pretty_formula'])\n", | |
"anions = [\n", | |
" \"H\",\n", | |
" \"B\",\n", | |
" \"C\",\n", | |
" \"Si\",\n", | |
" \"N\",\n", | |
" \"P\",\n", | |
" \"As\",\n", | |
" \"Sb\",\n", | |
" \"O\",\n", | |
" \"S\",\n", | |
" \"Se\",\n", | |
" \"Te\",\n", | |
" \"F\",\n", | |
" \"Cl\",\n", | |
" \"Br\",\n", | |
" \"I\",\n", | |
"]\n", | |
"els = [k for k in comp.as_dict().keys() if k not in anions]\n", | |
"comps_in = (\n", | |
" np.array([comp.as_dict()[el] for el in els])\n", | |
" / np.array([comp.as_dict()[el] for el in els]).sum()\n", | |
")\n", | |
"chemsys = comp.to_data_dict[\"elements\"]\n", | |
"compdict = comp.fractional_composition.get_el_amt_dict()\n", | |
"pbx_entries = r.get_pourbaix_entries(chemsys)\n", | |
"ref_entries = [entry for entry in pbx_entries if entry.entry_id == results[0][\"material_id\"]]\n", | |
"ref_mentry = MultiEntry(ref_entries)\n", | |
"pbx_diagram = PourbaixDiagram(\n", | |
" pbx_entries,\n", | |
" comp_dict={k: v for k, v in compdict.items() if k not in [\"H\", \"O\"]},\n", | |
" filter_solids=True,\n", | |
")" | |
], | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"100%|██████████| 139/139 [00:00<00:00, 747.70it/s]\n" | |
], | |
"name": "stderr" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "eCsVQVqNob60", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"rheshe = lambda rhe, ph: rhe - 0.059 * ph" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "uWBUgJKYoeFp", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"stable = pbx_diagram.get_stable_entry(13, rheshe(1.5, 13))" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "QEsmD5MOopFc", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 36 | |
}, | |
"outputId": "a8c2a7fd-e666-48b2-ef8b-a2492eb76ab9" | |
}, | |
"source": [ | |
"stable.name" | |
], | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'VO4[-] + VO4[3-]'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 13 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "pPiJgBSVoprK", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 55 | |
}, | |
"outputId": "a68fe3c6-7b30-4990-e46e-b152e56302d9" | |
}, | |
"source": [ | |
"stable.entry_list" | |
], | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"[Pourbaix Entry : V1 O4 with energy = 0.6115, npH = -8.0, nPhi = -7.0, nH2O = 4.0, entry_id = ion-4 ,\n", | |
" Pourbaix Entry : V1 O4 with energy = 0.1351, npH = -8.0, nPhi = -5.0, nH2O = 4.0, entry_id = ion-3 ]" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 14 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "AzIgTBDzowGm", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Compare with materialsproject.org [pourbaix diagram](https://materialsproject.org/#apps/pourbaixdiagram/%7B%22chemsys%22%3A%5B%22Cu%22%2C%22V%22%5D%2C%22projel%22%3A%22%22%2C%22mp_id%22%3A%22mp-504747%22%7D) which shows VO4[-] + Cu2O3(s) at these conditions" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "CijR8bSMp7ld", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 36 | |
}, | |
"outputId": "6b0fcba3-9dd0-43e7-dbfa-c1631f363e2d" | |
}, | |
"source": [ | |
"ref_mentry.entry_list" | |
], | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"[Pourbaix Entry : O8 V2 Cu3 with energy = 0.4913, npH = -16.0, nPhi = -16.0, nH2O = 8.0, entry_id = mp-504747 ]" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 15 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Isp1t6mBp0QX", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 36 | |
}, | |
"outputId": "e5fd15cf-e36a-4e08-b7e4-5d77f764cf46" | |
}, | |
"source": [ | |
"pbx_diagram.get_decomposition_energy(ref_mentry, 13, rheshe(1.5, 13))" | |
], | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"2.102000956662368" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 16 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Eg1M6nQ2qINx", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"delta_Gpbx also ~0.7 eV/atom in this region according to online pourbaix diagram" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment