Your First Lennard-Jones Potential Energy Scan in Python

Sulstice
2 min readOct 3, 2023

--

Reference:

Google Colab Notebook

The Lennard-Jones is a mathematical model that represents the van der waals forces between atoms/molecules. Let’s see if we can produce a potential energy scan where we look at a surface of an energy with the variable of distance.

First our imports:

import numpy as np
import plotly.graph_objects as go

There is an attraction and repulsive component that is modeled with the mathematical equation:

You will often see this in Molecular Dynamics as the equation to be used between atom types. Where epsilon is the well depth, r is the current distance, and Rmin is the ideal distance where the energy is the most favorable between the two atoms. Let’s write this in python to calculate our energy as a function:

def calculate_energy(epsilon, minimal_distance, distance):
energy = epsilon * (((minimal_distance / distance) ** 12) - (2 * ((minimal_distance / distance) ** 6)))
return energy

Let’s go ahead and create some arbitrary parameters of epsilon and minimal distance and only supply a list of distance values we would like to scan.

distances = np.arange(2.5, 8.0, 0.1)

epsilon = 3.2
minimal_distance = 3

potential_energy_scan = [
calculate_energy(epsilon, minimal_distance, distance)
for distance in distances
]

Let’s plot the result:

fig = go.Figure()
fig.add_trace(
go.Scatter(
x=list(distances), y=potential_energy_scan,
mode='lines+markers',
name='transaction-based model',
marker=dict(size=10)
)
)

fig.update_layout(legend=dict(itemsizing='constant'))
fig.update_layout(legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1.05,
font = dict(family = "Arial", size = 20),
bordercolor="LightSteelBlue",
borderwidth=2,
),
)
fig.update_traces(line=dict(width=5))

fig.update_layout(
template='simple_white',
xaxis_tickformat = 'i',
bargap=0.2, # gap between bars of adjacent location coordinates,
height=600,
width=1350
)


fig.show()

Let’s see the energy curve:

A cool piece of code that can be used to teach the Lennard-Jones to a general audience.

Have fun!

--

--

Sulstice
Sulstice

No responses yet