Exemplo n.º 1
0
def orc(path, File, template, sysData, jobTemp):

    import re
    from supercomp import host
    from templates import orc_rjnJob
    from write import write_inp
    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"]])

    # PUT XYZ IN TEMPLATE
    input = xyzTemp(path, template, xyzData)

    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 + '.xyz\n'

    # WRITE INP
    write_inp(npath, name, input)

    # WRITE JOB
    lines = False

    if jobTemp:
        lines = job_replace(name, jobTemp)
    else:
        hw = host()
        if hw == 'rjn':
            lines = orc_rjnJob(name)

    if lines:
        write_job(npath, name, lines)
Exemplo n.º 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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def comp_tasks(task, path, filename, jobfile):
    import os.path
    from general import find_files, software, softInp
    from system import systemData
    from p_print import stat_print, file_print, e_print
    from p_print import noFiles
    from logFile import sort

    # FORMAT EXPECTED
    if filename:
        if path is '':
            path = './'
        Files = [[path, filename]]
    else:
        Files = False

    # GENERATE JOB/INP FROM TEMPLATE
    # EXPECTS .template FILE IN PATH DIRECTORY
    if task == "1":
        import sys
        from genJob import g09, gms, psi, fmo, orc

        # RECURSIVE FILE CREATION
        if not Files:
            #level        = False                   # ALL LEVELS
            level = input("Number of subdirs [0-9]: ")
            file_pattern = ['.xyz']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        for path, File in Files:

            # CHECK IF ANY TEMPLATE FILES ARE FMO FOR CORRECT FRAGMENTATION
            fmoC = False
            templates = []
            for template in os.listdir(path):
                if template.endswith('template'):
                    templates.append(template)
                    with open(template, 'r+') as f:
                        for line in f:
                            if '$FMO' in line:
                                fmoC = True

            # CHECK IF TEMPLATE FILE HAS BEEN FOUND
            if len(templates) == 0:
                sys.exit("No '*template' files found in directory.")

            # CHECK IF JOB TEMPLATE
            jobTemp = False

            if jobfile:
                jobTemp = open(path + jobfile, 'r+').read()

            elif os.path.isfile(path + 'template.job'):
                jobTemp = open(path + 'template.job', 'r+').read()

            # SEARCH FILES
            print('-' * 40)
            file_print(path, File, "Using")
            # ONLY HAPPEN ONCE FOR EACH XYZ
            sysData = systemData(path, File, fmoC)
            # COMPLETE FOR EVERY TEMPLATE
            for template in templates:
                file_print(path, template, "With template")
                soft = softInp(path, template)
                if soft == 'g09':
                    # JOB INCLUDED IN INPUT
                    g09(path, File, template, sysData)
                elif soft == 'gms':
                    gms(path, File, template, sysData, jobTemp)
                elif soft == 'psi':
                    psi(path, File, template, sysData, jobTemp)
                elif soft == 'fmo':
                    fmo(path, File, template, sysData, jobTemp)
                elif soft == 'orc':
                    orc(path, File, template, sysData, jobTemp)
                # WILL TREAT UNKNOWN INPUT FILE AS G09 TYPE
                else:
                    g09(path, File, template, sysData)

    ### PULL ENERGIES
    elif task == "2":
        from energy import energy_g09, energy_gms, energy_psi
        from write import write_energy
        from os import getcwd
        cwd = getcwd()
        energy = []  # TO PRINT AT END
        if not Files:
            level = 100  # ALL
            file_pattern = ['.log', '.out']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()
        # SEARCH FILES
        for path, File in Files:
            # DO NOT SORT PREVIOUS LOG FILES
            if not File.startswith('f-') and not File.startswith('slurm'):
                soft = software(path, File)
                if soft == 'gms':
                    energy = energy_gms(path, File, energy)
                elif soft == 'g09':
                    energy = energy_g09(path, File, energy)
                elif soft == 'psi':
                    energy = energy_psi(path, File, energy)
        mkfi = input("Write to file? (y/n) [n]")
        if mkfi == 'n' or mkfi == '':
            e_print(energy)
        elif mkfi == 'y':
            e_print(energy)
            write_energy(cwd, energy)

    ### SORT LOG FILES
    elif task == "3":
        if not Files:
            level = False  # ALL LEVELS
            level = input("Number of subdirs [0-9]: ")
            file_pattern = ['.log', '.out']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()
        # SEARCH FILES
        for path, File in Files:
            # DO NOT SORT PREVIOUS LOG FILES
            if not File.startswith('f-') and not File.startswith('slurm'):
                # GET SOFTWARE OF LOG
                soft = software(path, File)
                if not soft:
                    stat_print(path, File, 5)
                else:
                    # MOVE INTO DIRECTORIES & CREATE XYZ's
                    sort(path, File, soft)

    # MASS SED
    elif task == "4":
        from clean import sed
        sed(path)

    # MASS RENAME
    elif task == "5":
        from clean import rename
        rename(path)

    # DELETE N JOBS FROM QUEUE
    elif task == "6":
        from supercomp import deleteJob
        deleteJob()

    # COUNTERPOISE
    elif task == '7':
        import sys
        from genJob import g09, gms, psi, fmo
        from genJobCP import psi_cpoise, g09_cpoise, orc_cpoise

        if not Files:
            level = False  # ZERO LEVELS
            file_pattern = ['.xyz']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        templates = []
        for template in os.listdir(path):
            if template.endswith('template'):
                templates.append(template)

        # CHECK IF TEMPLATE FILE HAS BEEN FOUND
        if len(templates) == 0:
            sys.exit("No '*template' files found in directory.")

        # ASK USER IF SPHERE FOR BSSE
        task = input('                                          \n\
                          1. Full counterpoise calculation      \n\
                          2. Sphere around each molecule        \n\
                                                           Task: ')
        if task == '2':
            # USER DEFINED DISTANCE
            dist = input(
                "Enter the radius of the solvation shell to include: ")
        else:
            dist = False

        # CHECK IF JOB TEMPLATE
        jobTemp = False
        if jobfile:
            jobTemp = open(path + jobfile, 'r+').read()
        elif os.path.isfile(path + 'template.job'):
            jobTemp = open(path + 'template.job', 'r+').read()

        # SEARCH FILES
        for path, File in Files:
            file_print(path, File, "Using")
            # ONLY HAPPEN ONCE FOR EACH XYZ
            sysData = systemData(path, File, True)
            # COMPLETE FOR EVERY TEMPLATE
            for template in templates:
                soft = softInp(path, template)
                # PSI4 ONLY
                if soft == 'g09':
                    # JOB INCLUDED IN INPUT
                    g09_cpoise(path, File, template, sysData, dist)
                elif soft == 'gms':
                    pass
                elif soft == 'psi':
                    psi_cpoise(path, File, template, sysData, jobTemp, dist)
                elif soft == 'fmo':
                    pass
                elif soft == 'orc':
                    orc_cpoise(path, File, template, sysData, jobTemp, dist)

    # DISTANCES AND ANGLES
    elif task == '8':
        from geometry import sysGeom
        # GET PATHS
        if not Files:
            level = 1
            file_pattern = ['.xyz']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        # ASK USER QUESTIONS ABOUT WHAT THEY WANT
        task = input('                                    \n\
                          1. All interionic distances     \n\
                          2. H-bonding data               \n\
                          3. Intramolecular bond lengths  \n\
                                                           Task: ')

        for path, File in Files:
            file_print(path, File, "Using")
            sysData = systemData(path, File, True)
            sysGeom(sysData, task)

    # SUBMIT JOBS
    elif task == '9':

        from supercomp import submit
        # GET PATHS
        if not Files:
            level = False  # ALL LEVELS
            level = input("Number of subdirs [0-9]: ")
            file_pattern = ['.com', '.job']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        # ORIGINAL PATH
        os.chdir(path)
        cwd = os.getcwd()
        # SEARCH FILES
        for path2, File in Files:
            if File != 'template.job':
                os.chdir(path2)
                submit(File)
                os.chdir(cwd)

    # INFLATE SYSTEM
    # EXPECTS .xyz FILE IN PATH DIRECTORY
    elif task == "A":
        import sys
        from xyzGenerate import expand

        level = False  # NO LEVELS

        if not Files:
            file_pattern = ['.xyz']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        # DISTANCES BY USER
        print("Enter the minimum distance you want between fragments")
        dist = input("You can provide more than one separated by space: ")

        dists = []

        # CHECK FLOATS WERE GIVEN
        for i in dist.split():
            try:
                dists.append(float(i))
            except TypeError:
                sys.exit("Could not convert " + i + " into a float")

        # SEARCH FILES
        for path, File in Files:
            file_print(path, File, "Using")
            # ONLY HAPPEN ONCE FOR EACH XYZ
            sysData = systemData(path, File, True)
            expand(path, File, sysData, dists)

    # INTERACTION ENERGY
    elif task == 'B':

        from xyzGenerate import separate_mols

        # MAKE SURE CORRECT FRAGMENTATION
        check_frags = True
        level = False  # NO LEVELS

        if not Files:
            file_pattern = ['.xyz']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        # SEARCH FILES
        for path, File in Files:
            use = True
            skip = ['anion', 'cation', 'unknown', 'neutral']
            for i in skip:
                if i in File:
                    use = False

            if use:
                print('-' * 40)
                file_print(path, File, "Using")
                # ONLY HAPPEN ONCE FOR EACH XYZ
                sysData = systemData(path, File, check_frags)
                separate_mols(path, File, sysData)

    # FLUORESCENCE DATA
    elif task == 'C':
        from extras import get_fluorescence_data

        task = input('                                    \n\
                          1. Fluorescence Data            \n\
                                                           Task: ')
        if task == '1' or task == "":
            get_fluorescence_data()

    # GET XYZ SOLVATION SHELL OF EACH FRAGMENT
    elif task == 'D':
        from xyzGenerate import xyzShell

        # USER DEFINED DISTANCE
        dist = input("Enter the radius of the solvation shell to include: ")

        # MAKE SURE CORRECT FRAGMENTATION
        check_frags = True
        level = False  # NO LEVELS

        if not Files:
            file_pattern = ['.xyz']  # FILES TO CHECK
            Files = find_files(path, level, file_pattern)
            if len(Files) == 0:
                noFiles()

        # SEARCH FILES
        for path, File in Files:
            use = True
            skip = ['anion', 'cation', 'unknown', 'neutral']
            for i in skip:
                if i in File:
                    use = False

            if use:
                print('-' * 40)
                file_print(path, File, "Using")

                # ONLY HAPPEN ONCE FOR EACH XYZ
                sysData = systemData(path, File, check_frags)
                xyzShell(path, File, sysData, dist)

    # CHECK COMPLETED JOBS
    elif task == '10':
        from supercomp import host, rjn_q

        if os.path.exists(os.path.expanduser('~/sub.txt')):

            to_write = []
            to_save = []

            jobs = open(os.path.expanduser('~/sub.txt'), 'r+').readlines()
            hw = host()

            if hw == "rjn":

                queDicts = rjn_q()

                for job in jobs:
                    found = False
                    for jobDict in queDicts:
                        # CHECK IF FILES IN SAVED ARE IN QUEUE
                        #print(job)
                        #print(jobDict['id'])
                        if jobDict['id'] in job:
                            # IF FINISHED WRITE TO SAVE FILE
                            to_write.append(job)
                            found = True
                            #print('TRUE')
                            #print(jobDict['status'])
                            if jobDict['status'] == 'Q':
                                print('QUEUED\t' + job.replace('\n', ''))

                            elif jobDict['status'] == 'R':
                                print('RUNNIN\t' + job.replace('\n', ''))

                    if not found:
                        print('FINISH\t' + job.replace('\n', ''))
                        to_save.append(job)

                write = input('Remove data of completed jobs (y/n)? ')

                if write == 'y' or write == 'Y':

                    # REWRITE FILE WITHOUT FINISHED JOBS
                    f = open(os.path.expanduser('~/sub.txt'), 'w+')
                    for line in to_write:
                        f.write(line)
                    f.close()

                    # WRITE FINISHED JOBS INTO NEW FILE
                    f = open(os.path.expanduser('~/jobLog.txt'), 'w+')
                    for line in to_save:
                        f.write(line)
                    f.close()
