Class: Rubabel::Atom

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/rubabel/atom.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#index_by, #uniq_by

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

#obObject

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

Returns:

  • (Boolean)


263
# File 'lib/rubabel/atom.rb', line 263

def amide_nitrogen?() @ob.is_amide_nitrogen end

#anti_clockwise?Boolean

Returns:

  • (Boolean)


270
# File 'lib/rubabel/atom.rb', line 270

def anti_clockwise?() @ob.is_anti_clockwise end

#aromatic?Boolean

Returns:

  • (Boolean)


251
# File 'lib/rubabel/atom.rb', line 251

def aromatic?() @ob.is_aromatic end

#aromatic_noxide?Boolean

Returns:

  • (Boolean)


266
# File 'lib/rubabel/atom.rb', line 266

def aromatic_noxide?() @ob.is_aromatic_noxide end

#atomic_massObject



110
111
112
# File 'lib/rubabel/atom.rb', line 110

def atomic_mass
  @ob.get_atomic_mass
end

#atomic_numObject



114
115
116
# File 'lib/rubabel/atom.rb', line 114

def atomic_num
  @ob.get_atomic_num
end

#atomsObject

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

Returns:

  • (Boolean)


268
# File 'lib/rubabel/atom.rb', line 268

def axial?() @ob.is_axial end

#bondsObject

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

Returns:

  • (Boolean)


246
# File 'lib/rubabel/atom.rb', line 246

def carbon?() @ob.is_carbon end

#carbonyl_carbon?Boolean

Returns:

  • (Boolean)


296
297
298
# File 'lib/rubabel/atom.rb', line 296

def carbonyl_carbon?
  each_atom.any?(&:carbonyl_oxygen?)
end

#carbonyl_oxygen?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


287
288
289
# File 'lib/rubabel/atom.rb', line 287

def carboxyl_carbon?
  each_atom.any?(&:carboxyl_oxygen?)
end

#carboxyl_oxygen?Boolean

Returns:

  • (Boolean)


259
# File 'lib/rubabel/atom.rb', line 259

def carboxyl_oxygen?() @ob.is_carboxyl_oxygen end

#chiral?Boolean

Returns:

  • (Boolean)


267
# File 'lib/rubabel/atom.rb', line 267

def chiral?() @ob.is_chiral end

#chiral_volume?Boolean

Returns:

  • (Boolean)


274
# File 'lib/rubabel/atom.rb', line 274

def chiral_volume?() @ob.has_chiral_volume end

#chirality_specified?Boolean

Returns:

  • (Boolean)


273
# File 'lib/rubabel/atom.rb', line 273

def chirality_specified?() @ob.has_chirality_specified end

#clockwise?Boolean

Returns:

  • (Boolean)


269
# File 'lib/rubabel/atom.rb', line 269

def clockwise?() @ob.is_clockwise end

#connected?Boolean

Returns:

  • (Boolean)


256
# File 'lib/rubabel/atom.rb', line 256

def connected?() @ob.is_connected end

#coordsObject

# 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

Returns:

  • (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

#elObject

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

#elementObject

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.

Returns:

  • (Boolean)


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_massObject



118
119
120
# File 'lib/rubabel/atom.rb', line 118

def exact_mass
  @ob.get_exact_mass
end

#formal_chargeObject 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

Returns:

  • (Boolean)


275
# File 'lib/rubabel/atom.rb', line 275

def hbond_acceptor?() @ob.is_hbond_acceptor end

#hbond_donor?Boolean

Returns:

  • (Boolean)


276
# File 'lib/rubabel/atom.rb', line 276

def hbond_donor?() @ob.is_hbond_donor end

#hbond_donor_h?Boolean

Returns:

  • (Boolean)


277
# File 'lib/rubabel/atom.rb', line 277

def hbond_donor_h?() @ob.is_hbond_donor_h end

#heavy_valenceObject



132
133
134
# File 'lib/rubabel/atom.rb', line 132

def heavy_valence
  @ob.get_heavy_valence
end

#hetero_valenceObject



136
137
138
# File 'lib/rubabel/atom.rb', line 136

def hetero_valence
  @ob.get_hetero_valence
end

#heteroatom?Boolean

Returns:

  • (Boolean)


254
# File 'lib/rubabel/atom.rb', line 254

def heteroatom?() @ob.is_heteroatom end

#hybObject



140
141
142
# File 'lib/rubabel/atom.rb', line 140

def hyb
  @ob.get_hybridization
end

#hydrogen?Boolean

Returns:

  • (Boolean)


245
# File 'lib/rubabel/atom.rb', line 245

def hydrogen?() @ob.is_hydrogen end

#idObject



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

#idxObject

index of the atom (begins with 1)



48
49
50
# File 'lib/rubabel/atom.rb', line 48

def idx
  @ob.get_idx
end

#implicit_valenceObject



144
145
146
# File 'lib/rubabel/atom.rb', line 144

def implicit_valence
  @ob.get_implicit_valence
end

#in_ring?Boolean

Returns:

  • (Boolean)


252
# File 'lib/rubabel/atom.rb', line 252

def in_ring?() @ob.is_in_ring end

#in_ring_size?Boolean

Returns:

  • (Boolean)


253
# File 'lib/rubabel/atom.rb', line 253

def in_ring_size?() @ob.is_in_ring_size end

#inspectObject



308
309
310
# File 'lib/rubabel/atom.rb', line 308

def inspect
  "<#{type} id:#{id}>"
end

#inspect_internalsObject



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

#isotopeObject



148
149
150
# File 'lib/rubabel/atom.rb', line 148

def isotope
  @ob.get_isotope
end

#molObject

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

Returns:

  • (Boolean)


272
# File 'lib/rubabel/atom.rb', line 272

def negative_stereo?() @ob.is_negative_stereo end

#nitro_oxygen?Boolean

Returns:

  • (Boolean)


262
# File 'lib/rubabel/atom.rb', line 262

def nitro_oxygen?() @ob.is_nitro_oxygen end

#nitrogen?Boolean

Returns:

  • (Boolean)


247
# File 'lib/rubabel/atom.rb', line 247

def nitrogen?() @ob.is_nitrogen end

#non_polar_hydrogen?Boolean

Returns:

  • (Boolean)


265
# File 'lib/rubabel/atom.rb', line 265

def non_polar_hydrogen?() @ob.is_non_polar_hydrogen end

#not_c_or_h?Boolean

Returns:

  • (Boolean)


255
# File 'lib/rubabel/atom.rb', line 255

def not_c_or_h?() @ob.is_not_cor_h end

#one_four?Boolean

Returns:

  • (Boolean)


258
# File 'lib/rubabel/atom.rb', line 258

def one_four?() @ob.is_one_four end

#one_three?Boolean

Returns:

  • (Boolean)


257
# File 'lib/rubabel/atom.rb', line 257

def one_three?() @ob.is_one_three end

#oxygen?Boolean

Returns:

  • (Boolean)


248
# File 'lib/rubabel/atom.rb', line 248

def oxygen?() @ob.is_oxygen end

#partial_chargeObject



152
153
154
# File 'lib/rubabel/atom.rb', line 152

def partial_charge
  @ob.get_partial_charge
end

#phosphate_oxygen?Boolean

Returns:

  • (Boolean)


260
# File 'lib/rubabel/atom.rb', line 260

def phosphate_oxygen?() @ob.is_phosphate_oxygen end

#phosphorus?Boolean

Returns:

  • (Boolean)


250
# File 'lib/rubabel/atom.rb', line 250

def phosphorus?() @ob.is_phosphorus end

#polar_hydrogen?Boolean

Returns:

  • (Boolean)


264
# File 'lib/rubabel/atom.rb', line 264

def polar_hydrogen?() @ob.is_polar_hydrogen end

#positive_stereo?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


283
284
285
# File 'lib/rubabel/atom.rb', line 283

def single_bond?
  each_bond.any? {|bond| bond.bond_order == 1 }
end

#spinObject

end



229
230
231
# File 'lib/rubabel/atom.rb', line 229

def spin
  @ob.get_spin_multiplicity
end

#sulfate_oxygen?Boolean

Returns:

  • (Boolean)


261
# File 'lib/rubabel/atom.rb', line 261

def sulfate_oxygen?() @ob.is_sulfate_oxygen end

#sulfur?Boolean

Returns:

  • (Boolean)


249
# File 'lib/rubabel/atom.rb', line 249

def sulfur?() @ob.is_sulfur end

#typeObject



233
234
235
# File 'lib/rubabel/atom.rb', line 233

def type
  @ob.get_type
end

#valenceObject



237
238
239
# File 'lib/rubabel/atom.rb', line 237

def valence
  @ob.get_valence
end

#vectorObject



241
242
243
# File 'lib/rubabel/atom.rb', line 241

def vector
  @ob.get_vector
end