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

srp_failed = np.array(
[[3.857,	'O$_2$ + Al(111)'],
[5.844,	'HCl + Au(111)']]
)

srp_difficult = np.array(
[[4.44,	'O$_2$ + Cu(111)'],
[5.421, 	'H$_2$O + Ni(111)'],
[6.297, 	'NH$_3$ + Ru(0001)']]
)

srp_csrp = np.array(
[[7.382,	'N$_2$ + Ru(0001)'],
[8.395,	'H$_2$ + Ni(111)'],
[8.555,	'H$_2$ + Ru(0001)'],
[8.795,	'H$_2$ + Pt(211)']]
)

srp_srp = np.array(
[[7.885,	'H$_2$ + Cu(100)'],
[8.055,	'H$_2$ + Cu(111)'],
[9.065,	'H$_2$ + Pt(111)'],
[10.99,	'CH$_4$ + Ni(111)'],
[11.39,	'CH$_4$ + Pt(211)'],
[11.66,	'CH$_4$ + Pt(111)']]
)

mpl.rc("text", usetex=True)
#fig = plt.figure(figsize=(3.69,3))
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(6.69,3.))

dy = [0., 0.5]
ddy = 0.1
fontsize = 8

for i in srp_failed:
	handle1, = plt.plot( [float(i[0]), float(i[0])], [dy[0], dy[1]], color='red')
	plt.text( float(i[0]), dy[1] + ddy, i[1], fontsize=fontsize, rotation=90, rotation_mode='anchor', verticalalignment='center')

for i in srp_difficult:
	handle2, = plt.plot( [float(i[0]), float(i[0])], [dy[0], dy[1]], color='orange')
	plt.text( float(i[0]), dy[1] + ddy, i[1], fontsize=fontsize, rotation=90, rotation_mode='anchor', verticalalignment='center')

for i in srp_csrp:
	handle3, = plt.plot( [float(i[0]), float(i[0])], [dy[0], dy[1]], color='green')
	plt.text( float(i[0]), dy[1] + ddy, i[1], fontsize=fontsize, rotation=90, rotation_mode='anchor', verticalalignment='center')

for i in srp_srp:
	handle4, = plt.plot( [float(i[0]), float(i[0])], [dy[0], dy[1]], color='blue')
	plt.text( float(i[0]), dy[1] + ddy, i[1], fontsize=fontsize, rotation=90, rotation_mode='anchor', verticalalignment='center')

plt.annotate( '', xy=(6., 2.2), xycoords='data', xytext=(10.5, 2.2), textcoords='data', fontsize=10, arrowprops=dict(arrowstyle='->'))
plt.annotate( 'Increasing amount of electron transfer', xy=(6.7, 2.3), xycoords='data', fontsize=10)
plt.annotate( 'Increasing amount of "repulsiveness" of SRP DF', xy=(6.3, 2.), xycoords='data', fontsize=10)

plt.legend([handle1, handle2, handle3, handle4], ['failed', 'difficult', 'c-SRP', 'SRP'], loc='best', numpoints=1, frameon=False, handlelength=1, mode='expand', ncol=4)
#plt.legend(loc='upper left', numpoints=1, handletextpad=0.5, borderaxespad=0.2, frameon=False)
plt.xlim(3.5, 12.)
#plt.xticks( np.arange( 3., 15., 2. ) )
plt.ylim(0., 3.)
plt.yticks([])
plt.tick_params(length=6, width=1, labelleft=False)
plt.ylabel('Molecule-metal surface')
plt.xlabel('Work function - electron affinity (eV)')

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