def pilgrim_spc(xcc,symbols,bhessian,mname,eargs): # expand extra-args if len(eargs) == 1: spc_template = eargs[0] folder, clean = None, False elif len(eargs) == 2: spc_template, folder = eargs clean = False elif len(eargs) == 3: spc_template, folder, clean = eargs # no template?? if spc_template is None: raise Exc.NoTemplateGiven(Exception) # create folder if folder is not None: if not os.path.exists(folder): os.mkdir(folder) # Calculate gradient&hessian or just gradient if bhessian: inkey3 = "! EnGrad Freq " else : inkey3 = "! EnGrad " # names of files wname, ifile, ofile, engrad, hess, gbw, err = ITF.iofiles(mname,folder) # Input string_ifile = "" for line in spc_template.split("\n"): if key1 in line: line = "" for idx,symbol in enumerate(symbols): x,y,z = fncs.xyz(xcc,idx) linedata = (symbol,x*pc.ANGSTROM,y*pc.ANGSTROM,z*pc.ANGSTROM) line += "%2s %+11.6f %+11.6f %+11.6f\n"%linedata if key2 in line: pos = line.find(key2) line = line[0:pos] + wname + line[pos+len(key2):] if key3 in line: pos = line.find(key3) line = line[0:pos] + inkey3 + line[pos+len(key3):] # Add \n to line if not line.endswith("\n"): line += "\n" string_ifile += line ff.write_file(ifile,string_ifile) # Send calculation status = ITF.execute(ifile,ofile,err) # # Sleep 0.5 seconds, so Orca can write the files # time.sleep(0.5) # Check output exception = Exc.CalcFails(Exception) exception._var = ofile if not ITF.normal_termination(ofile): raise exception # Read data xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = ff.read_orca(ofile) # Remove files if clean: files = os.listdir(folder) files = [fff for fff in files if fff.startswith(name) ] files = [fff for fff in files if not fff.endswith(".inp") ] files = [fff for fff in files if not fff.endswith(".out") ] files = [fff for fff in files if not fff.endswith(".engrad")] files = [fff for fff in files if not fff.endswith(".hess") ] for fff in files: os.remove(folder+fff) return xcc, atonums, ch, mtp, E, gcc, Fcc, masses
def highlevel_sp(ctc, itc, keyHL, gtsfile, software, dtesHL, dhighlvl): # is calculation needed? if keyHL in dhighlvl.keys(): return None # folder for calculation and file name TMP = PN.TMPHLi % keyHL mname = "%s.%s" % (keyHL, "sp") # Function for calculation and template spc_fnc = get_spc_fnc(software) tes = dtesHL.get(software, {}).get(ctc, None) if tes is None: raise Exc.NoTemplateGiven(Exception) # extra-arguments for spc_fnc clean = False # do not delete files bhess = False # do not calculate hessian (no needed actually) eargs = (tes, TMP, clean) # Read gts file (Molecule instance) molecule = Molecule() molecule.set_from_gts(gtsfile) # HL-calculation out_spc = spc_fnc(molecule._xcc, molecule._symbols, bhess, mname, eargs) return out_spc[4]
def pilgrim_spc(xcc, symbols, bhessian, mname, eargs): # initialize folder = None clean = False oniomH = [] oniomM = [] oniomL = [] frozen = ([], []) # expand extra-args if len(eargs) == 1: spc_template = eargs[0] elif len(eargs) == 2: spc_template, folder = eargs elif len(eargs) == 3: spc_template, folder, clean = eargs elif len(eargs) == 5: spc_template, folder, clean, frozen, oniom_layers = eargs oniomH, oniomM, oniomL = oniom_layers # no template?? if spc_template is None: raise Exc.NoTemplateGiven(Exception) # create folder if folder is not None: if not os.path.exists(folder): os.mkdir(folder) # Calculate gradient&hessian or just gradient if bhessian: inkey3 = "freq=noraman " else: inkey3 = "force " # names of files wname, ifile, ofile, chk, fchk, err = ITF.iofiles(mname, folder) # Input string_ifile = "" for line in spc_template.split("\n"): if key1 in line: line = "" for idx, symbol in enumerate(symbols): x, y, z = fncs.xyz(xcc, idx) if idx in oniomH: layer = " H" elif idx in oniomM: layer = " M" elif idx in oniomL: layer = " L" else: layer = " " linedata = (symbol, x * pc.ANGSTROM, y * pc.ANGSTROM, z * pc.ANGSTROM, layer) line += "%2s %+11.6f %+11.6f %+11.6f %s\n" % linedata # add frozen atoms frozen_symbols, frozen_xcc = frozen for idx, symbol in enumerate(frozen_symbols): x, y, z = fncs.xyz(frozen_xcc, idx) # oniom layer? at = len(symbols) + idx if at in oniomH: layer = " H" elif at in oniomM: layer = " M" elif at in oniomL: layer = " L" else: layer = " " linedata = (symbol, x * pc.ANGSTROM, y * pc.ANGSTROM, z * pc.ANGSTROM, layer) line += "%2s -1 %+11.6f %+11.6f %+11.6f %s\n" % linedata if key2 in line: pos = line.find(key2) line = line[0:pos] + wname + line[pos + len(key2):] if key3 in line: pos = line.find(key3) line = line[0:pos] + inkey3 + line[pos + len(key3):] # Add \n to line if not line.endswith("\n"): line += "\n" string_ifile += line ff.write_file(ifile, string_ifile) # Send calculation status = ITF.execute(ifile, ofile, err) # Check output exception = Exc.CalcFails(Exception) exception._var = ofile if not ITF.normal_termination(ofile): raise exception # (a) chk exists! if os.path.exists(chk): # Generate fchk status = ITF.genfchk(chk, fchk, err) # Read data xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = ff.read_fchk(fchk) # (b) chk does not exist! else: xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = ITF.read_gauout( ofile) # Remove files if clean: files = os.listdir(folder) files = [fff for fff in files if fff.startswith(name)] files = [fff for fff in files if not fff.endswith(".gjf")] files = [fff for fff in files if not fff.endswith(".log")] files = [fff for fff in files if not fff.endswith(".out")] files = [fff for fff in files if not fff.endswith(".chk")] files = [fff for fff in files if not fff.endswith(".fchk")] for fff in files: os.remove(folder + fff) return xcc, atonums, ch, mtp, E, gcc, Fcc, masses
def pilgrim_spc(xcc, symbols, bhessian, mname, eargs): # expand extra-args if len(eargs) == 1: spc_template = eargs[0] folder, clean = None, False elif len(eargs) == 2: spc_template, folder = eargs clean = False elif len(eargs) == 3: spc_template, folder, clean = eargs elif len(eargs) == 5: spc_template, folder, clean, frozen, oniom_layers = eargs # no template?? if spc_template is None: raise Exc.NoTemplateGiven(Exception) # lines for GRADIENT (if any) gradient_lines = None if key4a in spc_template and key4b in spc_template: gradient_lines = spc_template.split(key4a)[1].split(key4b)[0] spc_template = spc_template.replace(gradient_lines, "").replace(key4b, "") gradient_lines = gradient_lines.strip() # lines for HESSIAN (if any) hessian_lines = None if key5a in spc_template and key5b in spc_template: hessian_lines = spc_template.split(key5a)[1].split(key5b)[0] spc_template = spc_template.replace(hessian_lines, "").replace(key5b, "") hessian_lines = hessian_lines.strip() # create folder if folder is not None: if not os.path.exists(folder): os.mkdir(folder) # names of files wname, ifile, ofile, engrad, hess, gbw, err = ITF.iofiles(mname, folder) # Input string_ifile = "" for line in spc_template.split("\n"): if key1 in line: line = "" for idx, symbol in enumerate(symbols): x, y, z = fncs.xyz(xcc, idx) linedata = (symbol, x * pc.ANGSTROM, y * pc.ANGSTROM, z * pc.ANGSTROM) line += "%2s %+11.6f %+11.6f %+11.6f\n" % linedata if key2 in line: pos = line.find(key2) line = line[0:pos] + wname + line[pos + len(key2):] #--------------------------------# # Gradient & Hessian computation # #--------------------------------# # (a) via key3 if key3 in line: if bhessian: inkey3 = "! EnGrad Freq " else: inkey3 = "! EnGrad " pos = line.find(key3) line = line[0:pos] + inkey3 + line[pos + len(key3):] # (b) via key4 & key5 if key4a in line: line = line.replace(key4a, gradient_lines) if key5a in line: if bhessian: line = line.replace(key5a, hessian_lines) else: continue #--------------------------------# # Add \n to line if not line.endswith("\n"): line += "\n" string_ifile += line with open(ifile, 'w') as asdf: asdf.write(string_ifile) # Send calculation status = ITF.execute(ifile, ofile, err) # # Sleep 0.5 seconds, so Orca can write the files # time.sleep(0.5) # Check output exception = Exc.CalcFails(Exception) exception._var = ofile if not ITF.normal_termination(ofile): raise exception # Read data xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = ITF.read_orca(ofile) # Remove files if clean: files = os.listdir(folder) files = [fff for fff in files if fff.startswith(name)] files = [fff for fff in files if not fff.endswith(".inp")] files = [fff for fff in files if not fff.endswith(".out")] files = [fff for fff in files if not fff.endswith(".engrad")] files = [fff for fff in files if not fff.endswith(".hess")] for fff in files: os.remove(folder + fff) return xcc, atonums, ch, mtp, E, gcc, Fcc, masses