-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathphono3py-get-kappa
140 lines (99 loc) · 4.1 KB
/
phono3py-get-kappa
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
# -------
# Imports
# -------
import csv
import os
import numpy as np
from argparse import ArgumentParser
from Phono3pyPowerTools.Phono3pyIO import Phono3pyKappaHDF5
from Phono3pyPowerTools.Utilities import OpenForCSVWriter
# ----
# Main
# ----
if __name__ == "__main__":
# Command-line arguments.
parser = ArgumentParser(
description = "Get k_latt(T) from Phono3py kappa-*.hdf5 files and save to CSV"
)
parser.add_argument(
metavar = "input_file",
nargs = '+', dest = 'InputFiles',
help = "Phono3py kappa-*.hdf5 files to read"
)
parser.add_argument(
"-o", "--output-file",
metavar = "output_file",
dest = "OutputFile",
help = "Output file to write (single input file only)"
)
args = parser.parse_args()
# Sanity check.
if args.OutputFile is not None and len(args.InputFiles) > 1:
raise Exception("Error: The -o/--output-file option can only be used when one input file is specified.")
# Loop over input files.
for input_file in args.InputFiles:
# Load input file.
kappa_hdf5 = Phono3pyKappaHDF5(input_file)
# Prepare output data.
header_row = [
"T [K]",
"k_xx [W/m.K]", "k_yy [W/m.K]", "k_zz [W/m.K]",
"k_yz [W/m.K]", "k_xz [W/m.K]", "k_xy [W/m.K]",
"k_iso [W/m.K]"
]
output_data = []
temps = kappa_hdf5.GetTemperature()
if kappa_hdf5.IsLBTE:
if kappa_hdf5.IsWigner:
# LBTE calculation with Wigner correction.
output_data = [
(temps, kappa_hdf5.GetKappa(wigner_mode = 'k_p'), "K_P_LBTE"),
(temps, kappa_hdf5.GetKappa(lbte_rta = True, wigner_mode = 'k_p'), "K_P_RTA"),
(temps, kappa_hdf5.GetKappa(wigner_mode = 'k_c'), "K_C"),
(temps, kappa_hdf5.GetKappa(wigner_mode = 'k_tot'), "K_Tot_LBTE"),
(temps, kappa_hdf5.GetKappa(lbte_rta = True, wigner_mode = 'k_tot'), "K_Tot_RTA"),
]
else:
# LBTE calculation.
output_data = [
(temps, kappa_hdf5.GetKappa(), "LBTE"),
(temps, kappa_hdf5.GetKappa(lbte_rta = True), "RTA")
]
else:
# RTA calculation with Wigner correction.
if kappa_hdf5.IsWigner:
output_data = [
(temps, kappa_hdf5.GetKappa(wigner_mode = 'k_p'), "K_P"),
(temps, kappa_hdf5.GetKappa(wigner_mode = 'k_c'), "K_C"),
(temps, kappa_hdf5.GetKappa(wigner_mode = 'k_tot'), "K_Tot")
]
else:
# RTA calculation.
output_data = [
(temps, kappa_hdf5.GetKappa(), None)
]
for temps_out, kappa_out, output_suffix in output_data:
data_rows = []
for t, k in zip(temps_out, kappa_out):
k_iso = np.mean(k[:3])
data_rows.append(
[t] + [k_ab for k_ab in k] + [k_iso]
)
# Name for output file.
output_file = args.OutputFile
if output_file is None:
# Generate an output file name based on the input file:
# kappa-m*.hdf5 --> kappa-m*.csv
_, tail = os.path.split(input_file)
root, _ = os.path.splitext(tail)
output_file = r"{0}.csv".format(root)
if output_suffix is not None:
root, ext = os.path.splitext(output_file)
output_file = "{0}.{1}{2}".format(root, output_suffix, ext)
# Write output file.
with OpenForCSVWriter(output_file) as output_writer:
output_writer_csv = csv.writer(output_writer)
output_writer_csv.writerow(header_row)
for data_row in data_rows:
output_writer_csv.writerow(data_row)