예제 #1
0
파일: examples.py 프로젝트: irt21/pyising
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)
예제 #2
0
파일: examples.py 프로젝트: irt21/pyising
def md_nve(number_of_particles, temperature, box_length, number_of_steps, sample_frequency):
    """This is an example NVE (constant number of particles, system volume and system energy) simulation.

    Parameters
    ----------
    number_of_particles: int
        Number of particles to simulate.
    temperature: float
        Initial temperature of the particles, in Kelvin.
    box_length: float
        Length of a single dimension of the simulation square, in Angstrom.
    number_of_steps: int
        Number of integration steps to be performed.
    sample_frequency: int
        Frequency with which the visualisation environment is to be updated.

    Returns
    -------
    System
        System information.
    """
    system = md.initialise(number_of_particles, temperature, box_length, 'square')
    sample_system = sample.Interactions(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.time += system.timestep_length
        system.step += 1
        if system.step % sample_frequency == 0:
            sample_system.update(system)
    return system
예제 #3
0
파일: md.py 프로젝트: irt21/pyising
def initialise(number_of_particles,
               temperature,
               box_length,
               init_conf,
               timestep_length=1e-14):
    """Initialise the particle positions (this can be either as a square or random arrangement), velocities (based on
    the temperature defined, and calculate the initial forces/accelerations.

    Parameters
    ----------
    number_of_particles: int
        Number of particles to simulate.
    temperature: float
        Initial temperature of the particles, in Kelvin.
    box_length: float
        Length of a single dimension of the simulation square, in Angstrom.
    init_conf: string, optional
        The way that the particles are initially positioned. Should be one of:

        - 'square'
        - 'random'
    timestep_length: float (optional)
        Length for each Velocity-Verlet integration step, in seconds.

    Returns
    -------
    System
        System information.
    """
    system = util.System(number_of_particles,
                         temperature,
                         box_length,
                         init_conf=init_conf,
                         timestep_length=timestep_length)
    v = np.random.rand(system.particles.size, 2) - 0.5
    v2sum = np.average(np.square(v))
    v = (v - np.average(v)) * np.sqrt(2 * system.init_temp / (v2sum))
    system.particles['xvelocity'] = v[:, 0]
    system.particles['yvelocity'] = v[:, 1]
    system.particles, system.distances, system.forces = comp.compute_forces(
        system.particles, system.distances, system.forces, system.box_length)
    return system