Skip to content

Instantly share code, notes, and snippets.

@utf
Created Aug 20, 2021
Embed
What would you like to do?
#! /usr/bin/awk -f
#
# Name: Extract elastic constant tensor
# Author: Alex Ganose
# Version: 1.0
# Date: 20/08/21
# Usage: elastic [OUTCAR]
/TOTAL ELASTIC MODULI/ {
l = NR
}
(NR == l + 3) {
C1111 = $2 / 10
C1122 = $3 / 10
C1133 = $4 / 10
C1112 = $5 / 10
C1123 = $6 / 10
C1131 = $7 / 10
}
(NR == l + 4) {
C2211 = $2 / 10
C2222 = $3 / 10
C2233 = $4 / 10
C2212 = $5 / 10
C2223 = $6 / 10
C2231 = $7 / 10
}
(NR == l + 5) {
C3311 = $2 / 10
C3322 = $3 / 10
C3333 = $4 / 10
C3312 = $5 / 10
C3323 = $6 / 10
C3331 = $7 / 10
}
(NR == l + 6) {
C1211 = $2 / 10
C1222 = $3 / 10
C1233 = $4 / 10
C1212 = $5 / 10
C1223 = $6 / 10
C1231 = $7 / 10
}
(NR == l + 7) {
C2311 = $2 / 10
C2322 = $3 / 10
C2333 = $4 / 10
C2312 = $5 / 10
C2323 = $6 / 10
C2331 = $7 / 10
}
(NR == l + 8) {
C3111 = $2 / 10
C3122 = $3 / 10
C3133 = $4 / 10
C3112 = $5 / 10
C3123 = $6 / 10
C3131 = $7 / 10
}
END {
if (l > 1) {
print "elastic_constant:"
printf " - [ %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f ]\n", C1111, C1122, C1133, C1123, C1131, C1112
printf " - [ %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f ]\n", C2211, C2222, C2233, C2223, C2231, C2212
printf " - [ %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f ]\n", C3311, C3322, C3333, C3323, C3331, C3312
printf " - [ %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f ]\n", C2311, C2322, C2333, C2323, C2331, C2312
printf " - [ %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f ]\n", C3111, C3122, C3133, C3123, C3131, C3112
printf " - [ %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f ]\n", C1211, C1222, C1233, C1223, C1231, C1212
} else {
print "ERROR: No elastic tensor found"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment