Class: Rubabel::Atom
Instance Attribute Summary collapse
-
#ob ⇒ Object
the OpenBabel::OBAtom object.
Class Method Summary collapse
-
.[](el_sym = :h, id = nil) ⇒ Object
takes an element symbol and creates that atom.
Instance Method Summary collapse
-
#add_atom!(other) ⇒ Object
creates a bond and adds it to both atoms.
- #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
-
#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
- #connected? ⇒ Boolean
-
#coords ⇒ Object
# does this carbon hold a primary alcohol def primary_alcohol_carbon? end.
- #double_bond? ⇒ Boolean
-
#each_atom(&block) ⇒ Object
(also: #each)
iterates through each neighboring atom.
- #each_bond(&block) ⇒ Object
-
#el ⇒ Object
abbreviated name, all lowercase as a Symbol.
-
#element ⇒ Object
abbreviated name, properly capitalized and as a String.
-
#equal?(other) ⇒ Boolean
(also: #==, #eql?)
the exact same atom in the same molecule.
- #exact_mass ⇒ 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
- #heavy_valence ⇒ Object
- #hetero_valence ⇒ Object
- #heteroatom? ⇒ Boolean
- #hyb ⇒ Object
- #hydrogen? ⇒ Boolean
- #id ⇒ Object
- #id=(val) ⇒ Object
-
#idx ⇒ Object
index of the atom (begins with 1).
- #implicit_valence ⇒ Object
- #in_ring? ⇒ Boolean
- #in_ring_size? ⇒ Boolean
-
#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_an_h!(add_charge = true) ⇒ Object
permanently removes a hydrogen by properly incrementing the spin_multiplicity (and deleting a hydrogen if one is explicitly attached to the atom).
- #single_bond? ⇒ Boolean
-
#spin ⇒ Object
end.
- #sulfate_oxygen? ⇒ Boolean
- #sulfur? ⇒ Boolean
- #type ⇒ Object
- #valence ⇒ Object
- #vector ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(obatom) ⇒ Atom
Returns a new instance of Atom.
35 36 37 |
# File 'lib/rubabel/atom.rb', line 35 def initialize(obatom) @ob = obatom end |
Instance Attribute Details
#ob ⇒ Object
the OpenBabel::OBAtom object
33 34 35 |
# File 'lib/rubabel/atom.rb', line 33 def ob @ob end |
Class Method Details
.[](el_sym = :h, id = nil) ⇒ Object
takes an element symbol and creates that atom. If el_sym is set to nil or 0, then an atom of atomic number 0 is used
19 20 21 22 23 24 |
# File 'lib/rubabel/atom.rb', line 19 def [](el_sym=:h, id=nil) ob_atom = OpenBabel::OBAtom.new ob_atom.set_id(id) if id ob_atom.set_atomic_num(Rubabel::EL_TO_NUM[el_sym] || 0) self.new(ob_atom) end |
Instance Method Details
#add_atom!(other) ⇒ Object
creates a bond and adds it to both atoms
63 64 65 66 67 68 69 70 |
# File 'lib/rubabel/atom.rb', line 63 def add_atom!(other) obbond = OpenBabel::OBBond.new obbond.set_begin(self.ob) obbond.set_end(other.ob) @ob.add_bond(obbond) other.ob.add_bond(obbond) self end |
#amide_nitrogen? ⇒ Boolean
263 |
# File 'lib/rubabel/atom.rb', line 263 def amide_nitrogen?() @ob.is_amide_nitrogen end |
#anti_clockwise? ⇒ Boolean
270 |
# File 'lib/rubabel/atom.rb', line 270 def anti_clockwise?() @ob.is_anti_clockwise end |
#aromatic? ⇒ Boolean
251 |
# File 'lib/rubabel/atom.rb', line 251 def aromatic?() @ob.is_aromatic end |
#aromatic_noxide? ⇒ Boolean
266 |
# File 'lib/rubabel/atom.rb', line 266 def aromatic_noxide?() @ob.is_aromatic_noxide end |
#atomic_mass ⇒ Object
110 111 112 |
# File 'lib/rubabel/atom.rb', line 110 def atomic_mass @ob.get_atomic_mass end |
#atomic_num ⇒ Object
114 115 116 |
# File 'lib/rubabel/atom.rb', line 114 def atomic_num @ob.get_atomic_num end |
#atoms ⇒ Object
returns the neighboring atoms. Consider using each_atom.
106 107 108 |
# File 'lib/rubabel/atom.rb', line 106 def atoms each_atom.map.to_a end |
#axial? ⇒ Boolean
268 |
# File 'lib/rubabel/atom.rb', line 268 def axial?() @ob.is_axial end |
#bonds ⇒ Object
returns the bonds. Consider using each_bond.
89 90 91 |
# File 'lib/rubabel/atom.rb', line 89 def bonds each_bond.map.to_a end |
#carbon? ⇒ Boolean
246 |
# File 'lib/rubabel/atom.rb', line 246 def carbon?() @ob.is_carbon end |
#carbonyl_carbon? ⇒ Boolean
296 297 298 |
# File 'lib/rubabel/atom.rb', line 296 def carbonyl_carbon? each_atom.any?(&:carbonyl_oxygen?) end |
#carbonyl_oxygen? ⇒ Boolean
291 292 293 294 |
# File 'lib/rubabel/atom.rb', line 291 def carbonyl_oxygen? ats = atoms ats.size == 1 && ats.first.el == :c && double_bond? end |
#carboxyl_carbon? ⇒ Boolean
287 288 289 |
# File 'lib/rubabel/atom.rb', line 287 def carboxyl_carbon? each_atom.any?(&:carboxyl_oxygen?) end |
#carboxyl_oxygen? ⇒ Boolean
259 |
# File 'lib/rubabel/atom.rb', line 259 def carboxyl_oxygen?() @ob.is_carboxyl_oxygen end |
#chiral? ⇒ Boolean
267 |
# File 'lib/rubabel/atom.rb', line 267 def chiral?() @ob.is_chiral end |
#chiral_volume? ⇒ Boolean
274 |
# File 'lib/rubabel/atom.rb', line 274 def chiral_volume?() @ob.has_chiral_volume end |
#chirality_specified? ⇒ Boolean
273 |
# File 'lib/rubabel/atom.rb', line 273 def chirality_specified?() @ob.has_chirality_specified end |
#clockwise? ⇒ Boolean
269 |
# File 'lib/rubabel/atom.rb', line 269 def clockwise?() @ob.is_clockwise end |
#connected? ⇒ Boolean
256 |
# File 'lib/rubabel/atom.rb', line 256 def connected?() @ob.is_connected end |
#coords ⇒ Object
# does this carbon hold a primary alcohol
def primary_alcohol_carbon?
end
304 305 306 |
# File 'lib/rubabel/atom.rb', line 304 def coords Vector[@ob.x, @ob.y, @ob.z] end |
#double_bond? ⇒ Boolean
279 280 281 |
# File 'lib/rubabel/atom.rb', line 279 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
94 95 96 97 98 99 100 101 102 |
# File 'lib/rubabel/atom.rb', line 94 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
72 73 74 75 76 77 78 79 80 |
# File 'lib/rubabel/atom.rb', line 72 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 |
#el ⇒ Object
abbreviated name, all lowercase as a Symbol
53 54 55 |
# File 'lib/rubabel/atom.rb', line 53 def el NUM_TO_EL[atomic_num] end |
#element ⇒ Object
abbreviated name, properly capitalized and as a String
58 59 60 |
# File 'lib/rubabel/atom.rb', line 58 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.
190 191 192 |
# File 'lib/rubabel/atom.rb', line 190 def equal?(other) other.respond_to?(:mol) && mol.equal?(other.mol) && id == other.id end |
#exact_mass ⇒ Object
118 119 120 |
# File 'lib/rubabel/atom.rb', line 118 def exact_mass @ob.get_exact_mass end |
#formal_charge ⇒ Object Also known as: charge
122 123 124 |
# File 'lib/rubabel/atom.rb', line 122 def formal_charge @ob.get_formal_charge end |
#formal_charge=(val) ⇒ Object Also known as: charge=
127 128 129 |
# File 'lib/rubabel/atom.rb', line 127 def formal_charge=(val) @ob.set_formal_charge(val) end |
#get_bond(atom) ⇒ Object
retrieves the bond
84 85 86 |
# File 'lib/rubabel/atom.rb', line 84 def get_bond(atom) @ob.get_bond(atom.ob).andand.upcast end |
#hbond_acceptor? ⇒ Boolean
275 |
# File 'lib/rubabel/atom.rb', line 275 def hbond_acceptor?() @ob.is_hbond_acceptor end |
#hbond_donor? ⇒ Boolean
276 |
# File 'lib/rubabel/atom.rb', line 276 def hbond_donor?() @ob.is_hbond_donor end |
#hbond_donor_h? ⇒ Boolean
277 |
# File 'lib/rubabel/atom.rb', line 277 def hbond_donor_h?() @ob.is_hbond_donor_h end |
#heavy_valence ⇒ Object
132 133 134 |
# File 'lib/rubabel/atom.rb', line 132 def heavy_valence @ob.get_heavy_valence end |
#hetero_valence ⇒ Object
136 137 138 |
# File 'lib/rubabel/atom.rb', line 136 def hetero_valence @ob.get_hetero_valence end |
#heteroatom? ⇒ Boolean
254 |
# File 'lib/rubabel/atom.rb', line 254 def heteroatom?() @ob.is_heteroatom end |
#hyb ⇒ Object
140 141 142 |
# File 'lib/rubabel/atom.rb', line 140 def hyb @ob.get_hybridization end |
#hydrogen? ⇒ Boolean
245 |
# File 'lib/rubabel/atom.rb', line 245 def hydrogen?() @ob.is_hydrogen end |
#id ⇒ Object
39 40 41 |
# File 'lib/rubabel/atom.rb', line 39 def id @ob.get_id end |
#id=(val) ⇒ Object
43 44 45 |
# File 'lib/rubabel/atom.rb', line 43 def id=(val) @ob.set_id(val) end |
#idx ⇒ Object
index of the atom (begins with 1)
48 49 50 |
# File 'lib/rubabel/atom.rb', line 48 def idx @ob.get_idx end |
#implicit_valence ⇒ Object
144 145 146 |
# File 'lib/rubabel/atom.rb', line 144 def implicit_valence @ob.get_implicit_valence end |
#in_ring? ⇒ Boolean
252 |
# File 'lib/rubabel/atom.rb', line 252 def in_ring?() @ob.is_in_ring end |
#in_ring_size? ⇒ Boolean
253 |
# File 'lib/rubabel/atom.rb', line 253 def in_ring_size?() @ob.is_in_ring_size end |
#inspect ⇒ Object
308 309 310 |
# File 'lib/rubabel/atom.rb', line 308 def inspect "<#{type} id:#{id}>" end |
#inspect_internals ⇒ Object
312 313 314 315 316 317 318 319 320 |
# File 'lib/rubabel/atom.rb', line 312 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
148 149 150 |
# File 'lib/rubabel/atom.rb', line 148 def isotope @ob.get_isotope end |
#mol ⇒ Object
returns the molecule that is parent of this atom
28 29 30 |
# File 'lib/rubabel/atom.rb', line 28 def mol @ob.get_parent.andand.upcast end |
#negative_stereo? ⇒ Boolean
272 |
# File 'lib/rubabel/atom.rb', line 272 def negative_stereo?() @ob.is_negative_stereo end |
#nitro_oxygen? ⇒ Boolean
262 |
# File 'lib/rubabel/atom.rb', line 262 def nitro_oxygen?() @ob.is_nitro_oxygen end |
#nitrogen? ⇒ Boolean
247 |
# File 'lib/rubabel/atom.rb', line 247 def nitrogen?() @ob.is_nitrogen end |
#non_polar_hydrogen? ⇒ Boolean
265 |
# File 'lib/rubabel/atom.rb', line 265 def non_polar_hydrogen?() @ob.is_non_polar_hydrogen end |
#not_c_or_h? ⇒ Boolean
255 |
# File 'lib/rubabel/atom.rb', line 255 def not_c_or_h?() @ob.is_not_cor_h end |
#one_four? ⇒ Boolean
258 |
# File 'lib/rubabel/atom.rb', line 258 def one_four?() @ob.is_one_four end |
#one_three? ⇒ Boolean
257 |
# File 'lib/rubabel/atom.rb', line 257 def one_three?() @ob.is_one_three end |
#oxygen? ⇒ Boolean
248 |
# File 'lib/rubabel/atom.rb', line 248 def oxygen?() @ob.is_oxygen end |
#partial_charge ⇒ Object
152 153 154 |
# File 'lib/rubabel/atom.rb', line 152 def partial_charge @ob.get_partial_charge end |
#phosphate_oxygen? ⇒ Boolean
260 |
# File 'lib/rubabel/atom.rb', line 260 def phosphate_oxygen?() @ob.is_phosphate_oxygen end |
#phosphorus? ⇒ Boolean
250 |
# File 'lib/rubabel/atom.rb', line 250 def phosphorus?() @ob.is_phosphorus end |
#polar_hydrogen? ⇒ Boolean
264 |
# File 'lib/rubabel/atom.rb', line 264 def polar_hydrogen?() @ob.is_polar_hydrogen end |
#positive_stereo? ⇒ Boolean
271 |
# File 'lib/rubabel/atom.rb', line 271 def positive_stereo?() @ob.is_positive_stereo end |
#remove_an_h!(add_charge = true) ⇒ Object
permanently removes a hydrogen by properly incrementing the spin_multiplicity (and deleting a hydrogen if one is explicitly attached to the atom). If called with cnt=2 a carbene or nitrene can be made (giving a spin_multiplicity of 3). Makes no effort to ensure that the proper number of hydrogens already exist to be deleted, just alters the spin_multiplicity and deletes the right number of hydrogens if they are available to be deleted. Adds one charge to the atom.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rubabel/atom.rb', line 163 def remove_an_h!(add_charge=true) new_spin = case @ob.get_spin_multiplicity when 0 then 2 when 2 then 3 end @ob.set_spin_multiplicity(new_spin) atoms.each do |atom| if atom.atomic_num == 1 self.mol.delete_atom(atom) break end end # add the charge (self.charge = charge + 1) if add_charge self end |
#single_bond? ⇒ Boolean
283 284 285 |
# File 'lib/rubabel/atom.rb', line 283 def single_bond? each_bond.any? {|bond| bond.bond_order == 1 } end |
#spin ⇒ Object
end
229 230 231 |
# File 'lib/rubabel/atom.rb', line 229 def spin @ob.get_spin_multiplicity end |
#sulfate_oxygen? ⇒ Boolean
261 |
# File 'lib/rubabel/atom.rb', line 261 def sulfate_oxygen?() @ob.is_sulfate_oxygen end |
#sulfur? ⇒ Boolean
249 |
# File 'lib/rubabel/atom.rb', line 249 def sulfur?() @ob.is_sulfur end |
#type ⇒ Object
233 234 235 |
# File 'lib/rubabel/atom.rb', line 233 def type @ob.get_type end |
#valence ⇒ Object
237 238 239 |
# File 'lib/rubabel/atom.rb', line 237 def valence @ob.get_valence end |
#vector ⇒ Object
241 242 243 |
# File 'lib/rubabel/atom.rb', line 241 def vector @ob.get_vector end |