示例#1
0
def run_molpro(s, exe='molpro', template='molpro_template.txt', mult=None, overwrite=False):
    """
    Runs molpro, returns a string specifying the status of the calculation.
    TODO
    """
    mol = ob.get_mol(s, make3D=True)
    if mult is None:
        mult = ob.get_multiplicity(mol)
    tmp = io.read_file(template)
    inptext = get_input(mol, tmp, mult)
    prefix = ob.get_smiles_filename(s)
    inpfile = prefix + '.nw'
    outfile = prefix + '_nwchem.log'
    command = [exe, inpfile]
    if io.check_file(outfile, timeout=1):
        if overwrite:
            msg = 'Overwriting previous calculation "{0}"\n'.format(io.get_path(outfile))
            run = True
        else:
            msg = 'Skipping calculation, found "{0}"\n'.format(io.get_path(outfile))
            run = False
    else:
        run = True
    if run:
        if not io.check_file(inpfile, timeout=1) or overwrite:
            io.write_file(inptext, inpfile)
        if io.check_file(inpfile, timeout=1):
            msg = io.execute(command,stdoutfile=outfile,merge=True)
            if io.check_file(outfile, timeout=1):
                msg += ' Output file: "{0}"\n'.format(io.get_path(outfile))
        else:
            msg = 'Failed, cannot find input file "{0}"\n'.format(io.get_path(inpfile))
    return msg
示例#2
0
def get_input(x, template,method='CCSD',basis='cc-pvdz'):
    """
    Returns Gaussian input file text (str) based on a given template.
    """
    mol = ob.get_mol(x)
    mult = ob.get_multiplicity(mol)
    nopen = mult - 1
    charge = ob.get_charge(mol)
    formula = ob.get_formula(mol)
    geo = ob.get_geo(mol)
    xyz = ob.get_xyz(mol)
    zmat = ob.get_zmat(mol)
    uniquename = ob.get_inchi_key(mol, mult)
    smilesname = ob.get_smiles_filename(mol)
    inp = template.replace("QTC(CHARGE)", str(charge))
    inp = inp.replace("QTC(MULTIPLICITY)", str(mult))
    inp = inp.replace("QTC(NOPEN)", str(nopen))
    inp = inp.replace("QTC(UNIQUENAME)", uniquename)
    inp = inp.replace("QTC(SMILESNAME)", smilesname)
    inp = inp.replace("QTC(ZMAT)", zmat)
    inp = inp.replace("QTC(GEO)", geo)
    inp = inp.replace("QTC(XYZ)", xyz)
    inp = inp.replace("QTC(FORMULA)", formula)
    inp = inp.replace("QTC(METHOD)", method)
    inp = inp.replace("QTC(BASIS)", basis)
    if "QTC(" in inp:
        print("Error in template file:\n" + inp)
        return
    return inp
示例#3
0
def run_gaussian(s, exe='g09', template='gaussian_template.txt', mult=None, overwrite=False):
    """
    Runs gaussian calculation
    """
    mol = ob.get_mol(s, make3D=True)
    if mult is None:
        mult = ob.get_multiplicity(mol)
    tmp = io.read_file(template)
    inptext = get_gaussian_input(mol, tmp, mult)
    prefix = ob.get_smiles_filename(s)
    inpfile = prefix + '.g09'
    outfile = prefix + '_gaussian.log'
    command = [exe, inpfile, outfile]
    if io.check_file(outfile, timeout=1):
        if overwrite:
            msg = 'Overwriting previous calculation "{0}"\n'.format(io.get_path(outfile))
            run = True
        else:
            msg = 'Skipping calculation, found "{0}"\n'.format(io.get_path(outfile))
            run = False
    else:
        run = True
    if run:
        if not io.check_file(inpfile, timeout=1) or overwrite:
            io.write_file(inptext, inpfile)
        if io.check_file(inpfile, timeout=1):
            msg = io.execute(command)
            if io.check_file(outfile, timeout=1):
                msg += ' Output file: "{0}"\n'.format(io.get_path(outfile))
        else:
            msg = 'Failed, cannot find input file "{0}"\n'.format(io.get_path(inpfile))
    return msg
