parameters.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. # TODO: what is with the units of c0 calculated here?
  21. return kappa ** 2 / (8 * np.pi * bjerrum(temp, epsilon))
  22. def screening_calculator(radius: float, temp: float, epsilon: float,
  23. kappa: float = None, kappaR: float = None, c0: float = None) -> (float, float, float):
  24. if kappa is not None:
  25. return kappa, kappa * radius, concentration_from_kappa(kappa, temp, epsilon)
  26. elif kappaR is not None:
  27. return kappaR / radius, kappaR, concentration_from_kappa(kappaR / radius, temp, epsilon)
  28. elif c0 is not None:
  29. kappa = kappa_from_concentration(c0, temp, epsilon)
  30. return kappa, kappa * radius, c0
  31. raise ValueError('One of the arguments kappa, kappaR or c0 should be different from None.')