rubabel 0.3.0 → 0.4.0

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
+ SHA1:
3
+ metadata.gz: 6e50e4f083ed06992600b2b86767d0d3a2b00fcf
4
+ data.tar.gz: e2b4f65a73450c8336b31d650c3c4bfff6981942
5
+ SHA512:
6
+ metadata.gz: a1e131cbc6b178f52ea340acc11ca1b48b606846cdfe3f21609e9578c7b7ecbd9f5590655c988a1098bc7356e9089a930c5570dc359df09f6384f4349d69c65f
7
+ data.tar.gz: e626626e6f236810a4e46e41bdcf63da8927e8bfe0bc2d8b271c915ba2fc48dc898012eccf0c535f2b5c95dd1281e3be2c1d99c27c53f9779811613da191629b
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ .*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubabel.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,36 +1,4 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'rake'
5
-
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gem|
8
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
9
- gem.name = "rubabel"
10
- gem.homepage = "http://github.com/princelab/rubabel"
11
- gem.license = "MIT"
12
- gem.summary = %Q{Ruby interface to the OpenBabel ruby bindings similar to pybel}
13
- gem.description = %Q{Ruby interface to the openbabel ruby bindings (or the openbabel gem). The
14
- interface attempts to be a ruby-ish analogue of pybel.}
15
- gem.email = "jtprince@gmail.com"
16
- gem.authors = ["John T. Prince"]
17
- [
18
- ["openbabel", "~> 2.3.1.2"],
19
- ["andand", "~> 1.3.3"],
20
- ["mini_magick", "~> 3.4"]
21
- ].each do |args|
22
- gem.add_dependency(*args)
23
- end
24
-
25
- [
26
- ["rspec", "~> 2.13.0"],
27
- ["rdoc", "~> 3.12"],
28
- ["jeweler", "~> 1.8.3"]
29
- ].each do |args|
30
- gem.add_development_dependency(*args)
31
- end
32
- end
33
- Jeweler::RubygemsDotOrgTasks.new
1
+ require "bundler/gem_tasks"
34
2
 
35
3
  require 'rspec/core'
36
4
  require 'rspec/core/rake_task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,3 +1,4 @@
1
+ require 'rubabel/version'
1
2
  require 'openbabel'
2
3
  require 'rubabel/molecule'
3
4
 
@@ -141,9 +141,10 @@ module Rubabel
141
141
  end
142
142
  alias_method :charge=, :formal_charge=
143
143
 
144
- def heavy_valence
145
- @ob.get_heavy_valence
146
- end
144
+ # not recognizing get_heavy_valence right now for some reason
145
+ #def heavy_valence
146
+ # @ob.get_heavy_valence
147
+ #end
147
148
 
148
149
  def hetero_valence
149
150
  @ob.get_hetero_valence
@@ -165,31 +166,75 @@ module Rubabel
165
166
  @ob.get_partial_charge
166
167
  end
167
168
 
168
- # permanently removes a hydrogen by properly incrementing the
169
- # spin_multiplicity (and deleting a hydrogen if one is explicitly attached
170
- # to the atom). If called with cnt=2 a carbene or nitrene can be made
171
- # (giving a spin_multiplicity of 3). Makes no effort to ensure that the
172
- # proper number of hydrogens already exist to be deleted, just alters the
173
- # spin_multiplicity and deletes the right number of hydrogens if they are
174
- # available to be deleted. Adds one charge to the atom.
175
- def remove_an_h!(add_charge=true)
176
- new_spin =
177
- case @ob.get_spin_multiplicity
178
- when 0 then 2
179
- when 2 then 3
169
+ # doesn't take into account pH (use Molecule#do_without_hydrogens)
170
+ def do_without_hydrogens(&block)
171
+ _obmol = @ob.get_parent
172
+ had_hydrogens = _obmol.has_hydrogens_added
173
+ _obmol.delete_hydrogens(self.ob) if had_hydrogens
174
+ reply = block.call(had_hydrogens)
175
+ _obmol.add_hydrogens(self.ob) if had_hydrogens
176
+ reply
177
+ end
178
+
179
+ # doesn't take into account pH (use Molecule#do_with_hydrogens)
180
+ def do_with_hydrogens(&block)
181
+ _obmol = @ob.get_parent
182
+ had_hydrogens = _obmol.has_hydrogens_added
183
+ _obmol.add_hydrogens(self.ob) unless had_hydrogens
184
+ reply = block.call(had_hydrogens)
185
+ _obmol.delete_hydrogens(self.ob) unless had_hydrogens
186
+ reply
187
+ end
188
+
189
+ def remove_a_proton!(add_placeholder_hydrogens=false)
190
+ remove_a_hydrogen!(0, add_placeholder_hydrogens)
191
+ end
192
+
193
+ def remove_a_hydrogen!(with_num_electrons=1, add_placeholder_hydrogens=false)
194
+ self.dec_implicit_valence!
195
+ case with_num_electrons
196
+ when 0
197
+ self.charge -= 1
198
+ when 1
199
+ raise NotImplementedError, "not doing free radicals just yet"
200
+ when 2
201
+ self.charge += 1
202
+ end
203
+ if @ob.explicit_hydrogen_count > 0
204
+ _obmol = @ob.get_parent
205
+ each do |atom|
206
+ if atom.hydrogen?
207
+ _obmol.delete_atom(atom.ob, false)
208
+ break
209
+ end
180
210
  end
