Compare commits

...

4 Commits

Author SHA1 Message Date
nikhitha79
f740be8ac8
Merge 4200aa200b into f3f32ae3ca 2024-11-21 21:35:19 +05:30
pre-commit-ci[bot]
f3f32ae3ca
[pre-commit.ci] pre-commit autoupdate (#12385)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-18 22:07:12 +01:00
pre-commit-ci[bot]
4200aa200b [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-30 16:23:03 +00:00
nikhitha79
4fbdd8e171
Create translation_partition 2024-10-30 21:51:02 +05:30
2 changed files with 49 additions and 1 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus - id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3 rev: v0.7.4
hooks: hooks:
- id: ruff - id: ruff
- id: ruff-format - id: ruff-format

View File

@ -0,0 +1,48 @@
import math
def translation_partition_function(mass: float, temperature: float,
volume: float) -> float:
"""
Calculates the translational partition
function using the formula:
q_trans = ((2 * pi * m * k_B * T)^(3/2) * V) / h^3
mass: Mass of the molecule in kg
temperature: Temperature in Kelvin
volume: Volume in cubic meters
>>> round(translation_partition_function(2e-26, 300, 1e-3), 4)
4.081816847078438e+28
>>> round(translation_partition_function(4e-26, 300, 1e-3), 4)
1.1545121488522627e+29
>>> round(translation_partition_function(-4e-26, 300, 1e-3), 4)
Traceback (most recent call last):
...
ValueError: Mass must be positive
>>> round(translation_partition_function(4e-26, 0, 1e-3), 4)
Traceback (most recent call last):
...
ValueError: Temperature must be positive
>>> round(translation_partition_function(4e-26, 300, 0), 4)
Traceback (most recent call last):
...
ValueError: Volume must be positive
"""
if mass <= 0:
raise ValueError("Mass must be positive")
if temperature <= 0:
raise ValueError("Temperature must be positive")
if volume <= 0:
raise ValueError("Volume must be positive")
h = 6.62607015e-34 # Planck's constant in J·s
k_B = 1.380649e-23 # Boltzmann constant in J/K
prefactor = (2 * math.pi * mass * k_B * temperature) ** (3 / 2)
denominator = h ** 3
return (prefactor * volume) / denominator
if __name__ == "__main__":
import doctest
doctest.testmod(name="translation_partition_function")