Class: Rubabel::Bond

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

Overview

delegates to obbond object if the method is missing

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#index_by, #uniq_by

Constructor Details

#initialize(obbond) ⇒ Bond

Returns a new instance of Bond.



40
41
42
# File 'lib/rubabel/bond.rb', line 40

def initialize(obbond)
  @ob = obbond
end

Instance Attribute Details

#obObject

Returns the value of attribute ob.



38
39
40
# File 'lib/rubabel/bond.rb', line 38

def ob
  @ob
end

Instance Method Details

#+(val) ⇒ Object

Increases the bond order and returns a new Rubabel::Bond object–but it will still be pointing to the same underlying @ob object.



106
107
108
109
# File 'lib/rubabel/bond.rb', line 106

def +(val)
  inc!(val)
  @ob.upcast
end

#-(val) ⇒ Object

Decreases the bond order and returns a new Rubabel::Bond object–but it will still be pointing to the same underlying @ob object. Won’t decrease below zero.



127
128
129
# File 'lib/rubabel/bond.rb', line 127

def -(val)
  self.+(-val)
end

#atomsObject

returns an array of Rubabel::Atoms



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

def atoms
  [@ob.get_begin_atom.upcast, @ob.get_end_atom.upcast]
end

#bond_orderObject Also known as: order



59
60
61
# File 'lib/rubabel/bond.rb', line 59

def bond_order
  @ob.get_bond_order
end

#bond_order=(val = 1) ⇒ Object Also known as: order=

1 = single, 2 = double, 5 = aromatic



65
66
67
# File 'lib/rubabel/bond.rb', line 65

def bond_order=(val=1)
  @ob.set_bond_order(val)
end

#dec!(val = 1) ⇒ Object

decrease the bond order by val



120
121
122
# File 'lib/rubabel/bond.rb', line 120

def dec!(val=1)
  inc!(-val)
end

#each_atom(&block) ⇒ Object Also known as: each



50
51
52
53
54
55
# File 'lib/rubabel/bond.rb', line 50

def each_atom(&block)
  block or return enum_for(__method__)
  block.call @ob.get_begin_atom.upcast
  block.call @ob.get_end_atom.upcast
  self
end

#inc!(val = 1) ⇒ Object

increase the bond order by val



112
113
114
115
116
117
# File 'lib/rubabel/bond.rb', line 112

def inc!(val=1)
  newval = @ob.get_bond_order + val
  newval = 0 if newval < 0
  @ob.set_bond_order(newval)
  self
end

#include?(atom) ⇒ Boolean

considered included if the atom ids match

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/rubabel/bond.rb', line 45

def include?(atom)
  # atoms.any? {|atm| atom.id == atm.id }
  (@ob.get_begin_atom.get_id == atom.id) || (@ob.get_end_atom.get_id == atom.id)
end

#inspectObject



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

def inspect
  bond_symbol = case bond_order
  when 2 then '='
  when 3 then ''
  else 
    '-'
  end
  "#{atoms.map(&:inspect).join(bond_symbol)}"
end

#set_atoms!(beg_atom, end_atom) ⇒ Object

returns self



71
72
73
74
75
# File 'lib/rubabel/bond.rb', line 71

def set_atoms!(beg_atom, end_atom)
  @ob.set_begin(beg_atom.ob)
  @ob.set_end(end_atom.ob)
  self
end

#set_begin!(atom) ⇒ Object

Sets the beginning atom of the bond to atom. returns self



78
79
80
81
# File 'lib/rubabel/bond.rb', line 78

def set_begin!(atom)
  @ob.set_begin(atom.ob)
  self
end

#set_end!(atom) ⇒ Object

Sets the end atom of the bond to the given atom. returns self



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

def set_end!(atom)
  @ob.set_end(atom.ob)
  self
end