#!/usr/bin/env python ######################################################### import matplotlib.pyplot as plt # import matplotlib as mpl # import numpy as np # from scipy.interpolate import Rbf # from scipy.optimize import minimize # from math import * # from sys import stdout # ######################################################### # # # this code produces a 2D contour plot and the MEP on # # the PES. # # this code is written for a diatomic molecule thinking # # about the 2D cut of the potential considering the # # interatomic distance (r) and the distance of the # # CoM (Z) from the surface as variables. # # Therefore the data.dat input file must be formatted # # as: r Z E # # You can define the variables related to the plot # # apperance and (more important) to the interpolation # # and the MEP calculation in the VARIABLES section. # # # # Davide Migliorini Leiden, 2015 # # # #-------------------------------------------------------# # A massive update has been implemented including a way # # better fitting procedure to find the MEP and a better # # 2D interpolation function: scipy.interpolate.Rbf # # I am too lazy to proper document all the changes # # however the comments in the code should make it # # (fairly) self-explainatory. # # I hope. # # # # Davide Migliorini Leiden, 2018 # # # #-------------------------------------------------------# # Some changes were implemented to improve the figures, # # too lazy to document. # # # # Nick Gerrits Leiden, 2018 # # # ######################################################### ######################################################### # VARIABLES ############################################# # Title & file name inputs = [ 'barrier_theta_phi_top.dat', 'barrier_theta_phi_fcc.dat', 'barrier_theta_phi_bridge.dat', 'barrier_theta_phi_TS.dat' ] titles = [ 'Top', 'Fcc', 'Bridge', 'TS' ] # contour line minE = 100. # min and max E shown in the plot maxE = 204. # spacing = 10.0 # E spacing between contour lines # set up plot parameters mpl.rc("text", usetex=True) Ncols=4 fig, ax = plt.subplots(nrows=1, ncols=Ncols, figsize=(6.96,4)) ######################################################## # Contour plot ######################################### ######################################################## images = [] def ReadAndInterpolate(INP, Title, minE, maxE, spacing, plot,bar=False): plt.subplot(1,Ncols,plot) X = [] Y = [] E = [] lines = open(INP).readlines() for i in range(0, len(lines)): X.append(float( lines[i].split()[1] )) Y.append(float( lines[i].split()[2] )) E.append(float( lines[i].split()[5] )) N = len(lines) X = np.array(X) Y = np.array(Y) E = np.array(E) print( " -----------------------" ) print( " file: ", INP ) print( " title:", Title ) print( " Energy values (min-max):" ) print( " (", min(E), max(E), ") [ eV ]" ) # CONTOUR LINES PLOT ################################### levels = np.arange( minE, maxE , spacing ) #range of energies shown # generate a uniform XY grid density = 100 # number of points per dimention in the denser grid Xnew, Ynew = np.meshgrid( np.linspace( min(X), max(X), density ), np.linspace( min(Y), max(Y), density ) ) # interpolate Z on the XY uniform grid F = Rbf(X, Y, E, function='cubic', smooth=0. ) Znew = F(Xnew, Ynew) # Contour lines ### # plt.subplot(1,2,plot) areas = plt.contourf(Xnew, Ynew, Znew, levels, zorder=-1, cmap='jet' )# , colors='k' ) # coloured areas contours = plt.contour( Xnew, Ynew, Znew, levels, colors='k', zorder=0 ) # black level lines # plt.scatter(Xnew,Ynew, s=1) # plot appereance ### images.append( areas ) # plt.colorbar(areas) #plt.axis('scaled') plt.xlabel( r'$\theta$ (deg.)' ) if plot == 1: plt.ylabel( r'$\phi$ (deg.)' ) else: plt.tick_params(labelleft='off') # plt.axis('equal') # plt.xlim(min(X), max(X)) plt.xlim(90., 149.) plt.ylim(min(Y), max(Y)) plt.yticks( np.arange(0., 420., 60.) ) plt.title( "%s" % Title ) ################################################################### ################################################################### ################################################################### for i in range(4): ReadAndInterpolate(inputs[i], titles[i], minE, maxE, spacing, i+1, True) plt.tight_layout() plt.subplots_adjust(wspace=0.0, hspace=-0.0) cbar_ax = fig.add_axes([0.89, 0.1, 0.025, 0.85]) #xmin, ymin, xwidth, ywidth fig.colorbar(images[0], cax=cbar_ax) #, ticks=np.arange(0.0,0.7,0.1) cbar_ax.set_ylabel('Barrier height (kJ/mol)') fig.subplots_adjust(right=0.87, left=0.08) plt.savefig('barrier_theta_phi.pdf') #plt.show()