# Where can I find this formula?

I found this source code written by someone:

def get_energy_of_one_atom(atoms_vec,
period_box_len__int,
atom_index__int,
min_atom_distance__float,
max_atom_distance__float):
"""
Evaluates the energy of a single atom
"""
en = 0
for i in range(len(atoms_vec)):
if i == atom_index__int:
continue
dx = abs(atoms_vec[atom_index__int][0] - atoms_vec[i][0])
dy = abs(atoms_vec[atom_index__int][1] - atoms_vec[i][1])

dx = dx if dx < period_box_len__int / 2 else period_box_len__int - dx
dy = dy if dy < period_box_len__int / 2 else period_box_len__int - dy

d = math.sqrt(dx ** 2 + dy ** 2)

if d < min_atom_distance__float:
en += 10000000
elif d < max_atom_distance__float:
en += -1
return en


This source code calculates the energy of one gas atom in a box.

What formula was used here?

Can you supply me with a reference?

Obviously what the code does here is to treat all atoms as essentially rigid balls with a finite-ranged attraction potential: $$V(r) = \left\{\begin{array}{ll}10000000,& r and compute the energy of the total system. The resulting energy is the exact energy of an atom but with an extremely simplified and unrealistic interaction potential. The code is only applicable for calculating the energy of an atom in that particular toy model, and must be modified if realistic potentials (such as the Lennard-Jones potential) are used. There is no need to give a reference; it's even faster to work out the formulas by yourself than to look for a reference.
• If nothing else, this unrealistic potential would probably use fewer clock cycles to calculate than calculating $d^6 - d^{12}$, and might be helpful to use for testing purposes before replacing it with the "real" Lennard-Jones potential later on. Apr 26, 2022 at 16:28