Coverage for eminus/units.py: 100.00%
34 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-01 11:47 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-01 11:47 +0000
1# SPDX-FileCopyrightText: 2021 The eminus developers
2# SPDX-License-Identifier: Apache-2.0
3"""Collection of constants and unit conversion functions.
5For more about atomic units, see: https://en.wikipedia.org/wiki/Hartree_atomic_units
6All values are directly calculated from the CODATA 2018 constants as found in SciPy.
7"""
9import math
11#: Hartree in electronvolt.
12# scipy.constants.value("Hartree energy in eV")
13electronvolt = eV = 27.211386245988 # noqa: N816
14#: Hartree in kcal per mol.
15# scipy.constants.value("Hartree energy") * scipy.constants.value("Avogadro constant") / 4.184 / 1e3
16kcalmol = 627.5094740630557
17#: Bohr radius in Angstrom.
18# scipy.constants.value("Bohr radius") * 1e10
19Angstrom = A = 0.529177210903
20#: Elementary charge times bohr radius in Debye.
21# scipy.constants.value("atomic unit of electric dipole mom.") / \
22# scipy.constants.value("hertz-inverse meter relationship") * 1e21
23Debye = D = 2.5417464731818566
24#: Hartree in kb times Kelvin.
25# scipy.constants.value("kelvin-hartree relationship")
26Kelvin = K = 3.1668115634556e-06
29def ha2ev(E):
30 """Convert Hartree to electronvolt.
32 Args:
33 E: Energy in Hartree.
35 Returns:
36 Energy in electronvolt.
37 """
38 return E * electronvolt
41def ev2ha(E):
42 """Convert electronvolt to Hartree.
44 Args:
45 E: Energy in electronvolt.
47 Returns:
48 Energy in Hartree.
49 """
50 return E / electronvolt
53def ha2kcalmol(E):
54 """Convert Hartree to kcal/mol.
56 Args:
57 E: Energy in Hartree.
59 Returns:
60 Energy in kcal/mol.
61 """
62 return E * kcalmol
65def kcalmol2ha(E):
66 """Convert kcal/mol to Hartree.
68 Args:
69 E: Energy in kcal/mol.
71 Returns:
72 Energy in Hartree.
73 """
74 return E / kcalmol
77def ha2ry(E):
78 """Convert Hartree to Rydberg.
80 Args:
81 E: Energy in Hartree.
83 Returns:
84 Energy in Rydberg.
85 """
86 return 2 * E
89def ry2ha(E):
90 """Convert Rydberg to Hartree.
92 Args:
93 E: Energy in Rydberg.
95 Returns:
96 Energy in Hartree.
97 """
98 return E / 2
101def ha2kelvin(E):
102 """Convert Hartree to Kelvin.
104 Args:
105 E: Energy in Hartree.
107 Returns:
108 Temperature in Kelvin.
109 """
110 return E / Kelvin
113def kelvin2ha(T):
114 """Convert Kelvin to Hartree.
116 Args:
117 T: Temperature in Kelvin.
119 Returns:
120 Energy in Hartree.
121 """
122 return T * Kelvin
125def ang2bohr(r):
126 """Convert Angstrom to Bohr.
128 Args:
129 r: Length in Angstrom.
131 Returns:
132 Length in Bohr.
133 """
134 return r / Angstrom
137def bohr2ang(r):
138 """Convert Bohr to Angstrom.
140 Args:
141 r: Length in Bohr.
143 Returns:
144 Length in Angstrom.
145 """
146 return r * Angstrom
149def ebohr2d(p):
150 """Convert e * Bohr to Debye.
152 Args:
153 p: Electric dipole moment in e * Bohr.
155 Returns:
156 Electric dipole moment in Debye.
157 """
158 return p * Debye
161def d2ebohr(p):
162 """Convert Debye to e * Bohr.
164 Args:
165 p: Electric dipole moment in Debye.
167 Returns:
168 Electric dipole moment in e * Bohr.
169 """
170 return p / Debye
173def rad2deg(a):
174 """Convert Radians to Degree.
176 Args:
177 a: Angle in Radians.
179 Returns:
180 Angle in Degree.
181 """
182 return a * 180 / math.pi
185def deg2rad(a):
186 """Convert Degree to Radians.
188 Args:
189 a: Angle in Degree.
191 Returns:
192 Angle in Radians.
193 """
194 return a * math.pi / 180