{
"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",
" symbol | \n",
" x | \n",
" y | \n",
" z | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" H | \n",
" 1.032386 | \n",
" 6.784453 | \n",
" 2.604526 | \n",
"
\n",
" \n",
" 1 | \n",
" H | \n",
" 1.803768 | \n",
" 2.861700 | \n",
" 5.597986 | \n",
"
\n",
" \n",
" 2 | \n",
" H | \n",
" 1.488886 | \n",
" 1.586134 | \n",
" 1.667751 | \n",
"
\n",
" \n",
" 3 | \n",
" H | \n",
" 1.304391 | \n",
" 7.581787 | \n",
" 6.658065 | \n",
"
\n",
" \n",
" 4 | \n",
" H | \n",
" 2.687215 | \n",
" 5.624346 | \n",
" 7.935414 | \n",
"
\n",
" \n",
" 5 | \n",
" H | \n",
" 3.611814 | \n",
" 0.867768 | \n",
" 6.808235 | \n",
"
\n",
" \n",
" 6 | \n",
" H | \n",
" 3.455902 | \n",
" 3.536857 | \n",
" 1.089975 | \n",
"
\n",
" \n",
" 7 | \n",
" H | \n",
" 3.677819 | \n",
" 7.840515 | \n",
" 2.902969 | \n",
"
\n",
" \n",
" 8 | \n",
" H | \n",
" 5.150307 | \n",
" 4.829348 | \n",
" 3.958955 | \n",
"
\n",
" \n",
" 9 | \n",
" H | \n",
" 5.359657 | \n",
" 1.344457 | \n",
" 3.427006 | \n",
"
\n",
" \n",
" 10 | \n",
" H | \n",
" 6.068226 | \n",
" 3.004010 | \n",
" 8.041704 | \n",
"
\n",
" \n",
" 11 | \n",
" H | \n",
" 6.089307 | \n",
" 8.290729 | \n",
" 6.112190 | \n",
"
\n",
" \n",
" 12 | \n",
" H | \n",
" 6.270537 | \n",
" 6.295901 | \n",
" 1.342648 | \n",
"
\n",
" \n",
" 13 | \n",
" H | \n",
" 7.779489 | \n",
" 6.219615 | \n",
" 6.898890 | \n",
"
\n",
" \n",
" 14 | \n",
" H | \n",
" 7.669570 | \n",
" 2.655679 | \n",
" 2.535040 | \n",
"
\n",
" \n",
" 15 | \n",
" H | \n",
" 8.631402 | \n",
" 2.379311 | \n",
" 7.750683 | \n",
"
\n",
" \n",
" 16 | \n",
" O | \n",
" 1.661344 | \n",
" 3.288553 | \n",
" 0.895464 | \n",
"
\n",
" \n",
" 17 | \n",
" O | \n",
" 2.252441 | \n",
" 7.890762 | \n",
" 1.787531 | \n",
"
\n",
" \n",
" 18 | \n",
" O | \n",
" 2.193323 | \n",
" 6.051175 | \n",
" 6.263781 | \n",
"
\n",
" \n",
" 19 | \n",
" O | \n",
" 3.121875 | \n",
" 1.568882 | \n",
" 5.210278 | \n",
"
\n",
" \n",
" 20 | \n",
" O | \n",
" 6.867725 | \n",
" 7.678591 | \n",
" 7.634948 | \n",
"
\n",
" \n",
" 21 | \n",
" O | \n",
" 6.482595 | \n",
" 5.721000 | \n",
" 3.118545 | \n",
"
\n",
" \n",
" 22 | \n",
" O | \n",
" 7.361162 | \n",
" 3.199850 | \n",
" 6.768000 | \n",
"
\n",
" \n",
" 23 | \n",
" O | \n",
" 6.554401 | \n",
" 1.278874 | \n",
" 2.030744 | \n",
"
\n",
" \n",
"
\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",
" x | \n",
" y | \n",
" z | \n",
" frame | \n",
" symbol | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1.386029 | \n",
" 10.148803 | \n",
" 2.527119 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 1 | \n",
" 6.298432 | \n",
" 0.408980 | \n",
" 6.614086 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 2 | \n",
" 2.705972 | \n",
" 4.812221 | \n",
" 1.851418 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 3 | \n",
" 0.925476 | \n",
" 7.572369 | \n",
" 3.711328 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 4 | \n",
" -0.712621 | \n",
" 7.029148 | \n",
" 6.158907 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
"
\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",
" vx | \n",
" vy | \n",
" vz | \n",
" frame | \n",
" symbol | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.000266 | \n",
" 0.000348 | \n",
" -0.000371 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 1 | \n",
" -0.000284 | \n",
" -0.000844 | \n",
" 0.000613 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 2 | \n",
" 0.000434 | \n",
" -0.000134 | \n",
" 0.000023 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 3 | \n",
" -0.000236 | \n",
" 0.001189 | \n",
" 0.000255 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 4 | \n",
" 0.000289 | \n",
" -0.000445 | \n",
" 0.000056 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
"
\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",
" fx | \n",
" fy | \n",
" fz | \n",
" frame | \n",
" symbol | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" -0.014144 | \n",
" -0.001770 | \n",
" -0.010127 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 1 | \n",
" -0.003695 | \n",
" 0.015956 | \n",
" -0.013014 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 2 | \n",
" -0.003526 | \n",
" -0.001231 | \n",
" 0.003031 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 3 | \n",
" 0.017270 | \n",
" -0.005110 | \n",
" -0.001918 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
" 4 | \n",
" 0.002262 | \n",
" 0.006420 | \n",
" 0.002992 | \n",
" 86300 | \n",
" H | \n",
"
\n",
" \n",
"
\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",
" time(ps) | \n",
" ekinc | \n",
" T_cell(K) | \n",
" Tion(K) | \n",
" etot | \n",
" enthal | \n",
" econs | \n",
" econt | \n",
" Volume | \n",
" Pressure(GPa) | \n",
" atom_count | \n",
"
\n",
" \n",
" \n",
" \n",
" 86300 | \n",
" 1.043756E+01 | \n",
" 1.165034E-03 | \n",
" 0.000000E+00 | \n",
" 1.991763E+02 | \n",
" -139.02493778 | \n",
" -139.02493778 | \n",
" -139.00223062 | \n",
" -139.04934698 | \n",
" 7.272825E+02 | \n",
" -0.00000 | \n",
" 24 | \n",
"
\n",
" \n",
" 86310 | \n",
" 1.043877E+01 | \n",
" 1.177623E-03 | \n",
" 0.000000E+00 | \n",
" 1.951384E+02 | \n",
" -139.02452520 | \n",
" -139.02452520 | \n",
" -139.00227838 | \n",
" -139.00110075 | \n",
" 7.272825E+02 | \n",
" -0.00000 | \n",
" 24 | \n",
"
\n",
" \n",
" 86320 | \n",
" 1.043998E+01 | \n",
" 2.023734E-03 | \n",
" 0.000000E+00 | \n",
" 1.817591E+02 | \n",
" -139.02385374 | \n",
" -139.02385374 | \n",
" -139.00313223 | \n",
" -139.00110849 | \n",
" 7.272825E+02 | \n",
" -0.00000 | \n",
" 24 | \n",
"
\n",
" \n",
" 86330 | \n",
" 1.044119E+01 | \n",
" 1.223379E-03 | \n",
" 0.000000E+00 | \n",
" 1.886373E+02 | \n",
" -139.02383875 | \n",
" -139.02383875 | \n",
" -139.00233309 | \n",
" -139.00110971 | \n",
" 7.272825E+02 | \n",
" -0.00000 | \n",
" 24 | \n",
"
\n",
" \n",
" 86340 | \n",
" 1.044240E+01 | \n",
" 2.015737E-03 | \n",
" 0.000000E+00 | \n",
" 1.967750E+02 | \n",
" -139.02555726 | \n",
" -139.02555726 | \n",
" -139.00312386 | \n",
" -139.00110813 | \n",
" 7.272825E+02 | \n",
" -0.00000 | \n",
" 24 | \n",
"
\n",
" \n",
"
\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
}