Class: Aims::Bond

Inherits:
Object
  • Object
show all
Defined in:
lib/aims/bond.rb

Overview

A representation of a bond between two atoms Bonds are not directional, so two bonds are equal if they bond the same atoms regradless of order

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atom1, atom2) ⇒ Bond

Initialize a bond between two atoms



10
11
12
# File 'lib/aims/bond.rb', line 10

def initialize(atom1, atom2)
	self.atoms = [atom1, atom2]
end

Instance Attribute Details

#atomsObject

Returns the value of attribute atoms.



7
8
9
# File 'lib/aims/bond.rb', line 7

def atoms
  @atoms
end

Instance Method Details

#==(bond) ⇒ Object

Two bonds are equal iff the set of atoms in both bonds is the same.



16
17
18
19
20
21
22
# File 'lib/aims/bond.rb', line 16

def ==(bond)
	# Take the difference between the two sets
	diff1 = (self.atoms - bond.atoms)
	diff2 = (bond.atoms - self.atoms)
	# the lists are the same if both sets are empty
	diff1.empty? & diff2.empty?
end

#[](i) ⇒ Object

Access the atoms in the bond



41
42
43
# File 'lib/aims/bond.rb', line 41

def [](i)
	atoms[i]
end

#eql?(bond) ⇒ Boolean

Two bonds are eql? iff the set of atoms in both bonds is the same.

Returns:

  • (Boolean)


26
27
28
# File 'lib/aims/bond.rb', line 26

def eql?(bond)
  self == bond
end

#hashObject

Implementation of hash for equality testing



31
32
33
# File 'lib/aims/bond.rb', line 31

def hash
  self.atoms.hash
end

#lengthObject

The bond length is the distance between the two atoms



36
37
38
# File 'lib/aims/bond.rb', line 36

def length
	self.atoms[0].distance_to(self.atoms[1])
end