예제 #1
0
    def setUp(self):
        self.freeh = Freeh(modvals={"tstart": "200", "tend": "250"})
        self.freehfile = """          ------------------
           your wishes are :
          ------------------

  pstart=  0.1000E+00  pend=  0.1000E+00  nump=   1

  tstart=   298.1      tend=   298.1      numt=   1
 
           zero point vibrational energy
           -----------------------------
           zpe=   481.3     kJ/mol
 
   T        p       ln(qtrans) ln(qrot) ln(qvib) chem.pot.   energy    entropy
  (K)      (MPa)                                 (kJ/mol)   (kJ/mol) (kJ/mol/K)
 
 298.15   0.1000000      19.81    15.66    15.89    353.99    530.06   0.59886
 
   T        P              Cv            Cp       enthalpy
  (K)     (MPa)        (kJ/mol-K)    (kJ/mol-K)   (kJ/mol)
 298.15   0.1000000     0.2849985     0.2933128    532.54
 
"""
        write_file("testfreeh", self.freehfile.split("\n"))
예제 #2
0
def submit_job(job, script=None):
    """Submit the specified job to queue for calculation"""

    logging.debug("Submitting job to queue")

    if not script:
        try:
            script = turbogo_helpers.read_clean_file("submitscript.sge")
        except turbogo_helpers.FileAccessError:
            raise turbogo_helpers.FileAccessError
    # submit job in Popen pipe and get job number back.
    p = Popen("qsub", stdin=PIPE, stdout=PIPE)
    poutput, perr = p.communicate(input=script)
    if "has been submitted" in poutput:
        jobid = poutput.split("\n")[0].split(" ")[2]
        if turbogo_helpers.is_int(jobid):
            job.jobid = jobid
            logging.info("Job {} with job id {} submitted".format(job.name, jobid))
            turbogo_helpers.write_file("jobid", ["{}: {}".format(job.jobtype, jobid)])
        else:
            job.jobid = None
            logging.warning("Job id unknown.")
    else:
        job.jobid = None
        logging.warning("Error starting job. qsub output: \n{}".format(poutput))
    return job.jobid
예제 #3
0
def ensure_not_ts(job):
    """
    This runs to read out the vibrational modes. If there are negatives, runs
    screwer to adjust the geometry along the imaginary coordinate, and
    resubmits job.
    """
    if job.freqopt == 'numforce':
        newdir = os.path.join(job.indir, 'numforce')
    else:
        newdir = job.indir
    filetoread = os.path.join(newdir, 'control')

    controlfile = turbogo_helpers.read_clean_file(filetoread)

    vib1 = False

    for i in range(len(controlfile)):
        if '$vibrational spectrum' in controlfile[i]:
            for j in range (i+3, len(controlfile)):
                col = controlfile[j][15:34].strip()
                if not (col == '0.00' or col == '-0.00'):
                    try:
                        vib1 = float(col)
                    except ValueError:
                        pass
                    else:
                        mode = controlfile[j][:6].strip()
                        break
        if vib1:
            break

    if vib1:
        if job.firstfreq == vib1:
            #Found the same TS as before. End job.
            return 'same'
        job.firstfreq = vib1
        if vib1 < 0:
            os.chdir(newdir)
            screwer = Screwer(mode)
            try:
                screwer.run_screwer()
            except Exception as e:
                logging.warning("Error '{}' running screwer on job {}.".format(
                    e, job.name))
                os.chdir(TOPDIR)
                return "error"
            control = turbogo_helpers.read_clean_file('control')
            newcoord = list()
            readin = False
            for line in control:
                if '$newcoord' in line:
                    readin = -1
                elif '$end' in line:
                    readin = False
                if readin:
                    newcoord.append(line)
                elif readin == -1:
                    readin = True
            if job.freqopt == 'numforce':
                os.chdir(os.pardir)
                turbogo_helpers.write_file('coord', newcoord)
                try:  # Better to remove numforce, if not no biggie
                    os.remove(os.path.join(os.curdir, 'control'))
                    shutil.rmtree(os.path.join(os.curdir, 'numforce'))
                except OSError:
                    pass
            try:
                job.jobid, job.freqopt, job.name, job.jobtype = jobrunner(job=self.job)
                job.curstart = time()
            except Exception as e:
                logging.warning("Error {} resubmitting job {}.".format(
                    e, job.name))
                os.chdir(TOPDIR)
                return 'error'
            os.chdir(TOPDIR)
            return 'opt'
        else:
            return 'completed'
    else:
        logging.warning(
            'Error getting vibrational frequencies from job {}.'.format(
            job.name
        ))
        return 'error'
