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
def get_gaussian_input(x, template, mult=0): """ Returns Gaussian input file based on a given template. """ if type(x) is str: mol = ob.get_mol(x) else: mol = x if mult == 0: mult = ob.get_multiplicity(mol) charge = ob.get_charge(mol) geo = ob.get_geo(mol) xyz = ob.get_xyz(mol) zmat = ob.get_zmat(mol) uniquename = ob.get_inchi_key(mol, mult) inp = template.replace("QTC(CHARGE)", str(charge)) inp = inp.replace("QTC(MULTIPLICITY)", str(mult)) inp = inp.replace("QTC(UNIQUENAME)", uniquename) inp = inp.replace("QTC(ZMAT)", zmat) inp = inp.replace("QTC(GEO)", geo) inp = inp.replace("QTC(XYZ)", xyz) if "QTC(" in inp: print("Error in template file:\n" + inp) return return inp
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
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
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
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
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
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