{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Usage of SystemCalculator Instance\n", "We here provide some examples on how to run the code with system calculator.\n", "Let us consider a very simple inputfile and a small system, that can be give from file and from a dictionary of atomic positions." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'dft': {'ixc': 'PBE', 'rmult': [3, 8.0]}}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from BigDFT import Inputfiles as I\n", "from BigDFT.Calculators import SystemCalculator\n", "from futile.Utils import write\n", "inp=I.Inputfile()\n", "inp.set_xc('PBE')\n", "inp.set_rmult(coarse=3) #very very little, only for test\n", "inp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We initalize the SystemCalculator instance by specifying the number of OMP threads and the *command* to be used for the mpirun calculation." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialize a Calculator with OMP_NUM_THREADS=1 and command mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft\n" ] } ], "source": [ "code=SystemCalculator(omp=1,mpi_run='mpirun -np 2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us define the function for validating the runs:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def validate_run(inputfile,logfile):\n", " \"\"\"\n", " Checks that the inputfile and the logfiles exists and have recent dates.\n", " \"\"\"\n", " import os.path as P\n", " from futile.Utils import write,file_time\n", " from time import time\n", " write('Input and log existing',P.isfile(inputfile),P.isfile(logfile))\n", " write('Created since',time()-file_time(inputfile),time()-file_time(logfile))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Basic run, no name and atomic positions from a file:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating the yaml input file \"./input.yaml\"\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft\n", "Energy -8.09733985003\n", "Input and log existing True True\n", "Created since 2.02708792686 0.0871000289917\n" ] } ], "source": [ "result=code.run(input=inp,posinp='CH4_posinp.xyz')\n", "write('Energy',result.energy)\n", "validate_run('input.yaml','log.yaml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let us provide a naming scheme. The inputfile and the logfile will have different names:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating the yaml input file \"./test1.yaml\"\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n test1\n", "Energy -8.09733985003\n", "Input and log existing True True\n", "Created since 1.93355202675 0.0256290435791\n" ] } ], "source": [ "result=code.run(input=inp,posinp='CH4_posinp.xyz',name='test1')\n", "write('Energy',result.energy)\n", "validate_run('test1.yaml','log-test1.yaml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us now provide a output directory. To do that there are two different options:\n", " * Provide the `outdir` command to the `bigdft` executable\n", " * Define a `run_dir` for the run of the calculator instance.\n", "The difference between the two is the position of the input files. In the first case they will be in the Current Working Directory, whereas in the second one they will be placed in the run_directory." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating the yaml input file \"./test2.yaml\"\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n test2 -d out1\n", "Energy -8.09733985003\n", "Input and log existing True True\n", "Created since 1.86937189102 0.0214099884033\n", "Create the sub-directory 'out2'\n", "Copy the posinp file 'CH4_posinp.xyz' into 'out2'\n", "Creating the yaml input file \"out2/test3.yaml\"\n", "Run directory out2\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n test3\n", "Energy -8.06514886077\n", "Input and log existing True True\n", "Created since 1.96282911301 0.0228381156921\n", "Create the sub-directory 'out3'\n", "Copy the posinp file 'CH4_posinp.xyz' into 'out3'\n", "Creating the yaml input file \"out3/test4.yaml\"\n", "Run directory out3\n", "Executing command: mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n test4 -d out4\n", "Energy -8.06514886077\n", "Input and log existing True True\n", "Created since 1.95026421547 0.0226290225983\n" ] } ], "source": [ "from os.path import join as j\n", "#first case\n", "result=code.run(input=inp,posinp='CH4_posinp.xyz',name='test2',outdir='out1')\n", "write('Energy',result.energy)\n", "validate_run('test2.yaml',j('out1','log-test2.yaml'))\n", "#second case\n", "result=code.run(input=inp,posinp='CH4_posinp.xyz',name='test3',run_dir='out2')\n", "write('Energy',result.energy)\n", "validate_run(j('out2','test3.yaml'),j('out2','log-test3.yaml'))\n", "#combine the two\n", "result=code.run(input=inp,posinp='CH4_posinp.xyz',name='test4',run_dir='out3',outdir='out4')\n", "write('Energy',result.energy)\n", "validate_run(j('out3','test4.yaml'),j('out3','out4','log-test4.yaml'))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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": 1 }