예제 #4
0
    def setUp(self):
        os.mkdir("testdir")
        os.chdir("testdir")
        os.mkdir("indir-good1")
        os.mkdir("indir-good2")
        os.mkdir("indir-badfile3")
        os.mkdir("indir-nofile4")
        os.mkdir("indir-twofile5")
        os.mkdir("indir-deep")
        os.mkdir(os.path.join("indir-deep", "deepdir"))
        self.infile = """%nproc=8
%mem=100MW
%arch=GA
%maxcycles=200
# Opt ri marij b3-lyp/TZVP

Test Infile

0 1
C -10.14896312689057 1.75782324146904 -0.2949862481115
C -8.99358457406949 2.76561418392812 1.85268749294372
C -6.82890329788933 1.622707823532 2.83855761235287
C -5.82243516371775 -0.51249372509826 1.62856597451948

$ricore 0
$ricore_slave 1
-$marij

"""
        os.chdir("indir-good1")
        write_file("input1.in", self.infile.split("\n"))
        os.chdir(os.pardir)
        os.chdir("indir-good2")
        write_file("input2.in", self.infile.split("\n"))
        os.chdir(os.pardir)
        os.chdir("indir-badfile3")
        write_file("input3.in", ["this is a bad file", "booya"])
        os.chdir(os.pardir)
        os.chdir("indir-twofile5")
        write_file("input5a.in", self.infile.split("\n"))
        write_file("input5b.in", self.infile.split("\n"))
        os.chdir(os.pardir)
        os.chdir("indir-deep")
        os.chdir("deepdir")
        write_file("input6.in", self.infile.split("\n"))
        os.chdir(os.pardir)
        os.chdir(os.pardir)
예제 #5
0
def submit_script_prepare(job, filename="submitscript.sge"):
    """Write a submit script for gridengine for the job."""

    logging.debug("Preparing gridengine submit script")

    # NPROC has to be one less for MPI jobs
    nproc = job.nproc
    if job.para_arch == "MPI":
        nproc = nproc - 1

    env_mod = ""
    # env = turbogo_helpers.check_env()
    # if env:
    #    logging.warn("Env vars not set. Attempting to fix via submit script")
    #    for key in env:
    #        env_mod += "export {}={}\n".format(key, env[key])

    # Set up the parallel preamble. No parallel arch info if numforce
    if job.jobtype != "numforce":
        preamble_template = """export PARA_ARCH={para_arch}\n""".format(para_arch=job.para_arch)
    else:
        preamble_template = ""

    preamble_template += """export MPI_IC_ORDER="TCP"
export PARNODES={nproc}
cat $PE_HOSTFILE | awk '{{for(i=0;i<$2;i++) print $1}}' > hosts_file
export HOSTS_FILE=`readlink -f hosts_file`
""".format(
        nproc=nproc
    )

    if job.nproc > 1:
        parallel_preamble = preamble_template
    else:
        parallel_preamble = ""

    # set up the job command call itself
    if job.jobtype == "opt" or job.jobtype == "optfreq":
        jobcommand = "jobex"
        jobcommand += " -c {}".format(job.iterations)
        if job.ri:
            jobcommand += " -ri"
        # add making xyz sp geom and opt trajectory xyz files after jobex
        jobcommand += " > opt.out"
        jobcommand += "\nt2x > optimization.xyz\nt2x -c > final_geometry.xyz"

    elif job.jobtype == "aoforce":
        jobcommand = "aoforce"
        jobcommand += " > aoforce.out"

    elif job.jobtype == "numforce":
        jobcommand = "NumForce -central"
        if job.ri:
            jobcommand += " -ri"
        if job.nproc > 1:
            jobcommand += " -mfile hosts_file"
        jobcommand += " > numforce.out"

    elif job.jobtype == "sp":
        if job.ri:
            jobcommand = "ridft"
        else:
            jobcommand = "dscf"
        jobcommand += " > sp.out"

    elif job.jobtype == "ts":
        if job.ri:
            jobcommand = "ridft\nrdgrad\njobex -trans -ri"
        else:
            jobcommand = "dscf\ngrad\njobex -trans"
        if job.iterations:
            jobcommand += " -c {}".format(job.iterations)
        jobcommand += " > ts.out"
        jobcommand += "\nt2x > optimization.xyz\nt2x -c > final_geometry.xyz"

    logging.debug("Job submit script: {} completed.".format(jobcommand.replace("\n", " & ")))

    # make one big sumbit script
    # runs the jobcommand
    submit_script = """#!/bin/bash
#$ -cwd
#$ -V
#$ -j y
#$ -o {jobname}.stdout
#$ -N tm.{jobname}
#$ -l h_rt={rt}
#$ -R y
#$ -pe threaded {nproc}
{env_mod}
{parallel_preamble}
source $TURBODIR/Config_turbo_env

ulimit -s unlimited

touch startfile

{jobcommand}
""".format(
        jobname=turbogo_helpers.slug(job.name),
        nproc=job.nproc,
        parallel_preamble=parallel_preamble,
        jobcommand=jobcommand,
        env_mod=env_mod,
        rt=job.rt,
    )

    # listify script by lines and write lines to file
    try:
        turbogo_helpers.write_file(filename, submit_script.split("\n"))
    except turbogo_helpers.FileAccessError:
        logging.warning("Error writing submit script to file.")
    logging.debug("Submit script generated at {}.".format(filename))
    return submit_script
예제 #6
0
def write_coord(job, filename="coord"):
    """Write the coord file"""
    job.geometry.insert(0, "$coord")
    job.geometry.append("$end")
    turbogo_helpers.write_file(filename, job.geometry)
    logging.debug("File {} written.".format(filename))