Skip to content

Commit

Permalink
Improved the sscha-plot-data script
Browse files Browse the repository at this point in the history
  • Loading branch information
mesonepigreco committed May 23, 2022
1 parent 48d4c6c commit e1f30c7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Modules/Ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ def get_free_energy_interpolating(self, target_supercell, support_dyn_coarse = N
support_dyn_coarse,
support_dyn_fine)
else:
new_dyn = self.current_dyn.InterpolateMesh(target_supercell)
new_dyn = self.current_dyn.InterpolateMesh(target_supercell, lo_to_splitting = True)

print("dyn after interpolation:", new_dyn.GetSupercell())

Expand Down
127 changes: 77 additions & 50 deletions scripts/sscha-plot-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,65 +48,92 @@ def main():
minim_files = [sys.argv[x] + '.dat' for x in range(1, len(sys.argv))]

# Check if all the files exist
plot_frequencies = None
plot_minim = None
for f, m in zip(freqs_files, minim_files):
assert os.path.exists(f), 'Error, file {} not found.'.format(f)
assert os.path.exists(m), 'Error, file {} not found.'.format(m)

print("Reading the input...")

# Load all the data
freqs_data = np.concatenate([np.loadtxt(f) for f in freqs_files])
minim_data = np.concatenate([np.loadtxt(f) for f in minim_files])

print("Plotting...")

# Insert the x axis in the plotting data
xsteps = np.arange(minim_data.shape[0])
new_data = np.zeros(( len(xsteps), 8), dtype = np.double)
new_data[:,0] = xsteps
new_data[:, 1:] = minim_data
minim_data = new_data
if os.path.exists(f):
if plot_frequencies is None:
plot_frequencies = True
if not plot_frequencies:
raise IOError("Error, file {} found, but not others .freqs".format(f))
else:
if plot_frequencies:
raise IOError("Error, file {} not found.".format(f))
plot_frequencies = False


if os.path.exists(m):
if plot_minim is None:
plot_minim = True
if not plot_minim:
raise IOError("Error, file {} found, but not others .freqs".format(m))
else:
if plot_minim:
raise IOError("Error, file {} not found.".format(m))
plot_minim = False

if not plot_frequencies and not plot_minim:
print("Nothing to plot, check if the .dat and .freqs files exist.")
exit()

if plot_minim:
print("Preparing the minimization data...")
minim_data = np.concatenate([np.loadtxt(f) for f in minim_files])

# Insert the x axis in the plotting data
xsteps = np.arange(minim_data.shape[0])
new_data = np.zeros(( len(xsteps), 8), dtype = np.double)
new_data[:,0] = xsteps
new_data[:, 1:] = minim_data
minim_data = new_data

fig_data, axarr = plt.subplots(nrows=2, ncols = 2, sharex = True, dpi = DPI)

# Plot the data
axarr[0,0].fill_between(minim_data[:,0], minim_data[:,1] - minim_data[:, 2]*.5 ,
minim_data[:, 1] + minim_data[:, 2] * .5, color = "aquamarine")
axarr[0,0].plot(minim_data[:,0], minim_data[:,1], color = "k")
axarr[0,0].set_ylabel("Free energy / unit cell [meV]", fontsize = LBL_FS)


axarr[0,1].fill_between(minim_data[:,0], minim_data[:,3] - minim_data[:, 4]*.5 ,
minim_data[:, 3] + minim_data[:, 4] * .5, color = "aquamarine")
axarr[0,1].plot(minim_data[:,0], minim_data[:,3], color = "k")
axarr[0,1].set_ylabel("FC gradient", fontsize = LBL_FS)

axarr[1,1].fill_between(minim_data[:,0], minim_data[:,5] - minim_data[:, 6]*.5 ,
minim_data[:, 5] + minim_data[:, 6] * .5, color = "aquamarine")
axarr[1,1].plot(minim_data[:,0], minim_data[:,5], color = "k")
axarr[1,1].set_ylabel("Structure gradient", fontsize = LBL_FS)
axarr[1,1].set_xlabel("Good minimization steps", fontsize = LBL_FS)


axarr[1,0].plot(minim_data[:,0], minim_data[:,7], color = "k")
axarr[1,0].set_ylabel("Effective sample size", fontsize = LBL_FS)
axarr[1,0].set_xlabel("Good minimization steps", fontsize = LBL_FS)
fig_data.tight_layout()

fig_data, axarr = plt.subplots(nrows=2, ncols = 2, sharex = True, dpi = DPI)

# Plot the data
axarr[0,0].fill_between(minim_data[:,0], minim_data[:,1] - minim_data[:, 2]*.5 ,
minim_data[:, 1] + minim_data[:, 2] * .5, color = "aquamarine")
axarr[0,0].plot(minim_data[:,0], minim_data[:,1], color = "k")
axarr[0,0].set_ylabel("Free energy / unit cell [meV]", fontsize = LBL_FS)


axarr[0,1].fill_between(minim_data[:,0], minim_data[:,3] - minim_data[:, 4]*.5 ,
minim_data[:, 3] + minim_data[:, 4] * .5, color = "aquamarine")
axarr[0,1].plot(minim_data[:,0], minim_data[:,3], color = "k")
axarr[0,1].set_ylabel("FC gradient", fontsize = LBL_FS)

axarr[1,1].fill_between(minim_data[:,0], minim_data[:,5] - minim_data[:, 6]*.5 ,
minim_data[:, 5] + minim_data[:, 6] * .5, color = "aquamarine")
axarr[1,1].plot(minim_data[:,0], minim_data[:,5], color = "k")
axarr[1,1].set_ylabel("Structure gradient", fontsize = LBL_FS)
axarr[1,1].set_xlabel("Good minimization steps", fontsize = LBL_FS)

if plot_frequencies:
print("Plotting the frequencies")

axarr[1,0].plot(minim_data[:,0], minim_data[:,7], color = "k")
axarr[1,0].set_ylabel("Effective sample size", fontsize = LBL_FS)
axarr[1,0].set_xlabel("Good minimization steps", fontsize = LBL_FS)
fig_data.tight_layout()


# Now plot the frequencies
fig_freqs = plt.figure(dpi = DPI)
ax = plt.gca()
# Load all the data
freqs_data = np.concatenate([np.loadtxt(f) for f in freqs_files])
# Now plot the frequencies
fig_freqs = plt.figure(dpi = DPI)
ax = plt.gca()

N_points, Nw = np.shape(freqs_data)
N_points, Nw = np.shape(freqs_data)

for i in range(Nw):
ax.plot(freqs_data[:, i] * CC.Units.RY_TO_CM)
for i in range(Nw):
ax.plot(freqs_data[:, i] * CC.Units.RY_TO_CM)

ax.set_xlabel("Good minimization steps", fontsize = LBL_FS)
ax.set_ylabel("Frequency [cm-1]", fontsize = LBL_FS)
ax.set_title("Frequcency evolution", fontsize = TITLE_FS)
fig_freqs.tight_layout()
ax.set_xlabel("Good minimization steps", fontsize = LBL_FS)
ax.set_ylabel("Frequency [cm-1]", fontsize = LBL_FS)
ax.set_title("Frequcency evolution", fontsize = TITLE_FS)
fig_freqs.tight_layout()

plt.show()

Expand Down

0 comments on commit e1f30c7

Please sign in to comment.