181
- @ob.set_spin_multiplicity(new_spin)
182
- atoms.each do |atom|
183
- if atom.hydrogen?
184
- self.mol.delete_atom(atom)
185
- break
211
+ else
212
+ if add_placeholder_hydrogens
213
+ @ob.get_parent.add_hydrogens(@ob)
186
214
  end
187
215
  end
188
- # add the charge
189
- (self.charge = charge + 1) if add_charge
190
216
  self
191
217
  end
192
218
 
219
+ # removes a proton with its electrons from an atom.
220
+ # This gives precisely the same molecule as if the molecule were input by
221
+ # smiles. csmiles, formula, exact_mass, valence, implicit_valence, etc.
222
+ #
223
+ # mol = Rubabel["CC"]
224
+ # mol[1].remove_a_hydride!
225
+ # mol == Rubabel["C[CH2+]"] # in all characteristics
226
+ #
227
+ # Note, however, that with explicit hydrogens, the <b>partial charge</b>
228
+ # is not matching up, even though every other property seems to be. I'm
229
+ # not sure why this is.
230
+ #
231
+ # mol == Rubabel["C[CH2+]"].add_h!
232
+ # mol[1].remove_a_hydride!
233
+ # mol == Rubabel["C[CH2+]"].add_h! # identical except in partial charge!
234
+ def remove_a_hydride!(add_placeholder_hydrogens=false)
235
+ remove_a_hydrogen!(2, add_placeholder_hydrogens)
236
+ end
237
+
193
238
  # philosophy on equality: there are *so* many ways for two atoms to be
194
239
  # different that we can never really ensure that "equivalence" is met
195
240
  # without calling ~20 methods. We narrowly define equivalence so it is
@@ -250,10 +295,32 @@ module Rubabel
250
295
  @ob.get_type
251
296
  end
252
297
 
298
+ # Returns the current number of explicit connections. Don't confuse this for
299
+ # implicit_valence.
253
300
  def valence
254
301
  @ob.get_valence
255
302
  end
256
303
 
304
+ # maximum number of connections expected for this atom
305
+ def implicit_valence
306
+ @ob.get_implicit_valence
307
+ end
308
+
309
+ # set the maximum number of connections expected for this atom
310
+ def implicit_valence=(val)
311
+ @ob.set_implicit_valence(val)
312
+ end
313
+
314
+ # increase by one the maximum number of connections expected for this atom
315
+ def inc_implicit_valence!
316
+ @ob.increment_implicit_valence
317
+ end
318
+
319
+ # decrease by one the maximum number of connections expected for this atom
320
+ def dec_implicit_valence!
321
+ @ob.decrement_implicit_valence
322
+ end
323
+
257
324
  def vector
258
325
  @ob.get_vector
259
326
  end
@@ -297,6 +364,13 @@ module Rubabel
297
364
  @ob.implicit_hydrogen_count + @ob.explicit_hydrogen_count
298
365
  end
299
366
 
367
+ def implicit_hydrogen_count
368
+ @ob.implicit_hydrogen_count
369
+ end
370
+
371
+ def explicit_hydrogen_count
372
+ @ob.explicit_hydrogen_count
373
+ end
300
374
  alias_method :num_h, :hydrogen_count
301
375
 
302
376
  def double_bond?
@@ -342,6 +416,5 @@ module Rubabel
342
416
  end.compact.join(" ") << ">"
343
417
  end
344
418
 
345
-
346
419
  end
347
420
  end
@@ -227,6 +227,25 @@ module Rubabel
227
227
  end
228
228
  alias_method :h_added?, :hydrogens_added?
