Repository navigation
Expand file tree
/
Copy pathrun_vasp.sh
More file actions
125 lines (112 loc) · 5.26 KB
/
Copy pathrun_vasp.sh
File metadata and controls
125 lines (112 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
vasp_run="mpirun -np 8 vasp_cpu_mkl"
directory_path="/home/lebedmi2/DATA/VASP_data/Ti_test_structures/INT_0_1/POSCARs" # Update with your directory path
# Signal handler for SIGINT
function handle_sigint() {
echo "Script interrupted by user, exiting."
exit 1 # Exit script immediately
}
# Trap SIGINT (Control+C) and call handle_sigint
trap handle_sigint SIGINT
#Checking if the files with names of VASP directories exists. If yes, do not create it but continue with its content
if [ ! -f "directory_list.txt" ]; then
search_dir="$directory_path" # Ensure this variable is defined before running the script
dir_list="directory_list.txt"
touch "$dir_list" # This is optional since '>>' will create the file if it doesn't exist
for dir in "$search_dir"/*; do
if [ -d "$dir" ]; then
echo "FOUND DIR: $(basename "$dir")"
echo "$(basename "$dir")" >> "$dir_list"
fi
done
# Sort the directory list after collecting all directory names
temp_file=$(mktemp)
sort -V -t '_' -k 1,1 "$dir_list" > "$temp_file"
mv "$temp_file" "$dir_list"
else
# The file exists, inform the user
echo -e "The file 'directory_list.txt' with names of folders on which to run VASP calculations already exists.\nContinuing with it."
fi
vasp_file_name="OSZICAR" # Update with your vasp file name
directories_file="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)/directory_list.txt"
start_dir=$(pwd)
output_file="${directory_path}/OUTPUT_END_of_CYCLES_LIST.txt"
if [ ! -f "${directory_path}/OUTPUT_END_of_CYCLES_LIST.txt" ]; then
echo "Does not exists, creating."
echo -e "#FOLDER_NAME\tLAST_DAV_CYCLE\tCONVERGED?\tNELM\tENERGY[eV]\tTIME[min]" > "$output_file"
fi
mapfile -t dir_names < "$directories_file"
# Loop over the array of directory names
# Loop over directories in directory_path
#while IFS= read -r dir_name; do
for dir_name in "${dir_names[@]}"; do
folder_path="${directory_path}/$dir_name"
if [ -d "$folder_path" ]; then # Ensure it's a directory
cd "$folder_path"
echo -e "\n\n\n===================================== STARTING VASP CALCULATIONS ====================================="
echo "$folder_path"
echo "====================================================================================================="
start_time=$(date +%s)
$vasp_run
echo "===================================== CALCULATIONS FINISHED ====================================="
echo -e "=====================================================================================================\n\n\n"
# Check if vasp_file_name exists in h
if [ -f "$vasp_file_name" ]; then
echo "FOUND FILE $vasp_file_name in FOLDER $folder_name"
# Get the last and second last lines of the file
last_line=$(tail -n 1 "$vasp_file_name")
second_last_line=$(tail -n 2 "$vasp_file_name" | head -n 1)
# Split the lines into arrays
read -ra last_line_arr <<< "$last_line"
read -ra second_last_line_arr <<< "$second_last_line"
echo "$last_line"
echo "$second_last_line"
# Check if the last_line_arr[1] is a number
echo "${last_line_arr[1]}"
NELM=$(grep "^NELM" INCAR | awk '{print $3}')
if [ -z "$NELM" ]; then
NELM=60
fi
echo "NELM value: $NELM"
if [[ "${last_line_arr[1]}" == "F=" ]]; then
if [ "${last_line_arr[1]}" == "F=" ]; then
if [[ "${second_last_line_arr[1]}" == "$NELM" ]]; then
cycle_finished_yes_no="NO"
cycle_number="${second_last_line_arr[1]}"
nelm=$NELM
ener="${last_line_arr[2]}"
else
nelm=$NELM
ener="${last_line_arr[2]}"
cycle_finished_yes_no="YES"
cycle_number="${second_last_line_arr[1]}"
fi
else
ener="${last_line_arr[2]}"
cycle_finished_yes_no="NO_$NELM"
cycle_number="${last_line_arr[1]}"
fi
else
# If last_line_arr[1] is not a number, set cycle_number to zero
cycle_finished_yes_no="NO_STOPPED"
cycle_number="0"
fi
cd "$start_dir" || exit
# Append to output file
end_time=$(date +%s) # Get end time of the loop iteration
duration=$(echo "scale=2; ($end_time - $start_time) / 60" | bc)
echo -e "$folder_path\t$cycle_number\t$cycle_finished_yes_no\t$nelm\t$ener\t$duration" >> "$output_file"
sed -i "/^$dir_name$/d" "$directories_file"
else
echo "------- NOT FOUND $vasp_file_name in FOLDER $(basename "$folder_name") -------"
cd "$start_dir" || exit
# Append to output file
end_time=$(date +%s) # Get end time of the loop iteration
duration=$(echo "scale=2; ($end_time - $start_time) / 60" | bc)
echo -e "$folder_path\t0\tNO\tERROR\tERROR\t$duration" >> "$output_file"
sed -i "/^$dir_name$/d" "$directories_file"
fi
fi
done
rm -f $directories_file
echo "FINISHED. OUTPUT IS IN THE FILE: $output_file"