Esempio n. 1
0
def expand(path, File, sysData, dists):
    from write import write_xyz
    import numpy as np

    fragList, atmList, totChrg, totMult = sysData

    # GET SMALLEST INTERIONIC DISTANCE
    # a, b ARE INDEX OF SMALLEST DIST ATOMS
    dmin = get_min_interionic_dist(atmList)

    atmList, fragList = rearrange_list(atmList, fragList)

    relxyz, coords = get_relative_coords(atmList, fragList)

    # FIND NEW ORIGIN // MEAN OF ALL POINTS
    d_origin = np.mean(coords, axis=0)

    # REDEFINE POINTS W.R.T NEW ORIGIN
    coords = coords - d_origin

    # FOR EACH DISTANCE
    for dist in dists:
        scale = dist / dmin
        # SCALE
        coords_new = scale * coords

        # PLUS POSITION OF EACH TO ALL RELATIVE POSITIONS TO GET NEW XYZ
        coords_new = coords_new + relxyz

        # RELXYZ AND COORDS IN ORDER OF APPEARANCE IN FRAGLIST
        i = 0
        newxyz = []
        for frag in fragList:
            for atm in atmList:
                if atm["id"] in frag['ids_by_int_dist']:
                    newxyz.append([
                        atm["sym"], coords_new[i][0], coords_new[i][1],
                        coords_new[i][2]
                    ])
                    i += 1

        name = File.replace('.xyz', '_' + str(dist) + 'A')
        write_xyz(path, name, newxyz)
Esempio n. 2
0
def separate_mols(path, File, sysData):

    from write import write_xyz

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

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

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

        # WRITE XYZ
        write_xyz(path, name + '-' + frag["name"], ifrag)
Esempio n. 3
0
def separate_mols(path, File, sysData):

    from write import write_xyz

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

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

    ncat, nani, nntr, nunk = 0, 0, 0, 0

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


        # 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(nntr)
                nntr += 1
        except:
            if frag['chrg'] == '?':
                ion = 'unknown' + str(nunk)
                nunk += 1

        # WRITE XYZ
        write_xyz(path, name + '-' + ion, ifrag)
Esempio n. 4
0
def sort(path, File, soft):
    import os, re
    from shutil import copyfile
    from general import software
    from general import gms_check_spec
    from general import g09_check_spec
    from general import psi_check_spec
    from pprint import stat_print
    from write import write_xyz

    if soft:
        # CHECK IF SPEC AND CHECK IF LOG TERMINA
        if soft == 'gms':
            spec = gms_check_spec(path, File)
            err, ext, stat = gms_log(path, File, spec)
        elif soft == 'g09':
            spec = g09_check_spec(path, File)
            err, ext, stat = g09_log(path, File, spec)
        elif soft == 'psi':
            spec = psi_check_spec(path, File)
            err, ext, stat = psi_log(path, File, spec)

        # NAME WITH EXTENSION
        name = File.replace('.log', ext).replace('.out', ext)
        # PRINT MESSAGE
        if spec and not err:
            stat_print(path, File, 2)
        if not spec:
            # SUCCESSFUL JOB
            if not err:
                stat_print(path, File, stat)
                # GET GEOMETRY
                id = "spec/"
                if soft == 'gms':
                    geom = gms_geom(path, File, True)
                elif soft == 'g09':
                    geom = g09_geom(path, File, True)
                elif soft == 'psi':
                    geom = psi_geom(path, File, True)

                if not os.path.isdir(path + id):
                    os.makedirs(path + id)
                #copyfile(path + File, path + id +'c-'+ File)
                # WRITE XYZ
                write_xyz(path + id, name, geom)
            # FOR ALL UNFINISHED
            else:
                # GET GEOMETRY
                if soft == 'gms':
                    geom = gms_geom(path, File, False)
                elif soft == 'g09':
                    geom = g09_geom(path, File, False)
                elif soft == 'psi':
                    geom = psi_geom(path, File, False)

                # IF NO STEPS IN OPTIMISATION
                if len(geom) == 0:
                    stat_print(path, File, 6)
                    name = File.replace('.out', '').replace('.log', '')
                    nam1 = name + '.xyz'
                    nam2 = name + '_'
                    nam3 = name + '_Fail.xyz'
                    # REGULAR XYZ NAME
                    try:
                        copyfile(path + nam1, path + "rerun/" + nam3)
                    except:
                        # IF XYZ NAME WITH EXTENTION
                        for fILE in os.listdir(path):
                            if nam2 in fILE:
                                if not os.path.exists(path + 'rerun'):
                                    os.mkdir(path + 'rerun')
                                try:
                                    copyfile(path + fILE,
                                             path + "rerun/" + nam3)
                                except:
                                    print(File +
                                          ": could not pull geom, zero steps")

                # RETURNED GEOMETRY
                else:
                    stat_print(path, File, stat)
                    if err in ['conv', 'hes']:
                        id = 'notConv/'
                    elif err in ['inp', 'max', 'mem', 'time']:
                        id = 'rerun/'
                    elif err in ['unk']:
                        id = 'unknown/'
                    if not os.path.isdir(path + id):
                        os.makedirs(path + id)
                    copyfile(path + File, path + id + 'f-' + File)
                    write_xyz(path + id, name, geom)

        # IF FAILED SPEC
        elif spec and err:

            xyz  = File.replace('.out', '.xyz') \
            .replace('.log', '.xyz')
            xyz_ = File.replace('.out', '_.+xyz') \
            .replace('.log', '_.+xyz')

            found = False
            for file in os.listdir(path):
                if xyz == file or re.search(xyz_, file):
                    if not os.path.exists(path + "rerun"):
                        os.mkdir(path + "rerun")
                    newExt = file.split('_')[0] + ext + '.xyz'
                    copyfile(path + file, path + "rerun/" + newExt)
                    stat_print(path, File, 16)
                    found = True
            if not found:
                stat_print(path, File, 15)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