229
229
 
230
+ # ensures that hydrogens are added before an operation, but returns the
231
+ # molecule to the original hydrogen or no hydrogen state when finished.
232
+ # returns whatever was returned by the block.
233
+ def do_with_hydrogens(ph=nil, polaronly=false, &block)
234
+ hydr_added = @ob.has_hydrogens_added
235
+ add_h!(ph, polaronly) unless hydr_added
236
+ reply = block.call
237
+ @ob.delete_hydrogens unless hydr_added
238
+ reply
239
+ end
240
+
241
+ def do_without_hydrogens(ph=nil, polaronly=false, &block)
242
+ hydr_added = @ob.has_hydrogens_added
243
+ @ob.delete_hydrogens if hydr_added
244
+ reply = block.call
245
+ add_h!(ph, polaronly) if hydr_added
246
+ reply
247
+ end
248
+
230
249
  # returns self. Corrects for ph if ph is not nil. NOTE: the reversal of
231
250
  # arguments from the OpenBabel api.
232
251
  def add_h!(ph=nil, polaronly=false)
@@ -278,10 +297,12 @@ module Rubabel
278
297
  # #alias_method :add_h!, :add_hydrogens!
279
298
 
280
299
  # returns self
281
- def remove_h!
300
+ def delete_hydrogens!
282
301
  @ob.delete_hydrogens
283
302
  self
284
303
  end
304
+ alias_method :remove_h!, :delete_hydrogens!
305
+ alias_method :remove_hydrogens!, :delete_hydrogens!
285
306
 
286
307
  # returns just the smiles string :smi (not the id)
287
308
  def smiles
@@ -671,22 +692,6 @@ module Rubabel
671
692
  end
672
693
  distance_matrix.max
673
694
  end
674
-
675
- # adds 1 hydrogen to the formula and returns self
676
- def add_hydrogen_to_formula!
677
- string = @ob.get_formula
678
- substituted = false
679
- new_string = string.sub(/H(\d*)/) { substituted=true; "H#{$1.to_i+1}" }
680
- unless substituted
681
- new_string = string.sub("^(C?\d*)") { $1 + 'H' }
682
- end
683
- puts 'HERE'
684
- p string
685
- p new_string
686
- #@ob.set_formula(new_string)
687
- self
688
- end
689
-
690
695
  end
691
696
  end
692
697
 
@@ -58,11 +58,12 @@ module Rubabel
58
58
  nmol = self.dup
59
59
  ncarbon = nmol.atom(carbon.id)
60
60
  noxygen = nmol.atom(oxygen.id)
61
+
62
+ is_carboxyl = noxygen.carboxyl_oxygen?
63
+
61
64
  nmol.delete_bond(ncarbon, noxygen)
62
- ncarbon.remove_an_h!
63
- #noxygen.ob.set_spin_multiplicity 1
64
- noxygen.spin = 1
65
- noxygen.charge = -1
65
+ ncarbon.remove_a_hydride!
66
+ noxygen.remove_a_proton!
66
67
  nmol.split
67
68
  end
68
69
 
@@ -0,0 +1,3 @@
1
+ module Rubabel
2
+ VERSION = "0.4.0"
3
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubabel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubabel"
8
+ spec.version = Rubabel::VERSION
9
+ spec.authors = ["John T. Prince"]
10
+ spec.email = ["jtprince@gmail.com"]
11
+ spec.description = %q{Ruby interface to the OpenBabel ruby bindings similar to pybel}
12
+ spec.summary = %q{Ruby interface to the openbabel ruby bindings (or the openbabel gem). The
13
+ interface attempts to be a ruby-ish analogue of pybel.}
14
+ spec.homepage = "http://github.com/princelab/rubabel"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ [
23
+ ["openbabel", "~> 2.3.1.2"],
24
+ ["andand", "~> 1.3.3"],
25
+ ["mini_magick", "~> 3.6.0"]
26
+ ].each do |args|
27
+ spec.add_dependency(*args)
28
+ end
29
+ [
30
+ ["bundler", "~> 1.3"],
31
+ ["rspec", "~> 2.13.0"],
32
+ ["rdoc", "~> 3.12"],
33
+ ["jeweler", "~> 1.8.3"],
34
+ ["simplecov"],
35
+ ["rake"]
36
+ ].each do |args|
37
+ spec.add_development_dependency(*args)
38
+ end
39
+ end
@@ -28,8 +28,8 @@ describe 'Chemistry Toolkit Rosetta Wiki' do
28
28
  (png1.size - png2.size < delta)
