westpy_100.ipynb 9.49 KB
Newer Older
Marco Govoni's avatar
Marco Govoni committed
1
2
3
4
5
6
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
7
    "This tutorial can be downloaded [link](http://greatfire.uchicago.edu/west-public/westpy/raw/master/doc/tutorials/westpy_100.ipynb)."
Marco Govoni's avatar
Marco Govoni committed
8
9
   ]
  },
10
11
12
13
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Marco Govoni's avatar
Marco Govoni committed
14
    "# 1.0 Getting Started: Ground State"
Marco Govoni's avatar
Marco Govoni committed
15
16
17
18
19
20
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Marco Govoni's avatar
Marco Govoni committed
21
    "We are going to generate an input file for the [QuantumEspresso](https://www.quantum-espresso.org/) code or [Qbox](http://qboxcode.org/). Each code will compute the ground state electronic stucture for the methane molecule using Density Functional Theory. "
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
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Load westpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " _    _ _____ _____ _____            \n",
      "| |  | |  ___/  ___|_   _|           \n",
      "| |  | | |__ \\ `--.  | |_ __  _   _  \n",
      "| |/\\| |  __| `--. \\ | | '_ \\| | | | \n",
      "\\  /\\  / |___/\\__/ / | | |_) | |_| | \n",
      " \\/  \\/\\____/\\____/  \\_/ .__/ \\__, | \n",
      "                       | |     __/ | \n",
      "                       |_|    |___/  \n",
      " \n",
Marco Govoni's avatar
Marco Govoni committed
50
51
      "WEST version     :  3.1.1\n",
      "Today            :  2018-09-19 15:21:13.244247\n"
52
53
54
55
56
57
58
59
60
61
62
     ]
    }
   ],
   "source": [
    "from westpy import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
63
    "## Step 2: Geometry"
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
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "geom = Geometry()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's define a cubic cell of edge 25 Bohr."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "geom.setCell((25,0,0),(0,25,0),(0,0,25))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We load the atomic positions from a XYZ file, available online. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
Marco Govoni's avatar
Marco Govoni committed
104
    "geom.addAtomsFromOnlineXYZ( \"http://www.west-code.org/doc/training/methane/CH4.xyz\" )"
105
106
107
108
109
110
111
112
113
114
115
116
117
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We associate pseudopotential files to each species."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
118
   "outputs": [],
119
   "source": [
120
121
    "geom.addSpecies( \"C\", \"http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf\")\n",
    "geom.addSpecies( \"H\", \"http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf\")"
122
123
124
125
126
127
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
128
    "## Step 3.1: Ground State"
Marco Govoni's avatar
Marco Govoni committed
129
130
131
132
133
134
135
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The ground state calculation is defined by the geometry, a choice of the exchange-correlation functional, and by setting an energy cutoff for the wavefunctions. "
136
137
138
139
   ]
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
140
   "execution_count": 6,
141
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
   "outputs": [],
   "source": [
    "gs = GroundState(geom,xc=\"PBE\",ecut=40.0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are now able to generate the input file for QuantumEspresso."
   ]
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
156
   "execution_count": 7,
Marco Govoni's avatar
Marco Govoni committed
157
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
158
159
160
161
162
163
164
165
166
167
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Generated file:  pw.in\n"
     ]
    }
   ],
Marco Govoni's avatar
Marco Govoni committed
168
169
170
171
172
173
174
175
176
177
178
179
180
   "source": [
    "gs.generateInputPW()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can inspect the file pw.in"
   ]
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
181
   "execution_count": 8,
Marco Govoni's avatar
Marco Govoni committed
182
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
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
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "&CONTROL\n",
      "calculation       = 'scf'\n",
      "restart_mode      = 'from_scratch'\n",
      "pseudo_dir        = './'\n",
      "outdir            = './'\n",
      "prefix            = 'calc'\n",
      "wf_collect        = .TRUE.\n",
      "/\n",
      "&SYSTEM\n",
      "ibrav             = 0\n",
      "nat               = 5\n",
      "ntyp              = 2\n",
      "ecutwfc           = 40.0\n",
      "nbnd              = 8\n",
      "input_dft         = 'PBE'\n",
      "nosym             = .TRUE.\n",
      "noinv             = .TRUE.\n",
      "/\n",
      "&ELECTRONS\n",
      "diago_full_acc = .TRUE.\n",
208
      "conv_thr       = 1.d-8\n",