示例#4
0
def run_mopac(s, exe='mopac', template='mopac_template.txt', mult=None, overwrite=False):
    """
    Runs mopac, returns a string specifying the status of the calculation.
    mopac inp inp.out
    Mopac always writes the log file into a file with .out extension
    """
    mol = ob.get_mol(s, make3D=True)
    if mult is None:
        mult = ob.get_multiplicity(mol)
    tmp = io.read_file(template)
    inptext = get_input(mol, tmp, mult)
    prefix = ob.get_smiles_filename(s)
    inpfile = prefix + '.mop'
    outfile = prefix + '.out'
    command = [exe, inpfile]
    if io.check_file(outfile, timeout=1):
        if overwrite:
            msg = 'Overwriting previous calculation "{0}"\n'.format(io.get_path(outfile))
            run = True
        else:
            msg = 'Skipping calculation, found "{0}"\n'.format(io.get_path(outfile))
            run = False
    else:
        run = True
    if run:
        if not io.check_file(inpfile, timeout=1) or overwrite:
            io.write_file(inptext, inpfile)
        if io.check_file(inpfile, timeout=1):
            msg = io.execute(command)
            if io.check_file(outfile, timeout=1):
                msg += 'Output file: "{0}"\n'.format(io.get_path(outfile))
        else:
            msg = 'Failed, cannot find input file "{0}"\n'.format(io.get_path(inpfile))
    return msg
示例#5
0
def get_anharm(rorp,
               i,
               natom,
               node,
               anlevel,
               anovrwrt,
               species,
               optlevel,
               paths=''):
    """
    Runs the anharm module to project out torsional modes from xmatrix and
    find the updated vpt2 frequencies
    """
    import sys
    if paths:
        sys.path.insert(0, paths['qtc'])
    import patools as pa
    import iotools as io
    import obtools as ob
    import anharm
    opts = {}
    species = species.split('_m')[0]
    opts['smiles'] = species
    opts['node'] = node
    opts['theory'] = anlevel
    opts['optlevel'] = optlevel
    opts['anlevel'] = anlevel
    opts['natoms'] = natom
    if 'ts' in rorp:
        opts['logfile'] = 'geoms/' + 'tsgta_l1.log'
        opts['freqfile'] = 'me_files/ts_fr.me'
        opts['unprojfreq'] = 'me_files/ts_unpfr.me'
    else:
        opts['logfile'] = 'geoms/' + rorp + i + '_l1.log'
        opts['freqfile'] = 'me_files/' + rorp + i + '_fr.me'
        opts['unprojfreq'] = 'me_files/' + rorp + i + '_unpfr.me'
    if io.check_file(ob.get_smiles_filename(species) +
                     'anharm.log') and not anovrwrt.lower() == 'true':
        opts['anharmlog'] = ob.get_smiles_filename(species) + 'anharm'
        opts['writegauss'] = 'false'
        opts['rungauss'] = 'false'
    else:
        opts['writegauss'] = 'true'
        opts['rungauss'] = 'true'
        opts['anharmlog'] = ob.get_smiles_filename(species) + 'anharm'

    return anharm.main(opts)
示例#6
0
def read_xyzdir(s, xyzdir):
    """ 
    Reads xyz from xyzdir 
    """
    import obtools as ob
    xyz = ''
    slabel = ob.get_slabel(s)
    xyzfile = '{}{}{}.xyz'.format(xyzdir, os.path.sep,
                                  ob.get_smiles_filename(slabel))
    if check_file(xyzfile):
        xyz = read_file(xyzfile)
    elif check_file(xyzfile.split('_m')[0] + '_m1.xyz'):

        xyz = read_file(xyzfile.split('_m')[0] + '_m1.xyz')
    return xyz
示例#7
0
def run(s, template, parameters, mult=None):
    """
    Runs nwchem, returns a string specifying the status of the calculation.
    nwchem inp.nw > nw.log
    NWChem writes output and error to stdout.
    Generates .db (a binary file to restart a job) and .movecs (scf wavefunction) files in the run directory.
    Generates many junk files in a scratch directory.
    If scratch is not specified, these junk files are placed in the run directory.
    """
    package = parameters['qcpackage']
    overwrite = parameters['overwrite']
    mol = ob.get_mol(s, make3D=True)
    msg = ''
    if mult is None:
        mult = ob.get_multiplicity(mol)
    else:
        ob.set_mult(mol, mult)
    tmp = io.read_file(template)
    inptext = get_input(mol, tmp)
    prefix = ob.get_smiles_filename(s) + '_' + package
    inpfile = prefix + '.inp'
    outfile = prefix + '.out'
    if io.check_file(outfile, timeout=1):
        if overwrite:
            msg = 'Overwriting previous calculation "{0}"\n'.format(io.get_path(outfile))
            run = True
        else:
            msg = 'Skipping calculation, found "{0}"\n'.format(io.get_path(outfile))
            run = False
    else:
        run = True
    if run:
        if not io.check_file(inpfile, timeout=1) or overwrite:
            io.write_file(inptext, inpfile)
        if io.check_file(inpfile, timeout=1):
            if package == 'extrapolation':
                run_extrapolation(s, parameters)
            elif package == 'nwchem':
                command = [parameters['qcexe'], inpfile]
                msg += io.execute(command,stdoutfile=outfile,merge=True)
            else:
                command = [parameters['qcexe'], inpfile, outfile] 
                msg = io.execute(command)
            if io.check_file(outfile, timeout=1):
                msg += ' Output file: "{0}"\n'.format(io.get_path(outfile))
        else:
            msg += 'Failed, cannot find input file "{0}"\n'.format(io.get_path(inpfile))
    return msg