29
29
  end
30
30
 
31
- def pngs_have_same_header(png1, png2, check_length=60)
32
- png1[0..check_length] == png2[0..check_length]
31
+ def pngs_have_same_header(png1, png2, check_length=18)
32
+ png1[0,check_length] == png2[0,check_length]
33
33
  end
34
34
 
35
35
  before(:each) do
@@ -269,7 +269,7 @@ describe 'Chemistry Toolkit Rosetta Wiki' do
269
269
  File.unlink('3016_highlighted.rubabel.png')
270
270
  end
271
271
 
272
- xspecify 'Align the depiction using a fixed substructure' do
272
+ specify 'Align the depiction using a fixed substructure' do
273
273
  # http://ctr.wikia.com/wiki/Align_the_depiction_using_a_fixed_substructure
274
274
  #TODO
275
275
  end
@@ -45,24 +45,127 @@ describe Rubabel::Atom do
45
45
  (mol.atoms[0].eql?(mol2.atoms[0])).should_not be_true
46
46
  end
47
47
 
48
- it 'removes hydrogens with proper charge accounting' do
49
- mol = Rubabel["CC"]
50
- mol.add_h!
51
- mol.atoms[0].remove_an_h!
52
- mol.formula.should == "C2H5"
53
- mol.csmiles.should == 'C[CH2+]'
54
- mol.exact_mass.round(5).should == 29.03913
55
- mol.charge.should == 1
56
-
57
- # can't seem to get working properly!!!
58
- #mol.atoms[0].add_an_h!
59
- #mol.formula.should == 'C2H6'
60
- #mol.csmiles.should == 'CC'
61
- #mol.charge.should == 0
62
- ##fmol.atoms[0].charge -= 1
63
- #mol.exact_mass.should == 323
48
+
49
+ describe 'removing protons and hydrides' do
50
+
51
+ def are_identical(obs, exp, atom_index)
52
+ [:formula, :csmiles, :charge, :exact_mass].each do |mol_prop|
53
+ exp_val = exp.send(mol_prop)
54
+ obs_val = obs.send(mol_prop)
55
+ exp_val.is_a?(Float) ?
56
+ (obs_val.round(5).should == exp_val.round(5)) :
57
+ (obs_val.should == exp_val)
58
+ end
59
+
60
+ [:formal_charge, :implicit_valence, :isotope, :spin, :valence, :partial_charge].each do |prop|
61
+ obs[atom_index].send(prop).should == exp.atoms[atom_index].send(prop)
62
+ end
63
+ end
64
+
65
+ context 'on a molecule with implicit hydrogens' do
66
+ subject { Rubabel["CC"] }
67
+
68
+ specify 'removing a hydride' do
69
+ subject[1].remove_a_hydride!
70
+ are_identical( subject, Rubabel["C[CH2+]"].remove_h!, 1)
71
+ end
72
+
73
+ specify 'removing a proton' do
74
+ subject[1].remove_a_proton!
75
+ are_identical( subject, Rubabel["C[CH2-]"].remove_h!, 1)
76
+ end
77
+ end
78
+
79
+ context 'on a molecule with explicit hydrogens' do
80
+ subject { Rubabel["CC"].add_h! }
81
+
82
+ specify 'removing a hydride' do
83
+ subject[1].remove_a_hydride!
84
+ are_identical( subject, Rubabel["C[CH2+]"].add_h!, 1)
85
+ end
86
+
87
+ specify 'removing a proton' do
88
+ subject[1].remove_a_proton!
89
+ are_identical( subject, Rubabel["C[CH2-]"].add_h!, 1)
90
+ end
91
+
92
+ # the :partial_charge is not matching up on these, not sure why!
93
+ specify 'the atom matches the partial_charge from atom made from smiles'
94
+ end
64
95
  end
65
96
 
