diff --git a/build/lib.linux-x86_64-3.6/pylj/__init__.py b/build/lib.linux-x86_64-3.6/pylj/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/build/lib.linux-x86_64-3.6/pylj/_testutils.py b/build/lib.linux-x86_64-3.6/pylj/_testutils.py deleted file mode 100644 index e2336fd..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/_testutils.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Generic test utilities. -AMENDED FROM scipy version Aug17 -""" - -from __future__ import division, print_function, absolute_import - -import os -import sys - - -__all__ = ['PytestTester'] - - -class PytestTester(object): - """ - Pytest test runner entry point. - """ - - def __init__(self, module_name): - self.module_name = module_name - - def __call__(self, label="fast", verbose=1, extra_argv=None, - doctests=False, coverage=False, tests=None): - import pytest - - module = sys.modules[self.module_name] - module_path = os.path.abspath(module.__path__[0]) - - pytest_args = ['-l'] - - if doctests: - raise ValueError("Doctests not supported") - - if extra_argv: - pytest_args += list(extra_argv) - - if verbose and int(verbose) > 1: - pytest_args += ["-" + "v" * (int(verbose) - 1)] - - if coverage: - pytest_args += ["--cov=" + module_path] - - if label == "fast": - pytest_args += ["-m", "not slow"] - elif label != "full": - pytest_args += ["-m", label] - - if tests is None: - tests = [self.module_name] - - pytest_args += ['--pyargs'] + list(tests) - - try: - code = pytest.main(pytest_args) - except SystemExit as exc: - code = exc.code - - return (code == 0) diff --git a/build/lib.linux-x86_64-3.6/pylj/comp.cpython-36m-x86_64-linux-gnu.so b/build/lib.linux-x86_64-3.6/pylj/comp.cpython-36m-x86_64-linux-gnu.so deleted file mode 100755 index 574d8e1..0000000 Binary files a/build/lib.linux-x86_64-3.6/pylj/comp.cpython-36m-x86_64-linux-gnu.so and /dev/null differ diff --git a/build/lib.linux-x86_64-3.6/pylj/forcefields.py b/build/lib.linux-x86_64-3.6/pylj/forcefields.py deleted file mode 100644 index e1987b0..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/forcefields.py +++ /dev/null @@ -1,67 +0,0 @@ -import numpy as np - - -def lennard_jones(dr, constants, force=False): - r"""Calculate the energy or force for a pair of particles using the - Lennard-Jones (A/B variant) forcefield. - - .. math:: - E = \frac{A}{dr^{12}} - \frac{B}{dr^6} - - .. math:: - f = \frac{12A}{dr^{13}} - \frac{6B}{dr^7} - - Parameters - ---------- - dr: float, array_like - The distances between the all pairs of particles. - constants: float, array_like - An array of length two consisting of the A and B parameters for the - 12-6 Lennard-Jones function. - force: bool (optional) - If true, the negative first derivative will be found. - - Returns - ------- - float: - The potential energy or force between the particles. - """ - if force: - return 12 * constants[0] * np.power(dr, -13) - (6 * constants[1] * - np.power(dr, -7)) - else: - return constants[0] * np.power(dr, -12) - (constants[1] * - np.power(dr, -6)) - - -def buckingham(dr, constants, force=False): - r""" Calculate the energy or force for a pair of particles using the - Buckingham forcefield. - - .. math:: - E = Ae^{(-Bdr)} - \frac{C}{dr^6} - - .. math:: - f = ABe^{(-Bdr)} - \frac{6C}{dr^7} - - Paramters - --------- - dr: float, array_like - The distances between all the pairs of particles. - constants: float, array_like - An array of lenght three consisting of the A, B and C parameters for - the Buckingham function. - force: bool (optional) - If true, the negative first derivative will be found. - - Returns - ------- - float: - the potential energy or force between the particles. - """ - if force: - return constants[0] * constants[1] * np.exp(-constants[1] * dr) - \ - 6 * constants[2] / np.power(dr, 7) - else: - return constants[0] * np.exp(-constants[1] * dr) \ - - constants[2] / np.power(dr, 6) diff --git a/build/lib.linux-x86_64-3.6/pylj/mc.py b/build/lib.linux-x86_64-3.6/pylj/mc.py deleted file mode 100644 index d4cc1b5..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/mc.py +++ /dev/null @@ -1,187 +0,0 @@ -import numpy as np -from pylj import forcefields as ff - - -def initialise(number_of_particles, temperature, box_length, init_conf, - mass=39.948, constants=[1.363e-134, 9.273e-78], - forcefield=None): - """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' - mass: float (optional) - The mass of the particles being simulated. - constants: float, array_like (optional) - The values of the constants for the forcefield used. - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - - Returns - ------- - System - System information. - """ - from pylj import util - if forcefield is None: - forcefield = ff.lennard_jones - system = util.System(number_of_particles, temperature, box_length, - constants, forcefield, mass, - init_conf=init_conf) - system.particles['xvelocity'] = 0 - system.particles['yvelocity'] = 0 - return system - - -def initialize(number_particles, temperature, box_length, init_conf): - """Maps to the mc.initialise function to account for US english spelling. - """ - a = initialise(number_particles, temperature, box_length, init_conf) - return a - - -def sample(total_energy, system): - """Sample parameters of interest in the simulation. - - Parameters - ---------- - total_energy: float - The total system energy. - system: System - Details about the whole system - - Returns - ------- - System: - Details about the whole system, with the new temperature, pressure, - msd, and force appended to the appropriate - arrays. - """ - system.energy_sample = np.append(system.energy_sample, total_energy) - return system - - -def select_random_particle(particles): - """Selects a random particle from the system and return its index and - current position. - - Parameters - ---------- - particles: util.particle.dt, array_like - Information about the particles. - - Returns - ------- - int: - Index of the random particle that is selected. - float, array_like: - The current position of the chosen particle. - """ - random_particle = np.random.randint(0, particles.size) - position_store = [particles['xposition'][random_particle], - particles['yposition'][random_particle]] - return random_particle, position_store - - -def get_new_particle(particles, random_particle, box_length): - """Generates a new position for the particle. - - Parameters - ---------- - particles: util.particle.dt, array_like - Information about the particles. - random_particle: int - Index of the random particle that is selected. - box_length: float - Length of a single dimension of the simulation square. - - Returns - ------- - util.particle.dt, array_like - Information about the particles, updated to account for the change of - selected particle position. - """ - particles['xposition'][random_particle] = np.random.uniform(0, box_length) - particles['yposition'][random_particle] = np.random.uniform(0, box_length) - return particles - - -def accept(new_energy): - """Accept the move. - - Parameters - ---------- - new_energy: float - A new total energy for the system. - - Returns - ------- - float: - A new total energy for the system. - """ - return new_energy - - -def reject(position_store, particles, random_particle): - """Reject the move and return the particle to the original place. - - Parameters - ---------- - position_store: float, array_like - The x and y positions previously held by the particle that has moved. - particles: util.particle.dt, array_like - Information about the particles. - random_particle: int - Index of the random particle that is selected. - - Returns - ------- - util.particle.dt, array_like - Information about the particles, with the particle returned to the - original position - """ - particles['xposition'][random_particle] = position_store[0] - particles['yposition'][random_particle] = position_store[1] - return particles - - -def metropolis(temperature, old_energy, new_energy, n=np.random.rand()): - """Determines if the move is accepted or rejected based on the metropolis - condition. - - Parameters - ---------- - temperature: float - Simulation temperature. - old_energy: float - The total energy of the simulation in the previous configuration. - new_energy: float - The total energy of the simulation in the current configuration. - n: float, optional - The random number against which the Metropolis condition is tested. The - default is from a numpy uniform distribution. - - Returns - ------- - bool - True if the move should be accepted. - """ - boltzmann_constant = 1.3806e-23 # joules/kelvin - beta = 1 / (boltzmann_constant * temperature) - energy_difference = new_energy - old_energy - metropolis_factor = np.exp(-beta * energy_difference) - if n < metropolis_factor: - return True - else: - return False diff --git a/build/lib.linux-x86_64-3.6/pylj/md.py b/build/lib.linux-x86_64-3.6/pylj/md.py deleted file mode 100644 index d8d061a..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/md.py +++ /dev/null @@ -1,365 +0,0 @@ -import numpy as np -from pylj import pairwise as heavy -from pylj import forcefields as ff - - -def initialise(number_of_particles, temperature, box_length, init_conf, - timestep_length=1e-14, mass=39.948, - constants=[1.363e-134, 9.273e-78], forcefield=None): - """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. - mass: float (optional) - The mass of the particles being simulated. - constants: float, array_like (optional) - The values of the constants for the forcefield used. - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - - Returns - ------- - System - System information. - """ - from pylj import util - if forcefield is None: - forcefield = ff.lennard_jones - - system = util.System(number_of_particles, temperature, box_length, - constants, forcefield, mass, - init_conf=init_conf, - timestep_length=timestep_length) - v = np.random.rand(system.particles.size, 2, 12) - v = np.sum(v, axis=2) - 6. - mass_kg = mass * 1.6605e-27 - v = v * np.sqrt(1.3806e-23 * system.init_temp / mass_kg) - v = v - np.average(v) - system.particles['xvelocity'] = v[:, 0] - system.particles['yvelocity'] = v[:, 1] - return system - - -def initialize(number_particles, temperature, box_length, init_conf, - timestep_length=1e-14): - """Maps to the md.initialise function to account for US english spelling. - """ - a = initialise(number_particles, temperature, box_length, init_conf, - timestep_length) - return a - - -def velocity_verlet(particles, timestep_length, box_length, - cut_off, constants, forcefield, mass): - """Uses the Velocity-Verlet integrator to move forward in time. The - Updates the particles positions and velocities in terms of the Velocity - Verlet algorithm. Also calculates the instanteous temperature, pressure, - and force and appends these to the appropriate system array. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - timestep_length: float - Length for each Velocity-Verlet integration step, in seconds. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - Returns - ------- - util.particle_dt, array_like: - Information about the particles, with new positions and velocities. - """ - xposition_store = list(particles['xposition']) - yposition_store = list(particles['yposition']) - pos, prev_pos = update_positions([particles['xposition'], - particles['yposition']], - [particles['xprevious_position'], - particles['yprevious_position']], - [particles['xvelocity'], - particles['yvelocity']], - [particles['xacceleration'], - particles['yacceleration']], - timestep_length, box_length) - [particles['xposition'], particles['yposition']] = pos - [particles['xprevious_position'], particles['yprevious_position']] = pos - xacceleration_store = list(particles['xacceleration']) - yacceleration_store = list(particles['yacceleration']) - particles, distances, forces, energies = heavy.compute_force( - particles, box_length, cut_off, constants, forcefield, mass) - [particles['xvelocity'], particles['yvelocity']] = update_velocities( - [particles['xvelocity'], particles['yvelocity']], - [xacceleration_store, yacceleration_store], - [particles['xacceleration'], particles['yacceleration']], - timestep_length) - particles['xprevious_position'] = xposition_store - particles['yprevious_position'] = yposition_store - return particles, distances, forces, energies - - -def sample(particles, box_length, initial_particles, system): - """Sample parameters of interest in the simulation. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - initial_particles: util.particle_dt, array-like - Information about the initial particle conformation. - system: System - Details about the whole system - Returns - ------- - System: - Details about the whole system, with the new temperature, pressure, - msd, and force appended to the appropriate - arrays. - """ - temperature_new = calculate_temperature(particles, system.mass) - system.temperature_sample = np.append(system.temperature_sample, - temperature_new) - pressure_new = heavy.calculate_pressure( - particles, box_length, temperature_new, system.cut_off, - system.constants, system.forcefield) - msd_new = calculate_msd(particles, initial_particles, box_length) - system.pressure_sample = np.append(system.pressure_sample, pressure_new) - system.force_sample = np.append(system.force_sample, np.sum(system.forces)) - system.energy_sample = np.append( - system.energy_sample, np.sum(system.energies)) - system.msd_sample = np.append(system.msd_sample, msd_new) - return system - - -def calculate_msd(particles, initial_particles, box_length): - """Determines the mean squared displacement of the particles in the system. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - initial_particles: util.particle_dt, array_like - Information about the initial state of the particles. - box_length: float - Size of the cell vector. - Returns - ------- - float: - Mean squared deviation for the particles at the given timestep. - """ - xpos = np.array(particles['xposition']) - ypos = np.array(particles['yposition']) - dxinst = xpos - particles['xprevious_position'] - dyinst = ypos - particles['yprevious_position'] - for i in range(0, particles['xposition'].size): - if np.abs(dxinst[i]) > 0.5 * box_length: - if xpos[i] <= 0.5 * box_length: - particles['xpbccount'][i] += 1 - if xpos[i] > 0.5 * box_length: - particles['xpbccount'][i] -= 1 - xpos[i] += box_length * particles['xpbccount'][i] - if np.abs(dyinst[i]) > 0.5 * box_length: - if ypos[i] <= 0.5 * box_length: - particles['ypbccount'][i] += 1 - if ypos[i] > 0.5 * box_length: - particles['ypbccount'][i] -= 1 - ypos[i] += box_length * particles['ypbccount'][i] - dx = xpos - initial_particles['xposition'] - dy = ypos - initial_particles['yposition'] - dr = np.sqrt(dx * dx + dy * dy) - return np.average(dr ** 2) - - -def update_positions(positions, old_positions, velocities, - accelerations, timestep_length, box_length): - """Update the particle positions using the Velocity-Verlet integrator. - Parameters - ---------- - positions: (2, N) array_like - Where N is the number of particles, and the first row are the x - positions and the second row the y positions. - old_positions: (2, N) array_like - Where N is the number of particles, and the first row are the - previous x positions and the second row are the y positions. - velocities: (2, N) array_like - Where N is the number of particles, and the first row are the x - velocities and the second row the y velocities. - accelerations: (2, N) array_like - Where N is the number of particles, and the first row are the x - accelerations and the second row the y - accelerations. - timestep_length: float - Length for each Velocity-Verlet integration step, in seconds. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - Returns - ------- - (2, N) array_like: - Updated positions. - """ - old_positions[0] = np.array(positions[0]) - old_positions[1] = np.array(positions[1]) - positions[0] += ( - velocities[0] * timestep_length) + ( - 0.5 * accelerations[0] * timestep_length * timestep_length) - positions[1] += ( - velocities[1] * timestep_length) + ( - 0.5 * accelerations[1] * timestep_length * timestep_length) - positions[0] = positions[0] % box_length - positions[1] = positions[1] % box_length - return [positions[0], positions[1]], [old_positions[0], old_positions[1]] - - -def update_velocities(velocities, accelerations_old, accelerations_new, - timestep_length): - """Update the particle velocities using the Velocity-Verlet algoritm. - Parameters - ---------- - velocities: (2, N) array_like - Where N is the number of particles, and the first row are the x - velocities and the second row the y velocities. - accelerations: (2, N) array_like - Where N is the number of particles, and the first row are the x - accelerations and the second row the y - accelerations. - timestep_length: float - Length for each Velocity-Verlet integration step, in seconds. - Returns - ------- - (2, N) array_like: - Updated velocities. - """ - velocities[0] += 0.5 * (accelerations_old[0] + - accelerations_new[0]) * timestep_length - velocities[1] += 0.5 * (accelerations_old[1] + - accelerations_new[1]) * timestep_length - return [velocities[0], velocities[1]] - - -def calculate_temperature(particles, mass): - """Determine the instantaneous temperature of the system. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - Returns - ------- - float: - Calculated instantaneous simulation temperature. - """ - boltzmann_constant = 1.3806e-23 # joules/kelvin - atomic_mass_unit = 1.660539e-27 # kilograms - mass_kg = mass * atomic_mass_unit # kilograms - v = np.sqrt((particles['xvelocity'] * particles['xvelocity']) + - (particles['yvelocity'] * particles['yvelocity'])) - k = 0.5 * np.sum(mass_kg * v * v) - t = k / (particles.size * boltzmann_constant) - return t - - -def compute_force(particles, box_length, cut_off, constants, forcefield, mass): - r"""Calculates the forces and therefore the accelerations on each of the - particles in the simulation. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - cut_off: float - The distance greater than which the forces between particles is taken - as zero. - constants: float, array_like (optional) - The constants associated with the particular forcefield used, e.g. for - the function forcefields.lennard_jones, theses are [A, B] - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - mass: float (optional) - The mass of the particle being simulated (units of atomic mass units). - Returns - ------- - util.particle_dt, array_like - Information about particles, with updated accelerations and forces. - float, array_like - Current distances between pairs of particles in the simulation. - float, array_like - Current forces between pairs of particles in the simulation. - float, array_like - Current energies between pairs of particles in the simulation. - """ - part, dist, forces, energies = heavy.compute_force(particles, - box_length, - cut_off, - constants, - forcefield, - mass=mass) - return part, dist, forces, energies - - -def compute_energy(particles, box_length, cut_off, constants, forcefield): - r"""Calculates the total energy of the simulation. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - cut_off: float - The distance greater than which the energies between particles is - taken as zero. - constants: float, array_like (optional) - The constants associated with the particular forcefield used, e.g. for - the function forcefields.lennard_jones, theses are [A, B] - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - Returns - ------- - util.particle_dt, array_like - Information about particles, with updated accelerations and forces. - float, array_like - Current distances between pairs of particles in the simulation. - float, array_like - Current energies between pairs of particles in the simulation. - """ - dist, energies = heavy.compute_energy(particles, - box_length, - cut_off, - constants, - forcefield) - return dist, energies - - -def heat_bath(particles, temperature_sample, bath_temperature): - r"""Rescales the velocities of the particles in the system to control the - temperature of the simulation. Thereby allowing for an NVT ensemble. The - velocities are rescaled according the following relationship, - .. math:: - v_{\text{new}} = v_{\text{old}} \times - \sqrt{\frac{T_{\text{desired}}}{\bar{T}}} - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - temperature_sample: float, array_like - The temperature at each timestep in the simulation. - bath_temp: float - The desired temperature of the simulation. - Returns - ------- - util.particle_dt, array_like - Information about the particles with new, rescaled velocities. - """ - particles = heavy.heat_bath(particles, temperature_sample, - bath_temperature) - return particles diff --git a/build/lib.linux-x86_64-3.6/pylj/pairwise.py b/build/lib.linux-x86_64-3.6/pylj/pairwise.py deleted file mode 100644 index c7c08df..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/pairwise.py +++ /dev/null @@ -1,286 +0,0 @@ -from __future__ import division -import numpy as np -try: - from pylj import comp as heavy -except ImportError: - print("WARNING, using slow force and energy calculations") - from pylj import pairwise as heavy - - -def compute_force(particles, box_length, cut_off, constants, forcefield, mass): - r"""Calculates the forces and therefore the accelerations on each of the - particles in the simulation. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - cut_off: float - The distance greater than which the forces between particles is taken - as zero. - constants: float, array_like (optional) - The constants associated with the particular forcefield used, e.g. for - the function forcefields.lennard_jones, theses are [A, B] - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - mass: float (optional) - The mass of the particle being simulated (units of atomic mass units). - Returns - ------- - util.particle_dt, array_like - Information about particles, with updated accelerations and forces. - float, array_like - Current distances between pairs of particles in the simulation. - float, array_like - Current forces between pairs of particles in the simulation. - float, array_like - Current energies between pairs of particles in the simulation. - """ - particles['xacceleration'] = np.zeros(particles['xacceleration'].size) - particles['yacceleration'] = np.zeros(particles['yacceleration'].size) - pairs = int((particles['xacceleration'].size - 1) * - particles['xacceleration'].size / 2) - forces = np.zeros(pairs) - distances = np.zeros(pairs) - energies = np.zeros(pairs) - atomic_mass_unit = 1.660539e-27 # kilograms - mass_amu = mass # amu - mass_kg = mass_amu * atomic_mass_unit # kilograms - distances, dx, dy = heavy.dist(particles['xposition'], - particles['yposition'], box_length) - forces = forcefield(distances, constants, force=True) - energies = forcefield(distances, constants, force=False) - forces[np.where(distances > cut_off)] = 0. - energies[np.where(distances > cut_off)] = 0. - particles = update_accelerations(particles, forces, mass_kg, dx, dy, - distances) - return particles, distances, forces, energies - - -def separation(dx, dy): - """Calculate the distance in 2D space. - Parameters - ---------- - dx: float - Vector in the x dimension - dy: float - Vector in the y dimension - Returns - float: - Magnitude of the 2D vector. - """ - return np.sqrt(dx * dx + dy * dy) - - -def update_accelerations(particles, f, m, dx, dy, dr): - """Update the acceleration arrays of particles. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - f: float - The force on the pair of particles. - m: float - Mass of the particles. - dx: float - Distance between the particles in the x dimension. - dy: float - Distance between the particles in the y dimension. - dr: float - Distance between the particles. - Returns - ------- - util.particle_dt, array_like - Information about the particles with updated accelerations. - """ - k = 0 - for i in range(0, particles.size-1): - for j in range(i + 1, particles.size): - particles['xacceleration'][i] += second_law(f[k], m, dx[k], dr[k]) - particles['yacceleration'][i] += second_law(f[k], m, dy[k], dr[k]) - particles['xacceleration'][j] -= second_law(f[k], m, dx[k], dr[k]) - particles['yacceleration'][j] -= second_law(f[k], m, dy[k], dr[k]) - k += 1 - return particles - - -def second_law(f, m, d1, d2): - """Newton's second law of motion to get the acceleration of the particle - in a given dimension. - Parameters - ---------- - f: float - The force on the pair of particles. - m: float - Mass of the particle. - d1: float - Distance between the particles in a single dimension. - d2: float - Distance between the particles across all dimensions. - Returns - ------- - float: - Acceleration of the particle in a given dimension. - """ - return (f * d1 / d2) / m - - -def compute_energy(particles, box_length, cut_off, constants, forcefield): - r"""Calculates the total energy of the simulation. - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - box_length: float - Length of a single dimension of the simulation square, in Angstrom. - cut_off: float - The distance greater than which the energies between particles is - taken as zero. - constants: float, array_like (optional) - The constants associated with the particular forcefield used, e.g. for - the function forcefields.lennard_jones, theses are [A, B] - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - Returns - ------- - util.particle_dt, array_like - Information about particles, with updated accelerations and forces. - float, array_like - Current distances between pairs of particles in the simulation. - float, array_like - Current energies between pairs of particles in the simulation. - """ - pairs = int((particles['xacceleration'].size - 1) * - particles['xacceleration'].size / 2) - distances = np.zeros(pairs) - energies = np.zeros(pairs) - distances, dx, dy = heavy.dist(particles['xposition'], - particles['yposition'], box_length) - energies = forcefield(distances, constants, force=False) - energies[np.where(distances > cut_off)] = 0. - return distances, energies - - -def calculate_pressure(particles, box_length, temperature, - cut_off, constants, forcefield): - r"""Calculates the instantaneous pressure of the simulation cell, found - with the following relationship: - .. math:: - p = \langle \rho k_b T \rangle + \bigg\langle \frac{1}{3V}\sum_{i} - \sum_{j cut_off)] = 0. - pres = np.sum(forces * distances) - boltzmann_constant = 1.3806e-23 # joules / kelvin - pres = 1. / (2 * box_length * box_length) * pres + ( - particles['xposition'].size / (box_length * box_length) * - boltzmann_constant * temperature) - return pres - - -def heat_bath(particles, temperature_sample, bath_temp): - r"""Rescales the velocities of the particles in the system to control the - temperature of the simulation. Thereby allowing for an NVT ensemble. The - velocities are rescaled according the following relationship, - .. math:: - v_{\text{new}} = v_{\text{old}} \times - \sqrt{\frac{T_{\text{desired}}}{\bar{T}}} - Parameters - ---------- - particles: util.particle_dt, array_like - Information about the particles. - temperature_sample: float, array_like - The temperature at each timestep in the simulation. - bath_temp: float - The desired temperature of the simulation. - Returns - ------- - util.particle_dt, array_like - Information about the particles with new, rescaled velocities. - """ - average_temp = np.average(temperature_sample) - particles['xvelocity'] = particles['xvelocity'] * np.sqrt(bath_temp / - average_temp) - particles['yvelocity'] = particles['yvelocity'] * np.sqrt(bath_temp / - average_temp) - return particles - - -def dist(xposition, yposition, box_length): - """Returns the distance array for the set of particles. - Parameters - ---------- - xpos: float, array_like (N) - Array of length N, where N is the number of particles, providing the - x-dimension positions of the particles. - ypos: float, array_like (N) - Array of length N, where N is the number of particles, providing the - y-dimension positions of the particles. - box_length: float - The box length of the simulation cell. - Returns - ------- - drr float, array_like ((N - 1) * N / 2)) - The pairs of distances between the particles. - dxr float, array_like ((N - 1) * N / 2)) - The pairs of distances between the particles, in only the x-dimension. - dyr float, array_like ((N - 1) * N / 2)) - The pairs of distances between the particles, in only the y-dimension. - """ - drr = np.zeros(int((xposition.size - 1) * xposition.size / 2)) - dxr = np.zeros(int((xposition.size - 1) * xposition.size / 2)) - dyr = np.zeros(int((xposition.size - 1) * xposition.size / 2)) - k = 0 - for i in range(0, xposition.size - 1): - for j in range(i+1, xposition.size): - dx = xposition[i] - xposition[j] - dy = yposition[i] - yposition[j] - dx = pbc_correction(dx, box_length) - dy = pbc_correction(dy, box_length) - dr = separation(dx, dy) - drr[k] = dr - dxr[k] = dx - dyr[k] = dy - k += 1 - return drr, dxr, dyr - - -def pbc_correction(position, cell): - """Correct for the periodic boundary condition. - Parameters - ---------- - position: float - Particle position. - cell: float - Cell vector. - Returns - ------- - float: - Corrected particle position.""" - if np.abs(position) > 0.5 * cell: - position *= 1 - cell / np.abs(position) - return position diff --git a/build/lib.linux-x86_64-3.6/pylj/sample.py b/build/lib.linux-x86_64-3.6/pylj/sample.py deleted file mode 100644 index 7361052..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/sample.py +++ /dev/null @@ -1,661 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt - - -class Scattering(object): # pragma: no cover - """The Scattering class will plot the particle positions, radial - distribution function, mean squared deviation and scattering profile (as a - fft of the rdf). This sampling class is ideal for observing the phase - transitions between solid, liquid, gas. - - Parameters - ---------- - system: System - The whole system information. - """ - def __init__(self, system): - fig, ax = environment(4) - self.average_rdf = [] - self.r = [] - self.average_diff = [] - self.q = [] - self.initial_pos = [system.particles['xposition'], - system.particles['yposition']] - - setup_cellview(ax[0, 0], system) - setup_rdfview(ax[0, 1], system) - setup_diffview(ax[1, 1]) - setup_msdview(ax[1, 0]) - - plt.tight_layout() - self.ax = ax - self.fig = fig - - def update(self, system): - """This updates the visualisation environment. Often this can be slower - than the cythonised force calculation so used is wisely. - - Parameters - ---------- - system: System - The whole system information. - """ - update_cellview(self.ax[0, 0], system) - update_rdfview(self.ax[0, 1], system, self.average_rdf, self.r) - update_diffview(self.ax[1, 1], system, self.average_diff, self.q) - update_msdview(self.ax[1, 0], system) - self.fig.canvas.draw() - - def average(self): - gr = np.average(self.average_rdf, axis=0) - x = np.average(self.r, axis=0) - line = self.ax[0, 1].lines[0] - line.set_xdata(x) - line.set_ydata(gr) - self.ax[0, 1].set_ylim([0, np.amax(gr) + np.amax(gr) * 0.05]) - - iq = np.average(self.average_diff, axis=0) - x = np.average(self.q, axis=0) - line = self.ax[1, 1].lines[0] - line.set_ydata(iq) - line.set_xdata(x) - self.ax[1, 1].set_ylim([0, np.amax(iq) + np.amax(iq) * 0.05]) - self.ax[1, 1].set_xlim([np.amin(x), np.amax(x)]) - self.fig.canvas.draw() - - -class Phase(object): # pragma: no cover - """The Phase class will plot the particle positions, radial - distribution function, mean squared deviation and total energy of the - simulation. This sampling class is ideal for observing the phase - transitions between solid, liquid, gas. - - Parameters - ---------- - system: System - The whole system information. - """ - def __init__(self, system): - fig, ax = environment(4) - self.average_rdf = [] - self.r = [] - self.average_diff = [] - self.q = [] - self.initial_pos = [system.particles['xposition'], - system.particles['yposition']] - - setup_cellview(ax[0, 0], system) - setup_rdfview(ax[1, 1], system) - setup_energyview(ax[0, 1]) - setup_msdview(ax[1, 0]) - - plt.tight_layout() - self.ax = ax - self.fig = fig - - def update(self, system): - """This updates the visualisation environment. Often this can be slower - than the cythonised force calculation so used is wisely. - - Parameters - ---------- - system: System - The whole system information. - """ - update_cellview(self.ax[0, 0], system) - update_rdfview(self.ax[1, 1], system, self.average_rdf, self.r) - update_energyview(self.ax[0, 1], system) - update_msdview(self.ax[1, 0], system) - self.fig.canvas.draw() - - def average(self): - gr = np.average(self.average_rdf, axis=0) - x = np.average(self.r, axis=0) - line = self.ax[1, 1].lines[0] - line.set_xdata(x) - line.set_ydata(gr) - self.ax[1, 1].set_ylim([0, np.amax(gr) + 0.01 * np.max(gr)]) - self.fig.canvas.draw() - - -class Interactions(object): # pragma: no cover - """The Interactions class will plot the particle positions, total force, - simulation pressure and temperature. This class is perfect for showing the - interactions between the particles and therefore the behaviour of ideal - gases and deviation when the conditions of an ideal gas are not met. - - Parameters - ---------- - system: System - The whole system information. - """ - def __init__(self, system): - fig, ax = environment(4) - - setup_cellview(ax[0, 0], system) - setup_forceview(ax[1, 1]) - setup_pressureview(ax[1, 0]) - setup_tempview(ax[0, 1]) - - plt.tight_layout() - self.ax = ax - self.fig = fig - - def update(self, system): - """This updates the visualisation environment. Often this can be slower - than the cythonised force calculation so used is wisely. - - Parameters - ---------- - system: System - The whole system information. - """ - update_cellview(self.ax[0, 0], system) - update_forceview(self.ax[1, 1], system) - update_tempview(self.ax[0, 1], system) - update_pressureview(self.ax[1, 0], system) - - self.fig.canvas.draw() - - -class JustCell(object): # pragma: no cover - """The JustCell class will plot just the particles positions. This is a - simplistic sampling class for quick visualisation. - - Parameters - ---------- - system: System - The whole system information. - """ - def __init__(self, system): - fig, ax = environment(1) - - setup_cellview(ax, system) - - plt.tight_layout() - - self.ax = ax - self.fig = fig - - def update(self, system): - """This updates the visualisation environment. Often this can be slower - than the cythonised force calculation so use this wisely. - - Parameters - ---------- - system: System - The whole system information. - """ - update_cellview(self.ax, system) - - self.fig.canvas.draw() - - -class CellPlus(object): # pragma: no cover - """The CellPlus class will plot the particles positions in addition to one - user defined one-dimensional dataset. This is designed to allow user - interaction with the plotting data. - - Parameters - ---------- - system: System - The whole system information. - xlabel: string - The label for the x-axis of the custom plot. - ylabel: string - The label for the y-axis of the custom plot. - """ - def __init__(self, system, xlabel, ylabel): - fig, ax = environment(2) - - setup_cellview(ax[0], system) - ax[1].plot([0], color='#34a5daff') - ax[1].set_ylabel(ylabel, fontsize=16) - ax[1].set_xlabel(xlabel, fontsize=16) - - plt.tight_layout() - - self.ax = ax - self.fig = fig - - def update(self, system, xdata, ydata): - """This updates the visualisation environment. Often this can be slower - than the cythonised force calculation so use this wisely. - - Parameters - ---------- - system: System - The whole system information. - xdata: float, array-like - x-data that should be plotted in the custom plot. - ydata: float, array-like - y-data that should be plotted in the custom plot. - """ - update_cellview(self.ax[0], system) - line1 = self.ax[1].lines[0] - line1.set_xdata(xdata) - line1.set_ydata(ydata) - self.ax[1].set_ylim([np.amin(ydata), np.amax(ydata)]) - self.ax[1].set_xlim(np.amin(xdata), np.amax(xdata)) - self.fig.canvas.draw() - - -class Energy(object): # pragma: no cover - """The energy class will plot the particle positions and potential energy - of the system. - - Parameters - ---------- - system: System - The whole system information. - """ - def __init__(self, system): - fig, ax = environment(2) - - setup_cellview(ax[0], system) - setup_energyview(ax[1]) - - plt.tight_layout() - self.ax = ax - self.fig = fig - - def update(self, system): - """This updates the visualisation environment. Often this can be slower - than the cythonised force calculation so used is wisely. - - Parameters - ---------- - system: System - The whole system information. - """ - update_cellview(self.ax[0], system) - update_energyview(self.ax[1], system) - self.fig.canvas.draw() - - -class RDF(object): # pragma: no cover - """The RDF class will plot the particle positions and radial distribution - function. This sampling class is can be used to show the relative RDFs for - solid, liquid, gas. - - Parameters - ---------- - system: System - The whole system information. - """ - def __init__(self, system): - fig, ax = environment(2) - self.average_rdf = [] - self.r = [] - self.average_diff = [] - self.q = [] - self.initial_pos = [system.particles['xposition'], - system.particles['yposition']] - - setup_cellview(ax[0], system) - setup_rdfview(ax[1], system) - - plt.tight_layout() - self.ax = ax - self.fig = fig - - def update(self, system): - """This updates the visualisation environment. Often this can be - slower than the cythonised force calculation so used is wisely. - - Parameters - ---------- - system: System - The whole system information. - """ - update_cellview(self.ax[0], system) - update_rdfview(self.ax[1], system, self.average_rdf, self.r) - self.fig.canvas.draw() - - def average(self): - gr = np.average(self.average_rdf, axis=0) - x = np.average(self.r, axis=0) - line = self.ax[1].lines[0] - line.set_xdata(x) - line.set_ydata(gr) - self.ax[1].set_ylim([0, np.amax(gr) + np.amax(gr) * 0.05]) - self.fig.canvas.draw() - - -def environment(panes): # pragma: no cover - """The visualisation environment consists of a series of panes (1, 2, or 4 - are allowed). This function allows the number of panes in the - visualisation to be defined. - - Parameters - ---------- - panes: int - Number of visualisation panes. - - Returns - ------- - Matplotlib.figure.Figure object: - The relevant Matplotlib figure. - Axes object or array of axes objects: - The axes related to each of the panes. For panes=1 this is a single - object, for panes=2 it is a 1-D array and - for panes=4 it is a 2-D array. - """ - if panes == 1: - fig, ax = plt.subplots(figsize=(4, 4)) - elif panes == 2: - fig, ax = plt.subplots(1, 2, figsize=(8, 4)) - elif panes == 4: - fig, ax = plt.subplots(2, 2, figsize=(8, 8)) - else: - AttributeError('The only options for the number of panes are 1, 2, or ' - '4') - return fig, ax - - -def setup_cellview(ax, system): # pragma: no cover - """Builds the particle position visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - xpos = system.particles['xposition'] - ypos = system.particles['yposition'] - # These numbers are chosen to scale the size of the particles nicely to - # allow the particles to appear to interact appropriately - mk = (6.00555e-8 / (system.box_length - 2.2727e-10) - 1e-10) - ax.plot(xpos, ypos, 'o', markersize=mk, markeredgecolor='black', - color='#34a5daff') - ax.set_xlim([0, system.box_length]) - ax.set_ylim([0, system.box_length]) - ax.set_xticks([]) - ax.set_yticks([]) - - -def setup_forceview(ax): # pragma: no cover - """Builds the total force visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - """ - ax.plot([0], color='#34a5daff') - ax.set_ylabel('Force/N', fontsize=16) - ax.set_xlabel('Time/s', fontsize=16) - - -def setup_energyview(ax): # pragma: no cover - """Builds the total force visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - """ - ax.plot([0], color='#34a5daff') - ax.set_ylabel('Energy/J', fontsize=16) - ax.set_xlabel('Step', fontsize=16) - - -def setup_rdfview(ax, system): # pragma: no cover - """Builds the radial distribution function visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - ax.plot([0], color='#34a5daff') - ax.set_xlim([0, system.box_length / 2]) - ax.set_yticks([]) - ax.set_ylabel('RDF', fontsize=16) - ax.set_xlabel('r/m', fontsize=16) - - -def setup_diffview(ax): # pragma: no cover - """Builds the scattering profile visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - """ - ax.plot([0], color='#34a5daff') - ax.set_yticks([]) - ax.set_ylabel('I(q)', fontsize=16) - ax.set_xlabel('q/m$^{-1}$', fontsize=16) - - -def setup_pressureview(ax): # pragma: no cover - """Builds the simulation instantaneous pressure visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - """ - ax.plot([0], color='#34a5daff') - ax.set_ylabel(r'Pressure/$\times10^6$Pa m$^{-1}$', fontsize=16) - ax.set_xlabel('Time/s', fontsize=16) - - -def setup_tempview(ax): # pragma: no cover - """Builds the simulation instantaneous temperature visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - """ - ax.plot([0], color='#34a5daff') - ax.set_ylabel('Temperature/K', fontsize=16) - ax.set_xlabel('Time/s', fontsize=16) - - -def update_cellview(ax, system): # pragma: no cover - """Updates the particle positions visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - x3 = system.particles['xposition'] - y3 = system.particles['yposition'] - line = ax.lines[0] - line.set_ydata(y3) - line.set_xdata(x3) - - -def update_rdfview(ax, system, average_rdf, r): # pragma: no cover - """Updates the radial distribution function visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - average_rdf: array_like - The radial distribution functions g(r) for each timestep, to later be - averaged. - r: array_like - The radial distribution functions r for each timestep, to later be - averaged. - """ - hist, bin_edges = np.histogram( - system.distances, - bins=np.linspace(0, system.box_length / 2 + 0.5e-10, 100)) - gr = hist / (system.number_of_particles * (system.number_of_particles / - system.box_length ** 2) * - np.pi * (bin_edges[:-1] + 0.5e-10 / 2.) * 0.5) - average_rdf.append(gr) - x = bin_edges[:-1] + 0.5e-10 / 2 - r.append(x) - - line = ax.lines[0] - line.set_xdata(x) - line.set_ydata(gr) - ax.set_ylim([0, np.amax(gr) + np.amax(gr) * 0.01]) - - -def update_diffview(ax, system, average_diff, q): # pragma: no cover - """Updates the scattering profile visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - average_diff: array_like - The scattering profile's i(q) for each timestep, to later be averaged. - q: array_like - The scattering profile's q for each timestep, to later be averaged. - """ - # the range of q is chosen to give a representive range for the - # interactions minimum is the reciprocal of the box length and the maximum - # is the reciprocal of the van der Waals diameter of the argon atom - qw = np.linspace(2 * np.pi / system.box_length, 10e10, 1000)[20:] - i = np.zeros_like(qw) - for j in range(0, len(qw)): - i[j] = np.sum(3.644 * (np.sin(qw[j] * system.distances)) / ( - qw[j] * system.distances)) - if i[j] < 0: - i[j] = 0 - x2 = qw - y2 = i - average_diff.append(y2) - q.append(x2) - line1 = ax.lines[0] - line1.set_xdata(x2) - line1.set_ydata(y2) - ax.set_ylim([0, np.amax(y2) + np.amax(y2) * 0.05]) - ax.set_xlim(np.amin(x2), np.amax(x2)) - - -def update_forceview(ax, system): # pragma: no cover - """Updates the total force visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - line = ax.lines[0] - line.set_ydata(system.force_sample) - line.set_xdata(np.arange(0, system.step) * system.timestep_length) - ax.set_xlim(0, system.step * system.timestep_length) - ax.set_ylim(np.amin(system.force_sample)-np.amax(system.force_sample) * - 0.05, - np.amax(system.force_sample)+np.amax(system.force_sample) * - 0.05) - - -def update_energyview(ax, system): # pragma: no cover - """Updates the total force visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - line = ax.lines[0] - if system.force_sample != []: - y = system.energy_sample + 1.3806e-23 * system.temperature_sample - line.set_xdata(np.arange(0, system.step) * system.timestep_length) - ax.set_xlim(0, system.step * system.timestep_length) - ax.set_xlabel('Time/s', fontsize=16) - else: - y = system.energy_sample - line.set_xdata(np.arange(0, system.step+1)) - ax.set_xlim(0, system.step) - line.set_ydata(y) - ax.set_ylim(np.amin(y) - np.abs(np.amax(y)) * 0.05, np.amax( - y) + np.abs(np.amax(y)) * 0.05) - - -def update_tempview(ax, system): # pragma: no cover - """Updates the simulation instantaneous temperature visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - line = ax.lines[0] - line.set_ydata(system.temperature_sample) - line.set_xdata(np.arange(0, system.step) * system.timestep_length) - ax.set_xlim(0, system.step * system.timestep_length) - ax.set_ylim(np.amin(system.temperature_sample)-np.amax( - system.temperature_sample) * 0.05, - np.amax(system.temperature_sample)+np.amax( - system.temperature_sample) * 0.05) - - -def update_pressureview(ax, system): # pragma: no cover - """Updates the simulation instantaneous pressure visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - line = ax.lines[0] - # Scaling the pressure to give the numbers with a nice number of - # significant figures - data = system.pressure_sample * 1e6 - line.set_ydata(data) - line.set_xdata(np.arange(0, system.step) * system.timestep_length) - ax.set_xlim(0, system.step * system.timestep_length) - ax.set_ylim(np.amin(data) - np.amax(data) * 0.05, - np.amax(data) + np.amax(data) * 0.05) - - -def setup_msdview(ax): # pragma: no cover - """Builds the simulation mean squared deviation visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - """ - ax.plot([0], color='#34a5daff') - ax.set_ylabel('MSD/m$^2$', fontsize=16) - ax.set_xlabel('Time/s', fontsize=16) - - -def update_msdview(ax, system): # pragma: no cover - """Updates the simulation mean squared deviation visualisation pane. - - Parameters - ---------- - ax: Axes object - The axes position that the pane should be placed in. - system: System - The whole system information. - """ - line = ax.lines[0] - - line.set_ydata(system.msd_sample) - line.set_xdata(np.arange(0, system.step) * system.timestep_length) - ax.set_xlim(0, system.step * system.timestep_length) - ax.set_ylim(0, np.amax(system.msd_sample)+np.amax(system.msd_sample) * - 0.05) diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/__init__.py b/build/lib.linux-x86_64-3.6/pylj/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/test_comp.py b/build/lib.linux-x86_64-3.6/pylj/tests/test_comp.py deleted file mode 100644 index 99460dc..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/tests/test_comp.py +++ /dev/null @@ -1,15 +0,0 @@ -from numpy.testing import assert_almost_equal -from pylj import comp -import unittest -import numpy as np - - -class TestPairwise(unittest.TestCase): - def test_dist(self): - xpos = np.array([0, 1]) - ypos = np.array([0, 1]) - box_length = 5. - dr, dx, dy = comp.dist(xpos, ypos, box_length) - assert_almost_equal(dr, [np.sqrt(2)]) - assert_almost_equal(dx, [-1]) - assert_almost_equal(dy, [-1]) diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/test_forcefields.py b/build/lib.linux-x86_64-3.6/pylj/tests/test_forcefields.py deleted file mode 100644 index f101fd5..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/tests/test_forcefields.py +++ /dev/null @@ -1,21 +0,0 @@ -from numpy.testing import assert_almost_equal -from pylj import forcefields -import unittest - - -class TestForcefields(unittest.TestCase): - def test_lennard_jones_energy(self): - a = forcefields.lennard_jones(2., [1., 1.]) - assert_almost_equal(a, -0.015380859) - - def test_lennard_jones_force(self): - a = forcefields.lennard_jones(2., [1., 1.], force=True) - assert_almost_equal(a, -0.045410156) - - def test_buckingham_energy(self): - a = forcefields.buckingham(2., [1., 1., 1.]) - assert_almost_equal(a, 0.1197103832) - - def test_buckingham_force(self): - a = forcefields.buckingham(2., [1., 1., 1.], force=True) - assert_almost_equal(a, 0.08846028324) diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/test_mc.py b/build/lib.linux-x86_64-3.6/pylj/tests/test_mc.py deleted file mode 100644 index 879127c..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/tests/test_mc.py +++ /dev/null @@ -1,63 +0,0 @@ -from numpy.testing import assert_almost_equal, assert_equal -from pylj import mc -import unittest - - -class TestMc(unittest.TestCase): - def test_initialise_square(self): - a = mc.initialise(2, 300, 8, 'square') - assert_equal(a.number_of_particles, 2) - assert_almost_equal(a.box_length, 8e-10) - assert_almost_equal(a.init_temp, 300) - assert_almost_equal(a.particles['xposition']*1e10, [2, 2]) - assert_almost_equal(a.particles['yposition']*1e10, [2, 6]) - - def test_initialize_square(self): - a = mc.initialize(2, 300, 8, 'square') - assert_equal(a.number_of_particles, 2) - assert_almost_equal(a.box_length, 8e-10) - assert_almost_equal(a.init_temp, 300) - assert_almost_equal(a.particles['xposition']*1e10, [2, 2]) - assert_almost_equal(a.particles['yposition']*1e10, [2, 6]) - - def test_sample(self): - a = mc.initialise(2, 300, 8, 'square') - a = mc.sample(300, a) - assert_almost_equal(a.energy_sample, [300]) - - def test_select_random_particle(self): - a = mc.initialise(2, 300, 8, 'square') - b, c = mc.select_random_particle(a.particles) - self.assertTrue(0 <= b < 2) - self.assertTrue(0 <= c[0] <= 8e-10) - self.assertTrue(0 <= c[1] <= 8e-10) - - def test_get_new_particle(self): - a = mc.initialise(2, 300, 8, 'square') - b, c = mc.select_random_particle(a.particles) - d = mc.get_new_particle(a.particles, b, a.box_length) - self.assertTrue(0 <= d['xposition'][b] <= 8e-10) - self.assertTrue(0 <= d['yposition'][b] <= 8e-10) - - def test_accept(self): - a = mc.accept(300) - assert_almost_equal(a, 300) - - def test_reject(self): - a = mc.initialise(2, 300, 8, 'square') - b = [1e-10, 1e-10] - c = mc.reject(b, a.particles, 1) - assert_almost_equal(c['xposition'][1]*1e10, 1) - assert_almost_equal(c['yposition'][1]*1e10, 1) - - def test_metropolis_energy_reduce(self): - a = mc.metropolis(300, 100, 1) - self.assertTrue(a) - - def test_metropolis_energy_increase_accept(self): - a = mc.metropolis(300, 100e-20, 101e-20, n=0.01) - self.assertTrue(a) - - def test_metropolis_energy_increase_reject(self): - a = mc.metropolis(300, 100e-20, 101e-20, n=0.1) - self.assertFalse(a) diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/test_md.py b/build/lib.linux-x86_64-3.6/pylj/tests/test_md.py deleted file mode 100644 index caa5670..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/tests/test_md.py +++ /dev/null @@ -1,83 +0,0 @@ -from numpy.testing import assert_almost_equal, assert_equal -from pylj import md -import unittest - - -class TestMd(unittest.TestCase): - def test_initialise_square(self): - a = md.initialise(2, 300, 8, 'square') - assert_equal(a.number_of_particles, 2) - assert_almost_equal(a.box_length, 8e-10) - assert_almost_equal(a.init_temp, 300) - assert_almost_equal(a.particles['xposition']*1e10, [2, 2]) - assert_almost_equal(a.particles['yposition']*1e10, [2, 6]) - - def test_velocity_verlet(self): - a = md.initialise(2, 300, 8, 'square') - a.particles, a.distances, a.forces, a.energies = md.velocity_verlet( - a.particles, 1, a.box_length, a.cut_off, a.constants, a. - forcefield, a.mass) - assert_almost_equal(a.particles['xprevious_position']*1e10, [2, 2]) - assert_almost_equal(a.particles['yprevious_position']*1e10, [2, 6]) - - def test_update_positions(self): - a = md.initialise(2, 300, 8, 'square') - a.particles['xvelocity'] = 1e4 - a.particles['yvelocity'] = 1e4 - a.particles['xacceleration'] = 1e4 - a.particles['yacceleration'] = 1e4 - b, c = md.update_positions([a.particles['xposition'], - a.particles['yposition']], - [a.particles['xprevious_position'], - a.particles['yprevious_position']], - [a.particles['xvelocity'], - a.particles['yvelocity']], - [a.particles['xacceleration'], - a.particles['yacceleration']], - a.timestep_length, a.box_length) - assert_almost_equal(b[0][0]*1e10, 3) - assert_almost_equal(b[1][0]*1e10, 3) - assert_almost_equal(b[0][1]*1e10, 3) - assert_almost_equal(b[1][1]*1e10, 7) - - def test_update_velocities(self): - a = md.initialise(2, 300, 8, 'square') - a.particles['xvelocity'] = 1e-10 - a.particles['yvelocity'] = 1e-10 - a.particles['xacceleration'] = 1e4 - a.particles['yacceleration'] = 1e4 - xacceleration_new = 2e4 - yacceleration_new = 2e4 - b = md.update_velocities([a.particles['xvelocity'], - a.particles['yvelocity']], - [xacceleration_new, yacceleration_new], - [a.particles['xacceleration'], - a.particles['yacceleration']], - a.timestep_length) - assert_almost_equal(b[0][0]*1e10, 2.5) - assert_almost_equal(b[1][0]*1e10, 2.5) - assert_almost_equal(b[0][1]*1e10, 2.5) - assert_almost_equal(b[1][1]*1e10, 2.5) - - def test_calculate_temperature(self): - a = md.initialise(1, 300, 8, 'square') - a.particles['xvelocity'] = [1e-10] - a.particles['yvelocity'] = [1e-10] - a.particles['xacceleration'] = [1e4] - a.particles['yacceleration'] = [1e4] - b = md.calculate_temperature(a.particles, mass=39.948) - assert_almost_equal(b * 1e23, 4.8048103702737945) - - def test_calculate_msd(self): - a = md.initialise(2, 300, 8, 'square') - a.particles['xposition'] = [3e-10, 3e-10] - a.particles['yposition'] = [3e-10, 7e-10] - b = md.calculate_msd(a.particles, a.initial_particles, a.box_length) - assert_almost_equal(b, 2e-20) - - def test_calculate_msd_large(self): - a = md.initialise(2, 300, 8, 'square') - a.particles['xposition'] = [7e-10, 3e-10] - a.particles['yposition'] = [7e-10, 7e-10] - b = md.calculate_msd(a.particles, a.initial_particles, a.box_length) - assert_almost_equal(b, 10e-20) diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/test_pairwise.py b/build/lib.linux-x86_64-3.6/pylj/tests/test_pairwise.py deleted file mode 100644 index 45d274b..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/tests/test_pairwise.py +++ /dev/null @@ -1,70 +0,0 @@ -from numpy.testing import assert_almost_equal -from pylj import pairwise, util -from pylj import forcefields as ff -import unittest -import numpy as np - - -class TestPairwise(unittest.TestCase): - - def test_update_accelerations(self): - part_dt = util.particle_dt() - particles = np.zeros(2, dtype=part_dt) - ones = np.array([1]) - dist = np.array([np.sqrt(2)]) - particles = pairwise.update_accelerations(particles, ones, 1, ones, - ones, dist) - assert_almost_equal(particles['xacceleration'][0], 0.707106781) - assert_almost_equal(particles['yacceleration'][0], 0.707106781) - assert_almost_equal(particles['xacceleration'][1], -0.707106781) - assert_almost_equal(particles['yacceleration'][1], -0.707106781) - - def test_second_law(self): - a = pairwise.second_law(1, 1, 1, np.sqrt(2)) - assert_almost_equal(a, 0.707106781) - - def test_separation(self): - a = pairwise.separation(1, 1) - assert_almost_equal(a, np.sqrt(2)) - - def test_compute_forces(self): - part_dt = util.particle_dt() - particles = np.zeros(2, dtype=part_dt) - particles['xposition'][0] = 1e-10 - particles['xposition'][1] = 5e-10 - particles, distances, forces, energies = pairwise.compute_force( - particles, 30, 15, constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones, mass=39.948) - assert_almost_equal(distances, [4e-10]) - assert_almost_equal(energies, [-1.4515047e-21]) - assert_almost_equal(forces, [-9.5864009e-12]) - assert_almost_equal(particles['yacceleration'], [0, 0]) - assert_almost_equal(particles['xacceleration'][0]/1e14, 1.4451452) - assert_almost_equal(particles['xacceleration'][1]/1e14, -1.4451452) - - def test_compute_energy(self): - part_dt = util.particle_dt() - particles = np.zeros(2, dtype=part_dt) - particles['xposition'][0] = 1e-10 - particles['xposition'][1] = 5e-10 - d, e = pairwise.compute_energy(particles, 30, 15, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - assert_almost_equal(d, [4e-10]) - assert_almost_equal(e, [-1.4515047e-21]) - - def test_calculate_pressure(self): - part_dt = util.particle_dt() - particles = np.zeros(2, dtype=part_dt) - particles['xposition'][0] = 1e-10 - particles['xposition'][1] = 5e-10 - p = pairwise.calculate_pressure(particles, 30, 300, 15, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - assert_almost_equal(p*1e24, 7.07368869) - - def test_pbc_correction(self): - a = pairwise.pbc_correction(1, 10) - assert_almost_equal(a, 1) - b = pairwise.pbc_correction(11, 10) - assert_almost_equal(b, 1) diff --git a/build/lib.linux-x86_64-3.6/pylj/tests/test_util.py b/build/lib.linux-x86_64-3.6/pylj/tests/test_util.py deleted file mode 100644 index afbafb9..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/tests/test_util.py +++ /dev/null @@ -1,67 +0,0 @@ -from numpy.testing import assert_almost_equal, assert_equal -from pylj import util -from pylj import forcefields as ff -import unittest - - -class TestUtil(unittest.TestCase): - def test_system_square(self): - a = util.System(2, 300, 8, mass=39.948, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - assert_equal(a.number_of_particles, 2) - assert_equal(a.init_temp, 300) - assert_almost_equal(a.box_length * 1e10, 8) - assert_almost_equal(a.timestep_length, 1e-14) - assert_almost_equal(a.particles['xposition'] * 1e10, [2, 2]) - assert_almost_equal(a.particles['yposition'] * 1e10, [2, 6]) - assert_almost_equal(a.initial_particles['xposition'] * 1e10, [2, 2]) - assert_almost_equal(a.initial_particles['yposition'] * 1e10, [2, 6]) - assert_almost_equal(a.cut_off * 1e10, 4.0) - assert_equal(a.distances.size, 1) - assert_equal(a.forces.size, 1) - assert_equal(a.energies.size, 1) - - def test_system_random(self): - a = util.System(2, 300, 8, init_conf='random', mass=39.948, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - assert_equal(a.number_of_particles, 2) - assert_equal(a.init_temp, 300) - assert_almost_equal(a.box_length * 1e10, 8) - assert_almost_equal(a.timestep_length, 1e-14) - self.assertTrue(0 <= a.particles['xposition'][0] * 1e10 <= 8) - self.assertTrue(0 <= a.particles['yposition'][0] * 1e10 <= 8) - self.assertTrue(0 <= a.particles['xposition'][1] * 1e10 <= 8) - self.assertTrue(0 <= a.particles['yposition'][1] * 1e10 <= 8) - assert_almost_equal(a.cut_off * 1e10, 4.0) - assert_equal(a.distances.size, 1) - assert_equal(a.forces.size, 1) - assert_equal(a.energies.size, 1) - - def test_system_too_big(self): - with self.assertRaises(AttributeError) as context: - util.System(2, 300, 1000, mass=39.948, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - self.assertTrue('With a box length of 1000 the particles are probably ' - 'too small to be seen in the viewer. Try something ' - '(much) less than 600.' in str(context.exception)) - - def test_system_too_small(self): - with self.assertRaises(AttributeError) as context: - util.System(2, 300, 2, mass=39.948, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - self.assertTrue('With a box length of 2 the cell is too small to ' - 'really hold more than one particle.' in str( - context.exception)) - - def test_system_init_conf(self): - with self.assertRaises(NotImplementedError) as context: - util.System(2, 300, 100, init_conf='horseradish', mass=39.948, - constants=[1.363e-134, 9.273e-78], - forcefield=ff.lennard_jones) - self.assertTrue('The initial configuration type horseradish is not ' - 'recognised. Available options are: square or ' - 'random' in str(context.exception)) diff --git a/build/lib.linux-x86_64-3.6/pylj/util.py b/build/lib.linux-x86_64-3.6/pylj/util.py deleted file mode 100644 index 1f0fec8..0000000 --- a/build/lib.linux-x86_64-3.6/pylj/util.py +++ /dev/null @@ -1,244 +0,0 @@ -from __future__ import division -import numpy as np -import webbrowser -from pylj import md, mc - - -class System: - """Simulation system. - This class is designed to store all of the information about the job that - is being run. This includes the particles - object, as will as sampling objects such as the temperature, pressure, etc. - arrays. - 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. - cut_off: float (optional) - The distance apart that the particles must be to consider there - interaction to be negliable. - constants: float, array_like (optional) - The values of the constants for the forcefield used. - mass: float (optional) - The mass of the particles being simulated. - forcefield: function (optional) - The particular forcefield to be used to find the energy and forces. - """ - def __init__(self, number_of_particles, temperature, box_length, - constants, forcefield, mass, init_conf='square', - timestep_length=1e-14, cut_off=15): - self.number_of_particles = number_of_particles - self.init_temp = temperature - self.constants = constants - self.forcefield = forcefield - self.mass = mass - if box_length <= 600: - self.box_length = box_length * 1e-10 - else: - raise AttributeError('With a box length of {} the particles are ' - 'probably too small to be seen in the ' - 'viewer. Try something (much) less than ' - '600.'.format(box_length)) - if box_length >= 4: - self.box_length = box_length * 1e-10 - else: - raise AttributeError('With a box length of {} the cell is too ' - 'small to really hold more than one ' - 'particle.'.format(box_length)) - self.timestep_length = timestep_length - self.particles = None - if init_conf == 'square': - self.square() - elif init_conf == 'random': - self.random() - else: - raise NotImplementedError('The initial configuration type {} is ' - 'not recognised. Available options are: ' - 'square or random'.format(init_conf)) - if box_length > 30: - self.cut_off = cut_off * 1e-10 - else: - self.cut_off = box_length / 2 * 1e-10 - self.step = 0 - self.time = 0. - self.distances = np.zeros(self.number_of_pairs()) - self.forces = np.zeros(self.number_of_pairs()) - self.energies = np.zeros(self.number_of_pairs()) - self.temperature_sample = np.array([]) - self.pressure_sample = np.array([]) - self.force_sample = np.array([]) - self.msd_sample = np.array([]) - self.energy_sample = np.array([]) - self.initial_particles = np.array(self.particles) - self.position_store = [0, 0] - self.old_energy = 0 - self.new_energy = 0 - self.random_particle = 0 - - def number_of_pairs(self): - """Calculates the number of pairwise interactions in the simulation. - Returns - ------- - int: - Number of pairwise interactions in the system. - """ - return int((self.number_of_particles - 1) * - self.number_of_particles / 2) - - def square(self): - """Sets the initial positions of the particles on a square lattice. - """ - part_dt = particle_dt() - self.particles = np.zeros(self.number_of_particles, dtype=part_dt) - m = int(np.ceil(np.sqrt(self.number_of_particles))) - d = self.box_length / m - n = 0 - for i in range(0, m): - for j in range(0, m): - if n < self.number_of_particles: - self.particles[n]['xposition'] = (i + 0.5) * d - self.particles[n]['yposition'] = (j + 0.5) * d - n += 1 - - def random(self): - """Sets the initial positions of the particles in a random arrangement. - """ - part_dt = particle_dt() - self.particles = np.zeros(self.number_of_particles, dtype=part_dt) - num_part = self.number_of_particles - self.particles['xposition'] = np.random.uniform(0, self.box_length, - num_part) - self.particles['yposition'] = np.random.uniform(0, self.box_length, - num_part) - - def compute_force(self): - """Maps to the compute_force function in either the comp (if Cython is - installed) or the pairwise module and allows for a cleaner interface. - """ - part, dist, forces, energies = md.compute_force(self.particles, - self.box_length, - self.cut_off, - self.constants, - self.forcefield, - self.mass - ) - self.particles = part - self.distances = dist - self.forces = forces - self.energies = energies - - def compute_energy(self): - """Maps to the compute_energy function in either the comp (if Cython - is installed) or the pairwise module and allows for a cleaner - interface. - """ - self.distances, self.energies = md.compute_energy(self.particles, - self.box_length, - self.cut_off, - self.constants, - self.forcefield) - - def integrate(self, method): - """Maps the chosen integration method. - Parameters - ---------- - method: method - The integration method to be used, e.g. md.velocity_verlet. - """ - self.particles, self.distances, self.forces, self.energies = method( - self.particles, self.timestep_length, self.box_length, - self.cut_off, self.constants, self.forcefield, self.mass) - - def md_sample(self): - """Maps to the md.sample function. - """ - self = md.sample(self.particles, self.box_length, - self.initial_particles, self) - - def heat_bath(self, bath_temperature): - """Maps to the heat_bath function in either the comp (if Cython is - installed) or the pairwise modules. - Parameters - ---------- - target_temperature: float - The target temperature for the simulation. - """ - self.particles = md.heat_bath(self.particles, self.temperature_sample, - bath_temperature) - - def mc_sample(self): - """Maps to the mc.sample function. - Parameters - ---------- - energy: float - Energy to add to the sample - """ - mc.sample(self.old_energy, self) - - def select_random_particle(self): - """Maps to the mc.select_random_particle function. - """ - self.random_particle, self.position_store = mc.select_random_particle( - self.particles) - - def new_random_position(self): - """Maps to the mc.get_new_particle function. - """ - self.particles = mc.get_new_particle(self.particles, - self.random_particle, - self.box_length) - - def accept(self): - """Maps to the mc.accept function. - """ - self.old_energy = mc.accept(self.new_energy) - - def reject(self): - """Maps to the mc.reject function. - """ - self.particles = mc.reject(self.position_store, self.particles, - self.random_particle) - - -def __cite__(): # pragma: no cover - """This function will launch the website for the JOSE publication on - pylj.""" - webbrowser.open( - 'http://jose.theoj.org/papers/58daa1a1a564dc8e0f99ffcdae20eb1d') - - -def __version__(): # pragma: no cover - """This will print the number of the pylj version currently in use.""" - major = 1 - minor = 1 - micro = 16 - print('pylj-{:d}.{:d}.{:d}'.format(major, minor, micro)) - - -def particle_dt(): - """Builds the data type for the particles, this consists of: - - xposition and yposition - - xvelocity and yvelocity - - xacceleration and yacceleration - - xprevious_position and yprevious_position - - xforce and yforce - - energy - """ - return np.dtype([('xposition', np.float64), ('yposition', np.float64), - ('xvelocity', np.float64), ('yvelocity', np.float64), - ('xacceleration', np.float64), - ('yacceleration', np.float64), - ('xprevious_position', np.float64), - ('yprevious_position', np.float64), - ('energy', np.float64), ('xpbccount', int), - ('ypbccount', int)]) diff --git a/build/temp.linux-x86_64-3.6/src/_ccomp.o b/build/temp.linux-x86_64-3.6/src/_ccomp.o deleted file mode 100644 index 3e8d285..0000000 Binary files a/build/temp.linux-x86_64-3.6/src/_ccomp.o and /dev/null differ diff --git a/build/temp.linux-x86_64-3.6/src/comp.o b/build/temp.linux-x86_64-3.6/src/comp.o deleted file mode 100644 index ba9f19e..0000000 Binary files a/build/temp.linux-x86_64-3.6/src/comp.o and /dev/null differ diff --git a/dist/pylj-1.1.16-py3.6-linux-x86_64.egg b/dist/pylj-1.1.16-py3.6-linux-x86_64.egg deleted file mode 100644 index 52e0ccb..0000000 Binary files a/dist/pylj-1.1.16-py3.6-linux-x86_64.egg and /dev/null differ diff --git a/examples/ideal_gas_law/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/examples/ideal_gas_law/.ipynb_checkpoints/Untitled-checkpoint.ipynb deleted file mode 100644 index 342215a..0000000 --- a/examples/ideal_gas_law/.ipynb_checkpoints/Untitled-checkpoint.ipynb +++ /dev/null @@ -1,904 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "import warnings\n", - "from pylj import md, sample\n", - "from pylj import forcefields as ff\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "\n", - "warnings.filterwarnings('ignore')\n", - "def md_simulation(number_of_particles, temperature, box_length, number_of_steps, sample_frequency):\n", - " # Creates the visualisation environment\n", - " %matplotlib notebook\n", - " # Initialise the system\n", - " system = md.initialise(number_of_particles, temperature, box_length, 'square', \n", - " constants=[1.69e-15, 3.66e10, 1.02e-77], forcefield=ff.buckingham)\n", - " # This sets the sampling class\n", - " sample_system = sample.Energy(system)\n", - " # Start at time 0\n", - " system.time = 0\n", - " # Begin the molecular dynamics loop\n", - " for i in range(0, number_of_steps):\n", - " # Run the equations of motion integrator algorithm, this \n", - " # includes the force calculation\n", - " system.integrate(md.velocity_verlet)\n", - " # Sample the thermodynamic and structural parameters of the system\n", - " system.md_sample()\n", - " # Allow the system to interact with a heat bath\n", - " system.heat_bath(temperature)\n", - " # Iterate the time\n", - " system.time += system.timestep_length\n", - " system.step += 1\n", - " # At a given frequency sample the positions and plot the RDF\n", - " if system.step % sample_frequency == 0:\n", - " sample_system.update(system)\n", - " return system" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "MD 1 \n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "window.mpl = {};\n", - "\n", - "\n", - "mpl.get_websocket_type = function() {\n", - " if (typeof(WebSocket) !== 'undefined') {\n", - " return WebSocket;\n", - " } else if (typeof(MozWebSocket) !== 'undefined') {\n", - " return MozWebSocket;\n", - " } else {\n", - " alert('Your browser does not have WebSocket support.' +\n", - " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", - " 'Firefox 4 and 5 are also supported but you ' +\n", - " 'have to enable WebSockets in about:config.');\n", - " };\n", - "}\n", - "\n", - "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", - " this.id = figure_id;\n", - "\n", - " this.ws = websocket;\n", - "\n", - " this.supports_binary = (this.ws.binaryType != undefined);\n", - "\n", - " if (!this.supports_binary) {\n", - " var warnings = document.getElementById(\"mpl-warnings\");\n", - " if (warnings) {\n", - " warnings.style.display = 'block';\n", - " warnings.textContent = (\n", - " \"This browser does not support binary websocket messages. \" +\n", - " \"Performance may be slow.\");\n", - " }\n", - " }\n", - "\n", - " this.imageObj = new Image();\n", - "\n", - " this.context = undefined;\n", - " this.message = undefined;\n", - " this.canvas = undefined;\n", - " this.rubberband_canvas = undefined;\n", - " this.rubberband_context = undefined;\n", - " this.format_dropdown = undefined;\n", - "\n", - " this.image_mode = 'full';\n", - "\n", - " this.root = $('
');\n", - " this._root_extra_style(this.root)\n", - " this.root.attr('style', 'display: inline-block');\n", - "\n", - " $(parent_element).append(this.root);\n", - "\n", - " this._init_header(this);\n", - " this._init_canvas(this);\n", - " this._init_toolbar(this);\n", - "\n", - " var fig = this;\n", - "\n", - " this.waiting = false;\n", - "\n", - " this.ws.onopen = function () {\n", - " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", - " fig.send_message(\"send_image_mode\", {});\n", - " if (mpl.ratio != 1) {\n", - " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", - " }\n", - " fig.send_message(\"refresh\", {});\n", - " }\n", - "\n", - " this.imageObj.onload = function() {\n", - " if (fig.image_mode == 'full') {\n", - " // Full images could contain transparency (where diff images\n", - " // almost always do), so we need to clear the canvas so that\n", - " // there is no ghosting.\n", - " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", - " }\n", - " fig.context.drawImage(fig.imageObj, 0, 0);\n", - " };\n", - "\n", - " this.imageObj.onunload = function() {\n", - " fig.ws.close();\n", - " }\n", - "\n", - " this.ws.onmessage = this._make_on_message_function(this);\n", - "\n", - " this.ondownload = ondownload;\n", - "}\n", - "\n", - "mpl.figure.prototype._init_header = function() {\n", - " var titlebar = $(\n", - " '
');\n", - " var titletext = $(\n", - " '
');\n", - " titlebar.append(titletext)\n", - " this.root.append(titlebar);\n", - " this.header = titletext[0];\n", - "}\n", - "\n", - "\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "\n", - "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "mpl.figure.prototype._init_canvas = function() {\n", - " var fig = this;\n", - "\n", - " var canvas_div = $('
');\n", - "\n", - " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", - "\n", - " function canvas_keyboard_event(event) {\n", - " return fig.key_event(event, event['data']);\n", - " }\n", - "\n", - " canvas_div.keydown('key_press', canvas_keyboard_event);\n", - " canvas_div.keyup('key_release', canvas_keyboard_event);\n", - " this.canvas_div = canvas_div\n", - " this._canvas_extra_style(canvas_div)\n", - " this.root.append(canvas_div);\n", - "\n", - " var canvas = $('');\n", - " canvas.addClass('mpl-canvas');\n", - " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", - "\n", - " this.canvas = canvas[0];\n", - " this.context = canvas[0].getContext(\"2d\");\n", - "\n", - " var backingStore = this.context.backingStorePixelRatio ||\n", - "\tthis.context.webkitBackingStorePixelRatio ||\n", - "\tthis.context.mozBackingStorePixelRatio ||\n", - "\tthis.context.msBackingStorePixelRatio ||\n", - "\tthis.context.oBackingStorePixelRatio ||\n", - "\tthis.context.backingStorePixelRatio || 1;\n", - "\n", - " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband = $('');\n", - " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", - "\n", - " var pass_mouse_events = true;\n", - "\n", - " canvas_div.resizable({\n", - " start: function(event, ui) {\n", - " pass_mouse_events = false;\n", - " },\n", - " resize: function(event, ui) {\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " stop: function(event, ui) {\n", - " pass_mouse_events = true;\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " });\n", - "\n", - " function mouse_event_fn(event) {\n", - " if (pass_mouse_events)\n", - " return fig.mouse_event(event, event['data']);\n", - " }\n", - "\n", - " rubberband.mousedown('button_press', mouse_event_fn);\n", - " rubberband.mouseup('button_release', mouse_event_fn);\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " rubberband.mousemove('motion_notify', mouse_event_fn);\n", - "\n", - " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", - " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", - "\n", - " canvas_div.on(\"wheel\", function (event) {\n", - " event = event.originalEvent;\n", - " event['data'] = 'scroll'\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " mouse_event_fn(event);\n", - " });\n", - "\n", - " canvas_div.append(canvas);\n", - " canvas_div.append(rubberband);\n", - "\n", - " this.rubberband = rubberband;\n", - " this.rubberband_canvas = rubberband[0];\n", - " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", - " this.rubberband_context.strokeStyle = \"#000000\";\n", - "\n", - " this._resize_canvas = function(width, height) {\n", - " // Keep the size of the canvas, canvas container, and rubber band\n", - " // canvas in synch.\n", - " canvas_div.css('width', width)\n", - " canvas_div.css('height', height)\n", - "\n", - " canvas.attr('width', width * mpl.ratio);\n", - " canvas.attr('height', height * mpl.ratio);\n", - " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", - "\n", - " rubberband.attr('width', width);\n", - " rubberband.attr('height', height);\n", - " }\n", - "\n", - " // Set the figure to an initial 600x600px, this will subsequently be updated\n", - " // upon first draw.\n", - " this._resize_canvas(600, 600);\n", - "\n", - " // Disable right mouse context menu.\n", - " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", - " return false;\n", - " });\n", - "\n", - " function set_focus () {\n", - " canvas.focus();\n", - " canvas_div.focus();\n", - " }\n", - "\n", - " window.setTimeout(set_focus, 100);\n", - "}\n", - "\n", - "mpl.figure.prototype._init_toolbar = function() {\n", - " var fig = this;\n", - "\n", - " var nav_element = $('
')\n", - " nav_element.attr('style', 'width: 100%');\n", - " this.root.append(nav_element);\n", - "\n", - " // Define a callback function for later on.\n", - " function toolbar_event(event) {\n", - " return fig.toolbar_button_onclick(event['data']);\n", - " }\n", - " function toolbar_mouse_event(event) {\n", - " return fig.toolbar_button_onmouseover(event['data']);\n", - " }\n", - "\n", - " for(var toolbar_ind in mpl.toolbar_items) {\n", - " var name = mpl.toolbar_items[toolbar_ind][0];\n", - " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", - " var image = mpl.toolbar_items[toolbar_ind][2];\n", - " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", - "\n", - " if (!name) {\n", - " // put a spacer in here.\n", - " continue;\n", - " }\n", - " var button = $('