{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Usage of Dataset class\n", "We here show the API of the Dataset class, conceived to run and collects ensemble calculations." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from BigDFT import Datasets as D, Calculators as C, Inputfiles as I" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'sym': 'O', 'O': [0.0, 0.0, 1.1282]}], 'global monopole': 0.0}\n" ] } ], "source": [ "from BigDFT.Database import Molecules\n", "CO=Molecules.Molecule('CO')\n", "print CO" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true }, "outputs": [], "source": [ "inp=I.Inputfile({'dft': {'rmult': [3,8]}})" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialize a Calculator with OMP_NUM_THREADS=2 and command mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft\n" ] } ], "source": [ "code=C.SystemCalculator(omp=2,mpi_run='mpirun -np 2')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reload(D)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "study=D.Dataset(label='CO',run_dir='CO',posinp=CO)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "inp.set_rmult(coarse=3)\n", "study.append_run(id={'crmult': 3}, runner= code, input=inp,skip=False)\n", "inp.set_rmult(coarse=4)\n", "study.append_run(id={'crmult': 4}, runner= code, input=inp)\n", "inp.set_rmult(coarse=5)\n", "study.append_run(id={'crmult': 5}, runner= code, input=inp)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "code.update_global_options(skip=False)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating the yaml input file \"CO/crmult:3.yaml\"\n", "Run directory CO\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n crmult:3\n", "Creating the yaml input file \"CO/crmult:4.yaml\"\n", "Run directory CO\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n crmult:4\n", "Creating the yaml input file \"CO/crmult:5.yaml\"\n", "Run directory CO\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n crmult:5\n" ] } ], "source": [ "data=study.run()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-21.611635946132814, -21.64835568408899, -21.651311269276533]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "study.fetch_results(attribute='energy')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'run_dir': 'CO', 'input': {'dft': {'rmult': [3, 8.0]}}, 'posinp': {'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'O': [0.0, 0.0, 1.1282], 'sym': 'O'}], 'global monopole': 0.0}, 'skip': False, 'label': 'CO'}\n", "-21.6116359461\n", "{'run_dir': 'CO', 'input': {'dft': {'rmult': [4, 8.0]}}, 'posinp': {'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'O': [0.0, 0.0, 1.1282], 'sym': 'O'}], 'global monopole': 0.0}, 'label': 'CO'}\n", "-21.6483556841\n", "{'run_dir': 'CO', 'input': {'dft': {'rmult': [5, 8.0]}}, 'posinp': {'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'O': [0.0, 0.0, 1.1282], 'sym': 'O'}], 'global monopole': 0.0}, 'label': 'CO'}\n", "-21.6513112693\n" ] } ], "source": [ "for d in range(len(study.runs)):\n", " print study.runs[d]\n", " print study.results[d].energy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Polarizability tensor of a molecule" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating the yaml input file \"./CO-GS.yaml\"\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n CO-GS\n" ] } ], "source": [ "inp=I.Inputfile()\n", "mol=Molecules.Molecule('CO')\n", "#mol['positions'][1]['O']=[0.0,0.0,1.12016] #our positions\n", "inp.set_xc('PBE')\n", "inp.set_hgrid('0.37')\n", "inp.set_rmult(coarse=11)\n", "logGS=code.run(input=inp,posinp=mol,name='CO-GS')" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "intensity=-1.e-2\n", "PolTensor=D.Dataset(label='Poltensor',run_dir='polt',input=inp,posinp=mol,d0=logGS.dipole,F=intensity)\n", "for idir,coord in enumerate(['x','y','z']):\n", " el=np.zeros(3)\n", " el[idir]=intensity\n", " inp.apply_electric_field(el.tolist())\n", " PolTensor.append_run({'id': coord,'F':intensity},code,input=inp)" ] }, { "cell_type": "code", "execution_count": 89, "metadata": {}, "outputs": [], "source": [ "def extract_alpha(PolT):\n", " d0=np.array(PolT.get_global_option('d0'))\n", " F=PolT.get_global_option('F')\n", " ds=PolT.fetch_results(attribute='dipole')\n", " alpha=np.mat(np.zeros(9)).reshape(3,3)\n", " for idir in range(3):\n", " alpha[idir]=(np.array(ds[idir])-d0)/F\n", " return alpha" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [], "source": [ "code.update_global_options(skip=False)" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [], "source": [ "PolTensor.set_postprocessing_function(extract_alpha)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating the yaml input file \"polt/F:-0.01,id:x.yaml\"\n", "Run directory polt\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n F:-0.01,id:x\n", "Creating the yaml input file \"polt/F:-0.01,id:y.yaml\"\n", "Run directory polt\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n F:-0.01,id:y\n", "Creating the yaml input file \"polt/F:-0.01,id:z.yaml\"\n", "Run directory polt\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n F:-0.01,id:z\n" ] } ], "source": [ "alpha=PolTensor.run()" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "alpha1=_" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[ 1.26423306e+01, 3.50890610e-03, -3.31700000e-02],\n", " [ 3.50890610e-03, 1.26423306e+01, -3.31700000e-02],\n", " [ 3.70690000e-05, 3.70690000e-05, 1.58543700e+01]])" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alpha1" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [], "source": [ "alpha2=alpha" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[ 1.26423306e+01, 3.50890610e-03, -3.31700000e-02],\n", " [ 3.50890610e-03, 1.26423306e+01, -3.31700000e-02],\n", " [ 3.70690000e-05, 3.70690000e-05, 1.58543700e+01]])" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alpha1" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{0: ,\n", " 1: ,\n", " 2: }" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alpha2" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[ 1.26686738e+01, -3.23449840e-03, 3.77370000e-02],\n", " [-3.23449840e-03, 1.26686738e+01, 3.77370000e-02],\n", " [-1.11158900e-03, -1.11158900e-03, 1.58224360e+01]])" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alpha" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "a=0.5*(alpha1+alpha2)" ] }, { "cell_type": "code", "execution_count": 93, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.1334035481704943" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.mean(np.diag(alpha))*(0.529177**3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15rc1" } }, "nbformat": 4, "nbformat_minor": 2 }