97
+
98
+ # describe 'removing protons and hydrides' do
99
+ #describe 'on molecule with implicit hydrogens' do
100
+ #subject { Rubabel["CC"] }
101
+
102
+ #it 'behaves like an ethane carbanion' do
103
+ ##http://en.wikipedia.org/wiki/Carbanion
104
+ #ethane_carbanion = Rubabel["C[CH2-]"]
105
+ #ethane_carbanion.add_h! if subject.hydrogens_added?
106
+ #[:formula, :csmiles, :charge, :exact_mass].each do |mol_prop|
107
+ #ethane_carbanion.send(mol_prop).should == subject.send(mol_prop)
108
+ #end
109
+ #[:formal_charge, :implicit_valence, :isotope, :partial_charge, :spin, :valence].each do |prop|
110
+ #ethane_carbanion[1].send(prop).should == subject.atoms[altered_atom_idx].send(prop)
111
+ #end
112
+ #end
113
+ #end
114
+ #end
115
+
116
+ #xit "removes protons on molecule with implicit hydrogens" do
117
+ #mol = Rubabel["CC"]
118
+ #mol.atoms[1].remove_a_proton!
119
+ #include_examples "is ethane carbanion", mol
120
+ #end
121
+
122
+ #xit "removes protons on molecule with explicit H's" do
123
+ #mol = Rubabel["CC"]
124
+ #mol.add_h!
125
+ #mol.atoms[1].remove_a_proton!
126
+ #mol.formula.should == "C2H5-"
127
+ #mol.csmiles.should == '[CH2-]C'
128
+ #mol.exact_mass.round(5).should == 29.03913
129
+ #mol.charge.should == 1
130
+ #end
131
+ #end
132
+
133
+ #describe 'properly removing a hydride' do
134
+ #before do
135
+ #@ethane = Rubabel["CC"]
136
+ #end
137
+
138
+ #shared_examples "is ethenium" do |mol|
139
+ ## http://en.wikipedia.org/wiki/Ethenium
140
+ ## protonated ethylene
141
+ #ethenium = Rubabel["C[CH2+]"]
142
+ #ethenium.add_h! if mol.hydrogens_added?
143
+ #[:formula, :csmiles, :charge, :exact_mass].each do |mol_prop|
144
+ #ethenium.send(mol_prop).should == mol.send(mol_prop)
145
+ #end
146
+ #[:formal_charge, :implicit_valence, :isotope, :partial_charge, :spin, :valence].each do |prop|
147
+ #ethenium.send(prop).should == mol.send(prop)
148
+ #end
149
+ #end
150
+
151
+ #it "removes hydrides on molecule with implicit hydrogens" do
152
+ #@ethane.atoms[1].remove_a_hydride!
153
+ #include_examples "is ethenium", @ethane
154
+ #end
155
+
156
+ #xit "removes hydrides on molecule with explicit hydrogens" do
157
+ #@ethane = Rubabel["CC"]
158
+ #@ethane.add_h!
159
+ #@ethane.atoms[1].remove_a_hydride!
160
+ #@ethane.formula.should == "C2H5-"
161
+ #@ethane.csmiles.should == 'C[CH2-]'
162
+ #@ethane.exact_mass.round(5).should == 29.03913
163
+ #@ethane.charge.should == -1
164
+ #end
165
+ #end
166
+
167
+
168
+
66
169
  it 'can find atom identities with simple questions' do
67
170
  mol = Rubabel["NCC(O)CC(=O)"]
68
171
  (c_exp, o_exp) = mol.matches("C=O").first
@@ -54,23 +54,26 @@ describe Rubabel::Molecule::Fragmentable do
54
54
  # oxygen just steals the electron pair it is attached to. This
55
55
  # typically results in a negatively charged oxygen and a positively
56
56
  # charged carbo-cation.
57
- specify 'ether to ions (same for esters)' do
57
+ specify 'ether to ions' do
58
58
  mol = Rubabel["CCOCCN"]
59
59
  frag_set = mol.fragment(rules: [:oxe])
60
60
  frags = frag_set.first
61
61
  frags.first.csmiles.should == "C[CH2+]"
62
62
  frags.last.csmiles.should == '[O-]CC[NH3+]'
63
- frags.first.formula.should == 'C2H5'
63
+ frags.first.formula.should == 'C2H5+'
64
64
  frags.last.formula.should == 'C2H7NO'
65
65
  frags.first.exact_mass.should be_within(1e-6).of(29.03912516)
66
66
  frags.last.exact_mass.should be_within(1e-6).of(61.052763849)
67
+ end
67
68
 
69
+ specify 'ester to ions' do
68
70
  mol = Rubabel["CCOC(=O)CCN"]
69
71
  frag_set = mol.fragment(rules: [:oxe])
70
72
  ff = frag_set.first
71
73
  ff.first.csmiles.should == 'C[CH2+]'
72
74
  ff.last.csmiles.should == '[O-]C(=O)CC[NH3+]'
73
- ff.first.formula.should == "C2H5"
75
+ ff.first.formula.should == "C2H5+"
76
+
74
77
  ff.last.formula.should == "C3H7NO2"
