summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/nucleardata/nucleardata.sty
blob: 6e431f13533e4de465d9203fde881249b51991b7 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
%%
%% This is file `nucleardata.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% nucleardata.dtx  (with options: `package')
%% ----------------------------------------------------------------
%% 
%% nucleardata --- Getting info about nuclides into LaTeX documents
%% 
%% E-mail: bnettles@uu.edu
%% 
%% Released under the LaTeX Project Public License v1.3c or later
%% 
%% See http://www.latex-project.org/lppl.txt
%% 
%% ----------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{nucleardata}[2015/11/18 v1.00 LaTeX package for providing basic nuclear properties to documents efficiently]
\RequirePackage{pythontex}
\RequirePackage{siunitx}

\begin{pycode}
import sys
import fileinput
import csv
from subprocess import check_output

u2Mev=931.502
u2kev=u2Mev*1000.
Mev2u=1.0/u2Mev
kev2u=1.0/u2kev
u2kg=1.660539e-27
kg2u=1.0/u2kg

hbarev=6.5828e-16
hbarmev=hbarev/1.e6
hbarkev=hbarev/1.e3

class Nucdata(object):
    def __init__(self):
        self.units_dict={
            'ev':'\si{\electronvolt}',
            'mev':'\si{\mega\electronvolt}',
            'Mev':'\si{\mega\electronvolt}',
            'kev':'\si{\kilo\electronvolt}',
            'us':'\si{\micro\second}',
            'y':'\si{\ensuremath{\mathrm{yr}}}',
            'yr':'\si{\ensuremath{\mathrm{yr}}}',
            'm':'\si{\min}',
            'min':'\si{\min}',
            'h':'\si{\hour}',
            'hr':'\si{\hour}',
            'd':'\si{\day}',
            'day':'\si{\day}',
            's':'\si{\second}',
            'ms':'\si{\ms}',
            'ps':'\si{\ps}',
            'ns':'\si{\\ns}',
            'My':'\si{\ensuremath{\mathrm{My}}}',
            'Gy':'\si{\ensuremath{\mathrm{Gy}}}'
            }

        self.time_dict={
            "yr":1,
            "y":1,
            "d":365.25,
            "day":365.25,
            "days":365.25,
            "h":365.25*24,
            "hr":365.25*24,
            "m":365.25*24*60,
            "min":365.25*24*60,
            "s":365.25*24*3600,
            "ms":365.25*24*3600*1e3,
            "us":365.25*24*3600*1e6,
            "ns":365.25*24*3600*1e9,
            "ps":365.25*24*3600*1e12,
            "My":1e-6,
            "Gy":1e-9}

    def timeenergy(self,ene):
        return hbarev*0.69315/ene/time_dict.get("s")

    def  getNuclide(self,EL,A):
        res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]
        return res

    def getElement(self,Z):
        res=[v for v in nucleardata if  int(v.get('Z'))== Z]
        return res[0].get('SYM')

    def getMass_u(self,EL,A):
        try:
            EL = int(eval(str(EL)))
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper() == EL.upper() and v.get('A') == A]
        else:
            res=[v for v in nucleardata if  int(v.get('Z')) == EL and v.get('A') == A]
        return res[0].get('mass')

    def getNuclearMass_u(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]

        return res[0].get('mass')-int(res[0].get('Z'))*0.511/931.502

    def getMass_mev(self,EL,A):
        massu=self.getMass_u(EL,A)
        return massu*931.502

    def getMass_kev(self,EL,A):
        massu=self.getMass_u(EL,A)
        return massu*931502.

    def getNuclearMass_mev(self,EL,A):
        massu=self.getnuclearmass_u(EL,A)
        return massu*931.502

    def getNuclearMass_kev(self,EL,A):
        massu=self.getnuclearmass_u(EL,A)
        return massu*931502.

    def getReaction_u(self,EL1,A1,EL2,A2,EL3,A3,EL4,A4):
        m1=self.getNuclearMass_u(EL1,A1)
        m2=self.getNuclearMass_u(EL2,A2)
        m3=self.getNuclearMass_u(EL3,A3)
        m4=self.getNuclearMass_u(EL4,A4)
        return m1+m2-m3-m4

    def getReaction_mev(self,EL1,A1,EL2,A2,EL3,A3,EL4,A4):
        qu=self.getReaction_u(EL1,A1,EL2,A2,EL3,A3,EL4,A4)
        return qu*931.502

    def getReaction_kev(self,EL1,A1,EL2,A2,EL3,A3,EL4,A4):
        qu=self.getReaction_u(EL1,A1,EL2,A2,EL3,A3,EL4,A4)
        return qu*931502.

    def getExcess(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]

        return res[0].get('Excess')

    def getHalfLife(self,EL,A,newunit):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == int(A)]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == int(A)]

        rest=res[0].get('halflife')
        if type(rest)==type('x'):
            if rest.lower().strip():
                value= rest.lower().strip().split()
                if len(value)>1:
                    number = eval(value[0].strip())
                    unit = value[1].strip()
                    if newunit: # user wants to change the unit
                        if unit in ['ev','kev','mev']:
                            number=timeenergy(number)
                            if unit=='kev':
                                number=number/1.e3
                            elif unit=='mev':
                                number=number/1.e6
                            unit='y'
                        number=number*self.time_dict.get(newunit)/self.time_dict.get(unit)
                        unit=newunit
                    result= "\\num{" + str(number) + "} " + self.units_dict.get(unit)
                else:
                    result=value[0].strip()
                return result
            else:
                return 'undetermined'
        else:
            return rest

    def getHalfLifeValue(self,EL,A,newunit):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]

        rest=res[0].get('halflife')
        if type(rest)==type('x'):
            if rest.lower().strip():
                value= rest.lower().strip().split()
                if len(value)>1:
                    number = eval(value[0].strip())
                    unit = value[1].strip()
                    if newunit: # user wants to change the unit
                        if unit in ['ev','kev','mev']:
                            number=timeenergy(number)
                            if unit=='kev':
                                number=number/1.e3
                            elif unit=='mev':
                                number=number/1.e6
                            unit='y'
                        number=number*self.time_dict.get(newunit)/self.time_dict.get(unit)
                        unit=newunit
                    result= "\\num{" + str(number) + "} "
                else:
                    result=value[0].strip()
                return result
            else:
                return 'undetermined'
        else:
            return rest

    def getHalfLifeUnit(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]

        rest=res[0].get('halflife')
        if type(rest)==type('x'):
            value= rest.lower().strip().split()
            if len(value)>1:
                unit = value[1].strip()
                result= self.units_dict.get(unit)
            else:
                result=value[0].strip()
            return result

        else:
            return(rest)

    def getBea(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]

        return res[0].get('BEA')

    def getQbeta(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]
        return res[0].get('Qbeta')

    def getQposi(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]
        return res[0].get('Qposi')

    def getQec(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]
        return res[0].get('Qec')

    def getQalpha(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]
        return res[0].get('Qalpha')

    def is_alpha(self,EL,A):
        try:
            val= self.getQalpha(EL,A)>0
        except:
            val = False
        return val

    def is_beta(self,EL,A):
        try:
            val= self.getQbeta(EL,A)>0
        except:
            val = False
        return val

    def is_posi(self,EL,A):
        try:
            val= self.getQposi(EL,A)>0
        except:
            val = False
        return val

    def is_ec(self,EL,A):
        try:
            val= self.getQec(EL,A)>0
        except:
            val = False
        return val

    def getIsotopes(self,EL):
        try:
            EL = int(eval(str(EL)))

        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper()]
        else:
            res=[v for v in nucleardata if  int(v.get('Z'))== EL]

        isotopes=[]
        for v in res:
            isotopes.append(int(v.get('A')))
        isostring=str(isotopes)[1:-1]
        return isostring

    def getZ(self,name):
        res=[v for v in elementdata if  v.get('SYM').strip().upper()== name.upper() or v.get('NAME').strip().upper()== name.upper()]
        return int(res[0].get('Z'))

    def getSymbol(self,namez):
        try:
            namez = int(eval(str(namez)))
        except:
            pass
        res=[v for v in elementdata if  int(v.get('Z'))== namez or v.get('NAME').strip().upper()== str(namez).upper()]
        return res[0].get('SYM').strip()

    def getName(self,namez):
        try:
            namez = int(eval(str(namez)))
        except:
            pass
        res=[v for v in elementdata if  int(v.get('Z'))== namez or v.get('SYM').strip().upper()== str(namez).upper()]
        return res[0].get('NAME').strip()

    def getSpin(self,EL,A):
        try:
            EL = int(eval(str(EL)))
            res=[v for v in nucleardata if  int(v.get('Z'))== EL and v.get('A') == A]
        except:
            res=[v for v in nucleardata if  v.get('SYM').strip().upper()== EL.upper() and v.get('A') == A]
        return res[0].get('spin-parity')

