From 7f77cbfa6e5a15130f8f796e0148e4f3c92ddcbf Mon Sep 17 00:00:00 2001 From: "Billy K. Poon" Date: Mon, 14 Oct 2024 06:14:56 -0700 Subject: [PATCH] smtbx: remove pytest dependency - Reverts 0f7535f048d57e02f31c974c0193a10117df3981 --- smtbx/conftest.py | 4 - .../constraints/tests/test_rigid.py | 258 ---------------- .../{test_direction.py => tst_direction.py} | 6 +- .../{test_disorder.py => tst_disorder.py} | 7 +- ...test_occupancies.py => tst_occupancies.py} | 6 +- .../refinement/constraints/tests/tst_rigid.py | 288 ++++++++++++++++++ .../{test_same_group.py => tst_same_group.py} | 9 +- ...dp_restraints.py => tst_adp_restraints.py} | 15 +- .../tests/{test_manager.py => tst_manager.py} | 6 +- smtbx/run_tests.py | 11 +- smtbx/tests/{test_utils.py => tst_utils.py} | 6 +- 11 files changed, 340 insertions(+), 276 deletions(-) delete mode 100644 smtbx/conftest.py delete mode 100644 smtbx/refinement/constraints/tests/test_rigid.py rename smtbx/refinement/constraints/tests/{test_direction.py => tst_direction.py} (95%) rename smtbx/refinement/constraints/tests/{test_disorder.py => tst_disorder.py} (97%) rename smtbx/refinement/constraints/tests/{test_occupancies.py => tst_occupancies.py} (98%) create mode 100644 smtbx/refinement/constraints/tests/tst_rigid.py rename smtbx/refinement/constraints/tests/{test_same_group.py => tst_same_group.py} (96%) rename smtbx/refinement/restraints/tests/{test_adp_restraints.py => tst_adp_restraints.py} (96%) rename smtbx/refinement/restraints/tests/{test_manager.py => tst_manager.py} (98%) rename smtbx/tests/{test_utils.py => tst_utils.py} (90%) diff --git a/smtbx/conftest.py b/smtbx/conftest.py deleted file mode 100644 index cede9885ac..0000000000 --- a/smtbx/conftest.py +++ /dev/null @@ -1,4 +0,0 @@ -from __future__ import absolute_import, division, print_function - -from libtbx.test_utils.pytest import libtbx_collector -pytest_collect_file = libtbx_collector() diff --git a/smtbx/refinement/constraints/tests/test_rigid.py b/smtbx/refinement/constraints/tests/test_rigid.py deleted file mode 100644 index 1cf792117a..0000000000 --- a/smtbx/refinement/constraints/tests/test_rigid.py +++ /dev/null @@ -1,258 +0,0 @@ -from __future__ import absolute_import, division, print_function - -from cctbx import uctbx, xray, crystal -from cctbx.array_family import flex -import math -import pytest -from scitbx import matrix as mat -from scitbx import sparse -from scitbx.matrix import col -from smtbx.refinement import constraints -from smtbx.refinement.constraints import rigid -from six.moves import range - -def test_rigid_site_proxy(n=5): - uc = uctbx.unit_cell((1, 2, 3)) - reparam = constraints.ext.reparametrisation(uc) - independents = [ ] - for name in ('C#', 'C##'): - sc = xray.scatterer(name, site=tuple(flex.random_double(3))) - sc.flags.set_grad_site(True) - p = reparam.add(constraints.independent_site_parameter, sc) - independents.append(p) - pivot, pivot_neighbour = independents - rigid_group_scatterers = [ ] - for i in range(n): - sc = xray.scatterer('C%i' %i, - site=tuple(flex.random_double(3))) - sc.flags.set_grad_site(True) - rigid_group_scatterers.append(sc) - phi = reparam.add(constraints.independent_scalar_parameter, - value=0.1, variable=True) - size = reparam.add(constraints.independent_scalar_parameter, - value=1, variable=True) - rigid_group = reparam.add(constraints.rigid_pivoted_rotatable_group, - pivot, pivot_neighbour, - azimuth=phi, - size=size, - scatterers=rigid_group_scatterers) - proxies = [ ] - for i in range(n): - proxies.append(reparam.add(constraints.rigid_site_proxy, - parent=rigid_group, - index=i)) - reparam.finalise() - - assert str(reparam) == """\ -digraph dependencies { -8 -> 0; -8 -> 3; -8 -> 6; -8 -> 7; -23 -> 8; -26 -> 8; -29 -> 8; -32 -> 8; -35 -> 8; -0 [label="independent_site_parameter (C#) #0"]; -3 [label="independent_site_parameter (C##) #3"]; -6 [label="independent_scalar_parameter #6"]; -7 [label="independent_scalar_parameter #7"]; -8 [label="rigid_pivoted_rotatable_group (C0, C1, C2, C3, C4) #8"]; -23 [label="rigid_site_proxy #23"]; -26 [label="rigid_site_proxy #26"]; -29 [label="rigid_site_proxy #29"]; -32 [label="rigid_site_proxy #32"]; -35 [label="rigid_site_proxy #35"] -}""" - - reparam.linearise() - jt = reparam.jacobian_transpose - - q = 2*3 + 1 + 1 # pivot, its neighbour, azimuthal angle, size - jt0 = sparse.matrix(q, q + 2*3*n) # + rigid_group + constrained site proxies - assert jt.n_rows == jt0.n_rows - assert jt.n_cols == jt0.n_cols - for i, j in zip(range(q, q+3*n), range(q+3*n, jt0.n_cols)): - assert jt.col(i) == jt.col(j) - -def test_rigid_pivoted_rotatable(): - uc = uctbx.unit_cell((1, 1, 1)) - xs = xray.structure( - crystal_symmetry=crystal.symmetry( - unit_cell=uc, - space_group_symbol='hall: P 2x 2y'), - scatterers=flex.xray_scatterer(( #triangle - xray.scatterer('C0', site=(0,0,0)), - xray.scatterer('C1', site=(0,2,0)), - xray.scatterer('C2', site=(1,1,0)), - ))) - r = constraints.ext.reparametrisation(xs.unit_cell()) - sc = xs.scatterers() - pivot = r.add(constraints.independent_site_parameter, sc[0]) - pivot_neighbour = r.add(constraints.independent_site_parameter, sc[1]) - azimuth = r.add(constraints.independent_scalar_parameter, - value=math.pi/2, variable=True) - size = r.add(constraints.independent_scalar_parameter, - value=1, variable=False) - rg = r.add(constraints.rigid_pivoted_rotatable_group, - pivot=pivot, - pivot_neighbour=pivot_neighbour, - azimuth=azimuth, - size=size, - scatterers=(sc[1], sc[2])) - site_proxy = r.add(constraints.rigid_site_proxy, rg, 1) - r.finalise() - r.linearise() - r.store() - #check that proxy and the final results are the same... - assert uc.distance(col(site_proxy.value), col(sc[2].site)) == pytest.approx(0, abs=1e-15) - #rotation happens around the center of gravity - assert uc.distance(col((0,1,1)), col(sc[2].site)) == pytest.approx(0, abs=1e-15) - -@pytest.fixture -def rr(): - class rigid_rotatable(object): - def __init__(self): - self.size_value = 9 - self.rx = math.pi - self.ry = math.pi/2 - self.rz = math.pi/3 - self.sites = ((0,0,0), (1,0,0), (0,1,0), (0,0,1)) - self.uc = uctbx.unit_cell((1, 1, 1)) - self.xs = xray.structure( - crystal_symmetry=crystal.symmetry( - unit_cell=self.uc, - space_group_symbol='hall: P 2x 2y'), - scatterers=flex.xray_scatterer(( #triangle - xray.scatterer('C0'), - xray.scatterer('C1'), - xray.scatterer('C2'), - xray.scatterer('C3'), - ))) - self.center = col((0,0,0)) - for s in self.sites: - self.center = self.center + col(s) - self.center = self.center / len(self.sites) - sc = self.xs.scatterers() - for i, s in enumerate(self.sites): - sc[i].site = s - return rigid_rotatable() - -def test_rotatable_expansion(rr): - r = constraints.ext.reparametrisation(rr.uc) - sc = rr.xs.scatterers() - pivot = r.add(constraints.independent_site_parameter, sc[0]) - size = r.add(constraints.independent_scalar_parameter, - value=rr.size_value, variable=True) - r_x = r.add(constraints.independent_scalar_parameter, - value=0, variable=False) - r_y = r.add(constraints.independent_scalar_parameter, - value=0, variable=False) - r_z = r.add(constraints.independent_scalar_parameter, - value=0, variable=False) - rg = r.add(constraints.rigid_rotatable_expandable_group, - pivot=pivot, - size = size, - alpha = r_x, - beta = r_y, - gamma = r_z, - scatterers=(sc[1], sc[2], sc[3])) - r.finalise() - r.linearise() - r.store() - shift = col(rr.sites[0]) - (col(rr.sites[0])-rr.center)*rr.size_value - for i in range(1,4): - calc_site = (col(rr.sites[i])-rr.center)*rr.size_value + shift - assert rr.uc.distance(calc_site, col(sc[i].site)) == pytest.approx(0, abs=1e-14) - -def test_rotatable_rotation(rr): - r = constraints.ext.reparametrisation(rr.uc) - sc = rr.xs.scatterers() - pivot = r.add(constraints.independent_site_parameter, sc[0]) - size = r.add(constraints.independent_scalar_parameter, - value=1, variable=False) - r_x = r.add(constraints.independent_scalar_parameter, - value=math.pi, variable=True) - r_y = r.add(constraints.independent_scalar_parameter, - value=math.pi/2, variable=True) - r_z = r.add(constraints.independent_scalar_parameter, - value=math.pi/3, variable=True) - rg = r.add(constraints.rigid_rotatable_expandable_group, - pivot=pivot, - size = size, - alpha = r_x, - beta = r_y, - gamma = r_z, - scatterers=(sc[1], sc[2], sc[3])) - r.finalise() - r.linearise() - r.store() - rx_m = mat.sqr((1, 0, 0, - 0, math.cos(rr.rx), -math.sin(rr.rx), - 0, math.sin(rr.rx), math.cos(rr.rx))) - ry_m = mat.sqr((math.cos(rr.ry), 0, math.sin(rr.ry), - 0, 1, 0, - -math.sin(rr.ry), 0, math.cos(rr.ry))) - rz_m = mat.sqr((math.cos(rr.rz), -math.sin(rr.rz), 0, - math.sin(rr.rz), math.cos(rr.rz), 0, - 0, 0, 1)) - R = rx_m*ry_m*rz_m #comulative rotation matrix - shift = col(rr.sites[0])-col(mat.row(col(rr.sites[0])-rr.center)*R) - for i in range(1,4): - calc_site = col(mat.row(col(rr.sites[i])-rr.center)*R) + shift - assert rr.uc.distance(calc_site, col(sc[i].site)) == pytest.approx(0, abs=1e-14) - -idealised_def_len_ref = { - "Naphthalene" : ((0.695,-1.203775), - (-0.695,-1.203775), - (-1.39,-0), - (-0.695,1.203775), - (0.695,1.203775), - (1.39,0), - (2.78,0), - (3.475,1.203775), - (2.78,2.407551), - (1.39,2.407551)), - "Cp*" : ((0.373269,-1.148804), - (-0.977231,-0.71), - (-0.977231,0.71), - (0.373269,1.148804), - (1.207924,0), - (0.701754,-2.159777), - (-1.837216,-1.334816), - (-1.837216,1.334816), - (0.701754,2.159777), - (2.270924,0)), - "Cp" : ((0.373269,-1.148804), - (-0.977231,-0.71), - (-0.977231,0.71), - (0.373269,1.148804), - (1.207924,0)), - "Ph" : ((0.695,-1.203775), - (-0.695,-1.203775), - (-1.39,-0), - (-0.695,1.203775), - (0.695,1.203775), - (1.39,0)) -} - -@pytest.mark.parametrize('fragment', ("Cp", "Ph", "Cp*", "Naphthalene"), ids=("Cp", "Ph", "CpStar", "Naphthalene")) -def test_idealised_generation(fragment): - generated = rigid.idealised_fragment().generate_fragment(fragment) - reference = idealised_def_len_ref[fragment] - for i, gen in enumerate(generated): - assert gen.x == pytest.approx(reference[i][0], abs=1e-6) - assert gen.y == pytest.approx(reference[i][1], abs=1e-6) - -def test_idealised_fitting(): - tested = rigid.idealised_fragment() - source_pts_indices = [1, 2, 5] - ref_sites = ((-0.695,-1.203775,0), (-1.39,-0,0), (1.39,0,0)) - control_pts_indices = [0, 1, 4] - fragment = tested.generate_fragment("Ph") - crds = tested.fit(fragment, ref_sites, control_pts_indices) - uc = uctbx.unit_cell((1, 1, 1)) - for i, p in enumerate(source_pts_indices): - assert uc.distance(col((fragment[p].x,fragment[p].y,0)), - crds[control_pts_indices[i]]) == pytest.approx(0, abs=1e-6) diff --git a/smtbx/refinement/constraints/tests/test_direction.py b/smtbx/refinement/constraints/tests/tst_direction.py similarity index 95% rename from smtbx/refinement/constraints/tests/test_direction.py rename to smtbx/refinement/constraints/tests/tst_direction.py index 593bbfed29..7286505fd9 100644 --- a/smtbx/refinement/constraints/tests/test_direction.py +++ b/smtbx/refinement/constraints/tests/tst_direction.py @@ -1,6 +1,6 @@ from __future__ import absolute_import, division, print_function -def test_direction(): +def exercise_direction(): from cctbx.array_family import flex from cctbx import uctbx, xray, crystal from smtbx.refinement import constraints @@ -44,3 +44,7 @@ def test_direction(): nc = row(v01).cross(row(v21)).normalize() assert approx_equal(n, n1, eps=1e-15) assert approx_equal(n, nc, eps=1e-15) + +if __name__ == '__main__': + exercise_direction() + print('OK') diff --git a/smtbx/refinement/constraints/tests/test_disorder.py b/smtbx/refinement/constraints/tests/tst_disorder.py similarity index 97% rename from smtbx/refinement/constraints/tests/test_disorder.py rename to smtbx/refinement/constraints/tests/tst_disorder.py index 6f22aae4d4..434f0225f3 100644 --- a/smtbx/refinement/constraints/tests/test_disorder.py +++ b/smtbx/refinement/constraints/tests/tst_disorder.py @@ -1,7 +1,6 @@ from __future__ import absolute_import, division, print_function from six.moves import zip - from six.moves import cStringIO as StringIO disordered = """ @@ -67,7 +66,7 @@ HKLF 4 """ -def test_with_disorder(): +def exercise_with_disorder(): from iotbx import shelx from smtbx import refinement import smtbx.refinement.constraints as core @@ -100,3 +99,7 @@ def test_with_disorder(): assert isinstance(params.site, expected_type) assert ([sc1.label for sc1 in params.site.argument(0).scatterers] == [expected_pivot]) + +if __name__ == '__main__': + exercise_with_disorder() + print('OK') diff --git a/smtbx/refinement/constraints/tests/test_occupancies.py b/smtbx/refinement/constraints/tests/tst_occupancies.py similarity index 98% rename from smtbx/refinement/constraints/tests/test_occupancies.py rename to smtbx/refinement/constraints/tests/tst_occupancies.py index 8662aa4fd6..5918f3f9c1 100644 --- a/smtbx/refinement/constraints/tests/test_occupancies.py +++ b/smtbx/refinement/constraints/tests/tst_occupancies.py @@ -101,7 +101,7 @@ } """ -def test_simple_disorder(): +def exercise_simple_disorder(): ins = fnames.thpp_ins model = smtbx.refinement.model.from_shelx(ins) ls = model.least_squares() @@ -113,3 +113,7 @@ def test_simple_disorder(): covann.variance_of('C7A.occ')) assert approx_equal(covann.variance_of('C3.occ'), covann.variance_of('N3.occ')) + +if __name__ == '__main__': + exercise_simple_disorder() + print('OK') diff --git a/smtbx/refinement/constraints/tests/tst_rigid.py b/smtbx/refinement/constraints/tests/tst_rigid.py new file mode 100644 index 0000000000..d56b759ae9 --- /dev/null +++ b/smtbx/refinement/constraints/tests/tst_rigid.py @@ -0,0 +1,288 @@ +from __future__ import absolute_import, division, print_function + +from cctbx.array_family import flex +from scitbx import sparse +from cctbx import uctbx, xray, crystal +from smtbx.refinement import constraints +from math import pi +import math +from scitbx.matrix import col +from scitbx import matrix as mat +from libtbx.test_utils import approx_equal +from smtbx.refinement.constraints import rigid +from six.moves import range + +def exercise_rigid_site_proxy(n=5): + uc = uctbx.unit_cell((1, 2, 3)) + reparam = constraints.ext.reparametrisation(uc) + independents = [ ] + for name in ('C#', 'C##'): + sc = xray.scatterer(name, site=tuple(flex.random_double(3))) + sc.flags.set_grad_site(True) + p = reparam.add(constraints.independent_site_parameter, sc) + independents.append(p) + pivot, pivot_neighbour = independents + rigid_group_scatterers = [ ] + for i in range(n): + sc = xray.scatterer('C%i' %i, + site=tuple(flex.random_double(3))) + sc.flags.set_grad_site(True) + rigid_group_scatterers.append(sc) + phi = reparam.add(constraints.independent_scalar_parameter, + value=0.1, variable=True) + size = reparam.add(constraints.independent_scalar_parameter, + value=1, variable=True) + rigid_group = reparam.add(constraints.rigid_pivoted_rotatable_group, + pivot, pivot_neighbour, + azimuth=phi, + size=size, + scatterers=rigid_group_scatterers) + proxies = [ ] + for i in range(n): + proxies.append(reparam.add(constraints.rigid_site_proxy, + parent=rigid_group, + index=i)) + reparam.finalise() + + assert str(reparam) == """\ +digraph dependencies { +8 -> 0; +8 -> 3; +8 -> 6; +8 -> 7; +23 -> 8; +26 -> 8; +29 -> 8; +32 -> 8; +35 -> 8; +0 [label="independent_site_parameter (C#) #0"]; +3 [label="independent_site_parameter (C##) #3"]; +6 [label="independent_scalar_parameter #6"]; +7 [label="independent_scalar_parameter #7"]; +8 [label="rigid_pivoted_rotatable_group (C0, C1, C2, C3, C4) #8"]; +23 [label="rigid_site_proxy #23"]; +26 [label="rigid_site_proxy #26"]; +29 [label="rigid_site_proxy #29"]; +32 [label="rigid_site_proxy #32"]; +35 [label="rigid_site_proxy #35"] +}""" + + reparam.linearise() + jt = reparam.jacobian_transpose + + q = 2*3 + 1 + 1 # pivot, its neighbour, azimuthal angle, size + jt0 = sparse.matrix(q, q + 2*3*n) # + rigid_group + constrained site proxies + assert jt.n_rows == jt0.n_rows + assert jt.n_cols == jt0.n_cols + for i,j in zip(range(q, q+3*n), range(q+3*n, jt0.n_cols)): + assert jt.col(i) == jt.col(j) + +def exercise_rigid_pivoted_rotatable(): + uc = uctbx.unit_cell((1, 1, 1)) + xs = xray.structure( + crystal_symmetry=crystal.symmetry( + unit_cell=uc, + space_group_symbol='hall: P 2x 2y'), + scatterers=flex.xray_scatterer(( #triangle + xray.scatterer('C0', site=(0,0,0)), + xray.scatterer('C1', site=(0,2,0)), + xray.scatterer('C2', site=(1,1,0)), + ))) + r = constraints.ext.reparametrisation(xs.unit_cell()) + sc = xs.scatterers() + pivot = r.add(constraints.independent_site_parameter, sc[0]) + pivot_neighbour = r.add(constraints.independent_site_parameter, sc[1]) + azimuth = r.add(constraints.independent_scalar_parameter, + value=pi/2, variable=True) + size = r.add(constraints.independent_scalar_parameter, + value=1, variable=False) + rg = r.add(constraints.rigid_pivoted_rotatable_group, + pivot=pivot, + pivot_neighbour=pivot_neighbour, + azimuth=azimuth, + size=size, + scatterers=(sc[1], sc[2])) + site_proxy = r.add(constraints.rigid_site_proxy, rg, 1) + r.finalise() + r.linearise() + r.store() + #check that proxy and the final results are the same... + assert approx_equal( + uc.distance(col(site_proxy.value), col(sc[2].site)), 0, eps=1e-15) + #rotation happens around the center of gravity + assert approx_equal( + uc.distance(col((0,1,1)), col(sc[2].site)), 0, eps=1e-15) + +class rigid_rotatable(object): + def __init__(self): + self.size_value = 9 + self.rx = pi + self.ry = pi/2 + self.rz = pi/3 + self.sites = ((0,0,0), (1,0,0), (0,1,0), (0,0,1)) + self.uc = uctbx.unit_cell((1, 1, 1)) + self.xs = xray.structure( + crystal_symmetry=crystal.symmetry( + unit_cell=self.uc, + space_group_symbol='hall: P 2x 2y'), + scatterers=flex.xray_scatterer(( #triangle + xray.scatterer('C0'), + xray.scatterer('C1'), + xray.scatterer('C2'), + xray.scatterer('C3'), + ))) + self.center = col((0,0,0)) + for s in self.sites: + self.center = self.center + col(s) + self.center = self.center / len(self.sites) + self.reset_sites() + def reset_sites(self): + sc = self.xs.scatterers() + for i, s in enumerate(self.sites): + sc[i].site = s + def exercise_expansion(self): + self.reset_sites() + r = constraints.ext.reparametrisation(self.uc) + sc = self.xs.scatterers() + pivot = r.add(constraints.independent_site_parameter, sc[0]) + size = r.add(constraints.independent_scalar_parameter, + value=self.size_value, variable=True) + r_x = r.add(constraints.independent_scalar_parameter, + value=0, variable=False) + r_y = r.add(constraints.independent_scalar_parameter, + value=0, variable=False) + r_z = r.add(constraints.independent_scalar_parameter, + value=0, variable=False) + rg = r.add(constraints.rigid_rotatable_expandable_group, + pivot=pivot, + size = size, + alpha = r_x, + beta = r_y, + gamma = r_z, + scatterers=(sc[1], sc[2], sc[3])) + r.finalise() + r.linearise() + r.store() + shift = col(self.sites[0]) - (col(self.sites[0])-self.center)*self.size_value + for i in range(1,4): + calc_site = (col(self.sites[i])-self.center)*self.size_value + shift + assert approx_equal( + self.uc.distance( + calc_site, col(sc[i].site)), 0, eps=1e-14) + def exercise_rotation(self): + self.reset_sites() + r = constraints.ext.reparametrisation(self.uc) + sc = self.xs.scatterers() + pivot = r.add(constraints.independent_site_parameter, sc[0]) + size = r.add(constraints.independent_scalar_parameter, + value=1, variable=False) + r_x = r.add(constraints.independent_scalar_parameter, + value=pi, variable=True) + r_y = r.add(constraints.independent_scalar_parameter, + value=pi/2, variable=True) + r_z = r.add(constraints.independent_scalar_parameter, + value=pi/3, variable=True) + rg = r.add(constraints.rigid_rotatable_expandable_group, + pivot=pivot, + size = size, + alpha = r_x, + beta = r_y, + gamma = r_z, + scatterers=(sc[1], sc[2], sc[3])) + r.finalise() + r.linearise() + r.store() + rx_m = mat.sqr((1, 0, 0, + 0, math.cos(self.rx), -math.sin(self.rx), + 0, math.sin(self.rx), math.cos(self.rx))) + ry_m = mat.sqr((math.cos(self.ry), 0, math.sin(self.ry), + 0, 1, 0, + -math.sin(self.ry), 0, math.cos(self.ry))) + rz_m = mat.sqr((math.cos(self.rz), -math.sin(self.rz), 0, + math.sin(self.rz), math.cos(self.rz), 0, + 0, 0, 1)) + R = rx_m*ry_m*rz_m #comulative rotation matrix + shift = col(self.sites[0])-col(mat.row(col(self.sites[0])-self.center)*R) + for i in range(1,4): + calc_site = col(mat.row(col(self.sites[i])-self.center)*R) + shift + assert approx_equal( + self.uc.distance( + calc_site, col(sc[i].site)), 0, eps=1e-14) + def excercise(self): + self.exercise_expansion() + self.exercise_rotation() + +class idealised(object): + def __init__(self): + self.def_len_ref = { + "Naphthalene" : ((0.695,-1.203775), + (-0.695,-1.203775), + (-1.39,-0), + (-0.695,1.203775), + (0.695,1.203775), + (1.39,0), + (2.78,0), + (3.475,1.203775), + (2.78,2.407551), + (1.39,2.407551)), + "Cp*" : ((0.373269,-1.148804), + (-0.977231,-0.71), + (-0.977231,0.71), + (0.373269,1.148804), + (1.207924,0), + (0.701754,-2.159777), + (-1.837216,-1.334816), + (-1.837216,1.334816), + (0.701754,2.159777), + (2.270924,0)), + "Cp" : ((0.373269,-1.148804), + (-0.977231,-0.71), + (-0.977231,0.71), + (0.373269,1.148804), + (1.207924,0)), + "Ph" : ((0.695,-1.203775), + (-0.695,-1.203775), + (-1.39,-0), + (-0.695,1.203775), + (0.695,1.203775), + (1.39,0)) + } + self.tested = rigid.idealised_fragment() + + def compare_results(self, _a , _b): + for i, a in enumerate(_a): + assert approx_equal(a.x, _b[i][0], 1e-6) + assert approx_equal(a.y, _b[i][1], 1e-6) + + def exercise_generation(self): + frags = ("Cp", "Ph", "Cp*", "Naphthalene") + for i in frags: + self.compare_results( + self.tested.generate_fragment(i), self.def_len_ref[i]) + + def exercise_fitting(self): + source_pts_indices = [1, 2, 5] + ref_sites = ((-0.695,-1.203775,0), (-1.39,-0,0), (1.39,0,0)) + control_pts_indices = [0, 1, 4] + fragment = self.tested.generate_fragment("Ph") + crds = self.tested.fit(fragment, ref_sites, control_pts_indices) + uc = uctbx.unit_cell((1, 1, 1)) + for i, p in enumerate(source_pts_indices): + approx_equal( + uc.distance( + col((fragment[p].x,fragment[p].y,0)), + crds[control_pts_indices[i]]), 1e-14) + + def exercise(self): + self.exercise_generation() + self.exercise_fitting() + +def run(): + exercise_rigid_site_proxy() + exercise_rigid_pivoted_rotatable() + rigid_rotatable().excercise() + idealised().exercise() + print('OK') + +if __name__ == '__main__': + run() diff --git a/smtbx/refinement/constraints/tests/test_same_group.py b/smtbx/refinement/constraints/tests/tst_same_group.py similarity index 96% rename from smtbx/refinement/constraints/tests/test_same_group.py rename to smtbx/refinement/constraints/tests/tst_same_group.py index 8cf40d1773..25e7c05511 100644 --- a/smtbx/refinement/constraints/tests/test_same_group.py +++ b/smtbx/refinement/constraints/tests/tst_same_group.py @@ -9,7 +9,7 @@ import os from smtbx.regression.test_data import fnames -def test_basics(): +def exercise_basics(): # construct a simple structure whose sites and u_iso's are to be refined xs = xray.structure( crystal_symmetry=crystal.symmetry( @@ -87,7 +87,7 @@ def test_basics(): jacobian_transpose_matching_grad_fc, sc_params) -def test_real_life_structure(): +def exercise_real_life_structure(): working_dir = os.path.dirname(__file__) res = fnames.sucrose_p1_res xs = xray.structure.from_shelx(filename=res) @@ -98,3 +98,8 @@ def test_real_life_structure(): ls = m.least_squares() ls.build_up() # wip + +if __name__ == '__main__': + exercise_basics() + exercise_real_life_structure() + print('OK') diff --git a/smtbx/refinement/restraints/tests/test_adp_restraints.py b/smtbx/refinement/restraints/tests/tst_adp_restraints.py similarity index 96% rename from smtbx/refinement/restraints/tests/test_adp_restraints.py rename to smtbx/refinement/restraints/tests/tst_adp_restraints.py index d045e2a72b..451627e5d2 100644 --- a/smtbx/refinement/restraints/tests/test_adp_restraints.py +++ b/smtbx/refinement/restraints/tests/tst_adp_restraints.py @@ -15,7 +15,7 @@ def get_pair_sym_table(xray_structure): scattering_types, exclude_scattering_types=flex.std_string(("H","D"))) return pair_asu_table.extract_pair_sym_table() -def test_adp_similarity(): +def exercise_adp_similarity(): xray_structure = development.sucrose() pair_sym_table = get_pair_sym_table(xray_structure) for table in (None,pair_sym_table): @@ -56,7 +56,7 @@ def test_adp_similarity(): assert approx_equal(proxies[i].i_seqs, expected_i_seqs[i]) assert approx_equal(proxies[i].weight, expected_weights[i]) -def test_rigid_bond(): +def exercise_rigid_bond(): xray_structure = development.sucrose() pair_sym_table = get_pair_sym_table(xray_structure) for table in (None,pair_sym_table): @@ -99,7 +99,7 @@ def test_rigid_bond(): assert approx_equal(proxies[i].i_seqs, expected_i_seqs[i]) assert approx_equal(proxies[i].weight, expected_weights[i]) -def test_isotropic_adp(): +def exercise_isotropic_adp(): xray_structure = development.sucrose() xray_structure.scatterers()[10].set_use_u_iso_only() pair_sym_table = get_pair_sym_table(xray_structure) @@ -137,7 +137,7 @@ def test_isotropic_adp(): assert approx_equal(proxies[i].i_seqs[0], expected_i_seqs[i]) assert approx_equal(proxies[i].weight, expected_weights[i]) -def test_rigu(): +def exercise_rigu(): xray_structure = development.sucrose() pair_sym_table = get_pair_sym_table(xray_structure) for table in (None,pair_sym_table): @@ -179,3 +179,10 @@ def test_rigu(): for i in range(proxies.size()): assert approx_equal(proxies[i].i_seqs, expected_i_seqs[i]) assert approx_equal(proxies[i].weight, expected_weights[i]) + +if __name__ == '__main__': + exercise_isotropic_adp() + exercise_rigid_bond() + exercise_adp_similarity() + exercise_rigu() + print('OK') diff --git a/smtbx/refinement/restraints/tests/test_manager.py b/smtbx/refinement/restraints/tests/tst_manager.py similarity index 98% rename from smtbx/refinement/restraints/tests/test_manager.py rename to smtbx/refinement/restraints/tests/tst_manager.py index 0ec30ca05f..16a1c22f1b 100644 --- a/smtbx/refinement/restraints/tests/test_manager.py +++ b/smtbx/refinement/restraints/tests/tst_manager.py @@ -10,7 +10,7 @@ from six.moves import cStringIO as StringIO import sys -def test_manager(): +def exercise_manager(): xray_structure = smtbx.development.sucrose() xray_structure.scatterers()[10].set_use_u_iso_only() asu_mappings = xray_structure.asu_mappings(buffer_thickness=3.5) @@ -161,3 +161,7 @@ def test_manager(): ... (remaining 21 not shown) """ + +if __name__ == '__main__': + exercise_manager() + print('OK') diff --git a/smtbx/run_tests.py b/smtbx/run_tests.py index 0a570d3126..ebfca9bfbe 100644 --- a/smtbx/run_tests.py +++ b/smtbx/run_tests.py @@ -1,7 +1,6 @@ from __future__ import absolute_import, division, print_function from libtbx import test_utils -from libtbx.test_utils.pytest import discover import libtbx.load_env tst_list = [ @@ -16,18 +15,26 @@ "--fix_random_seeds"], "$D/refinement/constraints/tests/tst_lbfgs.py", "$B/refinement/constraints/tests/tst_reparametrisation", + "$D/refinement/constraints/tests/tst_occupancies.py", "$B/refinement/constraints/tests/tst_geometrical_hydrogens", + "$D/refinement/constraints/tests/tst_same_group.py", "$B/refinement/constraints/tests/tst_special_position", "$D/refinement/constraints/tests/tst_reparametrisation.py", ["$D/refinement/constraints/tests/tst_constrained_structure.py", '--normal_eqns_solving_method=naive'], + "$D/refinement/constraints/tests/tst_disorder.py", ["$D/refinement/constraints/tests/tst_constrained_structure.py", '--normal_eqns_solving_method=levenberg-marquardt'], + "$D/refinement/constraints/tests/tst_rigid.py", + "$D/refinement/constraints/tests/tst_direction.py", + "$D/refinement/restraints/tests/tst_adp_restraints.py", + "$D/refinement/restraints/tests/tst_manager.py", ["$D/refinement/restraints/tests/tst_restraints.py", '--verbose', '--scatterers=5', '--resolution=0.2'], "$D/regression/tst_commandline_refine.py", "$D/regression/tst_commandline_anomrefine.py", -] + discover() + "$D/tests/tst_utils.py", +] # unstable test tst_list_expected_unstable = [ diff --git a/smtbx/tests/test_utils.py b/smtbx/tests/tst_utils.py similarity index 90% rename from smtbx/tests/test_utils.py rename to smtbx/tests/tst_utils.py index 1da585479d..8e0871696a 100644 --- a/smtbx/tests/test_utils.py +++ b/smtbx/tests/tst_utils.py @@ -4,7 +4,7 @@ from libtbx.test_utils import approx_equal from smtbx import development, utils -def test_connectivity_table(): +def exercise_connectivity_table(): xs = development.sucrose() connectivity = utils.connectivity_table(xs) pair_counts = [ @@ -21,3 +21,7 @@ def test_connectivity_table(): connectivity.remove_bond(0, 1) connectivity.remove_bond(5,5, rt_mx_ji=sgtbx.rt_mx("x+1,y,z")) assert approx_equal(connectivity.pair_asu_table.pair_counts(), pair_counts) + +if __name__ == '__main__': + exercise_connectivity_table() + print('OK')