Skip to content

Commit

Permalink
cleanup plotting module
Browse files Browse the repository at this point in the history
  • Loading branch information
ireaml committed Dec 25, 2023
1 parent 45ef3be commit b54e322
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 171 deletions.
3 changes: 3 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
[ ] Tests
1. Check coverage of main functions

[ ] Code
* Cleanup plotting module. The function `plot_active_plane` is limited to only specific planes.

[ ] Tutorials
* Add tutorial for all main functions (currently missing `plot_variation_along_vector`, `plot_on_site_potential`)
62 changes: 31 additions & 31 deletions docs/tutorials/Porous/Porous.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,6 @@
"6. Sample the potential from the pore centre"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_7455/391802285.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses\n",
" import imp\n"
]
}
],
"source": [
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import sys\n",
"sys.path.append('../../')\n",
"import imp\n",
"import macrodensity as md\n",
"import math\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import os"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -122,7 +93,36 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import sys\n",
"sys.path.append('../../')\n",
"import imp\n",
"import macrodensity as md\n",
"import math\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand All @@ -142,7 +142,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand Down
88 changes: 88 additions & 0 deletions docs/tutorials/Slab/Bi2O3_slab.POSCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Bi32 O48
1.0
5.8547529999999997 0.0000000000000000 0.0000000000000000
0.0000000000000000 8.0749659999999999 0.0000000000000000
-18.2721760000000017 0.0000000000000000 41.1248829999999970
Bi O
32 48
direct
0.6534340000000000 0.6880890000000000 0.0220230000000000 Bi
0.2644550000000000 0.9555830000000000 0.0373360000000000 Bi
0.2355450000000000 0.4555830000000000 0.0459980000000000 Bi
0.8465660000000000 0.1880890000000000 0.0613100000000000 Bi
0.1534340000000000 0.8119110000000000 0.1053560000000000 Bi
0.7644550000000000 0.5444170000000000 0.1206690000000000 Bi
0.7355450000000000 0.0444170000000000 0.1293310000000000 Bi
0.3465660000000000 0.3119110000000000 0.1446440000000000 Bi
0.6534340000000000 0.6880890000000000 0.1886900000000000 Bi
0.2644550000000000 0.9555830000000000 0.2040020000000000 Bi
0.2355450000000000 0.4555830000000000 0.2126640000000000 Bi
0.8465660000000000 0.1880890000000000 0.2279770000000000 Bi
0.1534340000000000 0.8119110000000000 0.2720230000000000 Bi
0.7644550000000000 0.5444170000000000 0.2873360000000000 Bi
0.7355450000000000 0.0444170000000000 0.2959980000000000 Bi
0.3465660000000000 0.3119110000000000 0.3113100000000000 Bi
0.6534340000000000 0.6880890000000000 0.6886900000000000 Bi
0.2644550000000000 0.9555830000000000 0.7040020000000000 Bi
0.2355450000000000 0.4555830000000000 0.7126640000000000 Bi
0.8465660000000000 0.1880890000000000 0.7279770000000000 Bi
0.1534340000000000 0.8119110000000000 0.7720230000000000 Bi
0.7644550000000000 0.5444170000000000 0.7873360000000000 Bi
0.7355450000000000 0.0444170000000000 0.7959980000000000 Bi
0.3465660000000000 0.3119110000000000 0.8113100000000000 Bi
0.6534340000000000 0.6880890000000000 0.8553560000000000 Bi
0.2644550000000000 0.9555830000000000 0.8706690000000000 Bi
0.2355450000000000 0.4555830000000000 0.8793310000000000 Bi
0.8465660000000000 0.1880890000000000 0.8946440000000000 Bi
0.1534340000000000 0.8119110000000000 0.9386900000000000 Bi
0.7644550000000000 0.5444170000000000 0.9540020000000000 Bi
0.7355450000000000 0.0444170000000000 0.9626640000000000 Bi
0.3465660000000000 0.3119110000000000 0.9779770000000000 Bi
0.7429070000000000 0.4672280000000000 0.0022820000000000 O
0.8878110000000000 0.0512400000000000 0.0205840000000000 O
0.4298160000000000 0.2047000000000000 0.0345480000000000 O
0.0701840000000000 0.7047000000000000 0.0487850000000000 O
0.6121890000000000 0.5512400000000000 0.0627490000000000 O
0.7570930000000000 0.9672280000000000 0.0810510000000000 O
0.2429070000000000 0.0327720000000000 0.0856160000000000 O
0.3878110000000000 0.4487600000000000 0.1039170000000000 O
0.9298160000000000 0.2953000000000000 0.1178810000000000 O
0.5701840000000000 0.7953000000000000 0.1321190000000000 O
0.1121890000000000 0.9487600000000000 0.1460830000000000 O
0.2570930000000000 0.5327720000000000 0.1643840000000000 O
0.7429070000000000 0.4672280000000000 0.1689490000000000 O
0.8878110000000000 0.0512400000000000 0.1872510000000000 O
0.4298160000000000 0.2047000000000000 0.2012150000000000 O
0.0701840000000000 0.7047000000000000 0.2154520000000000 O
0.6121890000000000 0.5512400000000000 0.2294160000000000 O
0.7570930000000000 0.9672280000000000 0.2477180000000000 O
0.2429070000000000 0.0327720000000000 0.2522820000000000 O
0.3878110000000000 0.4487600000000000 0.2705840000000000 O
0.9298160000000000 0.2953000000000000 0.2845480000000000 O
0.5701840000000000 0.7953000000000000 0.2987850000000000 O
0.1121890000000000 0.9487600000000000 0.3127490000000000 O
0.2570930000000000 0.5327720000000000 0.3310510000000000 O
0.7429070000000000 0.4672280000000000 0.6689490000000000 O
0.8878110000000000 0.0512400000000000 0.6872509999999999 O
0.4298160000000000 0.2047000000000000 0.7012150000000000 O
0.0701840000000000 0.7047000000000000 0.7154520000000000 O
0.6121890000000000 0.5512400000000000 0.7294160000000000 O
0.7570930000000000 0.9672280000000000 0.7477180000000000 O
0.2429070000000000 0.0327720000000000 0.7522820000000000 O
0.3878110000000000 0.4487600000000000 0.7705840000000000 O
0.9298160000000000 0.2953000000000000 0.7845480000000000 O
0.5701840000000000 0.7953000000000000 0.7987850000000000 O
0.1121890000000000 0.9487600000000000 0.8127490000000001 O
0.2570930000000000 0.5327720000000000 0.8310510000000000 O
0.7429070000000000 0.4672280000000000 0.8356160000000000 O
0.8878110000000000 0.0512400000000000 0.8539170000000000 O
0.4298160000000000 0.2047000000000000 0.8678810000000000 O
0.0701840000000000 0.7047000000000000 0.8821190000000000 O
0.6121890000000000 0.5512400000000000 0.8960830000000000 O
0.7570930000000000 0.9672280000000000 0.9143840000000000 O
0.2429070000000000 0.0327720000000000 0.9189490000000000 O
0.3878110000000000 0.4487600000000000 0.9372509999999999 O
0.9298160000000000 0.2953000000000000 0.9512150000000000 O
0.5701840000000000 0.7953000000000000 0.9654520000000000 O
0.1121890000000000 0.9487600000000000 0.9794160000000000 O
0.2570930000000000 0.5327720000000000 0.9977180000000000 O
89 changes: 83 additions & 6 deletions docs/tutorials/Slab/SlabCalculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -47,7 +47,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -83,16 +83,93 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"bunzip2: Can't open input file LOCPOT_Bi2O3.vasp.bz2: No such file or directory.\n"
]
}
],
"source": [
"if os.path.isfile('LOCPOT.BiO3.vasp'):\n",
" print('LOCPOT already exists')\n",
"else:\n",
" os.system('bunzip2 LOCPOT_Bi2O3.vasp.bz2')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"import pymatgen\n",
"from pymatgen.core.structure import Structure\n",
"from pymatgen.core.surface import Slab\n",
"\n",
"\n",
"def get_layer_sites(\n",
" structure: Structure,\n",
" epsilon: float=1.5,\n",
"):\n",
" \"\"\"\n",
" Returns sites in top and bottom layer of slab. These are selected as those whose\n",
" z coordinate lies between the top/bottom of slab and top-epsilon/bottom+epsilon.\n",
"\n",
" Args:\n",
" structure (pymatgen.core.structure.Structure):\n",
" pymatgen Structure object of slab\n",
" epsilon (float):\n",
" Length from top/bottom of slab to select the sites that lie within\n",
" (i.e. sites within top/bottom surface of slab +- epsilon).\n",
" Defaults to 1.5 A.\n",
"\n",
" Returns:\n",
" [dict]: dict with top_layer and bottom_layer sites\n",
" \"\"\"\n",
" max_z = max(site.coords[2] for site in structure)\n",
" min_z = min(site.coords[2] for site in structure)\n",
" top_layer = [site for site in structure if site.coords[2] >= max_z - epsilon]\n",
" bottom_layer = [site for site in structure if site.coords[2] <= min_z + epsilon]\n",
" # print(f\"Number of sites in top layer: {len(top_layer)}\")\n",
" return {\"top_layer\": top_layer, \"bottom_layer\": bottom_layer}"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[array([0.346566, 0.311911, 0.977977]),\n",
" array([0.112189, 0.94876 , 0.979416]),\n",
" array([0.257093, 0.532772, 0.997718])]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from pymatgen.core.structure import Structure\n",
"\n",
"slab_struc = Structure.from_file(\"Bi2O3_slab.POSCAR\")\n",
"\n",
"# Get sites in surface layer\n",
"layers = get_layer_sites(slab_struc, 1.3)\n",
"layers[\"top_layer\"]\n",
"# Get fractional coordinates as points\n",
"top_layer_points = [site.frac_coords for site in layers[\"top_layer\"]]\n",
"top_layer_points"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -114,7 +191,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -134,7 +211,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down
Loading

0 comments on commit b54e322

Please sign in to comment.