def periodic_boundary(number_of_steps, temperature): """This is a piece of exemplary code to show a single particle traveling across the periodic boundary. Parameters ---------- number_of_steps: int Number of step in simulation. temperature: float Temperature of simulation. """ number_of_particles = 1 sample_freq = 10 system = md.initialise(number_of_particles, temperature, 50, 'square') sampling = sample.JustCell(system) system.time = 0 for i in range(0, number_of_steps): system.particles, system.distances, system.forces = comp.compute_forces(system.particles, system.distances, system.forces, system.box_length) system.particles = md.velocity_verlet(system.particles, system.timestep_length, system.box_length) system = md.sample(system.particles, system.box_length, system.initial_particles, system) system.particles = comp.heat_bath(system.particles, system.temperature_sample, temperature) system.time += system.timestep_length system.step += 1 if system.step % sample_freq == 0: sampling.update(system)
def pbc(): number_of_particles = 1 temperature = 100 box_length = 30 number_of_steps = 10000 sample_frequency = 25 # Initialise the system system = md.initialise(number_of_particles, temperature, box_length, 'square') system.particles['xvelocity'] = (np.random.randn() - 0.5) * 14 system.particles['yvelocity'] = (np.random.randn() - 0.5) * 14 # This sets the sampling class sample_system = sample.JustCell(system) # Start at time 0 system.time = 0 # Begin the molecular dynamics loop for i in range(0, number_of_steps): # At each step, calculate the forces on each particle and get # acceleration system.compute_force() # Run the equations of motion integrator algorithm system.integrate(md.velocity_verlet) # Sample the thermodynamic and structural parameters of the system system.md_sample() # Allow the system to interact with a heat bath system.heat_bath(temperature) # Iterate the time system.time += system.timestep_length system.step += 1 # At a given frequency sample the positions and plot the RDF if system.step % sample_frequency == 0: sample_system.update(system)
def simulation(temperature): """ Runs a molecular dynamics simulation in suing the pylj molecular dynamics engine. Parameters ---------- number_of_particles: int The number of particles in the simulation temperature: float The temperature for the initialisation and thermostating box_length: float The length of the simulation square number_of_steps: int The number of molecular dynamics steps to run sample_frequency: How regularly the visualisation should be updated Returns ------- pylj.util.System The complete system information from pylj """ # Initialise the system system = md.initialise(20, temperature, 20, 'square') # This sets the sampling class sample_system = sample.JustCell(system) # Start at time 0 system.time = 0 # Begin the molecular dynamics loop for i in range(0, 1000): # Run the equations of motion integrator algorithm, this # includes the force calculation system.integrate(md.velocity_verlet) # Sample the thermodynamic and structural parameters of the system system.md_sample() # Allow the system to interact with a heat bath system.heat_bath(temperature) # Iterate the time system.time += system.timestep_length system.step += 1 # At a given frequency sample the positions and plot the RDF if system.step % 10 == 0: sample_system.update(system) return system
def simulation(temperature): """ Runs a molecular dynamics simulation in suing the pylj molecular dynamics engine. Parameters ---------- temperature: float The temperature for the initialisation and thermostating Returns ------- pylj.util.System The complete system information from pylj """ # Initialise the system system = md.initialise(2, temperature, 10, 'square', constants=[440.5, 1.522e-10], forcefield=bond) system.cut_off = 30 system.particles['xposition'] = [5e-10, 6e-10] system.particles['yposition'] = [5e-10, 6e-10] # This sets the sampling class sample_system = sample.JustCell(system, scale=2) # Start at time 0 system.time = 0 # Begin the molecular dynamics loop for i in range(0, 4000): # Run the equations of motion integrator algorithm, this # includes the force calculation system.integrate(md.velocity_verlet) # Sample the thermodynamic and structural parameters of the system system.md_sample() # Allow the system to interact with a heat bath system.heat_bath(temperature) # Iterate the time system.time += system.timestep_length system.step += 1 # At a given frequency sample the positions and plot the RDF if system.step % 10 == 0: sample_system.update(system) return system