Scripts for setting up VASP simulations

Bash / Python scripts for setting up VASP simulations

Github

Soon on YouTube

Overview

1. ‚Ecut.sh‚: Performs DFT energy / lattice parameters convergence test for varying energy cutoff, also showing total simulation time for each cutoff step.
2. ‚k_sampling.sh‚:  Performs DFT energy / lattice parameters convergence test for varying k-space sampling, also showing total simulation time for each step.
3 ‚create_files.sh‚: Generates disordered and deformed structures in POSCAR format using Atomsk.
4. ‚create_poscars.sh‚: Sorts the previously generated structures into corresponding folders and copies into them input files for VASP calculations.
5. ‚create_potcars.sh‚: Into each generated folder for VASP calculations, it automatically creates POTCAR with elements found in POSCAR.
6. ‚run_vasp.sh‚: Runs the simulations one by one for each prepared VASP folder, also generating output file showing total simulation time and whether the convergence was succesfull or not.

1. Energy cutoff convergence test

The following is a bash script, run it with:
Place ‚python_run.py‘, ‚Ecut.sh‘ in the same folder, then make it executable and run it with:
sudo chmod +x Ecut.sh
./Ecut.sh

This script performs the DFT energy/lattice parameters convergence test for varying energy cutoff parameter. The script is running from the best settings to the worst, i.e., the first one will be calculated with the E_cutoff = ENCUT_MAX. If you allow in INCAR to optimize lattice parameters, the output will also show changes in them. The output will be in the same folder as the VASP data (‚directory_path‘) and will be named: ‚ENCUT_CONVERGENCE_TEST_ENERGY_and_LATT_PARAMETERS.txt‚. In this file, each column corresponds to the following: 1.(Energy cutoff [eV]) 2.(Total simulation time for the current energy cutoff [minutes]) 3.(Total energy [eV]) 4.(Difference in total energy between the best set energy cutoff and its current value [eV]) 5. to 10.(Lattice parameters [A, °]), 11. to 16.(Difference in lattice parameters from the best energy cutoff [A, °])

 

Prerequisities

  • Bash
  • Python 3.x
  • py4vasp (pip install py4vasp)
  • VASP compiled with HDF5 
  • mdtraj (pip install mdtraj)
  • numpy (pip install numpy)

Usage

Set the directory with the prepared VASP folder in 'Ecut.sh':
directory_path="/home/lebedmi2/VASP_calculations_ALL/test_only/Fe_bcc/Fe_2"
#Set parameters of energy_cutoff test and the number of processors for the VASP
ENCUT_MAX=800
ENCUT_MIN=400
ENCUT_STEP=25
NUMBER_OF_PROCESSORS=12
VASP_BINARY_NAME="vasp_std"
After running the script: an example of content of ENCUT_CONVERGENCE_TEST_ENERGY_and_LATT_PARAMETERS.txt:

2. K-points convergence test

The following is a bash script, run it with:
Place ‚p_change_kpoints.py‘, ‚python_run.py‘, ‚k_sampling.sh‘ in the same folder, then make it executable and run it with:
sudo chmod +x k_sampling.sh
./k_sampling.sh

This script performs the DFT energy/lattice parameters convergence test for varying k-points. In this script, everything above .4 is rounded up, e.g., if k1 = 3.4231, it will be set as 4. If k1 = 3.39, then it will be 3. Everthing below 1 will be rounded to 1, e.g., if k1 = 0.213 (very large supercell), it will be set as 1. Script is running from the best settings to the worst, i.e., the first one will be calculated the smallest k_spacing (e.g., 0.0175, which has the largest numbers of k-sampling). If you allow in INCAR to optimize lattice parameters, the output will also show changes in them. The output will be in the same folder as the VASP data (‚directory_path‘) and will be named: K_SAMPLING_CONVERGENCE_TEST_ENERGY_and_LATT_PARAMETERS.txt„. In this file, each column corresponds to the following: 1.(Energy cutoff [eV]) 2.(Total simulation time for the current energy cutoff [minutes]) 3.(Total energy [eV]) 4.(Difference in total energy between the best set energy cutoff and its current value [eV]) 5. to 10.(Lattice parameters [A, °]), 11. to 16.(Difference in lattice parameters from the best energy cutoff [A, °])

 

Prerequisities

  • Bash
  • Python 3.x
  • py4vasp (pip install py4vasp)
  • VASP compiled with HDF5
  • mdtraj (pip install mdtraj)
  • numpy (pip install numpy)

