-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementInfomation.jl
More file actions
executable file
·87 lines (78 loc) · 2.71 KB
/
Copy pathElementInfomation.jl
File metadata and controls
executable file
·87 lines (78 loc) · 2.71 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
module ElementInformation
using Color
export
Element,
ElementDatabase,
createElementDictionary,
calcf0!
#############################################################
##### CREATE TYPES #####
#############################################################
type Element
symbol::ASCIIString
atomicNumber::Int64
cm_a1::Float64
cm_a2::Float64
cm_a3::Float64
cm_a4::Float64
cm_b1::Float64
cm_b2::Float64
cm_b3::Float64
cm_b4::Float64
cm_c ::Float64
f0::Dict{Float64,Float64}
color::RGB
end
#############################################################
##### FUNCTIONS #####
#############################################################
function createElementDictionary()
maxColorValue = 255
elementDictionary = Dict{ASCIIString, Element}()
atmScatFacDict = Dict{Float64, Float64}()
cmFile = open("Cromer-Mann_Coefficients.txt")
for line in eachline(cmFile)
if line[1:2] == "#S" && length(split(line)) > 3
symbol = split(line)[3]
atomicNumber = parseint(split(line)[2])
a1 = parsefloat(split(line)[4])
a2 = parsefloat(split(line)[5])
a3 = parsefloat(split(line)[6])
a4 = parsefloat(split(line)[7])
c = parsefloat(split(line)[8])
b1 = parsefloat(split(line)[9])
b2 = parsefloat(split(line)[10])
b3 = parsefloat(split(line)[11])
b4 = parsefloat(split(line)[12])
red = parseint(split(line)[13])
green = parseint(split(line)[14])
blue = parseint(split(line)[15])
rgb = RGB(red/maxColorValue, green/maxColorValue, blue/maxColorValue)
elementInfo = Element(symbol, atomicNumber, a1, a2, a3, a4,
b1, b2, b3, b4, c, atmScatFacDict, rgb)
elementDictionary[symbol] = elementInfo
end
end
return elementDictionary
end
function calcf0!(elementDict::Dict{ASCIIString,Element}, angles::Vector{Float64}, wavelength::Float64)
k_sqrd = (sin(deg2rad(angles))/wavelength).^2
for key in keys(elementDict)
element = deepcopy(elementDict[key])
a1 = element.cm_a1
a2 = element.cm_a2
a3 = element.cm_a3
a4 = element.cm_a4
b1 = element.cm_b1
b2 = element.cm_b2
b3 = element.cm_b3
b4 = element.cm_b4
c = element.cm_c
f0_values = c + a1*exp(-(b1 * k_sqrd)) + a2*exp(-(b2 * k_sqrd)) + a3*exp(-(b3 * k_sqrd)) + a4*exp(-(b4 * k_sqrd))
for i = 1:length(angles)
element.f0[angles[i]] = f0_values[i]
end
elementDict[key] = element
end
end
end