File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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")
You can’t perform that action at this time.
0 commit comments