rotational_path.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import numpy as np
  2. from dataclasses import dataclass, field
  3. import quaternionic
  4. import expansion
  5. from parameters import ModelParams
  6. import interactions
  7. import matplotlib.pyplot as plt
  8. Quaternion = quaternionic.array
  9. Array = np.ndarray
  10. @dataclass
  11. class PairRotationalPath:
  12. rotations1: list[Quaternion] = field(default_factory=list)
  13. rotations2: list[Quaternion] = field(default_factory=list)
  14. def add(self, rotation1: Quaternion, rotation2: Quaternion):
  15. self.rotations1.append(rotation1)
  16. self.rotations2.append(rotation2)
  17. def add_euler(self, alpha1: Array = 0, beta1: Array = 0, gamma1: Array = 0,
  18. alpha2: Array = 0, beta2: Array = 0, gamma2: Array = 0):
  19. R1_euler = quaternionic.array.from_euler_angles(alpha1, beta1, gamma1)
  20. R2_euler = quaternionic.array.from_euler_angles(alpha2, beta2, gamma2)
  21. R1_euler, R2_euler = np.broadcast_arrays(R1_euler, R2_euler)
  22. self.add(Quaternion(R1_euler), Quaternion(R2_euler))
  23. def get_rotations(self) -> (Quaternion, Quaternion):
  24. return Quaternion(np.vstack(self.rotations1)), Quaternion(np.vstack(self.rotations2))
  25. zero_to_pi_half = np.linspace(0, np.pi/2, 1000)
  26. QuadPath = PairRotationalPath()
  27. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half)
  28. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half[::-1])
  29. QuadPath.add_euler(beta1=zero_to_pi_half)
  30. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half)
  31. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half, alpha2=np.pi/2)
  32. QuadPath.add_euler(beta1=np.pi/2, beta2=np.pi/2, alpha2=zero_to_pi_half[::-1])
  33. if __name__ == '__main__':
  34. params = ModelParams(R=150, kappaR=3)
  35. ex1 = expansion.MappedExpansion(1, params.kappaR, 0.001, max_l=15)
  36. # ex1 = expansion.Expansion24(sigma2=0.001, sigma4=0)
  37. ex2 = ex1.clone()
  38. rotations1, rotations2 = QuadPath.get_rotations()
  39. ex1.rotate(rotations1)
  40. ex2.rotate(rotations2)
  41. dist = 3
  42. energy = interactions.charged_shell_energy(ex1, ex2, dist, params)
  43. plt.plot(energy)
  44. plt.show()