import pylab
import sys
import matplotlib.pyplot as plt
import matplotlib.patches as ptc
from matplotlib import colors, ticker, cm

#------------------------
# User defined parameters
#------------------------

# The filenames of the averaged Hartree difference potential
fnames = ['hdp80','hdp100','hdp120','hdp140']

# The right material central region widths in Ang
names = ['80','100','120','140']

# z-coordinate of the interface position in Ang calculated as the midpoint between 
# the last atom of the left material and the first atom in the right material
zcoord_int = 27.2734

#------------
# Plot figure
#------------

plt.figure(figsize=(5,2))
ax = pylab.subplot(111)

# Loop through the different widths
for n in range(len(fnames)): 
	data = numpy.loadtxt(fnames[n]+'.dat', usecols=(0,1))
	ax.plot(data[:,0], data[:,1],label=names[n]+r' $\AA$',linewidth=0.75+0.1*n,zorder=len(fnames)-1-n)

emin = min(data[:,1])-0.5
emax = max(data[:,1])+0.5
zmin = min(data[:,0])
zmax = max(data[:,0])

print(zmin)
print(zmax)

ax.plot([zcoord_int,zcoord_int],[emin,emax],color='black',linestyle='-',linewidth=0.5)

ax.set_ylabel(r'$\langle\Delta$ $V_H\rangle$ (eV)', fontsize=10)
ax.set_xlabel(r'Cell Length Z ($\AA$)', fontsize=10)
ax.set_ylim(emin,emax)
ax.set_xlim(zmin,zmax)

ax.spines['top'].set_linewidth(0.5)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['right'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
ax.xaxis.set_tick_params(width=0.25,zorder=20)
ax.yaxis.set_tick_params(width=0.25,zorder=20)
ax.tick_params(direction='in', pad=7.5)

ax.legend(loc="lower right",fontsize=10,frameon=False,ncol=2)
plt.tight_layout()
plt.savefig("edp.png",dpi=300)
