energy_gap.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from charged_shells import expansion, interactions, mapping
  4. from charged_shells.parameters import ModelParams
  5. from functools import partial
  6. from pathlib import Path
  7. from matplotlib import cm
  8. from mpl_toolkits.axes_grid1 import make_axes_locatable
  9. from matplotlib.colors import TwoSlopeNorm
  10. from matplotlib.ticker import FuncFormatter
  11. import json
  12. Expansion = expansion.Expansion
  13. def energy_gap(ex1: Expansion, params: ModelParams, dist=2., match_expansion_axis_to_params=None):
  14. ex2 = ex1.clone()
  15. ex3 = ex1.clone()
  16. ex2.rotate_euler(alpha=0, beta=np.pi/2, gamma=0) # to get EP config between ex1 and ex2
  17. energy_fn = mapping.parameter_map_two_expansions(partial(interactions.charged_shell_energy, dist=dist),
  18. match_expansion_axis_to_params)
  19. energy_ep = energy_fn(ex1, ex2, params)
  20. energy_pp = energy_fn(ex1, ex3, params)
  21. return (energy_pp - energy_ep) / energy_pp
  22. def abar_kappaR_dependence(save_as=None):
  23. kappaR = np.linspace(0.01, 25, 25)
  24. a_bar = np.array([0.2, 0.4, 0.6, 0.8])
  25. params = ModelParams(R=150, kappaR=kappaR)
  26. ex = expansion.MappedExpansionQuad(a_bar[:, None], kappaR[None, :], 0.001)
  27. # ex = expansion.MappedExpansionQuad(a_bar, kappaR, 0.001)
  28. gap = energy_gap(ex, params, match_expansion_axis_to_params=1)
  29. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  30. for g, lbl in zip(gap, [rf'$\bar a={a}$' for a in a_bar]):
  31. ax.plot(kappaR, g, label=lbl)
  32. ax.legend(fontsize=17)
  33. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  34. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  35. ax.set_ylabel(r'$\frac{V_{pp}-V_{ep}}{V_{pp}}$', fontsize=20)
  36. plt.tight_layout()
  37. if save_as is not None:
  38. plt.savefig(save_as, dpi=600)
  39. plt.show()
  40. def abar_kappaR_dependence2(save_as=None):
  41. kappaR = np.array([1, 3, 10, 30])
  42. a_bar = np.linspace(0.2, 0.8, 30)
  43. params = ModelParams(R=150, kappaR=kappaR)
  44. ex = expansion.MappedExpansionQuad(a_bar[:, None], kappaR[None, :], 0.001)
  45. # ex = expansion.MappedExpansionQuad(a_bar, kappaR, 0.001)
  46. gap = energy_gap(ex, params, match_expansion_axis_to_params=1)
  47. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  48. for g, lbl in zip(gap.T, [rf'$\kappa R={kR}$' for kR in kappaR]):
  49. ax.plot(a_bar, g, label=lbl)
  50. ax.legend(fontsize=17)
  51. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  52. ax.set_xlabel(r'$\bar a$', fontsize=15)
  53. ax.set_ylabel(r'$\frac{V_{pp}-V_{ep}}{V_{pp}}$', fontsize=20)
  54. plt.tight_layout()
  55. if save_as is not None:
  56. plt.savefig(save_as, dpi=600)
  57. plt.show()
  58. def charge_kappaR_dependence(a_bar, min_charge, max_charge, save_as=None, cmap=cm.jet):
  59. kappaR = np.linspace(0.01, 10, 50)
  60. params = ModelParams(R=150, kappaR=kappaR)
  61. charge = np.linspace(min_charge, max_charge, 100)
  62. ex = expansion.MappedExpansionQuad(a_bar, kappaR, 0.001, sigma0=charge)
  63. # ex = expansion.MappedExpansionQuad(a_bar, kappaR, 0.001)
  64. gap = energy_gap(ex, params, match_expansion_axis_to_params=0)
  65. colors = cmap(np.linspace(0, 1, len(charge)))
  66. sm = cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=np.min(charge), vmax=np.max(charge)))
  67. sm.set_array([])
  68. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  69. for g, lbl, c in zip(gap.T, [rf'$\sigma_0 ={1000 * c:.2f}$' for c in charge], colors):
  70. ax.plot(kappaR, g, label=lbl, c=c)
  71. # ax.legend(fontsize=17)
  72. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  73. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  74. ax.set_ylabel(r'$\frac{V_{pp}-V_{ep}}{V_{pp}}$', fontsize=20)
  75. divider = make_axes_locatable(ax)
  76. cax = divider.append_axes('right', size='5%', pad=0.05)
  77. cbar = fig.colorbar(sm, cax=cax, orientation='vertical')
  78. cbar.set_label(r'$\tilde \sigma_0$', rotation=90, labelpad=15, fontsize=12)
  79. plt.tight_layout()
  80. if save_as is not None:
  81. plt.savefig(save_as, dpi=600)
  82. plt.show()
  83. def charge_kappaR_dependence_heatmap(a_bar, min_charge, max_charge, save_as=None, cmap=cm.jet):
  84. kappaR = np.linspace(0.01, 10, 50)
  85. params = ModelParams(R=150, kappaR=kappaR)
  86. charge = np.linspace(min_charge, max_charge, 100)
  87. ex = expansion.MappedExpansionQuad(a_bar, kappaR, 0.001, sigma0=charge)
  88. # ex = expansion.MappedExpansionQuad(a_bar, kappaR, 0.001)
  89. gap = energy_gap(ex, params, match_expansion_axis_to_params=0)
  90. norm = TwoSlopeNorm(vmin=np.min(gap), vcenter=0, vmax=np.max(gap))
  91. sm = cm.ScalarMappable(cmap=cmap, norm=norm)
  92. sm.set_array([])
  93. def y_formatter(x, pos):
  94. return f"{charge[int(x)-1]:.2f}"
  95. def x_formatter(x, pos):
  96. return f"{kappaR[int(x)-1]:.2f}"
  97. fig, ax = plt.subplots(figsize=plt.figaspect(1))
  98. ax.imshow(gap.T, cmap=cmap, origin='lower',
  99. # extent=[kappaR.min(), kappaR.max(), charge.min(), charge.max()]
  100. )
  101. # ax.legend(fontsize=17)
  102. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  103. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  104. ax.set_ylabel(r'$\tilde \sigma_0$', fontsize=15)
  105. plt.gca().xaxis.set_major_formatter(FuncFormatter(x_formatter))
  106. plt.gca().yaxis.set_major_formatter(FuncFormatter(y_formatter))
  107. # ax.set_xticks(kappaR)
  108. # ax.set_yticks(charge)
  109. divider = make_axes_locatable(ax)
  110. cax = divider.append_axes('right', size='5%', pad=0.05)
  111. cbar = fig.colorbar(sm, cax=cax, orientation='vertical')
  112. cbar.set_label(r'$\frac{V_{pp}-V_{ep}}{V_{pp}}$', rotation=90, labelpad=20, fontsize=12)
  113. plt.tight_layout()
  114. if save_as is not None:
  115. plt.savefig(save_as, dpi=600)
  116. plt.show()
  117. def IC_gap_plot(config_data: dict, save_as=None):
  118. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_10"))
  119. em_data = np.load(em_data_path.joinpath("relative_gap.npz"))
  120. for k in list(em_data.keys()):
  121. data = em_data[k]
  122. print(k, data.shape)
  123. for i in range(3):
  124. print(np.unique(data[:, i]))
  125. print('\n')
  126. def IC_gap_kappaR(config_data: dict, save_as=None):
  127. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_10"))
  128. em_data = np.load(em_data_path.joinpath("relative_gap.npz"))
  129. data = em_data['fixA']
  130. print(data)
  131. sort = np.argsort(data[:, 2])
  132. xdata = data[:, 2][sort]
  133. ydata = data[:, 3][sort]
  134. plt.plot(xdata, ydata)
  135. plt.xlabel('kappaR')
  136. plt.ylabel('gap')
  137. plt.show()
  138. def IC_gap_abar(config_data: dict, save_as=None):
  139. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_10"))
  140. em_data = np.load(em_data_path.joinpath("relative_gap.npz"))
  141. data = em_data['fixM']
  142. print(data)
  143. sort = np.argsort(data[:, 1])
  144. xdata = data[:, 1][sort]
  145. ydata = data[:, 3][sort]
  146. plt.plot(xdata, ydata)
  147. plt.xlabel('abar')
  148. plt.ylabel('gap')
  149. plt.show()
  150. def IC_gap_charge_at_abar(a_bar, config_data: dict, save_as=None, cmap=cm.coolwarm, which_change='changezp'):
  151. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_10"))
  152. em_data = np.load(em_data_path.joinpath("relative_gap.npz"))
  153. data = em_data[which_change]
  154. relevant_indices = data[:, 1] == a_bar
  155. if not np.any(relevant_indices):
  156. raise ValueError(f'No results for given a_bar = {a_bar}. Possible values: {np.unique(data[:, 1])}')
  157. data = data[relevant_indices]
  158. print('Unique gap sizes', np.unique(data[:, 3]))
  159. charge, inverse, counts = np.unique(data[:, 0], return_counts=True, return_inverse=True)
  160. colors = cmap(np.linspace(0, 1, len(charge)))
  161. sm = cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=np.min(charge), vmax=np.max(charge)))
  162. sm.set_array([])
  163. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  164. for i, c in enumerate(colors):
  165. idx, = np.nonzero(inverse == i)
  166. kR = data[idx, 2]
  167. gap = data[idx, 3]
  168. sort = np.argsort(kR)
  169. ax.plot(kR[sort], gap[sort], c=c)
  170. # ax.legend(fontsize=17)
  171. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  172. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  173. ax.set_ylabel(r'$\frac{V_{pp}-V_{ep}}{V_{pp}}$', fontsize=20)
  174. ax.set_xlim(-0.25, 10.25)
  175. # ax.set_ylim(-4.25, 6.25)
  176. divider = make_axes_locatable(ax)
  177. cax = divider.append_axes('right', size='5%', pad=0.05)
  178. cbar = fig.colorbar(sm, cax=cax, orientation='vertical')
  179. cbar.set_label(r'$\tilde \sigma_0$', rotation=90, labelpad=15, fontsize=12)
  180. plt.tight_layout()
  181. if save_as is not None:
  182. plt.savefig(save_as, dpi=600)
  183. plt.show()
  184. def main():
  185. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  186. config_data = json.load(config_file)
  187. # abar_kappaR_dependence(Path("/home/andraz/ChargedShells/Figures/full_amplitude_kappaR_dep.png"))
  188. # abar_kappaR_dependence2(Path("/home/andraz/ChargedShells/Figures/full_amplitude_abar_dep.png"))
  189. # charge_kappaR_dependence(a_bar=0.5, min_charge=-0.003, max_charge=0.003,
  190. # save_as=Path("/home/andraz/ChargedShells/Figures/full_amplitude_charge_abar05.png"),
  191. # cmap=cm.coolwarm)
  192. # charge_kappaR_dependence_heatmap(a_bar=0.5, min_charge=-0.003, max_charge=0.003,
  193. # save_as=Path("/home/andraz/ChargedShells/Figures/full_amplitude_heatmap_abar05.png"),
  194. # cmap=cm.bwr)
  195. # IC_gap_plot(config_data)
  196. # IC_gap_kappaR(config_data)
  197. # IC_gap_abar(config_data)
  198. IC_gap_charge_at_abar(0.8, config_data, which_change='changezc',
  199. # save_as=Path("/home/andraz/ChargedShells/Figures/Emanuele_data/IC_full_amplitude_charge_abar08.png")
  200. )
  201. if __name__ == '__main__':
  202. main()