Example #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
Example #2
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
Example #3
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
Example #4
0
def run_pac99(formula, pac99='pac99'):
    """
    Run pac99 for a given species name (formula)
    https://www.grc.nasa.gov/WWW/CEAWeb/readme_pac99.htm
    requires formula+'i97' and new.groups files
    TODO: Maybe add delete empty files
    linus
    pac99='/tcghome/sjk/gen/aux_me/therm/pac99.x'
    """
    from subprocess import Popen, PIPE
    import iotools as io
    msg = ''
    c97file = formula + '.c97'
    i97file = formula + '.i97'
    o97file = formula + '.o97'
    if io.check_exe(pac99):
        if io.check_file(i97file):
            if io.check_file('new.groups'):
                if io.check_exe(pac99):
                    p = Popen(pac99, stdin=PIPE)
                    p.communicate(formula)
                else:
                    msg += 'pac99 not found.\n'
                    return msg
            else:
                msg += 'new.groups file is required to run pac99.\n'
        else:
            msg += '{0} file not found.\n'.format(i97file)

    else:
        msg += '{0} file not found.\n'.format(pac99)
    if io.check_file(c97file) and io.check_file(o97file):
        msg += "{0} {1} files are written.\n".format(c97file, o97file)
    return msg
Example #5
0
def check_hrs(n, typ):
    """
    Checks MC geoms to make sure they are the same inchii as the starting species
    """
    import sys
    import iotools as io

    msg = 'Checking me_files/{1}{0}_hr.me'.format(str(n), typ)

    filename = 'data/' + typ + str(n) + '.dat'
    nrotors = 0
    md = False
    if io.check_file(filename):
        data = io.read_file(filename)
        tmp = data.split('nhind')
        if len(tmp) > 2:
            nrotors = tmp[1].split('\n')[1]
        if len(tmp) > 3:
            md = True

    data = ''
    filename = 'me_files/' + typ + str(n) + '_hr.me'
    if io.check_file(filename):
        data = io.read_file(filename)
    else:
        msg = '\nNo hr me_file found'
        log.error(msg)
        return

    if md:
        if 'MultiRotor' in data:
            msg = '\nMDTau successfully completed'
            log.info(msg)
        else:
            msg = '\nMD scan incomplete'
            log.error(msg)
        filename = 'me_files/' + typ + str(n) + '_1dhr.me'
        if io.check_file(filename):
            data = io.read_file(filename)
        else:
            msg += '\nNo 1dhr me_file found'
            log.error(msg)
            return

    data = data.split('Rotor')
    ncomplete = len(data) - 1
    msg = '\n{0} out of {1} rotors successfully scanned'.format(
        str(ncomplete), nrotors)
    if int(nrotors) == ncomplete:
        msg = '\n1DTau has completed successfully'
    else:
        msg = '\nScan incomplete'
        log.error(msg)
    log.info(msg)
    return
Example #6
0
def run(s):
    """
    A driver function to run quantum chemistry and thermochemistry calculations based
    on command line options:
    --qcmethod
    --qccode
    """
    import qctools as qc
    import obtools as ob
    import tctools as tc
    import iotools as io
    mol = ob.get_mol(s)
    mult = ob.get_multiplicity(mol)
    dirpath = ob.get_unique_path(mol, method=_qcmethod, mult=mult)
    groupsfile = 'new.groups'
    io.mkdir(dirpath)
    cwd = io.pwd()
    if _runthermo:
        if io.check_file(groupsfile):
            io.cp(groupsfile, dirpath)
            if not io.check_file(groupsfile, 1):
                print 'Could not copy new.groups file to target directory {0}'.format(
                    dirpath)
                return -1
        else:
            print 'new.groups file required in working directory'
            return -1
    if io.check_dir(dirpath, 1):
        io.cd(dirpath)
    else:
        print 'I/O error, {0} directory not found'.format(dirpath)
        return -1
    if _runqc:
        if _qccode == 'mopac':
            outstr = qc.run_mopac(s,
                                  mopacexe=_mopacexe,
                                  method=_qcmethod,
                                  mult=mult)
            outfile = outstr.split(' : ')[0]
            if _runthermo:
                lines = io.read_file(outfile, aslines=True)
                xyz = qc.get_mopac_xyz(lines)
                freqs = qc.get_mopac_freq(lines)
                zpe = qc.get_mopac_zpe(lines)
                deltaH = qc.get_mopac_deltaH(lines)
                get_chemkin_polynomial(mol, _qcmethod, zpe, xyz, freqs, deltaH)
    io.cd(cwd)
    return outstr
Example #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
Example #8
0
def parse_qclog_cclib(qclog,anharmonic=False):
    xyz = None
    freqs = None
    zpe = None
    deltaH = None
    xmat = None
    afreqs = None
    msg =''
    if io.check_file(qclog, 1):
        s = io.read_file(qclog, aslines=False)
    else:
        msg = 'File not found: "{0}"\n'.format(io.get_path(qclog))
        return msg,xyz,freqs,zpe,deltaH,afreqs,xmat
    if check_output(s):
        if cclib:
            ccdata = parse_cclib(qclog)
            xyz = ccdata.writexyz()
            try:
                freqs = ccdata.vibfreqs
                freqs = get_listofstrings(freqs)
                nfreq = len(freqs)
            except AttributeError:
                pass
            try:
                deltaH = ccdata.enthalpy
            except AttributeError:
                pass
            if anharmonic:
                xmat = ccdata.vibanharms
                afreqs = get_gaussian_fundamentals(s, nfreq)[:,1]
                afreqs = get_listofstrings(afreqs)
    else:
        msg = 'Failed job: "{0}"\n'.format(io.get_path(qclog))

    return msg,xyz,freqs,zpe,deltaH,afreqs,xmat
