Phono3py batch order to run conductivity:

1) In running directory store files: 
POSCAR  POTCAR KPOINTS KPOINTS 
and batch job for runnong VASP:
vasp_rundef.sh
 
2)The order of running jobs is:
phooo3pydispfc2fc3.sh 
phono3pyprepfc2fc3.sh
submitdispxxxfc2fc3defused.sh
phono3pycollectfc2fc3.sh
phono3pyhdffc2fc3.sh
phono3pythconductsig444.sh

3) The listing of used batch jobs:
vi vasp_rundef.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phonopy_UC2
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=64
#SBATCH --mem=0
#SBATCH --time=18:00:00

# Load the modules:
# local Barbara
module load  StdEnv/2023  intel/2023.2.1  intelmpi/2021.9.0 vasp/6.5.0

srun vasp_std

vi phono3pydispfc2fc3.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phono3py_UC2
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=1
#SBATCH --mem=0
#SBATCH --time=1:00:00

#module load StdEnv/2020 scipy-stack
# to fix numpy error on Narval add this line
#module load python/3.8.10 scipy-stack/2021a hdf5/1.12.1

module load StdEnv/2023
module load python/3.13.2

source ~/phono3py_env/bin/activate
#generate displacements
phono3py -d --dim="2 2 2" -c POSCAR
#To reduce number of displacement files use cut off
#phono3py --cutoff-pair=2  -d  --dim-fc2="2 2 2" --dim="2 2 2" -c POSCAR

vi phonpyprepfc2fc3.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phono3py_UC2Phono3py
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=1
#SBATCH --mem=0
#SBATCH --time=1:00:00

P='/home/szpunarb/scratch/VASPUC2fcc/UC2Phonopy3calcfc2fc3'
#    With zsh,
    for i in `ls POSCAR-0*|sed s/POSCAR-//`;
    do
    cd $P
    mkdir disp-$i
    cd  disp-$i
    cp ../KPOINTS .
    cp ../INCAR .
    cp ../POTCAR .
    cp ../POSCAR-$i POSCAR
         echo $i
    done

vi submitdispxxxfc2fc3defused.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phonopy_UO2
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=4
#SBATCH --mem=0
#SBATCH --time=64:00:00

P='/home/szpunarb/scratch/VASPUC2fcc/UC2Phonopy3calcfc2fc3'

# number of displacements
#poc=9
#    for i in `seq 1 $poc `;
#    do
#    cd $P
#    cd disp-0000"$i"
#    cp ../vasp_runadm.sh .
#    sbatch vasp_runadm.sh
#    echo $i
#    done

    for i in `ls POSCAR-0*|sed s/POSCAR-//`;
    do
    cd $P
    cd disp-$i
    cp ../vasp_rundef.sh .
    sbatch vasp_rundef.sh
    echo $i
    done


vi phono3pycollectfc2fc3.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phono3py_UC2
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=64
#SBATCH --mem=0
#SBATCH --time=48:00:00

#module load StdEnv/2020 scipy-stack
# to fix numpy error on Narval add this line
#module load python/3.8.10 scipy-stack/2021a hdf5/1.12.1

module load StdEnv/2023
module load python/3.13.2

source ~/phono3py_env/bin/activate
#phono3py --cf3 disp-{00001..00111}/vasprun.xml
for i in `ls POSCAR-0*|sed s/POSCAR-//`;
do echo disp-$i/vasprun.xml;done > file_list.dat
phono3py --cf3-file file_list.dat
#Not needed
#phono3py --cf2 disp_fc2-{00001..00024}/vasprun.xml

If you have POSCAR in this directory, rename it before running next, e.g.:
mv POSCAR SpPOSCAR

vi phono3pyhdffc2fc3.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phono3py_UC2
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=1
#SBATCH --mem=0
#SBATCH --time=1:00:00

#module load StdEnv/2020 scipy-stack
# to fix numpy error on Narval add this line
#module load python/3.8.10 scipy-stack/2021a hdf5/1.12.1

module load StdEnv/2023
module load python/3.13.2

source ~/phono3py_env/bin/activate
#phono3py --dim="2 2 2" -c POSCAR
phono3py --fc-symmetry

vi phono3pythconductsig121212.sh
#!/bin/bash -l
#SBATCH --job-name=VASP_phono3py_UC2
#SBATCH --account=def-szpunarb
#SBATCH --nodes=1
#SBATCH --tasks-per-node=64
#SBATCH --mem=0
#SBATCH --time=48:00:00

#module load StdEnv/2020 scipy-stack
# to fix numpy error on Narval add this line
#module load python/3.8.10 scipy-stack/2021a hdf5/1.12.1

module load StdEnv/2023
module load python/3.13.2

source ~/phono3py_env/bin/activate
#phono3py --fc3 --fc2 --dim="2 2 2" --mesh="4 4 4" -c POSCAR --br
# check for various meshes dependence on conductivity, 
#current version command:
#phono3py --mesh 4 4 4 --br
phono3py --mesh 12 12 12 --br


Check for commands' updates:
https://phonopy.github.io/phono3py/vasp.html
https://phonopy.github.io/phono3py/command-options.html

Note useful commands that work from the command line OK:
https://phonopy.github.io/phono3py/auxiliary-tools.html#phono3py-kaccum-cumulative-lattice-thermal-conductivity-and-related-properties that produced dat file:
phono3py-kaccum kappa-m444.hdf5 |tee kaccum.dat
and 
phono3py-kdeplot kappa-m444.hdf5
which output png file of lifetime density at 300 K.

Modify the last batch job to calculate the imaginary part of self energy (gamma) as listed in the above link and adapted below:

The gamma calculation at each grid point can be separately calculated since they are independent, and no communication is necessary during the computation. The procedure is as follows:

First run the same command with the addition option of --wgp:

phono3py --fc3 --fc2 --mesh 12 12 12 --br --wgp

ir_grid_points.yaml is obtained. Irreducible q-points are found in this file. The grid point indices of the irreducible q-points are not increasing by one when cutoff is used and can be printed using

$ grep grid_point: ir_grid_points.yaml|awk '{printf("%d ", $3)}'
0 1 2 3 4 5 6 7 8 9 20 21 22 23 24 25 26 27 28 40 41 42 43 44...
2326 2327  2355 2667 2668 2669 2687 2688 2716 3048 3049 3077 3627

Gammas for all (e.g. 146) irreducible grid points can be calculated on clusters and stored in kappa-m181818-g*.hdf5 files with --write-gamma option by:

$ phono3py --mesh 12 12 12 --br --write-gamma --gp  0 1 2 3 4 5 6 7 8 9 20 21 22 23 24.....2355 2667 2668 2669 2687 2688 2716 3048 3049 3077 3627

The produced HDF5 files contain:
    frequency 
    gamma 
    grid_
    group_velocity 
    gv_by_gv 
    heat_capacity 
    kappa_unit_conversion 
    mesh 
    temperature 
    version 

This command: To avoid HDF5 compression, set phono3py --hdf5-compression=None would be better updated to produce dat files that can be converted to csv.


After finishing distributed calculations at all irreducible grid points (0, 1, …, 146), run with --read-gamma option to calculate thermal conductivity (tetrahedron method):

% phono3py --fc3 --fc2 --mesh 12 12 12 --br --read-gamma

Once this calculation runs without problem, separately calculated hdf5 files on grid points can be converted to csv to view and lifetimes (tau) can be calculated from the relation:
tau = 1/2gamma.

Some links for conversions of hdf5 files to csv:

1) python script
python3 hdf2df.py data.hf > data.csv

#!/usr/bin/env python3
import pandas as pd
import sys
fpath = sys.argv[1]
if len(sys.argv)>2:
    key = sys.argv[2]
    df = pd.read_hdf(fpath, key=key)
else:
    df = pd.read_hdf(fpath)

df.to_csv(sys.stdout, index=False)

https://stackoverflow.com/questions/23758893/converting-hdf5-to-csv-or-tsv-files

2)https://convert.guru/h5-converter
https://www.hdfgroup.org/download-hdfview/

3) Matlab conversion hdf5 to csv commands:
data = h5read('your_file.h5', '/path/to/your/dataset');
writematrix(data, 'output.csv');

4) Reading HFD5 usng fortran and python:
https://www.admin-magazine.com/HPC/Articles/HDF5-with-Python-and-Fortran
https://www.icare.univ-lille.fr/reading-an-hdf-file/
https://juser.fz-juelich.de/record/908674/files/HDF5.pdf
https://support.hdfgroup.org/documentation/hdf5/latest/_view_tools_convert.html





