Class: Rubabel::Atom
Instance Attribute Summary collapse
-
#ob ⇒ Object
the OpenBabel::OBAtom object.
Instance Method Summary collapse
- #amide_nitrogen? ⇒ Boolean
- #anti_clockwise? ⇒ Boolean
- #aromatic? ⇒ Boolean
- #aromatic_noxide? ⇒ Boolean
- #atomic_mass ⇒ Object
- #atomic_num ⇒ Object
-
#atoms ⇒ Object
returns the neighboring atoms.
- #axial? ⇒ Boolean
-
#bond!(arg, bond_order = 1) ⇒ Object
(also: #<<)
connects the atom-like specifier to this atom through Molecule#add_atom! returns the atom that was just added for chaining.
-
#bonds ⇒ Object
returns the bonds.
- #carbon? ⇒ Boolean
- #carbonyl_carbon? ⇒ Boolean
- #carbonyl_oxygen? ⇒ Boolean
- #carboxyl_carbon? ⇒ Boolean
- #carboxyl_oxygen? ⇒ Boolean
- #chiral? ⇒ Boolean
- #chiral_volume? ⇒ Boolean
- #chirality_specified? ⇒ Boolean
- #clockwise? ⇒ Boolean
-
#connect!(atom, bond_order = 1) ⇒ Object
connects a Rubabel::Atom object with a bond.
- #connected? ⇒ Boolean
-
#coords ⇒ Object
# does this carbon hold a primary alcohol def primary_alcohol_carbon? end.
-
#dec_implicit_valence! ⇒ Object
decrease by one the maximum number of connections expected for this atom.
-
#do_with_hydrogens(&block) ⇒ Object
doesn’t take into account pH (use Molecule#do_with_hydrogens).
-
#do_without_hydrogens(&block) ⇒ Object
doesn’t take into account pH (use Molecule#do_without_hydrogens).
- #double_bond? ⇒ Boolean
-
#each_atom(&block) ⇒ Object
(also: #each)
iterates through each neighboring atom.
- #each_bond(&block) ⇒ Object
-
#element ⇒ Object
(also: #el)
elemental symbol, properly capitalized and returned as a Symbol.
-
#equal?(other) ⇒ Boolean
(also: #==, #eql?)
the exact same atom in the same molecule.
- #exact_mass ⇒ Object
- #explicit_hydrogen_count ⇒ Object
- #formal_charge ⇒ Object (also: #charge)
- #formal_charge=(val) ⇒ Object (also: #charge=)
-
#get_bond(atom) ⇒ Object
retrieves the bond.
- #hbond_acceptor? ⇒ Boolean
- #hbond_donor? ⇒ Boolean
- #hbond_donor_h? ⇒ Boolean
-
#hetero_valence ⇒ Object
not recognizing get_heavy_valence right now for some reason def heavy_valence @ob.get_heavy_valence end.
- #heteroatom? ⇒ Boolean
- #hyb ⇒ Object
- #hydrogen? ⇒ Boolean
-
#hydrogen_count ⇒ Object
(also: #num_h)
the total number of hydrogens bonded to the atom (implicit + explicit).
- #id ⇒ Object
- #id=(val) ⇒ Object
-
#idx ⇒ Object
index of the atom (begins with 1).
- #implicit_hydrogen_count ⇒ Object
-
#implicit_valence ⇒ Object
maximum number of connections expected for this atom.
-
#implicit_valence=(val) ⇒ Object
set the maximum number of connections expected for this atom.
- #in_ring? ⇒ Boolean
- #in_ring_size? ⇒ Boolean
-
#inc_implicit_valence! ⇒ Object
increase by one the maximum number of connections expected for this atom.
-
#initialize(obatom) ⇒ Atom
constructor
A new instance of Atom.
- #inspect ⇒ Object
- #inspect_internals ⇒ Object
- #isotope ⇒ Object
-
#mol ⇒ Object
returns the molecule that is parent of this atom.
- #negative_stereo? ⇒ Boolean
- #nitro_oxygen? ⇒ Boolean
- #nitrogen? ⇒ Boolean
- #non_polar_hydrogen? ⇒ Boolean
- #not_c_or_h? ⇒ Boolean
- #one_four? ⇒ Boolean
- #one_three? ⇒ Boolean
- #oxygen? ⇒ Boolean
- #partial_charge ⇒ Object
- #phosphate_oxygen? ⇒ Boolean
- #phosphorus? ⇒ Boolean
- #polar_hydrogen? ⇒ Boolean
- #positive_stereo? ⇒ Boolean
-
#remove_a_hydride!(add_placeholder_hydrogens = false) ⇒ Object
removes a proton with its electrons from an atom.
- #remove_a_hydrogen!(with_num_electrons = 1, add_placeholder_hydrogens = false) ⇒ Object
- #remove_a_proton!(add_placeholder_hydrogens = false) ⇒ Object
- #single_bond? ⇒ Boolean
-
#spin ⇒ Object
end.
- #spin=(val) ⇒ Object
- #sulfate_oxygen? ⇒ Boolean
- #sulfur? ⇒ Boolean
- #type ⇒ Object
-
#valence ⇒ Object
Returns the current number of explicit connections.
- #vector ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(obatom) ⇒ Atom
Returns a new instance of Atom.
48 49 50 |
# File 'lib/rubabel/atom.rb', line 48 def initialize(obatom) @ob = obatom end |
Instance Attribute Details
#ob ⇒ Object
the OpenBabel::OBAtom object
46 47 48 |
# File 'lib/rubabel/atom.rb', line 46 def ob @ob end |
Instance Method Details
#amide_nitrogen? ⇒ Boolean
346 |
# File 'lib/rubabel/atom.rb', line 346 def amide_nitrogen?() @ob.is_amide_nitrogen end |
#anti_clockwise? ⇒ Boolean
353 |
# File 'lib/rubabel/atom.rb', line 353 def anti_clockwise?() @ob.is_anti_clockwise end |
#aromatic? ⇒ Boolean
334 |
# File 'lib/rubabel/atom.rb', line 334 def aromatic?() @ob.is_aromatic end |
#aromatic_noxide? ⇒ Boolean
349 |
# File 'lib/rubabel/atom.rb', line 349 def aromatic_noxide?() @ob.is_aromatic_noxide end |
#atomic_mass ⇒ Object
122 123 124 |
# File 'lib/rubabel/atom.rb', line 122 def atomic_mass @ob.get_atomic_mass end |
#atomic_num ⇒ Object
126 127 128 |
# File 'lib/rubabel/atom.rb', line 126 def atomic_num @ob.get_atomic_num end |
#atoms ⇒ Object
returns the neighboring atoms. Consider using each_atom.
118 119 120 |
# File 'lib/rubabel/atom.rb', line 118 def atoms each_atom.map.to_a end |
#axial? ⇒ Boolean
351 |
# File 'lib/rubabel/atom.rb', line 351 def axial?() @ob.is_axial end |
#bond!(arg, bond_order = 1) ⇒ Object Also known as: <<
connects the atom-like specifier to this atom through Molecule#add_atom! returns the atom that was just added for chaining. Takes any argument that Molecule#add_atom! will take.
74 75 76 |
# File 'lib/rubabel/atom.rb', line 74 def bond!(arg, bond_order=1) mol.add_atom!(arg, bond_order, self) end |
#bonds ⇒ Object
returns the bonds. Consider using each_bond.
101 102 103 |
# File 'lib/rubabel/atom.rb', line 101 def bonds each_bond.map.to_a end |
#carbon? ⇒ Boolean
329 |
# File 'lib/rubabel/atom.rb', line 329 def carbon?() @ob.is_carbon end |
#carbonyl_carbon? ⇒ Boolean
393 394 395 |
# File 'lib/rubabel/atom.rb', line 393 def carbonyl_carbon? each_atom.any?(&:carbonyl_oxygen?) end |
#carbonyl_oxygen? ⇒ Boolean
388 389 390 391 |
# File 'lib/rubabel/atom.rb', line 388 def carbonyl_oxygen? ats = atoms ats.size == 1 && ats.first.el == :C && double_bond? end |
#carboxyl_carbon? ⇒ Boolean
384 385 386 |
# File 'lib/rubabel/atom.rb', line 384 def carboxyl_carbon? each_atom.any?(&:carboxyl_oxygen?) end |
#carboxyl_oxygen? ⇒ Boolean
342 |
# File 'lib/rubabel/atom.rb', line 342 def carboxyl_oxygen?() @ob.is_carboxyl_oxygen end |
#chiral? ⇒ Boolean
350 |
# File 'lib/rubabel/atom.rb', line 350 def chiral?() @ob.is_chiral end |
#chiral_volume? ⇒ Boolean
357 |
# File 'lib/rubabel/atom.rb', line 357 def chiral_volume?() @ob.has_chiral_volume end |
#chirality_specified? ⇒ Boolean
356 |
# File 'lib/rubabel/atom.rb', line 356 def chirality_specified?() @ob.has_chirality_specified end |
#clockwise? ⇒ Boolean
352 |
# File 'lib/rubabel/atom.rb', line 352 def clockwise?() @ob.is_clockwise end |
#connect!(atom, bond_order = 1) ⇒ Object
connects a Rubabel::Atom object with a bond
80 81 82 |
# File 'lib/rubabel/atom.rb', line 80 def connect!(atom, bond_order=1) @ob.get_parent.add_bond(@ob.get_idx, atom.ob.get_idx, bond_order) end |
#connected? ⇒ Boolean
339 |
# File 'lib/rubabel/atom.rb', line 339 def connected?() @ob.is_connected end |
#coords ⇒ Object
# does this carbon hold a primary alcohol
def primary_alcohol_carbon?
end
401 402 403 |
# File 'lib/rubabel/atom.rb', line 401 def coords Vector[@ob.x, @ob.y, @ob.z] end |
#dec_implicit_valence! ⇒ Object
decrease by one the maximum number of connections expected for this atom
320 321 322 |
# File 'lib/rubabel/atom.rb', line 320 def dec_implicit_valence! @ob.decrement_implicit_valence end |
#do_with_hydrogens(&block) ⇒ Object
doesn’t take into account pH (use Molecule#do_with_hydrogens)
180 181 182 183 184 185 186 187 |
# File 'lib/rubabel/atom.rb', line 180 def do_with_hydrogens(&block) _obmol = @ob.get_parent had_hydrogens = _obmol.has_hydrogens_added _obmol.add_hydrogens(self.ob) unless had_hydrogens reply = block.call(had_hydrogens) _obmol.delete_hydrogens(self.ob) unless had_hydrogens reply end |
#do_without_hydrogens(&block) ⇒ Object
doesn’t take into account pH (use Molecule#do_without_hydrogens)
170 171 172 173 174 175 176 177 |
# File 'lib/rubabel/atom.rb', line 170 def do_without_hydrogens(&block) _obmol = @ob.get_parent had_hydrogens = _obmol.has_hydrogens_added _obmol.delete_hydrogens(self.ob) if had_hydrogens reply = block.call(had_hydrogens) _obmol.add_hydrogens(self.ob) if had_hydrogens reply end |
#double_bond? ⇒ Boolean
376 377 378 |
# File 'lib/rubabel/atom.rb', line 376 def double_bond? each_bond.any? {|bond| bond.bond_order == 2 } end |
#each_atom(&block) ⇒ Object Also known as: each
iterates through each neighboring atom
106 107 108 109 110 111 112 113 114 |
# File 'lib/rubabel/atom.rb', line 106 def each_atom(&block) block or return enum_for(__method__) iter = @ob.begin_bonds _atom = @ob.begin_nbr_atom(iter) while _atom block.call _atom.upcast _atom = @ob.next_nbr_atom(iter) end end |
#each_bond(&block) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/rubabel/atom.rb', line 84 def each_bond(&block) block or return enum_for(__method__) iter = @ob.begin_bonds _bond = @ob.begin_bond(iter) while _bond block.call _bond.upcast _bond = @ob.next_bond(iter) end end |
#element ⇒ Object Also known as: el
elemental symbol, properly capitalized and returned as a Symbol
66 67 68 |
# File 'lib/rubabel/atom.rb', line 66 def element NUM_TO_ELEMENT[atomic_num] end |
#equal?(other) ⇒ Boolean Also known as: ==, eql?
the exact same atom in the same molecule. The equivalency test for molecules is a little pricey, so better to use something like atom.id == other.id if you know you are working within the same molecule.
247 248 249 |
# File 'lib/rubabel/atom.rb', line 247 def equal?(other) other.respond_to?(:mol) && mol.equal?(other.mol) && id == other.id end |
#exact_mass ⇒ Object
130 131 132 |
# File 'lib/rubabel/atom.rb', line 130 def exact_mass @ob.get_exact_mass end |
#explicit_hydrogen_count ⇒ Object
371 372 373 |
# File 'lib/rubabel/atom.rb', line 371 def explicit_hydrogen_count @ob.explicit_hydrogen_count end |
#formal_charge ⇒ Object Also known as: charge
134 135 136 |
# File 'lib/rubabel/atom.rb', line 134 def formal_charge @ob.get_formal_charge end |
#formal_charge=(val) ⇒ Object Also known as: charge=
139 140 141 |
# File 'lib/rubabel/atom.rb', line 139 def formal_charge=(val) @ob.set_formal_charge(val) end |
#get_bond(atom) ⇒ Object
retrieves the bond
96 97 98 |
# File 'lib/rubabel/atom.rb', line 96 def get_bond(atom) @ob.get_bond(atom.ob).andand.upcast end |
#hbond_acceptor? ⇒ Boolean
358 |
# File 'lib/rubabel/atom.rb', line 358 def hbond_acceptor?() @ob.is_hbond_acceptor end |
#hbond_donor? ⇒ Boolean
359 |
# File 'lib/rubabel/atom.rb', line 359 def hbond_donor?() @ob.is_hbond_donor end |
#hbond_donor_h? ⇒ Boolean
360 |
# File 'lib/rubabel/atom.rb', line 360 def hbond_donor_h?() @ob.is_hbond_donor_h end |
#hetero_valence ⇒ Object
not recognizing get_heavy_valence right now for some reason def heavy_valence
@ob.get_heavy_valence
end
149 150 151 |
# File 'lib/rubabel/atom.rb', line 149 def hetero_valence @ob.get_hetero_valence end |
#heteroatom? ⇒ Boolean
337 |
# File 'lib/rubabel/atom.rb', line 337 def heteroatom?() @ob.is_heteroatom end |
#hyb ⇒ Object
153 154 155 |
# File 'lib/rubabel/atom.rb', line 153 def hyb @ob.get_hybridization end |
#hydrogen? ⇒ Boolean
328 |
# File 'lib/rubabel/atom.rb', line 328 def hydrogen?() @ob.is_hydrogen end |
#hydrogen_count ⇒ Object Also known as: num_h
the total number of hydrogens bonded to the atom (implicit + explicit)
363 364 365 |
# File 'lib/rubabel/atom.rb', line 363 def hydrogen_count @ob.implicit_hydrogen_count + @ob.explicit_hydrogen_count end |
#id ⇒ Object
52 53 54 |
# File 'lib/rubabel/atom.rb', line 52 def id @ob.get_id end |
#id=(val) ⇒ Object
56 57 58 |
# File 'lib/rubabel/atom.rb', line 56 def id=(val) @ob.set_id(val) end |
#idx ⇒ Object
index of the atom (begins with 1)
61 62 63 |
# File 'lib/rubabel/atom.rb', line 61 def idx @ob.get_idx end |
#implicit_hydrogen_count ⇒ Object
367 368 369 |
# File 'lib/rubabel/atom.rb', line 367 def implicit_hydrogen_count @ob.implicit_hydrogen_count end |
#implicit_valence ⇒ Object
maximum number of connections expected for this atom
305 306 307 |
# File 'lib/rubabel/atom.rb', line 305 def implicit_valence @ob.get_implicit_valence end |
#implicit_valence=(val) ⇒ Object
set the maximum number of connections expected for this atom
310 311 312 |
# File 'lib/rubabel/atom.rb', line 310 def implicit_valence=(val) @ob.set_implicit_valence(val) end |
#in_ring? ⇒ Boolean
335 |
# File 'lib/rubabel/atom.rb', line 335 def in_ring?() @ob.is_in_ring end |
#in_ring_size? ⇒ Boolean
336 |
# File 'lib/rubabel/atom.rb', line 336 def in_ring_size?() @ob.is_in_ring_size end |
#inc_implicit_valence! ⇒ Object
increase by one the maximum number of connections expected for this atom
315 316 317 |
# File 'lib/rubabel/atom.rb', line 315 def inc_implicit_valence! @ob.increment_implicit_valence end |
#inspect ⇒ Object
405 406 407 |
# File 'lib/rubabel/atom.rb', line 405 def inspect "<#{type} id:#{id}>" end |
#inspect_internals ⇒ Object
409 410 411 412 413 414 415 416 417 |
# File 'lib/rubabel/atom.rb', line 409 def inspect_internals "<" << @ob.methods.grep(/get_/).map do |mthd| begin "#{mthd.to_s.sub(/get_/,'')}=#{@ob.send(mthd)}" rescue ArgumentError nil end end.compact.join(" ") << ">" end |
#isotope ⇒ Object
161 162 163 |
# File 'lib/rubabel/atom.rb', line 161 def isotope @ob.get_isotope end |
#mol ⇒ Object
returns the molecule that is parent of this atom
41 42 43 |
# File 'lib/rubabel/atom.rb', line 41 def mol @ob.get_parent.andand.upcast end |
#negative_stereo? ⇒ Boolean
355 |
# File 'lib/rubabel/atom.rb', line 355 def negative_stereo?() @ob.is_negative_stereo end |
#nitro_oxygen? ⇒ Boolean
345 |
# File 'lib/rubabel/atom.rb', line 345 def nitro_oxygen?() @ob.is_nitro_oxygen end |
#nitrogen? ⇒ Boolean
330 |
# File 'lib/rubabel/atom.rb', line 330 def nitrogen?() @ob.is_nitrogen end |
#non_polar_hydrogen? ⇒ Boolean
348 |
# File 'lib/rubabel/atom.rb', line 348 def non_polar_hydrogen?() @ob.is_non_polar_hydrogen end |
#not_c_or_h? ⇒ Boolean
338 |
# File 'lib/rubabel/atom.rb', line 338 def not_c_or_h?() @ob.is_not_cor_h end |
#one_four? ⇒ Boolean
341 |
# File 'lib/rubabel/atom.rb', line 341 def one_four?() @ob.is_one_four end |
#one_three? ⇒ Boolean
340 |
# File 'lib/rubabel/atom.rb', line 340 def one_three?() @ob.is_one_three end |
#oxygen? ⇒ Boolean
331 |
# File 'lib/rubabel/atom.rb', line 331 def oxygen?() @ob.is_oxygen end |
#partial_charge ⇒ Object
165 166 167 |
# File 'lib/rubabel/atom.rb', line 165 def partial_charge @ob.get_partial_charge end |
#phosphate_oxygen? ⇒ Boolean
343 |
# File 'lib/rubabel/atom.rb', line 343 def phosphate_oxygen?() @ob.is_phosphate_oxygen end |
#phosphorus? ⇒ Boolean
333 |
# File 'lib/rubabel/atom.rb', line 333 def phosphorus?() @ob.is_phosphorus end |
#polar_hydrogen? ⇒ Boolean
347 |
# File 'lib/rubabel/atom.rb', line 347 def polar_hydrogen?() @ob.is_polar_hydrogen end |
#positive_stereo? ⇒ Boolean
354 |
# File 'lib/rubabel/atom.rb', line 354 def positive_stereo?() @ob.is_positive_stereo end |
#remove_a_hydride!(add_placeholder_hydrogens = false) ⇒ Object
removes a proton with its electrons from an atom. This gives precisely the same molecule as if the molecule were input by smiles. csmiles, formula, exact_mass, valence, implicit_valence, etc.
mol = Rubabel["CC"]
mol[1].remove_a_hydride!
mol == Rubabel["C[CH2+]"] # in all characteristics
Note, however, that with explicit hydrogens, the partial charge is not matching up, even though every other property seems to be. I’m not sure why this is.
mol == Rubabel["C[CH2+]"].add_h!
mol[1].remove_a_hydride!
mol == Rubabel["C[CH2+]"].add_h! # identical except in partial charge!
234 235 236 |
# File 'lib/rubabel/atom.rb', line 234 def remove_a_hydride!(add_placeholder_hydrogens=false) remove_a_hydrogen!(2, add_placeholder_hydrogens) end |
#remove_a_hydrogen!(with_num_electrons = 1, add_placeholder_hydrogens = false) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/rubabel/atom.rb', line 193 def remove_a_hydrogen!(with_num_electrons=1, add_placeholder_hydrogens=false) self.dec_implicit_valence! case with_num_electrons when 0 self.charge -= 1 when 1 raise NotImplementedError, "not doing free radicals just yet" when 2 self.charge += 1 end if @ob.explicit_hydrogen_count > 0 _obmol = @ob.get_parent each do |atom| if atom.hydrogen? _obmol.delete_atom(atom.ob, false) break end end else if add_placeholder_hydrogens @ob.get_parent.add_hydrogens(@ob) end end self end |
#remove_a_proton!(add_placeholder_hydrogens = false) ⇒ Object
189 190 191 |
# File 'lib/rubabel/atom.rb', line 189 def remove_a_proton!(add_placeholder_hydrogens=false) remove_a_hydrogen!(0, add_placeholder_hydrogens) end |
#single_bond? ⇒ Boolean
380 381 382 |
# File 'lib/rubabel/atom.rb', line 380 def single_bond? each_bond.any? {|bond| bond.bond_order == 1 } end |
#spin ⇒ Object
end
286 287 288 |
# File 'lib/rubabel/atom.rb', line 286 def spin @ob.get_spin_multiplicity end |
#spin=(val) ⇒ Object
290 291 292 |
# File 'lib/rubabel/atom.rb', line 290 def spin=(val) @ob.set_spin_multiplicity(val) end |
#sulfate_oxygen? ⇒ Boolean
344 |
# File 'lib/rubabel/atom.rb', line 344 def sulfate_oxygen?() @ob.is_sulfate_oxygen end |
#sulfur? ⇒ Boolean
332 |
# File 'lib/rubabel/atom.rb', line 332 def sulfur?() @ob.is_sulfur end |
#type ⇒ Object
294 295 296 |
# File 'lib/rubabel/atom.rb', line 294 def type @ob.get_type end |
#valence ⇒ Object
Returns the current number of explicit connections. Don’t confuse this for implicit_valence.
300 301 302 |
# File 'lib/rubabel/atom.rb', line 300 def valence @ob.get_valence end |
#vector ⇒ Object
324 325 326 |
# File 'lib/rubabel/atom.rb', line 324 def vector @ob.get_vector end |