def xyzShell(path, File, sysData, dist, returnList=False):
    """Uses a distance to create a shell of molecules
       around each fragment."""
    import math
    from write import write_xyz

    fragList, atmList, totChrg, totMult = sysData

    # FOR EACH FRAGMENT
    for val, frag in enumerate(fragList):

        # GET ATOMS IN THE FRAGMENT
        mol = []

        # FOR EACH ATOM
        for atm in atmList:

            # IF ATOM IN THIS FRAG ADD TO mol
            if atm["id"] in frag["ids"]:
                mol.append(atm)

        # GET CENTER OF MASS OF FRAGMENT
        fragList[val]["com"] = get_center_of_mass(mol)

    # FOR EACH FRAG
    xyzs = []
    for frag in fragList:

        # ADD ORIGIN FRAG TO coordList
        firstMol = []
        otherMol = []
        for atm in atmList:
            if atm["id"] in frag["ids"]:
                firstMol.append(atm)

        # PAIR WITH SECOND FRAG
        for frag2 in fragList:
            if frag != frag2:

                # GET DISTANCE BETWEEN REFERENCE FRAG AND EACH FRAG
                s = (frag["com"][0] - frag2["com"][0]) ** 2 + \
                    (frag["com"][1] - frag2["com"][1]) ** 2 + \
                    (frag["com"][2] - frag2["com"][2]) ** 2
                s = math.sqrt(s)

                # CHECK IF CENTER OF MASS IS WITHIN DIST
                if s < float(dist):
                    # ADD TO coordList
                    for atm in atmList:
                        if atm["id"] in frag2["ids"]:
                            otherMol.append(atm)

                xyzs.append([frag, firstMol, otherMol])

        # PRINT NUMBER OF ATOMS INCLUDED FOR EACH CALCULATION
        print(frag["name"], ':', len(firstMol + otherMol))

    # RETURN LIST
    if returnList:
        return xyzs

    # ADD MOLECULE TOGETHER AND WRITE TO FILE
    for xyz_parts in xyzs:
        xyz = []
        for atm in xyz_parts[1]:
            xyz.append([atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])
        for atm in xyz_parts[2]:
            xyz.append([atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])

        # WRITE FRAGS WITHIN DIST TO XYZ IF NOT returnList
        name = File.replace('.xyz',
                            '') + '-' + xyz_parts[0]["name"] + '-' + dist

        # WRITE
        write_xyz(path, name, xyz)
