Class: Alumina::Atom

Inherits:
Object show all
Includes:
HIN::Writer::Atom
Defined in:
lib/alumina/atom.rb

Overview

An atom as part of a Molecule.

Constant Summary collapse

BOND_TYPES =
[ :single, :double, :triple, :aromatic ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HIN::Writer::Atom

#to_hin

Constructor Details

#initialize(id, element, x, y, z) ⇒ Atom

Initializes a new atom. After initializing it you can define its bonds strucrure using the bind method. Atoms are added to Molecules with the @<<@ method.

checked here.

Parameters:

  • id (Fixnum)

    A unique identifier for this atom. Uniqueness is not

  • element (Element)

    The atom’s type.

  • x (Float)

    The atom’s x-coordinate in the molecule.

  • y (Float)

    The atom’s y-coordinate in the molecule.

  • z (Float)

    The atom’s z-coordinate in the molecule.



42
43
44
45
46
47
48
49
# File 'lib/alumina/atom.rb', line 42

def initialize(id, element, x, y, z)
  @id = id
  @element = element
  @x = x
  @y = y
  @z = z
  @bonds = Hash.new
end

Instance Attribute Details

#bondsHash<Atom, Symbol>

the bond type.

Returns:

  • (Hash<Atom, Symbol>)

    The atoms this atom is bonded to, along with



24
25
26
# File 'lib/alumina/atom.rb', line 24

def bonds
  @bonds
end

#elementElement

Returns The atomic type.

Returns:



15
16
17
# File 'lib/alumina/atom.rb', line 15

def element
  @element
end

#idFixnum

Returns The unique numerical identifier assigned to the atom.

Returns:

  • (Fixnum)

    The unique numerical identifier assigned to the atom.



11
12
13
# File 'lib/alumina/atom.rb', line 11

def id
  @id
end

#ignored1Object



29
30
31
# File 'lib/alumina/atom.rb', line 29

def ignored1
  @ignored1
end

#ignored2Object



29
30
31
# File 'lib/alumina/atom.rb', line 29

def ignored2
  @ignored2
end

#labelString?

Returns The optional label given to the atom.

Returns:

  • (String, nil)

    The optional label given to the atom.



13
14
15
# File 'lib/alumina/atom.rb', line 13

def label
  @label
end

#partial_chargeFixnum

Returns The partial charge.

Returns:

  • (Fixnum)

    The partial charge.



26
27
28
# File 'lib/alumina/atom.rb', line 26

def partial_charge
  @partial_charge
end

#xFloat

Returns The atom’s x-coordinate in the molecule.

Returns:

  • (Float)

    The atom’s x-coordinate in the molecule.



17
18
19
# File 'lib/alumina/atom.rb', line 17

def x
  @x
end

#yFloat

Returns The atom’s y-coordinate in the molecule.

Returns:

  • (Float)

    The atom’s y-coordinate in the molecule.



19
20
21
# File 'lib/alumina/atom.rb', line 19

def y
  @y
end

#zFloat

Returns The atom’s z-coordinate in the molecule.

Returns:

  • (Float)

    The atom’s z-coordinate in the molecule.



21
22
23
# File 'lib/alumina/atom.rb', line 21

def z
  @z
end

Class Method Details

.bind(atom1, atom2, type) ⇒ Object

Binds two atoms together.

Parameters:

  • atom1 (Atom)

    An atom to bind.

  • atom2 (Atom)

    An atom to bind.

  • The (Symbol)

    bond type. (See BOND_TYPES.)

Raises:

  • (ArgumentError)

    If an invalid bond type is given.



58
59
60
61
62
63
# File 'lib/alumina/atom.rb', line 58

def self.bind(atom1, atom2, type)
  raise ArgumentError, "Invalid bond type #{type.inspect}" unless BOND_TYPES.include?(type)
  
  atom1.bonds[atom2] = type
  atom2.bonds[atom1] = type
end

Instance Method Details

#bond_countFixnum

Returns The number of atoms bound to this atom.

Returns:

  • (Fixnum)

    The number of atoms bound to this atom.



67
68
69
# File 'lib/alumina/atom.rb', line 67

def bond_count
  bonds.size
end

#dupAtom

Creates a duplicate of this atom with no bonds.

Returns:

  • (Atom)

    A duplicate of this atom.



75
76
77
78
79
80
81
82
# File 'lib/alumina/atom.rb', line 75

def dup
  atom = Atom.new(id, element, x, y, z)
  atom.label = label
  atom.partial_charge = partial_charge
  atom.ignored1 = ignored1
  atom.ignored2 = ignored2
  return atom
end

#inspectObject



85
86
87
88
89
90
91
# File 'lib/alumina/atom.rb', line 85

def inspect
  if label then
    "#<Atom ##{id} #{label} (#{element.symbol})>"
  else
    "#<Atom ##{id} #{element.symbol}>"
  end
end