示例#8
0
def run_nwchem(s, exe='nwchem', template='nwchem_template.txt', mult=None, overwrite=False):
    """
    Runs nwchem, returns a string specifying the status of the calculation.
    nwchem inp.nw > nw.log
    NWChem writes output and error to stdout.
    Generates .db (a binary file to restart a job) and .movecs (scf wavefunction) files in the run directory.
    Generates many junk files in a scratch directory.
    If scratch is not specified, these junk files are placed in the run directory.
    """
    mol = ob.get_mol(s, make3D=True)
    if mult is None:
        mult = ob.get_multiplicity(mol)
    tmp = io.read_file(template)
    inptext = get_input(mol, tmp)
    prefix = ob.get_smiles_filename(s)
    inpfile = prefix + '.nw'
    outfile = prefix + '_nwchem.log'
    command = [exe, inpfile]
    if io.check_file(outfile, timeout=1):
        if overwrite:
            msg = 'Overwriting previous calculation "{0}"\n'.format(io.get_path(outfile))
            run = True
        else:
            msg = 'Skipping calculation, found "{0}"\n'.format(io.get_path(outfile))
            run = False
    else:
        run = True
    if run:
        if not io.check_file(inpfile, timeout=1) or overwrite:
            io.write_file(inptext, inpfile)
        if io.check_file(inpfile, timeout=1):
            msg = io.execute(command,stdoutfile=outfile,merge=True)
            if io.check_file(outfile, timeout=1):
                msg += ' Output file: "{0}"\n'.format(io.get_path(outfile))
        else:
            msg = 'Failed, cannot find input file "{0}"\n'.format(io.get_path(inpfile))
    return msg
示例#9
0
def run_extrapolation(s, parameters):
    lines = io.read_file(parameters['qctemplate'],aslines=True)
    smilesname = ob.get_smiles_filename(s)
    filename = smilesname + '_cbs.ene'
    qcdir = parameters['qcdirectory']
    directories = []
    msg = ''
    for line in lines:
        if 'directories=' in line:
            exec(line)
            ndir = len(directories)
            energies=[0.]*ndir
            for i, edir in enumerate(directories):
                efile = io.join_path(*[edir,smilesname+'.ene'])
                if io.check_file(efile,verbose=True):        
                    energies[i] = float(io.read_file(efile, aslines=False))
                    print('Reading energy from {0} = {1}'.format(edir,energies[i]))
    for line in lines:
        if 'energy=' in line:
            energy = 0
            exec(line)
            print('Extrapolation based on formula: {0}'.format(line))        
            print('Extrapolated energy = {0}'.format(energy))
        if 'filename=' in line:
            exec(line)
    if len(directories) < 1:
        print('You have to specifies directories as a list in the template file')         
    if energy:
        msg += 'Extrapolation successful'
        if parameters['writefiles']:
            if qcdir:
                filename = io.join_path(*[qcdir,filename])
            io.write_file(str(energy), filename)
            msg += 'Extrapolation enegy file {0}'.format(filename)
    else:
        msg += 'Extrapolation failed'      
    return msg