Marco Govoni's avatar
Marco Govoni committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
      "/\n",
      "ATOMIC_SPECIES\n",
      "C 12.011 C_ONCV_PBE-1.0.upf\n",
      "H 1.008 H_ONCV_PBE-1.0.upf\n",
      "ATOMIC_POSITIONS {bohr}\n",
      "C 0.0 0.0 0.0\n",
      "H 1.185992116575257 -1.185803143962673 1.185992116575257\n",
      "H -1.185992116575257 1.185992116575257 1.185992116575257\n",
      "H -1.185992116575257 -1.185992116575257 -1.185992116575257\n",
      "H 1.185992116575257 1.185992116575257 -1.185992116575257\n",
      "K_POINTS {gamma}\n",
      "CELL_PARAMETERS {bohr}\n",
      "25.0 0.0 0.0\n",
      "0.0 25.0 0.0\n",
      "0.0 0.0 25.0\n",
      "\n"
     ]
    }
   ],
Marco Govoni's avatar
Marco Govoni committed
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
   "source": [
    "with open(\"pw.in\",\"r\") as file :\n",
    "    data = file.read()\n",
    "    print(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can optionally also download the pseudopotentials files. "
   ]
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
243
   "execution_count": 9,
Marco Govoni's avatar
Marco Govoni committed
244
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
245
246
247
248
249
250
251
252
253
254
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded file:  C_ONCV_PBE-1.0.upf , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf\n",
      "Downloaded file:  H_ONCV_PBE-1.0.upf , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf\n"
     ]
    }
   ],
255
   "source": [
Marco Govoni's avatar
Marco Govoni committed
256
    "gs.downloadPseudopotentials()"
257
258
259
260
261
262
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
263
    "## Step 3.2: Ground State with Qbox"
264
265
266
267
268
269
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Marco Govoni's avatar
Marco Govoni committed
270
    "To generate the input for Qbox we can simply update Species to use the xml formats."
271
272
   ]
  },
Marco Govoni's avatar
Marco Govoni committed
273
274
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
275
   "execution_count": 10,
Marco Govoni's avatar
Marco Govoni committed
276
277
   "metadata": {},
   "outputs": [],
278
   "source": [
279
280
    "gs.updateSpecies(\"C\", \"http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml\")\n",
    "gs.updateSpecies(\"H\", \"http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml\")"
281
282
283
284
285
286
287
288
289
290
291
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are now able to generate the input file for QuantumEspresso."
   ]
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
292
   "execution_count": 11,
293
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
294
295
296
297
298
299
300
301
302
303
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Generated file:  qbox.in\n"
     ]
    }
   ],
304
   "source": [
Marco Govoni's avatar
Marco Govoni committed
305
    "gs.generateInputQbox()"
306
307
308
309
310
311
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Marco Govoni's avatar
Marco Govoni committed
312
    "We can inspect the file qbox.in"
313
314
315
316
   ]
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
317
   "execution_count": 12,
318
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
319
320
321
322
323
324
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set cell 25.0 0.0 0.0 0.0 25.0 0.0 0.0 0.0 25.0\n",
325
326
      "species Carbon http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml\n",
      "species Hydrogen http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml\n",
Marco Govoni's avatar
Marco Govoni committed
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
      "atom C1 Carbon 0.0 0.0 0.0\n",
      "atom H2 Hydrogen 1.185992116575257 -1.185803143962673 1.185992116575257\n",
      "atom H3 Hydrogen -1.185992116575257 1.185992116575257 1.185992116575257\n",
      "atom H4 Hydrogen -1.185992116575257 -1.185992116575257 -1.185992116575257\n",
      "atom H5 Hydrogen 1.185992116575257 1.185992116575257 -1.185992116575257\n",
      "set ecut 40.0\n",
      "set wf_dyn JD\n",
      "set xc PBE\n",
      "set scf_tol 1.e-8\n",
      "randomize_wf\n",
      "run -atomic_density 0 100 5\n",
      "save gs.xml\n",
      "\n"
     ]
    }
   ],
343
   "source": [
Marco Govoni's avatar
Marco Govoni committed
344
345
346
347
348
349
350
351
352
353
    "with open(\"qbox.in\",\"r\") as file :\n",
    "    data = file.read()\n",
    "    print(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can optionally also download the pseudopotentials files. "
354
   ]
Marco Govoni's avatar
Marco Govoni committed
355
356
357
  },
  {
   "cell_type": "code",
Marco Govoni's avatar
Marco Govoni committed
358
   "execution_count": 13,
Marco Govoni's avatar
Marco Govoni committed
359
   "metadata": {},
Marco Govoni's avatar
Marco Govoni committed
360
361
362
363
364
365
366
367
368
369
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded file:  C_ONCV_PBE-1.0.xml , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml\n",
      "Downloaded file:  H_ONCV_PBE-1.0.xml , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml\n"
     ]
    }
   ],
Marco Govoni's avatar
Marco Govoni committed
370
371
372
373
374
375
376
377
378
379
   "source": [
    "gs.downloadPseudopotentials()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
Marco Govoni's avatar
Marco Govoni committed
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
  }
 ],
 "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",
Marco Govoni's avatar
Marco Govoni committed
398
   "version": "3.7.0"
Marco Govoni's avatar
Marco Govoni committed
399
400
401
402
403
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}