示例#1
0
 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
示例#2
0
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
示例#3
0
 def __init__(self, cartesians, species, i, glo):
     self.twoStageTS = False
     self.tempBiEne = 0
     self.energyDictionary = {"".join(species): 0}
     self.MiddleSteps = 2
     self.spline_ene = []
     self.NEBrelax = glo.NEBrelax
     self.NEBsteps = glo.NEBsteps
     self.eneBaseline = 0.0
     self.workingDir = os.getcwd()
     self.procNum = str(i)
     self.lowString = 'Raw/calcLow' + str(i) + '/'
     self.lowLev = glo.lowerLevel
     self.lowMeth = glo.lowerMethod
     self.highLev = glo.higherLevel
     self.highMeth = glo.higherMethod
     self.highString = 'Raw/calcHigh' + str(i) + '/'
     self.singleString = 'Raw/calcSingle' + str(i) + '/'
     self.singleMeth = glo.singleMethod
     self.singleLev = glo.singleLevel
     self.ReacFreqs = []
     self.Reac = Atoms(symbols=species, positions=cartesians)
     self.ReacName = tl.getSMILES(self.Reac, False)
     self.TS = Atoms(symbols=species, positions=cartesians)
     self.TSFreqs = []
     self.TS2 = Atoms(symbols=species, positions=cartesians)
     self.TS2Freqs = []
     self.ProdFreqs = []
     self.Prod = Atoms(symbols=species, positions=cartesians)
     self.ProdName = tl.getSMILES(self.Prod, False)
     self.biProd = Atoms(symbols=species, positions=cartesians)
     self.biProdName = tl.getSMILES(self.Prod, False)
     self.biProdFreqs = []
     self.biReac = Atoms(symbols=species, positions=cartesians)
     self.biReacName = tl.getSMILES(self.Reac, False)
     self.biReacFreqs = []
     self.CombProd = Atoms(symbols=species, positions=cartesians)
     self.CombProdFreqs = []
     self.CombReac = Atoms(symbols=species, positions=cartesians)
     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.reactantEnergy = 0.0
     self.productEnergy = 0.0
     self.have_reactant = False
     self.inc = glo.dynPrintFreq
     self.dynPrintStart = glo.dynPrintStart
     self.printNEB = glo.printNEB
     self.QTS3 = glo.QTS3
     self.MidPoint = Atoms(symbols=species, positions=cartesians)
     self.checkAltProd = glo.checkAltProd
     self.AltProd = Atoms(symbols=species, positions=cartesians)
     self.is_IntermediateProd = False
     self.TScorrect = False
     self.TS2correct = False
     self.CombProductEnergy = 0
示例#4
0
 def newReac(self, path, name, Reac, opt):
     if Reac == True:
         self.Reac = read(path + '/Reac.xyz')
     else:
         self.Reac = read(path + '/Prod.xyz')
     self.ReacName = name
     self.CombReac = self.Reac.copy()
     self.TS = self.Reac.copy()
     self.TSFreqs = []
     self.TS2 = self.Reac.copy()
     self.TS2Freqs = []
     self.ProdFreqs = []
     self.Prod = self.Reac.copy()
     self.spline_ene = []
     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
     self.reactantEnergy = self.Reac.get_potential_energy()
     if opt:
         self.optReac()
示例#5
0
 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()
示例#6
0
 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
示例#7
0
 def characteriseTSFreqInternal(self, mol):
     os.chdir((self.workingDir + '/' + '/Raw/' + self.procNum))
     vib = Vibrations(mol)
     vib.clean()
     vib.run()
     viblist = vib.get_frequencies()
     freqs, zpe = tl.getVibString(viblist, False, True)
     vib.clean()
     os.chdir((self.workingDir))
     imaginaryFreq = tl.getImageFreq(viblist)
     return freqs, zpe, imaginaryFreq
示例#8
0
 def re_init(self, path):
     self.TS = read(path + '/Reac.xyz')
     self.TSFreqs = []
     self.TS2 = read(path + '/Reac.xyz')
     self.TS2Freqs = []
     self.ProdFreqs = []
     self.spline_ene = []
     self.Prod = read(path + '/Reac.xyz')
     self.ProdName = tl.getSMILES(self.Prod, False).strip('\n\t')
     self.biProd = read(path + '/Reac.xyz')
     self.biProdName = tl.getSMILES(self.Prod, False).strip('\n\t')
     self.biProdFreqs = []
     self.CombProd = read(path + '/Reac.xyz')
     self.is_bimol_prod = False
     self.imaginaryFreq = 0.0
     self.imaginaryFreq2 = 0.0
     self.barrierlessReaction = False
     self.forwardBarrier = 0.0
     self.forwardBarrier2 = 0.0
     self.productEnergy = 0.0
     self.TScorrect = False
