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)


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

def amide_nitrogen?() @ob.is_amide_nitrogen end

#anti_clockwise?Boolean

Returns:

  • (Boolean)


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

def anti_clockwise?() @ob.is_anti_clockwise end

#aromatic?Boolean

Returns:

  • (Boolean)


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

def aromatic?() @ob.is_aromatic end

#aromatic_noxide?Boolean

Returns:

  • (Boolean)


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

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)


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

def axial?() @ob.is_axial end

#bondsObject

returns the bonds. Consider using each_bond.



90
91
92
# File 'lib/rubabel/atom.rb', line 90

def bonds
  each_bond.map.to_a
end

#carbon?Boolean

Returns:

  • (Boolean)


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

def carbon?() @ob.is_carbon end

#carboxyl_carbon?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/rubabel/atom.rb', line 206

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

#carboxyl_oxygen?Boolean

Returns:

  • (Boolean)


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

def carboxyl_oxygen?() @ob.is_carboxyl_oxygen end

#chiral?Boolean

Returns:

  • (Boolean)


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

def chiral?() @ob.is_chiral end

#chiral_volume?Boolean

Returns:

  • (Boolean)


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

def chiral_volume?() @ob.has_chiral_volume end

#chirality_specified?Boolean

Returns:

  • (Boolean)


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

def chirality_specified?() @ob.has_chirality_specified end

#clockwise?Boolean

Returns:

  • (Boolean)


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

def clockwise?() @ob.is_clockwise end

#connected?Boolean

Returns:

  • (Boolean)


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

def connected?() @ob.is_connected end

#coordsObject

# does this carbon hold a primary alcohol

def primary_alcohol_carbon?
end


214
215
216
# File 'lib/rubabel/atom.rb', line 214

def coords
  Vector[@ob.x, @ob.y, @ob.z]
end

#each_atom(&block) ⇒ Object

iterates through each neighboring atom



95
96
97
98
99
100
101
102
103
# File 'lib/rubabel/atom.rb', line 95

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 Also known as: each



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

#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



85
86
87
# File 'lib/rubabel/atom.rb', line 85

def get_bond(atom)
  @ob.get_bond(atom.ob).andand.upcast
end

#hbond_acceptor?Boolean

Returns:

  • (Boolean)


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

def hbond_acceptor?() @ob.is_hbond_acceptor end

#hbond_donor?Boolean

Returns:

  • (Boolean)


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

def hbond_donor?() @ob.is_hbond_donor end

#hbond_donor_h?Boolean

Returns:

  • (Boolean)


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

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)


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

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)


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

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)


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

def in_ring?() @ob.is_in_ring end

#in_ring_size?Boolean

Returns:

  • (Boolean)


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

def in_ring_size?() @ob.is_in_ring_size end

#inspectObject



218
219
220
# File 'lib/rubabel/atom.rb', line 218

def inspect
  "<#{type} id:#{id}>"
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)


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

def negative_stereo?() @ob.is_negative_stereo end

#nitro_oxygen?Boolean

Returns:

  • (Boolean)


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

def nitro_oxygen?() @ob.is_nitro_oxygen end

#nitrogen?Boolean

Returns:

  • (Boolean)


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

def nitrogen?() @ob.is_nitrogen end

#non_polar_hydrogen?Boolean

Returns:

  • (Boolean)


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

def non_polar_hydrogen?() @ob.is_non_polar_hydrogen end

#not_c_or_h?Boolean

Returns:

  • (Boolean)


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

def not_c_or_h?() @ob.is_not_cor_h end

#one_four?Boolean

Returns:

  • (Boolean)


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

def one_four?() @ob.is_one_four end

#one_three?Boolean

Returns:

  • (Boolean)


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

def one_three?() @ob.is_one_three end

#oxygen?Boolean

Returns:

  • (Boolean)


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

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)


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

def phosphate_oxygen?() @ob.is_phosphate_oxygen end

#phosphorus?Boolean

Returns:

  • (Boolean)


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

def phosphorus?() @ob.is_phosphorus end

#polar_hydrogen?Boolean

Returns:

  • (Boolean)


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

def polar_hydrogen?() @ob.is_polar_hydrogen end

#positive_stereo?Boolean

Returns:

  • (Boolean)


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

def positive_stereo?() @ob.is_positive_stereo end

#spinObject



156
157
158
# File 'lib/rubabel/atom.rb', line 156

def spin
  @ob.get_spin_multiplicity
end

#sulfate_oxygen?Boolean

Returns:

  • (Boolean)


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

def sulfate_oxygen?() @ob.is_sulfate_oxygen end

#sulfur?Boolean

Returns:

  • (Boolean)


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

def sulfur?() @ob.is_sulfur end

#typeObject



160
161
162
# File 'lib/rubabel/atom.rb', line 160

def type
  @ob.get_type
end

#valenceObject



164
165
166
# File 'lib/rubabel/atom.rb', line 164

def valence
  @ob.get_valence
end

#vectorObject



168
169
170
# File 'lib/rubabel/atom.rb', line 168

def vector
  @ob.get_vector
end