Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Setup

Before running the workflows in the aiida-pl package, you need to set up the computers, codes and pseudo potentials. This notebook takes you through all the necessary steps to do so.

from aiida import orm, load_profile
from aiida.common.exceptions import NotExistent

load_profile()

Computers

First we’ll set up the computers for AiiDA to run on. For this AiiDA needs to know the “working directory” on the remote computer

working_directory = '/scratch/pawsey1141/mbercx/aiida-defect/aiida'

The cell below configures two computers:

The “transport” that we’ll use (identified via core.ssh_async) will automatically use the configuration from your ~/.ssh/config. Hence the instructions below assume that you’ve already set up you connection with the computer.

try:
    pawsey = orm.load_computer('pawsey')
except NotExistent:
    pawsey = orm.Computer(
        label='pawsey',
        hostname='setonix.pawsey.org.au',
        transport_type='core.ssh_async',
        scheduler_type='core.slurm',
    )
    pawsey.set_workdir(working_directory)
    pawsey.set_mpirun_command('srun -N {num_machines} -n {tot_num_mpiprocs} -c 1 -m block:block:block'.split())
    pawsey.set_default_mpiprocs_per_machine(64)
    pawsey.set_use_double_quotes(True)
    pawsey.configure()
    pawsey.store()

try:
    pawsey_direct = orm.load_computer('pawsey-direct')
except NotExistent:
    pawsey_direct = orm.Computer(
        label='pawsey-direct',
        hostname='setonix.pawsey.org.au',
        transport_type='core.ssh_async',
        scheduler_type='core.direct',
    )
    pawsey_direct.set_workdir(working_directory)
    pawsey_direct.set_default_mpiprocs_per_machine(1)
    pawsey_direct.set_use_double_quotes(True)
    pawsey_direct.configure()
    pawsey_direct.store()

We can see if the computers have been set up properly using the CLI command:

!verdi computer list

As well as test them:

!verdi computer test pawsey

Codes

Next, we’ll set up the VASP codes we need to run on pawsey. We’ll need to run both the vasp_gam and vasp_std version, which we’ll set up as separate codes:

try:
    orm.load_code('vasp-6.5.1_gam@pawsey')
except NotExistent:
    code = orm.InstalledCode(
        label='vasp-6.5.1_gam',
        computer=pawsey,
        default_calc_job_plugin='vasp.vasp',
        filepath_executable='/software/projects/pawsey1141/cverdi/vasp.6.5.1/bin/vasp_gam'
    )
    code.description = 'VASP 6.5.1 gamma version'
    code.use_double_quotes = True
    code.prepend_text = """
module load hdf5/1.14.3-api-v112 netlib-scalapack/2.2.0 fftw/3.3.10
export OMP_NUM_THREADS=1
export MPICH_OFI_STARTUP_CONNECT=1
export MPICH_OFI_VERBOSE=1
export FI_CXI_DEFAULT_VNI=$(od -vAn -N4 -tu < /dev/urandom)
ulimit -s unlimited
"""
    code.store()

try:
    orm.load_code('vasp-6.5.1_std@pawsey')
except NotExistent:
    code = orm.InstalledCode(
        label='vasp-6.5.1_std',
        computer=pawsey,
        default_calc_job_plugin='vasp.vasp',
        filepath_executable='/software/projects/pawsey1141/cverdi/vasp.6.5.1/bin/vasp_std'
    )
    code.description = 'VASP 6.5.1 gamma version'
    code.use_double_quotes = True
    code.prepend_text = """
module load hdf5/1.14.3-api-v112 netlib-scalapack/2.2.0 fftw/3.3.10
export OMP_NUM_THREADS=1
export MPICH_OFI_STARTUP_CONNECT=1
export MPICH_OFI_VERBOSE=1
export FI_CXI_DEFAULT_VNI=$(od -vAn -N4 -tu < /dev/urandom)
ulimit -s unlimited
"""
    code.store()

We need to be able to calculate the transition dipole moments (TDMs) using vaspkit. The simple bash script below wraps vaspkit to calculate all TDMs for a range of “target levels”

vaspkit_script = """
#!/usr/bin/env bash
set -e

MIN_INDEX="$1"
MAX_INDEX="$2"
TARGET_DIR="$3"

CURR_DIR="$(pwd)"

if [ -n "$TARGET_DIR" ]; then
    cd "$TARGET_DIR"
fi

for target_level in $(seq "$MIN_INDEX" "$MAX_INDEX"); do
    for source_level in $(seq 1 $((target_level - 1))); do
        echo "Running vaspkit for index $idx..."
        (
            echo -e "71\n713\n0\n${source_level} ${target_level}\n1" | vaspkit
            echo "$source_level $target_level" >> "$CURR_DIR/tdm_dw.dat"
            echo "$source_level $target_level" >> "$CURR_DIR/tdm_up.dat"
            cat TDM_COMPONENTS_DW.dat >> "$CURR_DIR/tdm_dw.dat"
            cat TDM_COMPONENTS_UP.dat >> "$CURR_DIR/tdm_up.dat"
        )
    done
done

if [ -n "$TARGET_DIR" ]; then
    cd "$CURR_DIR"
fi

"""

In our current approach, the script needs to be available on the remote machine. We could also copy the script for every execution, but that seems unnecessary. The cells below take care of copying the script to the remote and

script_directory = '/home/mbercx/aiida-scripts'
script_filename = 'get_tdm.sh'
from pathlib import Path

script_directory = Path(script_directory)
tdm_script_path = Path(script_filename).absolute()

with tdm_script_path.open('w') as handle:
    handle.write(vaspkit_script)

with pawsey.get_transport() as transport:
    transport.makedirs(script_directory, ignore_existing=True)
    transport.put(tdm_script_path, script_directory)
    transport.chmod(script_directory / script_filename, 0o700)
from aiida_shell import ShellCode

try:
    orm.load_code('get_tdm@pawsey-direct')
except NotExistent:
    code = ShellCode(
        label='get_tdm',
        computer=pawsey_direct,
        filepath_executable=f'{script_directory}/{script_filename}'
    )
    code.use_double_quotes = True
    code.store()

Let’s make sure we have all codes set up properly!

!verdi code list

You should see something along the lines of:

Full label               Pk  Entry point
---------------------  ----  -------------------------
vasp-6.5.1_gam@pawsey     1  core.code.installed
vasp-6.5.1_std@pawsey     2  core.code.installed
get_tdm@pawsey-direct     3  core.code.installed.shell

Pseudo potentials

In order to set up the input POTCAR files, the aiida-vasp plugin needs access to the VASP pseudo potentials.

path_to_potcar_files = '/Users/mbercx/tmp/potpaw'

The cell below loads the pseudo potentials from the path specified above. Since you can only upload them once, we once again wrap the cell in a try-except block.

from aiida_vasp.data.potcar import PotcarData

try:
    orm.load_group('PBE.64')
except NotExistent:
    PotcarData.upload_potcar_family(
        source=path_to_potcar_files,
        group_name='PBE.64',
        group_description='Family of the v64 pseudo potentials for VASP.'
    );

We can confirm that the pseudo potentials have been installed properly using:

!verdi data vasp.potcar listfamilies

You should see PBE.64 among the list of families. If so, time to move on to the “Energy levels workflow”!