75
78
  ff.first.exact_mass.should be_within(1e-6).of(29.03912516035)
76
79
  ff.last.exact_mass.should be_within(1e-6).of(89.04767846841)
@@ -81,10 +84,13 @@ describe Rubabel::Molecule::Fragmentable do
81
84
  frag_set = mol.fragment(rules: [:oxe])
82
85
  ff = frag_set.first
83
86
  ff.first.csmiles.should == 'CC[C+]=O'
84
- ff.last.csmiles.should == '[O-]'
85
- ff.first.formula.should == "C3H5O"
87
+ # this is a carboxylate oxygen that falls off
88
+ ff.last.csmiles.should == '[O-2]'
89
+ #ff.first.formula.should == "C3H5O"
90
+ ff.first.formula.should == "C3H5O+"
86
91
  ff.first.exact_mass.should be_within(1e-6).of(57.034039779909996)
87
- ff.last.formula.should == "O"
92
+ #ff.last.formula.should == "O"
93
+ ff.last.formula.should == "O--"
88
94
  end
89
95
 
90
96
  specify 'phosphodiester' do
@@ -92,10 +98,13 @@ describe Rubabel::Molecule::Fragmentable do
92
98
  frag_set = mol.fragment(rules: [:oxepd])
93
99
  ff = frag_set.first
94
100
  ff.first.csmiles.should == '[O-]CCC'
95
- ff.last.csmiles.should == '[NH3+]CCO[P](=O)=O'
96
- ff.first.formula.should == 'C3H7O'
101
+ #ff.last.csmiles.should == '[NH3+]CCO[P](=O)=O'
102
+ ff.last.csmiles.should == "[NH3+]CCOP(=O)=O"
103
+ #ff.first.formula.should == 'C3H7O'
104
+ ff.first.formula.should == 'C3H7O-'
97
105
  ff.first.exact_mass.should be_within(1e-6).of(59.049689844)
98
- ff.last.formula.should == 'C2H7NO3P'
106
+ #ff.last.formula.should == 'C2H7NO3P'
107
+ ff.last.formula.should == 'C2H7NO3P+'
99
108
  ff.last.exact_mass.should be_within(1e-6).of(124.016354719)
100
109
 
101
110
  mol = Rubabel["CCCOP(=O)(OCC[N+](C)(C)C)[O-]"]
@@ -105,8 +114,8 @@ describe Rubabel::Molecule::Fragmentable do
105
114
  # other are allowed to cancel one another out!
106
115
  frag_set.size.should == 4
107
116
  mols = frag_set.flatten
108
- mols.map(&:csmiles).should == ["CC[CH2+]", "[O-]P(=O)(OCC[N+](C)(C)C)[O-]", "CCCOP(=O)([O-])[O-]", "[CH2+]C[N+](C)(C)C", "[O-]CCC", "O=[P](=O)OCC[N+](C)(C)C", "CCCO[P](=O)=O", "[O-]CC[N+](C)(C)C"]
109
- mols.map(&:formula).should == ["C3H7", "C5H13NO4P", "C3H7O4P", "C5H13N", "C3H7O", "C5H13NO3P", "C3H7O3P", "C5H13NO"]
117
+ mols.map(&:csmiles).should == ["CC[CH2+]", "[O-]P(=O)(OCC[N+](C)(C)C)[O-]", "CCCOP(=O)([O-])[O-]", "[CH2+]C[N+](C)(C)C", "[O-]CCC", "O=P(=O)OCC[N+](C)(C)C", "CCCOP(=O)=O", "[O-]CC[N+](C)(C)C"]
118
+ mols.map(&:formula).should == ["C3H7+", "C5H13NO4P-", "C3H7O4P--", "C5H13N++", "C3H7O-", "C5H13NO3P+", "C3H7O3P", "C5H13NO"]
110
119
  mols.map(&:exact_mass).zip([43.05477522449, 182.05821952995, 138.00819533273, 87.10479942171, 59.04968984405, 166.06330491039, 122.01328071317, 103.09971404127]) do |act, exp|
111
120
  act.should be_within(1e-6).of(exp)
112
121
  end
@@ -126,7 +135,8 @@ describe Rubabel::Molecule::Fragmentable do
126
135
  ll = frags.last
127
136
  ll.first.csmiles.should == 'CC=CC[NH3+]'
128
137
  ll.last.csmiles.should == 'O'
129
- ff.first.formula.should == 'C4H10N'
138
+ #ff.first.formula.should == 'C4H10N'
139
+ ff.first.formula.should == 'C4H10N+'
130
140
  ff.first.exact_mass.should be_within(1e-6).of(72.0813243255)
