Example #1
0
def gms(path, File, template, sysData, jobTemp):

    import re
    from supercomp import host
    from templates import gms_rjnJob
    from templates import gms_mgsJob
    from templates import gms_gaiJob
    from templates import gms_masJob
    from templates import gms_monJob
    from templates import gms_stmJob
    from write import write_gmsInp
    from write import write_job

    name = File.replace('.xyz', '').split('_')[0]

    # MAKE NEW DIR AND NEW PATH
    npath = newDir(path, File, template)

    # UNPACK sysData
    fragList, atmList, totChrg, totMult = sysData

    # CREATE xyzData
    xyzData = []
    for frag in fragList:
        for atm in atmList:
            if atm['id'] in frag['ids']:
                xyzData.append(
                    [atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])

    # GET TEMPLATE LINES WITH COORDS
    input = xyzTemp(path, template, xyzData)

    # CHARGE AND MULT
    for ind in range(len(input)):
        if 'ICHARG' in input[ind]:
            if totChrg == '?':
                print("Cannot determine chrg/mult, using template values")
            else:
                spl_line = re.split('=| ', input[ind])
                for val, bit in enumerate(spl_line):
                    if bit == 'ICHARG':
                        oldChrg = spl_line[val + 1]
                input[ind] = input[ind].replace('ICHARG=' + \
                oldChrg, 'ICHARG=' + str(totChrg))

        if totMult != 0:
            if 'CONTRL' in input[ind]:
                if totChrg == '?':
                    print("Cannot determine chrg/mult, using template values")
                elif not 'MULT' in input[ind]:
                    input[ind] = input[ind].\
                    replace(' RUN',' MULT=' + str(totMult) + ' RUN')

        # MEMORY USED IN INPUT
        if 'MWORDS' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'MWORDS' in input[ind]:
                    memory = spl_line[val + 1]

        # MEMORY USED IN INPUT
        ddi = False
        if 'MEMDDI' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'MEMDDI' in input[ind]:
                    ddi = spl_line[val + 1]

    # WRITE INP
    write_gmsInp(npath, name, input)

    # WRITE JOB
    lines = False
    if jobTemp:
        lines = job_replace(name, jobTemp)
    else:
        hw = host()
        if hw == 'rjn':
            lines = gms_rjnJob(name)
        elif hw == 'mgs':
            lines = gms_mgsJob(name)
        elif hw == 'gai':
            lines = gms_gaiJob(name)
        elif hw == 'mas':
            lines = gms_masJob(name)
        elif hw == 'mon':
            lines = gms_monJob(name)
        elif hw == 'stm':
            lines = gms_stmJob(name)

    if lines:
        write_job(npath, name, lines)