Example #9
0
 def parse_thermo(self, n, species, d):
     printstr = '\n=====================\n          '+species+'\n=====================\n'
     optprog, optmethod, optbasis = self.optlevel.split('/')
     if self.enlevel == 'optlevel':
         prog   =  optprog
         method =  optmethod
         basis  =  optbasis
     else:
         prog, method, basis = self.enlevel.split('/') 
     d[  'prog'] = prog
     d['method'] = method
     d[ 'basis'] = basis
     if self.args.anharm != 'false':
         anpfr     = ', '.join('%4.4f' % freq for freq in self.anfreqs[n-1])
         pxmat     =('\n\t'.join(['\t'.join(['%3.3f'%item for item in row]) 
                     for row in self.anxmat[n-1]]))
         printstr += '\nAnharmonic Frequencies  (cm-1):\t' + anpfr
         printstr += '\nX matrix:\n\t' + pxmat #+   anxmat[i-1]
         d['panharm'] = anpfr
         d[  'pxmat'] = pxmat
     printstr += '\nHeat of formation(  0K): {0:.2f} kcal / {1:.2f}  kJ\n'.format(self.dH0[n-1],   self.dH0[n-1]/.00038088/ 627.503)
     printstr +=   'Heat of formation(298K): {0:.2f} kcal / {1:.2f}  kJ\n'.format(float(self.dH298[n-1]), float(self.dH298[n-1])/.00038088/ 627.503)
     d[   'dH0K'] = self.dH0
     d[ 'dH298K'] = self.dH298
     if self.args.store:
         database = self.args.database 
         if self.args.anharm != 'false':
             anprog, anmethod, anbasis = anlevel.split('/')
             io.db_store_sp_prop(anpfr, species, 'panhrm', database,  anprog, anmethod, anbasis, optprog, optmethod, optbasis)
             io.db_store_sp_prop(pxmat, species,  'pxmat', database,  anprog, anmethod, anbasis, optprog, optmethod, optbasis) 
         if not io.check_file(io.db_sp_path(prog, method, basis, database, species, optprog, optmethod, optbasis) + '/' + species + '.hf298k'):
             io.db_store_sp_prop('Energy (kcal)\tBasis\n----------------------------------\n',species,'hf298k',database, prog,method,basis, optprog, optmethod, optbasis)
         if len(self.hfbases) >= n+1:
             io.db_append_sp_prop(str(self.dH298[n-1]) + '\t' + ', '.join(self.hfbases[n]) + '\n', species, 'hf298k',database, prog,method,basis, optprog, optmethod, optbasis)
     return printstr, d
Example #10
0
def run_pf(messpf='messpf', inputfile='pf.inp'):
    """
    Runs mess to generate partition function
    Requires an input file,i.e. pf.inp.
    '/tcghome/ygeorgi/fock/crossrate/bin/partition_function'
    Output is input_prefix + ".log"
    e.g.
    Temperature(step[K],size)        100.   30
    RelativeTemperatureIncrement            0.001
    Species   C2H3
    RRHO
    Geometry[angstrom]     5   ! CCSD(T)/cc-pVQZ
    C          0.0000000000        0.0229607853       -0.6194779279
    C          0.0000000000       -0.0846208019        0.6897727967
    H          0.0000000000        0.9977802761       -1.1068370147
    H          0.0000000000       -0.8465433753       -1.2673164024
    H          0.0000000000        0.5835275291        1.5364927734
    Core     RigidRotor
    SymmetryFactor       1
    End
    Frequencies[1/cm]      9   ! CCSD(T)/CBS; anh
    692    796    894    1019    1353    1580    2895    3023    3114
    ZeroEnergy[kcal/mol]            -34.41  ! ANL1
    ElectronicLevels[1/cm]        1
    0   2
    End
    """
    import subprocess
    import iotools as io
    msg = ''
    if io.check_exe(messpf):
        if io.check_file(inputfile, 1):
            if io.check_exe(messpf):
                subprocess.call([messpf, inputfile])
                if io.check_file('pf.log', 1):
                    msg += '{0} generated by mess.\n'.format(inputfile)
            else:
                msg += 'Mess executable not found {0}\n'.format(messpf)
                return msg
        else:
            msg += "{0} input file does not exist.\n".format(inputfile)

    else:
        msg += "{0} mess partitition function executable does not exist.\n".format(
            messpf)
    return msg
Example #11
0
def getcc_xyz(out):
    if type(out) is not cclib.parser.data.ccData_optdone_bool:
        if io.check_file(out, 1):
            ccdata = parse_cclib(out)
        else:
            return '{0} not found'.format(out)
    else:
        ccdata = out
    return ccdata.writexyz()
Example #12
0
    def get_results(self):

       msg = printheader()
       d = {}
       for i,reac in enumerate(self.args.reacs, start=1):
           lines  = ''
           if io.check_file('geoms/reac' + str(i) + '_l1.log'):
               lines   = io.read_file('geoms/reac' + str(i) + '_l1.log')
           lines2  = ''
           if io.check_file('me_files/reac' +  str(i) + '_fr.me'):
               lines2  = io.read_file('me_files/reac' +  str(i) + '_fr.me')
           if lines:
               printstr, d[reac] = self.parse(i, reac, lines, lines2)
               msg += printstr
           else:
               log.warning('No geom for ' + reac + ' in geoms/reac' + str(i) + '_l1.log')
       for j,prod in enumerate(self.args.prods, start=1):
           lines  = ''
           if io.check_file('geoms/prod' + str(i) + '_l1.log'):
               lines = io.read_file('geoms/prod' + str(j) + '_l1.log')
           lines2 = ''
           if io.check_file('me_files/reac' +  str(j) + '_fr.me'):
               lines2  = io.read_file('me_files/prod' +  str(j) + '_fr.me')
           if lines:
               printstr, d[prod] = self.parse(i+j-1, prod, lines, lines2)
               msg += printstr
           else:
               log.warning('No geom for ' + prod + '  in geoms/prod' + str(j) + '_l1.log')

       #if args.nTS > 0:
       #    lines = io.read_file('geoms/tsgta_l1.log')
       #    printstr += ts_parse(0,lines)
       #    if args.nTS > 1:
       #        lines = io.read_file('geoms/wellr_l1.log')
       #        printstr += ts_parse(1,lines)
       #        if args.nTS > 2:
       #            lines = io.read_file('geoms/wellp_l1.log')
       #            printstr += ts_parse(2,lines)
       log.info(msg)
       self.d = d
       return 
Example #13
0
def run_thermp(thermpinput,
               thermpfile='thermp.dat',
               pffile='pf.log',
               thermpexe='thermp'):
    """
    Runs thermp.exe
    Requires pf.dat and thermp.dat files to be present
    linus
    /tcghome/sjk/gen/aux_me/therm/thermp.exe
    """
    import iotools as io
    msg = ''
    io.write_file(thermpinput, thermpfile)
    if not io.check_file(thermpfile, 1):
        return "{0} file not found.\n".format(thermpfile)
    pfdat = pffile.replace('log', 'dat')
    io.mv(pffile, pfdat)
    if io.check_file(pfdat, 1):
        msg += io.execute(thermpexe)
    else:
        msg += "{0} file not found.\n".format(pffile)
    return msg
Example #14
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
Example #15
0
    def get_hlen(self):

        hlen     = []
        msg = ''
        for i in range(len(self.args.reacs)):
            if io.check_file('me_files/reac'+str(i+1) + '_en.me'):
                hlen.append(float(io.read_file('me_files/reac'+str(i+1) + '_en.me')))
                for meth in self.args.meths:
                    if 'hlevel' in meth:
                        self.enlevel = '{}/{}'.format(meth[1],meth[2])
            else:
               msg += 'No energy found for reac{:g}\n'.format(i+1)

        for i in range(len(self.args.prods)):
            if io.check_file('me_files/prod'+str(i+1) + '_en.me'):
                hlen.append(float(io.read_file('me_files/prod'+str(i+1) + '_en.me')))
            else:
               msg += 'No energy found for prod{:g}\n'.format(i+1)

        if self.args.reactype:
            if io.check_file('me_files/ts_en.me'):
                hlen.append(float(io.read_file('me_files/ts_en.me')))
            else:
                msg += 'No energy found for ts\n'
            if self.args.wellr and self.args.wellr.lower() != 'false':
                if io.check_file('me_files/wellr_en.me'):
                    hlen.append(float(io.read_file('me_files/wellr_en.me')))
                else:
                   msg += 'No energy found for wellr\n'
            if self.args.wellp and self.args.wellp.lower() != 'false':
                if io.check_file('me_files/wellp_en.me'):
                    hlen.append(float(io.read_file('me_files/wellp_en.me')))
                else:
                   msg += 'No energy found for wellp\n'
        log.warning(msg)
        self.hlen = hlen
        return hlen