Usage

Set the directory with the prepared VASP folder in 'k_sampling.sh':
directory_path="/home/lebedmi2/VASP_calculations_ALL/test_only/Fe_bcc/Fe_2"
#Set parameters of the equidistant k_spacing and the number of processors for VASP and name of its binary
k_spacing_MIN=0.0175
k_spacing_MAX=0.1
STEP=0.0025
NUMBER_OF_PROCESSORS=12
VASP_BINARY_NAME="vasp_std"
After running the script: an example of content of K_SAMPLING_CONVERGENCE_TEST_ENERGY_and_LATT_PARAMETERS.txt:

3. Create disturbed and deformed structures using Atomsk

The following is a bash script, make it executable and run it with:
sudo chmod +x create_files.sh
./create_files.sh

This script employs Atomsk to generate disordered and deformed structures in POSCAR format from the specified initial structure. It selects the degree of atomic position disturbance and the extent of deformation based on a uniform distribution within a given range. Upon determining the atomic disturbance value, Atomsk applies a normal distribution to execute the modifications. 

The second version of this script will also attempt to distribute the atoms such that no two are closer to each other than the specified ‚distance_separ_limit‚ and it requires Python with Pandas module. Additionally, it generates an output file named ‚output_all.txt‘, where the first column contains the names of the generated structures and the second column lists the minimum distances between atoms, as determined by the RDF for each structure.

Prerequisities

  • Bash
  • Atomsk
  • Python with Pandas module 

Usage

Place the script in the same folder as the initially created structure (‚name_of_input_file‚) that will be deformed and disturbed.
You might want to change the following parameters:

#Set the path to the file which atomic positions will be disturbed and the structure will be deformed
directory_path="/home/lebedmi2/DATA/VASP_data/Ti_test_structures/scripts/structures"
#Number of structures to create:
num_of_structures=899
#Name of the input file to be disturbed and deformed
name_of_input_file="Ti_36_INIT_Standard.lmp"
#Part of the ouput file name
name_of_output_poscar="POSCAR_STD"
#Minimum and maximum deformations
min_deform=-15
max_deform=15
#Minimum and maximum disturbances
min_disturb=0.1
max_disturb=1.0
#Set the maximum allowable distance between any atoms. For each randomly generated structure, the RDF will be calculated using Atomsk. If any distance between atoms is smaller than this limit, the structure will be regenerated until it meets the minimum distance requirement.
distance_separ_limit=1.5
Before running the script:

Name of the introduced bash script: create_files.sh
Name of the input file to be disturbed: „Ti_36_INIT_Standard.lmp“

After running the script:

Outputs are the POSCAR files with names in format: a_$(name_of_output_poscar)_b_c%, where a = ID of  the generated structure, b = value of the selected disturbance, c = value of the selected deformation, e.g., 8_POSCAR_STD_0.417_-11.768%

4. Prepare folders having INCAR, KPOINTS, and POSCAR files

The following is a bash script, make it executable and run it with:
sudo chmod +x create_poscars.sh
./create_poscars.sh

For each file generated by the ‚create_files.sh‘, this script extracts the filename and creates a corresponding directory within the target directory. Then, it copies the original file to the newly created directory, renaming it to ‚POSCAR‘, and also copies additional required VASP files (INCAR, KPOINTS) into the same directory. POTCAR can be copied by the next illustrated script (which automatically prepares it with the potentials for found elements within POSCAR), or can be uncommented in this script and copied directly also.

Prerequisities

  • Bash

Usage

#Set the path to the file which atomic positions will be disturbed and the structure will be deformed
directory_path="/home/lebedmi2/DATA/VASP_data/Ti_test_structures/scripts/structures"

Place the ‚create_poscars.sh‚ script and your INCAR, KPOINTS, and possibly POTCAR files into the same folder. If you want to copy also POTCAR, uncomment: #cp „./POTCAR“ „$dir_name/“

Before running the script:
After running the script:

5. Automatically prepare POTCAR files from individual elements found in POSCARs

! Note ! This is a python script, make it executable and run it with:
python3 prepare_potcars.py

