Exemplo n.º 1
0
def calc_statistic_xyg3(C, FitClass):
    '''\
    return statistic informations for "XYG3" type optimization\
    '''
    from my_io import print_List
    from my_io import print_Error

    from opt_func import opt_func

    print_List(FitClass.IOut, C, 4, Info='Testing parameters in this round')
    #for x,y in FitClass.CompDict.iteritems():
    #    print x,y
    FitClass.run_OptCalc(opt_func, C)
    if FitClass.OptAlgo[:5] == 'batch':
        FitClass.get_OptResu(iop=1)
        print_List(FitClass.IOut,FitClass.InitGuess,\
            4,Info='Batch corresponds to these parameters ::')
        FitClass.run_Statistic()
    else:
        FitClass.get_OptResu(iop=0)
        AD, wAD, MAD, wMAD, RMS, wRMS = FitClass.run_Statistic()
        if FitClass.OptAlgo == 'leastsq':
            return array(FitClass.Result)
        elif FitClass.OptAlgo[-3:] == 'rms':
            return wRMS
        elif FitClass.OptAlgo[-3:] == 'mad':
            return wMAD
        elif FitClass.OptAlgo[-2:] == 'ad':
            return wAD
        else:
            print_Error(FitClass.IOut,
                'Error in returning required type of statistic data'+\
                ' \"calc_statistic()->%s\"' % FitClass.OptAlgo)
    return
Exemplo n.º 2
0
def calc_statistic_xmp2(C, FitClass):
    '''\
    return statistic informations for xMP2 type optimization\
    '''
    from my_io import print_List
    from my_io import print_Error

    from opt_func import update_qchem_xmp2

    print_List(FitClass.IOut, C, 4, Info='Testing parameters in this round')
    update_qchem_xmp2(C, FitClass)
    FitClass.run_QcmBatch()
    if FitClass.OptAlgo[:5] == 'batch':
        FitClass.get_OptResu(iop=1)
        print_List(FitClass.IOut,FitClass.InitGuess,\
            4,Info='Batch corresponds to these parameters ::')
        FitClass.run_Statistic()
    else:
        FitClass.get_OptResu(iop=0)
        AD, wAD, MAD, wMAD, RMS, wRMS = FitClass.run_Statistic()
        if FitClass.OptAlgo == 'leastsq':
            return array(FitClass.Result)
        elif FitClass.OptAlgo[-3:] == 'rms':
            return wRMS
        elif FitClass.OptAlgo[-3:] == 'mad':
            return wMAD
        elif FitClass.OptAlgo[-2:] == 'ad':
            return wAD
        else:
            print_Error(FitClass.IOut,
                'Error in return required type of statistic data'+\
                ' \"calc_statistic()->%s\"' % FitClass.OptAlgo)
    return
Exemplo n.º 3
0
    def __init__(self, iout, fn=None, bugctrl=0):
        '''\
        Initialize variables belonged to GauIO\
        '''
        from os import getcwd
        from os import getenv
        from os.path import isfile

        from my_io import print_Error
        from my_io import print_String

        self.IOut = iout  # Flow of the output file
        self.IPrint = bugctrl  # to control the printing out
        self.FileName = fn  # Name of the input file

        self.WorkDir = getcwd().strip()  # STRING, current DIR
        self.HomeDir = getenv('HOME')  # STRING, Home DIR

        if getenv('IGOR_MODULES_PATH'):  # STRING, private module DIR
            self.ModuDir = getenv('IGOR_MODULES_PATH')
        else:
            print_Error(self.IOut,
                'Error in getting the grobal environment '+\
                '\"$IGOR_MODULES_PATH\" which is the direction to private modules')

        if self.FileName == None:
            self.f = 'None'
            if self.IPrint >= 1:
                print_String(self.IOut,
                             'Do not open input file for CP2KIO class', 1)
        else:
            try:
                self.f = file(self.FileName, 'r')  # Open it
            except IOError:
                self.f = file('Error_%s' % self.FileName, 'w')
            if self.IPrint >= 1:
                print_String(
                    self.IOut, 'Open CP2K-Input file "%s" for CP2KIO class' %
                    self.FileName, 1)
            #
            #Generating "self.JobName" which is head of "self.FileName"
            #For example, if    self.FileName  = 'g03_1.gjf'
            #             then  self.JobName   = 'g03_1'
            TmpList = self.FileName.split('.')
            if len(TmpList) <= 2:
                self.JobName = TmpList[0]
            else:
                self.JobName = '.'.join(TmpList[0:-1])  # Name of this job
            del TmpList
            if bugctrl >= 1:
                print_String(iout, 'Enter the job : \"%s\"' % self.JobName, 2)

        self.InpuDict = {}

        self.SCFReal = 0.0  # REAL, SCF energy
        return