elementdata=[]  #list of dictionaries of Z, Elemental symbol, Name of element

filename=check_output("kpsewhich elementlist.csv", shell=True)

if sys.version_info.major == 2:
    g = open(filename[0:-2], 'rb')
else:
    g = open(filename[0:-2], 'r', newline='')
gin=csv.DictReader(g)#,quoting=csv.QUOTE_NONNUMERIC)

#headline=['Z','SYM','NAME']
for line in gin:
    elementdata.append(line)
g.close()

nucleardata=[] #list of dictionaries of nuclear mass, halflife, etc.

filename=check_output("kpsewhich massdata.csv", shell=True)

if sys.version_info.major == 2:
    g = open(filename[0:-2], 'rb')
else:
    g = open(filename[0:-2], 'r', newline='')
gin=csv.DictReader(g,quoting=csv.QUOTE_NONNUMERIC)

#headline=["C","N","Z","A","SYM","ORIG","Excess","unc1","BEA","unc2","btype","benergy","bunc","mass","munc","halflife","spin-parity","Qbeta","Qposi","Qec","Qalpha"]

for line in gin:
    nucleardata.append(line)
g.close()

nuc=Nucdata()

\end{pycode}

\newcommand{\nucspin}[2]{\py{nuc.getSpin('#1',#2)}}

\newcommand{\nucamassu}[3][6]{\py{round(nuc.getMass_u('#2',#3),#1)}}

\newcommand{\nucamassmev}[3][6]{\py{round(nuc.getMass_mev('#2',#3),#1)}}

\newcommand{\nucamasskev}[3][3]{\py{round(nuc.getMass_kev('#2',#3),#1)}}

\newcommand{\nuclearmassu}[3][6]{\py{round(nuc.getNuclearMass_u('#2',#3),#1)}}

\newcommand{\nuclearmassmev}[3][6]{\py{round(nuc.getNuclearMass_mev('#2',#3),#1)}}

\newcommand{\nuclearmasskev}[3][3]{\py{round(nuc.getNuclearMass_kev('#2',#3),#1)}}

\newcommand{\nuchalflife}[3][]{\py{nuc.getHalfLife('#2',#3,'#1')}}

\newcommand{\nuchalfvalue}[3][]{\py{nuc.getHalfLifeValue('#2',#3,'#1')}}

\newcommand{\nuchalfunit}[2]{\py{nuc.getHalfLifeUnit('#1',#2)}}

\newcommand{\nucz}[1]{\py{nuc.getZ('#1')}}

\newcommand{\nucName}[1]{\py{nuc.getName('#1')}}

\newcommand{\nucname}[1]{\py{nuc.getName('#1').lower()}}

\newcommand{\nucsymbol}[1]{\py{nuc.getSymbol('#1')}}

\newcommand{\nucexcess}[3][3]{\py{round(nuc.getExcess('#2',#3),#1)}}

\newcommand{\nucQalpha}[3][6]{\py{round(nuc.getQalpha('#2',#3),#1)}}

\newcommand{\nucQbeta}[3][6]{\py{round(nuc.getQbeta('#2',#3),#1)}}

\newcommand{\nucQposi}[3][6]{\py{round(nuc.getQposi('#2',#3),#1)}}

\newcommand{\nucQec}[3][6]{\py{round(nuc.getQec('#2',#3),#1)}}

\newcommand{\nucisalpha}[2]{\py{nuc.getQalpha('#1',#2)>0}}

\newcommand{\nucisbeta}[2]{\py{nuc.getQbeta('#1',#2)>0}}

\newcommand{\nucisposi}[2]{\py{nuc.getQposi('#1',#2)>0}}

\newcommand{\nucisec}[2]{\py{nuc.getQec('#1',#2)>0}}

\newcommand{\nucbea}[3][3]{\py{round(nuc.getBea('#2',#3)/1000.,#1)}}

\newcommand{\nucisotopes}[1]{\py{nuc.getIsotopes('#1')}}

\newcommand{\nucreactionqu}[9][3]{\py{round(nuc.getReaction_u('#2',#3,'#4',#5,'#6',#7,'#8',#9),#1)}}

\newcommand{\nucreactionqmev}[9][3]{\py{round(nuc.getReaction_mev('#2',#3,'#4',#5,'#6',#7,'#8',#9),#1)}}

\newcommand{\nucreactionqkev}[9][3]{\py{round(nuc.getReaction_kev('#2',#3,'#4',#5,'#6',#7,'#8',#9),#1)}}
\endinput
%% Copyright (C) 2015 by Bill Nettles <bnettles@uu.edu>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or (at your option) any later
%% version.  The latest version of this license is in the file:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Bill Nettles.
%% 
%% This work consists of the file  nucleardata.dtx
%% and the derived files           nucleardata.ins,
%%                                 nucleardata.pdf,
%%                                 nucleardata.sty,
%%                                 elementlist.csv,
%%                                 massdata.csv
%%
%% End of file `nucleardata.sty'.