def corrEtotplot(ax,Eact,Ecmp,a,b,label): d1 = combinenparrayrange(Eact, a, b, Eidx) d2 = combinenparrayrange(Ecmp, a, b, Eidx) rmse = gt.calculaterootmeansqrerror(d1, d2) slope, intercept, r_value, p_value, std_err = st.linregress(d1, d2) lin = 'Slope: ' + '%s' % float('%.3g' % slope) + ' Int.: ' + '%s' % float('%.3g' % intercept) + ' $r^2$: ' + '%s' % float('%.3g' % r_value**2) ax.plot(d1,d1,color='black',label='DFT',linewidth=2,) ax.scatter(d1, d2, color='red',label=label + ' RMSE ' + '%s' % float('%.3g' % rmse) + ' kcal/mol ' + lin, marker=r"o",s=50) # Set Limits ax.set_xlim([d1.min(),d1.max()]) ax.set_ylim([d1.min(),d1.max()]) font = {'family': 'Bitstream Vera Sans', 'weight': 'heavy', 'size': 24} ax.set_ylabel('$E_{cmp}$',fontdict=font) ax.set_xlabel('$E_{ref}$',fontdict=font) ax.legend(bbox_to_anchor=(0.01, 0.99), loc=2, borderaxespad=0., fontsize=10) t_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(t_formatter) ax.yaxis.set_major_formatter(t_formatter)
def graphEdiffDelta2D(ax, data1, data2, Na): #data1 = gt.convert * data1 #data2 = gt.convert * data2 x, y, z, d = gt.calculateelementdiff2D(data1) x2, y2, z2, d2 = gt.calculateelementdiff2D(data2) RMSE = gt.calculaterootmeansqrerror(d, d2) / float(Na) print('dataz1:', z) print('dataz2:', z2) z = np.abs(z - z2) print('zdiff:', z) # Set up a regular grid of interpolation points xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100) xi, yi = np.meshgrid(xi, yi) # Interpolate rbf = scipy.interpolate.Rbf(x, y, z, function='linear') zi = rbf(xi, yi) im = ax.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower', extent=[x.min(), x.max(), y.min(), y.max()]) ax.set_title('Difference Plot (symmetric)\nRMSE: ' + "{:.5f}".format(RMSE) + 'kcal/mol/atom Atoms: ' + str(Na), fontsize=14) # plt.xlabel('Structure') # plt.ylabel('Structure') ax.scatter(x, y, c=z, vmin=z.min(), vmax=z.max()) ax.set_xlim([-0.02 * x.max(), x.max() + 0.02 * x.max()]) ax.set_ylim([-0.02 * y.max(), y.max() + 0.02 * y.max()]) #ax.plot([x.min(),x.max()],[y.min(),x.max()],color='red',linewidth=4) ax.grid(True) return im
def graphEdiffDelta2D(ax, data1, data2, Na): #data1 = gt.convert * data1 #data2 = gt.convert * data2 x, y, z, d = gt.calculateelementdiff2D(data1) x2, y2, z2, d2 = gt.calculateelementdiff2D(data2) RMSE = gt.calculaterootmeansqrerror(d, d2) / float(Na) print('Number of atoms: ' + str(Na)) print('RMSE: ' + str(RMSE) + ' kcal/mol/atom') print('RMSE: ' + str(float(Na) * RMSE) + ' kcal/mol') z = np.abs(z - z2) C = data1.shape[0] mat = np.ndarray(shape=(C, C), dtype=float) for i in x: for j in y: I = int(i) J = int(j) mat[J, I] = z[J + I * C] #get discrete colormap cmap = plt.get_cmap('RdBu', np.max(mat) - np.min(mat) + 1) # Show mat im = ax.matshow(mat, vmin=np.min(mat), vmax=np.max(mat)) cmap = plt.cm.jet norm = plt.Normalize(mat.min(), mat.max()) rgba = cmap(norm(mat)) rgba[range(C), range(C), :3] = 1, 1, 1 ax.imshow(rgba, interpolation='nearest') # Plot center line #ax.plot([x.min()-0.5,x.max()+0.5],[y.min()-0.5,x.max()+0.5],color='black',linewidth=4,alpha=0.9) # Set Limits ax.set_xlim([-0.02 * x.max(), x.max() + 0.02 * x.max()]) ax.set_ylim([-0.02 * y.max(), y.max() + 0.02 * y.max()]) ax.xaxis.tick_bottom() return im
def graphEdiffDelta2D(ax, data1, data2, Na): #data1 = gt.convert * data1 #data2 = gt.convert * data2 x, y, z, d = gt.calculateelementdiff2D(data1) x2, y2, z2, d2 = gt.calculateelementdiff2D(data2) RMSE = gt.calculaterootmeansqrerror(d,d2) / float(Na) print ('Number of atoms: ' + str(Na)) print ('RMSE: ' + str(RMSE) + ' kcal/mol/atom') print ('RMSE: ' + str(float(Na)*RMSE) + ' kcal/mol') z = np.abs(z - z2) C = data1.shape[0] mat = np.ndarray(shape=(C,C),dtype=float) for i in x: for j in y: I = int(i) J = int(j) mat[J,I] = z[J+I*C] #get discrete colormap cmap = plt.get_cmap('RdBu', np.max(mat)-np.min(mat)+1) # Show mat im = ax.matshow(mat,vmin = np.min(mat), vmax = np.max(mat)) cmap = plt.cm.jet norm = plt.Normalize(mat.min(), mat.max()) rgba = cmap(norm(mat)) rgba[range(C), range(C), :3] = 1, 1, 1 ax.imshow(rgba, interpolation='nearest') # Plot center line #ax.plot([x.min()-0.5,x.max()+0.5],[y.min()-0.5,x.max()+0.5],color='black',linewidth=4,alpha=0.9) # Set Limits ax.set_xlim([-0.02*x.max(),x.max()+0.02*x.max()]) ax.set_ylim([-0.02*y.max(),y.max()+0.02*y.max()]) ax.xaxis.tick_bottom() return im
def Ecorrplot (ax1,Eact,Ecmp,mlbl,color,lab=False): mx = Eact.max() mn = Eact.min() if lab: ax1.plot((mn, mx), (mn, mx), color='black',label='DFT', linewidth=5) else: ax1.plot((mn, mx), (mn, mx), color='black', linewidth=5) rmse = gt.calculaterootmeansqrerror(Eact, Ecmp) ax1.scatter(Eact, Ecmp, marker=r'o', color=color, label= mlbl + ' RMSE: ' + "{:.3f}".format(rmse) + ' kcal/mol', linewidth=1) ax1.set_xlim([mn,mx]) ax1.set_ylim([mn,mx]) #ax1.set_title("title) ax1.set_ylabel('$\Delta E_{cmp}$ (kcal/mol)') ax1.set_xlabel('$\Delta E_{ref}$ (kcal/mol)') ax1.legend(bbox_to_anchor=(0.01, 0.99), loc=2, borderaxespad=0., fontsize=16)
def graphEdiffDelta2D(ax, data1, data2, Na): data1 = gt.convert * data1 data2 = gt.convert * data2 x, y, z, d = gt.calculateelementdiff2D(data1) x2, y2, z2, d2 = gt.calculateelementdiff2D(data2) RMSE = gt.calculaterootmeansqrerror(d, d2) / float(Na) print("dataz1:", z) print("dataz2:", z2) z = np.abs(z - z2) print("zdiff:", z) # Set up a regular grid of interpolation points xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100) xi, yi = np.meshgrid(xi, yi) # Interpolate rbf = scipy.interpolate.Rbf(x, y, z, function="linear") zi = rbf(xi, yi) im = ax.imshow(zi, vmin=z.min(), vmax=z.max(), origin="lower", extent=[x.min(), x.max(), y.min(), y.max()]) ax.set_title( "Difference Plot (symmetric)\nRMSE: " + "{:.5f}".format(RMSE) + "kcal/mol/atom Atoms: " + str(natm), fontsize=14 ) # plt.xlabel('Structure') # plt.ylabel('Structure') ax.scatter(x, y, c=z, vmin=z.min(), vmax=z.max()) ax.set_xlim([-0.02 * x.max(), x.max() + 0.02 * x.max()]) ax.set_ylim([-0.02 * y.max(), y.max() + 0.02 * y.max()]) # ax.plot([x.min(),x.max()],[y.min(),x.max()],color='red',linewidth=4) ax.grid(True) return im
def corrEtotplot(ax, Eact, Ecmp, a, b, label): d1 = combinenparrayrange(Eact, a, b, Eidx) d2 = combinenparrayrange(Ecmp, a, b, Eidx) rmse = gt.calculaterootmeansqrerror(d1, d2) slope, intercept, r_value, p_value, std_err = st.linregress(d1, d2) lin = ( "Slope: " + "%s" % float("%.3g" % slope) + " Int.: " + "%s" % float("%.3g" % intercept) + " $r^2$: " + "%s" % float("%.3g" % r_value ** 2) ) ax.plot(d1, d1, color="black", label="DFT", linewidth=2) ax.scatter( d1, d2, color="red", label=label + " RMSE " + "%s" % float("%.3g" % rmse) + " kcal/mol " + lin, marker=r"o", s=50, ) # Set Limits ax.set_xlim([d1.min(), d1.max()]) ax.set_ylim([d1.min(), d1.max()]) font = {"family": "Bitstream Vera Sans", "weight": "heavy", "size": 24} ax.set_ylabel("$E_{cmp}$", fontdict=font) ax.set_xlabel("$E_{ref}$", fontdict=font) ax.legend(bbox_to_anchor=(0.01, 0.99), loc=2, borderaxespad=0.0, fontsize=10) t_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(t_formatter) ax.yaxis.set_major_formatter(t_formatter)
# Print some data from the NeuroChem print( '1) Number of Atoms Loaded: ' + str(nc.getNumAtoms()) ) print( '1) Number of Confs Loaded: ' + str(nc.getNumConfs()) ) # Compute Energies of Conformations print('Computing energies...') _t1b = tm.time() Ecmp_t = nc.computeEnergies() _t2b = (tm.time() - _t1b) * 1000.0 print('Computation complete. Time: ' + "{:.4f}".format(_t2b) + 'ms') Ecmp_t = setmaxE(Eact_t, Ecmp_t, 300.0) Eact_t = setmaxE(Eact_t, Eact_t, 300.0) tNa = nc.getNumAtoms() err.append(gt.hatokcal * gt.calculaterootmeansqrerror(np.array(Eact_t, dtype=float),np.array(Ecmp_t, dtype=float)) / float(tNa)) sze.append(float(len(Eact_t))) time += _t2b Eidx.append(N) Emin.append(gt.hatokcal * np.array( Ecmp_t ).min()) Efle.append(i) N += 1 Ecmp.append( gt.hatokcal * np.array( Ecmp_t ) ) Eact.append( gt.hatokcal * np.array( Eact_t ) ) err = np.array(err, dtype=float) sze = np.array(sze, dtype=float)
# n = 0 # m = 9 # Ecmp1 = gt.hatokcal * Ecmp1[n:m] # Eact = gt.hatokcal * Eact[n:m] Ecmp1 = gt.hatokcal * Ecmp1 Eact = gt.hatokcal * Eact # Eact2 = gt.hatokcal * Eact2 IDX = np.arange(0, Eact.shape[0], 1, dtype=float) + 1 # Ecmp1 = Ecmp1 - Ecmp1.min() # Eact = Eact - Eact.min() # Eact2 = Eact2 - Eact2.min() rmse1 = gt.calculaterootmeansqrerror(Eact, Ecmp1) # rmse2 = gt.calculaterootmeansqrerror(Eact,Eact2) print("Spearman corr. 1: " + "{:.3f}".format(st.spearmanr(Ecmp1, Eact)[0])) # print ( "Spearman corr. 2: " + "{:.3f}".format(st.spearmanr(Eact2,Eact)[0]) ) # plt.plot (IDX, Eact, '-', marker=r'o', color='black',label='DFT', linewidth=2, markersize=10) # plt.plot (IDX, Ecmp1, ':', marker=r'D', color='red', label='ANI-1 RMSE: ' + "{:.7f}".format(rmse1) + ' kcal/mol', linewidth=4, markersize=8) plt.plot(IDX, Eact, "-", color="black", label="DFT", linewidth=3) plt.plot(IDX, Ecmp1, "--", color="red", label="ANI-1 RMSE: " + "{:.3f}".format(rmse1) + " kcal/mol", linewidth=3) # plt.plot (IDX, Eact2, '--', color='blue', label='DFTB RMSE: ' + "{:.3f}".format(rmse2) + ' kcal/mol', linewidth=2) plt.title("BO MD Trajectory - Ranolazine") plt.ylabel("$\Delta$E calculated (kcal/mol)") plt.xlabel("Step number")
#n = 0 #m = 9 #Ecmp1 = gt.hatokcal * Ecmp1[n:m] #Eact = gt.hatokcal * Eact[n:m] Ecmp1 = gt.hatokcal * Ecmp1 Eact = gt.hatokcal * Eact #Eact2 = gt.hatokcal * Eact2 IDX = np.arange(0,Eact.shape[0],1,dtype=float) + 1 #Ecmp1 = Ecmp1 - Ecmp1.min() #Eact = Eact - Eact.min() #Eact2 = Eact2 - Eact2.min() rmse1 = gt.calculaterootmeansqrerror(Eact,Ecmp1) #rmse2 = gt.calculaterootmeansqrerror(Eact,Eact2) print ( "Spearman corr. 1: " + "{:.3f}".format(st.spearmanr(Ecmp1,Eact)[0]) ) #print ( "Spearman corr. 2: " + "{:.3f}".format(st.spearmanr(Eact2,Eact)[0]) ) #plt.plot (IDX, Eact, '-', marker=r'o', color='black',label='DFT', linewidth=2, markersize=10) #plt.plot (IDX, Ecmp1, ':', marker=r'D', color='red', label='ANI-1 RMSE: ' + "{:.7f}".format(rmse1) + ' kcal/mol', linewidth=4, markersize=8) plt.plot (IDX, Eact, '-', color='black',label='DFT', linewidth=3) plt.plot (IDX, Ecmp1, '--', color='red', label='ANI-1 RMSE: ' + "{:.3f}".format(rmse1) + ' kcal/mol', linewidth=3) #plt.plot (IDX, Eact2, '--', color='blue', label='DFTB RMSE: ' + "{:.3f}".format(rmse2) + ' kcal/mol', linewidth=2) plt.title("BO MD Trajectory - Ranolazine") plt.ylabel('$\Delta$E calculated (kcal/mol)') plt.xlabel('Step number')
dir = '/Research/ANN-Test-Data/GDB-11-W98XD-6-31gd/train_05/' dir2 = '/Research/ANN-Test-Data/GDB-11-W98XD-6-31gd/train_06/' #file = 'RMSEperATOM.dat' file = 'gdb11_s05-99_test.dat_graph' data1 = gt.getfltsfromfile('/home/' + user + dir + file, [0]) data2 = gt.getfltsfromfile('/home/' + user + dir + file, [1]) data3 = gt.getfltsfromfile('/home/' + user + dir + file, [2]) data4 = gt.getfltsfromfile('/home/' + user + dir2 + file, [2]) data2 = gt.calculateelementdiff(data2) data3 = gt.calculateelementdiff(data3) data4 = gt.calculateelementdiff(data4) rmse5 = gt.calculaterootmeansqrerror(data2[:,1],data3[:,1]) / 63.0 rmse6 = gt.calculaterootmeansqrerror(data2[:,1],data4[:,1]) / 63.0 print('Datasize: ' + str(data1.shape[0])) font = {'family' : 'Bitstream Vera Sans', 'weight' : 'normal', 'size' : 14} plt.rc('font', **font) #print(data2) plt.plot(data2[:,0], data2[:,1], color='black', label='wB97X/6-31G*',linewidth=2) plt.scatter(data2[:,0], data2[:,1], color='black',linewidth=4) plt.plot(data3[:,0], data3[:,1],'r--', color='blue', label='ANN - GDB-5 RMSE: ' + "{:.6f}".format(rmse5) + "eV/atom",linewidth=2)
print("1) Number of Confs Loaded: " + str(nc.getNumConfs())) # Compute Energies of Conformations print("Computing energies...") _t1b = tm.time() Ecmp_t = nc.computeEnergies() _t2b = (tm.time() - _t1b) * 1000.0 print("Computation complete. Time: " + "{:.4f}".format(_t2b) + "ms") Ecmp_t = setmaxE(Eact_t, Ecmp_t, 300.0) Eact_t = setmaxE(Eact_t, Eact_t, 300.0) tNa = nc.getNumAtoms() err.append( gt.hatokcal * gt.calculaterootmeansqrerror(np.array(Eact_t, dtype=float), np.array(Ecmp_t, dtype=float)) / float(tNa) ) sze.append(float(len(Eact_t))) time += _t2b Eidx.append(N) Emin.append(gt.hatokcal * np.array(Ecmp_t).min()) Efle.append(i) N += 1 Ecmp.append(gt.hatokcal * np.array(Ecmp_t)) Eact.append(gt.hatokcal * np.array(Eact_t)) err = np.array(err, dtype=float)
[1]) data3 = gt.convert * gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [2]) #data4 = gt.convert * gt.getfltsfromfile('/home/' + user + dir1 + file2,' ', [1]) #data4 = gt.getfltsfromfile('/home/' + user + dir2 + file,' ', [1]) #data5 = gt.getfltsfromfile('/home/' + user + dir2 + file,' ', [2]) #data5 = gt.getfltsfromfile('/home/' + user + dir3 + file, [2]) #mean = np.mean(data3) #data2 = data2 - np.mean(data2) #data3 = data3 - np.mean(data3) #data4 = data4 - np.mean(data4) rmse1 = gt.calculaterootmeansqrerror(data2, data3) #rmse2 = gt.calculaterootmeansqrerror(data2,data4) #rmse3 = gt.calculaterootmeansqrerror(data2,data5) print('Datasize: ' + str(data1.shape[0])) font = {'family': 'Bitstream Vera Sans', 'weight': 'normal', 'size': 14} plt.rc('font', **font) data1 = data1 plt.plot(data1, data2, color='black', label='wB97X/6-31G*', linewidth=4) plt.scatter(data1, data2, color='black', linewidth=3) plt.scatter(data1, data3, color='blue', linewidth=3) plt.plot(data1,
def produce_scan(ax,title,xlabel,cnstfile,saefile,nnfdir,dtdir,dt1,dt2,dt3,smin,smax,iscale,ishift): xyz, typ, Eact, chk = gt.readncdat(dtdir + dt1,np.float32) xyz2, typ2, Eact2, chk = gt.readncdat(dtdir + dt2) xyz3, typ3, Eact3, chk = gt.readncdat(dtdir + dt3) #gt.writexyzfile("/home/jujuman/Dropbox/ChemSciencePaper.AER/TestCases/Dihedrals/4-Cyclohexyl-1-butanol/optimization/dihedral_"+dt1+".xyz",xyz,typ) #Eact = np.array(Eact) #Eact2 = np.array(Eact2) #Eact3 = np.array(Eact3) # Construct pyNeuroChem classes nc1 = pync.pyNeuroChem(cnstfile, saefile, nnfdir, 1) # Set the conformers in NeuroChem nc1.setConformers(confs=xyz, types=typ) # Print some data from the NeuroChem print('1) Number of Atoms Loaded: ' + str(nc1.getNumAtoms())) print('1) Number of Confs Loaded: ' + str(nc1.getNumConfs())) # Compute Forces of Conformations print('Computing energies 1...') _t1b = tm.time() Ecmp1 = nc1.energy() print('Computation complete 1. Time: ' + "{:.4f}".format((tm.time() - _t1b) * 1000.0) + 'ms') n = smin m = smax Ecmp1 = gt.hatokcal * Ecmp1 Eact = gt.hatokcal * Eact Eact2 = gt.hatokcal * Eact2 Eact3 = gt.hatokcal * Eact3 IDX = np.arange(0, Eact.shape[0], 1, dtype=float) * iscale + ishift IDX = IDX[n:m] Eact = Eact[n:m] Eact2 = Eact2[n:m] Eact3 = Eact3[n:m] Ecmp1 = Ecmp1[n:m] Ecmp1 = Ecmp1 - Ecmp1.min() Eact = Eact - Eact.min() Eact2 = Eact2 - Eact2.min() Eact3 = Eact3 - Eact3.min() rmse1 = gt.calculaterootmeansqrerror(Eact, Ecmp1) rmse3 = gt.calculaterootmeansqrerror(Eact, Eact2) rmse4 = gt.calculaterootmeansqrerror(Eact, Eact3) print("Spearman corr. 1: " + "{:.3f}".format(st.spearmanr(Ecmp1, Eact)[0])) print("Spearman corr. 2: " + "{:.3f}".format(st.spearmanr(Eact2, Eact)[0])) print("Spearman corr. 3: " + "{:.3f}".format(st.spearmanr(Eact3, Eact)[0])) ax.plot(IDX, Eact, '-', marker=r'o', color='black', label='DFT', linewidth=2, markersize=7) ax.plot(IDX, Ecmp1, ':', marker=r'D', color='red', label='ANI-1 RMSE: ' + '%s' % float('%.3g' % rmse1) + ' kcal/mol', linewidth=2, markersize=5) ax.plot(IDX, Eact2, ':', marker=r'v', color='blue', label='DFTB RMSE: ' + '%s' % float('%.3g' % rmse3) + ' kcal/mol', linewidth=2, markersize=5) ax.plot(IDX, Eact3, ':', marker=r'*', color='orange', label='PM6 RMSE: ' + '%s' % float('%.3g' % rmse4) + ' kcal/mol', linewidth=2, markersize=7) #ax.plot(IDX, Eact, color='black', label='DFT', linewidth=3) #ax.scatter(IDX, Eact, marker='o', color='black', linewidth=4) th = ax.set_title(title,fontsize=16) th.set_position([0.5,1.005]) # Set Limits ax.set_xlim([ IDX.min(),IDX.max()]) ax.set_ylim([Eact.min()-1.0,Eact.max()+1.0]) ax.set_ylabel('$\Delta$E calculated (kcal/mol)') ax.set_xlabel(xlabel) ax.legend(bbox_to_anchor=(0.2, 0.98), loc=2, borderaxespad=0., fontsize=14)
def produce_scan(title, xlabel, cnstfile, saefile, nnfdir, dtdir, dt1, smin, smax, iscale, ishift, atm): xyz, frc, typ, Eact, chk = gt.readncdatwforce(dtdir + dt1) xyz = np.asarray(xyz, dtype=np.float32) xyz = xyz.reshape((xyz.shape[0], len(typ), 3)) print(xyz) frc = np.asarray(frc, dtype=np.float32) frc = frc.reshape((frc.shape[0], len(typ), 3)) Eact = np.array(Eact) # Construct pyNeuroChem classes nc1 = pync.pyNeuroChem(cnstfile, saefile, nnfdir, 0) # Set the conformers in NeuroChem nc1.setConformers(confs=xyz, types=typ) # Print some data from the NeuroChem print('1) Number of Atoms Loaded: ' + str(nc1.getNumAtoms())) print('1) Number of Confs Loaded: ' + str(nc1.getNumConfs())) # Compute Energies of Conformations print('Computing energies...') _t1b = tm.time() Ecmp1 = nc1.energy() print('Energy computation complete. Time: ' + "{:.4f}".format((tm.time() - _t1b) * 1000.0) + 'ms') # Compute Forces of Conformations print('Compute forces...') _t1b = tm.time() F = nc1.force() print('Force computation complete. Time: ' + "{:.4f}".format((tm.time() - _t1b) * 1000.0) + 'ms') #Fn = np.array(nc1.computeNumericalForces(dr=0.0001)) n = smin m = smax Ecmp1 = gt.hatokcal * Ecmp1 Eact = gt.hatokcal * Eact IDX = np.arange(0, Eact.shape[0], 1, dtype=float) * iscale + ishift IDX = IDX Eact = Eact Ecmp1 = Ecmp1 Ecmp1 = Ecmp1 - Ecmp1.min() Eact = Eact - Eact.min() rmse1 = gt.calculaterootmeansqrerror(Eact, Ecmp1) print("Spearman corr. 1: " + "{:.3f}".format(st.spearmanr(Ecmp1, Eact)[0])) fig, axes = plt.subplots(nrows=2, ncols=2) axes.flat[0].plot(IDX, Eact, '-', color='black', label='DFT', linewidth=6) axes.flat[0].plot(IDX, Ecmp1, '--', color='red', label='ANI-1', linewidth=6) #ax.plot(IDX, Eact, color='black', label='DFT', linewidth=3) #ax.scatter(IDX, Eact, marker='o', color='black', linewidth=4) th = axes.flat[0].set_title(title, fontsize=13) th.set_position([0.5, 1.00]) # Set Limits axes.flat[0].set_xlim([IDX.min(), IDX.max()]) #axes.flat[0].set_ylim([Eact.min()-1.0,Eact.max()+1.0]) axes.flat[0].set_ylabel('$\Delta$E calculated (kcal/mol)') axes.flat[0].set_xlabel(xlabel) axes.flat[0].legend(bbox_to_anchor=(0.2, 0.98), loc=2, borderaxespad=0., fontsize=12) #print (Fn) for i in range(0, 3): Fq = F[:, :, i][:, atm] #Fnq = Fn[:,i] Faq = (1.8897259885789 * np.array(frc)[:, :, i][:, atm]) print(Fq) print(Faq) th = axes.flat[i + 1].set_title("Force for atom " + str(atm) + ": coordinate " + str(i), fontsize=13) th.set_position([0.5, 1.00]) axes.flat[i + 1].set_xlim([IDX.min(), IDX.max()]) axes.flat[i + 1].plot(IDX, Faq, '-', color='black', label='DFT', linewidth=6) #axes.flat[i+1].plot(IDX, Fnq, '-', color='blue', label='ANI Numerical', # linewidth=6) axes.flat[i + 1].plot(IDX, Fq, '--', color='red', label='ANI Analytical', linewidth=6) axes.flat[i + 1].set_ylabel('Force (Ha/A)') axes.flat[i + 1].set_xlabel(xlabel) axes.flat[i + 1].legend(bbox_to_anchor=(0.2, 0.98), loc=2, borderaxespad=0., fontsize=12) font = {'family': 'Bitstream Vera Sans', 'weight': 'normal', 'size': 12} plt.rc('font', **font) plt.show()
mse_t = sqd / float(dpts) print('|-----------Prediction Complete-----------|') print(' Epoch error MSE(Ha) -- ') print(' Test: ' + "{:.5f}".format(mse_t)) print(' Epoch error RMSE(kcal/mol) -- ') print(' Test: ' + "{:.5f}".format(gt.hatokcal * np.sqrt(mse_t))) print('|-----------------------------------------|') Ecmp = gt.hatokcal * np.array(Ecmp, dtype=float) Eact = gt.hatokcal * np.array(Eact, dtype=float) # Compute RMSE in kcal/mol rmse = gt.calculaterootmeansqrerror(Ecmp, Eact) # End timer _t1e = tm.time() print('Computation complete. Time: ' + "{:.4f}".format((_t1e - _t1b)) + 's') # Output model information print('RMSE: ' + str(rmse)) # Plot plt.scatter(Eact, Ecmp, label='Baseline RMSE: ' + '%s' % float('%.3g' % rmse) + ' kcal/mol', color='red') plt.scatter(Eact, Eact, label='DFT', color='blue')
file = 'pp_02_test.dat_graph' #file = 'polypep_test.dat_graph' #file = 'aminoacid_00-12_test.dat_graph' #file = 'benzamide_conformers-0_test.dat_graph' #file = 'pentadecane_test.dat_graph' #file = 'retinolconformer_test.dat_graph' #data1 = gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [0]) data0 = gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [1]) data1 = gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [2]) data0 = gt.calculateelementdiff(data0) data1 = gt.calculateelementdiff(data1) rmse1 = 27.2113825435 * gt.calculaterootmeansqrerror(data0[:,1],data1[:,1]) / 24.0 print('Datasize: ' + str(data1.shape[0])) font = {'family' : 'Bitstream Vera Sans', 'weight' : 'normal', 'size' : 8} plt.rc('font', **font) data = data0 plt.plot(data[:,0], data[:,1], color='black', label='wB97X/6-31G*',linewidth=2) plt.scatter(data[:,0], data[:,1], color='black',linewidth=4) data = data1 plt.plot(data[:,0], data[:,1],'r--', color='blue', label='ANN - GDB-7 (6.1$\AA$) RMSE: ' + "{:.6f}".format(rmse1) + "eV/atom",linewidth=2)
file = 'pp_02_test.dat_graph' #file = 'polypep_test.dat_graph' #file = 'aminoacid_00-12_test.dat_graph' #file = 'benzamide_conformers-0_test.dat_graph' #file = 'pentadecane_test.dat_graph' #file = 'retinolconformer_test.dat_graph' #data1 = gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [0]) data0 = gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [1]) data1 = gt.getfltsfromfile('/home/' + user + dir1 + file, ' ', [2]) data0 = gt.calculateelementdiff(data0) data1 = gt.calculateelementdiff(data1) rmse1 = 27.2113825435 * gt.calculaterootmeansqrerror(data0[:, 1], data1[:, 1]) / 24.0 print('Datasize: ' + str(data1.shape[0])) font = {'family': 'Bitstream Vera Sans', 'weight': 'normal', 'size': 8} plt.rc('font', **font) data = data0 plt.plot(data[:, 0], data[:, 1], color='black', label='wB97X/6-31G*', linewidth=2) plt.scatter(data[:, 0], data[:, 1], color='black', linewidth=4)
Ecmp3 = gt.hatokcal * Ecmp3 Ecmp4 = gt.hatokcal * Ecmp4 Ecmp5 = gt.hatokcal * Ecmp5 Eact = gt.hatokcal * Eact Eotr = gt.hatokcal * Eotr Emax = 400.0 Ecmp1 = setmaxE(Eact,Ecmp1,Emax) Ecmp2 = setmaxE(Eact,Ecmp2,Emax) Ecmp3 = setmaxE(Eact,Ecmp3,Emax) Ecmp4 = setmaxE(Eact,Ecmp4,Emax) Ecmp5 = setmaxE(Eact,Ecmp5,Emax) Eotr = setmaxE(Eact,Eotr, Emax) Eact = setmaxE(Eact,Eact, Emax) rmse1 = gt.calculaterootmeansqrerror(Eact,Eotr) rmse2 = gt.calculaterootmeansqrerror(Eact,Ecmp1) rmse3 = gt.calculaterootmeansqrerror(Eact,Ecmp2) rmse4 = gt.calculaterootmeansqrerror(Eact,Ecmp3) rmse5 = gt.calculaterootmeansqrerror(Eact,Ecmp4) rmse6 = gt.calculaterootmeansqrerror(Eact,Ecmp5) mx = Eact.max() mn = Eact.min() #plt.scatter(IDX, Eact, marker='o' , color='black', linewidth=3) print ( "Spearman corr. DFTB: " + "{:.3f}".format(st.spearmanr(Eotr,Eact)[0]) ) print ( "Spearman corr. TGM 08: " + "{:.3f}".format(st.spearmanr(Ecmp1,Eact)[0]) ) #print ( "Spearman corr. TGM 07: " + "{:.3f}".format(st.spearmanr(Ecmp2,Eact)[0]) ) #print ( "Spearman corr. TGM 06: " + "{:.3f}".format(st.spearmanr(Ecmp3,Eact)[0]) )
data1 = gt.getfltsfromfile('/home/' + user + dir1 + file,' ', [0]) data2 = gt.convert * gt.getfltsfromfile('/home/' + user + dir1 + file,' ', [1]) data3 = gt.convert * gt.getfltsfromfile('/home/' + user + dir1 + file,' ', [2]) #data4 = gt.convert * gt.getfltsfromfile('/home/' + user + dir1 + file2,' ', [1]) #data4 = gt.getfltsfromfile('/home/' + user + dir2 + file,' ', [1]) #data5 = gt.getfltsfromfile('/home/' + user + dir2 + file,' ', [2]) #data5 = gt.getfltsfromfile('/home/' + user + dir3 + file, [2]) #mean = np.mean(data3) #data2 = data2 - np.mean(data2) #data3 = data3 - np.mean(data3) #data4 = data4 - np.mean(data4) rmse1 = gt.calculaterootmeansqrerror(data2,data3) #rmse2 = gt.calculaterootmeansqrerror(data2,data4) #rmse3 = gt.calculaterootmeansqrerror(data2,data5) print('Datasize: ' + str(data1.shape[0])) font = {'family' : 'Bitstream Vera Sans', 'weight' : 'normal', 'size' : 14} plt.rc('font', **font) data1 = data1 plt.plot(data1, data2, color='black', label='wB97X/6-31G*',linewidth=4) plt.scatter(data1, data2, color='black',linewidth=3)
""" # Fit model clf.fit(X_train, y_train) # Compute and print r^2 score print(clf.score(X_test, y_test)) # Store predicted energies Ecmp = clf.predict(X_test) Ecmp = gt.hatokcal * (Ecmp) Eact = gt.hatokcal * (y_test) # Compute RMSE in kcal/mol rmse = gt.calculaterootmeansqrerror(Ecmp, Eact) # End timer _t1e = tm.time() print("Computation complete. Time: " + "{:.4f}".format((_t1e - _t1b)) + "s") # Output model information print("RMSE: " + str(rmse)) # print(clf.coef_) # print(clf.intercept_) # Plot plt.scatter(Eact, Ecmp, label="Baseline RMSE: " + "%s" % float("%.3g" % rmse) + " kcal/mol", color="red") plt.scatter(Eact, Eact, label="DFT", color="blue") plt.title("GDB-2 - CM/MLP energy correlation to DFT")
deltas = gt.hatokcal * np.abs(Ecmp_t - np.array(Eact_t, dtype=float)) Me = max (deltas) if Me > Herror: Herror = Me Wfile = i Le = min (deltas) if Le < Lerror: Lerror = Le Bfile = i #print (gt.hatokcal * gt.calculaterootmeansqrerror(np.array(Eact_t, dtype=float),Ecmp_t)) tNa = nc.getNumAtoms() err.append(gt.hatokcal * gt.calculaterootmeansqrerror(np.array(Eact_t, dtype=float),Ecmp_t) / float(tNa)) sze.append(float(len(Eact_t))) time += _t2b Ecmp += Ecmp_t Eact += Eact_t #plt_by_index(np.array(Eerr),-1) Ndps = len(Ecmp) print ('\nMax Delta (kcal/mol): ' + str(Herror) + ' FILE: ' + Wfile) print ('Min Delta (kcal/mol): ' + str(Lerror) + ' FILE: ' + Bfile) print('\nMAXE') print(ld)
def produce_scan(title, xlabel, cnstfile, saefile, nnfdir, dtdir, dt1, smin, smax, iscale, ishift, atm): xyz, frc, typ, Eact, chk = gt.readncdatwforce(dtdir + dt1) xyz = np.asarray(xyz, dtype=np.float32) xyz = xyz.reshape((xyz.shape[0], len(typ), 3)) print(xyz) frc = np.asarray(frc, dtype=np.float32) frc = frc.reshape((frc.shape[0], len(typ), 3)) Eact = np.array(Eact) # Construct pyNeuroChem classes nc1 = pync.pyNeuroChem(cnstfile, saefile, nnfdir, 0) # Set the conformers in NeuroChem nc1.setConformers(confs=xyz, types=typ) # Print some data from the NeuroChem print("1) Number of Atoms Loaded: " + str(nc1.getNumAtoms())) print("1) Number of Confs Loaded: " + str(nc1.getNumConfs())) # Compute Energies of Conformations print("Computing energies...") _t1b = tm.time() Ecmp1 = nc1.energy() print("Energy computation complete. Time: " + "{:.4f}".format((tm.time() - _t1b) * 1000.0) + "ms") # Compute Forces of Conformations print("Compute forces...") _t1b = tm.time() F = nc1.force() print("Force computation complete. Time: " + "{:.4f}".format((tm.time() - _t1b) * 1000.0) + "ms") # Fn = np.array(nc1.computeNumericalForces(dr=0.0001)) n = smin m = smax Ecmp1 = gt.hatokcal * Ecmp1 Eact = gt.hatokcal * Eact IDX = np.arange(0, Eact.shape[0], 1, dtype=float) * iscale + ishift IDX = IDX Eact = Eact Ecmp1 = Ecmp1 Ecmp1 = Ecmp1 - Ecmp1.min() Eact = Eact - Eact.min() rmse1 = gt.calculaterootmeansqrerror(Eact, Ecmp1) print("Spearman corr. 1: " + "{:.3f}".format(st.spearmanr(Ecmp1, Eact)[0])) fig, axes = plt.subplots(nrows=2, ncols=2) axes.flat[0].plot(IDX, Eact, "-", color="black", label="DFT", linewidth=6) axes.flat[0].plot(IDX, Ecmp1, "--", color="red", label="ANI-1", linewidth=6) # ax.plot(IDX, Eact, color='black', label='DFT', linewidth=3) # ax.scatter(IDX, Eact, marker='o', color='black', linewidth=4) th = axes.flat[0].set_title(title, fontsize=13) th.set_position([0.5, 1.00]) # Set Limits axes.flat[0].set_xlim([IDX.min(), IDX.max()]) # axes.flat[0].set_ylim([Eact.min()-1.0,Eact.max()+1.0]) axes.flat[0].set_ylabel("$\Delta$E calculated (kcal/mol)") axes.flat[0].set_xlabel(xlabel) axes.flat[0].legend(bbox_to_anchor=(0.2, 0.98), loc=2, borderaxespad=0.0, fontsize=12) # print (Fn) for i in range(0, 3): Fq = F[:, :, i][:, atm] # Fnq = Fn[:,i] Faq = 1.8897259885789 * np.array(frc)[:, :, i][:, atm] print(Fq) print(Faq) th = axes.flat[i + 1].set_title("Force for atom " + str(atm) + ": coordinate " + str(i), fontsize=13) th.set_position([0.5, 1.00]) axes.flat[i + 1].set_xlim([IDX.min(), IDX.max()]) axes.flat[i + 1].plot(IDX, Faq, "-", color="black", label="DFT", linewidth=6) # axes.flat[i+1].plot(IDX, Fnq, '-', color='blue', label='ANI Numerical', # linewidth=6) axes.flat[i + 1].plot(IDX, Fq, "--", color="red", label="ANI Analytical", linewidth=6) axes.flat[i + 1].set_ylabel("Force (Ha/A)") axes.flat[i + 1].set_xlabel(xlabel) axes.flat[i + 1].legend(bbox_to_anchor=(0.2, 0.98), loc=2, borderaxespad=0.0, fontsize=12) font = {"family": "Bitstream Vera Sans", "weight": "normal", "size": 12} plt.rc("font", **font) plt.show()
Ecmp3 = gt.hatokcal * Ecmp3 Ecmp4 = gt.hatokcal * Ecmp4 Ecmp5 = gt.hatokcal * Ecmp5 Eact = gt.hatokcal * Eact Eotr = gt.hatokcal * Eotr Emax = 400.0 Ecmp1 = setmaxE(Eact, Ecmp1, Emax) Ecmp2 = setmaxE(Eact, Ecmp2, Emax) Ecmp3 = setmaxE(Eact, Ecmp3, Emax) Ecmp4 = setmaxE(Eact, Ecmp4, Emax) Ecmp5 = setmaxE(Eact, Ecmp5, Emax) Eotr = setmaxE(Eact, Eotr, Emax) Eact = setmaxE(Eact, Eact, Emax) rmse1 = gt.calculaterootmeansqrerror(Eact, Eotr) rmse2 = gt.calculaterootmeansqrerror(Eact, Ecmp1) rmse3 = gt.calculaterootmeansqrerror(Eact, Ecmp2) rmse4 = gt.calculaterootmeansqrerror(Eact, Ecmp3) rmse5 = gt.calculaterootmeansqrerror(Eact, Ecmp4) rmse6 = gt.calculaterootmeansqrerror(Eact, Ecmp5) mx = Eact.max() mn = Eact.min() #plt.scatter(IDX, Eact, marker='o' , color='black', linewidth=3) print("Spearman corr. DFTB: " + "{:.3f}".format(st.spearmanr(Eotr, Eact)[0])) print("Spearman corr. TGM 08: " + "{:.3f}".format(st.spearmanr(Ecmp1, Eact)[0])) #print ( "Spearman corr. TGM 07: " + "{:.3f}".format(st.spearmanr(Ecmp2,Eact)[0]) )