Class: GaussianParser::FileItemProcessor
- Inherits:
-
Object
- Object
- GaussianParser::FileItemProcessor
- Includes:
- Cli
- Defined in:
- lib/gaussian_parser/file_item_processor.rb
Constant Summary collapse
- HEADERS_FOR_FILES =
{ 'distances.dat' => %w(No Distance Value Distances), 'angles.dat' => %w(No Angle Value Angles), 'dihedrals.dat' => %w(No Dihedral Value Dihedrals), 'molecular_orbitals.dat' => %w(No Symmetry Value_Hartree Value_eV Occupancy Homo/Lumo), 'harmonic_frequencies.dat' => ['No', 'Symmetry', 'Frequency', 'Red._mass', 'Frc_const.', 'IR_Intensity', 'Raman_Activity', 'Depolar_(P)', 'Depolar_(U)'] }
Constants included from Cli
Cli::ERROR_COLOR, Cli::SUCCESS_COLOR
Instance Method Summary collapse
- #change_element_format(line) ⇒ Object
-
#initialize(params) ⇒ FileItemProcessor
constructor
A new instance of FileItemProcessor.
- #proccess ⇒ Object
- #process_output_file(results, file_path, file_name, line_format) ⇒ Object
Methods included from Cli
#print_as_error, #print_as_success, #print_as_usual
Constructor Details
#initialize(params) ⇒ FileItemProcessor
Returns a new instance of FileItemProcessor.
16 17 18 19 20 |
# File 'lib/gaussian_parser/file_item_processor.rb', line 16 def initialize(params) @output_path = params[:output_path] @file_name = params[:file_name] @parser = DataProcessor.new(File.open(@file_name, 'r')) end |
Instance Method Details
#change_element_format(line) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gaussian_parser/file_item_processor.rb', line 87 def change_element_format(line) element = line[1] # element # # L(13,15,18,30,-1) # TODO: make sure regexp is correct count = element.scan(/-?[0-9]+/) right_format = count.map! do |el| @atom_count[el].nil? ? "?(#{el})" : (@atom_count[el] + el) end line[1] = right_format.join("-") line end |
#proccess ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gaussian_parser/file_item_processor.rb', line 22 def proccess print_as_usual("Checking for normal termination") if @parser.has_normal_termination? print_as_success("Normal termination found") print_as_usual("Checking for stationary point...") @stationary_point, @atom_count, @molecular_orbitals, @harmonic_frequencies = @parser.parse if !@stationary_point.empty? stp_results = { angles: [], dihedrals: [], distances: [] } # Sort results due to # their types @stationary_point.each do |rl| if rl[0][0] == 'R' stp_results[:distances].push rl elsif rl[0][0] == 'A' stp_results[:angles].push rl else stp_results[:dihedrals].push rl end end # Line format for output files line_format = "% -10s %15s %10s" # Change element format stp_results.each_value do |results| results.each do |result| change_element_format(result) end end # Create separate file for each type stp_results.each do |type, results| process_output_file(results, @output_path, "#{type.to_s}.dat", line_format) end else print_as_error("Stationary point was not found in #{@file_name}") end if !@molecular_orbitals.empty? line_format = "% -10s %2s %15s %15s %15s %10s" process_output_file(@molecular_orbitals, @output_path, "molecular_orbitals.dat", line_format) else print_as_error("'Molecular Orbital Coefficients' line wasn't found!") end if !@harmonic_frequencies.empty? line_format = "% -5s %5s %15s %15s %15s %15s %15s %15s %15s" process_output_file(@harmonic_frequencies, @output_path, "harmonic_frequencies.dat", line_format) else print_as_error("Error during harmonic frequencies analyze!") end else print_as_error("Normal termination was not found in #{@file_name}") end end |
#process_output_file(results, file_path, file_name, line_format) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/gaussian_parser/file_item_processor.rb', line 102 def process_output_file(results, file_path, file_name, line_format) File.open(File.join(file_path, file_name), "w") do |f| f.puts line_format % HEADERS_FOR_FILES[file_name] if HEADERS_FOR_FILES[file_name] f.puts results.each do |line| f.puts line_format % line end end end |