Class: LennardJones

Inherits:
Object
  • Object
show all
Defined in:
lib/gimuby/problem/lennard_jones/lennard_jones.rb

Instance Method Summary collapse

Constructor Details

#initializeLennardJones

Returns a new instance of LennardJones.



5
6
7
# File 'lib/gimuby/problem/lennard_jones/lennard_jones.rb', line 5

def initialize
  @sigma = 1
end

Instance Method Details

#evaluate(atoms_positions) ⇒ Object

Parameters:

  • atoms_positions (Array)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gimuby/problem/lennard_jones/lennard_jones.rb', line 10

def evaluate(atoms_positions)
  number = atoms_positions.length
  potential = 0.0
  (number - 1).times do |i|
    atom_position_i = atoms_positions[i]
    target_indices = *(i+1..number-1)
    target_indices = [target_indices] unless target_indices.class == Array
    target_indices.each do |j|
      atom_position_j = atoms_positions[j]
      distance = get_euclidian_distance(atom_position_i, atom_position_j)
      if distance != 0
        potential += (@sigma / distance) ** 12
        potential -= (@sigma / distance) ** 6
      end
    end
  end
  potential * 4
end