Exemplo n.º 4
0
    def get_Result(self, iop=0):
        '''Collect results'''
        from re import compile
        from os.path import isfile
        from my_io import my_plus
        from my_io import print_String
        from my_io import print_Error

        if isfile('Job_%s.log' % self.JobName):
            lf = file('Job_%s.log' % self.JobName, 'r')
            if self.IPrint >= 1:
                print_String(self.IOut, 'Now open Job_%s.log' % self.JobName,
                             1)
        else:
            print_Error(self.IOut, 'Error in finding Output file')

        if iop == 0:  # For SCF energy
            p1 = compile('ENERGY\| Total FORCE_EVAL \( QS \) energy \(a.u.\):')
            p2 = compile('SCF run converged in')
            p3 = compile('MAXIMUM NUMBER OF OPTIMIZATION STEPS REACHED')
            lf.seek(0L)
            TmpFile = lf.read().strip()
            if  p2.search(TmpFile) and not p3.search(TmpFile) and\
                p1.search(TmpFile):                                  # Patch for dual basis guess
                LocPos = 0
                for x in p1.finditer(TmpFile):
                    tmpPos = x.end()
                    if tmpPos > LocPos:
                        LocPos = tmpPos
                #while TmpFile[LocPos-1:LocPos]!='\n':
                #    LocPos  = LocPos - 1
                lf.seek(LocPos + 1)
                TmpString = lf.readline().strip()
                TmpList = TmpString.split()
                try:
                    self.SCFReal = float(TmpList[0])
                    if self.IPrint >= 1:
                        print_String(self.IOut,'SCF Energy     = '+\
                            '%18.8f' %self.SCFReal,1)
                except ValueError:
                    print_String(self.IOut,'Error occurss '+\
                        'in getting SCF Energy',1)
                    self.SCFReal = 'NAN'
                    if self.IPrint >= 1:
                        print_String(self.IOut,'SCF Energy     = '+\
                            '       NAN',1)
            else:
                print_String(self.IOut, 'SCF Convergence is not found', 1)
                self.SCFReal = 'NAN'

        return
Exemplo n.º 5
0
    def __init__(self, iout, clist, ian, iop=0, bugctrl=0,\
        c6para=None, c12para=None, r0para=None, dpara=None):
        '''\
        Initialize parameters in this class\
        '''
        from my_io import print_Error
        self.IOut   = iout
        self.CList  = clist
        self.IAn    = ian
        self.IPrint = bugctrl
        self.ICtrl  = iop                                            # ICtrl = 0 : Grimme Disp.
                                                                     #         1 : 6-order term
                                                                     #         2 : 12-order term
                                                                     #         3 : "1" + "2"
                                                                     #         4 : damped 12-order
        self.EngyReal = 0.0
        self.ForcList = []
        self.HessList = []

        if r0para==None:                                             # Now loading dispersion parameters
            self.R0Para = DispGrim.R0Para[:]
        else:
            self.R0Para = r0para[:]
        if c6para==None:
            self.C6Para = DispGrim.C6Para[:]
        else:
            self.C6Para = c6para[:]
        if c12para==None:
            self.C12Para = DispGrim.C12Para[:]
        else:
            self.C12Para = c12para[:]
        if dpara==None:
            self.DPara = DispGrim.DPara
        else:
            try:
                self.DPara = dpara
            except TypeError:
                print_Error(self.IOut,'dpara should be "float" but not "List"')
        return
Exemplo n.º 6
0
def run_optimization(FitClass):
    '''\
    run optimization based on FitClass\
    '''
    from my_io import print_List

    if FitClass.OptAlgo == 'leastsq':  # leastsq algorithm
        plsq    = opt.leastsq(calc_statistic,FitClass.InitGuess,\
            args=tuple([FitClass]))
        tmpresult = [float(x) for x in plsq[0]]
        print_List(FitClass.IOut,
                   tmpresult,
                   4,
                   Info='Optimized result by leastsq algorithm')
        FitClass.InitGuess = tmpresult[:]
    elif FitClass.OptAlgo[:11] == 'fmin_cobyla':  # fmin algorithm
        try:
            from opt_func import opt_func_constrained
        except:
            print_Error(FitClass.IOut,'\"opt_func_constrained\"'+\
                ' is required for \"fmin_cobyla\"')
        interval = 1.0  #   Set initial changes
        for i in FitClass.InitGuess:
            if abs(i) < interval:
                interval = abs(i)
            if i == 0.0:
                interval = 1.0
                break
        plsq    = opt.fmin_cobyla(calc_statistic,FitClass.InitGuess,\
            cons=opt_func_constrained,
            args=tuple([FitClass]),rhobeg=interval)
        print_List(FitClass.IOut,
                   plsq,
                   4,
                   Info='Optimized result by fmin_cobyla algorithm')
        FitClass.InitGuess = plsq[:]
    elif FitClass.OptAlgo[:4] == 'fmin':  # fmin algorithm
        plsq    = opt.fmin(calc_statistic,FitClass.InitGuess,\
            args=tuple([FitClass]))
        print_List(FitClass.IOut,
                   plsq,
                   4,
                   Info='Optimized result by fmin algorithm')
        FitClass.InitGuess = plsq[:]
    elif FitClass.OptAlgo[:5] == 'brute':  # brute algorithm
        plsq    = opt.brute(calc_statistic,\
                ((-4.,-2.),(-1.,1.),(-4.,-2.),(-1.,1.)),\
            args=(FitClass))
        print_List(FitClass.IOut,
                   plsq,
                   4,
                   Info='Optimized result by brute algorithm')
        FitClass.InitGuess = plsq[:]
    elif FitClass.OptAlgo[:6] == 'anneal':  # anneal algorithm
        plsq    = opt.anneal(calc_statistic,FitClass.InitGuess,\
            args=tuple([FitClass]),dwell=200,maxiter=2000,lower=0.0,upper=1.0, T0=200.0)
        print_List(FitClass.IOut,
                   plsq[0],
                   4,
                   Info='Optimized result by anneal algorithm')
        FitClass.InitGuess = plsq[0][:]
    elif FitClass.OptAlgo[:5] == 'batch':  # Just DEBUGING
        calc_statistic(FitClass.InitGuess, FitClass)
    return