示例#10
0
def run(s):
    """
    A driver function to run quantum chemistry and thermochemistry calculations based
    on command line options:
    --qcmethod
    --qcpackage
    """
    global parameters
    runqc = parameters['runqc']
    parseqc = parameters['parseqc']
    runthermo = parameters['runthermo']
    runanharmonic = parameters['anharmonic']
    msg = "***************************************\n"
    msg += "{0}\n".format(s)
    mult = ob.get_mult(s)
    mol = ob.get_mol(s)
    smilesname = ob.get_smiles_filename(s)
    smilesdir = ob.get_smiles_path(mol, mult, method='', basis='', geopath='')
    qcdirectory = io.join_path(*[smilesdir, parameters['qcdirectory']])
    qctemplate = io.get_path(parameters['qctemplate'])
    qcpackage = parameters['qcpackage']
    qcscript = io.get_path(parameters['qcscript'])
    qclog = smilesname + '_' + qcpackage + '.out'
    xyzpath = parameters['xyzpath']
    xyzfile = None
    if xyzpath:
        if io.check_file(xyzpath):
            xyzfile = xyzpath
        elif io.check_file(io.join_path(*(smilesdir, xyzpath))):
            xyzfile = io.join_path(*(smilesdir, xyzpath))
        elif io.check_dir(xyzpath):
            try:
                xyzfile = next(io.find_files(xyzpath, '*.xyz'))
            except StopIteration:
                msg += "xyz file not found in {0}".format(xyzpath)
        elif io.check_dir(io.join_path(*(smilesdir, xyzpath))):
            xyzpath = io.join_path(*(smilesdir, xyzpath))
            try:
                xyzfile = next(io.find_files(xyzpath, '*.xyz'))
            except StopIteration:
                msg += "xyz file not found in {0}".format(xyzpath)
        else:
            msg += "xyz path not found {0}".format(xyzpath)
            return msg
    if xyzfile:
        msg += "Using xyz file in '{0}'\n".format(xyzfile)
        xyz = io.read_file(xyzfile)
        coords = ob.get_coordinates_array(xyz)
        mol = ob.set_xyz(mol, coords)
    print(msg)
    msg = ''
    io.mkdir(qcdirectory)
    cwd = io.pwd()
    if io.check_dir(qcdirectory, 1):
        io.cd(qcdirectory)
        msg += "cd '{0}'\n".format(qcdirectory)
    else:
        msg += ('I/O error, {0} directory not found.\n'.format(qcdirectory))
        return -1
    print(msg)
    msg = ''
    available_packages = [
        'nwchem', 'molpro', 'mopac', 'gaussian', 'extrapolation'
    ]
    if runqc:
        if qcpackage in available_packages:
            print('Running {0}'.format(qcpackage))
            msg += qc.run(s, qctemplate, parameters, mult)
        elif qcpackage == 'qcscript':
            msg += "Running qcscript...\n"
            geofile = smilesname + '.geo'
            geo = ob.get_geo(mol)
            io.write_file(geo, geofile)
            if io.check_file(geofile, 1):
                msg += qc.run_qcscript(qcscript, qctemplate, geofile, mult)
        else:
            msg = '{0} package not implemented\n'.format(qcpackage)
            msg += 'Available packages are {0}'.format(available_packages)
            exit(msg)
        print(msg)
        msg = ''
    if parseqc:
        if io.check_file(qclog, timeout=1, verbose=False):
            out = io.read_file(qclog, aslines=False)
            d = qc.parse_output(out, smilesname, parameters['writefiles'])
            pprint(d)

    if runthermo:
        groupstext = tc.get_new_groups()
        io.write_file(groupstext, 'new.groups')
        msg += "Parsing qc logfile '{0}'\n".format(io.get_path(qclog))
        newmsg, xyz, freqs, zpe, deltaH, afreqs, xmat = qc.parse_qclog(
            qclog, qcpackage, anharmonic=runanharmonic)
        msg += newmsg
        if xyz is not None:
            msg += "Optimized xyz in Angstroms:\n{0} \n".format(xyz)
        else:
            runthermo = False
        if freqs is not None:
            msg += "Harmonic frequencies in cm-1:\n {0} \n".format(freqs)
        else:
            runthermo = False
        if afreqs:
            msg += "Anharmonic frequencies in cm-1:\n {0}\n".format(afreqs)
        else:
            runanharmonic = False
        if zpe:
            msg += 'ZPE = {0} kcal/mol\n'.format(zpe)
        else:
            runthermo = False
        if deltaH is not None:
            msg += 'deltaH = {0} kcal/mol\n'.format(deltaH)
        else:
            runthermo = False
        if xmat is not None:
            msg += 'Xmat = {0} kcal/mol\n'.format(xmat)
        else:
            runanharmonic = False
        if runthermo:
            msg += tc.write_chemkin_polynomial(mol, zpe, xyz, freqs, deltaH,
                                               parameters)
    io.cd(cwd)
    print(msg)
    return
