|
| 1 | +import math |
| 2 | + |
| 3 | +def translation_partition_function(mass: float, temperature: float, |
| 4 | + volume: float) -> float: |
| 5 | + """ |
| 6 | + Calculates the translational partition |
| 7 | + function using the formula: |
| 8 | + q_trans = ((2 * pi * m * k_B * T)^(3/2) * V) / h^3 |
| 9 | + |
| 10 | + mass: Mass of the molecule in kg |
| 11 | + temperature: Temperature in Kelvin |
| 12 | + volume: Volume in cubic meters |
| 13 | + |
| 14 | + >>> round(translation_partition_function(2e-26, 300, 1e-3), 4) |
| 15 | + 4.081816847078438e+28 |
| 16 | + >>> round(translation_partition_function(4e-26, 300, 1e-3), 4) |
| 17 | + 1.1545121488522627e+29 |
| 18 | + >>> round(translation_partition_function(-4e-26, 300, 1e-3), 4) |
| 19 | + Traceback (most recent call last): |
| 20 | + ... |
| 21 | + ValueError: Mass must be positive |
| 22 | + >>> round(translation_partition_function(4e-26, 0, 1e-3), 4) |
| 23 | + Traceback (most recent call last): |
| 24 | + ... |
| 25 | + ValueError: Temperature must be positive |
| 26 | + >>> round(translation_partition_function(4e-26, 300, 0), 4) |
| 27 | + Traceback (most recent call last): |
| 28 | + ... |
| 29 | + ValueError: Volume must be positive |
| 30 | + """ |
| 31 | + |
| 32 | + if mass <= 0: |
| 33 | + raise ValueError("Mass must be positive") |
| 34 | + if temperature <= 0: |
| 35 | + raise ValueError("Temperature must be positive") |
| 36 | + if volume <= 0: |
| 37 | + raise ValueError("Volume must be positive") |
| 38 | + |
| 39 | + h = 6.62607015e-34 # Planck's constant in J·s |
| 40 | + k_B = 1.380649e-23 # Boltzmann constant in J/K |
| 41 | + |
| 42 | + prefactor = (2 * math.pi * mass * k_B * temperature) ** (3 / 2) |
| 43 | + denominator = h ** 3 |
| 44 | + return (prefactor * volume) / denominator |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + import doctest |
| 48 | + doctest.testmod(name="translation_partition_function") |
0 commit comments