示例#9
0
    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
示例#10
0
    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
示例#11
0
 def re_init_bi(self, cartesians, species):
     self.Reac = Atoms(symbols=species, positions=cartesians)
     self.CombReac = self.Reac.copy()
     self.TS = Atoms(symbols=species, positions=cartesians)
     self.TSFreqs = []
     self.spline_ene = []
     self.TS2 = Atoms(symbols=species, positions=cartesians)
     self.TS2Freqs = []
     self.ProdFreqs = []
     self.Prod = Atoms(symbols=species, positions=cartesians)
     self.ProdName = tl.getSMILES(self.Prod, False)
     self.biProd = Atoms(symbols=species, positions=cartesians)
     self.biProdName = tl.getSMILES(self.Prod, False)
     self.biProdFreqs = []
     self.CombProd = Atoms(symbols=species, positions=cartesians)
     self.is_bimol_prod = False
     self.imaginaryFreq = 0.0
     self.imaginaryFreq2 = 0.0
     self.barrierlessReaction = False
     self.forwardBarrier = 0.0
     self.forwardBarrier2 = 0.0
     self.productEnergy = 0.0
     self.TScorrect = False
     self.optReac()
示例#12
0
 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)
示例#13
0
 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
示例#14
0
    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)
示例#15
0
 def TempBiEne(self, tempBi):
     tempBi = tl.setCalc(tempBi, self.singleString, self.singleMeth,
                         self.singleLev)
     ene = tempBi.get_potential_energy()
     return ene
示例#16
0
    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
示例#17
0
    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
示例#18
0
    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
示例#19
0
    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