Esempio n. 8
0
def orc_cpoise(path, File, template, sysData, jobTemp, dist):
    import os, re
    from supercomp  import host
    from genJob     import xyzTemp
    from genJob     import job_replace
    from templates  import orc_rjnJob
    from write      import write_inp
    from write      import write_xyz
    from write      import write_job

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

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

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

    # IF NOT RADIAL CUTOFF FOR MOLS INCLUDED DO ALL
    if not dist:

        # FOR EACH FRAGMENT
        for frag in fragList:
            ifrag = []
            for atm in atmList:
                if atm['id'] in frag['ids']:
                    ifrag.append([atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])
                else:
                    # MAKE OTHER FRAGS GHOST
                    ifrag.append([atm['sym'] + ':'] + [atm['nu'], atm["x"], atm["y"], atm["z"]])

            # MAKE FOLDERS
            if not os.path.isdir(npath + frag["name"]):
                os.mkdir(npath + frag["name"])

            # PUT XYZ IN TEMP FOR EACH FRAG
            input = xyzTemp(path, template, ifrag)

            # CHANGE CHARGE AND MULTIPLICITY/MEMORY
            for i in range(len(input)):
                if type(input[i]) != list:

                    # CHANGE CHRG AND MULT
                    if re.search('^\*xyzfile\s*-?[0-9]\s*-?[0-9]\s*', input[i]):
                        if totChrg == '?':
                            print("Cannot determine chrg/mult, using template values")
                        # IF CHRG = MULT COULD BE TRICKY
                        else:
                            line = input[i].split()
                            if '.xyz' in line[-1]:
                                input[i] = '*xyz ' + str(frag["chrg"]) + ' ' + str(frag["mult"]) + '\n'

                                # ADD XYZ AS GHOST ATOMS
                                for atm in ifrag:
                                    i += 1
                                    input.insert(i, atm)

                                # END XYZ
                                input.insert(i+1, '*')

                                # WILL CHANGE NUMBER OF LINES - DO NOT CONTINUE THIS LOOP
                                break

            # WRITE INPUT FILE FOR EACH FRAG
            write_inp(npath + frag["name"] + '/', name +'-'+ frag["name"], input)

            # WRITE JOB
            lines = False
            if jobTemp:
                lines = job_replace(name +'-'+ frag["name"], jobTemp)
            else:
                hw = host()
                if hw == 'rjn':
                    lines = orc_rjnJob(name +'-'+ frag["name"])

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

    # IF RADIAL CUTOFF FOR MOLS INCLUDED IN EACH FILE
    else:
        from xyzGenerate import xyzShell

        # GET < DIST SEPARATED FRAGS
        # xyzList = [frag, mol, ghost atoms]
        xyzList = xyzShell(path, File, sysData, dist, returnList=True)

        # FOR EACH FRAGMENT CENTER
        for frag, firstMol, otherMol in xyzList:
            ifrag = []
            for atm in firstMol:
                ifrag.append([atm['sym'], atm['nu'], atm["x"], atm["y"], atm["z"]])
            for atm in otherMol:
                ifrag.append([atm['sym'] + ":"] + [atm['nu'], atm["x"], atm["y"], atm["z"]])

            # MAKE FOLDERS
            if not os.path.isdir(npath + frag["name"]):
                os.mkdir(npath + frag["name"])

            # PUT XYZ IN TEMP FOR EACH FRAG
            input = xyzTemp(path, template, ifrag)

            # CHANGE CHARGE AND MULTIPLICITY/MEMORY
            # MEMORY OF INPUT NEEDS TO BE >>> MEM JOB
            for i in range(len(input)):
                if type(input[i]) != list:
                    # CHANGE CHRG AND MULT
                    if re.search('^\*xyzfile\s*-?[0-9]\s*-?[0-9]\s*', input[i]):
                        if totChrg == '?':
                            print("Cannot determine chrg/mult, using template values")
                        # IF CHRG = MULT COULD BE TRICKY
                        else:
                            line = input[i].split()
                            if '.xyz' in line[-1]:
                                input[i] = '*xyzfile ' + str(totChrg) + ' ' + str(totMult) + ' ' +line[-1]

                if re.search('.xyz', input[i]):
                    line     = input[i].strip()
                    line     = line.rsplit(' ', 1)[0]
                    input[i] = line+' '+name+'-ghost.xyz\n'

            # WRITE GHOST FILE XYZ
            write_xyz(npath + frag["name"] + '/', frag["name"] + "-ghost", ifrag)

            # WRITE INPUT FILE FOR EACH FRAG
            write_inp(npath + frag["name"] + '/', frag["name"], input)

            # WRITE JOB
            lines = False
            if jobTemp:
                lines = job_replace(frag["name"], jobTemp)
            else:
                hw = host()
                if hw == 'rjn':
                    lines = orc_rjnJob(frag["name"])

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