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 newReacFromSMILE(self, SMILE, opt=False): self.ReacName = SMILE SMILE.replace('____', '.') SMILE.replace('comp', '.') self.Reac = tl.getMolFromSmile(SMILE) self.CombReac = self.Reac.copy() self.TS = self.Reac.copy() self.TSFreqs = [] self.TS2 = self.Reac.copy() self.TS2Freqs = [] self.ProdFreqs = [] self.spline_ene = [] self.Prod = self.Reac.copy() self.ProdName = tl.getSMILES(self.Prod, False) self.biProd = self.Reac.copy() self.biProdName = tl.getSMILES(self.Prod, False) self.biProdFreqs = [] self.CombProd = self.Reac.copy() self.is_bimol_prod = False self.is_bimol_reac = False self.imaginaryFreq = 0.0 self.imaginaryFreq2 = 0.0 self.barrierlessReaction = False self.forwardBarrier = 0.0 self.forwardBarrier2 = 0.0 self.have_reactant = True self.is_IntermediateProd = False self.AltProd = self.Reac.copy() self.TScorrect = False if opt: self.optReac()
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 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 __init__(self, path): self.pathStride = 1 self.fixToPath = False self.pathDistCutOff = False self.BiList = [] self.full_geom_print = False mpath = path + '/inp.txt' self.InitialBi = False self.mixedTimestep = False self.RunType = "MechGen" self.printNEB = False self.checkAltProd = False self.eneBXD = False self.comBXD = False self.printDynPath = False self.printNEB = False self.maxAdapSteps = 0 self.eneBoxes = 0 self.grainSize = 0 self.numberOfBoxes = 10 self.dynPrintFreq = 5 self.dynPrintStart = 100 self.ReactIters = 1 self.NEBrelax = False self.GenBXDrelax = False self.NEBsteps = 3 self.printFreq = 10 self.QTS3 = False # BXD defaults self.decorrelationSteps = 10 self.histogramBins = 1 self.epsilon = 0.95 self.principalCoordinates = [] # Open Input inp = open(mpath, "r") geom = open(mpath,"r").readlines() self.printString = "" #Generate empty list to hold mm3 types if required self.atomTypes = [] self.MMfile = 'test.pdb' words = geom[1].split() # Check if the first word is Atoms, if so the starting molecule is specified in the input file if words[0] == "Atoms": self.numberOfAtoms = int(words[2]) size = self.numberOfAtoms self.species = np.zeros(size, dtype='str') self.cartesians = np.zeros((size,3), dtype='float') self.masses = np.zeros((size), dtype='float') for i in range(3,size+3): # Get index for species and cartesian arrays j = i - 3 words = geom[i].split() self.species[j] = words[0] self.cartesians[j][0] = float(words[1]) self.cartesians[j][1] = float(words[2]) self.cartesians[j][2] = float(words[3]) for i in range (0,size): if self.species[i] == 'C': self.masses[i] = 12.0107 if self.species[i] == 'O': self.masses[i] = 15.9994 if self.species[i] == 'H': self.masses[i] = 1.00794 if self.species[i] == 'N': self.masses[i] = 12.0107 self.StartType = "specified" # Loop over lines for line in inp: #GenBXD input; #Start type is the starting reactant unless specified in already. StartType is a SMILES string or file path to be read in if re.search("Start", line): self.StartType = str(line.split()[2]) self.Start = str(line.split()[3]) # End type specifies the target product for the GenBXD run if re.search("End", line): self.EndType = str(line.split()[2]) self.End = str(line.split()[3]) if re.search("MMfile", line): self.MMfile = str(line.split()[2]) # PathType defines the prgress along Traj. It is either simpleDistance (distance from boundary), distance (cumulative version of simple distance) # linear (projection onto linear path between start and end) or curve (projection onto some trajectory or path) if re.search("PathType", line): self.PathType = str(line.split()[2]) if self.PathType == 'curve' or self.PathType == 'gates': self.PathFile = str(line.split()[3]) # Determines the collective variables for GenBXD if re.search("CollectiveVarType", line): self.CollectiveVarType = str(line.split()[2]) if self.CollectiveVarType == 'specified': uVar = line.split()[3] uVar = uVar.replace("n","\n") c = StringIO(uVar) self.CollectiveVar = np.loadtxt(c, delimiter=',') elif self.CollectiveVarType == 'file': i = 4 while i < len(line.split()): array = self.readPrincipalComponents(line.split()[i], line.split()[3]) self.principalCoordinates.append(array) i+=1 elif self.CollectiveVarType != 'changedBonds': self.CollectiveVarTraj = str(line.split()[3]) if re.search("RunType", line): self.RunType = str(line.split()[2]) if re.search("NEBrelax", line): self.NEBrelax = True if re.search("printNEB", line): self.printNEB = True if re.search("printDynPath", line): self.printDynPath = True self.dynPrintFreq = int(line.split()[1]) self.dynPrintStart = int(line.split()[2]) if re.search("QTS3", line): self.QTS3 = True if re.search("checkAltProd", line): self.checkAltProd = True if re.search("NEBsteps", line): self.NEBsteps = int(line.split()[2]) if re.search("name", line): self.dirName = line.split()[2] if re.search("cores", line): self.cores =int(line.split()[2]) if re.search("ReactionIterations", line): self.ReactIters =int(line.split()[2]) if re.search("trajectoryMethod1", line): self.trajMethod1 = line.split()[2] self.trajLevel1 = line.split()[3] self.trajMethod2 = self.trajMethod1 self.trajLevel2 = self.trajLevel1 if re.search("trajectoryMethod2", line): self.trajMethod2 = line.split()[2] self.trajLevel2 = line.split()[3] if re.search("lowLevel", line): self.lowerMethod = line.split()[2] self.lowerLevel = line.split()[3] if re.search("highLevel", line): self.higherMethod = line.split()[2] self.higherLevel = line.split()[3] if re.search("singleLevel", line): self.singleMethod = line.split()[2] self.singleLevel = line.split()[3] if re.search("TrajectoryInitialTemp", line): self.trajInitT = int(line.split()[2]) if re.search("MDIntegrator", line): self.MDIntegrator = line.split()[2] if re.search("mdSteps", line): self.mdSteps = int(line.split()[2]) if re.search("printFreq", line): self.printFreq = int(line.split()[2]) if re.search("timeStep", line): self.timeStep = float(line.split()[2]) if re.search("endOnReaction", line): self.endOnReaction = bool(line.split()[2]) if re.search("reactionWindow", line): self.reactionWindow = int(line.split()[2]) if re.search("BiReactant", line): self.InitialBi = True if re.search("LangFriction", line): self.LFric = float(line.split()[2]) if re.search("full_geom_print", line): self.full_geom_print = True if re.search("LangTemperature", line): self.LTemp = float(line.split()[2]) if re.search("BiList", line): BiListStrings = [str(line.split()[2])] for x in BiListStrings: self.BiList.append(tl.getMolFromSmile(x)) if re.search("BiRate", line): self.BiRates = [str(line.split()[2])] if re.search("BiTemp", line): self.BiTemp = float(line.split()[2]) # BXD input if re.search("eneBXD", line): if (line.split()[2]) == 'True': self.eneBXD = True if (line.split()[2])== 'False': self.eneBXD = False if self.eneBXD is True: if re.search("eneUpper", line): self.eneUpper = float(line.split()[2]) if re.search("eneLower", line): self.eneLower = float(line.split()[2]) if re.search("eneAdaptive", line): if (line.split()[2]) == 'True': self.eneAdaptive = True if (line.split()[2])== 'False': self.eneAdaptive = False if re.search("eneMax", line): self.eneMax = float(line.split()[2]) if re.search('eneEvents', line): self.eneEvents = int(line.split()[2]) if re.search('eneBoxes', line): self.eneBoxes = int(line.split()[2]) if re.search('decorrelationSteps', line): self.decorrelationSteps = int(line.split()[2]) if re.search('histogramLevel', line): self.epsilon = float(line.split()[2]) if re.search('histogramBins', line): self.histogramBins = int(line.split()[2]) if re.search('fixToPath', line): self.fixToPath = True if re.search('pathStride', line): self.pathStride = int(line.split()[2]) if re.search('pathDistCutOff', line): uVar = line.split()[2] if ',' in uVar: c = StringIO(uVar) self.pathDistCutOff = np.loadtxt(c, delimiter=',') else: self.pathDistCutOff= np.empty(1000) self.pathDistCutOff.fill(float(uVar)) if re.search("maxHits",line): self.maxHits = int(line.split()[2]) if re.search("runsThrough",line): self.runsThrough = int(line.split()[2]) if re.search("adaptiveSteps",line): self.maxAdapSteps = int(line.split()[2]) if re.search("grainSize",line): self.grainSize = int(line.split()[2]) if re.search("numberOfBoxes",line): self.numberOfBoxes = int(line.split()[2]) if re.search("comBXD", line): if (line.split()[2]) == 'True': self.comBXD = True if (line.split()[2])== 'False': self.comBXD = False if self.comBXD is True or self.InitialBi is True: if re.search("minCOM", line): self.minCOM = float(line.split()[2]) if re.search("fragment_indices", line): self.fragIndices = [int(line.split()[2]),int(line.split()[3])] # Geometry opt if re.search("GeomPot", line): self.GeomPot1 = line.split()[2] # Single point ene if re.search("singlePoint", line): self.singlePoint = line.split()[2] # Master Equation if re.search("maxSimulationTime", line): self.maxSimulationTime = float(line.split()[2]) if re.search("equilThreshold", line): self.equilThreshold = int(line.split()[2]) # Look for mm3 types if re.search("AtomTypes", line): self.atomTypes = line.split()[2] self.atomTypes = self.atomTypes.split(",") for i in range (0,len(self.atomTypes)): self.atomTypes[i] = float(self.atomTypes[i]) self.trajMethod = self.trajMethod1 self.trajLevel = self.trajLevel1