Example #2
0
def fmo(path, File, template, sysData, jobTemp):

    import os, re
    from supercomp import host
    from chemData import pTable
    from templates import fmo_rjnJob
    from templates import fmo_mgsJob
    from templates import fmo_stmJob
    from templates import fmo_gaiJob
    from templates import fmo_monJob
    from templates import fmo_masJob
    from templates import gms_rjnJob
    from templates import gms_mgsJob
    from templates import gms_masJob
    from templates import gms_monJob
    from templates import gms_gaiJob
    from templates import gms_stmJob
    from tempInp import fmo_ions
    from write import write_xyz
    from write import write_gmsInp
    from write import write_job

    # NAME FOR WRITING FILE, DIRS
    ions = False
    name = File.replace('.xyz', '').split('_')[0]

    # MAKE NEW DIR AND NEW PATH
    npath = newDir(path, File, template)

    # UNPACK sysData
    mp2 = False
    fragList, atmList, totChrg, totMult = sysData

    # NUMBER OF FRAGS
    nfrags = len(fragList)

    # CREATE xyzData
    xyzData = []
    for frag in fragList:
        for atm in atmList:
            if atm['id'] in frag['ids']:
                xyzData.append(
                    [atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])

    # TEMPLATE LINES
    input = xyzTemp(path, template, xyzData)
    fmo_input = []

    # IF RUNTYP IS ENERGY MAKE ION JOBS
    for ind in range(len(input)):
        if 'NGROUP' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'NGROUP':
                    in_grp = spl_line[val + 1]
                    if in_grp != str(nfrags):
                        #print('Changing NGROUP to', nfrags)
                        input[ind] = input[ind].\
                        replace('NGROUP=' + in_grp, 'NGROUP=' + str(nfrags))

        # CHECK NFRAG = NO. OF FOUND FRAGMENTS
        if 'NFRAG' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'NFRAG':
                    in_nfrags = spl_line[val + 1]
                    if in_nfrags != str(nfrags):
                        #print('Changing NFRAG  to', nfrags)
                        input[ind] = input[ind].\
                        replace('NFRAG=' + in_nfrags, 'NFRAG=' + str(nfrags))

        # LIST OF CHARGES FOR FRAGMENTS
        if 'ICHARG' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if 'ICHARG' in bit:
                    in_chrg = spl_line[val + 1]
                    chrgs = []
                    for frag in fragList:
                        chrgs.append(frag['chrg'])
                    input[ind] = input[ind].replace('ICHARG(1)=' + in_chrg, \
                            'ICHARG(1)=' + ','.join(str(p) for p in chrgs) + '\n')

        # MULT
        if 'MULT' in input[ind]:
            spl_line = re.split('=', input[ind])
            for val, bit in enumerate(spl_line):
                if 'MULT' in bit:
                    mults = []
                    for frag in fragList:
                        mults.append(frag['mult'])
                    in_chrg = spl_line[val + 1]
                    input[ind] = input[ind].replace('MULT(1)=' + in_chrg,\
                    'MULT(1)=' + ','.join(str(p) for p in mults) + '\n')

        # CHECK IF SPEC FOR ION CALCS
        if 'RUNTYP' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if 'RUNTYP' in bit:
                    if spl_line[val + 1] == 'ENERGY':
                        ions = True

        # MEMORY USED IN INPUT USED FOR JOB MEMORY
        if 'MWORDS' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'MWORDS' in input[ind]:
                    memory = spl_line[val + 1]

        # MEMORY USED IN INPUT FOR JOB MEMORY
        ddi = False
        if 'MEMDDI' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'MEMDDI' in input[ind]:
                    ddi = spl_line[val + 1]

        # FOR FMO_IONS
        if '$MP2' in input[ind]:
            mp2 = input[ind]

        if "GBASIS" in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'GBASIS' in input[ind]:
                    bset = spl_line[val + 1]

    # REMOVE LINES FROM INPUT WITH NEW LIST
    # FOR MANY LINE CHANGES - COORDS, INDAT, ATM LIST
    atmUniq = []
    numUniq = []
    seenA = False
    for line in input:
        if type(line) != list:
            # INDAT MAY BE DIFF NUMBER OF LINES TO NEW INDAT
            if 'INDAT' in line:
                fmo_input.append('    INDAT(1)=0,1,-' +
                                 str(len(fragList[0]['ids'])) + ',\n')
                # REMEMBER WHERE LAST FRAG FINISHED
                n = len(fragList[0]['ids']) + 1
                for frag in fragList:
                    if not frag is fragList[0]:
                        fmo_input.append(' '*13 + '0,' + str(n) + \
                                ',-' + str(n + len(frag['ids']) - 1) + ',\n')
                        n += len(frag['ids'])
                fmo_input.append(' ' * 13 + '0\n')

            # SO NOT PASSED TO ELSE // EXTRA LINES TO DETERMINE FRAGMENT
            elif re.search('^\s*0,[0-9]{1,3},-[0-9]{1,3},\s*$', line) or \
                      re.search('^\s*0\s*$', line):
                pass

            # ATOM LIST MAY BE DIFF NUMBER OF LINES TO NEW ATOM LIST
            elif re.search('^\s*[A-Za-z]*\s*[0-9]*\.0*$', line):
                if not seenA:
                    for i in xyzData:
                        atmUniq.append(i[0])
                        numUniq.append(i[1])
                    atmUniq = list(set(atmUniq))
                    for i in range(len(atmUniq)):
                        for sym, data in pTable.items():
                            if sym == atmUniq[i]:
                                fmo_input.append(' ' + str(atmUniq[i]) + ' ' + \
                                str(data[0]) + '\n')
                    seenA = True

            # EVERY OTHER LINE AS IS
            else:
                fmo_input.append(line)
        else:
            fmo_input.append(line)

    # HARDWARE FOR WRITING
    hw = host()
    if ions:
        # FOR EACH FRAGMENT
        for frag in fragList:
            ifrag = []
            for ID in frag['ids']:
                atm = atmList[ID]
                ifrag.append(
                    [atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])

            # MAKE FOLDER AND XYZ
            if not os.path.isdir(npath + name + '-' + frag["name"]):
                os.mkdir(npath + name + '-' + frag["name"])
            write_xyz(npath + name + '-' + frag["name"] + '/',
                      name + '-' + frag["name"], ifrag)

            # INPUT AND OUTPUT FOR JOB
            input = fmo_ions(str(frag['chrg']), ifrag, bset, mp2)
            write_gmsInp(npath + name + '-' + frag["name"] + '/',
                         name + '-' + frag["name"], input)

            # WRITE JOB
            lines = False

            if jobTemp:
                # lines = job_replace(name, jobTemp)
                lines = job_replace(name + '-' + frag["name"], jobTemp)
            else:
                if hw == 'rjn':
                    lines = gms_rjnJob(name + '-' + frag["name"])
                elif hw == 'mgs':
                    lines = gms_mgsJob(name + '-' + frag["name"])
                elif hw == 'gai':
                    lines = gms_gaiJob(name + '-' + frag["name"])
                elif hw == 'mas':
                    lines = gms_masJob(name + '-' + frag["name"])
                elif hw == 'mon':
                    lines = gms_monJob(name + '-' + frag["name"])
                elif hw == 'stm':
                    lines = gms_stmJob(name + '-' + frag["name"])

            if lines:
                write_job(npath + name + '-' + frag["name"] + '/',
                          name + '-' + frag["name"], lines)

    # -------------------------------------------------

    # WRITE INP
    write_gmsInp(npath, name, fmo_input)

    # WRITE JOB
    lines = False

    if jobTemp:
        lines = job_replace(name, jobTemp)
    else:
        if hw == 'rjn':
            lines = fmo_rjnJob(name, nfrags, memory, ddi)
        elif hw == 'mgs':
            lines = fmo_mgsJob(name, nfrags, memory, ddi)
        elif hw == 'stm':
            lines = fmo_stmJob(name, nfrags, memory, ddi)
        elif hw == 'gai':
            lines = fmo_gaiJob(name)  #, nfrags, memory, ddi)
        elif hw == 'mon':
            lines = fmo_monJob(name, nfrags, memory, ddi)
        elif hw == 'mas':
            lines = fmo_masJob(name, nfrags, memory, ddi)

    if lines:
        write_job(npath, name, lines)
