Skip to content
Permalink
Browse files

More refactoring and typo fixing

  • Loading branch information...
jngrad committed Jun 7, 2019
1 parent 6e6899b commit 0da71aae42e2a237ee36cf38fdbf711a20fa1288
@@ -22,9 +22,7 @@
import unittest_decorators as utx
import numpy as np
import espressomd
import espressomd.electrostatics as el
import espressomd.electrostatic_extensions as el_ext
from espressomd import scafacos
from espressomd import electrostatics, electrostatic_extensions, scafacos
import tests_common


@@ -113,10 +111,10 @@ def test_zz_p3mElc(self):
self.S.periodicity = [1, 1, 1]
self.S.box_l = (10, 10, 10)

p3m = el.P3M(prefactor=1, accuracy=1e-6, mesh=(64, 64, 64))
p3m = electrostatics.P3M(prefactor=1, accuracy=1e-6, mesh=(64, 64, 64))

self.S.actors.add(p3m)
elc = el_ext.ELC(maxPWerror=1E-6, gap_size=1)
elc = electrostatic_extensions.ELC(maxPWerror=1E-6, gap_size=1)
self.S.actors.add(elc)
self.S.integrator.run(0)
self.compare("elc", energy=True)
@@ -126,7 +124,7 @@ def test_MMM2D(self):
self.S.box_l = (10, 10, 10)
self.S.cell_system.set_layered(n_layers=10, use_verlet_lists=False)
self.S.periodicity = [1, 1, 0]
mmm2d = (el.MMM2D(prefactor=1, maxPWerror=1E-7))
mmm2d = electrostatics.MMM2D(prefactor=1, maxPWerror=1E-7)

self.S.actors.add(mmm2d)
self.S.integrator.run(0)
@@ -149,7 +147,7 @@ def test_scafacos_p2nfft(self):
self.S.cell_system.set_domain_decomposition()
self.S.box_l = [10, 10, 10]