Example #16
0
def me_file_abs_path():
    """
    Replaces relative path in mdhr file with absolute path
    """
    import iotools as io
    if io.check_file('me_files/reac1_hr.me'):
        lines = io.read_file('me_files/reac1_hr.me')
        if "PotentialEnergySurface[kcal/mol]" in lines:
            before, after = lines.split("PotentialEnergySurface[kcal/mol]")
            after = after.split('\n')
            after[0] = after[0].replace('./', io.pwd() + '/')
            lines = before + "PotentialEnergySurface[kcal/mol]" + '\n'.join(
                after)
            io.write_file(lines, 'me_files/reac1_hr.me')
    return
Example #17
0
def parse_qclog_as_dict(qclog,qccode='gaussian',anharmonic=False):

    xyz = None
    freqs = None
    zpe = None
    deltaH = None
    xmat = None
    afreqs = None
    basis = None
    method = None
    msg =''
    if io.check_file(qclog, 1):
        s = io.read_file(qclog, aslines=False)
    else:
        msg = 'File not found: "{0}"\n'.format(io.get_path(qclog))
        return msg,xyz,freqs,zpe,deltaH,afreqs,xmat
    lines = s.splitlines()
    if check_output(s):
        try:
            if qccode == 'gaussian':
                mol = ob.get_gaussian_mol(qclog)
                zpe = mol.energy
                if cclib:
                    ccdata = parse_cclib(qclog)
                    xyz = ccdata.writexyz()
                    freqs = ccdata.vibfreqs
                    freqs = get_listofstrings(freqs)
                    nfreq = len(freqs)
                    deltaH = ccdata.enthalpy
                    if anharmonic:
                        xmat = ccdata.vibanharms
                        afreqs = get_gaussian_fundamentals(s, nfreq)[:,1]
                        afreqs = get_listofstrings(afreqs)

            elif qccode == 'mopac':
                xyz = get_mopac_xyz(lines)
                freqs = get_mopac_freq(lines)
                freqs = get_listofstrings(freqs)
                zpe = get_mopac_zpe(lines)
                deltaH = get_mopac_deltaH(lines)
        except:
            msg = 'Parsing failed for "{0}"\n'.format(io.get_path(qclog))
            return msg,xyz,freqs,zpe,deltaH,afreqs,xmat
    else:
        msg = 'Failed job: "{0}"\n'.format(io.get_path(qclog))

    return msg,xyz,freqs,zpe,deltaH,afreqs,xmat
Example #18
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)
Example #19
0
def write_thermp_input(formula,
                       deltaH,
                       enthalpyT=0.,
                       breakT=1000.,
                       filename='thermp.dat'):
    """
    Write thermp input file with given formula string, deltaH float
    e.g.
    1, 0
    Nwell, Nprod
    30
    nt
    71.82    0.                          //enthalpy at specified T (in kcal/mol), with T = 0 or 298 K
    C2H3                                    //name of species
    C  2                                    //composition in terms of
    H  3                                    //element_name  element_count
    **
    1000.                                   //temperature to break the fit
    """
    nH = get_stoichometry(formula, 'H')
    nC = get_stoichometry(formula, 'C')
    nN = get_stoichometry(formula, 'N')
    nO = get_stoichometry(formula, 'O')
    with open(filename, 'w') as f:
        f.write('1, 0\n')
        f.write('Nwell, Nprod\n')
        f.write('30\n')
        f.write('nt\n')
        f.write('{0} {1}\n'.format(deltaH, enthalpyT))
        f.write('{0}\n'.format(formula))
        if nC > 0:
            f.write('C {0}\n'.format(nC))
        if nH > 0:
            f.write('H {0}\n'.format(nH))
        if nO > 0:
            f.write('O {0}\n'.format(nO))
        if nN > 0:
            f.write('N {0}\n'.format(nN))
        f.write('**\n')
        f.write('{0}'.format(breakT))
    if io.check_file(filename, 1):
        msg = 'Thermp input file "{0}" written.\n'.format(filename)
    else:
        msg = 'Failed writing thermp input file "{0}".\n'.format(filename)
    return msg
Example #20
0
File: anharm.py Project: keceli/QTC
def run_gauss(filename, node):
    """
    Executes Guassian
    INPUT:
    filename - name of Guassian input file
    node     - node to run it on
    """
    if io.check_file(filename):
        executea = 'soft add +gcc-5.3; soft add +g09; g09 ' + filename
        executeb = 'cd `pwd`; export PATH=$PATH:~/bin; '
        ssh = '/usr/bin/ssh'
        host = node
        if str(host) == '0':
            os.system(executea)
        else:
            os.system('exec ' + ssh + ' -n ' + host +
                      ' \"' + executeb + executea + '\"')

    return
Example #21
0
def check_geoms(qtc, name, nsamps):
    """
    Checks MC geoms to make sure they are the same inchii as the starting species
    """
    import sys
    sys.path.insert(0, qtc)
    import iotools as io
    import obtools as ob

    msg = 'Checking level0 geometries'
    log.debug(msg)
    n = 2
    filename = 'geoms/' + name + '_' + '1'.zfill(n) + '.xyz'
    lowfilename = filename
    coords = io.read_file(filename)
    lowcoords = coords
    mol = ob.get_mol(coords)
    inchi = ob.get_inchi_key(mol)
    energy = float(coords.split('\n')[1])
    for i in range(2, int(nsamps) + 1):
        filename = 'geoms/' + name + '_' + '{}'.format(i).zfill(n) + '.xyz'
        log.info(filename)
        if io.check_file(filename):
            coords = io.read_file(filename)
            mol = ob.get_mol(coords)
            if inchi == ob.get_inchi_key(mol):
                if float(coords.split('\n')[1]) < energy:
                    energy = float(coords.split('\n')[1])
                    log.info('Lower energy of {:.2f} found in {}'.format(
                        energy, filename))
                    lowcoords = coords
                    lowfilename = filename
            else:
                log.info(
                    'Connectivity change after torsional optimization. (InChI mismatch) in {}.'
                    .format(filename))
    io.cp(lowfilename, 'torsopt.xyz')
    #io.write_file("\n".join(lowcoords.split("\n")),'geom.xyz')
    io.write_file("\n".join(lowcoords.split("\n")[2:]), 'geom.xyz')
    msg = '\nMonte Carlo sampling successfully found geom.xyz!\n'
    log.info(msg)
    return lowfilename
