-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_barostat.py
52 lines (46 loc) · 1.93 KB
/
test_barostat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import somd
import numpy as _np
import harmonic as _h
import numpy.testing as _nt
DECIMAL_F = 7
DECIMAL_D = 14
somd.utils.rng = somd.utils._rng.LEGACYRNG(1)
def test_barostat_1():
system = _h.get_harmonic_system()
system.box[:] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
c = [{'type': 0, 'indices': [0, 1], 'target': 1.0, 'tolerance': 1E-14},
{'type': 1, 'indices': [0, 1, 2], 'target': 1.57, 'tolerance': 1E-14}]
system.constraints.appends(c)
somd.utils.defaults.NHCLENGTH = 6
somd.utils.defaults.NHCNRESPA = 4
integrator = somd.core.integrators.nhc_integrator(
0.001, relaxation_times=[0.01])
barostat = somd.apps.barostats.BAROSTAT([1E-5], [1E-5], 0.1)
integrator.bind_system(system)
barostat.bind_integrator(integrator)
integrator.propagate()
barostat.update()
result = _np.loadtxt('data/barostat/barostat_1.dat')
_nt.assert_almost_equal(system.positions, result[0:4], DECIMAL_D)
_nt.assert_almost_equal(system.box, result[4:7], DECIMAL_D)
def test_barostat_2():
system = _h.get_harmonic_system()
system.box[:] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
c = [{'type': 0, 'indices': [0, 1], 'target': 1.0, 'tolerance': 1E-14},
{'type': 1, 'indices': [0, 1, 2], 'target': 1.57, 'tolerance': 1E-14}]
system.constraints.appends(c)
somd.utils.defaults.NHCLENGTH = 6
somd.utils.defaults.NHCNRESPA = 4
integrator = somd.core.integrators.nhc_integrator(
0.001, relaxation_times=[0.01])
barostat = somd.apps.barostats.BAROSTAT(
[1E-5, 1E-5, 1E-5, 1E-5, 1E-5, 1E-5],
[1E-5, 1E-5, 1E-5, 1E-5, 1E-5, 1E-5], 0.1)
integrator.bind_system(system)
barostat.bind_integrator(integrator)
barostat.initialize()
integrator.propagate()
barostat.update()
result = _np.loadtxt('data/barostat/barostat_2.dat')
_nt.assert_almost_equal(system.positions, result[0:4], DECIMAL_D)
_nt.assert_almost_equal(system.box, result[4:7], DECIMAL_D)