Scripts¶
Example submission scripts for NUS HPC¶
atlas9 CPU node
#!/bin/bash
#PBS -j oe
#PBS -N jobname
#PBS -q parallel20
#PBS -l select=1:ncpus=20:mem=120gb
#PBS -l walltime=720:00:00
#-----------------------------------
## things you need to check
export VASPEXE="vasp_gam"
export VASP_FOLDER=/home/svu/NUSID/app/vasp/tiger2/bin/
export OMP_NUM_THREADS=1
cd ${PBS_O_WORKDIR}
source /etc/profile.d/rec_modules.sh
# geom relaxi
module load xe_2018
export LD_LIBRARY_PATH=$MKLROOT/lib/intel64:$LD_LIBRARY_PATH
cd ${PBS_O_WORKDIR}
lscpu | grep avx
if [ $? -eq 0 ]
then
export vasproot=$VASP_FOLDER/tiger2/bin/$VASPEXE
fi
lscpu | grep avx2
if [ $? -eq 0 ]
then
export vasproot=$VASP_FOLDER/atlas8/bin/$VASPEXE
fi
lscpu | grep avx512
if [ $? -eq 0 ]
then
export vasproot=$VASP_FOLDER/atlas9/bin/$VASPEXE
fi
echo `date` "Starting relaxation ..." >> status.txt
if [ ! -f vasprun.xml.relaxed.gz ]
then
if [ ! -s POSCAR.orig ]
then
echo `date` "Backuping POSCAR to POSCAR.orig ....." >> status.txt
cp POSCAR POSCAR.orig
fi
if [ -s CONTCAR ]
then
echo `date` "Found CONTCAR... Copying CONTCAR to POSCAR and continuing relaxation ...." >> status.txt
cp CONTCAR POSCAR
fi
echo `date` "Running VASP" >> status.txt
mpirun -n 20 $vasproot >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`tail -1 OSZICAR | cut -c 1-4`
grep "Inconsistent Bravais lattice types found for crystalline" OUTCAR
if [ $? -eq 0 ]
then
echo "SYMPREC = 1e-08" >> INCAR
fi
while [ ${rel} -gt 10 ]; do
cp CONTCAR POSCAR
rm WAVECAR CHG*
echo `date` "Running VASP " >> status.txt
mpirun -n 20 $vasproot >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`grep -v '^$' OSZICAR| tail -1 | cut -c 1-4`
if [ ${rel} -gt 10 ]
then
echo `date` "No. of ionic steps ${rel} doesn't meet the requirement (<10), restarting ....." >> status.txt
fi
done
if [ ${rel} -le 10 ]
then
echo `date` "Relaxation finished!" >> status.txt
mv CONTCAR CONTCAR.relaxed
mv DOSCAR DOSCAR.relaxed
mv EIGENVAL EIGENVAL.relaxed
mv IBZKPT IBZKPT.relaxed
mv INCAR INCAR.relaxed
mv KPOINTS KPOINTS.relaxed
mv OSZICAR OSZICAR.relaxed
mv OUTCAR OUTCAR.relaxed
mv POSCAR POSCAR.relaxed
mv PROCAR PROCAR.relaxed
mv vasprun.xml vasprun.xml.relaxed
mv vasp.out vasp.out.relaxed
rm WAVECAR CHG*
echo `date` "Ending job ..." >> status.txt
gzip -f *
exit 0
else
echo `date` "Error or unfinished job!" >> status.txt
exit 1
fi
else
echo `date` "vasprun.xml.relaxed.gz exist, skip this calculation ....." >> status.txt
exit 0
fi
volta GPU node
#!/bin/bash
#PBS -P volta_pilot
#PBS -j oe
#PBS -N jobname
#PBS -q volta_gpu
#PBS -l select=1:ncpus=10:mem=95gb:ngpus=2
#PBS -l walltime=72:00:00
#-----------------------------------
## things you need to check
export OMP_NUM_THREADS=4 # use omp=5 with great care! use `top -d 0.5` to see if the CPU percentage ever go above 100%. IF it >isrunning sometimes at around 400% sometimes, then it is working probably
export CONTAINER_PATH=/hpctmp/NUSNETID/container/nushpc_volta_nvhpc24.3_cuda12.3_6.4.3.sif
# change the directory to your sif container
export VASP_EXE_LOW=/opt/vasp.6.4.3/bin/vasp_gam
export VASP_EXE_HIGH=/opt/vasp.6.4.3/bin/vasp_std
#-----------------------------------
## parameters that generally don't need to change
export OMPI_MCA_hwloc_base_binding_policy=none
export OMP_STACK_SIZE=4096m
cd ${PBS_O_WORKDIR}
echo `date` "Starting relaxation ..." >> status.txt
if [ ! -f vasprun.xml.relaxed.gz ]
then
if [ ! -s POSCAR.orig ]
then
echo `date` "Backuping POSCAR to POSCAR.orig ....." >> status.txt
cp POSCAR POSCAR.orig
fi
if [ -s CONTCAR ]
then
echo `date` "Found CONTCAR... Copying CONTCAR to POSCAR and continuing relaxation ...." >> status.txt
cp CONTCAR POSCAR
fi
grep "NSW = 400" INCAR
if [ $? -eq 0 ]
then
echo `date` "Copying CONTCAR to POSCAR and continuing relaxation with ENCUT=400" >> status.txt
singularity exec ${CONTAINER_PATH} mpirun -n 2 $VASP_EXE_LOW >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`tail -1 OSZICAR | cut -c 1-4`
while [ ${rel} -gt 10 ]; do
echo `date` "Copying CONTCAR to POSCAR and continuing relaxation with ENCUT=400" >> status.txt
cp CONTCAR POSCAR
echo `date` "Running VASP with low precision: ENCUT=400 and KPOINTS=4, this aims for a fast relaxation. Will be switching to >higher precision" >> status.txt
grep "Inconsistent Bravais lattice types found for crystalline" OUTCAR
if [ $? -eq 0 ]
then
echo "Inconsistent lattice types error, add SYMPREC=1e-08" >> status.txt
echo "SYMPREC = 1e-08" >> INCAR
fi
singularity exec ${CONTAINER_PATH} mpirun -n 2 $VASP_EXE_LOW >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`tail -1 OSZICAR | cut -c 1-4`
if [ ${rel} -gt 10 ]
then
echo `date` "No. of ionic steps ${rel} doesn't meet the requirement (<10), restarting ....." >> status.txt
fi
done
if [ ${rel} -le 10 ]
then
echo `date` "the ionic steps take less than 10 steps to converge. Now switch to high precision mode."
sed 's/ENCUT = 400/ENCUT = 520/g' INCAR > INCAR.tmp
cp INCAR.tmp INCAR
cp ../KPOINTS.precise KPOINTS
else
echo `date` "Error or unfinished job!" >> status.txt
exit 1
fi
fi
echo `date` "Running VASP with high precision" >> status.txt
singularity exec ${CONTAINER_PATH} mpirun -n 2 $VASP_EXE_HIGH >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`tail -1 OSZICAR | cut -c 1-4`
grep "Inconsistent Bravais lattice types found for crystalline" OUTCAR
if [ $? -eq 0 ]
then
echo "Inconsistent lattice types error, add SYMPREC=1e-08" >> status.txt
echo "SYMPREC = 1e-08" >> INCAR
fi
while [ ${rel} -gt 10 ]; do
cp CONTCAR POSCAR
rm WAVECAR CHG*
echo `date` "Running VASP " >> status.txt
singularity exec ${CONTAINER_PATH} mpirun -n 2 $VASP_EXE_HIGH >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`grep -v '^$' OSZICAR| tail -1 | cut -c 1-4`
grep "Inconsistent Bravais lattice types found for crystalline" OUTCAR
if [ $? -eq 0 ]
then
echo "Inconsistent lattice types error, add SYMPREC=1e-08" >> status.txt
echo "SYMPREC = 1e-08" >> INCAR
fi
if [ ${rel} -gt 10 ]
then
echo `date` "No. of ionic steps ${rel} doesn't meet the requirement (<10), restarting ....." >> status.txt
fi
done
if [ ${rel} -le 10 ]
then
echo `date` "Relaxation finished!" >> status.txt
mv CONTCAR CONTCAR.relaxed
mv DOSCAR DOSCAR.relaxed
mv EIGENVAL EIGENVAL.relaxed
mv IBZKPT IBZKPT.relaxed
mv INCAR INCAR.relaxed
mv KPOINTS KPOINTS.relaxed
mv OSZICAR OSZICAR.relaxed
mv OUTCAR OUTCAR.relaxed
mv POSCAR POSCAR.relaxed
mv PROCAR PROCAR.relaxed
mv vasprun.xml vasprun.xml.relaxed
mv vasp.out vasp.out.relaxed
rm WAVECAR CHG*
echo `date` "Ending job ..." >> status.txt
gzip -f *
exit 0
else
echo `date` "Error or unfinished job!" >> status.txt
exit 1
fi
else
echo `date` "vasprun.xml.relaxed.gz exist, skip this calculation ....." >> status.txt
exit 0
fi
Submission scripts for ALF project on NUS HPC¶
Submission script for running VASP single point calculation using GPU
#!/bin/bash
#PBS -P volta_pilot
#PBS -j oe
#PBS -N jobname
#PBS -q volta_gpu
#PBS -l select=1:ncpus=10:mem=95gb:ngpus=1
#PBS -l walltime=72:00:00
export OMPI_MCA_hwloc_base_binding_policy=none
export OMP_STACK_SIZE=4096m
source /etc/profile.d/rec_modules.sh
module add singularity/3.8.3
export vasp_gam=/opt/vasp/bin/vasp_gam
export vasp_std=/opt/vasp/bin/vasp_std
export OMP_NUM_THREADS=4 # use omp=5 with great care! use `top -d 0.5` to see if the CPU >percentage ever go above >100%. IF it is running sometimes at around 400% sometimes, then it >is working probably
export singularity_exec="singularity exec --nv /home/svu/msedz/nushpc_volta_nvhpc24.3_cuda12.3_6.4.3.sif mpirun -n 1" #change this line to your own directory
cd ${PBS_O_WORKDIR}
$singularity_exec $vasp_std > vasp.out
Submission script for running VASP relaxation using 2 GPUs
#!/bin/bash
#PBS -P volta_pilot
#PBS -j oe
#PBS -N jobname
#PBS -q volta_gpu
#PBS -l select=1:ncpus=10:mem=95gb:ngpus=2
#PBS -l walltime=72:00:00
#-----------------------------------
## things you need to check
export OMP_NUM_THREADS=4 # use omp=5 with great care! use `top -d 0.5` to see if the CPU >percentage ever go above 100%. IF it is running sometimes at around 400% sometimes, then it >is working probably
export vasp_gam=/opt/vasp/bin/vasp_gam
export vasp_std=/opt/vasp/bin/vasp_std
export singularity_exec="singularity exec --nv /home/svu/msedz/nushpc_volta_nvhpc24.3_cuda12.3_6.4.3.sif mpirun -n 2" #change this line to your own directory
#-----------------------------------
source /etc/profile.d/rec_modules.sh
module add singularity/3.8.3
export OMPI_MCA_hwloc_base_binding_policy=none
export OMP_STACK_SIZE=4096m
cd ${PBS_O_WORKDIR}
echo `date` "Running VASP ..." >> status.txt
$singularity_exec $vasp_std >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`tail -1 OSZICAR | cut -c 1-4`
grep "Inconsistent Bravais lattice types found for crystalline" OUTCAR
if [ $? -eq 0 ]
then
echo "Inconsistent lattice types error, add SYMPREC=1e-08" >> status.txt
echo "SYMPREC = 1e-08" >> INCAR
fi
while [ ${rel} -gt 10 ]; do
cp CONTCAR POSCAR
rm WAVECAR CHG*
echo `date` "Running VASP " >> status.txt
$singularity_exec $vasp_std >> vasp.out
echo `date` `tail -n -1 OSZICAR` >> status.txt
rel=`grep -v '^$' OSZICAR| tail -1 | cut -c 1-4`
grep "Inconsistent Bravais lattice types found for crystalline" OUTCAR
if [ $? -eq 0 ]
then
echo "Inconsistent lattice types error, add SYMPREC=1e-08" >> status.txt
echo "SYMPREC = 1e-08" >> INCAR
fi
if [ ${rel} -gt 10 ]
then
echo `date` "No. of ionic steps ${rel} doesn't meet the requirement (<10), >restarting ....." >> status.txt
fi
done
if [ ${rel} -le 10 ]
then
echo `date` "Relaxation finished!" >> status.txt
mv CONTCAR CONTCAR.relaxed
mv DOSCAR DOSCAR.relaxed
mv EIGENVAL EIGENVAL.relaxed
mv IBZKPT IBZKPT.relaxed
mv INCAR INCAR.relaxed
mv KPOINTS KPOINTS.relaxed
mv OSZICAR OSZICAR.relaxed
mv OUTCAR OUTCAR.relaxed
mv POSCAR POSCAR.relaxed
mv PROCAR PROCAR.relaxed
mv vasprun.xml vasprun.xml.relaxed
mv vasp.out vasp.out.relaxed
rm WAVECAR CHG*
echo `date` "Ending job ..." >> status.txt
gzip -f *
exit 0
else
echo `date` "Error or unfinished job!" >> status.txt
exit 1
fi
else
echo `date` "vasprun.xml.relaxed.gz exist, skip this calculation ....." >> status.txt
exit 0
fi
Python scripts for ALF project¶
Pymatgen to generate input files of VASP
from pymatgen.core import Structure
from pymatgen.io.vasp.sets import MITRelaxSet
incar_dict = { 'EDIFFG': -1e-2, 'IVDW': 11, 'ISYM':2,'NSW':1500, 'ENCUT':520}
structure = Structure.from_file("Al_empty.cif")
inputset = MITRelaxSet(structure = structure,user_incar_settings=incar_dict,
user_kpoints_settings={'length':25})
inputset.write_input(output_dir='./DFT_calc',include_cif=True)
Script to gather VASP output data
#!/usr/bin/env python
'''
This code is used for gathering DFT data as extxyz format using ASE >and pymatgen
Zeyu Deng
dengzeyu@gmail.com
'''
from ase.io import read
import os
from pymatgen.io.vasp import Vasprun
from pymatgen.io.vasp import Outcar
import logging
def gather_data(fname_output:str='data.extxyz',
calc_dir:str='./',
exclude:str='quickrelax',
read_magmom:bool=False,
outcar_name:str='OUTCAR.gz',
vasprun_name:str='vasprun.xml.gz')->None:
'''Gather DFT data as extxyz format using ASE and pymatgen
Parameters:
fname_output (str): The name of the output file in extxyz >format. Default is 'data.extxyz'.
calc_dir (str): The directory where the calculations are >stored. Default is './'.
exclude (str): The string to exclude certain files from >gathering. Default is 'quickrelax'.
read_magmom (bool): Whether to read magnetic moments from >OUTCAR file. Default is False.
outcar_name (str): The name of the OUTCAR file. Default is >'OUTCAR.gz'.
vasprun_name (str): The name of the vasprun.xml file. Default >is 'vasprun.xml.gz'.
Returns:
None
'''
vasprun_filenames = []
for path, subdirs, files in os.walk(calc_dir):
for name in files:
if vasprun_name in name and exclude not in name:
vasprun_filenames.append(os.path.join(path, name))
for vasprun_fname in vasprun_filenames:
try:
logger.info(f"Reading {vasprun_fname}")
vasprun = Vasprun(vasprun_fname)
except:
logger.exception(f"Error while reading {vasprun_fname}!")
continue
path_name = os.path.dirname(vasprun_fname)
structure_name = vasprun_fname.strip().split('/')[-2]
logger.info('checking {}'.format(structure_name))
if vasprun.converged:
atoms=read(vasprun_fname, format='vasp-xml')
atoms.info['name']=structure_name
atoms.info['path_name']=path_name
if not read_magmom:
try:
atoms.write(fname_output,format='extxyz',>append='a')
except:
logger.exception('Error while reading {}, skip..'.>format(outcar_name))
pass
else:
try:
logger.info(f"Reading {os.path.join(path_name,>outcar_name)}")
magnetization = [mag['tot'] for mag in Outcar(os.>path.join(path_name,outcar_name)).magnetization]
atoms.set_initial_magnetic_moments(magmoms = >magnetization)
atoms.write(fname_output,format='extxyz',>append='a')
except:
logger.exception('Error while reading {}, skip..'.>format(outcar_name))
pass
else:
logger.exception("-> {} not converged!".format>(structure_name))
logger = logging.getLogger()
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
gather_data(fname_output='data.extxyz',
calc_dir='/path/to/data',
exclude='quickrelax',
read_magmom=True,
outcar_name='OUTCAR.relaxed.gz',
vasprun_name='vasprun.xml.relaxed.gz')