Getting started#
A model#
from pylj.model import Model
from pylj.potentials import LennardJones, Species
argon = Species(mass=39.948, name="argon")
lj = LennardJones(epsilon=1.577e-21, sigma=3.372e-10)
model = Model.single(argon, lj)
Species takes the mass in atomic mass units. LennardJones takes the well depth in joules and the zero-crossing separation in metres. A Model is the species and the potential between each pair of them; Model.single builds it for one species.
Molecular dynamics#
from pylj import sample
from pylj.md import MDSimulation
simulation = MDSimulation.initialise(model, number_of_atoms=16, temperature=300, box=30, seed=1)
viewer = sample.Interactions(simulation)
for _ in range(2000):
simulation.step()
simulation.heat_bath(300)
simulation.sample()
if simulation.steps % 100 == 0:
viewer.update(simulation)
initialise takes the model, the number of atoms, the temperature in kelvin and the box side in Angstrom. step() advances one timestep, heat_bath() holds the temperature, sample() records the temperature, pressure and energies in simulation.samples, and the viewer redraws when asked.
Monte Carlo#
from pylj.mc import MCSimulation
simulation = MCSimulation.initialise(model, number_of_atoms=16, temperature=300, box=20, seed=1)
viewer = sample.Energy(simulation)
for _ in range(5000):
simulation.step()
if simulation.steps % 10 == 0:
simulation.sample()
if simulation.steps % 500 == 0:
viewer.update(simulation)
step() makes one Metropolis move, and sample() records the potential energy. Simulations describes both classes in full, Custom potentials how to add a potential, and Viewers and panes the viewers.