Full geometry optimization

Performing a volume optimization (e.g. ISIF = 3 ) in VASP requires to reset the Wavefunction.
This is to control the Pulay Stress.
To avoid such issue you can run consecutive geometry optimizations (cancelling the WAVECAR and copying CONTCAR in POSCAR) until the Pulay stress is minimized and the calculation converges in few (i.e. <7) steps.

In my experience this method allows to find a good (i.e. low in energy) minima of the structures you consider, but it comes to the price of considerable distortions.

Personally I run a less efficient method, which allows to find minima closer to the starting structure (this means that it is possible to find more stable structures though). Simply put, you need to run 5-7 geometry steps at the time and restart the job until convergence is reached.

In order to do so I use this simple snippet of code that works for both methods (upon change on NSW line in the INCAR).

    for i in {1..1000}
    do
    [COMMAND TO RUN VASP]
    cp CONTCAR POSCAR
       if grep -q "ed r" OUTCAR
            then
            break
       fi 
    done

Some comment on these lines.

  1. [COMMAND TO RUN VASP] this line is specific to your environment. I am assuming you use a script (local or more likely a queue script) to launch vasp on a parallel machine
  2. for i in {1..1000}; do; ... ; done

This is a do-loop that iterates the value of the variable i from 1 to 1000. For an INCAR where NSW =5 this means 5000 optimization steps, which should be more than sufficient to reach a minima. The commands looped are the ones included between do and done

  1. if grep -q "ed r" OUTCAR

Once geometry convergence is reached VASP prints the following line: reached required accuracy - stopping structural energy minimisation.To check if such line is printed is sufficient to grep just those 4 (in bold) characters.

The option -q mutes the output of grep returning only a TRUE/FALSE value if the geometry converged. If the line is printed, true is returned by grep to the if clause and then the command break is run. Such command simply interrupts the initial do-loop.

  1. if; ... ; fi is a normal if-clause for bash

This small code can be enriched with other options. For example copy the XDATCAR files for each step, or the CONTCARS.

cp XDATCAR XDATCAR_$i

or saving the energy of each step in an accessory file (remember to use >> to append and not > which would delete the previous file at each iteration).

grep F OSZICAR >> energy.dat

The previous data file can be easily plotted with gnuplot using the following command:

plot "energy.dat u 3 w lp

if you do not have a graphical terminal you can use the dear old style ASCII-art terminal dumb. You can set it up in gnuplot (Cheat code of gnuplot) BEFORE plotting giving the following command:

set terminal dumb

Gnuplot is available in most linux distribution and it is always installed by default. In case you do not have it in debian based version linux, which use APT (i.e. Ubuntu):

sudo apt-get install gnuplot

more information on its website.