This script automates the creation of a VASP POTCAR file by combining POTCAR files for individual elements found in a POSCAR file. The prepare_potcar.py script iterates over a main directory with subdirectories, each containing a POSCAR file, and generates a corresponding POTCAR file in each one of them. The script reads a POSCAR file, which specifies the elements and their quantities in a crystal structure, and then compiles the corresponding POTCAR files from a directory containing VASP potential files for each element. If some elements have zero quantities, it will remove them from the POSCAR file, e.g.: If POSCAR contains:

Cr Fe Ni Cu

11 11 11 3
It will prepare POTCAR file with Cr, Fe, Ni, Cu, and it will not change the POSCAR.
If POSCAR contains:
Cr Fe Ni Cu
7 0 5 0
It will prepare POTCAR file with Cr, Ni, and it will change the POSCAR to:
Cr Ni
7 5

Prerequisities

  • Python 3.x
Output example:
Consider a scenario with three distinct folders, each containing a file named POSCAR. The contents of the POSCAR files in these folders are as follows:
 
The POSCAR in the first folder lists the element Ti.
The POSCAR in the second folder includes a combination of elements: Cr, Fe, Ni, and Cu.
The POSCAR in the third folder contains Ti and Al.
Upon executing a specific script, it will automatically generate a file named POTCAR within each folder. The content of each POTCAR file will reflect the elements listed in the respective folder’s POSCAR file:
 
This process automates the creation of POTCAR files based on the elemental composition specified in each folder’s POSCAR file.
 
Usage:
#Set the path to the parent folder of the individual folders having VASP files:
INPUT_POSCAR_FOLDER = f'/home/lebedmi2/DATA/VASP_data/Ti_test_structures/POSCARs'
#Set the path to the parent folder of the individual folders having the element POTCARs: 
INPUT_VASP_POTENTIALS_FOLDER = f'/home/lebedmi2/DATA/VASP_data/Ti_test_structures/potencials/potPAW_PBE.54'
  • A POSCAR file must exist in the INPUT_POSCAR_FOLDER subdirectories.
  • The INPUT_VASP_POTENTIALS_FOLDER must contain the directories named after each element (e.g., folders called Fe, Cr, Ni, Cu, …), with a ‚POTCAR‘ file inside them.
  • Outputs: A POTCAR file will be created or overwritten in the INPUT_POSCAR_FOLDER directory.

Folder containing the potentials for individual elements (path to it set in INPUT_VASP_POTENTIALS_FOLDER)

After executing the script, a POTCAR file will be created inside each folder, containing the elements identified in the corresponding POSCAR file.

6. Run the VASP calculations gradually across multiple folders and monitor the convergence

The following is a bash script, make it executable and run it with:
sudo chmod +x run_vasp.sh
./run_vasp.sh

This script automates the execution of VASP calculations gradually across multiple directories, each containing VASP input files (INCAR, KPOINTS, POSCAR, POTCAR) prepared by preceding scripts. It works as follows:

  • It identifies folders that contain VASP input files (INCAR, KPOINTS, POSCAR, POTCAR) set up by a previous script.
  • The script then sequentially starts calculations in each of these folders, guided by the folder names listed in a file called ‚directory_list.txt‚.
  • After finishing calculations in a folder, the script removes that folder’s name from the ‚directory_list.txt‘ and proceeds to the next folder. This process ensures that if the script is stopped for any reason, it can resume from where it left off, skipping already processed folders.
  • At the beginning, the script checks if ‚directory_list.txt‚ exists to avoid recreating it. This way, calculations can continue from the last stopped point.
  • Additionally, the script generates a file named ‚OUTPUT_END_of_CYCLES_LIST.txt‚ in the parent directory. This file logs details from each calculation, including whether the calculations converged based on the NELM parameter from the INCAR file. If NELM isn’t specified, a default value of 60 is used. The script notes a non-convergence if the last cycle number in the OSZICAR file matches NELM. It also records the total time spent on the simulation for each folder.

Prerequisities

  • Bash
  • bc (sudo apt-get install bc)

Usage

Run the script from any location you want. Change the following:

#name of your VASP binary to call and number of processors to use
vasp_run="mpirun -np 1 vasp_gpu_mkl"
#Parent directory where the folders containing VASP settings files can be find
directory_path="/home/lebedmi2/DATA/VASP_data/Ti_test_structures/POSCARs"
After running the script:

Example of ‚directory_list.txt‚ file after it is being created and after 5 folders were already calculated.

Example of content of the generated ‚OUTPUT_END_of_CYCLES_LIST.txt‘ file after 5 folders were calculated: