rotational_path.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. rotation1, rotation2 = np.broadcast_arrays(rotation1, rotation2)
  16. self.rotations1.append(rotation1)
  17. self.rotations2.append(rotation2)
  18. def add_euler(self, *, alpha1: Array = 0, beta1: Array = 0, gamma1: Array = 0,
  19. alpha2: Array = 0, beta2: Array = 0, gamma2: Array = 0):
  20. R1_euler = quaternionic.array.from_euler_angles(alpha1, beta1, gamma1)
  21. R2_euler = quaternionic.array.from_euler_angles(alpha2, beta2, gamma2)
  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, 100, endpoint=False)
  26. pi_half_to_pi = np.linspace(np.pi/2, np.pi, 100, endpoint=False)
  27. QuadPath = PairRotationalPath()
  28. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half)
  29. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half[::-1])
  30. QuadPath.add_euler(beta1=zero_to_pi_half)
  31. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half)
  32. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half, alpha2=np.pi/2)
  33. QuadPath.add_euler(beta1=np.pi/2, beta2=np.pi/2, alpha1=zero_to_pi_half[::-1])
  34. DipolePath = PairRotationalPath()
  35. DipolePath.add_euler(beta1=pi_half_to_pi[::-1])
  36. DipolePath.add_euler(beta1=zero_to_pi_half[::-1])
  37. DipolePath.add_euler(beta1=zero_to_pi_half, beta2=zero_to_pi_half)
  38. DipolePath.add_euler(beta1=np.pi/2, beta2=np.pi/2, alpha1=zero_to_pi_half)
  39. DipolePath.add_euler(beta1=np.pi/2, alpha1=np.pi/2, beta2=zero_to_pi_half)
  40. DipolePath.add_euler(beta1=np.pi/2, beta2=pi_half_to_pi[::-1], alpha2=np.pi)
  41. DipolePath.add_euler(beta1=zero_to_pi_half[::-1], beta2=pi_half_to_pi, alpha2=np.pi)
  42. DipolePath.add_euler(beta1=zero_to_pi_half, beta2=pi_half_to_pi[::-1], alpha2=np.pi)
  43. DipolePath.add_euler(beta1=pi_half_to_pi, beta2=zero_to_pi_half[::-1], alpha2=np.pi)
  44. if __name__ == '__main__':
  45. params = ModelParams(R=150, kappaR=3)
  46. # ex1 = expansion.MappedExpansionQuad(0.44, params.kappaR, 0.001, max_l=20)
  47. # ex1 = expansion.Expansion24(sigma2=0.001, sigma4=0)
  48. # ex1 = expansion.Expansion(l_array=np.array([1]), coefs=expansion.rot_sym_expansion(np.array([1]), np.array([0.001])))
  49. # ex1 = expansion.SmearedCharges(omega_k=np.array([[0, 0], [np.pi, 0]]), lambda_k=5, sigma1=0.001, l_max=10)
  50. ex1 = expansion.SmearedCharges(omega_k=np.array([np.pi, 0]), lambda_k=3, sigma1=0.001, l_max=10)
  51. ex2 = ex1.clone()
  52. # rotations1, rotations2 = QuadPath.get_rotations()
  53. rotations1, rotations2 = DipolePath.get_rotations()
  54. ex1.rotate(rotations1)
  55. ex2.rotate(rotations2)
  56. dist = 2
  57. energy = interactions.charged_shell_energy(ex1, ex2, dist, params)
  58. plt.plot(energy)
  59. plt.show()