forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvibrational_partition
33 lines (28 loc) · 1.04 KB
/
vibrational_partition
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
def vibration_partition_function(frequency: float,
temperature: float) -> float:
"""
Calculates the vibrational partition function.
>>> round(vibration_partition_function(5e13, 300), 4)
1.0003
>>> round(vibration_partition_function(1e13, 300), 4)
1.2531
>>> round(vibration_partition_function(-1e13, 300), 4)
Traceback (most recent call last):
...
ValueError: Frequency must be positive
>>> round(vibration_partition_function(1e13, -300), 4)
Traceback (most recent call last):
...
ValueError: Temperature must be positive
"""
if frequency <= 0:
raise ValueError("Frequency must be positive")
if temperature <= 0:
raise ValueError("Temperature must be positive")
h = 6.62607015e-34 # Planck's constant
k_B = 1.380649e-23 # Boltzmann constant
theta_v = (h * frequency) / k_B
return 1 / (1 - math.exp(-theta_v / temperature))
if __name__ == "__main__":
import doctest
doctest.testmod(name="vibration_partition_function")