Verlet alghoritm and Lennard Jones simulation in Python

In summary, the conversation discusses the creation of a 2D simulation for 10 particles with the Verlet algorithm, but the individual is struggling with the implementation and calculation of forces. They have included their code for plotting the Lennard Jones potential for two particles and are seeking advice and solutions to their problem. The conversation also mentions the need to define periodic boundary conditions for the 10 particles.
  • #1
iwko
1
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
  • #2
Start by writing down the equations for the Verlet algorithm.
 
  • #3
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:

Related to Verlet alghoritm and Lennard Jones simulation in Python

1. What is the Verlet algorithm and how is it used in Lennard Jones simulations?

The Verlet algorithm is a numerical method used to solve equations of motion in classical mechanics. In Lennard Jones simulations, it is used to calculate the positions and velocities of particles in a system over time, taking into account the interactions between particles as described by the Lennard Jones potential.

2. How does the Verlet algorithm differ from other integration methods?

The Verlet algorithm is a symplectic integrator, meaning that it preserves the energy of the system and produces more accurate results compared to other integration methods that may introduce errors over time. It also only requires the positions and velocities of particles at the current time step, making it more efficient than other methods that may require additional information.

3. What are the key steps involved in implementing the Verlet algorithm in a Lennard Jones simulation?

The key steps in implementing the Verlet algorithm in a Lennard Jones simulation include calculating the forces between particles using the Lennard Jones potential, updating the positions of particles based on their velocities and accelerations, and then updating the velocities of particles using the new positions. This process is repeated for each time step to simulate the behavior of the system over time.

4. Can the Verlet algorithm be used for other types of simulations besides Lennard Jones?

Yes, the Verlet algorithm can be used for a variety of simulations, including molecular dynamics, N-body simulations, and even simulations in quantum mechanics. It is a versatile and widely used method for solving equations of motion in various scientific fields.

5. Is there a specific programming language required for implementing the Verlet algorithm and Lennard Jones simulation?

No, the Verlet algorithm and Lennard Jones simulation can be implemented in various programming languages. However, Python is a popular choice due to its ease of use and availability of libraries for scientific computing. Other languages such as C++, Java, and Fortran can also be used.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
2
Views
924
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
3K
  • Atomic and Condensed Matter
Replies
4
Views
1K
Back
Top