def main(): """ Reads a structure from a Gaussian Log file and other parameters from a Gaussian Com file and creates a new Gaussian Com. """ args = get_args() gaulog = GaussianLog(args.log) gaucom = GaussianCom(args.template_com) atoms_log_coords = gaulog.read_geometry(args.opt_step, args.scan_step) for no, atom in enumerate(gaucom.atoms_list): atom.SetVector(atoms_log_coords[no].GetVector()) gaucom.write_to_file(args.new_com)
def main(): import os import getopt, sys from omg.gaussian.gaussian import GaussianLog as GL from omg import misc, asciiplot, geom try: opts, args = getopt.gnu_getopt(sys.argv[1:], 'e:w:h') except getopt.GetoptError as err: sys.stderr.write(err + '\n') usage() sys.exit(2) # defaults scan_pts = 0 energytype = 'default' maxwidth = 80 multiline = True explain_symbols = False # provided input for o, a in opts: if o == '-s': scan_pts = int(a) elif o == '-e': energytype = a.lower() elif o == '-w': maxwidth = int(a) elif o == '-m': multiline = True elif o == '-h': explain_symbols = True if len(args) < 1 and explain_symbols: print(symbol_legend()) sys.exit(0) if len(args) < 1: usage() print('missing:') print(' inputname.log') sys.exit(2) elif len(args) > 1: usage() print('too many args:') print(' %s' % (','.join(args))) filein = args[0] basename, input_extension = os.path.splitext(filein) if input_extension not in ['.log']: print('WARNING:') print(' inputname suffix is: %s' % input_extension) # read gaussian.log gl = GL(filein) converged = [] for byte in gl.bytedict['Converged?'][-1]: # labels and thresh are constant for every byte, keep only last iter (labels, values, thresh) = gl.read_converged(byte) converged.append(values) converged = misc.transpose_list_of_lists(converged) # print! pretty = print_convergence_symbols(thresh, converged, labels, maxwidth, multiline) print(pretty) # scan info scan_info = False now_scan_point = len(gl.bytedict['Converged?']) total_scan_num_pts = 1 # default for opt if gl.modreds: # not None for modred in gl.modreds: if modred.action == 'S': scan_info = ['', ''] total_scan_num_pts = modred.scan_num_pts + 1 #measure_func = {'S': geom.distance, # 'A': geom.angle, # 'D': geom.dihedral # } #measure_func = measure_func[modred.coordtype] a = gl.atoms_list[modred.atomids[0]-1] b = gl.atoms_list[modred.atomids[1]-1] if modred.coordtype == 'B': scan_info[0] = 'distance' start_measure = a.GetDistance(b) elif modred.coordtype == 'A': scan_info[0] = 'angle' c = gl.atoms_list[modred.atomids[2]-1] start_measure = a.GetAngle(b, c) # b in the middle! elif modred.coordtype == 'D': scan_info[0] = 'dihedral' c = gl.atoms_list[modred.atomids[2]-1] d = gl.atoms_list[modred.atomids[3]-1] start_measure = a.GetDihedral(b,c,d) # x axis for asciiplot x_axis = [start_measure + modred.scan_step_sz*i for i in range(now_scan_point)] for atomid in modred.atomids: scan_info[1] += '%d %s, %s\n' % ( gl.atoms_list[atomid-1].resinfo.resnum, gl.atoms_list[atomid-1].resinfo.resname, gl.atoms_list[atomid-1].resinfo.name) scan_info[1] += '%s %s %s %d %f\n' % ( modred.coordtype, ' '.join([str(at) for at in modred.atomids]), modred.action, modred.scan_num_pts, modred.scan_step_sz) print ('Opt #: %3d out of %3d\n' % ( now_scan_point, total_scan_num_pts)) if explain_symbols: print(symbol_legend()) # get key for gl.energies dict energykey = energytype_convert(gl, energytype) # ENERGIES: if scan: last opt in each step; if opt: last scan_pt if len(gl.bytedict['Converged?']) > 1: energies = [e[-1] for e in gl.energies[energykey]] oneopt = False else: energies = gl.energies[energykey][-1] x_axis = [i+1 for i in range(len(energies))] oneopt = True HARTREE2KCAL = 627.509 minene = min(energies) y = [HARTREE2KCAL*(i - minene) for i in energies] p = asciiplot.AFigure() _ = p.plot(x_axis, y, marker='_s') p.xlim(min(x_axis), max(x_axis) ) print(p.draw().encode('utf-8')) if oneopt: print('Energy along optimization point.') else: print('Energy for optimized (or not) steps. (this is a scan)') if scan_info: print('X axis matches %s between:' % scan_info[0]) print(scan_info[1])
def main(): import os import getopt, sys from omg.gaussian.gaussian import GaussianLog as GL from omg import misc, asciiplot, geom try: opts, args = getopt.gnu_getopt(sys.argv[1:], 'e:w:h') except getopt.GetoptError as err: sys.stderr.write(err + '\n') usage() sys.exit(2) # defaults scan_pts = 0 energytype = 'default' maxwidth = 80 multiline = True explain_symbols = False # provided input for o, a in opts: if o == '-s': scan_pts = int(a) elif o == '-e': energytype = a.lower() elif o == '-w': maxwidth = int(a) elif o == '-m': multiline = True elif o == '-h': explain_symbols = True if len(args) < 1 and explain_symbols: print(symbol_legend()) sys.exit(0) if len(args) < 1: usage() print('missing:') print(' inputname.log') sys.exit(2) elif len(args) > 1: usage() print('too many args:') print(' %s' % (','.join(args))) filein = args[0] basename, input_extension = os.path.splitext(filein) if input_extension not in ['.log']: print('WARNING:') print(' inputname suffix is: %s' % input_extension) # read gaussian.log gl = GL(filein) converged = [] for byte in gl.bytedict['Converged?'][-1]: # labels and thresh are constant for every byte, keep only last iter (labels, values, thresh) = gl.read_converged(byte) converged.append(values) converged = misc.transpose_list_of_lists(converged) # print! pretty = print_convergence_symbols(thresh, converged, labels, maxwidth, multiline) print(pretty) # scan info scan_info = False now_scan_point = len(gl.bytedict['Converged?']) total_scan_num_pts = 1 # default for opt if gl.modreds: # not None for modred in gl.modreds: if modred.action == 'S': scan_info = ['', ''] total_scan_num_pts = modred.scan_num_pts + 1 #measure_func = {'S': geom.distance, # 'A': geom.angle, # 'D': geom.dihedral # } #measure_func = measure_func[modred.coordtype] a = gl.atoms_list[modred.atomids[0] - 1] b = gl.atoms_list[modred.atomids[1] - 1] if modred.coordtype == 'B': scan_info[0] = 'distance' start_measure = a.GetDistance(b) elif modred.coordtype == 'A': scan_info[0] = 'angle' c = gl.atoms_list[modred.atomids[2] - 1] start_measure = a.GetAngle(b, c) # b in the middle! elif modred.coordtype == 'D': scan_info[0] = 'dihedral' c = gl.atoms_list[modred.atomids[2] - 1] d = gl.atoms_list[modred.atomids[3] - 1] start_measure = a.GetDihedral(b, c, d) # x axis for asciiplot x_axis = [ start_measure + modred.scan_step_sz * i for i in range(now_scan_point) ] for atomid in modred.atomids: scan_info[1] += '%d %s, %s\n' % ( gl.atoms_list[atomid - 1].resinfo.resnum, gl.atoms_list[atomid - 1].resinfo.resname, gl.atoms_list[atomid - 1].resinfo.name) scan_info[1] += '%s %s %s %d %f\n' % ( modred.coordtype, ' '.join( [str(at) for at in modred.atomids]), modred.action, modred.scan_num_pts, modred.scan_step_sz) print('Opt #: %3d out of %3d\n' % (now_scan_point, total_scan_num_pts)) if explain_symbols: print(symbol_legend()) # get key for gl.energies dict energykey = energytype_convert(gl, energytype) # ENERGIES: if scan: last opt in each step; if opt: last scan_pt if len(gl.bytedict['Converged?']) > 1: energies = [e[-1] for e in gl.energies[energykey]] oneopt = False else: energies = gl.energies[energykey][-1] x_axis = [i + 1 for i in range(len(energies))] oneopt = True HARTREE2KCAL = 627.509 minene = min(energies) y = [HARTREE2KCAL * (i - minene) for i in energies] p = asciiplot.AFigure() _ = p.plot(x_axis, y, marker='_s') p.xlim(min(x_axis), max(x_axis)) print(p.draw().encode('utf-8')) if oneopt: print('Energy along optimization point.') else: print('Energy for optimized (or not) steps. (this is a scan)') if scan_info: print('X axis matches %s between:' % scan_info[0]) print(scan_info[1])
if len(sys.argv) == 1 or sys.argv[1] in ["-h", "--help"]: print("Como usar: {0} file.log ").format(sys.argv[0]) sys.exit() #ficheiro entrada (output do gaussian) global filein filein = sys.argv[1] #transformar o ficheiro log aberto numa variavel global (ler com o GaussianLog) ############## INICIO ############## main() #ler os bytes de todo o ficheiro e fazer todos os atributos d gaussianlog = GaussianLog(filein) for i, scan_step in enumerate( gaussianlog.grep_bytes['Step number'] ): print( "Scan", i, ": ", len(gaussianlog.grep_bytes['Step number'][i]), "opt steps" ) scan_step = input('Type "scan_step" that you which to extract. Options: scan_step="all": ') opt_step = input('Type "opt_step" that you which to extract. Options: opt_step="all": ') #verificar se existe o ficheiro output = input('Type the name of the output file: ') if path.exists(str(output) + '.pdb'): raise RuntimeError('%s already exists' %(str(output)+".pdb")) open_output = open(str(output) + ".pdb", "w") #casos em que extraio todos os scans if str(scan_step) == 'all': print(len(gaussianlog.grep_bytes['orientation:']))