Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions physics/vibrational_partition
Original file line number Diff line number Diff line change
@@ -0,0 +1,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")