Exemplo n.º 7
0
def calc_statistic_scsrpa(C, FitClass):
    '''\
    return statistic informations for SCPT2 type optimization\
    '''
    import time
    from os.path import isdir, abspath, isfile, splitext
    from os import listdir, remove, system
    from my_io import print_List
    from my_io import print_String
    from my_io import print_Error
    from opt_func import update_aims_scsrpa
    import re

    print_List(FitClass.IOut, C, 4, Info='Testing parameters in this round')
    # Initialize the running folder
    if isdir(FitClass.ProjDir):
        for xFile in listdir(FitClass.ProjDir):
            axFile = '%s/%s' % (FitClass.ProjDir, xFile)
            if isfile(axFile) and xFile[-4:] == '.log':
                remove(axFile)
            if isdir(axFile):
                for yFile in listdir(axFile):
                    ayFile = '%s/%s' % (axFile, yFile)
                    if isfile(ayFile) and\
                       yFile=='RUNNING' or\
                       yFile[-4:]=='.log':
                        remove(ayFile)
    time.sleep(2)
    update_aims_scsrpa(C, FitClass)
    if FitClass.BatchType == 'serial':
        FitClass.run_AimBatch()
    elif FitClass.BatchType == 'queue':
        # we should not re-run all finished jobs during this check
        tmpProjCtrl = FitClass.ProjCtrl
        FitClass.ProjCtrl = 2
        # we would like to turn of detailed output during the check
        tmpIPrint = FitClass.IPrint
        FitClass.IPrint = 0
        FlagBatch = FitClass.run_AimBatch()
        interval = 0
        while not FlagBatch:
            time.sleep(2)
            if interval >= 100:
                if FitClass.BatchCmd == 'bsub':
                    qq = 'bjobs'
                else:
                    qq = 'qstate'
                qn = FitClass.BatchQueueName
                un = 'wenxinz'
                system('bjobs > checkFile')
                cFile = open('checkFile', 'r')
                tFile = cFile.read()
                cFile.close()
                #WARNNING: dangerous! should be updated by further effort
                tmpString =\
                   '(?P<iters>\d+)\s*%s\s*RUN\s*%s\s*\S*\s*\S*\s*(?P<jobs>\S+)' %(un,qn)
                p16 = re.compile(tmpString)
                p16p = p16.findall(tFile)
                for (jobi, jobn) in p16p:
                    for job in FitClass.BatcList:
                        fn, fe = splitext(job[2])
                        fR = '%s/%s/RUNNING' % (FitClass.ProjDir, fn)
                        if fn == jobn[-len(fn):] and isfile(fR):
                            remove(fR)
                            xFile = '%s/%s/%s.log' % (FitClass.ProjDir, fn, fn)
                            if isfile(xFile):
                                remove(xFile)
                            xFile = '%s/%s.log' % (FitClass.ProjDir, fn)
                            if isfile(xFile):
                                remove(xFile)
                            os.system('bkill %s' % jobi)
                            print_String(
                                FitClass.IOut,
                                'Unexpected error for the job of %s' % fn, 1)
                            continue
                interval = 0
            FlagBatch = FitClass.run_AimBatch()
            interval = interval + 2
        FitClass.ProjType = tmpProjCtrl
        FitClass.IPrint = tmpIPrint
        # Print the results when all jobs are finished
        FlagBatch = FitClass.run_AimBatch()
        print_String(FitClass.IOut, 'This batch takes %i Seconds' % interval,
                     FitClass.IPrint)
    if FitClass.OptAlgo[:5] == 'batch':
        FitClass.get_OptResu(iop=1)
        print_List(FitClass.IOut,FitClass.InitGuess,\
            4,Info='Batch corresponds to these parameters ::')
        FitClass.run_Statistic()
    else:
        FitClass.get_OptResu(iop=0)
        AD, wAD, MAD, wMAD, RMS, wRMS = FitClass.run_Statistic()
        if FitClass.OptAlgo == 'leastsq':
            return array(FitClass.Result)
        elif FitClass.OptAlgo[-3:] == 'rms':
            return wRMS
        elif FitClass.OptAlgo[-3:] == 'mad':
            return wMAD
        elif FitClass.OptAlgo[-2:] == 'ad':
            return wAD
        else:
            print_Error(FitClass.IOut,
                'Error in return required type of statistic data'+\
                ' \"calc_statistic()->%s\"' % FitClass.OptAlgo)
    return
Exemplo n.º 8
0
    def __init__(self, iout, fn=None, bugctrl=0):
        '''\
        Initialize variables belonged to GauIO\
        '''
        from os import getcwd
        from os import getenv
        from os.path import isfile

        from my_io import print_Error
        from my_io import print_String

        self.IOut = iout  # Flow of the output file
        self.IPrint = bugctrl  # to control the printing out
        self.FileName = fn  # Name of the input file

        self.WorkDir = getcwd().strip()  # STRING, current DIR
        self.HomeDir = getenv('HOME')  # STRING, Home DIR
        if getenv('IGOR_MODULES_PATH'):  # STRING, private module DIR
            self.ModuDir = getenv('IGOR_MODULES_PATH')
        else:
            print_Error(self.IOut,
                'Error in getting grobal environment '+\
                '\"$IGOR_MODULES_PATH\" which is the direction to private modules')

        if self.FileName == None:
            self.f = 'None'
            if self.IPrint >= 1:
                print_String(self.IOut,
                             'Do not open input file for QChemIO class', 1)
        else:
            try:
                self.f = file(self.FileName, 'r')  # Open it
            except IOError:
                self.f = file('Error_%s' % self.FileName, 'w')
            if self.IPrint >= 1:
                print_String(
                    self.IOut, 'Open QChem-Input file "%s" for QChemIO class' %
                    self.FileName, 1)
            #
            #Generating "self.JobName" which is head of "self.FileName"
            #For example, if    self.FileName  = 'g03_1.gjf'
            #             then  self.JobName   = 'g03_1'
            TmpList = self.FileName.split('.')
            if len(TmpList) <= 2:
                self.JobName = TmpList[0]
            else:
                self.JobName = '.'.join(TmpList[0:-1])  # Name of this job
            del TmpList
            if bugctrl >= 1:
                print_String(iout, 'Enter the job : \"%s\"' % self.JobName, 2)

        self.InpuDict = {
            #              'RemList' : [],                                      # List, options for rem group
            #              'MolList' : [],                                      # List, info. for geom. group
            #              'XCFList' : [],                                      # List, options for xc_func.
            #              'OccList' : [],                                      # List, info. for occupied group
        }

        self.Charge = ''  # Input Chage
        self.Spin = ''  # Input Spin
        self.AtLabel = []  # List, Atom labels

        #       self.GeomList	= []                                         # Input Geometry
        #       self.IAn	= []                                             # List, Atom indexs
        #       self.CList	= []                                             # List, Atom coordinates
        #       self.CartesianFlag=False                                     # "True"  : Cartesian
        #       self.ZList  = []                                             # List, Atom Z-matrix
        #       self.ZListR = []                                             # List, Z-matrix parameters
        #                                                                    # "False" : Z-Matrix;
        #       self.NAtom	= 0                                              # Number of atoms
        #       self.RestList	= []                                         # Rest content after Geometry

        self.SCFReal = 0.0  # REAL, SCF energy
        self.CCSDTReal = 0.0  # REAL, CCSD(T) energy
        self.R5DFTReal = 0.0  # REAL, R5DFT energy
        self.PT21Real = 0.0  # REAL, the 1st term for PT2
        self.PT22Real = 0.0  # REAL, the 2nd term for PT2
        self.xMP2Real = 0.0  # REAL, xMP2 energy
        return
Exemplo n.º 9
0
    def get_Result(self, iop=0):
        '''Collect results'''
        from re import compile
        from os.path import isfile
        from my_io import my_plus
        from my_io import print_String
        from my_io import print_Error

        if isfile('Job_%s.log' % self.JobName):
            lf = file('Job_%s.log' % self.JobName, 'r')
            if self.IPrint >= 1:
                print_String(self.IOut, 'Now open Job_%s.log' % self.JobName,
                             1)
        else:
            print_Error(self.IOut, 'Error in finding Output file')

        if iop == 0:  # For SCF energy
            p1 = compile(
                ' *\d+ *([+-]\d*.\d*) *\d.\d+E[+-]\d\d *\d+ Convergence criterion met'
            )
            p2 = compile('Convergence failure')
            p3 = compile('Including correction')
            p4 = compile('Empirical dispersion =( *-[0-9]+.[0-9]*) hartree')
            lf.seek(0)
            TmpFile = lf.read().strip()
            if p4.search(TmpFile):
                print_String(
                    self.IOut, 'Empirical dispersion = %s hartree' %
                    (p4.search(TmpFile).group(1)), 1)
            if p3.search(TmpFile):  # Patch for dual basis scheme
                LocPos = p3.search(TmpFile).start()
                while TmpFile[LocPos - 1:LocPos] != '\n':
                    LocPos = LocPos - 1
                lf.seek(LocPos)
                TmpString = lf.readline().strip()
                TmpList = TmpString.split()
                try:
                    self.SCFReal = float(TmpList[1])
                except ValueError:
                    print_Error(self.IOut,'Error occurss '+\
                        'in getting SCF Energy')
                if self.IPrint >= 1:
                    print_String(self.IOut,'SCF Energy     = '+\
                        '%18.8f' %self.SCFReal,1)
            elif not p2.search(TmpFile) and\
                p1.search(TmpFile):                                  # Patch for dual basis guess
                LocPos = 0
                for x in p1.finditer(TmpFile):
                    tmpPos = x.start()
                    if tmpPos > LocPos:
                        LocPos = tmpPos
                        try:
                            self.SCFReal = float(x.group(1))
                        except ValueError:
                            print_Error(self.IOut,'Error occurss '+\
                                'in getting SCF Energy')
                if self.IPrint >= 1:
                    print_String(self.IOut,'SCF Energy     = '+\
                        '%18.8f' %self.SCFReal,1)
            else:
                print_String(self.IOut, 'SCF Convergence is not found', 1)
                self.SCFReal = 'NAN'

            # ----------------------------------
            # Now for post-HF or post-KS results
            # ----------------------------------
            p1 = compile('CCSD\(\w\) Total Energy   =')  # for ccsd(t) result
            p2 = compile('Total Local XYGJ-OS energy *=')  # for LXYGJOS result
            p3 = compile(' +MP2 *total energy *=')  # for     MP2 result
            p4 = compile(' +RIMP2 *total energy *= *([+-]\d+.\d+)'
                         )  # for   RIMP2 result
            p5 = compile(
                'Total *XYG3-RI *total energy *=')  # for  XYG3RI result
            p6 = compile('Total *XYGJ-OS *energy *=')  # for  XYGJOS result
            if p1.search(TmpFile):
                (Srt, End) = p1.search(TmpFile).span()
                LocPos = End
                lf.seek(LocPos)
                TmpString = lf.readline().strip()
                try:
                    self.CCSDTReal = float(TmpString)
                except ValueError:
                    print_String(self.IOut,'Error occurss '+\
                        'in getting CCSD(T) Energy',1)
                    self.CCSDTReal = 'NAN'
                if self.IPrint >= 1:
                    try:
                        print_String(self.IOut,'CCSD(T) energy = '+\
                            '%18.8f' %self.CCSDTReal,1)
                    except TypeError:
                        print_String(self.IOut,'CCSD(T) energy = '+\
                            '%18s' %self.CCSDTReal,1)
            elif p2.search(TmpFile):
                (Srt, End) = p2.search(TmpFile).span()
                LocPos = End
                lf.seek(LocPos)
                TmpString = lf.readline().strip()
                try:
                    self.R5DFTReal = float(TmpString)
                except ValueError:
                    print_String(self.IOut,'Error occurss '+\
                        'in getting LXYGJOS Energy',1)
                    self.R5DFTReal = 'NAN'
                if self.IPrint >= 1:
                    try:
                        print_String(self.IOut,'LXYGJOS energy = '+\
                            '%18.8f' %self.R5DFTReal,1)
                    except TypeError:
                        print_String(self.IOut,'LXYGJOS energy = '+\
                            '%18s' %self.R5DFTReal,1)
            elif p3.search(TmpFile):
                (Srt, End) = p3.search(TmpFile).span()
                LocPos = End
                lf.seek(LocPos)
                TmpString1 = lf.readline().strip()
                TmpString = TmpString1.split()[0]
                try:
                    self.R5DFTReal = float(TmpString)
                except ValueError:
                    print_String(self.IOut,'Error occurss '+\
                        'in getting MP2 Energy',1)
                    self.R5DFTReal = 'NAN'
                if self.IPrint >= 1:
                    try:
                        print_String(self.IOut,'MP2 Energy     = '+\
                            '%18.8f' %self.R5DFTReal,1)
                    except TypeError:
                        print_String(self.IOut,'MP2 Energy     = '+\
                            '%18s' %self.R5DFTReal,1)
            elif p4.search(TmpFile):
                try:
                    self.R5DFTReal = float(p4.search(TmpFile).group(1))
                except ValueError:
                    print_String(self.IOut, p4.search(TmpFile).group(0), 1)
                    print_String(self.IOut,'Error occurss '+\
                        'in getting RIMP2 Energy',1)
                    self.R5DFTReal = 'NAN'
                if self.IPrint >= 1:
                    try:
                        print_String(self.IOut,'RIMP2 Energy   = '+\
                            '%18.8f' %self.R5DFTReal,1)
                    except TypeError:
                        print_String(self.IOut,'RIMP2 Energy   = '+\
                            '%18s' %self.R5DFTReal,1)
            elif p5.search(TmpFile):
                (Srt, End) = p5.search(TmpFile).span()
                LocPos = End
                lf.seek(LocPos)
                TmpString = lf.readline().strip().split()[0]
                try:
                    self.R5DFTReal = float(TmpString)
                except ValueError:
                    print_String(self.IOut,'Error occurss '+\
                        'in getting LXYG3RI Energy',1)
                    self.R5DFTReal = 'NAN'
                if self.IPrint >= 1:
                    try:
                        print_String(self.IOut,'XYG3RI energy = '+\
                            '%18.8f' %self.R5DFTReal,1)
                    except TypeError:
                        print_String(self.IOut,'XYG3RI energy = '+\
                            '%18s' %self.R5DFTReal,1)
            elif p6.search(TmpFile):
                (Srt, End) = p6.search(TmpFile).span()
                LocPos = End
                lf.seek(LocPos)
                TmpString = lf.readline().strip()
                try:
                    self.R5DFTReal = float(TmpString)
                except ValueError:
                    print_String(self.IOut,'Error occurss '+\
                        'in getting XYGJOS Energy',1)
                    self.R5DFTReal = 'NAN'
                if self.IPrint >= 1:
                    try:
                        print_String(self.IOut,'XYGJOS energy = '+\
                            '%18.8f' %self.R5DFTReal,1)
                    except TypeError:
                        print_String(self.IOut,'XYGJOS energy = '+\
                            '%18s' %self.R5DFTReal,1)

        elif iop == 1:  # For PT21 term
            p1 = compile('E_DFTPT2_1ST =')
            lf.seek(0)
            TmpFile = lf.read().strip()
            if p1.search(TmpFile):
                (Srt, End) = p1.search(TmpFile).span()
                LocPos = End
                lf.seek(LocPos)
                TmpString = lf.readline().strip()
                TmpList = TmpString.split()
                try:
                    self.PT21Real = float(TmpList[0])
                except ValueError:
                    print_Error(self.IOut,'Error occurss '+\
                        'in getting 1st PT2 Energy')
                    self.PT21Real = 'NAN'
                if self.IPrint >= 1:
                    print_String(self.IOut,'1st PT2 Energy = '+\
                        '%18.8f' %self.PT21Real,1)
            else:
                print_String(self.IOut,'the 1st excitation '+\
                    'contribution for PT2 is not found',1)
                self.PT21Real = 'NAN'
        elif iop == 2:  # For PT22 term
            p1 = compile('aaaa *correlation energy = *([+-]*\d+.\d+)')
            p2 = compile('abab *correlation energy = *([+-]*\d+.\d+)')
            p3 = compile('bbbb *correlation energy = *([+-]*\d+.\d+)')
            p4 = compile('OS-MP2 correlation energy *= *([+-]*\d+.\d+)')
            lf.seek(0)
            TmpFile = lf.read().strip()
            if p4.search(TmpFile):
                try:
                    self.PT22Real = float(p4.search(TmpFile).group(1))
                    print_String(self.IOut,'OS-MP2 correlation '+\
                        'is %16.8f' %self.PT22Real,1)
                except ValueError:
                    self.PT22Real = 'NAN'
                    print_String(self.IOut,'OS-MP2 correlation '+\
                        'is %18s' %self.PT22Real,1)
            else:
                if p1.search(TmpFile):
                    try:
                        self.PT22Real = float(p1.search(TmpFile).group(1))
                        print_String(self.IOut,'aaaa correlation '+\
                            'is %16.8f' %self.PT22Real,1)
                    except ValueError:
                        print_String(self.IOut,'aaaa correlation '+\
                            'is not found',1)
                        self.PT22Real = 'NAN'
                else:
                    print_String(self.IOut,'aaaa correlation '+\
                        'is not found',1)
                    self.PT22Real = 'NAN'

                if p2.search(TmpFile):
                    try:
                        tmpValue = float(p2.search(TmpFile).group(1))
                        self.PT22Real += tmpValue
                        print_String(self.IOut,'abab correlation '+\
                            'is %16.8f' %tmpValue,1)
                    except ValueError:
                        print_String(self.IOut,'abab correlation '+\
                            'is not found',1)
                        self.PT22Real = 'NAN'
                else:
                    print_String(self.IOut,'abab correlation '+\
                        'is not found',1)
                    self.PT22Real = 'NAN'

                if p3.search(TmpFile):
                    try:
                        tmpValue = float(p3.search(TmpFile).group(1))
                        self.PT22Real += tmpValue
                        print_String(self.IOut,'bbbb correlation '+\
                            'is %16.8f' %tmpValue,1)
                        if self.IPrint >= 1:
                            print_String(self.IOut,'2nd PT2 Energy'+\
                                ' = %18.8f' %self.PT22Real,1)
                    except ValueError:
                        print_String(self.IOut,'bbbb correlation '+\
                            'is not found',1)
                        self.PT22Real = 'NAN'
                else:
                    print_String(self.IOut,'the 2nd excitation '+\
                        'contribution for PT2 is not found',1)
                    self.PT22Real = 'NAN'
                    if self.IPrint >= 1:
                        print_String(self.IOut,'2nd PT2 Energy = '+\
                            '%18s' %self.PT22Real,1)

            # Now for seperated DFT parts
            p1 = compile('exchange functionals invoked ::')
            lf.seek(0)
            TmpFile = lf.read().strip()
            if p1.search(TmpFile):
                print_String(self.IOut,'Now print information ' +\
                        'about separated Xs and Cs',1)
                (LocPos, EndPos) = p1.search(TmpFile).span()
                while TmpFile[LocPos - 1:LocPos] != '\n':
                    LocPos = LocPos - 1
                lf.seek(LocPos)
                p2 = compile('E_no_XC')
                TmpString = lf.readline()
                while not p2.search(TmpString):
                    self.IOut.write(TmpString)
                    TmpString = lf.readline()
                else:
                    self.IOut.write(TmpString)
            else:
                print_String(self.IOut,'Information about '+\
                    'separated Xs and Cs is not found',1)
        elif iop == 3:  # For xMP2 energy
            plist = [
                compile('E_no_XC      ='),
                compile('E_nBrillouin ='),
                compile('EK           ='),
                compile('aaaa *correlation energy ='),
                compile('abab *correlation energy ='),
                compile('bbbb *correlation energy =')
            ]
            lf.seek(0)
            TmpFile = lf.read().strip()
            self.xMP2Real = 0.0
            for p in plist:
                if p.search(TmpFile):
                    (Srt, End) = p.search(TmpFile).span()
                    LocPos = End
                    lf.seek(LocPos)
                    TmpString = lf.readline().strip()
                    TmpList = TmpString.split()
                    try:
                        self.xMP2Real += float(TmpList[0])
                    except ValueError:
                        print_Error(self.IOut,'Error occurss '+\
                            'in getting one portion of xMP2 Energy')
                        self.xMP2Real = 'NAN'
                        return
                else:
                    print_String(self.IOut,'one important '+\
                        'portion of xMP2 could not be found',1)
                    self.xMP2Real = 'NAN'
                    return
            if self.IPrint >= 1:
                print_String(self.IOut,'xMP2 Energy    = '+\
                    '%18.8f' %self.xMP2Real,1)
        return
