Skip to content

Commit 8cab51b

Browse files
committed
improved testing
1 parent f0409c5 commit 8cab51b

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

tests/test_twomolecules.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import numpy as np
1414

1515
from nmrdfrommd import NMRD
16+
from nmrdfrommd.utilities import compute_rij, cartesian_to_spherical
1617

1718
@pytest.fixture
1819
def twomol_universe():
@@ -56,3 +57,98 @@ def test_shape_array(twomol_universe):
5657
assert nmrd_aniso.R1.shape == (n_fft,)
5758
assert nmrd_aniso.R2.shape == (n_fft,)
5859
assert nmrd_aniso.gij.T[0].shape == (3,)
60+
61+
def test_distance(twomol_universe):
62+
"""Assert that the calculated distance is correct."""
63+
u, group_H2O = twomol_universe
64+
65+
nmrd_pbc = NMRD(
66+
u=u,
67+
atom_group=group_H2O,
68+
pbc=True)
69+
nmrd_pbc.run_analysis()
70+
71+
rij = compute_rij(
72+
nmrd_pbc.position_i,
73+
nmrd_pbc.position_j,
74+
nmrd_pbc.box,
75+
nmrd_pbc.pbc)
76+
77+
assert np.isclose(rij[0], -8.0)
78+
assert np.isclose(rij[1], 0.0)
79+
assert np.isclose(rij[2], 0.0)
80+
81+
nmrd_nopbc = NMRD(
82+
u=u,
83+
atom_group=group_H2O,
84+
pbc=False)
85+
nmrd_nopbc.run_analysis()
86+
87+
rij = compute_rij(
88+
nmrd_nopbc.position_i,
89+
nmrd_nopbc.position_j,
90+
nmrd_nopbc.box,
91+
nmrd_nopbc.pbc)
92+
93+
assert np.isclose(rij[0], 10.0)
94+
assert np.isclose(rij[1], 0.0)
95+
assert np.isclose(rij[2], 0.0)
96+
97+
def test_distance(twomol_universe):
98+
"""Assert that the calculated spherical functions are correct."""
99+
u, group_H2O = twomol_universe
100+
101+
nmrd_pbc = NMRD(
102+
u=u,
103+
atom_group=group_H2O,
104+
pbc=True)
105+
nmrd_pbc.run_analysis()
106+
107+
rij = compute_rij(
108+
nmrd_pbc.position_i,
109+
nmrd_pbc.position_j,
110+
nmrd_pbc.box,
111+
nmrd_pbc.pbc)
112+
r, theta, phi = cartesian_to_spherical(rij)
113+
114+
assert np.isclose(r[0], 8.0)
115+
assert np.isclose(theta[0], np.pi/2)
116+
assert np.isclose(phi[0], np.pi)
117+
118+
nmrd_nopbc = NMRD(
119+
u=u,
120+
atom_group=group_H2O,
121+
pbc=False)
122+
nmrd_nopbc.run_analysis()
123+
124+
rij = compute_rij(
125+
nmrd_nopbc.position_i,
126+
nmrd_nopbc.position_j,
127+
nmrd_nopbc.box,
128+
nmrd_nopbc.pbc)
129+
r, theta, phi = cartesian_to_spherical(rij)
130+
131+
assert np.isclose(r[0], 10.0)
132+
assert np.isclose(theta[0], np.pi/2)
133+
assert np.isclose(phi[0], 0)
134+
135+
if False:
136+
def test_correlation(twomol_universe):
137+
"""Assert that the calculated correlation is correct."""
138+
u, group_H2O = twomol_universe
139+
140+
nmrd_pbc = NMRD(
141+
u=u,
142+
atom_group=group_H2O,
143+
pbc=True)
144+
nmrd_pbc.run_analysis()
145+
146+
assert np.float32(np.round(nmrd_pbc.gij[0][0], 7)) == np.float32(np.round(1/8**6, 7))
147+
148+
nmrd_nopbc = NMRD(
149+
u=u,
150+
atom_group=group_H2O,
151+
pbc=False)
152+
nmrd_nopbc.run_analysis()
153+
154+
assert np.float32(np.round(nmrd_nopbc.gij[0][0], 7)) == np.float32(np.round(1/10**6, 7))

0 commit comments

Comments
 (0)