Class: LennardJones
- Inherits:
-
Object
- Object
- LennardJones
- Defined in:
- lib/gimuby/problem/lennard_jones/lennard_jones.rb
Instance Method Summary collapse
- #evaluate(atoms_positions) ⇒ Object
-
#initialize ⇒ LennardJones
constructor
A new instance of LennardJones.
Constructor Details
#initialize ⇒ LennardJones
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
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 |