示例#20
0
    def runGenBXD(self, Reac, Prod, maxHits, adapMax, pathType, path, bonds, decSteps, histogramBins, pathLength, fixToPath, pathDistCutOff, epsilon):

        self.iterations = 0

        keepGoing = True

        workingDir = os.getcwd()
        file = open("geo.xyz","w")
        sfile = open("plotData.txt", "w")





        #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, self.timeStep)

        #Check whether a list of bounds is present? If so read adaptive boundaries from previous run
        BXD = ChemDyME.BXDconstraint.genBXD(self.Mol, Reac, Prod, adapMax = adapMax, activeS = bonds, path = path, pathType = pathType, decorrelationSteps = decSteps, runType = 'adaptive', hitLimit = 1, hist = histogramBins, endDistance=pathLength, fixToPath=fixToPath, pathDistCutOff=pathDistCutOff, epsilon=epsilon )
        #Check whether a list of bounds is present? If so read adaptive boundaries from previous run
        if os.path.isfile("BXDbounds.txt"):
            BXD.readExisitingBoundaries("BXDbounds.txt")
            BXD.reset("fixed", maxHits)

        else:
            BXDfile = open("BXDbounds.txt", "w")

        # Get forces from designated potential
        try:
            self.forces = self.Mol.get_forces()
        except:
            print('forces error')

        # Run MD trajectory for specified number of steps
        while keepGoing:

            t = process_time()
            bxdt = process_time()
            BXD.update(self.Mol)
            bxdte = process_time()
            eBounded = BXD.inversion
            if eBounded:
                self.Mol.set_positions(mdInt.oldPos)
                bxd_del_phi = BXD.del_constraint(self.Mol)

            if self.MDIntegrator == 'VelocityVerlet' and not eBounded:
                print('S ' + str(BXD.s[2])  + ' box ' + str(BXD.box) + ' time ' + str(process_time()-t) + ' Etot ' + str(self.Mol.get_potential_energy() + self.Mol.get_kinetic_energy()))
            elif self.iterations % self.printFreq == 0 and not eBounded:
                print('pathNode = ' +str(BXD.pathNode) + ' distFromPath = ' + str(BXD.distanceToPath) + ' project = ' +str(BXD.s[2]) + ' S ' + str(BXD.s[0]) + " hits " + str(BXD.boxList[BXD.box].upper.hits) + ' ' + str(BXD.boxList[BXD.box].lower.hits) + " points in box " + str(len(BXD.boxList[BXD.box].data))  + ' box ' + str(BXD.box) + ' time ' + str(process_time()-t) + ' temperature ' + str(self.Mol.get_temperature()))

            if self.iterations % (self.printFreq/100) == 0:
                sfile.write('S \t=\t' + str(BXD.s[0]) + '\tbox\t=\t' + str(BXD.box) + " hits " + str(BXD.boxList[BXD.box].upper.hits) + ' ' + str(BXD.boxList[BXD.box].lower.hits) + "\n")
                sfile.flush()

            # Perform inversion if required
            if eBounded is True:
                mdInt.constrain(bxd_del_phi)

            mdpt = process_time()
            mdInt.mdStepPos(self.forces, self.timeStep, self.Mol)
            mdpte = process_time()
            # Get forces from designated potential
            ft = process_time()
            try:
                self.forces = self.Mol.get_forces()
            except:
                print('forces error')
            fte = process_time()
            mdvt = process_time()
            mdInt.mdStepVel(self.forces, self.timeStep, self.Mol)
            mdvte = process_time()

            self.numberOfSteps += 1

            if self.iterations % self.printFreq == 0:
                tl.printTraj(file,self.Mol)
            self.iterations += 1

            #print( "Forces time = " + str(fte - ft) + " BXDtime = " + str(bxdte - bxdt) + " MDP time = " + str(mdpte - mdpt) + "MDV time = " + str(mdvte - mdvt))

            #check if one full run is complete, if so stop the adaptive search
            if BXD.completeRuns == 1:
                keepGoing = False

        #Check whether inital run and adaptive box placement run, save boundaries and rest all bxd boundaries ready for convergence
        if BXD.runType == "adaptive":
            # reset all box data other than boundary positions and prepare to run full BXD
            # print boundaries to file
            keepGoing = True
            BXD.printBounds(BXDfile)
            BXD.reset("fixed", maxHits)

        file.close()

        # Rerun BXD with new adaptively set bounds to converge box to box statistics
        # Get forces and energy from designated potential
        try:
            self.forces = self.Mol.get_forces()
        except:
            print('forces error')

        while keepGoing:
            t = process_time()

            BXD.update(self.Mol)
            eBounded = BXD.inversion
            if eBounded:
                self.Mol.set_positions(mdInt.oldPos)

            eBounded = BXD.inversion
            if self.MDIntegrator == 'VelocityVerlet' and self.iterations % self.printFreq == 0:
                print('S ' + str(BXD.s[2])  + ' box ' + str(BXD.box) + ' time ' + str(process_time()-t) + ' Epot ' + str(self.Mol.get_potential_energy() + self.Mol.get_kinetic_energy()))
            elif self.iterations % self.printFreq == 0:
                print('pathNode = ' +str(BXD.pathNode) + ' project = ' +str(BXD.s[2]) + ' S ' + str(BXD.s[0]) + " hits " + str(BXD.boxList[BXD.box].upper.hits) + ' ' + str(BXD.boxList[BXD.box].lower.hits) + " points in box " + str(len(BXD.boxList[BXD.box].data))  + ' box ' + str(BXD.box) + ' time ' + str(process_time()-t) + ' temperature ' + str(self.Mol.get_temperature()))

            # Perform inversion if required
            if eBounded is True:
                mdInt.constrain(BXD.del_phi)

            mdInt.mdStepPos(self.forces, self.timeStep, self.Mol)
            # Get forces from designated potential
            try:
                self.forces = self.Mol.get_forces()
            except:
                print('forces error')
            mdInt.mdStepVel(self.forces, self.timeStep, self.Mol)

            self.numberOfSteps += 1

            if BXD.completeRuns == 1:
                keepGoing = False

        #Look for exsisting results files from previous runs and open a new results file numbered sequentially from those that exsist already
        i = 0
        while(os.path.isfile("BXDprofile" + str(i) + ".txt")):
            i += 1
        BXDprofile = open("BXDprofile" + str(i) + ".txt", "w")
        BXDrawData = open("BXDrawData" + str(i) + ".txt", "w")
        BXDlowRes = open("BXDlowResProfile" + str(i) + ".txt" , "w")
        BXD.gatherData(BXDprofile, BXDrawData, self.LangTemp, BXDlowRes)
示例#21
0
    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
示例#22
0
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)
示例#23
0
 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
示例#24
0
 def get_additional_lines(self, ts, p):
     string1 = "Prod\n\n0 " + str(self.parameters['mult']) + "\n"
     xyz1 = tl.convertMolToGauss(p)
     string2 = "TS\n\n0 " + str(self.parameters['mult']) + "\n"
     xyz2 = tl.convertMolToGauss(ts)
     return string1 + xyz1 + string2 + xyz2
示例#25
0
    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