Exemplo n.º 5
0
def deleteJob():
    import re, sys
    import subprocess as sp
    from   supercomp import host

    que = []
    IDs_list = []
    nms_list = []
    dict_IDs = {}
    toDel_list = []

    user = sp.Popen("echo $USER", shell=True, stdout=sp.PIPE).stdout
    user = user.read().decode("utf-8").split()[0]

    hw = host()

    if hw == 'rjn':
        # GET QUEUE
        print('Waiting for qstat from Raijin...')
        #print("qstat -u " + user)
        pipe = sp.Popen("qstat -u " + user, shell=True, stdout=sp.PIPE).stdout
        queue = pipe.read().decode("utf-8")
        queue = queue.split('\n')
        # REMOVE OTHER LINES
        for line in queue:
            if user in line:
                que.append(line)

        # PRINT FOR USER
        num_lin = len(que)
        for val, line in enumerate(que):
            print("{:5}{}".format(str(num_lin - val), line))

        # ASK USER NUMBER OF JOBS TO DELETE OR NAME
        typ = input("Delete by: 1: Number; 2: All; 3: Name; [Default=1] ")
        typ = typ or '1'

        # SAVE JOB NUMBERS AND NAMES
        for line in que:
            #print(que)
            ID = re.split(' |\.', line)
            ID = list(filter(None, ID))
            IDs_list.append(ID[0])
            nms_list.append(ID[4])
            dict_IDs[ID[0]] = ID[4]

        # IF DELETING BY NUMBER
        if typ == '1' or typ == '2':
            if typ == '2':
                sure = input('Are you sure you want to delete all jobs? (y/n) ')
                if sure == 'y':
                    n = len(IDs_list)
                else:
                    n = 0
            elif typ == '1':
                n = input("Number of jobs to delete from bottom of queue: ")

            # IF NO USER INPUT
            if not n:
                sys.exit("No user input given, exiting",)


            start = len(IDs_list) - int(n)
            finish = len(IDs_list)

            for i in range(len(IDs_list)):
                if start <= i < finish:
                    sp.call("qdel " + IDs_list[i], shell=True)
                    print("Removed " + IDs_list[i] + " from queue")

        # IF DELETING BY NAME
        elif typ == '3':
            subnm = input("Part of name unique to all jobs to delete: ")

            # FIND JOBS WITH NAME
            for ID, name in dict_IDs.items():
                if subnm in name:
                    print("To delete: ", name, ID)
                    toDel_list.append(ID)

            # DELETE
            toDel = input("Are you sure? y/n ")
            if toDel == 'y':
                for ID in toDel_list:
                    sp.call("qdel " + ID, shell=True)
                    print("Removed " + ID + " from queue")

    elif hw == 'mgs':
        print('Not written for magnus yet')

    elif hw == 'gai':
        print('Waiting for qstat from MCC...')

        pipe = sp.Popen("qstat -u " + user, shell=True, stdout=sp.PIPE).stdout
        queue = pipe.read().decode("utf-8")
        queue = queue.split('\n')
        # REMOVE OTHER LINES
        for line in queue:
            if user in line:
                que.append(line)

        # PRINT FOR USER
        num_lin = len(que)
        for val, line in enumerate(que):
            print("{:5}{}".format(str(num_lin - val), line))

        # ASK USER NUMBER OF JOBS TO DELETE OR NAME
        typ = input("Delete by: 1: Number; 2: All; 3: Name; [Default=1] ")
        typ = typ or '1'

        # SAVE JOB NUMBERS AND NAMES
        for line in que:
            #print(que)
            ID = re.split(' |\.', line)
            ID = list(filter(None, ID))
            IDs_list.append(ID[0])
            nms_list.append(ID[3])
            dict_IDs[ID[0]] = ID[3]

        # IF DELETING BY NUMBER
        if typ == '1' or typ == '2':
            if typ == '2':
                sure = input('Are you sure you want to delete all jobs? (y/n) ')
                if sure == 'y':
                    n = len(IDs_list)
                else:
                    n = 0
            elif typ == '1':
                n = input("Number of jobs to delete from bottom of queue: ")
            start = len(IDs_list) - int(n)
            finish = len(IDs_list)

            for i in range(len(IDs_list)):
                if start <= i < finish:
                    sp.call("qdel " + IDs_list[i], shell=True)
                    print("Removed " + IDs_list[i] + " from queue")

        # IF DELETING BY NAME
        elif typ == '3':
            subnm = input("Part of name unique to all jobs to delete: ")
            print(subnm)
            print(dict_IDs)
            # FIND JOBS WITH NAME
            for ID, name in dict_IDs.items():
                if subnm in name:
                    print("To delete: ", name, ID)
                    toDel_list.append(ID)

            # DELETE
            toDel = input("Are you sure? y/n ")
            if toDel == 'y':
                for ID in toDel_list:
                    sp.call("qdel " + ID, shell=True)
                    print("Removed " + ID + " from queue")