131
141
  end
132
142
 
@@ -138,7 +148,8 @@ describe Rubabel::Molecule::Fragmentable do
138
148
  frags = mol.fragment(rules: [:oxh])
139
149
  mols = frags.flatten
140
150
  mols.map(&:csmiles).should == ["C=CCC[NH3+]", "OO", "CC(=O)CC[NH3+]", "O", "CC=CC[NH3+]", "OO"]
141
- mols.map(&:formula).should == ["C4H10N", "H2O2", "C4H10NO", "H2O", "C4H10N", "H2O2"]
151
+ mols.map(&:formula).should == ["C4H10N+", "H2O2", "C4H10NO+", "H2O", "C4H10N+", "H2O2"]
152
+ #mols.map(&:formula).should == ["C4H10N", "H2O2", "C4H10NO", "H2O", "C4H10N", "H2O2"]
142
153
  mols.map(&:exact_mass).zip([72.081324325, 34.005479304, 88.076238945, 18.010564684, 72.081324325, 34.005479304]) do |act, exp|
143
154
  act.should be_within(1e-6).of(exp)
144
155
  end
@@ -165,7 +176,8 @@ describe Rubabel::Molecule::Fragmentable do
165
176
  frags = mol.fragment(rules: [:oxh])
166
177
  mols = frags.flatten
167
178
  mols.map(&:csmiles).should == ["C=C=O", "OCCC[NH3+]", "CC(=O)O", "C=CC[NH3+]"]
168
- mols.map(&:formula).should == ["C2H2O", "C3H10NO", "C2H4O2", "C3H8N"]
179
+ #mols.map(&:formula).should == ["C2H2O", "C3H10NO", "C2H4O2", "C3H8N"]
180
+ mols.map(&:formula).should == ["C2H2O", "C3H10NO+", "C2H4O2", "C3H8N+"]
169
181
  mols.map(&:exact_mass).zip([42.010564684, 76.076238945, 60.021129368000004, 58.065674261]) do |act,exp|
170
182
  act.should be_within(1e-6).of(exp)
171
183
  end
@@ -210,18 +210,6 @@ describe Rubabel::Molecule do
210
210
  ar.first.should be_a(OpenBabel::OBRing)
211
211
  end
212
212
 
213
- describe 'making carbo-cations: spin_multiplicity and charges' do
214
- # http://openbabel.org/docs/2.3.1/Features/Radicals.html
215
- subject { mol = Rubabel["CC"] }
216
- it 'can be turned into a carbocation' do
217
- mol = subject
218
- c = mol[0]
219
- c.ob.set_spin_multiplicity 2
220
- c.charge += 1
221
- mol.csmiles.should == "C[CH2+]"
222
- end
223
- end
224
-
225
213
  describe 'masses' do
226
214
  subject { Rubabel["C(=O)COC(=O)C[NH3+]"] }
227
215
  it '#mol_wt (or #avg_mass)' do
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'rspec'
2
5
  require 'stringio'
3
6
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubabel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - John T. Prince
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-21 00:00:00.000000000 Z
11
+ date: 2013-06-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: openbabel
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: andand
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,23 +41,34 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mini_magick
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: '3.4'
47
+ version: 3.6.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: '3.4'
54
+ version: 3.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: rspec
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
73
  - - ~>
68
74
  - !ruby/object:Gem::Version
@@ -70,7 +76,6 @@ dependencies:
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
80
  - - ~>
76
81
  - !ruby/object:Gem::Version
@@ -78,7 +83,6 @@ dependencies:
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: rdoc
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
87
  - - ~>
84
88
  - !ruby/object:Gem::Version
@@ -86,7 +90,6 @@ dependencies:
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
94
  - - ~>
92
95
  - !ruby/object:Gem::Version
@@ -94,7 +97,6 @@ dependencies:
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: jeweler
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
101
  - - ~>
100
102
  - !ruby/object:Gem::Version
@@ -102,24 +104,50 @@ dependencies:
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
108
  - - ~>
108
109
  - !ruby/object:Gem::Version
109
110
  version: 1.8.3
110
- description: ! 'Ruby interface to the openbabel ruby bindings (or the openbabel gem). The
111
-
112
- interface attempts to be a ruby-ish analogue of pybel.'
113
- email: jtprince@gmail.com
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Ruby interface to the OpenBabel ruby bindings similar to pybel
140
+ email:
141
+ - jtprince@gmail.com
114
142
  executables:
