forked from Auto-Mech/autochem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathptab.py
145 lines (113 loc) · 3.43 KB
/
ptab.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
"""
Periodic Table operations
"""
from qcelemental import periodictable
from qcelemental import vdwradii
from qcelemental import covalentradii
from qcelemental import constants
GROUP_2_VALENCE = {
None: 0,
1: 1, # H
2: 2, # Be
13: 3, # B
14: 4, # C
15: 3, # N
16: 2, # O
17: 1, # F
18: 0, # He
}
GROUP_2_LONE_PAIR_COUNT = {
None: 0,
1: 0, # H
2: 0, # Be
13: 0, # B
14: 0, # C
15: 1, # N
16: 2, # O
17: 3, # F
18: 4, # He
}
def to_symbol(atom):
"""Obtain the atomic symbol for a given atom.
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: str
"""
atom = 0 if atom == -1 else atom
return periodictable.to_E(atom)
def to_number(atom):
"""Obtain the atomic number for a given atom.
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: int
"""
atom = 0 if atom == -1 else atom
return periodictable.to_Z(atom)
def to_mass_number(atom):
"""Obtain the mass number for a given atom.
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: int
"""
atom = 0 if atom == -1 else atom
return periodictable.to_A(atom)
def to_mass(atom):
"""Obtain the atomic mass for a given atom (in amu).
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: float
"""
atom = 0 if atom == -1 else atom
return periodictable.to_mass(atom)
def to_group(atom):
"""Obtain the number of the group the atom belongs to.
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: int
"""
atom = 0 if atom == -1 else atom
return periodictable.to_group(atom)
def valence(atom):
"""Obtain the number of bonds typically formed by the atom.
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: int
"""
atom = 0 if atom == -1 else atom
grp = periodictable.to_group(atom)
val = GROUP_2_VALENCE[grp] if grp in GROUP_2_VALENCE else None
return val
def lone_pair_count(atom):
"""Obtain the number of bonds typically formed by the atom.
:param atom: atom representation (symbol, number, mass)
:type atom: str/int
:rtype: int
"""
atom = 0 if atom == -1 else atom
grp = periodictable.to_group(atom)
lpc = GROUP_2_LONE_PAIR_COUNT[grp] if grp in GROUP_2_LONE_PAIR_COUNT else None
return lpc
def covalent_radius(symb, angstrom=False):
"""Obtain the van der Waals radius for an atom
:param symb: atomic symbol
:type symb: str
:param angstrom: Return the radius in angstroms, instead of bohr?, default False
:type angstrom: bool, optional
:rtype: float
"""
units = "angstrom" if angstrom else "bohr"
if symb.upper() == "X":
return 0.5 * constants.conversion_factor("angstrom", units)
return covalentradii.get(symb, units=units)
def van_der_waals_radius(symb, angstrom=False):
"""Obtain the van der Waals radius for an atom
:param symb: atomic symbol
:type symb: str
:param angstrom: Return the radius in angstroms, instead of bohr?, default False
:type angstrom: bool, optional
:rtype: float
"""
units = "angstrom" if angstrom else "bohr"
if symb.upper() == "X":
return 1. * constants.conversion_factor("angstrom", units)
return vdwradii.get(symb, units=units)