-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.py
80 lines (65 loc) · 1.96 KB
/
atom.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
#!/bin/env python
# pylint: disable=invalid-name
"""This module contains the Atom class"""
PERIODIC_TABLE = {
1: {'symbol': 'H'},
2: {'symbol': 'He'},
3: {'symbol': 'Li'},
4: {'symbol': 'Be'},
5: {'symbol': 'B'},
6: {'symbol': 'C'},
7: {'symbol': 'N'},
8: {'symbol': 'O'},
9: {'symbol': 'F'},
10: {'symbol': 'Ne'},
11: {'symbol': 'Na'},
12: {'symbol': 'Mg'},
}
LIST_OF_ISO = {
'H': {'H': [1.007825, 0.99985], 'D': [2.01410178, 0.00015]},
'He': {'3He': [3.0160293, 0.00000137], '4He': [4.002602, 0.99999863]},
'C': {'12C': [12.0, 0.9893], '13C': [13.0033548378, 0.0107]},
'O': {'16O': [15.9949, 0.9976], '17O': [16.9991315, 0.00039],
'18O': [18, 0.00201]}, # mass of 18O is not correct
}
def elements(z):
"""Returns an element based on its atomic number"""
return PERIODIC_TABLE[z]
def iso(z):
"""Returns isotopes for an atomic number"""
return LIST_OF_ISO[z]
class Atom(object): # should input be number or string for Carbon, 'C' or '6'
"""Class that represents an atom"""
def __init__(self, Z=0, name=''):
"""Initilize internal variables"""
self.name = name
if Z > 0:
self.Z = Z
def __eq__(self, other):
"""Returns the equals value"""
if other.Z == self.Z:
equal = True
else:
equal = False
return equal
def symbol(self):
"""Returns the atomic symbol"""
info = elements(self.Z)
return info['symbol']
def iso(self):
"""Returns the atoms isotopes"""
info = iso(elements(self.Z)['symbol'])
return info
def mass(self):
"""Returns the atoms mass"""
info = iso(elements(self.Z)['symbol'])
amu = 0
for i in info.keys():
amu += (info[i][0] * info[i][1])
return amu
if __name__ == '__main__':
atom = Atom(1)
print atom.symbol()
print atom.iso()
print atom.mass()
atom.mass()