{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Support for Quantum ESPRESSO in exatomic" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import exa, exatomic\n", "from exatomic import qe\n", "from exatomic.base import resource, list_resources # Helper to find example files available in exatomic" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['qe.vel', 'qe.cel', 'qe.inp', 'qe.for', 'qe.evp', 'qe.eig', 'qe.pos']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# list_resources shows all available example files; here are some QE related ones\n", "[i for i in list_resources() if \"qe\" in i]" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "inppath = resource(\"qe.inp\")\n", "pospath = resource(\"qe.pos\")\n", "velpath = resource(\"qe.vel\")\n", "forpath = resource(\"qe.for\")\n", "evppath = resource(\"qe.evp\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0: 86300 10.43755843\n", " 1: 0.26582218192461E-03 0.34762151661751E-03 -0.37055692323044E-03\n", " 2: -0.28357409799207E-03 -0.84385574934985E-03 0.61301203789432E-03\n", " 3: 0.43446778391328E-03 -0.13368379507875E-03 0.22638614726700E-04\n", " 4: -0.23558263497270E-03 0.11887988312728E-02 0.25475038796956E-03\n", " 5: 0.28858553030712E-03 -0.44466330835073E-03 0.56058154685670E-04\n", " 6: -0.17782953131705E-03 -0.28382892061277E-04 -0.14986330474008E-03\n", " 7: -0.33509839767085E-03 -0.58101031888086E-03 0.98300831028985E-03\n", " 8: -0.45531989084626E-03 0.78072761126234E-04 -0.16013602508294E-03\n", " 9: -0.72505618884722E-03 0.53608322941604E-03 0.11241564898308E-02 " ] } ], "source": [ "exa.Editor(velpath).head() # We can use the Editor to view the actual file contents" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['ATOMIC_SPECIES',\n", " 'H 2.01355d0 H.pbe-rrkjus_psl.1.0.0.UPF',\n", " 'O 15.9994d0 O.pbe-n-rrkjus_psl.1.0.0.UPF',\n", " 'ATOMIC_POSITIONS (angstrom)']" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "exa.Editor(inppath)[34:38] # Likewise for the input file...\n", "# Note that the atom order of the pos, vel, etc files is the\n", "# order of the ATOMIC_SPECIES block" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This is one way to access the docs of a specific function\n", "# in the Jupyter notebook or IPython terminal\n", "qe.parse_symbols_from_input?" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
symbolxyz
0H1.0323866.7844532.604526
1H1.8037682.8617005.597986
2H1.4888861.5861341.667751
3H1.3043917.5817876.658065
4H2.6872155.6243467.935414
5H3.6118140.8677686.808235
6H3.4559023.5368571.089975
7H3.6778197.8405152.902969
8H5.1503074.8293483.958955
9H5.3596571.3444573.427006
10H6.0682263.0040108.041704
11H6.0893078.2907296.112190
12H6.2705376.2959011.342648
13H7.7794896.2196156.898890
14H7.6695702.6556792.535040
15H8.6314022.3793117.750683
16O1.6613443.2885530.895464
17O2.2524417.8907621.787531
18O2.1933236.0511756.263781
19O3.1218751.5688825.210278
20O6.8677257.6785917.634948
21O6.4825955.7210003.118545
22O7.3611623.1998506.768000
23O6.5544011.2788742.030744
\n", "
" ], "text/plain": [ " symbol x y z\n", "0 H 1.032386 6.784453 2.604526\n", "1 H 1.803768 2.861700 5.597986\n", "2 H 1.488886 1.586134 1.667751\n", "3 H 1.304391 7.581787 6.658065\n", "4 H 2.687215 5.624346 7.935414\n", "5 H 3.611814 0.867768 6.808235\n", "6 H 3.455902 3.536857 1.089975\n", "7 H 3.677819 7.840515 2.902969\n", "8 H 5.150307 4.829348 3.958955\n", "9 H 5.359657 1.344457 3.427006\n", "10 H 6.068226 3.004010 8.041704\n", "11 H 6.089307 8.290729 6.112190\n", "12 H 6.270537 6.295901 1.342648\n", "13 H 7.779489 6.219615 6.898890\n", "14 H 7.669570 2.655679 2.535040\n", "15 H 8.631402 2.379311 7.750683\n", "16 O 1.661344 3.288553 0.895464\n", "17 O 2.252441 7.890762 1.787531\n", "18 O 2.193323 6.051175 6.263781\n", "19 O 3.121875 1.568882 5.210278\n", "20 O 6.867725 7.678591 7.634948\n", "21 O 6.482595 5.721000 3.118545\n", "22 O 7.361162 3.199850 6.768000\n", "23 O 6.554401 1.278874 2.030744" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Here we get and order the symbol list\n", "xyz = qe.parse_symbols_from_input(inppath)\n", "xyz # pandas DataFrame" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'H',\n", " 'O',\n", " 'O',\n", " 'O',\n", " 'O',\n", " 'O',\n", " 'O',\n", " 'O',\n", " 'O']" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Turns out the symbols are in the right order but if we needed to reorder them...\n", "def mapper(sym):\n", " return {'H': 0, 'O': 1}[sym]\n", "\n", "xyz['order'] = xyz['symbol'].map(mapper)\n", "symbols = xyz.sort_values('order')['symbol'].tolist() # symbols = xyz['symbol'].tolist()\n", "symbols" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "pos = qe.parse_xyz(pospath, symbols)\n", "vel = qe.parse_xyz(velpath, symbols)\n", "vel.columns = (\"vx\", \"vy\", \"vz\", \"frame\", \"symbol\")\n", "force = qe.parse_xyz(forpath, symbols)\n", "force.columns = (\"fx\", \"fy\", \"fz\", \"frame\", \"symbol\")" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyzframesymbol
01.38602910.1488032.52711986300H
16.2984320.4089806.61408686300H
22.7059724.8122211.85141886300H
30.9254767.5723693.71132886300H
4-0.7126217.0291486.15890786300H
\n", "
" ], "text/plain": [ " x y z frame symbol\n", "0 1.386029 10.148803 2.527119 86300 H\n", "1 6.298432 0.408980 6.614086 86300 H\n", "2 2.705972 4.812221 1.851418 86300 H\n", "3 0.925476 7.572369 3.711328 86300 H\n", "4 -0.712621 7.029148 6.158907 86300 H" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pos.head()" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vxvyvzframesymbol
00.0002660.000348-0.00037186300H
1-0.000284-0.0008440.00061386300H
20.000434-0.0001340.00002386300H
3-0.0002360.0011890.00025586300H
40.000289-0.0004450.00005686300H
\n", "
" ], "text/plain": [ " vx vy vz frame symbol\n", "0 0.000266 0.000348 -0.000371 86300 H\n", "1 -0.000284 -0.000844 0.000613 86300 H\n", "2 0.000434 -0.000134 0.000023 86300 H\n", "3 -0.000236 0.001189 0.000255 86300 H\n", "4 0.000289 -0.000445 0.000056 86300 H" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vel.head()" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fxfyfzframesymbol
0-0.014144-0.001770-0.01012786300H
1-0.0036950.015956-0.01301486300H
2-0.003526-0.0012310.00303186300H
30.017270-0.005110-0.00191886300H
40.0022620.0064200.00299286300H
\n", "
" ], "text/plain": [ " fx fy fz frame symbol\n", "0 -0.014144 -0.001770 -0.010127 86300 H\n", "1 -0.003695 0.015956 -0.013014 86300 H\n", "2 -0.003526 -0.001231 0.003031 86300 H\n", "3 0.017270 -0.005110 -0.001918 86300 H\n", "4 0.002262 0.006420 0.002992 86300 H" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "force.head()" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "atom = pd.concat((pos, vel[[\"vx\", \"vy\", \"vz\"]], force[[\"fx\", \"fy\", \"fz\"]]), axis=1)" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
time(ps)ekincT_cell(K)Tion(K)etotenthaleconsecontVolumePressure(GPa)atom_count
863001.043756E+011.165034E-030.000000E+001.991763E+02-139.02493778-139.02493778-139.00223062-139.049346987.272825E+02-0.0000024
863101.043877E+011.177623E-030.000000E+001.951384E+02-139.02452520-139.02452520-139.00227838-139.001100757.272825E+02-0.0000024
863201.043998E+012.023734E-030.000000E+001.817591E+02-139.02385374-139.02385374-139.00313223-139.001108497.272825E+02-0.0000024
863301.044119E+011.223379E-030.000000E+001.886373E+02-139.02383875-139.02383875-139.00233309-139.001109717.272825E+02-0.0000024
863401.044240E+012.015737E-030.000000E+001.967750E+02-139.02555726-139.02555726-139.00312386-139.001108137.272825E+02-0.0000024
\n", "
" ], "text/plain": [ " time(ps) ekinc ... Pressure(GPa) atom_count\n", "86300 1.043756E+01 1.165034E-03 ... -0.00000 24\n", "86310 1.043877E+01 1.177623E-03 ... -0.00000 24\n", "86320 1.043998E+01 2.023734E-03 ... -0.00000 24\n", "86330 1.044119E+01 1.223379E-03 ... -0.00000 24\n", "86340 1.044240E+01 2.015737E-03 ... -0.00000 24\n", "\n", "[5 rows x 11 columns]" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Some extra steps to set the column names\n", "evp = qe.parse_evp(evppath, symbols)\n", "columns = evp.iloc[0, :].tolist()[1:] + [\"None\"] # Add a dummy column\n", "evp = evp.drop(\"#\", axis=0) # Delete first row\n", "evp.columns = columns\n", "evp['atom_count'] = len(symbols)\n", "evp = evp.dropna(how='all', axis=1) # Remove dummy column\n", "evp.head()" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "# Make a universe\n", "uni = exatomic.Universe(atom=atom, frame=evp)" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10001" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(uni)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x float64\n", "y float64\n", "z float64\n", "frame category\n", "symbol category\n", "vx float64\n", "vy float64\n", "vz float64\n", "fx float64\n", "fy float64\n", "fz float64\n", "dtype: object" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uni.atom.dtypes" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 6.69 s, sys: 298 ms, total: 6.99 s\n", "Wall time: 7.04 s\n" ] } ], "source": [ "%time uni.compute_atom_two() # Compute interatomic distances" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(240024, 11)" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uni.atom.shape" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1874130, 4)" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uni.atom_two.shape" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(80030, 3)" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uni.molecule.shape # Automatically computes molecules from atom-atom distances" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "exatomic.UniverseWidget(uni) # Visualize the universe!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }