Esempio n. 1
0
 def run_Job(self):
     '''run CP2K job through a specified csh named "CP2K_Environment"'''
     from os import system
     from os import mkdir
     from os import removedirs
     from os import remove
     from os import chdir
     from os.path import exists
     from os.path import isfile
     from os import getpid  # To make more then 2 jobs
     # running in one DIR
     from my_io import print_String
     CurrScr = './.script%s' % getpid()
     print 'Script is %s' % CurrScr
     if not exists('%s' % CurrScr):
         mkdir('%s' % CurrScr)
     system('mv Job_%s.inp %s/Job_%s.inp' %
            (self.JobName, CurrScr, self.JobName))
     chdir('%s' % CurrScr)
     if self.IPrint >= 1:
         print_String(self.IOut,'Now run the job of '+\
                 'Job_%s.inp ' %self.JobName +\
                 'in %s' %CurrScr,1)
     system('%s/CP2K_Environment Job_%s.inp ../../mpd.hosts' %
            (self.ModuDir, self.JobName))
     system('mv Job_%s.log ../Job_%s.log' % (self.JobName, self.JobName))
     chdir('../')
     #if self.IPrint<=1:
     #    remove('%s/Job_%s.in' % (CurrScr, self.JobName))
     #    removedirs('%s' %CurrScr)
     return
Esempio n. 2
0
    def form_Input(self):
        '''Form CP2K input file for given statements'''
        import re
        from copy import deepcopy
        from my_io import print_String
        from my_io import print_List
        #
        # Now parse and generate the input file by self.InpuDict
        #
        indent = '  '
        if self.IPrint >= 1:
            print_String(self.IOut,'Now generating CP2K input file' +\
                    ' for the job of %s' %self.JobName,1)
        wf = file('Job_%s.inp' % self.JobName, 'w')

        maxIndex = 1

        for x in sorted(self.InpuDict):
            if len(self.InpuDict[x]['index']) > maxIndex:
                maxIndex = len(self.InpuDict[x]['index'])

        tmpInput = ''
        for indx in range(maxIndex):
            for x in sorted(self.InpuDict):
                if len(self.InpuDict[x]['index']) == indx + 1:
                    if indx == 0:
                        tmpInput += indent * indx + '&%s' % x.upper(
                        ) + ' %s\n' % self.InpuDict[x]['rest']
                        for line in self.InpuDict[x]['content']:
                            tmpInput += indent * (indx + 1) + '%s\n' % line
                        tmpInput += indent * indx + '&END %s\n' % x.upper()
                        tmpInput += '\n'
                    else:
                        tmpString = ''
                        tmpString += indent * indx + '&%s' % x.upper(
                        ) + ' %s\n' % self.InpuDict[x]['rest']
                        for line in self.InpuDict[x]['content']:
                            tmpString += indent * (indx + 1) + '%s\n' % line
                        if x.split()[0] != 'kind':
                            tmpString += indent * indx + '&END %s\n' % x.upper(
                            )
                        else:
                            tmpString += indent * indx + '&END %s\n' % x.upper(
                            ).split()[0]

                        tmpFlag = indent * (
                            indx - 1
                        ) + '&END %s' % self.InpuDict[x]['index'][-2].upper()
                        p1 = re.compile(tmpFlag)
                        StartPos = p1.search(tmpInput).start()
                        tmpInput = tmpInput[:StartPos] + tmpString + tmpInput[
                            StartPos:]

        wf.write(tmpInput)
        wf.close()
        return
Esempio n. 3
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
Esempio n. 4
0
 def __del__(self):
     '''Close the document flow of input file'''
     from my_io import print_String
     if self.f == 'None':
         if self.IPrint >= 2:
             print_String(self.IOut,
                          'Do not close input file for CK2KIO class', 1)
     else:
         if self.IPrint >= 2:
             print_String(
                 self.IOut, 'Close CP2K-Input file "%s" for CP2KIO class' %
                 self.FileName, 1)
         self.f.close()  # Close input file
     return
