-
Notifications
You must be signed in to change notification settings - Fork 1
/
electrons.php
209 lines (200 loc) · 5.82 KB
/
electrons.php
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
<?php
// electrons and stuff go here
$electrons = [
'H' => ['block' => 's'],
'He' => ['block' => 's'],
'Li' => ['block' => 's'],
'Be' => ['block' => 's'],
'B' => ['block' => 'p'],
'C' => ['block' => 'p'],
'N' => ['block' => 'p'],
'O' => ['block' => 'p'],
'F' => ['block' => 'p'],
'Ne' => ['block' => 'p'],
'Na' => ['block' => 's'],
'Mg' => ['block' => 's'],
'Al' => ['block' => 'p'],
'Si' => ['block' => 'p'],
'P' => ['block' => 'p'],
'S' => ['block' => 'p'],
'Cl' => ['block' => 'p'],
'Ar' => ['block' => 'p'],
'K' => ['block' => 's'],
'Ca' => ['block' => 's'],
'Sc' => ['block' => 'd'],
'Ti' => ['block' => 'd'],
'V' => ['block' => 'd'],
'Cr' => ['block' => 'd'],
'Mn' => ['block' => 'd'],
'Fe' => ['block' => 'd'],
'Co' => ['block' => 'd'],
'Ni' => ['block' => 'd'],
'Cu' => ['block' => 'd'],
'Zn' => ['block' => 'd'],
'Ga' => ['block' => 'p'],
'Ge' => ['block' => 'p'],
'As' => ['block' => 'p'],
'Se' => ['block' => 'p'],
'Br' => ['block' => 'p'],
'Kr' => ['block' => 'p'],
'Rb' => ['block' => 's'],
'Sr' => ['block' => 's'],
'Y' => ['block' => 'd'],
'Zr' => ['block' => 'd'],
'Nb' => ['block' => 'd'],
'Mo' => ['block' => 'd'],
'Tc' => ['block' => 'd'],
'Ru' => ['block' => 'd'],
'Rh' => ['block' => 'd'],
'Pd' => ['block' => 'd'],
'Ag' => ['block' => 'd'],
'Cd' => ['block' => 'd'],
'In' => ['block' => 'p'],
'Sn' => ['block' => 'p'],
'Sb' => ['block' => 'p'],
'Te' => ['block' => 'p'],
'I' => ['block' => 'p'],
'Xe' => ['block' => 'p'],
'Cs' => ['block' => 's'],
'Ba' => ['block' => 's'],
'La' => ['block' => 'f'],
'Ce' => ['block' => 'f'],
'Pr' => ['block' => 'f'],
'Nd' => ['block' => 'f'],
'Pm' => ['block' => 'f'],
'Sm' => ['block' => 'f'],
'Eu' => ['block' => 'f'],
'Gd' => ['block' => 'f'],
'Tb' => ['block' => 'f'],
'Dy' => ['block' => 'f'],
'Ho' => ['block' => 'f'],
'Er' => ['block' => 'f'],
'Tm' => ['block' => 'f'],
'Yb' => ['block' => 'f'],
'Lu' => ['block' => 'd'],
'Hf' => ['block' => 'd'],
'Ta' => ['block' => 'd'],
'W' => ['block' => 'd'],
'Re' => ['block' => 'd'],
'Os' => ['block' => 'd'],
'Ir' => ['block' => 'd'],
'Pt' => ['block' => 'd'],
'Au' => ['block' => 'd'],
'Hg' => ['block' => 'd'],
'Tl' => ['block' => 'p'],
'Pb' => ['block' => 'p'],
'Bi' => ['block' => 'p'],
'Po' => ['block' => 'p'],
'At' => ['block' => 'p'],
'Rn' => ['block' => 'p'],
'Fr' => ['block' => 's'],
'Ra' => ['block' => 's'],
'Ac' => ['block' => 'f'],
'Th' => ['block' => 'f'],
'Pa' => ['block' => 'f'],
'U' => ['block' => 'f'],
'Np' => ['block' => 'f'],
'Pu' => ['block' => 'f'],
'Am' => ['block' => 'f'],
'Cm' => ['block' => 'f'],
'Bk' => ['block' => 'f'],
'Cf' => ['block' => 'f'],
'Es' => ['block' => 'f'],
'Fm' => ['block' => 'f'],
'Md' => ['block' => 'f'],
'No' => ['block' => 'f'],
'Lr' => ['block' => 'd'],
'Rf' => ['block' => 'd'],
'Db' => ['block' => 'd'],
'Sg' => ['block' => 'd'],
'Bh' => ['block' => 'd'],
'Hs' => ['block' => 'd'],
'Mt' => ['block' => 'd'],
'Ds' => ['block' => 'd'],
'Rg' => ['block' => 'd'],
'Cn' => ['block' => 'd'],
'Nh' => ['block' => 'p'],
'Fl' => ['block' => 'p'],
'Mc' => ['block' => 'p'],
'Lv' => ['block' => 'p'],
'Ts' => ['block' => 'p'],
'Og' => ['block' => 'p']
];
function electron_config($element_number, $shortened = false) {
// Check for exceptions
$exceptions = [
24 => '1s2 2s2 2p6 3s2 3p6 4s1 3d5',
29 => '1s2 2s2 2p6 3s2 3p6 4s1 3d10',
41 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s1 4d4',
42 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s1 4d5',
44 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s1 4d7',
45 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s1 4d8',
46 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 4d10',
47 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s1 4d10',
57 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 5d1',
58 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f1 5d1',
64 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f7 5d1',
78 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s1 4f14 5d9',
79 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s1 4f14 5d10',
89 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 6d1',
90 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 6d2',
91 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 5f2 6d1',
92 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 5f3 6d1',
93 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 5f4 6d1',
96 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 5f7 6d1',
103 => '1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6 5s2 4d10 5p6 6s2 4f14 5d10 6p6 7s2 5f14 7p1'
];
if(array_key_exists($element_number, $exceptions)) {
$notation_exception = $exceptions[$element_number];
}
$orbital_capacity = [
's' => 2,
'p' => 6,
'd' => 10,
'f' => 14
];
$notation_order = [
'1s', '2s', '2p', '3s', '3p',
'4s', '3d', '4p', '5s', '4d',
'5p', '6s', '4f', '5d', '6p',
'7s', '5f', '6d', '7p', '8s',
];
$electrons = $element_number;
$notation = '';
foreach($notation_order as $orbital) {
$orbital_type = substr($orbital, -1);
$orbital_value = 0;
while($electrons > 0 && $orbital_value < $orbital_capacity[$orbital_type]) {
$orbital_value++;
$electrons--;
}
$notation .= $orbital . $orbital_value;
if($electrons === 0) {
break;
} else {
$notation .= ' ';
}
}
if(isset($notation_exception)) {
$notation = $notation_exception;
}
// Optionally shorten the notation
$noble_gases = [
'He' => 2,
'Ne' => 10,
'Ar' => 18,
'Kr' => 36,
'Xe' => 54,
'Rn' => 86,
];
if($shortened) {
foreach(array_reverse($noble_gases) as $key => $gas) {
if($element_number > $gas) {
$replace_notation = electron_config($gas, false, 0);
$shortened_notation = '[' . $key . ']';
return str_replace($replace_notation, $shortened_notation, $notation);
}
}
}
return $notation;
}