File size: 7,983 Bytes
4920068
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ionisation potential of a porous material\n",
    "\n",
    "In this example we use `MacroDensity` with `VASP` to align the energy levels of a porous material.\n",
    "\n",
    "The procedure involves one DFT calculaion, yielding different important values:\n",
    "\n",
    "* $\\epsilon_{vbm}$ - the valence band maximum\n",
    "* $V_{vac}$ - the vacuum potential\n",
    "\n",
    "The ionisation potential ($IP$) is then obtained from:\n",
    "\n",
    "$IP = V_{vac} - \\epsilon_{vbm}$\n",
    "\n",
    "The difference to a bulk calculation is that here the material itself has a vacuum within it. This allows us to sample the vacuum level from the vacuum region, as explained in [this paper](http://pubs.acs.org/doi/abs/10.1021/ja4110073).\n",
    "\n",
    "## Our system \n",
    "\n",
    "We will demonstrate this procedure for the porous system ZIF-8.\n",
    "\n",
    "![](./zif8.png)\n",
    "\n",
    "## Procedure\n",
    "\n",
    "1. Optimise the structure\n",
    "2. Calculate the electronic structure at your chosen level of theory, adding the `LVHAR` flag to the `INCAR` file:\n",
    "\n",
    "    ``LVHAR = .TRUE.  # This generates a LOCPOT file with the potential`` \n",
    "    \n",
    "3. Locate the centre of the largest pore - do this \"by eye\" first\n",
    "4. Plot the potential in that plane, so see if it plateaus\n",
    "5. Plot a profile of the potential across the pore, again to see the plateau\n",
    "6. Sample the potential from the pore centre"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_13766/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": {},
   "source": [
    "### Read the potential"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "if os.path.isfile('LOCPOT'):\n",
    "    print('LOCPOT already exists')\n",
    "else:\n",
    "    os.system('bunzip2 LOCPOT.bz2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading header information...\n",
      "Reading 3D data using Pandas...\n",
      "Average of the potential =  1.9559870102655787e-14\n"
     ]
    }
   ],
   "source": [
    "input_file = 'LOCPOT'\n",
    "\n",
    "#=== No need to edit below\n",
    "vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density(input_file)\n",
    "vector_a,vector_b,vector_c,av,bv,cv = md.matrix_2_abc(Lattice)\n",
    "resolution_x = vector_a/NGX\n",
    "resolution_y = vector_b/NGY\n",
    "resolution_z = vector_c/NGZ\n",
    "grid_pot, electrons = md.density_2_grid(vasp_pot, NGX, NGY, NGZ)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Look for pore centre points\n",
    "\n",
    "* For this we will use `VESTA`.\n",
    "    * Open the LOCPOT in `VESTA`.\n",
    "    * Expand to 2x2x2 cell, by choosing the Boundary option on the left hand side.\n",
    "    * Look for a pore centre - [1,1,1] is at a pore centre here.\n",
    "    * Now draw a lattice plane through that point.\n",
    "        * Choose Edit > Lattice Planes.\n",
    "        * Click New.\n",
    "        * Put in the Miller index (e.g. 1,1,1).\n",
    "        * Move the plane up and down using the d parameter, until it passes through the point you think is the centre.\n",
    "        * It should look like the picture below.\n",
    "![](./111.png)\n",
    "\n",
    "* Now we look at a contour plot of this plane to see if we are at a plateau.\n",
    "    * Utiltiy > 2D Data Display.\n",
    "    * Click Slice and enter the same parameters as in the 3D view.\n",
    "    * Now choose contours to play with the settings\n",
    "    * Z(max) and Z(min) tell you the potential max and min.\n",
    "    * Set contour max = Z(max) and contour min = 0 and the interval to 0.1.\n",
    "    * With some playing with the General settings, you can get something like this:\n",
    "    \n",
    "![](./plane.png)\n",
    "\n",
    "* We can see the [1,1,1], at the centre of the picture is a maximum and is a plateau, so we can now use it for sampling.\n",
    "\n",
    "## Sampling the potential\n",
    "\n",
    "* We now set the point to sample at [1,1,1]\n",
    "* We must also set the travelled parameter, for this type of analysis it is always [0,0,0]."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "cube_origin = [1,1,1]\n",
    "travelled = [0,0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "216"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(cube_origin[0]*NGX)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* We want to try a range of sampling area sizes and analyse how this affects the potential.\n",
    "* We also want low variance (plateau condidtions).\n",
    "* Ideally we should have as large an area as possible, with low (< 1e-5) variance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dimension   Potential   Variance\n",
      "--------------------------------\n",
      "   1         2.3068     0.000000\n",
      "  10         2.3068     0.000001\n",
      "  20         2.3068     0.000003\n",
      "  40         2.3068     0.000019\n",
      "  60         2.3067     0.000108\n",
      "  80         2.3048     0.001151\n",
      " 100         2.2883     0.015872\n"
     ]
    }
   ],
   "source": [
    "dim = [1, 10, 20, 40, 60, 80, 100]\n",
    "print(\"Dimension   Potential   Variance\")\n",
    "print(\"--------------------------------\")\n",
    "for d in dim:\n",
    "    cube = [d, d, d]\n",
    "    cube_potential, cube_var = md.volume_average(cube_origin, cube,grid_pot, NGX, NGY, NGZ, travelled=travelled)\n",
    "    print(\" %3i     %10.4f   %10.6f\"%(d, cube_potential, cube_var))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So we take the potential value of `2.3068`. For the VBM value, we take it from the `OUTCAR` file (VBM: -2.4396 eV)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IP: 4.7464 eV\n"
     ]
    }
   ],
   "source": [
    "print(\"IP: %3.4f eV\" % (2.3068 -- 2.4396 ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}