115
143
  - fragmenter.rb
116
144
  extensions: []
117
- extra_rdoc_files:
118
- - LICENSE
119
- - README.md
145
+ extra_rdoc_files: []
120
146
  files:
121
147
  - .document
148
+ - .gitignore
122
149
  - .rspec
150
+ - Gemfile
123
151
  - LICENSE
124
152
  - README.md
125
153
  - Rakefile
@@ -136,6 +164,7 @@ files:
136
164
  - lib/rubabel/molecule_data.rb
137
165
  - lib/rubabel/pm.rb
138
166
  - lib/rubabel/smarts.rb
167
+ - lib/rubabel/version.rb
139
168
  - reference/OBConversion_methods.txt
140
169
  - reference/arity_method_list.txt
141
170
  - reference/arity_method_list_CLASS.txt
@@ -144,6 +173,7 @@ files:
144
173
  - reference/fragmentation_rules_.pdf
145
174
  - reference/get_methods.rb
146
175
  - reference/mol_methods.txt
176
+ - rubabel.gemspec
147
177
  - spec/chemistry_toolkit_rosetta/README.txt
148
178
  - spec/chemistry_toolkit_rosetta/benzodiazepine.sdf.gz
149
179
  - spec/chemistry_toolkit_rosetta/benzodiazepine.smi.gz
@@ -171,26 +201,51 @@ files:
171
201
  homepage: http://github.com/princelab/rubabel
172
202
  licenses:
173
203
  - MIT
204
+ metadata: {}
174
205
  post_install_message:
175
206
  rdoc_options: []
176
207
  require_paths:
177
208
  - lib
178
209
  required_ruby_version: !ruby/object:Gem::Requirement
179
- none: false
180
210
  requirements:
181
- - - ! '>='
211
+ - - '>='
182
212
  - !ruby/object:Gem::Version
183
213
  version: '0'
184
214
  required_rubygems_version: !ruby/object:Gem::Requirement
185
- none: false
186
215
  requirements:
187
- - - ! '>='
216
+ - - '>='
188
217
  - !ruby/object:Gem::Version
189
218
  version: '0'
190
219
  requirements: []
191
220
  rubyforge_project:
192
- rubygems_version: 1.8.23
221
+ rubygems_version: 2.0.2
193
222
  signing_key:
194
- specification_version: 3
195
- summary: Ruby interface to the OpenBabel ruby bindings similar to pybel
196
- test_files: []
223
+ specification_version: 4
224
+ summary: Ruby interface to the openbabel ruby bindings (or the openbabel gem). The
225
+ interface attempts to be a ruby-ish analogue of pybel.
226
+ test_files:
227
+ - spec/chemistry_toolkit_rosetta/README.txt
228
+ - spec/chemistry_toolkit_rosetta/benzodiazepine.sdf.gz
229
+ - spec/chemistry_toolkit_rosetta/benzodiazepine.smi.gz
230
+ - spec/chemistry_toolkit_rosetta/chemistry_toolkit_rosetta_spec.rb
231
+ - spec/chemistry_toolkit_rosetta/key/3016_highlighted.rubabel.frozen.png
232
+ - spec/chemistry_toolkit_rosetta/key/benzodiazepine_heavy_atom_counts.output.10.txt
233
+ - spec/chemistry_toolkit_rosetta/key/benzodiazepine_ring_counts.output.10.txt
234
+ - spec/chemistry_toolkit_rosetta/key/caffeine.frozen.png
235
+ - spec/chemistry_toolkit_rosetta/key/rule5.10.sdf
236
+ - spec/chemistry_toolkit_rosetta/tpsa.tab
237
+ - spec/rubabel/atom_spec.rb
238
+ - spec/rubabel/bond_spec.rb
239
+ - spec/rubabel/molecule/fragmentable_spec.rb
240
+ - spec/rubabel/molecule_data_spec.rb
241
+ - spec/rubabel/molecule_spec.rb
242
+ - spec/rubabel_spec.rb
243
+ - spec/spec_helper.rb
244
+ - spec/testfiles/7-oxocholesterol-d7.mol
245
+ - spec/testfiles/7-oxocholesterol-d7.sdf
246
+ - spec/testfiles/Samples.sdf
247
+ - spec/testfiles/Samples.sdf.gz
248
+ - spec/testfiles/cholesterol.mol
249
+ - spec/testfiles/cholesterol.sdf
250
+ - spec/testfiles/two.sdf
251
+ has_rdoc: