def getPath(Reac, Prod, gl): xyzfile3 = open(("IRC3.xyz"), "w") Path = [] Path.append(Reac.copy()) for i in range(0, 30): image = Reac.copy() image = tl.setCalc(image, "DOS/", gl.lowerMethod, gl.lowerLevel) Path.append(image) image = Prod.copy() image = tl.setCalc(image, "DOS/", gl.lowerMethod, gl.lowerLevel) Path.append(image) neb1 = NEB(Path, k=1.0, remove_rotation_and_translation=True) try: neb1.interpolate('idpp', optimizer="MDMin", k=1.0) except: neb1.interpolate() optimizer = FIRE(neb1) optimizer.run(fmax=0.07, steps=500) neb2 = NEB(Path, k=1.0, climb=True, remove_rotation_and_translation=True) optimizer = FIRE(neb2) optimizer.run(fmax=0.07, steps=1500) for i in range(0, len(Path)): tl.printTraj(xyzfile3, Path[i]) xyzfile3.close() return Path
def characteriseTSinternal(self, mol): os.chdir((self.workingDir + '/Raw/' + self.procNum)) if (self.lowMeth == 'nwchem'): mol = tl.setCalc(mol, self.lowString, 'nwchem2', self.lowLev) self.Reac.get_forces() else: mol = tl.setCalc(mol, self.lowString, self.lowMeth, self.lowLev) vib = Vibrations(mol) vib.clean() vib.run() viblist = vib.get_frequencies() print("getting vibs") TSFreqs, zpe = tl.getVibString(viblist, False, True) print("vibs done " + str(zpe)) imaginaryFreq = tl.getImageFreq(viblist) vib.clean() os.chdir((self.workingDir)) # Finally get single point energy mol = tl.setCalc(mol, self.singleString, self.singleMeth, self.singleLev) print("Getting single point energy for TS = " + str(mol.get_potential_energy()) + "zpe = " + str(zpe) + "reactant energy = " + str(self.reactantEnergy)) energy = mol.get_potential_energy() + zpe return TSFreqs, imaginaryFreq, zpe, energy
def optReac(self): print('minimising') self.is_bimol_reac = False self.CombReac = tl.setCalc(self.CombReac, self.lowString, self.lowMeth, self.lowLev) self.ReacName = tl.getSMILES(self.CombReac, True, True) FullName = self.ReacName.split('____', 1) path = (self.workingDir + '/Raw/calcHigh' + self.procNum) try: self.CombReac._calc.close() except: pass if len(FullName) > 1: self.is_bimol_reac = True self.ReacName = FullName[0].strip('\n\t') self.biReacName = FullName[1].strip('\n\t') self.Reac = tl.getMolFromSmile(self.ReacName) self.biReac = tl.getMolFromSmile(self.biReacName) else: self.Reac = self.CombReac self.Reac = tl.setCalc(self.Reac, self.highString, self.highMeth, self.highLev) try: self.Reac._calc.minimise_stable(path, self.Reac) except: self.Reac = tl.setCalc(self.Reac, self.lowString, self.lowMeth, self.lowLev) self.Reac._calc.minimise_stable(path, self.Reac) try: self.ReacFreqs, zpe = self.Reac._calc.read_vibs() except: self.ReacFreqs, zpe = self.characteriseFreqInternal(self.Reac) self.Reac = tl.setCalc(self.Reac, self.singleString, self.singleMeth, self.singleLev) self.reactantEnergy = self.Reac.get_potential_energy() + zpe try: self.Reac._calc.close() except: pass if self.is_bimol_reac == True: self.biReac = tl.setCalc(self.biReac, self.highString, self.highMeth, self.highLev) try: self.biReac._calc.minimise_stable(path, self.biReac) except: self.biReac = tl.setCalc(self.biReac, self.lowString, self.lowMeth, self.lowLev) self.biReac._calc.minimise_stable(path, self.biReac) try: self.biReacFreqs, zpe = self.biReac._calc.read_vibs() except: self.biReacFreqs, zpe = self.characteriseFreqInternal( self.biReac) self.biReac = tl.setCalc(self.biReac, self.singleString, self.singleMeth, self.singleLev) self.reactantEnergy += (self.biReac.get_potential_energy() + zpe) try: self.biReac._calc.close() except: pass
def refineTSpoint(self, MolList, TrajStart): iMol = MolList[TrajStart - 100].copy() iMol = tl.setCalc(iMol, self.lowString, self.lowMeth, self.lowLev) startName = tl.getSMILES(iMol, True) startName = startName.split('____') if len(startName) > 1: startName = startName[0] # Look for change in optimised geometry along reaction path point = 0 for i in range(TrajStart - 99, TrajStart + 100): iMol = MolList[i].copy() iMol = tl.setCalc(iMol, self.lowString, self.lowMeth, self.lowLev) Name = tl.getSMILES(iMol, True) FullName = Name.split('____') if len(FullName) > 1: FullName = FullName[0] if FullName != self.startName and FullName != self.ReacName: point = i return point return TrajStart
def optTSpoint(self, trans, path, MolList, TrajStart, idx): self.TS = MolList[TrajStart].copy() self.TS = tl.setCalc(self.TS, self.lowString, self.lowMeth, self.lowLev) c = FixAtoms(trans) self.TS.set_constraint(c) min = BFGS(self.TS) min.run(fmax=0.05, steps=50) os.mkdir(path + '/Data/') write(path + '/Data/TSGuess.xyz', self.TS) TSGuess = self.TS.copy() del self.TS.constraints if self.biReac or self.biProd: QTS3 = False else: QTS3 = True if (self.twoStageTS): try: self.TSFreqs, self.imaginaryFreq, zpe, energy, self.TS, rmol, pmol = self.characteriseTSExt( self.TS, True, path, QTS3) except: pass try: self.TSFreqs, self.imaginaryFreq, zpe, energy, self.TS, rmol, pmol = self.characteriseTSExt( self.TS, False, path, QTS3) except: try: print( "High Level TS opt for TS1 failed looking at lower level") self.TSFreqs, self.imaginaryFreq, zpe, energy, self.TS, rmol, pmol = self.characteriseTSExt( self.TS, True, path, QTS3) except: pass try: self.TScorrect = self.compareRandP(rmol, pmol) except: self.TScorrect = False self.TS = TSGuess self.TSFreqs, self.imaginaryFreq, zpe, energy = self.characteriseTSinternal( self.TS) write(path + '/TS1.xyz', self.TS) self.forwardBarrier = energy if (self.forwardBarrier < self.reactantEnergy and self.forwardBarrier < self.productEnergy): self.barrierlessReaction = True
def compareRandP(self, rmol, pmol): # Check if TS links reac and prod rmol = tl.setCalc(rmol, self.lowString, self.lowMeth, self.lowLev) Name = tl.getSMILES(rmol, False).strip('\n\t') FullName = Name.split('____') try: rmol._calc.close() except: pass pmol = tl.setCalc(pmol, self.lowString, self.lowMeth, self.lowLev) min = BFGS(pmol) Name2 = tl.getSMILES(pmol, False).strip('\n\t') FullName2 = Name2.split('____') if ((FullName == self.ReacName and FullName2 == self.ProdName) or (FullName2[0] == self.ReacName and FullName[0] == self.ProdName)): TScorrect = True else: TScorrect = False print('TS1 try does not connect reactants and products') try: pmol._calc.close() except: pass return TScorrect
def quickOptProd(self, cart, alt): self.is_bimol_prod = False if alt == True: self.CombProd = self.AltProd.copy() else: self.CombProd.set_positions(cart) try: self.CombProd._calc.close() except: pass path = (self.workingDir + '/Raw/calcHigh' + self.procNum) self.CombProd = tl.setCalc(self.CombProd, self.lowString, self.lowMeth, self.lowLev) self.ProdName = tl.getSMILES(self.CombProd, True, partialOpt=True) FullName = self.ProdName.split('____', 1) if len(FullName) > 1: self.is_bimol_prod = True self.ProdName = FullName[0].strip('\n\t') self.biProdName = FullName[1].strip('\n\t') self.Prod = tl.getMolFromSmile(self.ProdName) self.biProd = tl.getMolFromSmile(self.biProdName) else: self.Prod = self.CombProd self.ProdName = tl.getSMILES(self.Prod, False, partialOpt=False)
def run(gl): #Read reactant definition if gl.StartType == 'file': Reac = read(gl.Start) elif gl.StartType == 'Smile': Reac = tl.getMolFromSmile(gl.Start) #Read product definition if gl.EndType == 'file': Prod = read(gl.End) elif gl.EndType == 'Smile': Prod = tl.getMolFromSmile(gl.End) #Set calculatiors #Reac = tl.setCalc(Reac,"DOS/", gl.trajMethod, gl.atomTypes) if gl.trajMethod == "openMM": Reac = tl.setCalc(Reac, "GenBXD/", gl.trajMethod, gl) else: Reac = tl.setCalc(Reac, "GenBXD/", gl.trajMethod, gl.trajLevel) Prod = tl.setCalc(Prod, "GenBXD/", gl.trajMethod, gl.trajLevel) # Partially minimise both reactant and product if gl.GenBXDrelax: min = BFGS(Reac) try: min.run(fmax=0.1, steps=20) except: min.run(fmax=0.1, steps=20) min2 = BFGS(Prod) try: min2.run(fmax=0.1, steps=20) except: min2.run(fmax=0.1, steps=20) # Get important interatomic distances if gl.CollectiveVarType == "changedBonds": cbs = ct.getChangedBonds2(Reac, Prod) elif gl.CollectiveVarType == "all": cbs = ct.getChangedBonds2(Reac, Prod) elif gl.CollectiveVarType == "specified": cbs = gl.CollectiveVar elif gl.CollectiveVarType == "file": cbs = gl.principalCoordinates #Get path to project along distPath = [] totalPathLength = 0 if gl.PathType == 'curve' or gl.PathType == 'gates': if gl.PathFile == 'none': Path = getPath(Reac, Prod, gl) else: Path = read(gl.PathFile, index=('::' + str(gl.pathStride))) distPath.append((ct.getDistMatrix(Path[0], cbs)[0], 0)) for i in range(1, len(Path)): l = np.linalg.norm( ct.getDistMatrix(Path[i], cbs)[0] - ct.getDistMatrix(Path[i - 1], cbs)[0]) totalPathLength += l distPath.append((ct.getDistMatrix(Path[i], cbs)[0], totalPathLength)) elif gl.PathType == 'linear': distPath = ct.getDistMatrix(Prod, cbs)[0] - ct.getDistMatrix( Reac, cbs)[0] if gl.PathType == 'curve' or gl.PathType == 'gates': pathFile = open('reducedPath.txt', 'w') for p in distPath: pathFile.write('s = ' + str(p[0]) + '\n') pathFile.close() # initialise then run trajectory t = ChemDyME.Trajectory.Trajectory(Reac, gl, os.getcwd(), 0, False) t.runGenBXD(Reac, Prod, gl.maxHits, gl.maxAdapSteps, gl.PathType, distPath, cbs, gl.decorrelationSteps, gl.histogramBins, totalPathLength, gl.fixToPath, gl.pathDistCutOff, gl.epsilon)
def optNEB(self, trans, path, changePoints, mols): # Open files for saving IRCdata xyzfile3 = open((path + "/IRC3.xyz"), "w") MEP = open((path + "/MEP.txt"), "w") imagesTemp1 = [] index = changePoints[0] - 100 molTemp = mols[index].copy() imagesTemp1.append(molTemp.copy()) for i in range(0, 100): imagesTemp1.append(mols[changePoints[0] - 100].copy()) try: imagesTemp1.append(mols[changePoints[-1] + 300]) except: imagesTemp1.append(self.CombProd.copy()) neb1 = NEB(imagesTemp1, k=1.0, remove_rotation_and_translation=True) try: neb1.interpolate('idpp') except: neb1.interpolate() for i in range(0, len(imagesTemp1)): try: imagesTemp1[i] = tl.setCalc(imagesTemp1[i], self.lowString, self.lowMeth, self.lowLev) for i in range(0, len(trans)): c = FixAtoms(trans) imagesTemp1[i].set_constraint(c) min = BFGS(imagesTemp1[i]) min.run(fmax=0.005, steps=40) del imagesTemp1[i].constraints except: pass optimizer = FIRE(neb1) try: optimizer.run(fmax=0.07, steps=300) except: pass print("passed seccond neb") neb1_2 = NEB(imagesTemp1, k=0.01, remove_rotation_and_translation=True) try: optimizer.run(fmax=0.07, steps=200) except: pass neb2 = NEB(imagesTemp1, climb=True, remove_rotation_and_translation=True) try: optimizer.run(fmax=0.07, steps=200) except: pass for i in range(0, len(imagesTemp1)): tl.printTraj(xyzfile3, imagesTemp1[i]) print("NEB printed") xyzfile3.close() point = 0 maxEne = -50000000 try: for i in range(0, len(imagesTemp1)): MEP.write( str(i) + ' ' + str(imagesTemp1[i].get_potential_energy()) + '\n') if imagesTemp1[i].get_potential_energy() > maxEne and i > 5: point = i maxEne = imagesTemp1[i].get_potential_energy() self.TS2 = imagesTemp1[point] except: point = 0 print("TS Climb part") write(path + '/TSClimbGuess.xyz', self.TS2) try: self.TS2Freqs, self.imaginaryFreq2, zpe, energy, self.TS2, rmol, pmol = self.characteriseTSExt( self.TS2, False, path, self.QTS3) except: self.TS2Freqs, self.imaginaryFreq2, zpe, energy, self.TS2, rmol, pmol = self.characteriseTSExt( self.TS2, True, path, self.QTS3) self.TScorrect = self.compareRandP(rmol, pmol) self.forwardBarrier2 = energy + zpe
def optDynPath(self, trans, path, MolList, changePoints): # Open files for saving IRCdata xyzfile = open((path + "/Data/dynPath.xyz"), "w") MEP = open((path + "/Data/MEP.txt"), "w") orriginal = open((path + "/Data/orriginalPath.txt"), "w") dyn = open((path + "/Data/traj.xyz"), "w") dynList = [] end = int(changePoints + self.dynPrintStart) length = int(len(MolList)) if end < length: endFrame = end else: endFrame = length for i in range(int(changePoints - self.dynPrintStart), int(endFrame), self.inc): iMol = MolList[i].copy() tl.printTraj(dyn, iMol) iMol = tl.setCalc(iMol, self.lowString, self.lowMeth, self.lowLev) orriginal.write( str(i) + ' ' + str(iMol.get_potential_energy()) + '\n') c = FixAtoms(trans) iMol.set_constraint(c) min = BFGS(iMol) try: min.run(fmax=0.1, steps=150) except: min.run(fmax=0.1, steps=1) del iMol.constraints tl.printTraj(xyzfile, iMol) dynList.append(iMol.copy()) maxEne = -50000 point = 0 for i in range(0, len(dynList)): dynList[i] = tl.setCalc(dynList[i], self.lowString, self.lowMeth, self.lowLev) MEP.write( str(i) + ' ' + str(dynList[i].get_potential_energy()) + '\n') if dynList[i].get_potential_energy() > maxEne: point = i maxEne = dynList[i].get_potential_energy() self.TS2 = dynList[point] TS2Guess = self.TS2.copy() write(path + '/Data/TS2guess.xyz', self.TS2) try: self.TS2Freqs, self.imaginaryFreq2, zpe, energy, self.TS2, rmol, pmol = self.characteriseTSExt( self.TS2, True, path, self.QTS3) except: try: self.TS2Freqs, self.imaginaryFreq2, zpe, energy, self.TS2, rmol, pmol = self.characteriseTSExt( self.TS2, False, path, self.QTS3) except: pass try: self.TS2correct = self.compareRandP(rmol, pmol) except: print("TS2 does not connect products") self.TS2correct = False self.TS2 = TS2Guess self.TS2Freqs, self.imaginaryFreq2, zpe, energy = self.characteriseTSinternal( self.TS2) write(path + '/TS2.xyz', self.TS2) self.forwardBarrier2 = energy
def optTS(self, trans, path, MolList, TrajStart): raw_path = (self.workingDir + '/Raw/calcHigh' + self.procNum) self.TS = MolList[TrajStart].copy() self.TS = tl.setCalc(self.TS, self.lowString, self.lowMeth, self.lowLev) c = FixAtoms(trans) self.TS.set_constraint(c) min = BFGS(self.TS) min.run(fmax=0.05, steps=50) os.mkdir(path + '/Data/') write(path + '/Data/TSGuess.xyz', self.TS) TSGuess = self.TS.copy() del self.TS.constraints self.TS, rmol, pmol, irc_for, irc_rev = self.TS._calc.minimise_ts( raw_path, self.TS) try: self.TScorrect = self.compareRandP(rmol, pmol) except: self.TScorrect = False try: self.TS._calc.close() except: pass try: inc = -10 while self.TScorrect == False and inc <= 10: self.TS = MolList[TrajStart - inc].copy() self.TS = tl.setCalc(self.TS, self.lowString, self.lowMeth, self.lowLev) c = FixAtoms(trans) self.TS.set_constraint(c) min = BFGS(self.TS) min.run(fmax=0.05, steps=50) write(path + '/Data/TSGuess.xyz', self.TS) TSGuess = self.TS.copy() del self.TS.constraints self.TS, rmol, pmol, irc_for, irc_rev = self.TS._calc.minimise_ts( raw_path, self.TS) try: self.TScorrect = self.compareRandP(rmol, pmol) except: self.TScorrect = False inc += 1 try: self.TS._calc.close() except: pass except: pass if self.TScorrect: irc_ene = [] irc_rev.reverse() irc = irc_rev + irc_for for i in irc: i = tl.setCalc(i, self.lowString, self.lowMeth, self.lowLev) irc_ene.append(i.get_potential_energy()) try: i._calc.close() except: pass write(path + '/Data/IRC.xyz', irc) write(path + '/TS1.xyz', self.TS) self.TS = tl.setCalc(self.TS, self.highString, self.highMeth, self.highLev) try: self.TScorrect = self.TS._calc.minimise_ts_only( self.TS, self.CombReac, self.CombProd) copyfile(str(self.highString) + 'gaussian.log', path + '/G1.log') except: self.TS = tl.setCalc(self.TS, self.lowString, self.lowMeth, self.lowLev) try: self.TSFreqs, zpe, self.imaginaryFreq, self.TScorrect = self.TS._calc.read_ts_vibs( ) except: self.TS = tl.setCalc(self.TS, self.lowString, self.lowMeth, self.lowLev) self.TSFreqs, zpe, self.imaginaryFreq = self.characteriseTSFreqInternal( self.TS) try: self.TS._calc.close() except: pass self.TS = tl.setCalc(self.TS, self.singleString, self.singleMeth, self.singleLev) try: self.forwardBarrier = self.TS.get_potential_energy() + zpe self.TS._calc.close() except: pass self.TS = tl.setCalc(self.TS, self.lowString, self.lowMeth, self.lowLev) spline = self.TS._calc.minimise_bspline(raw_path, self.CombReac, self.CombProd) try: self.TS._calc.close() except: pass spline_ene = [] try: self.TS._calc.close() except: pass try: for sp in spline: sp = tl.setCalc(sp, self.lowString, self.lowMeth, self.lowLev) spline_ene.append(float(sp.get_potential_energy())) try: sp._calc.close() except: pass max_value = max(spline_ene) ind = spline_ene.index(max_value) write(path + '/Data/TS2.xyz', spline[ind]) self.TS2 = spline[ind].copy() write(path + '/Data/spline.xyz', spline) with open(path + '/Data/spline_ene.txt', 'w') as f: for sp in spline_ene: f.write(str(sp) + "\n") f.close() self.spline = spline_ene self.TS2 = tl.setCalc(self.TS2, self.lowString, self.lowMeth, self.lowLev) self.TS2, rmol, pmol, irc_for, irc_rev = self.TS2._calc.minimise_ts( raw_path, self.TS2) self.TS2 = tl.setCalc(self.TS2, self.highString, self.highMeth, self.highLev) try: self.TS2correct = self.TS2._calc.minimise_ts_only( self.TS, self.CombReac, self.CombProd) copyfile( str(self.highString) + 'gaussian.log', path + '/G2.log') except: self.TS2 = tl.setCalc(self.TS2, self.lowString, self.lowMeth, self.lowLev) try: self.TS2Freqs, zpe, self.imaginaryFreq2, self.TS2correct = self.TS2._calc.read_ts_vibs( ) except: self.TS2 = tl.setCalc(self.TS2, self.lowString, self.lowMeth, self.lowLev) self.TS2Freqs, zpe, self.imaginaryFreq2 = self.characteriseTSFreqInternal( self.TS2) try: self.TS2._calc.close() except: pass self.TS2 = tl.setCalc(self.TS2, self.singleString, self.singleMeth, self.singleLev) try: self.forwardBarrier2 = self.TS2.get_potential_energy() + zpe self.TS2._calc.close() except: pass except: self.TS2correct = False write(path + '/TS2.xyz', self.TS2) if (self.forwardBarrier <= self.reactantEnergy or self.forwardBarrier <= self.productEnergy): self.barrierlessReaction = True if self.TScorrect == False and self.TS2correct == True: self.TS = self.TS2 self.forwardBarrier = self.forwardBarrier2 self.imaginaryFreq = self.imaginaryFreq2 self.TSFreqs = self.TS2Freqs
def optProd(self, cart, alt): print('optimising product') self.is_bimol_prod = False if alt == True: self.CombProd = self.AltProd.copy() else: self.CombProd.set_positions(cart) try: self.CombProd._calc.close() except: pass path = (self.workingDir + '/Raw/calcHigh' + self.procNum) self.CombProd = tl.setCalc(self.CombProd, self.lowString, self.lowMeth, self.lowLev) self.ProdName = tl.getSMILES(self.CombProd, True, partialOpt=True) FullName = self.ProdName.split('____', 1) if len(FullName) > 1: self.is_bimol_prod = True self.ProdName = FullName[0].strip('\n\t') self.biProdName = FullName[1].strip('\n\t') self.Prod = tl.getMolFromSmile(self.ProdName) self.biProd = tl.getMolFromSmile(self.biProdName) else: self.Prod = self.CombProd try: self.Prod = tl.setCalc(self.Prod, self.highString, self.highMeth, self.highLev) self.Prod._calc.minimise_stable(path, self.Prod) except: self.Prod = tl.setCalc(self.Prod, self.lowString, self.lowMeth, self.lowLev) self.Prod._calc.minimise_stable(path, self.Prod) try: self.ProdFreqs, zpe = self.Prod._calc.read_vibs() except: self.ProdFreqs, zpe = self.characteriseFreqInternal(self.Prod) self.ProdName = tl.getSMILES(self.Prod, False, partialOpt=False) self.Prod = tl.setCalc(self.Prod, self.singleString, self.singleMeth, self.singleLev) self.productEnergy = self.Prod.get_potential_energy() + zpe try: self.Prod._calc.close() except: pass if self.is_bimol_prod == True: try: self.biProd = tl.setCalc(self.biProd, self.highString, self.highMeth, self.highLev) self.biProd._calc.minimise_stable(path, self.biProd) except: self.biProd = tl.setCalc(self.biProd, self.lowString, self.lowMeth, self.lowLev) self.biProd._calc.minimise_stable(path, self.biProd) try: self.biProdFreqs, zpe = self.biProd._calc.read_vibs() except: self.biProdFreqs, zpe = self.characteriseFreqInternal( self.biProd) self.biProd = tl.setCalc(self.biProd, self.singleString, self.singleMeth, self.singleLev) self.biProdName = tl.getSMILES(self.biProd, False, partialOpt=False) self.productEnergy += (self.biProd.get_potential_energy() + zpe) try: self.biProd._calc.close() except: pass try: try: self.CombProd = tl.setCalc(self.CombProd, self.highString, self.highMeth, self.highLev) self.CombProd._calc.minimise_stable(path, self.CombProd) except: self.CombProd = tl.setCalc(self.CombProd, self.lowString, self.lowMeth, self.lowLev) self.CombProd._calc.minimise_stable(path, self.CombProd) try: self.CombProdFreqs, zpe = self.CombProd._calc.read_vibs() except: self.CombProdFreqs, zpe = self.characteriseFreqInternal( self.CombProd) self.CombProd = tl.setCalc(self.CombProd, self.singleString, self.singleMeth, self.singleLev) self.CombProdName = tl.getSMILES(self.CombProd, False, partialOpt=False) self.CombProductEnergy = ( self.CombProd.get_potential_energy() + zpe) try: self.CombProd._calc.close() except: pass except: pass
def characteriseTSExt(self, mol, low, path, QTS3): os.chdir((self.workingDir)) # Higher level optimisation via some external program if low: print("looking for TS at lower level") mol = tl.setCalc(mol, self.lowString, self.lowMeth + 'TS', self.lowLev) else: mol = tl.setCalc(mol, self.highString, self.highMeth + 'TS', self.highLev) try: mol.get_forces() except: pass if not low and self.highMeth == "gauss": mol, imaginaryFreq, TSFreqs, zpe, rmol, pmol = tl.getGausTSOut( self.workingDir + '/Raw/calcHigh' + self.procNum, path, self.highLev, self.CombReac, self.CombProd, mol, self.is_bimol_reac, QTS3) os.chdir((self.workingDir)) else: print("getting TS geom") if low: mol = tl.getOptGeom( self.workingDir + '/Raw/' + 'calcLow' + self.procNum + '/', 'none', self.Reac, self.lowMeth) else: mol = tl.getOptGeom( self.workingDir + '/Raw/' + 'calcLow' + self.procNum + '/', 'none', self.Reac, self.lowMeth) # Then calculate frequencies os.chdir((self.workingDir + '/Raw/' + self.procNum)) print("getting TS freqs") if low: mol = tl.setCalc(mol, self.lowString, self.lowMeth + 'Freq', self.lowLev) else: mol = tl.setCalc(mol, self.highString, self.highMeth + 'Freq', self.highLev) try: mol.get_forces() except: pass print("reading TS freqs") if low: try: imaginaryFreq, TSFreqs, zpe, rmol, pmol = tl.getTSFreqs( self.workingDir + '/Raw/' + self.procNum + '/Raw/calcLow' + self.procNum, path + '/TSPreDirectImag', self.lowMeth, self.TS) except: os.chdir((self.workingDir)) else: try: imaginaryFreq, TSFreqs, zpe, rmol, pmol = tl.getTSFreqs( self.workingDir + '/Raw/' + self.procNum + '/Raw/calcHigh' + self.procNum, path + '/TSDirectImag', self.highMeth, self.TS) except: os.chdir((self.workingDir)) os.chdir((self.workingDir)) # Finally get single point energy mol = tl.setCalc(mol, self.singleString, self.singleMeth, self.singleLev) print("Getting single point energy for reaction" + str(self.ReacName) + "_" + str(self.ProdName) + " TS = " + str(mol.get_potential_energy()) + "zpe = " + str(zpe) + "reactant energy = " + str(self.reactantEnergy)) energy = mol.get_potential_energy() + zpe return TSFreqs, imaginaryFreq, zpe, energy, mol, rmol, pmol
def characteriseMinExt(self, mol, high): # Low level optimisation with BFGS os.chdir((self.workingDir)) mol = tl.setCalc(mol, self.lowString, self.lowMeth, self.lowLev) min = BFGS(mol) try: min.run(fmax=0.1, steps=100) except: min.run(fmax=0.1, steps=100) if high: if self.highMeth == "gauss": mol, freqs, zpe = tl.getGausOut( self.workingDir + '/Raw/calcHigh' + self.procNum, self.highLev, mol) os.chdir((self.workingDir)) else: # Higher level optimisation via some external program mol = tl.setCalc(mol, self.highString, self.highMeth + 'Opt', self.highLev) try: mol.get_forces() except: pass mol = tl.getOptGeom( self.workingDir + '/' + 'Raw/calcHigh' + self.procNum + '/', 'none', self.Reac, self.highMeth) # Then calculate frequencies os.chdir((self.workingDir + '/Raw/' + self.procNum)) mol = tl.setCalc(mol, self.highString, self.highMeth + 'Freq', self.highLev) try: mol.get_forces() except: pass freqs, zpe = self.characteriseFreqInternal(mol) os.chdir((self.workingDir)) else: if self.lowMeth == "gauss": mol, freqs, zpe = tl.getGausOut( self.workingDir + '/Raw/calcLow' + self.procNum, self.lowLev, mol) os.chdir((self.workingDir)) else: # Higher level optimisation via some external program mol = tl.setCalc(mol, self.lowString, self.lowMeth + 'Opt', self.lowLev) try: mol.get_forces() except: pass mol = tl.getOptGeom( self.workingDir + '/Raw/' + 'calcLow' + self.procNum + '/', 'none', self.Reac, self.lowMeth) # Then calculate frequencies os.chdir((self.workingDir + '/Raw/' + self.procNum)) mol = tl.setCalc(mol, self.lowString, self.lowMeth + 'Freq', self.lowLev) try: mol.get_forces() except: pass freqs, zpe = tl.getFreqs(mol) os.chdir((self.workingDir)) # Finally get single point energy mol = tl.setCalc(mol, self.singleString, self.singleMeth, self.singleLev) energy = mol.get_potential_energy() + zpe return freqs, energy, mol
def TempBiEne(self, tempBi): tempBi = tl.setCalc(tempBi, self.singleString, self.singleMeth, self.singleLev) ene = tempBi.get_potential_energy() return ene
def runTrajectory(self): # Create specific directory fails = 0 self.Mol =tl.setCalc(self.Mol, 'Traj_' + str(self.procNum), self.method, self.level) coords = self.Mol.get_positions() reac_smile = tl.getSMILES(self.Mol,True) self.Mol.set_positions(coords) workingDir = os.getcwd() newpath = workingDir + '/Raw/traj' + str(self.procNum) print("making directory " + newpath) if not os.path.exists(newpath): os.makedirs(newpath) os.chdir(newpath) file_name = str(newpath + "/totaltraj.xyz") if os.path.isfile(file_name): expand = 1 while True: expand += 1 new_file_name = file_name.split(".xyz")[0] + str(expand) + ".xyz" if os.path.isfile(new_file_name): continue else: file_name = new_file_name break namefile = open((file_name), "a") self.numberOfSteps = 0 consistantChange = 0 #Multiple stepsizes self.smallStep = self.timeStep timeStep = self.timeStep eneBXDon = False eBounded= False comBounded = False print("getting first forces") try: self.forces = self.Mol.get_forces() except: try: self.forces = self.Mol.get_forces() except: print("forces error") self.forces = np.zeros(len(self.forces.shape)) #Get MDintegrator type if self.MDIntegrator == 'VelocityVerlet': mdInt = ChemDyME.MDIntegrator.VelocityVerlet(self.forces, self.velocity, self.Mol) elif self.MDIntegrator == 'Langevin': mdInt = ChemDyME.MDIntegrator.Langevin(units.kB * self.LangTemp, self.LangFric, self.forces, self.velocity, self.Mol,timeStep) # Then set up reaction criteria or connectivity map con = ChemDyME.Connectivity.NunezMartinez(self.Mol) # Then set up various BXD procedures if self.comBXD or self.biMolecular: self.comBXD = True if self.mixedTimestep == True: mdInt.reset(self.timeStep * 10) comBxd = ChemDyME.BXDconstraint.COM(self.Mol, 0, self.minCOM, hitLimit = 100000, activeS = self.fragIdx, runType="fixed") if self.eneBXD: eneBXD = ChemDyME.BXDconstraint.Energy(self.Mol, -10000, 10000, hitLimit = 1, adapMax = self.adaptiveSteps, runType="adaptive") # Run MD trajectory for specified number of steps for i in range(0,self.mdSteps): t = process_time() try: self.ene = self.Mol.get_potential_energy() except: pass # Update the COM seperation and check whether it is bounded if self.comBXD: comBxd.update(self.Mol) comBounded = comBxd.inversion if self.comBXD and eneBXDon and i % self.printFreq == 0: print("Ene = " + str(eneBXD.s[0]) + ' S = ' + str(comBxd.s[0]) + ' step = ' + str(i) + ' process = ' + str(self.procNum) + ' time = ' + str(process_time()-t) + ' temperature = ' + str(self.Mol.get_temperature())) elif self.comBXD and i % self.printFreq == 0 : print("Ene = " + "NA" + ' S = ' + str(comBxd.s[0]) + ' step = ' + str(i) + ' process = ' + str(self.procNum) + ' time = ' + str(process_time()-t) + ' temperature = ' + str(self.Mol.get_temperature())) elif eneBXDon and i % self.printFreq == 0: print("Ene = " + str(self.Mol.get_potential_energy()) + ' box = ' + str(eneBXD.box) + ' step = ' + str(i) + ' process = ' + str(self.procNum) + ' time = ' + str(process_time()-t) + ' temperature = ' + str(self.Mol.get_temperature()) + ' Etot ' + str(self.Mol.get_potential_energy() + self.Mol.get_kinetic_energy())) if i % self.printFreq == 0 and self.geom_print is True: tl.printTraj(namefile, self.Mol.copy()) # Now check whether to turn BXDE on if self.comBXD: if (self.biMolecular or self.comBXD) and comBxd.s[0] < self.minCOM and eneBXDon == False: if self.mixedTimestep == True: mdInt.reset(self.timeStep) eneBXDon = False elif self.eneBXD and self.ReactionCountDown == 0: eneBXDon = True if eneBXDon == True: eneBXD.update(self.Mol) eBounded = eneBXD.inversion if comBounded is True and self.ReactionCountDown == 0: self.Mol.set_positions(mdInt.old_positions) com_del_phi = comBxd.del_constraint(self.Mol) if comBxd.stuck == True and comBxd.s[0] < self.minCOM: comBxd.stuckFix() if eBounded: self.Mol.set_positions(mdInt.old_positions) try: e_del_phi = eneBXD.del_constraint(self.Mol) except: pass # Perform inversion if required if eBounded is True and comBounded is True: mdInt.constrain2(e_del_phi, com_del_phi) elif eBounded is False and comBounded is True: mdInt.constrain(com_del_phi) elif eBounded is True and comBounded is False: mdInt.constrain(e_del_phi) timeStep = self.smallStep else: self.numberOfSteps += 1 timeStep = self.timeStep mdInt.md_step_pos(self.forces, timeStep, self.Mol) if eBounded and eneBXD.boxList[eneBXD.box].lower.hit( self.Mol.get_potential_energy(), 'down'): ene = self.Mol.get_potential_energy() self.Mol.set_positions(mdInt.old_positions) mdInt.current_positions = mdInt.old_positions ene1 = self.Mol.get_potential_energy() hit1 = eneBXD.boxList[eneBXD.box].lower.hit(ene1, 'down') mdInt.constrained = True mdInt.md_step_pos(self.forces, timeStep*0.0000001, self.Mol) ene2 = self.Mol.get_potential_energy() hit2 = eneBXD.boxList[eneBXD.box].lower.hit(ene2, 'down') try: self.forces = self.Mol.get_forces() except: try: self.forces = self.Mol.get_forces() except: print("forces error") self.forces = np.zeros(len(self.forces.shape)) mdInt.md_step_vel(self.forces, timeStep, self.Mol) self.MolList.append(self.Mol.copy()) # Update connectivity map to check for reaction con.update(self.Mol) if con.criteriaMet is True: if consistantChange == 0: self.TSpoint = i self.TSgeom = self.Mol.copy() consistantChange = self.consistantWindow elif consistantChange > 0: if consistantChange == 1: self.ReactionCountDown = self.window eneBXDon = False consistantChange -= 2 else: consistantChange -= 1 else: if consistantChange > 0: consistantChange = 0 con.criteriaMet = False if not self.ReactionCountDown == 0: self.ReactionCountDown -= 1 if self.ReactionCountDown == 1: awrite('temp.xyz', self.Mol) coords = self.Mol.get_positions() min = BFGS(self.Mol) min.run(fmax=0.1, steps=5) con2 = ChemDyME.Connectivity.NunezMartinez(self.Mol) pmol_name = tl.getSMILES(self.Mol,False) self.Mol.set_positions(coords) if not np.array_equal(con.C,con2.C): self.ReactionCountDown = 0 self.productGeom = self.Mol.get_positions() os.chdir(workingDir) break elif fails < 5: self.ReactionCountDown = self.window fails +=1 else: fails = 0 self.ReactionCountDown = 0 consistantChange = 0 while eneBXD.boxList[eneBXD.box].lower.hit( self.Mol.get_potential_energy(), 'down'): eneBXD.box -=1 try: self.Mol._calc.close() except: pass namefile.close() os.chdir(workingDir)