1 # -*- coding: iso-8859-1 -*-
4 from hoomd_script
import *
10 class angle_table_tests (unittest
.TestCase
):
13 # create a polymer system and add a angle to it
14 self
.polymer1
= dict(bond_len
=1.2, type=['A']*3, bond
="linear", count
=10);
15 self
.polymers
= [self
.polymer1
]
16 self
.box
= data
.boxdim(L
=35);
17 self
.separation
=dict(A
=0.35, B
=0.35)
18 self
.sys
= init
.create_random_polymers(box
=self
.box
, polymers
=self
.polymers
, separation
=self
.separation
);
20 for i
in range(len(self
.sys
.particles
)//3-1):
21 self
.sys
.angles
.add('angleA', 3*i
+0, 3*i
+1, 3*i
+2);
23 sorter
.set_params(grid
=8)
25 # test to see that se can create a angle.table
26 def test_create(self
):
27 angle
.table(width
=100);
29 # test setting the table
30 def test_set_coeff(self
):
31 def har(theta
, kappa
, theta_0
):
32 V
= 0.5 * kappa
* (theta
-theta_0
)**2;
33 T
= -kappa
*(theta
-theta_0
);
36 harmonic
= angle
.table(width
=1000)
37 harmonic
.angle_coeff
.set('angleA', func
=har
, coeff
=dict(kappa
=30,theta_0
=.1))
39 integrate
.mode_standard(dt
=0.005);
43 # test coefficient not set checking
44 def test_set_coeff_fail(self
):
45 harmonic
= angle
.table(width
=123)
47 integrate
.mode_standard(dt
=0.005);
49 self
.assertRaises(RuntimeError, run
, 100);
51 # compare against harmonic angle
52 def test_harmonic_compare(self
):
53 harmonic_1
= angle
.table(width
=1000)
54 harmonic_1
.angle_coeff
.set('angleA', func
=lambda theta
: (0.5*1*theta
*theta
, -theta
), coeff
=dict())
55 harmonic_2
= angle
.harmonic()
56 harmonic_2
.set_coeff('angleA', k
=1.0, t0
=0)
57 integrate
.mode_standard(dt
=0.005);
61 for i
in range(len(self
.sys
.particles
)):
62 f_1
= harmonic_1
.forces
[i
]
63 f_2
= harmonic_2
.forces
[i
]
64 # we have to have a very rough tolerance (~10%) because
65 # of 1) discretization of the potential and 2) different handling of precision issues in both potentials
66 self
.assertAlmostEqual(f_1
.energy
, f_2
.energy
,3)
67 self
.assertAlmostEqual(f_1
.force
[0], f_2
.force
[0],2)
68 self
.assertAlmostEqual(f_1
.force
[1], f_2
.force
[1],2)
69 self
.assertAlmostEqual(f_1
.force
[2], f_2
.force
[2],2)
75 if __name__
== '__main__':
76 unittest
.main(argv
= ['test.py', '-v'])