-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathKuruczMolecules.py
191 lines (131 loc) · 4.65 KB
/
KuruczMolecules.py
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import numpy as np
import math
import struct
import os
import argparse
# This script calculates the molecular line intensities
# It writes data files to prepare the HELIOS-K binary files
# Date: January 2022
# Author: Simon Grimm
#choose if the file contains wavenumber or not
Wavenumber = 2 #1: Wavenumber, 2: vacuum wavelength, 3: air based wavelenght
def main(name, mass, pfname, printA):
filename= '%s.asc' % name
outname = "%s.bin" % name
print(name, outname, mass)
output_file = open(outname,"wb")
numax = 0.0
nl = 0
if(printA == 1):
Afile = open("%s_A.dat" % name, "w")
with open(filename) as f:
line = f.readlines()
for ii in range(len(line)):
l = line[ii]
#E in cm^-1
#atomic line list format
if(Wavenumber == 1):
wn = float(l[0:10])
wl = 1.0E7/wn #wavelenght in nm
if(Wavenumber == 2):
wl = float(l[0:10]) #wavelenght in nm
wn = 1.0E7/wl
if(Wavenumber == 3):
wlAir = float(l[0:10]) #wavelenght in nm
loggf = float(l[10:17])
JLow = float(l[17:22])
ELow = float(l[22:32])
JUP = float(l[32:37])
EUP = float(l[37:48])
code = l[48:70]
e = 4.80320425E-10 #electron charge in cgs units [statcoulomb = cm^(3/2) g^(1/2) s^-1]
c = 2.99792458E10 #Speed of light cm/s
me = 9.1093835611E-28 #mass of electron in g
NA = 6.0221412927e23 #Avogadro Constant 1/mol
ELow = abs(ELow)
EUP = abs(EUP)
#somethimes ELOW is larger than EUP
if(ELow > EUP):
t = EUP
EUP = ELow
ELow = t
t = JUP
JUP = JLow
JLow = t
#convert air wavelength to vacuum wavelength
#http://www.astro.uu.se/valdwiki/Air-to-vacuum%20conversion
if(Wavenumber == 3):
if(wlAir > 200):
wlAir = wlAir * 10 #convert nm to Angstrom
s = 10000.0 / wlAir
n = 1.0 + 0.00008336624212083 + 0.02408926869968 / (130.1065924522 - s*s) + 0.0001599740894897 / (38.92568793293 - s*s)
wl = wlAir * n
wl = wl * 0.1 #convert Angstrom to nm
else:
wl = wlAir
wn = 1.0E7/wl #wavelenght in nm
gUP = 2 * JUP + 1
gLow = 2 * JLow + 1
A = 8.0 * math.pi * wn * wn * (10.0**loggf) / gUP * math.pi * e * e / (me * c)
nl = nl + 1
numax = max(numax, wn)
S = math.pi * e * e * 10.0**loggf * NA / (c * c * me * mass)
A = 8.0 * math.pi * wn * wn * 10.0**loggf / gUP * math.pi * e * e / (me * c)
if(printA == 1):
print(i, wn, A, ELow, gUP, mass, file = Afile)
#print(wn, 1.0E7/wn, loggf, ELow, EUP, JLow, JUP, mass, A)
#print(wn, S, A, ELow, EUP, gLow, gUP)
s = struct.pack('d', wn)
output_file.write(s)
s = struct.pack('d', S)
output_file.write(s)
s = struct.pack('d', ELow)
output_file.write(s)
s = struct.pack('d', A)
output_file.write(s)
print(" Lines:",nl, end='')
output_file.close()
if(printA == 1):
Afile.close()
if(nl > 0):
f = open("%s.param" % name,'w')
print("Database = 2", file = f)
print("Molecule number = 1", file = f)
print("Name = %s" % name, file = f)
print("Number of Isotopologues = 1", file = f)
print("#Id Abundance Q(296K) g Molar Mass(g) partition file :", file = f)
print("0 1.0 0.0 0 %s %s" % (mass, pfname), file = f)
print("Number of columns in partition File = 2", file = f)
print("Number of line/transition files = 1", file = f)
print("Number of lines per file :", file = f)
print("%d" % nl, file = f)
print("Line file limits :", file = f)
print("0", file = f)
print("%d" % (int(numax)+1), file = f)
print("#ExoMol :", file = f)
print("Number of states = 0", file = f)
print("Number of columns in transition files = 0", file = f)
print("Default value of Lorentzian half-width for all lines = 0.07", file = f)
print("Default value of temperature exponent for all lines = 0.5", file = f)
print("Version = %s" % filename, file = f)
f.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-name', '--name', type=str,
#help='name', default = 'coax')
help='name', default = 'tiototo')
parser.add_argument('-mass', '--mass', type=float,
#help='Isotopologue mass g/mol', default = 28.0101)
help='Isotopologue mass g/mol', default = 61.947545)
parser.add_argument('-pfFile', '--pfFile', type=str,
#help='partition function file name', default = '12C-16O__Li2015.pf')
help='partition function file name', default = '46Ti-16O__Toto.pf')
parser.add_argument('-printA', '--printA', type=int,
help='print A to file', default = 0)
args = parser.parse_args()
name = args.name
mass = args.mass
pfname = args.pfFile
printA = args.printA
print("name: %s, mass: %g; pfFile: %s; printA: %d" % (name, mass, pfname, printA))
main(name, mass, pfname, printA)