示例#11
0
def main(inputfile, outputfile, configfile=''):
    torspath = os.path.dirname(os.path.realpath(sys.argv[0]))
    if configfile == '':
        configfile = torspath + os.path.sep + 'configfile.txt'
    args = config.ARGS(inputfile)
    Config = config.CONFIG(configfile, outputfile)
    paths = Config.path_dic()
    paths['torsscan'] = torspath
    sys.path.insert(0, es.get_paths(paths, 'bin'))
    sys.path.insert(0, es.get_paths(paths, 'qtc'))
    sys.path.insert(0, es.get_paths(paths, 'torsscan'))

    log.info(random_cute_animal())
    #####  Build and Run EStokTP  ######
    ####################################
    global io, ob
    import obtools as ob
    import iotools as io
    import tctools as tc
    import shutil

    symnums = []
    samps = None
    if args.restart < 8:
        index = 0
        if "Opt" in args.jobs and args.restart < 1:
            alljobs = args.jobs
            args.jobs = ["Opt"]
            es.run_level0(args, paths)
            args.restart = 1
            args.jobs = alljobs
        if "1dTau" in args.jobs and args.restart < 4:
            logging.info("========\nBEGIN LEVEL 1 and 1DHR\n========\n")
            alljobs = args.jobs
            negvals = True
            attempt = 0
            while (negvals and attempt < 3):
                attempt += 1
                args.jobs = ["Opt_1", "1dTau"]
                negvals = False
                if attempt == 1 and args.restart == 3:
                    pass
                else:
                    stoichs, symnums = es.build_files(args, paths)
                    es.execute(paths, args.nodes[0])
                if io.check_file('output/estoktp.out'):
                    shutil.copy('output/estoktp.out', 'output/estoktp_l1.out')
                args.restart = 3
                for i in range(len(args.reacs)):
                    lowene = 0.0
                    lowenefile = None
                    if io.check_file('me_files/reac' + str(i + 1) + '_hr.me'):
                        hr = io.read_file('me_files/reac' + str(i + 1) +
                                          '_hr.me')
                        hr = hr.split('Rotor')
                        startkey = 'Potential'
                        for j, rotor in enumerate(hr[1:]):
                            pot = rotor.split(startkey)[1]
                            pot = pot.splitlines()[1]
                            for k, ene in enumerate(pot.split()):
                                if float(ene) - lowene < -0.1:
                                    lowene = float(ene)
                                    lowenefile = 'hr_geoms/geom_isp' + str(
                                        i + 1).zfill(2) + '_hr' + str(
                                            j + 1).zfill(2) + '_hpt' + str(
                                                k + 1).zfill(2) + '.xyz'
                    if lowenefile:
                        xyz = io.read_file(lowenefile)
                        logging.info(xyz)
                        slabel = ob.get_slabel(ob.get_mol(xyz))
                        if slabel.split('_m')[0] == ob.get_slabel(
                                args.reacs[i]).split('_m')[0]:
                            negvals = True
                            if io.check_file('data/ts.dat') and i == 0:
                                if 'isomerization' in args.reactype.lower():
                                    tsfile = io.read_file('data/ts.dat')
                                    ijk = tsfile.split('ji ki')[1].split()[:3]
                                    ijk.append(
                                        tsfile.split('ireact2')[1].split('\n')
                                        [1].split()[-1])
                                    xyz = xyz.splitlines()
                                    xyz[int(ijk[0]) +
                                        1] = '2 ' + xyz[int(ijk[0]) + 1]
                                    xyz[int(ijk[1]) +
                                        1] = '3 ' + xyz[int(ijk[1]) + 1]
                                    xyz[int(ijk[2]) +
                                        1] = '4 ' + xyz[int(ijk[2]) + 1]
                                    xyz[int(ijk[3]) +
                                        1] = '1 ' + xyz[int(ijk[3]) + 1]
                                    xyz = '\n'.join(xyz)
                                else:
                                    ijk = io.read_file('data/ts.dat').split(
                                        'ksite')[1].split()[:3]
                                    xyz = xyz.splitlines()
                                    xyz[int(ijk[0]) +
                                        1] = '2 ' + xyz[int(ijk[0]) + 1]
                                    xyz[int(ijk[1]) +
                                        1] = '1 ' + xyz[int(ijk[1]) + 1]
                                    xyz[int(ijk[2]) +
                                        1] = '3 ' + xyz[int(ijk[2]) + 1]
                                    xyz = '\n'.join(xyz)
                            slabel = ob.get_smiles_filename(
                                ob.get_slabel(args.reacs[i]))
                            io.mkdir('geomdir')
                            io.write_file(xyz, 'geomdir/' + slabel + '.xyz')
                            args.restart = 1
                            args.XYZ = 'geomdir'
                            args.xyzstart = '0'
                            log.warning(
                                'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to {}'
                                .format(slabel + '.xyz'))
                        else:
                            log.warning(
                                'Lower configuration found in 1dTau. But has different smiles: {} vs. {}'
                                .format(slabel, ob.get_slabel(args.reacs[i])))
                for l in range(len(args.prods)):
                    lowene = 0.
                    lowenefile = None
                    if io.check_file('me_files/prod' + str(l + 1) + '_hr.me'):
                        hr = io.read_file('me_files/prod' + str(l + 1) +
                                          '_hr.me')
                        hr = hr.split('Rotor')
                        startkey = 'Potential'
                        for j, rotor in enumerate(hr[1:]):
                            pot = rotor.split(startkey)[1]
                            pot = pot.splitlines()[1]
                            for k, ene in enumerate(pot.split()):
                                if float(ene) - lowene < -0.1:
                                    lowene = float(ene)
                                    lowenefile = 'hr_geoms/geom_isp' + str(
                                        i + l + 2).zfill(2) + '_hr' + str(
                                            j + 1).zfill(2) + '_hpt' + str(
                                                k + 1).zfill(2) + '.xyz'
                    if lowenefile:
                        xyz = io.read_file(lowenefile)
                        slabel = ob.get_slabel(ob.get_mol(xyz))
                        if slabel.split('_m')[0] == ob.get_slabel(
                                args.prods[l]).split('_m')[0]:
                            negvals = True
                            slabel = ob.get_smiles_filename(
                                ob.get_slabel(args.prods[l]))
                            io.mkdir('geomdir')
                            io.write_file(xyz, 'geomdir/' + slabel + '.xyz')
                            args.restart = 1
                            args.XYZ = 'geomdir'
                            args.xyzstart = '0'
                            log.warning(
                                'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to {}'
                                .format(slabel + '.xyz'))
                        else:
                            log.warning(
                                'Lower configuration found in 1dTau. But has different smiles: {} vs. {}'
                                .format(slabel, ob.get_slabel(args.prods[l])))
                if args.reactype.lower() in [
                        'addition', 'abstraction', 'isomerization',
                        'addition_well', 'isomerization_well'
                ]:
                    lowene = 0.
                    lowenefile = None
                    if io.check_file('me_files/ts_hr.me'):
                        hr = io.read_file('me_files/ts_hr.me')
                        hr = hr.split('Rotor')
                        startkey = 'Potential'
                        for j, rotor in enumerate(hr[1:]):
                            pot = rotor.split(startkey)[1]
                            pot = pot.splitlines()[1]
                            for k, ene in enumerate(pot.split()):
                                if float(ene) - lowene < -0.1:
                                    lowene = float(ene)
                                    lowenefile = 'hr_geoms/geom_isp00_hr' + str(
                                        j + 1).zfill(2) + '_hpt' + str(
                                            k + 1).zfill(2) + '.xyz'
                    if lowenefile:
                        xyz = io.read_file(lowenefile)
                        negvals = True
                        io.mkdir('geomdir')
                        io.write_file(xyz, 'geomdir/ts.xyz')
                        args.restart = 1
                        args.XYZ = 'geomdir'
                        args.xyzstart = '0'
                        log.warning(
                            'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to ts.xyz'
                        )

                    if args.wellp and args.wellp.lower() != 'false':
                        lowene = 0.
                        lowenefile = None
                        if io.check_file('me_files/wellp_hr.me'):
                            hr = io.read_file('me_files/wellp_hr.me')
                            hr = hr.split('Rotor')
                            startkey = 'Potential'
                            for j, rotor in enumerate(hr[1:]):
                                pot = rotor.split(startkey)[1]
                                pot = pot.splitlines()[1]
                                for k, ene in enumerate(pot.split()):
                                    if float(ene) - lowene < -0.1:
                                        lowene = float(ene)
                                        lowenefile = 'hr_geoms/geom_isp06_hr' + str(
                                            j + 1).zfill(2) + '_hpt' + str(
                                                k + 1).zfill(2) + '.xyz'
                        if lowenefile:
                            xyz = io.read_file(lowenefile)
                            negvals = True
                            io.mkdir('geomdir')
                            io.write_file(xyz, 'geomdir/wellp.xyz')
                            args.restart = 1
                            args.XYZ = 'geomdir'
                            args.xyzstart = '0'
                            log.warning(
                                'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to wellp.xyz'
                            )
                    if args.wellr and args.wellr.lower() != 'false':
                        lowene = 0.
                        lowenefile = None
                        if io.check_file('me_files/wellr_hr.me'):
                            hr = io.read_file('me_files/wellr_hr.me')
                            hr = hr.split('Rotor')
                            startkey = 'Potential'
                            for j, rotor in enumerate(hr[1:]):
                                pot = rotor.split(startkey)[1]
                                pot = pot.splitlines()[1]
                                for k, ene in enumerate(pot.split()):
                                    if float(ene) - lowene < -0.1:
                                        lowene = float(ene)
                                        lowenefile = 'hr_geoms/geom_isp05_hr' + str(
                                            j + 1).zfill(2) + '_hpt' + str(
                                                k + 1).zfill(2) + '.xyz'
                        if lowenefile:
                            xyz = io.read_file(lowenefile)
                            negvals = True
                            io.mkdir('geomdir')
                            io.write_file(xyz, 'geomdir/wellr.xyz')
                            args.restart = 1
                            args.XYZ = 'geomdir'
                            args.xyzstart = '0'
                            log.warning(
                                'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to wellr.xyz'
                            )
            args.jobs = alljobs
        elif "Opt_1" in args.jobs and args.restart < 2:
            log.info("========\nBEGIN LEVEL 1\n========\n")
            alljobs = args.jobs
            args.jobs = ["Opt_1"]
            stoichs, symnums = es.build_files(args, paths)
            es.execute(paths, args.nodes[0])
            if io.check_file('output/estoktp.out'):
                shutil.copy('output/estoktp.out', 'output/estoktp_l1.out')
            args.jobs = alljobs
            args.restart = 2
        if args.anharm.lower() != 'false' and 'd' not in args.nodes[0]:
            import thermo
            log.info("========\nBEGIN VPT2\n========\n")
            optlevel, anlevel = thermo.get_anlevel(args.anharm, args.meths)
            for n, reac in enumerate(args.reacs):
                typ = 'reac'
                natom = ob.get_natom(reac)
                if natom > 2:
                    mult = ob.get_mult(reac)
                    if io.check_file('me_files/' + typ + str(n + 1) +
                                     '_fr.me'):
                        if not 'Anh' in io.read_file('me_files/' + typ +
                                                     str(n + 1) + '_fr.me'):
                            anfr, fr1, anx, fr2, fr3, _ = thermo.get_anharm(
                                typ, str(n + 1), natom, args.nodes[0],
                                anlevel, args.anovrwrt, reac,
                                optlevel.split('/'), paths)
                            lines = io.read_file('me_files/' + typ +
                                                 str(n + 1) + '_fr.me')
                            io.write_file(
                                lines,
                                'me_files/' + typ + str(n + 1) + '_harm.me')
                            lines = fr1 + fr2.split(
                                'End'
                            )[0] + fr3 + '\n !************************************\n'
                            io.write_file(
                                lines,
                                'me_files/' + typ + str(n + 1) + '_fr.me')
            for n, prod in enumerate(args.prods):
                typ = 'prod'
                natom = ob.get_natom(prod)
                if natom > 2:
                    mult = ob.get_mult(prod)
                    if io.check_file('me_files/' + typ + str(n + 1) +
                                     '_fr.me'):
                        if not 'Anh' in io.read_file('me_files/' + typ +
                                                     str(n + 1) + '_fr.me'):
                            anfr, fr1, anx, fr2, fr3, _ = thermo.get_anharm(
                                typ, str(n + 1), natom, args.nodes[0],
                                anlevel, args.anovrwrt, prod,
                                optlevel.split('/'), paths)
                            lines = io.read_file('me_files/' + typ +
                                                 str(n + 1) + '_fr.me')
                            io.write_file(
                                lines,
                                'me_files/' + typ + str(n + 1) + '_harm.me')
                            lines = fr1 + fr2.split(
                                'End'
                            )[0] + fr3 + '\n !************************************\n'
                            io.write_file(
                                lines,
                                'me_files/' + typ + str(n + 1) + '_fr.me')
            if args.reactype and io.check_file('geoms/tsgta_l1.xyz'):
                typ = 'ts'
                mol = io.read_file('geoms/tsgta_l1.xyz')
                ts = ob.get_mol(mol)
                natom = ob.get_natom(ts)
                mult = ob.get_mult(ts)
                if io.check_file('me_files/ts_fr.me'):
                    if not 'Anh' in io.read_file('me_files/ts_fr.me'):
                        anfr, fr1, anx, fr2, fr3, _ = thermo.get_anharm(
                            typ, str(n + 1), natom, args.nodes[0], anlevel,
                            args.anovrwrt, 'ts', optlevel.split('/'), paths)
                        lines = io.read_file('me_files/' + typ + '_fr.me')
                        io.write_file(lines, 'me_files/' + typ + '_harm.me')
                        lines = fr1 + fr2.split(
                            'End'
                        )[0] + fr3 + '\n End\n !************************************\n'
                        io.write_file(lines, 'me_files/' + typ + '_fr.me')
        log.info("========\nBEGIN MDHR, HL\n========\n")
        if 'kTP' in args.jobs:
            alljobs = args.jobs
            args.jobs = []
            for job in alljobs:
                if job != 'kTP':
                    args.jobs.append(job)
            stoichs, symnums = es.build_files(args, paths)
            es.execute(paths, args.nodes[0])
            if io.check_file('me_files/ts_en.me'):
                tsen = float(io.read_file('me_files/ts_en.me'))
                tsen += float(io.read_file('me_files/ts_zpe.me'))
                reacen = 0
                proden = 0
                for i, reac in enumerate(args.reacs):
                    if io.check_file('me_files/reac{}_en.me'.format(i + 1)):
                        reacen += float(
                            io.read_file('me_files/reac{}_en.me'.format(i +
                                                                        1)))
                        reacen += float(
                            io.read_file('me_files/reac{}_zpe.me'.format(i +
                                                                         1)))
                if args.reactype.lower(
                ) == 'addition_well' or args.reactype.lower(
                ) == 'isomerization_well':
                    if io.check_file('me_files/wellp_en.me'):
                        proden += float(io.read_file('me_files/wellp_en.me'))
                        proden += float(io.read_file('me_files/wellp_zpe.me'))
                else:
                    for i, prod in enumerate(args.prods):
                        if io.check_file('me_files/prod{}_en.me'.format(i +
                                                                        1)):
                            proden += float(
                                io.read_file(
                                    'me_files/prod{}_en.me'.format(i + 1)))
                            proden += float(
                                io.read_file(
                                    'me_files/prod{}_zpe.me'.format(i + 1)))
                if tsen <= reacen or tsen <= proden:
                    log.info('Well Depth is negative. NoTunnel is turned on')
                    if args.esoptions:
                        args.esoptions += ',NoTunnel'
                    else:
                        args.esoptions = 'NoTunnel'
            log.info("========\nBEGIN kTP\n========\n")
            args.jobs = alljobs
            restart = 7
            stoichs, symnums = es.build_files(args, paths)
            es.execute(paths, args.nodes[0])
        else:
            stoichs, symnums = es.build_files(args, paths)
            es.execute(paths, args.nodes[0])
    if ("1dTau" in args.jobs or 'MdTau' in args.jobs):
        for i in range(len(args.reacs)):
            es.check_hrs(i + 1, 'reac')
        for i in range(len(args.prods)):
            es.check_hrs(i + 1, 'prod')
        es.me_file_abs_path()

    if args.restart == 10:
        io.execute([paths['bin'] + os.path.sep + 'mess', 'me_ktp.inp'])

    if args.reactype and io.check_file('rate.out'):
        import me_parser
        #initialize the class in which to store the results
        data = me_parser.paper()
        data.reactions = []
        # set some constants, depending upon whether the rate coefficients are to be used for CHEMKIN or something else.
        data.T0 = 1.0
        data.R = 1.987  # cal/mol-K.  Note that PLOG formalism requires Ea in cal/mol-K!
        data.N_avo = 6.0221415E23  #convert bimolecular rate coefficients from cm^3/sec to cm^3/mol/s

        # set the minimum and maximum temperature
        #data.Tmin = 600.0
        #data.Tmax = 1200.0

        # read me.out file from the command line
        me_dot_out = 'rate.out'
        if io.check_file(me_dot_out):
            lines = io.read_file(me_dot_out, True)
            if len(lines) < 2:
                log.info('rate.out is empty')
            ## copy new plog executable to the path of the source file
            #path = os.path.abspath(os.path.dirname(me_dot_out))
            #
            #command = 'cp /home/elliott/bin/dsarrfit.x_cfg ' + path
            #log.info( command)
            #os.system(command)
            # parse results for the temperature, pressure, and names of channels
            me_parser.get_temp_pres(data, lines)
            # parse results for the pdep rate constants
            me_parser.get_pdep_k(data, lines)
            # fit the results to PLOG expressions
            me_parser.fit_pdep(
                data, nonlin_fit=False
            )  #replace <True> with <False> if you don't want to use the nonlinear solver (not recommended)
            # print the resulting PLOG expressions to file
            me_parser.print_plog(data, me_dot_out)
            # plot the results: dashed line = single PLOG, solid line = double PLOG
            #me_parser.plot_reactant(data, me_dot_out, show_plot=False, save_plot=True)

    #######  Parse results  #########
    ########################################
    import results
    rs = results.RESULTS(args, paths)
    args.hlen = rs.get_hlen()
    args.optlevel = rs.optlevel
    args.enlevel = rs.enlevel
    args.taulevel = rs.taulevel

    if args.parseall.lower() == 'true' or args.alltherm.lower() == 'true':
        rs.get_results()
    #######  Build and run thermo  #########
    ########################################
    import thermo
    rs.thermo = False
    if args.alltherm.lower() == 'true':
        rs.thermo = True
        args.symnums = symnums
        rs.dH0, rs.dH298, rs.hfbases, rs.anfreqs, rs.anxmat = thermo.run(
            args, paths, rs.d)
        if args.parseall.lower() == 'true':
            rs.get_thermo_results()
    return