Example #3
0
def fmo(path, File, template, sysData, jobTemp):

    import os, re
    from general import hardware
    from chemData import pTable
    from templates import fmo_rjnJob
    from templates import fmo_mgsJob
    from templates import fmo_gaiJob
    from templates import gms_rjnJob
    from templates import gms_mgsJob
    from templates import gms_gaiJob
    from tempInp import fmo_ions
    from write import write_xyz
    from write import write_gmsInp
    from write import write_job

    # NAME FOR WRITING FILE, DIRS
    name = File.replace('.xyz', '').split('_')[0]

    # MAKE NEW DIR AND NEW PATH
    npath = newDir(path, File, template)

    # UNPACK sysData
    fmo = True
    mp2 = False
    fragList, atmList, totChrg, totMult = sysData

    # NUMBER OF FRAGS
    nfrags = len(fragList)

    # MAKE xyzData
    xyzData = []
    # USE LIST OF IDS TO APPEND
    for frag in fragList:
        for ID in frag['ids']:
            atm = atmList[ID]
            xyzData.append(
                [atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])

    # TEMPLATE LINES
    input = xyzTemp(path, template, xyzData)
    #print(input)
    fmo_input = []
    # ONE LINE REPLACEMENTS - NO MULT YET ***
    # IF RUNTYP IS ENERGY MAKE ION JOBS
    ions = False
    for ind in range(len(input)):
        if 'NGROUP' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'NGROUP':
                    in_grp = spl_line[val + 1]
                    if in_grp != str(nfrags):
                        #print('Changing NGROUP to', nfrags)
                        input[ind] = input[ind].\
                        replace('NGROUP=' + in_grp, 'NGROUP=' + str(nfrags))

        # CHECK NFRAG = NO. OF FOUND FRAGMENTS
        if 'NFRAG' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'NFRAG':
                    in_nfrags = spl_line[val + 1]
                    if in_nfrags != str(nfrags):
                        #print('Changing NFRAG  to', nfrags)
                        input[ind] = input[ind].\
                        replace('NFRAG=' + in_nfrags, 'NFRAG=' + str(nfrags))

        # LIST OF CHARGES FOR FRAGMENTS
        if 'ICHARG' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if 'ICHARG' in bit:
                    in_chrg = spl_line[val + 1]
                    chrgs = []
                    for frag in fragList:
                        chrgs.append(frag['chrg'])
                    input[ind] = input[ind].replace('ICHARG(1)=' + in_chrg, \
                            'ICHARG(1)=' + ','.join(str(p) for p in chrgs) + '\n')

        # MULT
        if 'MULT' in input[ind]:
            spl_line = re.split('=', input[ind])
            for val, bit in enumerate(spl_line):
                if 'MULT' in bit:
                    mults = []
                    for frag in fragList:
                        mults.append(frag['mult'])
                    in_chrg = spl_line[val + 1]
                    input[ind] = input[ind].replace('MULT(1)=' + in_chrg,\
                    'MULT(1)=' + ','.join(str(p) for p in mults) + '\n')

        # CHECK IF SPEC FOR ION CALCS
        if 'RUNTYP' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if 'RUNTYP' in bit:
                    if spl_line[val + 1] == 'ENERGY':
                        ions = True

        # MEMORY USED IN INPUT USED FOR JOB MEMORY
        if 'MWORDS' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'MWORDS' in input[ind]:
                    memory = spl_line[val + 1]

        # MEMORY USED IN INPUT FOR JOB MEMORY
        ddi = False
        if 'MEMDDI' in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'MEMDDI' in input[ind]:
                    ddi = spl_line[val + 1]

        # FOR FMO_IONS
        if '$MP2' in input[ind]:
            mp2 = input[ind]

        if "GBASIS" in input[ind]:
            spl_line = re.split('=| ', input[ind])
            for val, bit in enumerate(spl_line):
                if bit == 'GBASIS' in input[ind]:
                    bset = spl_line[val + 1]

    # REMOVE LINES FROM INPUT WITH NEW LIST
    # FOR MANY LINE CHANGES - COORDS, INDAT, ATM LIST
    atmUniq = []
    numUniq = []
    seenA = False
    for line in input:
        if type(line) != list:
            # INDAT MAY BE DIFF NUMBER OF LINES TO NEW INDAT
            if 'INDAT' in line:
                fmo_input.append('    INDAT(1)=0,1,-' +
                                 str(fragList[0]['ids'][-1] + 1) + ',\n')
                for frag in fragList:
                    if not frag is fragList[0]:
                        fmo_input.append(' '*13 + '0,' + str(frag['ids'][0] + 1) + \
                                ',-' + str(frag['ids'][-1] + 1) + ',\n')
                fmo_input.append(' ' * 13 + '0\n')

            # SO NOT PASSED TO ELSE // EXTRA LINES TO DETERMINE FRAGMENT
            elif re.search('^\s*0,[0-9]{1,3},-[0-9]{1,3},\s*$', line) or \
                      re.search('^\s*0\s*$', line):
                pass
            # ATOM LIST MAY BE DIFF NUMBER OF LINES TO NEW ATOM LIST
            elif re.search('^\s*[A-Za-z]*\s*[0-9]*\.0*$', line):
                if not seenA:
                    for i in xyzData:
                        atmUniq.append(i[0])
                        numUniq.append(i[1])
                    atmUniq = list(set(atmUniq))
                    for i in range(len(atmUniq)):
                        for sym, data in pTable.items():
                            if sym == atmUniq[i]:
                                fmo_input.append(' ' + str(atmUniq[i]) + ' ' + \
                                str(data[0]) + '\n')
                    seenA = True
            # EVERY OTHER LINE AS IS
            else:
                fmo_input.append(line)
        else:
            fmo_input.append(line)

    # HARDWARE FOR WRITING
    hw = hardware()
    # XYZ OF IONS ------------------------------------
    if ions:
        ncat = 0
        nani = 0
        nnrt = 0
        nunk = 0
        # FOR EACH FRAGMENT
        for i, frag in enumerate(fragList):
            ifrag = []
            for val, atm in enumerate(xyzData):
                if val in frag['ids']:
                    ifrag.append(atm)

            # IN CASE QUESTION MARK
            try:
                if frag['chrg'] < 0:
                    ion = 'anion' + str(nani)
                    nani += 1
                elif frag['chrg'] > 0:
                    ion = 'cation' + str(ncat)
                    ncat += 1
                else:
                    ion = 'neutral' + str(nnrt)
                    nnrt += 1
            except:
                if frag['chrg'] == '?':
                    ion = 'unknown' + str(nunk)
                    nunk += 1

            # MAKE FOLDER AND XYZ
            if not os.path.isdir(npath + ion):
                os.mkdir(npath + ion)
            write_xyz(npath + ion + '/', ion, ifrag)

            # INPUT AND OUTPUT FOR JOB
            input = fmo_ions(str(frag['chrg']), ifrag, bset, mp2)
            write_gmsInp(npath + ion + '/', ion, input)

            # WRITE JOB
            if hw == 'rjn':
                lines = gms_rjnJob(ion, memory, ddi)
            if hw == 'mgs':
                lines = gms_mgsJob(ion, memory, ddi)
            if hw == 'gai':
                lines = gms_gaiJob(ion, memory, ddi)
            write_job(npath + fol + '/', ion, lines)

    # -------------------------------------------------

    # WRITE INP
    write_gmsInp(npath, name, fmo_input)

    # WRITE JOB
    if jobTemp:
        lines = job_replace(name, jobTemp)
    else:
        if hw == 'rjn':
            lines = fmo_rjnJob(name, nfrags, memory, ddi)
        if hw == 'mgs':
            lines = fmo_mgsJob(name, nfrags, memory, ddi)
        if hw == 'gai':
            lines = fmo_gaiJob(name)  #, nfrags, memory, ddi)

    write_job(npath, name, lines)