Skip to content

Commit 48d4c6c

Browse files
committed
Merge branch 'master' of github.com:SSCHAcode/python-sscha
2 parents 7c84f4d + a8394db commit 48d4c6c

31 files changed

Lines changed: 7946 additions & 595 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import cellconstructor as CC, cellconstructor.Phonons, cellconstructor.ForceTensor
2+
import ase, ase.dft.kpoints
3+
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
import matplotlib.cm as cm
7+
import matplotlib.colors as colors
8+
9+
import sys, os
10+
11+
NQIRR = 13
12+
#CMAP = "Spectral_r"
13+
PATH = "GXWXKGL"
14+
N_POINTS = 1000
15+
16+
SPECIAL_POINTS = {"G": [0,0,0],
17+
"X": [0, .5, .5],
18+
"L": [.5, .5, .5],
19+
"W": [.25, .75, .5],
20+
"K": [3/8., 3/4., 3/8.]}
21+
22+
# Load the harmonic and sscha phonons
23+
harmonic_dyn = CC.Phonons.Phonons('harmonic_dyn', NQIRR)
24+
sscha_dyn = CC.Phonons.Phonons('sscha_T300_dyn', NQIRR)
25+
26+
# Get the band path
27+
qpath, data = CC.Methods.get_bandpath(harmonic_dyn.structure.unit_cell,
28+
PATH,
29+
SPECIAL_POINTS,
30+
N_POINTS)
31+
xaxis, xticks, xlabels = data # Info to plot correclty the x axis
32+
33+
# Get the phonon dispersion along the path
34+
harmonic_dispersion = CC.ForceTensor.get_phonons_in_qpath(harmonic_dyn, qpath)
35+
sscha_dispersion = CC.ForceTensor.get_phonons_in_qpath(sscha_dyn, qpath)
36+
37+
nmodes = harmonic_dyn.structure.N_atoms * 3
38+
39+
# Plot the two dispersions
40+
plt.figure(dpi = 150)
41+
ax = plt.gca()
42+
43+
for i in range(nmodes):
44+
lbl=None
45+
lblsscha = None
46+
if i == 0:
47+
lbl = 'Harmonic'
48+
lblsscha = 'SSCHA'
49+
50+
ax.plot(xaxis, harmonic_dispersion[:,i], color = 'k', ls = 'dashed', label = lbl)
51+
ax.plot(xaxis, sscha_dispersion[:,i], color = 'r', label = lblsscha)
52+
53+
# Plot vertical lines for each high symmetry points
54+
for x in xticks:
55+
ax.axvline(x, 0, 1, color = "k", lw = 0.4)
56+
ax.axhline(0, 0, 1, color = 'k', ls = ':', lw = 0.4)
57+
58+
ax.legend()
59+
60+
# Set the x labels to the high symmetry points
61+
ax.set_xticks(xticks)
62+
ax.set_xticklabels(xlabels)
63+
64+
ax.set_xlabel("Q path")
65+
ax.set_ylabel("Phonons [cm-1]")
66+
67+
plt.tight_layout()
68+
plt.savefig("dispersion.png")
69+
plt.show()
70+
71+
72+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import cellconstructor as CC, cellconstructor.Phonons
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
import scipy, scipy.optimize
6+
7+
import sys, os
8+
9+
"""
10+
This simple scripts plot the thermal expansion.
11+
It either directly plots the file produced at the end of thermal_expansion.py
12+
or it processes the dynamical matrices generated throughout the minimization.
13+
14+
It also fits the V(T) cuve and estimates the volumetric thermal expansion coefficient
15+
16+
alpha = dV/dT / V
17+
18+
At 300 K
19+
"""
20+
21+
22+
# Load all the dynamical matrices and compute volume
23+
DIRECTORY = "thermal_expansion"
24+
FILE = os.path.join(DIRECTORY, "thermal_expansion.dat")
25+
26+
27+
# Check if the file with the thermal expansion data exists
28+
if not os.path.exists( FILE):
29+
# If the simulation is not ended, load the volume from the dynamical matrices
30+
31+
# Get the dynamical matrices
32+
all_dyn_files = [x for x in os.listdir(DIRECTORY) if "sscha" in x and x.endswith("dyn1")]
33+
temperatures = [float(x.split("_")[-2].replace("T", "")) for x in all_dyn_files]
34+
35+
# Now sort in order of temperature
36+
sortmask = np.argsort(temperatures)
37+
all_dyn_files = [all_dyn_files[x] for x in sortmask]
38+
temperatures = np.sort(temperatures)
39+
40+
volumes = np.zeros_like(temperatures)
41+
42+
for i, fname in enumerate(all_dyn_files):
43+
# Load the dynamical matrix
44+
# The full_name means that we specify the name including the tail 1
45+
dyn = CC.Phonons.Phonons(os.path.join(DIRECTORY, fname), full_name = True)
46+
volumes[i] = dyn.get_volumes()
47+
48+
else:
49+
# Load the data from the final data file
50+
temperatures, volumes = np.loadtxt(FILE, unpack = True)
51+
52+
53+
# Prepare the figure and plot the V(T) from the sscha data
54+
plt.figure(dpi = 150)
55+
plt.scatter(temperatures, volumes, label = "SSCHA data", color = 'r')
56+
57+
# Fit the data with a quadratic curve
58+
def parabola(x, a, b, c):
59+
return a + b*x + c*x**2
60+
def diff_parab(x, a, b, c):
61+
return b + 2*c*x
62+
63+
popt, pcov = scipy.optimize.curve_fit(parabola, temperatures, volumes,
64+
p0 = [0,0,0])
65+
66+
# Evaluate the volume thermal expansion
67+
vol_thermal_expansion = diff_parab(300, *popt) / parabola(300, *popt)
68+
print("Vol thermal expansion: {} x 10^6 K^-1".format(vol_thermal_expansion * 1e6))
69+
plt.text(0.6, 0.2, r"$\alpha_v = "+"{:.1f}".format(vol_thermal_expansion*1e6)+r"\times 10^6 $ K$^{-1}$",
70+
transform = plt.gca().transAxes)
71+
72+
73+
# Plot the fit
74+
_t_ = np.linspace(np.min(temperatures), np.max(temperatures), 1000)
75+
plt.plot(_t_, parabola(_t_, *popt), label = "Fit", color = 'k', zorder = 0)
76+
77+
# Adjust the plot adding labels, legend, and saving in eps
78+
plt.xlabel("Temperature [K]")
79+
plt.ylabel(r"Volume [$\AA^3$]")
80+
plt.legend()
81+
plt.tight_layout()
82+
plt.savefig("thermal_expansion.png")
83+
plt.show()

0 commit comments

Comments
 (0)