Skip to content

Commit 107ad9e

Browse files
authored
Create vibrational_partition
1 parent 52602ea commit 107ad9e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

physics/vibrational_partition

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def vibration_partition_function(frequency: float,
2+
temperature: float) -> float:
3+
"""
4+
Calculates the vibrational partition function.
5+
6+
>>> round(vibration_partition_function(5e13, 300), 4)
7+
1.0003
8+
>>> round(vibration_partition_function(1e13, 300), 4)
9+
1.2531
10+
>>> round(vibration_partition_function(-1e13, 300), 4)
11+
Traceback (most recent call last):
12+
...
13+
ValueError: Frequency must be positive
14+
>>> round(vibration_partition_function(1e13, -300), 4)
15+
Traceback (most recent call last):
16+
...
17+
ValueError: Temperature must be positive
18+
"""
19+
20+
if frequency <= 0:
21+
raise ValueError("Frequency must be positive")
22+
if temperature <= 0:
23+
raise ValueError("Temperature must be positive")
24+
25+
h = 6.62607015e-34 # Planck's constant
26+
k_B = 1.380649e-23 # Boltzmann constant
27+
28+
theta_v = (h * frequency) / k_B
29+
return 1 / (1 - math.exp(-theta_v / temperature))
30+
31+
if __name__ == "__main__":
32+
import doctest
33+
doctest.testmod(name="vibration_partition_function")

0 commit comments

Comments
 (0)