parameters.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from dataclasses import dataclass
  2. import numpy as np
  3. import units_and_constants as uc
  4. @dataclass
  5. class ModelParams:
  6. R: float
  7. kappa: float = None
  8. kappaR: float = None
  9. c0: float = None
  10. epsilon: float = 80
  11. temperature: float = 293
  12. def __post_init__(self):
  13. self.kappa, self.kappaR, self.c0 = screening_calculator(self.R, self.temperature, self.epsilon,
  14. self.kappa, self.kappaR, self.c0)
  15. def bjerrum(temp: float, epsilon: float) -> float:
  16. return uc.CONSTANTS.e0 ** 2 / (4 * np.pi * epsilon * uc.CONSTANTS.epsilon0 * uc.CONSTANTS.Boltzmann * temp)
  17. def kappa_from_concentration(c0: float, temp: float, epsilon: float) -> float:
  18. return np.sqrt(8 * np.pi * bjerrum(temp, epsilon) * c0)
  19. def concentration_from_kappa(kappa: float, temp: float, epsilon: float):
  20. return kappa ** 2 / (8 * np.pi * bjerrum(temp, epsilon))
  21. def screening_calculator(radius: float, temp: float, epsilon: float,
  22. kappa: float = None, kappaR: float = None, c0: float = None) -> (float, float, float):
  23. if kappa is not None:
  24. return kappa, kappa * radius, concentration_from_kappa(kappa, temp, epsilon)
  25. elif kappaR is not None:
  26. return kappaR / radius, kappaR, concentration_from_kappa(kappaR / radius, temp, epsilon)
  27. elif c0 is not None:
  28. kappa = kappa_from_concentration(c0, temp, epsilon)
  29. return kappa, kappa * radius, c0
  30. raise ValueError('One of the arguments kappa, kappaR or c0 should be different from None.')