gaussian_parser 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3907d927f7b927df79f8f5d65bfbc3f4d3b4adcf2151597c521a9e7c1bdd2ebe
4
+ data.tar.gz: f26b4b9f4830f16fa3030308df06ecd1ca522ec563db2e2c7252516ebc1d4ae3
5
+ SHA512:
6
+ metadata.gz: 5018d73e415f404473e7e9dec640b7b72d930bca4e0db9c282fbd7864011e55a012645d7b8d30187041fc69de45e092ce14e7c9ff5c090b88dc7d3ade205fae6
7
+ data.tar.gz: 545563928595baa2975fba290033128c6ec58976a8d66452f3f005e219843337508da51a455d02cafd3a2bf3209824bb6d4d00f40576fb01ac8c3508e853d22b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ihnatolia3@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gaussian_parser.gemspec
6
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gaussian_parser (0.0.1)
5
+ colorize (~> 0.8.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ colorize (0.8.1)
11
+ diff-lcs (1.3)
12
+ rake (10.5.0)
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.0)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.1)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.16)
32
+ gaussian_parser!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.16.2
@@ -0,0 +1,39 @@
1
+ # GaussianParser
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gaussian_parser`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gaussian_parser'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gaussian_parser
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gaussian_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the GaussianParser project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gaussian_parser/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gaussian_parser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gaussian_parser'
4
+ params = ARGV.reject {|a| a =~ /^-/}
5
+ options = ARGV.select {|a| a =~ /^-/}
6
+
7
+ GaussianParser.process({params: params, options: options})
@@ -0,0 +1,50 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gaussian_parser/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gaussian_parser"
8
+ spec.version = GaussianParser::VERSION
9
+ spec.authors = ["Paul I"]
10
+ spec.email = ["ihnatolia3@gmail.com"]
11
+
12
+ spec.summary = %q{Parse Gaussian output log file and structure data}
13
+ spec.description = <<-DESCRIPTION
14
+ Gaussian (http://gaussian.com/) is one of the most popular general purpose computational chemistry
15
+ software packages. The output genearated by it contains a lot of data which should
16
+ be structured properly before evaluation.
17
+
18
+ The purpose of the Gaussian Parser is to perform routine operations for better and faster
19
+ log data processing. Currently it's able to parse the output file and process the data for
20
+
21
+ - Distance matrix
22
+ - Molecular Orbital Coefficients
23
+ - Harmonic frequencies
24
+ DESCRIPTION
25
+ spec.homepage = "https://github.com/paul-ihnatolia/gaussian_parser"
26
+
27
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
28
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
29
+ # if spec.respond_to?(:metadata)
30
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
31
+ # else
32
+ # raise "RubyGems 2.0 or newer is required to protect against " \
33
+ # "public gem pushes."
34
+ # end
35
+
36
+ # Specify which files should be added to the gem when it is released.
37
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
38
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
39
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
40
+ end
41
+ spec.bindir = "exe"
42
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
43
+ spec.require_paths = ["lib"]
44
+
45
+ spec.add_runtime_dependency "colorize", "~> 0.8.1"
46
+
47
+ spec.add_development_dependency "bundler", "~> 1.16"
48
+ spec.add_development_dependency "rake", "~> 10.0"
49
+ spec.add_development_dependency "rspec", "~> 3.0"
50
+ end
@@ -0,0 +1,8 @@
1
+ require "gaussian_parser/version"
2
+ require "gaussian_parser/parser"
3
+
4
+ module GaussianParser
5
+ def self.process(argv)
6
+ GaussianParser::Parser.new(argv).process
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ require 'colorize'
2
+
3
+ module GaussianParser
4
+ module Cli
5
+ ERROR_COLOR = :red
6
+ SUCCESS_COLOR = :green
7
+
8
+ def print_as_error(message)
9
+ puts "Error: #{message}".colorize(ERROR_COLOR)
10
+ end
11
+
12
+ def print_as_success(message)
13
+ puts "Success: #{message}".colorize(SUCCESS_COLOR)
14
+ end
15
+
16
+ def print_as_usual(message)
17
+ puts "#{message}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,242 @@
1
+ require "gaussian_parser/cli"
2
+ require "gaussian_parser/processors/results_processor"
3
+ require "gaussian_parser/processors/atom_processor"
4
+
5
+ module GaussianParser
6
+ class DataProcessor
7
+ include Cli
8
+
9
+ def initialize(file)
10
+ @file_lines = file.readlines
11
+ end
12
+
13
+ def has_normal_termination?
14
+ # programm terminates correctly when
15
+ # "normal termination" line is found
16
+ @file_lines.each do |line|
17
+ if line =~ /Normal termination/
18
+ return true
19
+ end
20
+ end
21
+ return false
22
+ end
23
+
24
+ def parse
25
+ processors = {}
26
+
27
+ atom_count = {}
28
+ molecular_orbitals = []
29
+ harmonic_frequencies = []
30
+ index = 0
31
+
32
+ was_stationary_point = false
33
+ was_standard_orientation = false
34
+ was_mo_coefficients = false
35
+
36
+ while index < @file_lines.length
37
+ line = @file_lines[index]
38
+ if line =~ /Stationary point found/ && !was_stationary_point
39
+ print_as_success("Stationary point found")
40
+ was_stationary_point = true
41
+ index += 7
42
+ results = []
43
+ while @file_lines[index] =~ /^\s*!/
44
+ results.push(@file_lines[index])
45
+ index += 1
46
+ end
47
+ processors[:results_processor] = Processors::ResultsProcessor.new(results)
48
+ end
49
+
50
+ if line =~ /Standard orientation:/ && was_stationary_point
51
+ unless was_standard_orientation
52
+ print_as_usual("Standard orientation processing")
53
+ was_standard_orientation = true
54
+ index += 5
55
+ atom_data = []
56
+ while @file_lines[index] =~ /^(\s+\d+){3}/
57
+ atom_data.push(@file_lines[index])
58
+ index += 1
59
+ end
60
+ processors[:atom_processor] = Processors::AtomProcessor.new(atom_data)
61
+ end
62
+ end
63
+
64
+ if line =~ /Molecular Orbital Coefficients/ && was_standard_orientation
65
+ unless was_mo_coefficients
66
+ print_as_usual("Molecular orbital processing")
67
+ was_mo_coefficients = true
68
+ mo_position = index + 1
69
+ current_line = @file_lines[mo_position].split(/\s+/)
70
+ current_line.delete ""
71
+ last_number = current_line.first.to_i - 1
72
+ mo_regexp = generate_mo_regexp(last_number)
73
+ while mo_position < @file_lines.length
74
+ prev_zayniatist = nil
75
+ if @file_lines[mo_position] =~ mo_regexp &&
76
+ @file_lines[mo_position + 2] =~ /Eigenvalues --/
77
+
78
+ current_line = @file_lines[mo_position].split(/\s+/)
79
+ last_number = current_line.last.to_i
80
+ mo_regexp = generate_mo_regexp(last_number)
81
+ current_line.delete ""
82
+ energy_types = @file_lines[mo_position+=1].split(/\s+/)
83
+ energy_types.delete ""
84
+ energy_values = @file_lines[mo_position+=1].scan(/-*\d+\.*\d+/)
85
+ energy_values.delete ""
86
+
87
+ current_line.each_with_index do |elem,i|
88
+ symetry = energy_types[i].split('--').first.scan(/\w/).join
89
+ zayniatist = energy_types[i].split('--').last
90
+ prev_zayniatist ||= zayniatist
91
+ hartri = energy_values[i]
92
+ s = []
93
+ s << elem
94
+ s << symetry
95
+ s << hartri
96
+ s << hartri_to_ev(hartri)
97
+ s << zayniatist
98
+ s << if prev_zayniatist != zayniatist
99
+ previous = molecular_orbitals.last
100
+ previous.pop()
101
+ previous.push "HOMO"
102
+ molecular_orbitals.pop()
103
+ molecular_orbitals.push(previous)
104
+ "LUMO"
105
+ else
106
+ ""
107
+ end
108
+ prev_zayniatist = zayniatist
109
+ molecular_orbitals << s
110
+ end
111
+ end
112
+ mo_position += 1
113
+ end
114
+ end
115
+ end
116
+
117
+ if line =~ /Harmonic frequencies/
118
+ print_as_usual("Harmonic frequencies processing")
119
+ index += 4
120
+ current_line = @file_lines[index].split(/\s+/)
121
+ current_line.delete ""
122
+ last_number = current_line.first.to_i
123
+ hf_regexp = /^\s+#{last_number}/
124
+ while !(@file_lines[index] =~ /Thermochemistry/)
125
+ if @file_lines[index] =~ hf_regexp
126
+ harmonic_frequencies_data = []
127
+ # save index position for return back
128
+ # if it is wrong line
129
+ saved_position = index + 1
130
+ # save current line for futher analyze
131
+ saved_line = @file_lines[index]
132
+
133
+ # Begin proccessing
134
+ mode_numbers = @file_lines[index].split(/\s+/)
135
+ mode_numbers.delete ""
136
+ harmonic_frequencies_data << mode_numbers
137
+
138
+ symmetries = @file_lines[index+=1].split(/\s+/)
139
+ symmetries.delete ""
140
+ harmonic_frequencies_data << symmetries
141
+
142
+ poss_frequencies = @file_lines[index+=1].split(/ --\s+/)
143
+ unless poss_frequencies.first =~ /Frequencies/
144
+ index = saved_position
145
+ next
146
+ end
147
+ frequencies = poss_frequencies.last.split(/\s+/)
148
+ harmonic_frequencies_data << frequencies
149
+
150
+ poss_red_masses = @file_lines[index+=1].split(/ --\s+/)
151
+ unless poss_red_masses.first =~ /Red. masses/
152
+ index = saved_position
153
+ next
154
+ end
155
+ red_masses = poss_red_masses.last.split(/\s+/)
156
+ harmonic_frequencies_data << red_masses
157
+
158
+ poss_frc_consts = @file_lines[index+=1].split(/ --\s+/)
159
+ unless poss_frc_consts.first =~ /Frc consts/
160
+ index = saved_position
161
+ next
162
+ end
163
+ frc_consts = poss_frc_consts.last.split(/\s+/)
164
+ harmonic_frequencies_data << frc_consts
165
+
166
+ poss_ir_inten = @file_lines[index+=1].split(/ --\s+/)
167
+ unless poss_ir_inten.first =~ /IR Inten/
168
+ index = saved_position
169
+ next
170
+ end
171
+ ir_inten = poss_ir_inten.last.split(/\s+/)
172
+ harmonic_frequencies_data << ir_inten
173
+
174
+ poss_raman_activ = @file_lines[index+=1].split(/ --\s+/)
175
+ unless poss_raman_activ.first =~ /Raman Activ/
176
+ index = saved_position
177
+ next
178
+ end
179
+ raman_activ = poss_raman_activ.last.split(/\s+/)
180
+ harmonic_frequencies_data << raman_activ
181
+
182
+ poss_depolar_p = @file_lines[index+=1].split(/ --\s+/)
183
+ unless poss_depolar_p.first =~ /Depolar \(P\)/
184
+ index = saved_position
185
+ next
186
+ end
187
+ depolar_p = poss_depolar_p.last.split(/\s+/)
188
+ harmonic_frequencies_data << depolar_p
189
+
190
+ poss_depolar_u = @file_lines[index+=1].split(/ --\s+/)
191
+ unless poss_depolar_u.first =~ /Depolar \(U\)/
192
+ index = saved_position
193
+ next
194
+ end
195
+ depolar_u = poss_depolar_u.last.split(/\s+/)
196
+ harmonic_frequencies_data << depolar_u
197
+
198
+ current_harmonic_position = harmonic_frequencies.size
199
+ harmonic_frequencies_data[0].size.times do |i|
200
+ harmonic_frequencies[current_harmonic_position + i] = []
201
+ harmonic_frequencies_data.each do |el|
202
+ harmonic_frequencies[current_harmonic_position + i] << el[i]
203
+ end
204
+ end
205
+
206
+ # ex. 1 2 3
207
+ # Split line with mode numbers
208
+ current_line = saved_line.split(/\s+/)
209
+ current_line.delete ""
210
+ # Get last mode number for futher search
211
+ last_number = current_line.last.to_i
212
+ # next search for line that consists two neccessary numbers
213
+ # separated with whitespace
214
+ # TODO!
215
+ hf_regexp = /^\s+#{last_number+=1}/
216
+ end
217
+ index += 1
218
+ end
219
+ break
220
+ end
221
+
222
+ index += 1
223
+ end
224
+ return [
225
+ processors[:results_processor].process,
226
+ processors[:atom_processor].process,
227
+ molecular_orbitals,
228
+ harmonic_frequencies
229
+ ]
230
+ end
231
+
232
+ def hartri_to_ev(hartri)
233
+ to_ev = 27.2107
234
+ (hartri.to_f * to_ev).round 6
235
+ end
236
+
237
+ def generate_mo_regexp(last_number)
238
+ str = (1..2).to_a.inject('^') {|memo, e| memo += "\\s+#{last_number + e}"; memo }
239
+ Regexp.new(str)
240
+ end
241
+ end
242
+ end