def plot_irc(axes, i, d, f): #print(f) Eact, xyz, spc, Rc = pyg.read_irc(d + f) Eact = hdt.hatokcal * Eact xyz = xyz[1:] Eact = Eact[1:] Rc = Rc[:-1] #print(Rc[:,1]) #print(Eact-Eact.min() - Rc[:,1]-Rc[:,1].min()) s_idx = f.split('IRC')[1].split('.')[0] hdt.writexyzfile(c + f.split('.')[0] + '.xyz', xyz, spc) #print(f.split('IRC')[1].split('.')[0],Rc.shape) if Rc.size > 10: #------------ CV NETWORKS 1 ----------- energies1 = [] N = 0 for comp in nc1: comp.setConformers(confs=xyz, types=list(spc)) energies1.append(hdt.hatokcal * comp.energy()) N = N + 1 energies2 = [] N = 0 for comp in nc2: comp.setConformers(confs=xyz, types=list(spc)) energies2.append(hdt.hatokcal * comp.energy()) N = N + 1 modl_std1 = np.std(energies1, axis=0)[::-1] energies1 = np.mean(np.vstack(energies1), axis=0) modl_std2 = np.std(energies2, axis=0)[::-1] energies2 = np.mean(np.vstack(energies2), axis=0) rmse1 = hdt.calculaterootmeansqrerror(energies1, Eact) rmse2 = hdt.calculaterootmeansqrerror(energies2, Eact) dba = Eact.max() - Eact[0] db1 = energies1.max() - energies1[0] db2 = energies2.max() - energies2[0] rpa = Eact[0] - Eact[-1] rp1 = energies1[0] - energies1[-1] rp2 = energies2[0] - energies2[-1] bar1.append(abs(db1 - dba)) bar2.append(abs(db2 - dba)) rmp1.append(abs(rpa - rp1)) rmp2.append(abs(rpa - rp2)) Ec1.append(energies1) Ec2.append(energies2) Ea.append(Eact) print(i, ')', f, ':', len(spc), ':', rmse1, rmse2, 'R/P1: ', abs(rpa - rp1), 'R/P2: ', abs(rpa - rp2), 'Barrier1:', abs(db1 - dba), 'Barrier2:', abs(db2 - dba)) Rce = hdt.hatokcal * (Rc[:, 0] - Rc[:, 0][0]) Rce1 = energies2[::-1] - energies2[::-1][0] axes.set_xlim([Rc.min(), Rc.max()]) axes.set_ylim([Rce.min() - 1.0, Rce1.max() + 20.0]) axes.plot(Rc[:, 1], hdt.hatokcal * (Rc[:, 0] - Rc[:, 0][0]), color='Black', label='DFT') axes.errorbar(Rc[:, 1], energies2[::-1] - energies2[::-1][0], yerr=modl_std2, fmt='--', color='red', label="ANI-1: " + "{:.1f}".format(bar2[-1]), linewidth=2) axes.errorbar(Rc[:, 1], energies1[::-1] - energies1[::-1][0], yerr=modl_std1, fmt='--', color='blue', label="[" + str(i) + "]: " + "{:.1f}".format(bar1[-1]), linewidth=2) #axes.set_xlabel("Reaction Coordinate $\AA$") #axes.set_ylabel(r"$\Delta E$ $ (kcal \times mol^{-1})$") #axes.plot(Rc[:, 1], energies2[::-1]-energies2[::-1][0],'--',color='red',label="["+str(i)+"]: "+"{:.1f}".format(bar2[-1]),linewidth=3) #axes.plot(Rc[:, 1], energies1[::-1]-energies1[::-1][0],'--',color='green',label="["+str(i)+"]: "+"{:.1f}".format(bar1[-1]),linewidth=3) axes.legend(loc="upper left", fontsize=10) axes.set_title(str(f), color='black', fontdict={'weight': 'bold'}, x=0.8, y=0.85)
import pygau09tools as g09 import hdnntools as hdn import numpy as np import matplotlib.pyplot as plt import pyNeuroChem as pync #dir = '/home/jujuman/Research/GDB-11-wB97X-6-31gd/dnnts_rxns/scans_double_bond_migration/' #dir = '/home/jujuman/Dropbox/IRC_DBondMig/rxn1/' dir = '/home/jujuman/Dropbox/IRC_DBondMig/rxn5/' filef = dir + 'IRC_fwd.log' fileb = dir + 'IRC_bck.log' dataf = g09.read_irc(filef) datab = g09.read_irc(fileb) xyz = np.concatenate([np.flipud(datab[1]), dataf[1]]) eng = hdn.hatokcal * np.concatenate([np.flipud(datab[0]), dataf[0]]) print(xyz.shape) hdn.writexyzfile(dir + 'scan.xyz', xyz, dataf[2]) # Set required files for pyNeuroChem # Set required files for pyNeuroChem anipath = '/home/jujuman/Dropbox/ChemSciencePaper.AER/ANI-c08e-ntwk' cnstfile = anipath + '/rHCNO-4.6A_16-3.1A_a4-8.params' saefile = anipath + '/sae_6-31gd.dat' nnfdir = anipath + '/networks/'
def plot_irc_data(axes, file, title, ntwl, cnstfile, saefile, dir, trained): Eact, xyz, typ, Rc = pyg.read_irc(file) Rc = Rc[:, 1] Rc = Rc[::-1] print(Eact.shape, Rc.shape, xyz.shape) # Shift reference to reactant #Eact = Eact[::-1] Eact = hdt.hatokcal * (Eact - Eact[-1]) # Plot reference results axes.scatter(Rc, Eact, color='black', linewidth=3) # Plot ANI results color = cm.rainbow(np.linspace(0, 1, len(ntwl))) terr = np.zeros(len(ntwl)) derr = np.zeros(len(ntwl)) berr = np.zeros(len(ntwl)) for i, (nt, c) in enumerate(zip(ntwl, color)): ncr = pync.conformers(dir + nt[0] + cnstfile, dir + nt[0] + saefile, rcdir + nt[0] + 'networks/', 0, True) # Set the conformers in NeuroChem ncr.setConformers(confs=xyz, types=list(typ)) # Compute Energies of Conformations E1 = ncr.energy() # Shift ANI E to reactant E1 = hdt.hatokcal * (E1 - E1[-1]) # Calculate error errn = hdt.calculaterootmeansqrerror(E1, Eact) terr[i] = errn derr[i] = np.abs( np.abs((E1[0] - E1[-1])) - np.abs((Eact[0] - Eact[-1]))) berr[i] = np.abs(E1.max() - Eact.max()) # Plot axes.plot(Rc, E1, 'r--', color=c, label="[" + str(i) + "]: " + "{:.1f}".format(berr[i]), linewidth=2) #axes.set_xlim([Rc.min(), Rc.max()]) #axes.set_ylim([-15, 70]) axes.legend(loc="upper left", fontsize=7) if trained: axes.set_title(title, color='green', fontdict={'weight': 'bold'}, x=0.83, y=0.70) else: axes.set_title(title, color='red', fontdict={'weight': 'bold'}, x=0.83, y=0.70) return terr, derr, berr
#cnstfile = 'rHCNO-4.6A_16-3.1A_a4-8.params' #saefile = 'sae_6-31gd.dat' Nnc = 2 files = os.listdir(d) files.sort() #print(files) # Construct pyNeuroChem classes nc1 = [pync.conformers(wkdir1 + cnstfile, wkdir1 + saefile, wkdir1 + 'train' + str(l) + '/networks/', 0, False) for l in range(Nnc)] comp_xyz = [] for f in files: #print(f) Eact, xyz, spc, Rc = pyg.read_irc(d+f) s_idx = f.split('IRC')[1].split('.')[0] hdt.writexyzfile(c+f.split('.')[0]+'.xyz',xyz,spc) #print(f.split('IRC')[1].split('.')[0],Rc.shape) if Rc.size > 10: #------------ CV NETWORKS 1 ----------- energies = [] N = 0 for comp in nc1: comp.setConformers(confs=xyz, types=list(spc)) energies.append(hdt.hatokcal*comp.energy()) N = N + 1 energies = np.vstack(energies) modl_std = np.std(energies[::-1],axis=0) / float(len(spc))
import numpy as np import pygau09tools as pyg import hdnntools as hdt n = '10' fpf = 'benz_rxn_' + str(n) wkdir = '/home/jujuman/Research/GDB-11-wB97X-6-31gd/dnnts_rxns/benz_dbm_rxns_full/irc_dbm_benz_'+str(n)+'/' #dtdir = '/home/jujuman/Dropbox/IRC_DBondMig/Benzene_rxn/rxn_ben'+str(n)+'/' dtdir = '/home/jujuman/Dropbox/IRC_DBondMig/Benzene_rxn2/rxn_ben'+str(n)+'/IRC.log' #en, cd, ty = pyg.get_irc_data(dtdir+'IRC_fwd.log',dtdir+'IRC_bck.log',dtdir+'saddle_ts.log') en, cd, ty, Rc = pyg.read_irc(dtdir) np.savez(wkdir+'reaction_coordinate.npz',x=Rc) Na = len(ty) Nc = en.shape[0] print (cd.shape,' ',en.shape) #for i,x in enumerate(cd): #hdt.write_rcdb_input(x,ty,i,wkdir,fpf,5,'wb97x/6-31g*','600.0',opt='0') hdt.writexyzfile(wkdir+'irc.xyz',cd,ty) f = open(wkdir+'irc.dat','w') f.write("comment\n") f.write(str(Nc)+'\n') f.write(str(Na)+',') for j in ty: f.write(j+',')
import pygau09tools as g09 import hdnntools as hdn import numpy as np wkdir = '/home/jujuman/Research/GDB-11-wB97X-6-31gd/dnnts_rxns/scans_double_bond_migration_1/' filef = '/home/jujuman/Research/GDB-11-wB97X-6-31gd/dnnts_rxns/scans_double_bond_migration_1/IRC_fwd.log' #fileb = '/home/jujuman/Research/GDB-11-wB97X-6-31gd/dnnts_rxns/scans_double_bond_migration/IRC_bck.log' dataf = g09.read_irc(filef) #datab = g09.read_irc(fileb) #xyz = np.concatenate([np.flipud(datab[1]),dataf[1]]) xyz = dataf[1] for i,x in enumerate(xyz): hdn.write_rcdb_input(x,dataf[2],i,wkdir,'double_B_mig',50,'wb97x/6-31g*','1000.0',opt='0')