Example #22
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
Example #23
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
Example #24
0
     parameters['parseqc'] = True
 parameters['qctemplate'] = io.get_path(args.qctemplate)
 parameters['qcexe'] = io.get_path(args.qcexe, executable=True)
 parameters['qcscript'] = io.get_path(args.qcscript)
 parameters['mopac'] = io.get_path(args.mopac, executable=True)
 parameters['nwchem'] = io.get_path(args.nwchem, executable=True)
 parameters['gaussian'] = io.get_path(args.gaussian, executable=True)
 parameters['molpro'] = io.get_path(args.molpro, executable=True)
 parameters['messpf'] = io.get_path(args.messpf, executable=True)
 parameters['thermp'] = io.get_path(args.thermp, executable=True)
 parameters['pac99'] = io.get_path(args.pac99, executable=True)
 beginindex = args.first
 endindex = args.last
 inp = args.input
 nproc = args.nproc
 if io.check_file(inp):
     mylist = io.read_list(inp)
 else:
     mylist = inp.split(',')
 if endindex:
     mylist = mylist[beginindex:endindex]
 else:
     mylist = mylist[beginindex:]
 print(__logo__)
 print("QTC: Date and time           = {0}".format(io.get_date()))
 print("QTC: Last update             = {0}".format(__updated__))
 print("QTC: Number of processes     = {0}".format(nproc))
 print("QTC: Hostname                = {0}".format(gethostname()))
 print('QTC: Given arguments         =')
 for param in parameters:
     print('                             --{0:20s}\t{1}'.format(
Example #25
0
def run_zero(args, paths, ists=False, restartts=False):
    stoichs, symnums = build_files(args, paths, ists, len(args.nodes),
                                   restartts)
    successful = True
    if not 'd' in args.nodes[0]:
        if len(args.nodes) > 1:
            import time
            for i, node in enumerate(args.nodes):
                if not ists:
                    io.rmrf(node)
                    io.mkdir(node)
                    io.cd(node)
                    shutil.copytree('../data', 'data')
                else:
                    io.cd(node)
                    shutil.copy('../data/estoktp.dat', 'data/estoktp.dat')
                    for i in range(len(args.reacs)):
                        filename = 'output/reac' + str(i + 1) + '_opt.out'
                        if io.check_file('../' + filename):
                            shutil.copy('../' + filename, filename)
                time.sleep(5)
                execute(paths, node, '&')
                io.cd('..')
            running = True
            outlength = {}
            for node in args.nodes:
                outlength[node] = 0
            while (running):
                running = False
                for node in args.nodes:
                    filename = node + '/geom.log'
                    if not io.check_file(filename):
                        running = True
                        #log.debug( 'waiting on node {}'.format(node))
                    else:
                        lines = io.read_file(filename)
                        newlength = len(lines)
                        if 'termination' in lines and newlength == outlength[
                                node]:
                            pass
                        else:
                            running = True
                            outlength[node] = newlength
                            #log.debug( 'waiting on node {}'.format(node))
                time.sleep(30)
            log.info('Jobs Completed')
            io.mkdir('geoms')
        else:
            execute(paths, args.nodes[0])
        j, k = gather_mcgeoms(args.nodes)
        for i in range(len(args.reacs)):
            filename = check_geoms(paths['qtc'], 'reac' + str(i + 1), j[i])
            filename = filename.split('/')[1].split(
                '_')[0] + '_opt_' + filename.split('_')[1]
            filename = 'output/' + filename.replace('.xyz', '.out')
            shutil.copy(filename, 'output/reac' + str(i + 1) + '_opt.out')
        for i in range(len(args.prods)):
            filename = check_geoms(paths['qtc'], 'prod' + str(i + 1), j[i + 2])
            filename = filename.split('/')[1].split(
                '_')[0] + '_opt_' + filename.split('_')[1]
            filename = 'output/' + filename.replace('.xyz', '.out')
            shutil.copy(filename, 'output/prod' + str(i + 1) + '_opt.out')
        if ists:
            if not io.check_file('geoms/ts_01.xyz'):
                successful = False
            if io.check_file('output/ts_opt_01.out'):
                shutil.copy('output/ts_opt_01.out', 'output/ts_opt.out')
        #    filename = filename.split('/')[1].split('_')[0] + '_opt_' +  filename.split('_')[1]
        #    filename = 'output/' + filename.replace('.xyz','.out')
        #    shutil.copy(filename, 'output/ts_opt.out')
        #    if args.wellp and args.wellp.lower() != 'false' and 'find' not in args.wellp.lower():
        #        filename = check_geoms(paths['qtc'], 'wellp', j[6])
        #        filename = filename.split('/')[1].split('_')[0] + '_opt_' +  filename.split('_')[1]
        #        filename = 'output/' + filename.replace('.xyz','.out')
        #        shutil.copy(filename, 'output/wellp_opt.out')
        #    if args.wellr and args.wellr.lower() != 'false' and 'find' not in args.wellr.lower():
        #        filename = check_geoms(paths['qtc'], 'wellr', j[5])
        #        filename = filename.split('/')[1].split('_')[0] + '_opt_' +  filename.split('_')[1]
        #        filename = 'output/' + filename.replace('.xyz','.out')
        #        shutil.copy(filename, 'output/wellr_opt.out')
    return successful
Example #26
0
def build_files(args, paths, ists=False, nodes=1, restartts=False):
    """
    Runs the build functions for reacn.dat, prodn.dat, theory.dat, and estoktp.dat
    Requirements: QTC, Openbabel, Pybel (OR prepared cartesian coordinate files) and x2z
    """

    import sys
    sys.path.insert(0, paths['qtc'])
    global io, ob
    import patools as pa
    import iotools as io
    import obtools as ob

    build_subdirs()
    os.chdir('./data')
    stoichs = []
    symnums = []
    mdtype = args.mdtype
    if not 'MdTau' in args.jobs:
        mdtype = ''
    #Create Read, Prod, and TS objects from parameters
    params = (args.nsamps, args.abcd, nodes, args.interval, args.nsteps,
              args.XYZ, args.xyzstart, mdtype)
    Reac = build.MOL(paths, params, 'reac', args.reactype)
    Prod = build.MOL(paths, params, 'prod')
    params = (args.nsamps, args.abcd, nodes, args.interval, args.nsteps,
              args.XYZ, args.xyzstart, mdtype)
    TS = build.MOL(paths, params, 'ts', args.reactype)

    reacs = args.reacs
    prods = args.prods

    key = set_keys(args.reactype)
    i, j, k = 0, 0, 0
    TSprops = [0, 0, [], [], [], '',
               0]  #charge, spin, angles, atoms, sort, bond, babs
    foundlist = []
    #Build reacn.dat
    for i, reac in enumerate(reacs, start=1):

        msg = 'Building reac{:g}.dat'.format(i)
        log.debug(msg)
        args.reacs, angles, atoms, args.jobs, foundlist, stoichs, symnums = build_mol_dat(
            Reac, reacs, i, stoichs, symnums, args.jobs, foundlist,
            args.select[i - 1], mdtype)
        TSprops = prep_reacs4TS(Reac, reac, i, key, angles, atoms, Reac.sort,
                                TSprops, args.reactype, paths)
        nsamps = Reac.nsamps
        msg = 'Completed'
        log.info(msg)

    #Build prodn.dat
    for j, prod in enumerate(prods, start=1):
        msg = 'Building prod{:g}.dat'.format(j)
        log.debug(msg)
        args.prods, angles, atoms, args.jobs, foundlist, stoichs, symnums = build_mol_dat(
            Prod, prods, j, stoichs, symnums, args.jobs, foundlist,
            args.select[i + j - 1], mdtype)
        msg = 'Completed'
        log.info(msg)

    #Build TS, wellr, and wellp.dat
    tstype = ['ts', 'wellr', 'wellp']
    tss = ['false', args.wellr.lower(), args.wellp.lower()]
    if args.reactype:
        tss[0] = 'true'
    TS.ijk = Reac.ijk
    TS.sort = TSprops[4]
    TS.bond = TSprops[5]
    TS.babs = TSprops[6]
    for k in range(3):
        if tss[k] and tss[k] != 'false':
            if k == 1 and 'true' in args.wellr.lower():
                if len(args.reacs) > 1:
                    spin = 0
                    reac1 = args.reacs[0].split('_m')
                    if len(reac1) > 1:
                        spin += (float(reac1[1]) - 1) / 2
                    reac2 = args.reacs[1].split('_m')
                    if len(reac2) > 1:
                        spin += (float(reac2[1]) - 1) / 2
                    else:
                        spin = 0
                    reac3 = reac1[0] + '.' + reac2[0]
                    if spin:
                        reac3 += '_m' + str(int(2 * spin + 1))
                    log.info('Building {} '.format(reac3))
                    angles, atoms = build_well_dat(Reac, reac3, 3, args.jobs,
                                                   restartts)
                else:
                    log.info(
                        'Two reactants are required when finding a reactant well'
                    )

            elif k == 2 and (args.reactype.lower() == 'addition_well'
                             or args.reactype.lower() == 'isomerization_well'):
                if io.check_file('prod1.dat'):
                    msg = 'moving prod1.dat to wellp.dat for {} reaction'.format(
                        args.reactype.lower())
                    log.info(msg)
                    io.mv('prod1.dat', 'wellp.dat')
                    j = 0
                    args.prods = []
                    msg = 'Completed'
                    log.info(msg)
            elif k == 2 and 'true' in args.wellp.lower():
                if len(args.prods) > 1:
                    spin = 0
                    prod1 = args.prods[0].split('_m')
                    if len(prod1) > 1:
                        spin += (float(prod1[1]) - 1) / 2
                    prod2 = args.prods[1].split('_m')
                    if len(prod2) > 1:
                        spin += (float(prod2[1]) - 1) / 2
                    else:
                        spin = 0
                    prod3 = prod1[0] + '.' + prod2[0]
                    if spin:
                        prod3 += '_m' + str(int(2 * spin + 1))
                    log.info('Building {} '.format(prod3))
                    angles, atoms = build_well_dat(Prod, prod3, 4, args.jobs,
                                                   restartts)
                else:
                    log.info(
                        'Two products are required when finding a product well'
                    )

            else:
                msg = 'Building ' + tstype[k] + '.dat'
                log.debug(msg)
                TS.charge = TSprops[0]
                TS.mult = int(2. * TSprops[1] + 1)
                TS.symnum = ' 1'
                if k == 0:
                    if 'geomdir' in args.XYZ and io.check_file(
                            '../geomdir/ts.xyz'):
                        angles, atoms = build_well_dat(TS, args.reactype, 'ts',
                                                       args.jobs, restartts)
                    else:
                        zmatstring = TS.build(tstype[k], args.reactype,
                                              args.jobs, False, TSprops[2],
                                              TSprops[3], restartts)
                        zmat = tstype[k] + '.dat'
                        io.write_file(zmatstring, zmat)
                else:
                    params = ('1', args.abcd, nodes, args.interval,
                              args.nsteps, 'False', 'start', 'MdTau'
                              in args.jobs)
                    TS = build.MOL(paths, params, 'ts')
                    TS.charge = TSprops[0]
                    TS.mult = int(2. * TSprops[1] + 1)
                    TS.symnum = ' 1'
                    zmatstring = TS.build(tstype[k], args.reactype, args.jobs,
                                          False, TSprops[2])
                    zmat = tstype[k] + '.dat'
                    io.write_file(zmatstring, zmat)
                msg = 'Completed'
                log.info(msg)

    mol = reac[0]
    #Builds me_head.dat
    if args.reactype:
        msg = 'Building me_head.dat'
        log.debug(msg)
        if args.mehead:
            if io.check_file('../' + args.mehead):
                headstring = io.read_file('../' + args.mehead)
            elif io.check_file(args.me_head):
                headstring = io.read_file(args.mehead)
            else:
                headstring = build.build_mehead()
        else:
            headstring = build.build_mehead()
        io.write_file(headstring, 'me_head.dat')
        msg = 'Completed'
        log.info(msg)
    #Builds theory.dat
    msg = 'Building theory.dat'
    log.debug(msg)
    theostring = build.build_theory(args.meths, tss, args.zedoptions,
                                    args.oneoptions, args.adiabatic)
    io.write_file(theostring, 'theory.dat')
    msg = 'Completed'
    log.info(msg)

    #Builds estoktp.dat to restart at any step
    msg = 'Building estoktp.dat'
    log.debug(msg)
    jobs = update_jobs(args.jobs, args.restart)
    params = (stoichs, args.reactype, args.coresh, args.coresl, args.meml,
              args.memh, args.esoptions)
    eststring = build.build_estoktp(params, jobs, i, j, tss, args.xyzstart,
                                    foundlist, ists)
    io.write_file(eststring, 'estoktp.dat')
    msg = 'Completed'
    log.info(msg)

    os.chdir('..')

    return stoichs, symnums
Example #27
0
File: anharm.py Project: keceli/QTC
def main(args, vibrots=None):

    extra = ' ZeroEnergy[kcal/mol]\t 0.\n ElectronicLevels[1/cm]\t\t1\n  0.0000000000000000\t\t1.0000000000000000\nEnd'
    if isinstance(args, dict):
        #natoms    = args['natoms']
        if 'writegauss' in args:
            if args['writegauss'] == 'true':
                anharminp = args['anharmlog'] + '.inp'
                anlevel = args['anlevel'].replace('g09', 'gaussian')
                write_anharm_inp(
                    args['logfile'], anharminp, '{}/{}'.format(anlevel.split('/')[1], anlevel.split('/')[2]))
        if 'rungauss' in args:
            if args['rungauss'] == 'true':
                anharminp = args['anharmlog'] + '.inp'
                node = args['node']
                run_gauss(anharminp, node)
        if 'pfreqs' in args:
            proj = np.array(args['pfreqs']).astype(np.float)
            unproj = np.array(args['freqs']).astype(np.float)
            proj = np.sort(proj)
            unproj = np.sort(unproj)
            a = np.arange(len(proj)+1)
            b = np.arange(len(unproj)+1)
            # a = nargs['pfreqs']).argsort()[::-1]
            #b = args['freqs'].argsort()[::-1]
        else:
            proj, b = get_freqs(args['freqfile'])
            unproj, a = get_freqs(args['unprojfreq'])
        #xmat = gauss_xmat(anharmlog,natoms)
        if 'xmat' in args:
            xmat = args['xmat']
        else:
            smiles = args['smiles']
            anlevel = args['theory']
            optlevel = args['optlevel']
            anharmlog = args['anharmlog'] + '.log'
            andire = io.db_sp_path(anlevel.split('/')[0], anlevel.split('/')[1], anlevel.split('/')[2], None, smiles,
                                   optlevel[0], optlevel[1], optlevel[2])
            if io.check_file(andire + '/' + smiles + '.xmat'):
                xmat = io.db_get_sp_prop(smiles, 'xmat', andire).split('\n')
                for i in range(len(xmat)):
                    xmat[i] = xmat[i].split(',')
            elif io.check_file(anharmlog):
                xmat = qc.get_gaussian_xmatrix(
                    io.read_file(anharmlog), len(unproj))
        for i in range(len(xmat)):
            xmat[i][i] = float(xmat[i][i])
            for j in range(i):
                xmat[i][j] = float(xmat[i][j])
                xmat[j][i] = xmat[i][j]
        modes = find_hinfreqs(proj, unproj, b)
        xmat = remove_modes(xmat, modes)
        #proj, b   = get_freqs(eskproj)
        anfreq = anharm_freq(proj, xmat)
        if vibrots:
            vibrots = remove_vibrots(vibrots, modes)
        return anfreq, mess_fr(anfreq),  xmat, mess_x(xmat), extra, vibrots
    ##########################
    else:
        anharmlog = args.anharmlog
        natoms = args.natoms
        eskfile = args.logfile
        eskproj = args.freqfile
        eskunproj = args.unprojfreq
        anharmlog = args.anharmlog
        node = args.node
        if args.writegauss.lower() == 'true':
            write_anharm_inp(eskfile, 'anharm.inp')
        if args.rungauss.lower() == 'true':
            run_gauss('anharm.inp', node)
        if args.computeanharm.lower() == 'true':
            xmat = gauss_xmat(anharmlog, natoms)
            proj, b = get_freqs(eskproj)
            unproj, a = get_freqs(eskunproj)
            modes = find_hinfreqs(proj, unproj, a)
            xmat = remove_modes(xmat, modes)
            proj, b = get_freqs(eskproj)
            anfreq = anharm_freq(proj, xmat)
            return anfreq, mess_fr(anfreq), xmat, mess_x(xmat), extra, vibrots
    return
Example #28
0
def run(args, paths, d={}):
    """
    Runs heatform, partition_function, thermp, pac99, and write chemkin file
    """
    import sys
    sys.path.insert(0, paths['qtc'])
    global pa, io, ob, tc
    import patools as pa
    import iotools as io
    import tctools as tc
    import obtools as ob
    import heatform as hf
    import shutil
    import re

    reacs = args.reacs
    prods = args.prods
    anharm = args.anharm
    anovrwrt = args.anovrwrt
    node = args.nodes[0]
    meths = args.meths
    hfbasis = args.hfbasis
    qtchf = args.qtchf
    enlevel = args.enlevel
    hlen = args.hlen
    hfbases = []
    speciess, speclist, anfreqs, anxmat = build_pfinput(args, d)
    dH0 = []
    dH298 = []
    anharmbool = False
    deltaH = 0
    if anharm.lower() != 'false':
        anharmbool = True
    for i, species in enumerate(speciess):
        if len(species.split('_m')) > 1:
            species, mult = species.split('_m')[0], species.split('_m')[1]
        if qtchf[0].lower() not in ['false', 'auto']:
            if len(qtchf) >= i:
                deltaH = float(qtchf[i])
                hfbasis = ['N/A']
                hfbases.append(hfbasis)
        else:
            logfile = 'geoms/' + speclist[i] + '_l1.log'
            if speclist[i] == 'ts':
                logfile = 'geoms/' + speclist[i] + 'gta_l1.log'
            if io.check_file(logfile):
                lines = io.read_file(logfile)
                energy = pa.energy(lines)[1]
                zpve = pa.zpve(lines)
                printE = '{}-    E: {:5g} pulled from: {}'.format(
                    species, energy, logfile)
                printzpve = '{}- zpve: {:5g} pulled from: {}'.format(
                    species, zpve, logfile)
                if enlevel != 'optlevel':
                    energy = hlen[i]
                    printE = '{}-    E: {:5g} pulled from: {}'.format(
                        species, energy, 'me_files/' + speclist[i] + '_en.me')
                if io.check_file('me_files/' + speclist[i] + '_zpe.me'):
                    zpve = float(
                        io.read_file('me_files/' + speclist[i] + '_zpe.me'))
                    printzpve = '{}- ZPVE: {:5g} pulled from: {}'.format(
                        species, zpve, 'me_files/' + speclist[i] + '_zpe.me')
                if zpve:
                    energy = energy + zpve
                log.info(printE + '\n' + printzpve)
                deltaH, hfbasis = hf.main(species,
                                          logfile,
                                          E=energy,
                                          basis=hfbasis,
                                          anharm=anharmbool,
                                          enlevel=enlevel)
                hfbases.append(hfbasis)
            else:
                deltaH = 0.00
        dH0.append(deltaH)
        if not speclist[i] == 'ts':
            log.debug('Running mess')
            tc.run_pf('/home/ygeorgi/build/crossrate/partition_function',
                      species + '.pf')
            log.info('Completed')
            log.debug('Generating thermp input.\n')
            log.info('Completed')

            stoich = ob.get_formula(ob.get_mol(species))
            inp = tc.get_thermp_input(stoich, deltaH)
            log.debug('Running thermp.\n')
            if io.check_file(species + '.pf.dat'):
                os.rename(species + '.pf.dat', 'pf.dat')
            else:
                log.error(
                    'No pf.dat produced, try soft adding gcc-5.3 and intel-16.0.0 and use Restart at: 5!'
                )
                return [], [], [], [], []
            tc.run_thermp(inp, 'thermp.dat', 'pf.dat',
                          '/home/elliott/Packages/therm/thermp.exe')
            lines = io.read_file('thermp.out')
            log.info('Completed')
            deltaH298 = ' h298 final\s*([\d,\-,\.]*)'
            deltaH298 = re.findall(deltaH298, lines)[-1]
            dH298.append(deltaH298)
            log.debug('Running pac99.\n')
            shutil.copyfile('/home/elliott/Packages/therm/new.groups',
                            './new.groups')
            shutil.copyfile(stoich + '.i97', species + '.i97')
            tc.run_pac99(species, '/home/elliott/Packages/therm/pac99.x')
            c97file = species + '.c97'
            if io.check_file(c97file):
                c97text = io.read_file(c97file)
                las, has, msg = tc.get_coefficients(c97text)
                log.info('Completed')
            else:
                log.error('No {} produced'.format(c97file))
            chemkinfile = stoich + '.ckin'
            log.debug('Writing chemkin file {0}.\n'.format(chemkinfile))
            method = meths[-1][2]
            chemininput = tc.write_chemkin_file(species, method, deltaH,
                                                float(deltaH298), stoich, 0,
                                                las, has, chemkinfile)

        log.info('Completed')
    return dH0, dH298, hfbases, anfreqs, anxmat
Example #29
0
def map_m500(snap,
             sim,
             env,
             ptype='BH',
             overwrite=False,
             mlim=0.,
             dirz=None,
             outdir=None,
             Testing=True):
    '''
    Map particle mass into r500 from Subfind

    Parameters
    -----------
    snap : int
        Snapshot number
    sim : string
        Name of the simulation
    env : string
        ari, arilega or cosma, to use the adecuate paths
    ptype : array of string
        array containing one of the allowed ptypes
    overwrite : boolean
        If True the output file will be overwritten
    mlim : float
        mass limit for M500 [Msun/h]
    dirz : string
        Alternative path to table with z and snapshot.
    outdir : string
        Path to output file
    Testing : boolean
        Calculations on part or all the simulation

    Returns
    -----
    prop : float array
        Mapped property

    Examples
    ---------
    >>> import bahamas as b
    >>> sim = 'HIRES/AGN_TUNED_nu0_L050N256_WMAP9'
    >>> b.get_propfunc(31,sim,'arilega')
    '''

    if (ptype == 'DM'):
        print(
            'WARNING (bahamas.map_m500): For DM, use directly the halo masses')
        return None

    # Type of particles to be read
    itype = ptypes.index(ptype)  # 0:gas, 1:DM, 4: stars, 5:BH
    ptype = 'PartType' + str(itype)

    # Output file
    outdir2 = outdir + 'BAHAMAS/' + sim + '/'
    dir_exists = io.create_dir(outdir2)
    outfile = outdir2 + 'm500_snap' + str(snap) + '.hdf5'
    file_exists = io.check_file(outfile)
    if (overwrite): file_exists = False

    # Get particle files
    files, allfiles = get_particle_files(snap, sim, env)

    if (not allfiles):
        print(
            'WARNING (bahamas.map_m500): no adequate particle files found, {}, {}'
            .format(snap, env))
        return None
    if (Testing): files = [files[0]]

    # Loop over the particle files
    for iff, ff in enumerate(files):
        f = h5py.File(ff, 'r')  #; print(ff)
        p0 = f[ptype]

        # Read particle information
        if (iff == 0):
            groupnum = p0['GroupNumber'][:]  # FoF group number particle is in
            # Negative values: particles within r200 but not part of the halo
            subgroupnum = p0['SubGroupNumber'][:]
            partmass = p0['Mass'][:] * 1e10  # Msun/h
            partx = p0['Coordinates'][:, 0]  # Mpc/h
            party = p0['Coordinates'][:, 1]
            partz = p0['Coordinates'][:, 2]
        else:
            groupnum = np.append(groupnum, p0['GroupNumber'][:])
            subgroupnum = np.append(subgroupnum, p0['SubGroupNumber'][:])
            partmass = np.append(partmass, p0['Mass'][:] * 1e10)
            partx = np.append(partx, p0['Coordinates'][:, 0])
            party = np.append(party, p0['Coordinates'][:, 0])
            partz = np.append(partz, p0['Coordinates'][:, 0])

    # If all groupnum are less than 0, take abs()
    allgneg = False
    ind = np.where(groupnum < 0)
    if (np.shape(ind)[1] == len(groupnum)):
        allgneg = True
        groupnum = abs(groupnum)

    # Get particle information into a pandas dataset to facilitate merging options
    df_part = pd.DataFrame(data=np.vstack(
        [groupnum, subgroupnum, partmass, partx, party, partz]).T,
                           columns=[
                               'groupnum', 'subgroupnum', 'partmass', 'partx',
                               'party', 'partz'
                           ])
    groupnum, subgroupnum, partmass, partx, party, partz = [[]
                                                            for i in range(6)
                                                            ]  #Empty arrays
    df_part.sort_values(by=['groupnum', 'subgroupnum'], inplace=True)
    df_part.reset_index(inplace=True, drop=True)

    # Get FOF/Subfind files
    files, allfiles = get_subfind_files(snap, sim, env)
    if (not allfiles):
        print(
            'WARNING (bahamas.map_m500): no adequate Subfind files found, {}, {}'
            .format(snap, env))
        return None
    if (Testing): files = [files[0], files[1]]

    # Loop over the FOF/Subfind files
    for iff, ff in enumerate(files):
        f = h5py.File(ff, 'r')  #; print(ff)
        fof = f['FOF']

        # Read particle information  r500,cop_x,cop_y,cop_z
        if (iff == 0):
            m500 = fof['Group_M_Crit500'][:] * 1e10  #Msun/h
            r500 = fof['Group_R_Crit500'][:]  #cMpc/h
            cop_x = fof['GroupCentreOfPotential'][:, 0]  #cMpc/h
            cop_y = fof['GroupCentreOfPotential'][:, 1]  #cMpc/h
            cop_z = fof['GroupCentreOfPotential'][:, 2]  #cMpc/h
        else:
            m500 = np.append(m500, fof['Group_M_Crit500'][:] * 1e10)
            r500 = np.append(r500, fof['Group_R_Crit500'][:])
            cop_x = np.append(cop_x, fof['GroupCentreOfPotential'][:, 0])
            cop_y = np.append(cop_y, fof['GroupCentreOfPotential'][:, 1])
            cop_z = np.append(cop_z, fof['GroupCentreOfPotential'][:, 2])

    # Get the FOF data into a pandas dataset
    df_fof = pd.DataFrame(data=np.vstack([m500, r500, cop_x, cop_y, cop_z]).T,
                          columns=['m500', 'r500', 'cop_x', 'cop_y', 'cop_z'])
    m500, r500, cop_x, cop_y, cop_z = [[] for i in range(5)
                                       ]  #Empty individual arrays

    # Generate a groupnum column from 1 to the last halo
    df_fof.index += 1
    df_fof.index.names = ['groupnum']
    df_fof.reset_index(inplace=True)

    # Join the particle and FoF information
    merge = pd.merge(df_part, df_fof, on=['groupnum'])

    # Get the boxsize
    omega0, omegab, lambda0, h0, boxsize = get_cosmology(sim, env)
    lbox2 = boxsize / 2.

    # Position of particles relative to the center of the group
    merge['partx'] = merge.partx - merge.cop_x
    merge['party'] = merge.party - merge.cop_y
    merge['partz'] = merge.partz - merge.cop_z

    # Correct for periodic boundary conditions (for gal. in groups)
    merge.partx.loc[
        merge.partx < -lbox2] = merge.partx.loc[merge.partx < -lbox2] + boxsize
    merge.party.loc[
        merge.party < -lbox2] = merge.party.loc[merge.party < -lbox2] + boxsize
    merge.partz.loc[
        merge.partz < -lbox2] = merge.partz.loc[merge.partz < -lbox2] + boxsize

    merge.partx.loc[
        merge.partx >= lbox2] = merge.partx.loc[merge.partx >= lbox2] - boxsize
    merge.party.loc[
        merge.party >= lbox2] = merge.party.loc[merge.party >= lbox2] - boxsize
    merge.partz.loc[
        merge.partz >= lbox2] = merge.partz.loc[merge.partz >= lbox2] - boxsize

    # Distances to selected particles
    merge = merge.loc[merge.m500 > mlim]
    merge['distance'] = (merge.partx**2 + merge.party**2 + merge.partz**2)**0.5

    # Mass of those particles enclosed in R500
    merge['inside_r500'] = merge.distance <= merge.r500
    merge = merge.loc[merge.inside_r500 == True]
    groups = merge.groupby(['groupnum'], as_index=False)
    massinr500 = groups.partmass.sum()  # partmass now = particle mass
    #final = pd.merge(massinr500, df_fof, on=['groupnum']) #here: do I need this?

    # Write properties to output file
    if (not file_exists):
        # Generate the file
        hf = h5py.File(outfile,
                       'w')  #here if appending columns here it'll be the place

        # Output header
        headnom = 'header'
        head = hf.create_dataset(headnom, (100, ))
        head.attrs[u'sim'] = sim
        head.attrs[u'snapshot'] = snap
        head.attrs[u'redshift'] = get_z(snap, sim, env, dirz=dirz)
        head.attrs[u'omega0'] = omega0
        head.attrs[u'omegab'] = omegab
        head.attrs[u'lambda0'] = lambda0
        head.attrs[u'h0'] = h0
        head.attrs[u'boxsize'] = boxsize

        # Output data with units
        hfdat = hf.create_group('data')
        units = unitdefault[proplabel]

        # Mass #here: all properties or only some?
        #
        hf.close()
        print(outfile)
        print(io.print_h5attr(outfile, inhead=headnom))
        exit()
        ##------------to be acomodated


#    # Output data
#    pn = 'midpoint'
#    hfdat.create_dataset(pn,data=mhist)
#    hfdat[pn].dims[0].label = 'log10('+proplabel+'_'+pn+' / '+units+')'
##--------------

# add property to alredy existent file?
#here: maybe new column with the property we want
    map_m500 = 'name'
    #-groupnum??? (groupnum,massinr500) or only massinr500 for MF
    map_m500 = 0
    ###here what do I pass? prop or file?
    #here: l.465 in bahamascal.py
    # Retrurn name of file with output
    return map_m500
Example #30
0
def main(mol,
         logfile='geoms/reac1_l1.log',
         E=9999.9,
         basis='auto',
         theory='auto/',
         db='tempdb',
         prog='auto'):

    basis = basis.split()
    #AUTO SET NONUSERDEFINED PARAMETRS##
    if is_auto(prog):
        prog = pa.get_prog(io.read_file(logfile))
    if is_auto(mol):
        mol = getname_fromdirname()
    if is_auto(theory) and io.check_file(logfile):
        theory = gettheory_fromlogfile(logfile)
        theory += '/'
        theory += getbasisset_fromlogfile(logfile)
    theory, basisset = theory.split('/')

    if is_auto(E):
        E = getenergy_fromlogfile(logfile, theory)

    basprint = 'manually select basis'
    atomlist = get_atomlist(mol)
    basisselection = 0
    if is_auto(basis[0]):
        basis = select_basis(atomlist)
        basisselection += 1
        basprint = 'automatically generate basis'
    elif basis[0] == 'basis.dat':
        basis = io.read_file('basis.dat').split()
        basprint = 'read basis from basis.dat'
    lines = (
        '\n-------------------------------------------------\n\n' +
        'HEAT OF FORMATION FOR: ' + mol + '\n    at ' + theory + '/' +
        basisset +
        '\n\n-------------------------------------------------\n\nYou have chosen to '
        + basprint + '\n\nBasis is: ' + ', '.join(basis))
    print lines

    for bas in basis:
        atomlist.extend(get_atomlist(bas))
    ####################################

    #COMPUTE Atomlist, stoichlist, matrix, and coefficients
    atomlist = list(set(atomlist))
    stoich = get_stoich(mol, atomlist)
    mat = form_mat(basis, atomlist)

    for i in range(5):
        if np.linalg.det(mat) != 0:
            break
        print 'Matrix is singular -- select new basis'
        atomlist = get_atomlist(mol)
        basis = select_basis(atomlist, basisselection)
        basisselection += 1
        print('\n\nBasis is: ' + ', '.join(basis))
        for bas in basis:
            atomlist.extend(get_atomlist(bas))
        atomlist = list(set(atomlist))
        stoich = get_stoich(mol, atomlist)
        mat = form_mat(basis, atomlist)
        print mat

    clist = comp_coeff(mat, stoich)
    ######################################################

    ###PRINT STUFF OUT
    lines = '\n  ' + mol + '\t\t' + '\t'.join(basis)
    for i in range(len(mat)):
        lines += '\n' + atomlist[i] + '  '
        lines += str(stoich[i]) + '    \t'
        for el in mat[i]:
            lines += str(el) + '\t'
    lines += '\n\nCoefficients are: '
    for co in clist:
        lines += str(co) + ' '
    print lines + '\n'
    print check(clist, basis, stoich, atomlist)
    ##################

    #COMPUTE AND PRINT delH###
    E = comp_energy(mol, basis, clist, E, theory, basisset, prog)
    lines = '\n        delHf(0K)'
    lines += '\nA.U. \t'
    for e in E[:1]:
        lines += str(e) + '\t'
    lines += '\nkJ   \t'
    for e in E[:1]:
        lines += str(e / .00038088) + '\t'
    lines += '\nkcal   \t'
    for e in E[:1]:
        lines += str(e * 627.503) + '\t'
    lines += '\n\n-------------------------------------------------\n\n'
    print lines
    ##########################
    return E[0] * 627.503