#!/usr/bin/env python
import matplotlib.pyplot as plt
import matplotlib as mpl

# ENCUT=400 eV, 3x3 supercell, 4,6,8,10 kpoints
Eb3_400_x = [4,5,6,7,8,9,10]
Eb3_400 = [[81.086,	84.069,	85.081,	85.412],
[80.792,	85.265,	85.125,	85.337],
[82.523,	83.446,	83.568,	83.757],
[81.424,	83.566,	84.170,	84.665],
[81.716,	84.202,	83.926,	84.214],
[82.494,	82.859,	83.986,	84.283],
[81.067,	82.829,	83.736,	84.070]]
				
# ENCUT=400 eV, 4x4 supercell, 4,6,8 kpoints
Eb4_400_x = [4,5,6,7,8,9,10]
Eb4_400 = [[80.616,	86.842,	84.550,	85.641],
[80.178,	86.099,	85.051,	84.937],
[83.064,	82.619,	83.457,	83.469],
[79.427,	84.695,	83.371,	83.652],
[81.239,	84.175,	83.466,	83.350],
[81.101,	83.240,	82.901,	83.475],
[80.132,	85.062,	82.976,	82.849]]

mpl.rc("text", usetex=True)
fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(4.,4.))

plt.subplot(2,1,1)
plt.plot( Eb3_400_x, Eb3_400, marker='o' )
#y_avg = (Eb3_400[5][3] + Eb3_400[6][3]) / 2
y_avg = (Eb4_400[5][3] + Eb4_400[6][3]) / 2
plt.plot( [0,12], [y_avg, y_avg], linestyle='--', c='black' )
plt.legend(['4', '6', '8', '10'], numpoints=1)
plt.xlim(3.5,13.9)
plt.ylim(80.5,86.)
plt.tick_params(labelbottom='off', length=6, width=1)
plt.ylabel('Barrier (kJ/mol)')
plt.annotate('3x3', xy=(8, 85.0), size=20)

plt.subplot(2,1,2)
plt.plot( Eb4_400_x, Eb4_400, marker='o' )
#plt.plot( Eb3_400_x, Eb3_400, marker='o' )
#y_avg = (Eb4_400[5][2] + Eb4_400[6][2]) / 2
plt.plot( [0,12], [y_avg, y_avg], linestyle='--', c='black' )
plt.legend(['3', '4', '6', '8'], numpoints=1)
plt.xlim(3.5,13.9)
plt.ylim(79.,87.)
plt.annotate('4x4', xy=(8, 85.5), size=20)
plt.xlabel('Amount of layers')
plt.ylabel('Barrier (kJ/mol)')
plt.tick_params(length=6, width=1)

plt.tight_layout()
plt.subplots_adjust(wspace=0, hspace=0)
plt.savefig('convergence.pdf')
#plt.show()
