path_plot.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import numpy as np
  2. from charged_shells.rotational_path import PairRotationalPath, PathEnergyPlot
  3. from charged_shells import expansion, patch_size, interactions
  4. from charged_shells.parameters import ModelParams
  5. import matplotlib.pyplot as plt
  6. from pathlib import Path
  7. import json
  8. Array = np.ndarray
  9. zero_to_pi_half = np.linspace(0, np.pi/2, 100, endpoint=True)
  10. pi_half_to_pi = np.linspace(np.pi/2, np.pi, 100, endpoint=True)
  11. QuadPath = PairRotationalPath()
  12. QuadPath.set_default_x_axis(zero_to_pi_half)
  13. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half)
  14. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half[::-1])
  15. QuadPath.add_euler(beta1=zero_to_pi_half)
  16. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half)
  17. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half, alpha2=np.pi/2)
  18. QuadPath.add_euler(beta1=np.pi/2, beta2=np.pi/2, alpha1=zero_to_pi_half[::-1])
  19. DipolePath = PairRotationalPath()
  20. DipolePath.set_default_x_axis(zero_to_pi_half)
  21. DipolePath.add_euler(beta2=pi_half_to_pi[::-1])
  22. DipolePath.add_euler(beta2=zero_to_pi_half[::-1])
  23. DipolePath.add_euler(beta2=zero_to_pi_half, beta1=zero_to_pi_half)
  24. DipolePath.add_euler(beta2=np.pi/2, beta1=np.pi/2, alpha2=zero_to_pi_half)
  25. DipolePath.add_euler(beta2=np.pi/2, alpha2=np.pi/2, beta1=pi_half_to_pi)
  26. DipolePath.add_euler(beta2=np.pi/2, beta1=pi_half_to_pi[::-1], alpha1=np.pi)
  27. DipolePath.add_euler(beta2=zero_to_pi_half[::-1], beta1=pi_half_to_pi, alpha1=np.pi)
  28. DipolePath.add_euler(beta2=zero_to_pi_half, beta1=pi_half_to_pi[::-1], alpha1=np.pi)
  29. DipolePath.add_euler(beta2=pi_half_to_pi, beta1=zero_to_pi_half[::-1], alpha1=np.pi)
  30. DipolePath2 = PairRotationalPath()
  31. DipolePath2.set_default_x_axis(zero_to_pi_half)
  32. DipolePath2.add_euler(beta2=pi_half_to_pi[::-1])
  33. DipolePath2.add_euler(beta2=zero_to_pi_half[::-1])
  34. DipolePath2.add_euler(beta2=zero_to_pi_half, beta1=zero_to_pi_half)
  35. DipolePath2.add_euler(beta2=np.pi/2, beta1=np.pi/2, alpha2=zero_to_pi_half)
  36. DipolePath2.add_euler(beta2=np.pi/2, alpha2=np.pi/2, beta1=pi_half_to_pi)
  37. DipolePath2.add_euler(beta2=zero_to_pi_half[::-1], beta1=pi_half_to_pi[::-1])
  38. DipolePath2.add_euler(beta2=zero_to_pi_half[::-1], beta1=np.pi)
  39. DipolePath2.add_euler(beta2=zero_to_pi_half, beta1=pi_half_to_pi[::-1], alpha1=np.pi)
  40. DipolePath2.add_euler(beta2=pi_half_to_pi, beta1=zero_to_pi_half[::-1], alpha1=np.pi)
  41. def model_comparison(save_as=None):
  42. params = ModelParams(R=150, kappaR=3)
  43. abar = 0.5
  44. sigma_tilde = 0.001
  45. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  46. ex2 = ex1.clone()
  47. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params)
  48. energy = path_plot.evaluate_path()
  49. x_axis = path_plot.rot_path.stack_x_axes()
  50. # peak_energy_sanity_check
  51. ex1new = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  52. ex2new = ex1new.clone()
  53. pp_energy = interactions.charged_shell_energy(ex1new, ex2new, params)
  54. print(f'PP energy: {pp_energy}')
  55. # Emanuele data
  56. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  57. config_data = json.load(config_file)
  58. em_data = np.load(Path(config_data["emanuele_data"]).joinpath("FIG_7").joinpath("pathway.npz"))['arr_0']
  59. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  60. ax.plot(em_data[:, 0], em_data[:, 1], label='ICi')
  61. ax.plot(x_axis, np.squeeze(energy), label='CSp')
  62. # ax.plot(x_axis, em_data[:, 1] / np.squeeze(energy), label='CSp')
  63. PathEnergyPlot.plot_style(fig, ax)
  64. if save_as is not None:
  65. plt.savefig(save_as, dpi=600)
  66. plt.show()
  67. def kappaR_dependence(kappaR: Array, abar: float, sigma_tilde=0.001, save_as=None):
  68. params = ModelParams(R=150, kappaR=kappaR)
  69. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  70. ex2 = ex1.clone()
  71. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params, match_expansion_axis_to_params=0)
  72. path_plot.plot(labels=[rf'$\kappa R$={kR}' for kR in kappaR],
  73. # norm_euler_angles={'beta2': np.pi},
  74. save_as=save_as)
  75. def abar_dependence(abar: Array, kappaR: float, sigma_tilde=0.001, save_as=None):
  76. params = ModelParams(R=150, kappaR=kappaR)
  77. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  78. ex2 = ex1.clone()
  79. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params, match_expansion_axis_to_params=None)
  80. path_plot.plot(labels=[rf'$\bar a$={a}' for a in abar],
  81. # norm_euler_angles={'beta2': np.pi},
  82. save_as=save_as)
  83. def sigma0_dependence(sigma0: Array, kappaR: float, abar: float, sigma_tilde=0.001, save_as=None):
  84. params = ModelParams(R=150, kappaR=kappaR)
  85. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30, sigma0=sigma0)
  86. ex2 = ex1.clone()
  87. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params, match_expansion_axis_to_params=None)
  88. path_plot.plot(labels=[rf'$\tilde \sigma_0={s0}$' for s0 in sigma0],
  89. # norm_euler_angles={'beta2': np.pi},
  90. save_as=save_as)
  91. def distance_dependence(dist: Array, kappaR: float, abar: float, sigma_tilde=0.001, save_as=None):
  92. params = ModelParams(R=150, kappaR=kappaR)
  93. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  94. ex2 = ex1.clone()
  95. plots = []
  96. for d in dist:
  97. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=d, params=params)
  98. x = d * kappaR
  99. plots.append(path_plot.evaluate_path() * np.exp(x) * x)
  100. x_axis = path_plot.rot_path.stack_x_axes()
  101. labels = [rf'$\rho/R ={d}$' for d in dist]
  102. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  103. for pl, lbl in zip(plots, labels):
  104. ax.plot(x_axis, pl, label=lbl)
  105. PathEnergyPlot.plot_style(fig, ax)
  106. ax.set_ylabel(r'$U \kappa\rho e^{\kappa\rho}$', fontsize=15)
  107. if save_as is not None:
  108. plt.savefig(save_as, dpi=600)
  109. plt.show()
  110. def IC_kappaR_dependence(config_data: dict, save_as=None):
  111. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("FIXEDCHARGE")
  112. .joinpath("FIX_A").joinpath("ECC_0.25"))
  113. kR1 = np.load(em_data_path.joinpath("EMME_1.").joinpath("pathway.npz"))['arr_0']
  114. kR3 = np.load(em_data_path.joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  115. kR10 = np.load(em_data_path.joinpath("EMME_10.").joinpath("pathway.npz"))['arr_0']
  116. labels = [rf'$\kappa R$={kR}' for kR in [1, 3, 10]]
  117. fig, ax = plt.subplots()
  118. ax.plot(kR1[:, 0], kR1[:, 1], label=labels[0])
  119. ax.plot(kR3[:, 0], kR3[:, 1], label=labels[1])
  120. ax.plot(kR10[:, 0], kR10[:, 1], label=labels[2])
  121. PathEnergyPlot.plot_style(fig, ax)
  122. if save_as is not None:
  123. plt.savefig(save_as, dpi=600)
  124. plt.show()
  125. def IC_abar_dependence(config_data: dict, save_as=None):
  126. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("FIXEDCHARGE").joinpath("FIX_M"))
  127. a03 = np.load(em_data_path.joinpath("ECC_0.15").joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  128. a04 = np.load(em_data_path.joinpath("ECC_0.2").joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  129. a05 = np.load(em_data_path.joinpath("ECC_0.25").joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  130. labels =[rf'$\bar a$={a}' for a in [0.3, 0.4, 0.5]]
  131. fig, ax = plt.subplots()
  132. ax.plot(a03[:, 0], a03[:, 1], label=labels[0])
  133. ax.plot(a04[:, 0], a04[:, 1], label=labels[1])
  134. ax.plot(a05[:, 0], a05[:, 1], label=labels[2])
  135. PathEnergyPlot.plot_style(fig, ax)
  136. if save_as is not None:
  137. plt.savefig(save_as, dpi=600)
  138. plt.show()
  139. def IC_sigma0_dependence(config_data: dict, save_as=None):
  140. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("CHARGE_ZC"))
  141. undercharged = np.load(em_data_path.joinpath("ZC_-277.27").joinpath("pathway.npz"))['arr_0']
  142. neutral = np.load(em_data_path.joinpath("ZC_-560").joinpath("pathway.npz"))['arr_0']
  143. overchargerd = np.load(em_data_path.joinpath("ZC_-842.74").joinpath("pathway.npz"))['arr_0']
  144. labels = [rf'$\tilde \sigma_0={s0}$' for s0 in [-0.001, 0, 0.001]]
  145. fig, ax = plt.subplots()
  146. ax.plot(overchargerd[:, 0], overchargerd[:, 1], label=labels[0])
  147. ax.plot(neutral[:, 0], neutral[:, 1], label=labels[1])
  148. ax.plot(undercharged[:, 0], undercharged[:, 1], label=labels[2])
  149. PathEnergyPlot.plot_style(fig, ax)
  150. if save_as is not None:
  151. plt.savefig(save_as, dpi=600)
  152. plt.show()
  153. def main():
  154. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  155. config_data = json.load(config_file)
  156. # model_comparison(
  157. # # save_as=Path(config_data["figures"]).joinpath("Emanuele_data").joinpath('IC_CS_quadrupole_path.pdf')
  158. # )
  159. # kappaR_dependence(np.array([1, 3, 10]), 0.5,
  160. # # save_as=Path("/home/andraz/ChargedShells/Figures/quadrupole_kappaR_dep.png")
  161. # )
  162. #
  163. # abar_dependence(np.array([0.3, 0.4, 0.5]), 3,
  164. # save_as=Path("/home/andraz/ChargedShells/Figures/quadrupole_abar_dep.png"))
  165. sigma0_dependence(np.array([0.001, 0.002, 0.003]), 3, 0.5,
  166. # save_as=Path("/home/andraz/ChargedShells/Figures/quadrupole_charge_dep_abar05_kappaR3.png")
  167. )
  168. # distance_dependence(dist=np.array([2, 3, 4, 6, 10, 20]), kappaR=3, abar=0.5,
  169. # # save_as=Path(config_data["figures"]).joinpath('quadrupole_distance_dep.png')
  170. # )
  171. # IC_kappaR_dependence(config_data,
  172. # # save_as=Path(config_data["figures"]).joinpath("Emanuele_data"). joinpath('quadrupole_kappaR_dep.png')
  173. # )
  174. #
  175. # IC_abar_dependence(config_data, save_as=Path(config_data["figures"]).joinpath("Emanuele_data").
  176. # joinpath('quadrupole_abar_dep.png'))
  177. #
  178. # IC_sigma0_dependence(config_data, save_as=Path(config_data["figures"]).joinpath("Emanuele_data").
  179. # joinpath('quadrupole_charge_dep_abar05_kappaR3.png'))
  180. if __name__ == '__main__':
  181. main()