Exemplo n.º 6
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)
Exemplo n.º 7
0
def psi_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 psi_rjnJob
    from templates  import psi_gaiJob
    from templates  import psi_masJob
    from write      import write_inp
    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

    # 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"]])

    # PUT XYZ IN TEMPLATE
    input = xyzTemp(path, template, xyzData)

    # IF bsse_type='cp' PSI4 ONLY ONE CALC
    cp_type = False
    for line in input:
        if "bsse_type=" in line and "'cp'" in line:
                cp_type = True

    # IF bsse_type='cp' PSI4 ONLY ONE CALC
    if cp_type:
        # REMOVE EXTRA '--' AND CHARGE MULTIPLICITY
        cp_input = []
        for line in input:
            if type(line) != list:
                if '--' in line:
                    pass
                elif re.search('\s*-?[0-9]\s*[0-9]\s*', line):
                    pass
                else:
                    cp_input.append(line)
            else:
                cp_input.append(line)

        # COUNT WHICH ATOM UP TO
        count = 0
        input = []
        for i in range(len(cp_input)):
            # IF ATOM LINE
            if type(cp_input[i]) is list:
                # FOR EACH FRAG
                put = False
                for frag in fragList:
                    # IF ATOM NUMBER LAST ATOMS OF FRAG
                    if count == frag['ids'][0]:
                        # IF NOT FIRST FRAG
                        if not count == fragList[0]['ids'][0]:
                            input.append('--\n')
                        input.append(str(frag['chrg'])+' '+str(frag['mult'])+'\n')
                        input.append(cp_input[i])
                        put = True
                if not put:
                    input.append(cp_input[i])
                count += 1

            else:
                input.append(cp_input[i])


        # WRITE INP
        write_inp(npath, name, input)

        # WRITE JOB
        lines = False

        if jobTemp:
            lines = job_replace(name, jobTemp)
        else:
            hw = host()
            if hw == 'rjn':
                lines = psi_rjnJob(name)
            elif hw == 'gai':
                lines = psi_gaiJob(name)
            elif hw == 'mas':
                lines = psi_masJob(name)

        if lines:
            write_job(npath, name, lines)


    # NORMAL INPUT -------------------------
    else:
        # IF NOT RADIAL CUTOFF FOR MOLS INCLUDED DO ALL
        if not dist:
            for i in range(len(input)):
                if type(input[i]) != list:
                    # CHANGE MEMORY to 64
                    #if 'memory' in input[i]:
                    #    line = input[i].split()
                    #    memory = line[1]
                    #    input[i] = input[i].replace(memory, '64')
                        # CHANGE CHRG AND MULT
                    if re.search('^\s*-?[0-9]\s*-?[0-9]\s*$', input[i]):
                        # IF CHRG = MULT COULD BE TRICKY
                        input[i] = ' ' + str(totChrg) + ' ' + str(totMult) + '\n'

            # WRITE INP
            write_inp(npath, name, input)

            # WRITE JOB
            lines = False
            if jobTemp:
                lines = job_replace(name, jobTemp)
            else:
                hw = host()
                if hw == 'rjn':
                    lines = psi_rjnJob(name)
                elif hw == 'gai':
                    lines = psi_gaiJob(name)
                elif hw == 'mas':
                    lines = psi_masJob(name)

            if lines:
                write_job(npath, name, lines)

            # 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
                # 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('^\s*-?[0-9]\s*-?[0-9]\s*$', input[i]):
                            # IF CHRG = MULT COULD BE TRICKY
                            input[i] = ' ' + str(frag['chrg']) + ' ' + str(totMult) + '\n'
                # 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 = psi_rjnJob(frag["name"])
                    elif hw == 'gai':
                        lines = psi_gaiJob(frag["name"])
                    elif hw == 'mas':
                        lines = psi_masJob(frag["name"])

                if lines:
                    write_job(npath + frag["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('^\s*-?[0-9]\s*-?[0-9]\s*$', input[i]):
                            # IF CHRG = MULT COULD BE TRICKY
                            input[i] = ' ' + str(frag['chrg']) + ' ' + str(totMult) + '\n'
                        # CHANGE MEMORY
                        if re.search('memory', input[i]):
                            line = re.split(' |G|g', input[i])
                            for bit in line:
                                if re.search('[0-9]', bit):
                                    input[i] = input[i].replace(bit, '64')
                                    break
                # 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 = psi_rjnJob(frag["name"])
                    elif hw == 'gai':
                        lines = psi_gaiJob(frag["name"])
                    elif hw == 'mas':
                        lines = psi_masJob(frag["name"])

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