Skip to content

Commit 6f127c6

Browse files
authored
Create rotational_partition
1 parent 52602ea commit 6f127c6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

physics/rotational_partition

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def rotation_partition_function(moment_of_inertia: float,
2+
temperature: float) -> float:
3+
"""
4+
Calculates the rotational partition
5+
function for linear molecules.
6+
7+
>>> round(rotation_partition_function(1e-46, 300), 4)
8+
5.9275
9+
>>> round(rotation_partition_function(2e-46, 300), 4)
10+
11.855
11+
>>> round(rotation_partition_function(-2e-46, 300), 4)
12+
Traceback (most recent call last):
13+
...
14+
ValueError: Moment of inertia must be positive
15+
>>> round(rotation_partition_function(1e-46, -300), 4)
16+
Traceback (most recent call last):
17+
...
18+
ValueError: Temperature must be positive
19+
"""
20+
21+
if moment_of_inertia <= 0:
22+
raise ValueError("Moment of inertia must be positive")
23+
if temperature <= 0:
24+
raise ValueError("Temperature must be positive")
25+
26+
k_B = 1.380649e-23 # Boltzmann constant
27+
h = 6.62607015e-34 # Planck's constant
28+
29+
return (2 * math.pi * moment_of_inertia * k_B * temperature) / (h ** 2)
30+
31+
if __name__ == "__main__":
32+
import doctest
33+
doctest.testmod(name="rotation_partition_function")

0 commit comments

Comments
 (0)