scafacos = el.Scafacos(
scafacos = electrostatics.Scafacos(
prefactor=1,
method_name="p2nfft",
method_params={
@@ -19,8 +19,7 @@
import unittest as ut
import unittest_decorators as utx
import numpy as np
from numpy import linalg as la
from numpy.random import random, seed
from numpy.random import random

import espressomd
import espressomd.magnetostatics
@@ -45,8 +44,8 @@ class BH_DDS_gpu_multCPU_test(ut.TestCase):

def vectorsTheSame(self, a, b):
tol = 5E-2
vec_len = la.norm(a - b)
rel = 2 * vec_len / (la.norm(a) + la.norm(b))
vec_len = np.linalg.norm(a - b)
rel = 2 * vec_len / (np.linalg.norm(a) + np.linalg.norm(b))
return rel <= tol

def test(self):
@@ -33,10 +33,10 @@

@utx.skipIfMissingFeatures(["DIPOLES", "FFTW"])
class Dipolar_p3m_mdlc_p2nfft(ut.TestCase):
"""Tests mdlc (2d) as well as dipolar p3m and dipolar p2nfft (3d) against stored data.
Validity of the stored data:
2d: as long as this test AND the scafacos_dipolar_1d_2d test passes, we are save.
3d: As long as the independently written p3m and p2nfft agree, we are save.
"""Tests mdlc (2d) as well as dipolar p3m and dipolar p2nfft (3d) against
stored data. Validity of the stored data:
2d: as long as this test AND the scafacos_dipolar_1d_2d test passes, we are safe.
3d: as long as the independently written p3m and p2nfft agree, we are safe.
"""
s = espressomd.System(box_l=[1.0, 1.0, 1.0])
s.seed = s.cell_system.get_state()['n_nodes'] * [1234]
@@ -57,7 +57,7 @@ def test_mdlc(self):
particle_radius = 0.5
box_l = pow(((4 * n_particle * np.pi) / (3 * rho)),
1.0 / 3.0) * particle_radius
s.box_l = box_l, box_l, box_l
s.box_l = 3 * [box_l]
f = open(abspath("data/mdlc_reference_data_energy.dat"))
ref_E = float(f.readline())
f.close()
@@ -59,11 +59,9 @@ class SwimmerTest(ut.TestCase):

def setUp(self):
S = self.S
boxl = 12
tstep = 0.01
S.box_l = [boxl, boxl, boxl]
S.box_l = 3 * [12]
S.cell_system.skin = 0.1
S.time_step = tstep
S.time_step = 0.01

S.part.add(id=0, pos=[6.0, 3.0, 2.0], quat=np.sqrt([.5, .5, 0, 0]),
swimming={"mode": "pusher", "v_swim": 0.10,
@@ -34,9 +34,7 @@ class ForceCap(ut.TestCase):
s.cell_system.skin = 0.0
s.seed = range(s.cell_system.get_state()["n_nodes"])

@classmethod
def setUpClass(cls):
np.random.seed(42)
np.random.seed(42)

def calc_f_max(self):
f = np.power(self.s.part[:].f, 2)
@@ -26,7 +26,7 @@ class GPUAvailability(ut.TestCase):
"""Tests consistency of GPU availability reporting."""

def test(self):
if "CUDA" in espressomd.features():
if espressomd.has_features("CUDA"):
system = espressomd.System(box_l=[1, 1, 1])
self.assertEqual(system.cuda_init_handle.device_list != {},
espressomd.gpu_available())
@@ -115,9 +115,8 @@ def dissipation_param_setup(self, n):
self.system.time_step = 0.007

# Space
box = 1.0
self.system.box_l = box, box, box
if espressomd.has_features(("PARTIAL_PERIODIC",)):
self.system.box_l = 3 * [1.0]
if espressomd.has_features("PARTIAL_PERIODIC"):
self.system.periodicity = [0, 0, 0]

# NVT thermostat
@@ -164,7 +163,7 @@ def dissipation_param_setup(self, n):
self.system.part.add(
rotation=(1, 1, 1), pos=(0.0, 0.0, 0.0), id=ind)
self.system.part[ind].v = [1.0, 1.0, 1.0]
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
self.system.part[ind].omega_body = [1.0, 1.0, 1.0]
self.system.part[ind].mass = self.mass
self.system.part[ind].rinertia = self.J
@@ -186,7 +185,7 @@ def fluctuation_dissipation_param_setup(self, n):
# Space
box = 10.0
self.system.box_l = 3 * [box]
if espressomd.has_features(("PARTIAL_PERIODIC",)):
if espressomd.has_features("PARTIAL_PERIODIC"):
self.system.periodicity = [0, 0, 0]

# NVT thermostat
@@ -231,7 +230,7 @@ def fluctuation_dissipation_param_setup(self, n):
rinertia=self.J,
pos=part_pos,
v=part_v)
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
self.system.part[ind].omega_body = part_omega_body

def check_dissipation(self, n):
@@ -258,7 +257,7 @@ def check_dissipation(self, n):
# tested here.
self.assertLess(abs(
self.system.part[ind].v[j] - math.exp(- self.gamma_tran_p_validate[k, j] * self.system.time / self.mass)), tol)
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
self.assertLess(abs(
self.system.part[ind].omega_body[j] - math.exp(- self.gamma_rot_p_validate[k, j] * self.system.time / self.J[j])), tol)

@@ -307,7 +306,7 @@ def check_fluctuation_dissipation(self, n):
for k in range(2):
ind = p + k * n
v = self.system.part[ind].v
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
o = self.system.part[ind].omega_body
o2[k,:] = o2[k,:] + np.power(o[:], 2)
pos = self.system.part[ind].pos
@@ -348,7 +347,7 @@ def check_fluctuation_dissipation(self, n):
self.assertLessEqual(
abs(dv[k]), tolerance, msg='Relative deviation in '
'translational energy too large: {0}'.format(dv[k]))
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
self.assertLessEqual(
abs(do[k]), tolerance, msg='Relative deviation in '
'rotational energy too large: {0}'.format(do[k]))
@@ -385,7 +384,7 @@ def set_particle_specific_gamma(self, n):
for i in range(n):
ind = i + k * n
self.system.part[ind].gamma = self.gamma_tran_p[k,:]
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
self.system.part[ind].gamma_rot = self.gamma_rot_p[k,:]

def set_particle_specific_temperature(self, n):
@@ -24,27 +24,25 @@

@utx.skipIfMissingFeatures("LENNARD_JONES")
class test_minimize_energy(ut.TestCase):

np.random.seed(42)
system = espressomd.System(box_l=[10.0, 10.0, 10.0])

test_rotation = espressomd.has_features(("ROTATION", "DIPOLES"))
if test_rotation:
from espressomd.constraints import HomogeneousMagneticField

@classmethod
def setUpClass(cls):
np.random.seed(42)

box_l = 10.0
density = 0.6
vol = box_l * box_l * box_l
vol = box_l**3
n_part = int(vol * density)

lj_eps = 1.0
lj_sig = 1.0
lj_cut = 1.12246

def setUp(self):
self.system.box_l = [self.box_l, self.box_l, self.box_l]
self.system.box_l = 3 * [self.box_l]
self.system.cell_system.skin = 0.4
self.system.time_step = 0.01
self.system.non_bonded_inter[0, 0].lennard_jones.set_params(
@@ -39,9 +39,7 @@ class RotDiffAniso(ut.TestCase):
# Particle properties
J = [0.0, 0.0, 0.0]

@classmethod
def setUpClass(cls):
np.random.seed(4)
np.random.seed(4)

def setUp(self):
self.system.time = 0.0
@@ -102,7 +100,7 @@ def rot_diffusion_param_setup(self, n):
part_pos = np.random.random(3) * box
self.system.part.add(rotation=(1, 1, 1), id=ind, rinertia=self.J,
pos=part_pos)
if "ROTATION" in espressomd.features():
if espressomd.has_features("ROTATION"):
self.system.part[ind].omega_body = [0.0, 0.0, 0.0]

def check_rot_diffusion(self, n):
@@ -29,7 +29,7 @@ class TestThole(ut.TestCase):

"""
This testcase takes a large box to minimize periodic effects and tests the
thole damping nonbonded interaction forces agains the analytical result
thole damping nonbonded interaction forces against the analytical result.
"""

box_l = 500.0
@@ -33,9 +33,7 @@ class VirtualSites(ut.TestCase):
system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system.seed = range(system.cell_system.get_state()["n_nodes"])

@classmethod
def setUpClass(cls):
np.random.seed(42)
np.random.seed(42)

def multiply_quaternions(self, a, b):
return np.array(

0 comments on commit 0da71aa

Please sign in to comment.
You can’t perform that action at this time.