Python Verlet alghoritm and Lennard Jones simulation in Python

Click For Summary
SUMMARY

The discussion focuses on implementing the Verlet algorithm for a 2D simulation of 10 particles interacting via the Lennard-Jones potential in Python. The user has successfully plotted the Lennard-Jones potential but struggles with force calculation and particle movement. Key recommendations include defining periodic boundary conditions and correctly calculating the Lennard-Jones force based on the distance between particles. The provided code demonstrates the basic structure for the Verlet integration method, but adjustments are necessary for multi-particle simulations.

PREREQUISITES
  • Understanding of the Verlet algorithm for numerical integration
  • Familiarity with Lennard-Jones potential and its mathematical formulation
  • Proficiency in Python programming, particularly with NumPy and Matplotlib
  • Knowledge of periodic boundary conditions in simulations
NEXT STEPS
  • Implement periodic boundary conditions for multi-particle simulations
  • Calculate the Lennard-Jones force using the formula F_LJ = -∇(LJ)
  • Explore advanced techniques for optimizing particle movement in simulations
  • Learn about visualizing multi-particle interactions using Matplotlib
USEFUL FOR

Researchers, physicists, and developers interested in molecular dynamics simulations, particularly those working with particle interactions and numerical methods in Python.

iwko
Messages
1
Reaction score
0
Hello,
I created script which draw plot of Lennard Jones potential for two particles. Now i want to create 2D simulation for 10 particles with verlet alghoritm but I have no idea how to create that. My problem is implementation of verlet alghoritm and calculating forces. I implemented boundaries and drawing of particles but I do not know how to calculate force properly using verlet alghoritm so I can't implement moving properly.Someone have solution of that problem? Any advices would be useful.
Below I present my code for plot.
Python:
import numpy as np
import matplotlib.pyplot as plt

sigma = 1
e = 1
r = np.zeros([1001])
v = np.zeros([1001])
t = np.zeros([1001])
a = np.zeros([1001])
dt = 0.01
r[0] = 1

def LJ(r):
    return -24*e*((2/r*(sigma/r)**12)-1/r*(sigma/r)**6)

def verlet():
    for i in range(0,1000):
        a[i] = -LJ(r[i])
        r[i+1] = r[i] + dt*v[i]+0.5*dt**2*a[i]
        a[i+1] = -LJ(r[i+1])
        v[i+1] = v[i] + 0.5*dt*(a[i]+a[i+1])
        t[i+1] = t[i]+dt

verlet()
plt.plot(r,a)
plt.axis([1, 2, -2.5, 2.5 ])
plt.show()
 
Technology news on Phys.org
Start by writing down the equations for the Verlet algorithm.
 
Just calculate the LJ force (F_LJ=-grad(LJ)) and use that to obtain the acceleration term.

EDIT: Moreover, the LJ potential is defined based upon the distance between two particles. The way this is currently written, you don't really have a two body problem, unless your coordinate system places one of the particles at the center, which isn't going to scale with the 10 particles. For 10 particles you might want to define periodic boundary conditions with a fixed box size.
 
Last edited:
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K