Skip to content

Commit

Permalink
Merge pull request #28 from arm61/2.0
Browse files Browse the repository at this point in the history
1.1
  • Loading branch information
Andrew McCluskey authored Aug 26, 2018
2 parents edb6550 + 78234a7 commit 1de9093
Show file tree
Hide file tree
Showing 16 changed files with 2,522 additions and 1,067 deletions.
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ test_script:
# to put the Python version you want to use on PATH.
- "python setup.py test"

after_test:
#after_test:
# This step builds your wheels.
# Again, you only need build.cmd if you're building C extensions for
# 64-bit Python 3.3/3.4. And you need to use %PYTHON% to get the correct
# interpreter
- "python setup.py bdist_wheel"
#- "python setup.py bdist_wheel"

artifacts:
#artifacts:
# bdist_wheel puts your built wheel in the dist directory
- path: dist\*
#- path: dist\*

#on_success:
# You can use this step to upload your artifacts to a public website.
Expand Down
Binary file added pylj/comp.cpython-36m-x86_64-linux-gnu.so
Binary file not shown.
27 changes: 27 additions & 0 deletions pylj/forcefields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np


def lennard_jones(dr, constants, force=False):
"""Calculate the energy of a pair of particles at a given distance.
Parameters
----------
dr: float, array_like
The distances between the all pairs of particles.
constants: float, array_like
An array of lenght 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))
42 changes: 33 additions & 9 deletions pylj/md.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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
from pylj import pairwise as heavy
from pylj import forcefields as ff


def initialise(number_of_particles, temperature, box_length, init_conf,
Expand Down Expand Up @@ -88,9 +85,9 @@ def velocity_verlet(particles, timestep_length, box_length, cut_off):
[particles['xprevious_position'], particles['yprevious_position']] = pos
xacceleration_store = list(particles['xacceleration'])
yacceleration_store = list(particles['yacceleration'])
particles, distances, forces, energies = heavy.compute_forces(particles,
box_length,
cut_off)
particles, distances, forces, energies = heavy.compute_force(particles,
box_length,
cut_off)
[particles['xvelocity'], particles['yvelocity']] = update_velocities(
[particles['xvelocity'], particles['yvelocity']],
[xacceleration_store, yacceleration_store],
Expand Down Expand Up @@ -126,7 +123,8 @@ def sample(particles, box_length, initial_particles, system):
system.temperature_sample = np.append(system.temperature_sample,
temperature_new)
pressure_new = heavy.calculate_pressure(particles, box_length,
temperature_new, system.cut_off)
temperature_new, system.cut_off,
system.constants)
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,
Expand Down Expand Up @@ -272,3 +270,29 @@ def calculate_temperature(particles):
k += mass_of_argon * v * v / (boltzmann_constant * 2 *
particles['xposition'].size)
return k


def compute_force(particles, box_length, cut_off,
constants=[1.363e-134, 9.273e-78], mass=39.948,
forcefield=ff.lennard_jones):
part, dist, forces, energies = heavy.compute_force(particles, box_length,
cut_off,
constants=constants,
mass=mass,
forcefield=forcefield)
return part, dist, forces, energies


def compute_energy(particles, box_length, cut_off,
constants=[1.363e-134, 9.273e-78],
forcefield=ff.lennard_jones):
dist, energies = heavy.compute_energy(particles, box_length, cut_off,
constants=constants,
forcefield=forcefield)
return dist, energies


def heat_bath(particles, temperature_sample, bath_temperature):
particles = heavy.heat_bath(particles, temperature_sample,
bath_temperature)
return particles
Loading

0 comments on commit 1de9093

Please sign in to comment.