Esempio n. 5
0
 def form_Input(self):
     '''Form qchem input file for given statements'''
     from my_io import print_String
     from my_io import print_List
     #
     # Now creat a new qchem input file
     #
     if self.IPrint >= 1:
         print_String(self.IOut,'Now generating input file' +\
                 ' for the job of %s' %self.JobName,1)
     wf = file('Job_%s.in' % self.JobName, 'w')
     for x in self.InpuDict.keys():
         for line in self.InpuDict[x]:
             wf.write('%s\n' % line)
         wf.write(' \n')
     wf.close()
     return
Esempio n. 6
0
 def run_Job(self, iop=0, cfg=None):
     '''run qchem job through a specified csh named "QChem_Environment"'''
     from os import system
     from os import mkdir
     from os import removedirs
     from os import remove
     from os import chdir
     from os.path import exists
     from os.path import isfile
     from os import getpid  # To make more then 2 jobs
     # running in one DIR
     from my_io import print_String
     CurrScr = './.script%s' % getpid()
     if cfg == None:
         cfg = 'rmp2'
     print('Script is %s' % CurrScr)
     if not exists('%s' % CurrScr):
         mkdir('%s' % CurrScr)
     system('mv Job_%s.in %s/Job_%s.in' %
            (self.JobName, CurrScr, self.JobName))
     chdir('%s' % CurrScr)
     if self.IPrint >= 1:
         print_String(self.IOut,'Now run the job of '+\
                 'Job_%s.in ' %self.JobName +\
                 'in %s' %CurrScr,1)
     if iop == 0:  # serial version qchem
         system('%s/QChem_Environment.ser %s Job_%s.in' %
                (self.ModuDir, cfg, self.JobName))
     elif iop == 1:  # parallel version qchem
         system('%s/QChem_Environment.par %s Job_%s.in' %
                (self.ModuDir, cfg, self.JobName))
     system('mv Job_%s.log ../Job_%s.log' % (self.JobName, self.JobName))
     chdir('../')
     #if self.IPrint<=1:
     #    remove('%s/Job_%s.in' % (CurrScr, self.JobName))
     #    removedirs('%s' %CurrScr)
     return
Esempio n. 7
0
    def get_Input(self):
        '''Loading input dictionary 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('^&')
        p2 = compile('^&end')
        if self.IPrint >= 1:
            print_String(self.IOut, 'Now parsing CP2K input file', 1)
        self.f.seek(0L)
        Lines = self.f.readlines()
        BlockList = []
        for tmpline in Lines:
            if p1.search(tmpline.strip().lower()):
                if p2.search(tmpline.strip().lower()):
                    BlockList = BlockList[:-1]
                else:
                    tmpList = tmpline.lower().strip().split('&')[1].split()
                    tmpFlag = tmpList[0]
                    if tmpFlag == 'kind':
                        tmpFlag = ' '.join(tmpList[:2])
                        tmpList = tmpList[1:]
                    BlockList.append(tmpFlag)
                    self.InpuDict[tmpFlag] = dict(index=BlockList[:],
                                                  content=[],
                                                  rest='')
                    if tmpList > 1:
                        self.InpuDict[tmpFlag]['rest'] = ' '.join(tmpList[1:])

            else:
                if len(BlockList) >= 1:
                    self.InpuDict[BlockList[-1]]['content'].append(
                        tmpline.strip())
                else:
                    pass
        return
Esempio 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 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
Esempio n. 9
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
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
0
    def get_ForcList(self):
        '''\
        Calculate the corresponding force for DFT+D methods\n\
        Contribution of atom j in atom i is :\n\
        Fij_x	= - Scal * (6.0 * (X_i-X_j) ) /|r_i-r_j|^(-8)\n\
        Fij_y	= - Scal * (6.0 * (Y_i-Y_j) ) /|r_i-r_j|^(-8)\n\
        Fij_z	= - Scal * (6.0 * (Z_i-Z_j) ) /|r_i-r_j|^(-8)\
        '''
        from math import sqrt

        from my_io import print_List
        from my_io import print_String
        Scal		= -1.0 * DFTD.FauCon * self.SixPara
        self.ForcList	= []
        if self.IPrint>=2:
            print_String(self.IOut, 
            '%10s%10s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s'
            %('Atom1','Atom2','Rij','Rr','Cij','Damp',
            'Fx_Disp','Fx_FDamp','Fy_Disp','Fy_FDamp',
            'Fz_Disp','Fz_FDamp'),2)
        if self.GauIO.NAtom==1:
            NTT             = self.GauIO.NAtom*3
            self.ForcList   = [0.0]*NTT
            if self.IPrint>=2:
                print_List(self.IOut,self.ForcList,4,
                    'CM Dispersion Cartesian Gradient:')
            return
        for i in range(self.GauIO.NAtom):
            TmpForceX	= 0.0
            TmpForceY	= 0.0
            TmpForceZ	= 0.0
            for j in range(self.GauIO.NAtom):
                if j!=i:
                    Rij	= get_Dist(self.CList[i],self.CList[j])
                    Rr	= DFTD.R0Para[self.IAn[i]]+\
                          DFTD.R0Para[self.IAn[j]]
                    Cijg= DFTD.C6Para[self.IAn[i]]*\
                          DFTD.C6Para[self.IAn[j]]
                    Cij	= sqrt(Cijg)
                    Damp= get_Damp(self.d,Rij,Rr)
                    XTerm1, YTerm1, ZTerm1	=\
                        get_Force(self.CList[i],self.CList[j],Rij)
                    XTerm	= XTerm1 * Damp
                    YTerm	= YTerm1 * Damp
                    ZTerm	= ZTerm1 * Damp
                    XTerm2, YTerm2, ZTerm2	=\
                        get_DampD(self.CList[i],self.CList[j],\
                        self.d,Rij,Rr)
                    XTermD	= XTerm2 * pow(Rij,-6)
                    YTermD	= YTerm2 * pow(Rij,-6)
                    ZTermD	= ZTerm2 * pow(Rij,-6)

                    TmpForceX		+= XTerm * Cij 
                    TmpForceY 		+= YTerm * Cij 
                    TmpForceZ 		+= ZTerm * Cij 

                    TmpForceX		+= XTermD * Cij 
                    TmpForceY 		+= YTermD * Cij 
                    TmpForceZ 		+= ZTermD * Cij 
                    if self.IPrint>=2:
                        self.IOut.write(\
 '%7s%3dth%5s%3dth%8.4f%8.4f%8.4f%8.4f%8.4f%8.4f%8.4f%8.4f%8.4f%8.4f\n' \
 %(self.AtLabel[i],i+1,self.AtLabel[j],j+1,\
 Rij,Rr,Cij,Damp,XTerm,XTermD,YTerm,YTermD,ZTerm,ZTermD))

            TmpForceX   = Scal * TmpForceX
            TmpForceY   = Scal * TmpForceY
            TmpForceZ   = Scal * TmpForceZ
            self.ForcList.append(TmpForceX)
            self.ForcList.append(TmpForceY)
            self.ForcList.append(TmpForceZ)
        if self.IPrint>=2:
            print_List(self.IOut,self.ForcList,4,
                'CM Dispersion Cartesian Gradient:')
        return
Esempio n. 13
0
    def reform_Geom(self):
        '''reform molecular geometry, and calculate\
           the minimum cubic size of this molecules'''
        from my_io import print_String
        from copy import deepcopy
        mingeom = [0.0, 0.0, 0.0]
        maxgeom = [0.0, 0.0, 0.0]
        minbox = [0.0, 0.0, 0.0]
        adpbox = [0.0, 0.0, 0.0]
        shiftbox = [0.0, 0.0, 0.0]
        tmpList = [[], [], []]
        for xx in self.InpuDict['coord']['content']:
            xxx = xx.strip().split()
            try:
                tmpxxx = [xxx[0], float(xxx[1]), float(xxx[2]), float(xxx[3])]
                tmpList[0].append(tmpxxx[1])
                tmpList[1].append(tmpxxx[2])
                tmpList[2].append(tmpxxx[3])
            except ValueError:
                pass
        for tmpindex in [0, 1, 2]:
            mingeom[tmpindex] = min(tmpList[tmpindex])
            maxgeom[tmpindex] = max(tmpList[tmpindex])
            minbox[tmpindex] = maxgeom[tmpindex] - mingeom[tmpindex]
            adpbox[tmpindex] = minbox[tmpindex]

        print_String(self.IOut,
            'The min box size is (ABC%16.8f%16.8f%16.8f)'\
            % tuple(minbox), 1)

        for tmpindex in [0, 1, 2]:  # increase the box size for practicle
            if adpbox[tmpindex] < 10.0:
                adpbox[tmpindex] += 5.0
            adpbox[tmpindex] *= 2.0

        for x in self.InpuDict['poisson']['content']:
            xlist = x.strip().lower().split()
            print xlist
            if xlist[0] == 'psolver' and xlist[
                    1] == 'mt':  # reform box size for MT
                for tmpindex in [0, 1, 2]:
                    shiftbox[tmpindex]=mingeom[tmpindex]-\
                        (adpbox[tmpindex]-minbox[tmpindex])/2                  # get the shift number
                tmpList = []
                for xx in self.InpuDict['coord']['content']:  # shift geometry
                    xxx = xx.strip().split()
                    try:
                        tmpxxx =[xxx[0],float(xxx[1])-shiftbox[0],\
                            float(xxx[2])-shiftbox[1],float(xxx[3])-shiftbox[2]]
                        tmpString = '%5s%16.8f%16.8f%16.8f' % tuple(tmpxxx)
                        tmpList.append(tmpString)
                    except ValueError:
                        pass
                self.InpuDict['coord']['content'] = tmpList[:]
                print_String(self.IOut,
                    'Recommaned ABC(MT) is (ABC%16.8f%16.8f%16.8f)'\
                    % tuple(adpbox), 1)
                for cellstr in self.InpuDict['cell'][
                        'content']:  # update the box size
                    celllist = cellstr.strip().lower().split()
                    if celllist[0] == 'abc':
                        self.InpuDict['cell']['content'].remove(cellstr)
                self.InpuDict['cell']['content'].append(\
                    'ABC%16.8f%16.8f%16.8f'\
                    % tuple(adpbox))
                print self.InpuDict['cell']['content']
        return
Esempio n. 14
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
Esempio n. 15
0
 def get_EngyReal(self):
     '''\
     Calculate the dispersion energy\
     '''
     from my_io import print_String
     from my_io import print_List
     from my_io import print_List_free
     from math  import sqrt
     if len(self.IAn)==1:
         self.EngyReal   = 0.0
         print_String(self.IOut,'E(%s)%s= %16.8f A.U. '
             %('Disp',' '*5,self.EngyReal),2)
         return self.EngyReal
     if self.ICtrl==0:                                            # for six-order damped disp.
         self.EngyReal   = 0.0
         ResuList    =[\
             ['Atom1','Atom2','Rij','Rr','Cij','Damp','Disp_G']\
             ]
         Scal    = -1.0 * DispGrim.Eau6Con
         for i in range(len(self.IAn)):
             for j in range(i):
                 Rij	= self.get_Dist(self.CList[i],self.CList[j])
                 Rr  = self.R0Para[self.IAn[i]]+\
                     self.R0Para[self.IAn[j]]
                 Cij = sqrt(self.C6Para[self.IAn[i]]*\
                     self.C6Para[self.IAn[j]])
                 Dmp = self.get_Damp(self.DPara,Rij,Rr)
                 Eny = Scal * Dmp * Cij * pow(Rij,-6)
                 self.EngyReal = self.EngyReal + Eny
                 ResuList.append(\
                     [self.IAn[i],i+1,self.IAn[j],j+1,\
                     Rij,Rr,Cij,Dmp,Eny])
         self.EngyReal	= self.EngyReal
         if self.IPrint>=2:
             FormList    = [\
                     '%4d%4dth%4d%4dth%8.4f%8.4f%8.4f%8.4f%8.4f',
                     '%10s%10s%8s%8s%8s%8s%8s']
             print_List_free(self.IOut,ResuList,2,FormList,
                 'Grimme\'s six-order damped dispersion')
         print_String(self.IOut,'E(%s)%s= %16.8f A.U. '
             %('Disp_G',' '*3,self.EngyReal),2)
     elif self.ICtrl==1:                                          # for pure six-order disp.
         self.EngyReal   = 0.0
         ResuList    =[\
             ['Atom1','Atom2','Rij','Cij','Disp_6']\
             ]
         Scal    = -1.0 * DispGrim.Eau6Con
         for i in range(len(self.IAn)):
             for j in range(i):
                 Rij	= self.get_Dist(self.CList[i],self.CList[j])
                 Cij = sqrt(self.C6Para[self.IAn[i]]*\
                     self.C6Para[self.IAn[j]])
                 Eny = Scal * Cij * pow(Rij,-6)
                 self.EngyReal = self.EngyReal + Eny
                 ResuList.append(\
                     [self.IAn[i],i+1,self.IAn[j],j+1,\
                     Rij,Cij,Eny])
         self.EngyReal	= self.EngyReal
         if self.IPrint>=2:
             FormList    = ['%4d%4dth%4d%4dth%16.8f%16.8f%16.8f',
                     '%10s%10s%16s%16s%16s']
             print_List_free(self.IOut,ResuList,2,FormList,
                 'Pure six-order dispersion')
         print_String(self.IOut,'E(%s)%s= %16.8f A.U. '
             %('Disp_6',' '*3,self.EngyReal),2)
     elif self.ICtrl==2:                                          # for pure twelve-order disp.
         self.EngyReal   = 0.0
         ResuList    =[\
             ['Atom1','Atom2','Rij','C12ij','Disp_12']\
             ]
         Scal    = self.Eau12Con
         for i in range(len(self.IAn)):
             for j in range(i):
                 Rij	= self.get_Dist(self.CList[i],self.CList[j])
                 Cij = sqrt(self.C12Para[self.IAn[i]]*\
                     self.C12Para[self.IAn[j]])
                 Eny = Scal * Cij * pow(Rij,-12)
                 self.EngyReal = self.EngyReal + Eny
                 ResuList.append(\
                     [self.IAn[i],i+1,self.IAn[j],j+1,\
                     Rij,Cij,Eny])
         self.EngyReal	= self.EngyReal
         if self.IPrint>=2:
             print_String(self.IOut,'Scal is %16.8f' %Scal ,2)
             FormList    = ['%4d%4dth%4d%4dth%16.8f%16.8f%16.8f',
                     '%10s%10s%16s%16s%16s']
             print_List_free(self.IOut,ResuList,2,FormList,
                 'Pure twelve-order dispersion')
         print_String(self.IOut,'E(%s)%s= %16.8f A.U. '
             %('Disp_12',' '*2,self.EngyReal),2)
     elif self.ICtrl==3:                                          # for 6 + 12 disp.
         self.EngyReal   = 0.0
         ResuList    =[\
             ['Atom1','Atom2','Rij','Cij','Disp.']\
             ]
         ScalSix     = -1.0 * DispGrim.Eau6Con
         ScalTwel    = DispGrim.Eau12Con
         for i in range(len(self.IAn)):
             for j in range(i):
                 Rij	= self.get_Dist(self.CList[i],self.CList[j])
                 C6ij    = sqrt(self.C6Para[self.IAn[i]]*\
                     self.C6Para[self.IAn[j]])
                 C12ij   = sqrt(self.C12Para[self.IAn[i]]*\
                     self.C12Para[self.IAn[j]])
                 Eny = ScalSix * C6ij * pow(Rij,-6) + \
                     ScalTwel * C12ij * pow(Rij,-12)
                 self.EngyReal = self.EngyReal + Eny
                 ResuList.append(\
                     [self.IAn[i],i+1,self.IAn[j],j+1,\
                     Rij,C6ij,C12ij,Eny])
         if self.IPrint>=2:
             FormList    = ['%4d%4dth%4d%4dth%8.4f%8.4f%8.4f%8.4f',
                     '%10s%10s%8s%8s%8s%8s']
             print_List_free(self.IOut,ResuList,2,FormList,
                 '6+12-order dispersion')
         print_String(self.IOut,'E(%s)%s= %16.8f A.U. '
             %('Disp',' '*5,self.EngyReal),2)
     elif self.ICtrl==4:                                          # for damped 12 Disp.
         self.EngyReal   = 0.0
         ResuList    =[\
             ['Atom1','Atom2','Rij','Rr','Cij','Damp','Disp_12s']\
             ]
         Scal    = -1.0 * DispGrim.Eau12Con
         for i in range(len(self.IAn)):
             for j in range(i):
                 Rij	= self.get_Dist(self.CList[i],self.CList[j])
                 Rr  = self.R0Para[self.IAn[i]]+\
                     self.R0Para[self.IAn[j]]
                 Cij = sqrt(self.C12Para[self.IAn[i]]*\
                     self.C12Para[self.IAn[j]])
                 Dmp = self.get_Damp(self.DPara/2,Rij,Rr)
                 Eny = Dmp * Cij * pow(Rij,-12.0)
                 self.EngyReal = self.EngyReal + Eny
                 ResuList.append(\
                     [self.IAn[i],i+1,self.IAn[j],j+1,\
                     Rij,Rr,Cij,Dmp,Eny])
         self.EngyReal	= Scal * self.EngyReal
         print_String(self.IOut,'E(%s)%s= %16.8f A.U. '
             %('Disp_12s',' '*1,self.EngyReal),2)
     return self.EngyReal
Esempio n. 16
0
def main(argv=None):
    from os import getcwd
    from os import getenv
    from os import chdir
    from os.path import isfile
    from os.path import split
    from os.path import splitext
    from time import ctime
    from time import time
    import sys
    if argv is None: argv = sys.argv
    WorkDir = getcwd().strip()  # STRING, current DIR
    HomeDir = getenv('HOME')  # STRING, Home DIR
    if getenv('IGOR_MODULES_PATH'):  # STRING, private module DIR
        ModuDir = getenv('IGOR_MODULES_PATH')
        sys.path.append(ModuDir)  # Append it into "sys.path"
        sys.path.append(WorkDir)  # Append it into "sys.path"
    else:
        print 'Error in getting grobal environment '+\
            '\"$IGOR_MODULES_PATH\" which is the ' +\
            'direction to private modules'
        sys.exit(1)
    from my_io import print_Error  # Import private modules
    from my_io import print_List
    from my_io import print_String
    from my_io import ConfigIO

    filename = argv[1]
    WorkPath, JobName = split(filename)
    Name, Prefix = splitext(JobName)
    if len(WorkPath) > 0:
        chdir(WorkPath)
    iout = file('%s.Fit' % Name, 'w')  # Open the output file

    print_String(iout, 'Fitting start from ' + ctime(),
                 1)  # Count time consuming
    TimeStart = time()

    MainFit = ConfigIO(iout, fn=filename,
                       bugctrl=iprint)  # Analysis config file
    MainFit.get_ProjEnvr()
    MainFit.get_Batch()
    MainFit.get_TrainSet()
    MainFit.get_OptJob()
    if MainFit.OptJob == 'xyg3':  # XYG3-like optimization job
        MainFit.get_OptInit()
        MainFit.get_OptAlgo()
        MainFit.get_OptComp()
        MainFit.get_OptFunc()

        run_optimization(MainFit)  #  Run optimization based on MainFit

    elif MainFit.OptJob.lower() == 'xmp2':  # extend MP2 optimization job
        if MainFit.ProjTool != 'qchem':
            print_String(iout,'At present, the optimization for'+\
                'could only be combined with Q-Chem package',1)
            return
        MainFit.get_QcmIOCmd()
        MainFit.get_OptInit()
        MainFit.get_OptAlgo()
        MainFit.get_OptFunc()

        run_optimization(MainFit)  #  Run optimization based on MainFit

    elif MainFit.OptJob.lower() == 'scpt2' or\
            MainFit.OptJob.lower() == 'scsrpa':
        if MainFit.ProjTool != 'aims':
            print_String(iout,'At present, the optimization for'+\
                'could only be combined with FHI-aims package',1)
            return
        MainFit.get_AimIOCmd()
        MainFit.get_OptInit()
        MainFit.get_OptAlgo()
        MainFit.get_OptFunc()

        run_optimization(MainFit)  #  Run optimization based on MainFit

    if MainFit.OptAlgo != 'batch':
        MainFit.OptAlgo = 'batch'
        run_optimization(MainFit)  # Print details for final one

    TimeEnd = time() - TimeStart  # Count time consuming
    print_String(iout, 'Total job time: %10.2f(wall)' % TimeEnd, 1)
    print_String(iout, 'Fitting end at ' + ctime(), 1)
    print_List(iout, __info__, 2,
               '%s' % '-' * 76 + '==')  # Print Authors Info.

    iout.close()
    return
Esempio n. 17
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