Exemplo n.º 10
0
    def get_Input(self):
        '''Loading molecule group from input file'''
        from re import compile
        from my_io import print_Error
        from my_io import print_List
        from my_io import print_String
        p1 = compile('\$molecule')  # Now loading molecule group
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading molecule group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['MolList'] = []
            self.InpuDict['MolList'].append('$molecule')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            if len(TmpLine.split()) != 2:
                print_Error(self.IOut,'Error occures in loading'+\
                        ' [Charge] and [Spin]')
            else:
                try:
                    self.Charge = int(TmpLine.split()[0])
                    self.Spin = int(TmpLine.split()[1])
                except ValueError:
                    print_Error(self.IOut,'Error occures in'+\
                            ' loading [Charge] and [Spin]')
            while not p2.search(TmpLine.lower()):
                self.InpuDict['MolList'].append(TmpLine)
                if len(TmpLine.strip()) == 4:
                    elem_name = TmpLine.lower().split()[0]
                    if elem_name in QChemIO.AtDict:
                        self.AtLabel.append(elem_name)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['MolList'].append('$end')
            print(self.AtLabel)
        else:
            print_String(self.IOut, 'No molecule group in INPUT file', 1)

        p1 = compile('\$rem')  # Now loading rem group
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading rem group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['RemList'] = []
            self.InpuDict['RemList'].append('$rem')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['RemList'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['RemList'].append('$end')
        else:
            print_String(self.IOut, 'No rem group in INPUT file', 1)

        p1 = compile('\$xc_functional')  # Now loading xc_functional
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading xc_functional group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['XCFList'] = []
            self.InpuDict['XCFList'].append('$xc_functional')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['XCFList'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['XCFList'].append('$end')
        else:
            print_String(self.IOut, 'No xc_functional group in INPUT file', 1)

        p1 = compile('\$occupied')  # Now loading occupied
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading occupied group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['OccList'] = []
            self.InpuDict['OccList'].append('$occupied')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['OccList'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['OccList'].append('$end')
        else:
            print_String(self.IOut, 'No occupied group in INPUT file', 1)

        p1 = compile('\$basis')  # Now loading basis
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading basis group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['BasList'] = []
            self.InpuDict['BasList'].append('$basis')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['BasList'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['BasList'].append('$end')
        else:
            print_String(self.IOut, 'No basis group in INPUT file', 1)

        p1 = compile('\$basis2')  # Now loading basis2
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading basis group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['Bas2List'] = []
            self.InpuDict['Bas2List'].append('$basis2')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['Bas2List'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['Bas2List'].append('$end')
        else:
            print_String(self.IOut, 'No basis2 group in INPUT file', 1)

        p1 = compile('\$ecp')  # Now loading basis
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading ecp group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['ECPList'] = []
            self.InpuDict['ECPList'].append('$ecp')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['ECPList'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['ECPList'].append('$end')
        else:
            print_String(self.IOut, 'No ecp group in INPUT file', 1)

        p1 = compile('\$aux_basis')  # Now loading aux_basis
        p2 = compile('\$end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now reading aux_basis group', 1)
        self.f.seek(0)
        TmpFile = self.f.read().lower()
        if p1.search(TmpFile):
            self.InpuDict['AUXBList'] = []
            self.InpuDict['AUXBList'].append('$aux_basis')
            LocPos = p1.search(TmpFile).start()
            self.f.seek(LocPos)
            self.f.readline()
            TmpLine = self.f.readline().strip()
            while not p2.search(TmpLine.lower()):
                self.InpuDict['AUXBList'].append(TmpLine)
                TmpLine = self.f.readline().strip()
            else:
                self.InpuDict['AUXBList'].append('$end')
        else:
            print_String(self.IOut, 'No aux_basis group in INPUT file', 1)
        return
Exemplo n.º 11
0
    def __init__(self, iout, GauIO, OptClass, bugctrl=0,\
        c6para=None, c12para=None, r0para=None, dpara=None):
        '''\
        Initialize parameters\
        '''
        self.IOut       = iout                                       # Set the logout file string
        self.GauIO      = GauIO                                      # Loading GauIO class
        self.OptClass   = OptClass                                   # Loading OptHandle class
        self.DispClass  = None                                       # DispClass
 #
        self.IPrint     = bugctrl                                    # INTEGER, control debugging
        self.AtLabel    = self.GauIO.AtLabel                         # List of AtLabel
        self.CList      = self.GauIO.CList                           # List of Geom. Info.
        self.IAn        = self.GauIO.IAn                             # List of IAn
        self.Method     = ''                                         # STRING, name of DFT+D
        self.SixPara    = 1.0                                        # REAL, Parameter of disp.
 #
        self.EngyReal   = 0.0                                        # REAL, dispersion energy
        self.ForcList   = []                                         # List, dispersion force
        self.HessList   = []                                         # List, dispersion hessian
        self.TurnOn     = False                                      # LOGIC, turn on or off DFT+D
        self.PureDisp   = False                                      # LOGIC, pure disp. calc.
 #
        for option in self.GauIO.OptionList:                         # Filter DFT+D method 
            for key in sorted(DFTD.GrimDict.keys()):
                TmpList=option.strip().split('/')
                if TmpList[0].lower()==key:
                    self.TurnOn   = True
                    self.Method   = key
                    self.SixPara=DFTD.GrimDict[key][0]
                    if len(TmpList)==1:
                        self.GauIO.OptionList.append(\
                            DFTD.GrimDict[key][1])
                    elif len(TmpList)==2:
                        self.GauIO.OptionList.append(\
                            '/'.join([DFTD.GrimDict[key][1],\
                            TmpList[1]]))
                    else:
                        print_Error(self.IOut,
                            'Error happens in DFT+D method '+\
                            'determination \"DFTD.__init__\"')
                    self.GauIO.OptionList.remove(option)
                    break
        if not self.TurnOn:                                          # Filter pure disp. calc.
            for option in self.GauIO.OptionList:
                for key in sorted(DFTD.DispDict.keys()):
                    TmpList = option.strip().split('/')
                    if TmpList[0].lower()==key:
                        self.TurnOn = True
                        self.Method = key
                        self.SixPara    = DFTD.DispDict[key][0]
                        if len(TmpList)==1:
                            self.GauIO.OptionList.append(\
                                DFTD.DispDict[key][1])
                        elif len(TmpList)==2:
                            self.GauIO.OptionList.append(\
                                '/'.join([DFTD.DispDict[key][1],\
                                TmpList[1]]))
                        else:
                            print_Error(self.IOut,
                                'Error happens in Disp. method '+\
                                'determination \"DFTD.__init__\"')
                        self.GauIO.OptionList.remove(option)

        self.OptClass.OptionList    = self.GauIO.OptionList[:]       # Sync OptionList between 
                                                                     #  "OptClass" and "GauIO"
        if self.TurnOn:
            if (self.Method == 'disp_g') or\
            (self.Method == 'dispersion_g'):
                self.PureDisp   = True
                self.DispClass  =\
                    DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 0,\
                    self.IPrint,\
                    c6para, c12para, r0para, dpara)
                if self.IPrint>=1:
                    print_String(self.IOut, 'Disp_G is required',1)
                return
            if (self.Method == 'disp_6') or\
            (self.Method == 'dispersion_6'):
                self.PureDisp   = True
                self.DispClass  =\
                    DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 1,\
                    self.IPrint,\
                    c6para, c12para, r0para, dpara)
                if self.IPrint>=1:
                    print_String(self.IOut, 'Disp_6 is required',1)
                return
            if (self.Method == 'disp_12') or\
            (self.Method == 'dispersion_12'):
                self.PureDisp   = True
                self.DispClass  =\
                    DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 2,\
                    self.IPrint,\
                    c6para, c12para, r0para, dpara)
                if self.IPrint>=1:
                    print_String(self.IOut, 'Disp_12 is required',1)
                return
            if (self.Method == 'disp') or\
            (self.Method == 'dispersion'):
                self.PureDisp   = True
                self.DispClass       =\
                    DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 3,\
                    self.IPrint,\
                    c6para, c12para, r0para, dpara)
                if self.IPrint>=1:
                    print_String(self.IOut,'Disp. is required',1)
                return
            if (self.Method == 'disp_12s') or\
            (self.Method == 'dispersion_12s'):
                self.PureDisp   = True
                self.DispClass       =\
                    DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 4,\
                    self.IPrint,\
                    c6para, c12para, r0para, dpara)
                if self.IPrint>=1:
                    print_String(self.IOut,'Disp_12s is required',1)
                return

            for option in self.OptClass.OptionList:
                TmpList=option.strip().split('/')
                if TmpList[0].lower()==self.Method:
                    if len(TmpList)==1:
                        self.OptClass.OptionList.append(\
                            DFTD.GrimDict[self.Method][1])
                    elif len(TmpList)==2:
                        self.OptClass.OptionList.append(\
                            DFTD.GrimDict[self.Method][1])
                        self.OptClass.OptionList.append(\
                            TmpList[1])
                    self.OptClass.OptionList.remove(option)
                    break
            self.DispClass       =\
                DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 0,\
                self.IPrint)
            if self.IPrint>=1:
                print_String(self.IOut,
                    '%s is employed with s_6 = %3.2f'
                    % (self.Method.upper(),self.SixPara),2)
        else:
            self.DispClass       =\
                DispGrim(self.IOut, GauIO.CList, GauIO.IAn, 0,\
                self.IPrint)
            if self.IPrint>=2:
                print_String(self.IOut,
                    'None DFT+D scheme is required',1)
        return