Skip to content

Instantly share code, notes, and snippets.

@andersx
Last active December 16, 2015 12:38
Show Gist options
  • Save andersx/5435486 to your computer and use it in GitHub Desktop.
Save andersx/5435486 to your computer and use it in GitHub Desktop.
2D lennard jones simulation
import numpy
import random
from numba import double # Add this
from numba.decorators import autojit, jit # Add this
#@jit(argtypes=[double[:], double[:]]) # Add this if you want more speed than autojit
@autojit # Add this
def calc_energy_and_gradient(X, Y):
""" Calculate the Lennard-Jones energy and
Energy gradient between particles.
X and Y are lists containing x and y
coordinates, respectively.
"""
[ code here ]
return energy, gradient
n_particles = 16
# Initialize particle coordinates and velocities
X = numpy.array([random.random() for i in range(n_particles)])
Y = numpy.array([random.random() for i in range(n_particles)])
# Calculate initial energy and gradient
for n in range(10000):
energy, gradient = calc_energy_and_gradient(X, Y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment