From 66c50f1ac426b28892d598b7fb057c295a42db68 Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Fri, 16 Dec 2022 16:38:34 +0100 Subject: [PATCH 01/10] Setup env fast --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 9d1deb9..e80aecd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ env: conda env create -f ./environment.yml -p ./env --quiet + ./env/bin/python -m pip install -e . test: python -m pytest -vrs tests From 7de1eec6ec9138b3e03b391a95f5ed46c13981bc Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Fri, 16 Dec 2022 17:05:21 +0100 Subject: [PATCH 02/10] Isolated bug --- tests/context.py | 16 ++++++++++++++ tests/resources/issue93/a.xyz | 22 +++++++++++++++++++ tests/resources/issue93/b.xyz | 22 +++++++++++++++++++ tests/resources/issue93/c.xyz | 22 +++++++++++++++++++ tests/resources/issue93/d.xyz | 22 +++++++++++++++++++ tests/test_reorder_print.py | 41 +++++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+) create mode 100644 tests/resources/issue93/a.xyz create mode 100644 tests/resources/issue93/b.xyz create mode 100644 tests/resources/issue93/c.xyz create mode 100644 tests/resources/issue93/d.xyz create mode 100644 tests/test_reorder_print.py diff --git a/tests/context.py b/tests/context.py index 3962ccd..fff703d 100644 --- a/tests/context.py +++ b/tests/context.py @@ -1,3 +1,19 @@ from pathlib import Path +import subprocess RESOURCE_PATH = Path("tests/resources") + +def call_main(args: list[str]) -> list[str]: + + root_path = Path("./") + filename = root_path / "rmsd/calculate_rmsd.py" + + cmd = ["python", f"{filename}", *args] + + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout, stderr = proc.communicate() + + if stderr is not None: + print(stderr.decode()) + + return stdout.decode().strip().split("\n") diff --git a/tests/resources/issue93/a.xyz b/tests/resources/issue93/a.xyz new file mode 100644 index 0000000..c849643 --- /dev/null +++ b/tests/resources/issue93/a.xyz @@ -0,0 +1,22 @@ +20 + +C -0.4378260222 -0.3027444364 -1.2372902933 +C 0.1107709466 1.1031415940 -1.5729191901 +C 0.5005103668 -1.1044030188 -0.2962381736 +C 0.3998133345 -0.7811385983 1.1631226837 +C 0.0885767200 -1.5765750897 2.2490552567 +C 0.4849378650 0.3701285431 3.0522986790 +H 0.0195747479 -1.5423304575 -2.8383838780 +H -1.5595867022 -1.6043371753 -2.4047214628 +H -1.3882210499 -0.1233250051 -0.7119415800 +H 1.5378933274 -0.9934345286 -0.6538216533 +H 0.2377875820 -2.1655077189 -0.4019180847 +H -0.1633586912 -2.6334567466 2.2467335441 +H 0.6168935065 1.2177913407 3.7166960247 +H 0.8625703727 1.2817813256 1.1335155509 +H -0.6039973796 0.7377874297 -3.2455391704 +N -0.7633488058 -0.9817332422 -2.5064360775 +N 0.6557050530 0.4639055355 1.7015091026 +N 0.1451038795 -0.8519411439 3.4200535140 +O 0.7148263821 1.8041376084 -0.7858085661 +O -0.1586606797 1.5088838316 -2.8169269008 diff --git a/tests/resources/issue93/b.xyz b/tests/resources/issue93/b.xyz new file mode 100644 index 0000000..b27b2b2 --- /dev/null +++ b/tests/resources/issue93/b.xyz @@ -0,0 +1,22 @@ +20 + +C -0.2769166422 -0.7099045701 -1.2865831838 +C -0.0318894674 0.6967020886 -1.8794695568 +C 0.6647089780 -1.0315870523 -0.0954617436 +C 0.2611763277 -0.4666702466 1.2320987930 +C -0.0191751268 -1.0867015822 2.4345274135 +C -0.2291714337 1.0136818561 2.8036493128 +H -0.8594037813 -2.4661239083 -2.2309783928 +H 0.7080595367 -2.0732382850 -2.5032982174 +H -1.3132498520 -0.6901271514 -0.9163939649 +H 1.6889557061 -0.7206820514 -0.3611372211 +H 0.6818980659 -2.1236321622 0.0197593401 +H 0.2183924342 1.5973044617 0.7751919144 +H -0.0088301381 -2.1515499995 2.6500889072 +H -0.4092099932 1.9792682002 3.2647218979 +H -0.3655783827 -0.1675785054 -3.4867813105 +N -0.2277128834 -1.6869155940 -2.3914365186 +N 0.1251882275 0.8821440432 1.4922681597 +N -0.3220367191 -0.1577068300 3.4064874889 +O -0.1893763020 0.7629926388 -3.2044168223 +O 0.2560010284 1.6738952911 -1.2175802549 diff --git a/tests/resources/issue93/c.xyz b/tests/resources/issue93/c.xyz new file mode 100644 index 0000000..1672093 --- /dev/null +++ b/tests/resources/issue93/c.xyz @@ -0,0 +1,22 @@ +20 +b.xyz - modified +6 -0.40759914 -0.21976042 -1.24619800 +6 -0.00056312 1.26286681 -1.40816417 +6 0.58710277 -1.02255927 -0.36586236 +6 0.41909751 -0.87621203 1.11560424 +6 0.16739220 -1.81528006 2.09726918 +6 0.33911177 0.05972314 3.12041893 +1 -1.36062251 -1.48928504 -2.58617323 +1 0.21329021 -1.22102654 -2.95535420 +1 -1.38339903 -0.19684427 -0.73756537 +1 1.61529960 -0.76790502 -0.67292786 +1 0.43914697 -2.08630272 -0.59541156 +1 0.36609516 0.83692342 3.87711598 +1 0.66401664 1.21334374 1.32621590 +1 0.02744709 -2.88534987 1.97140463 +1 -0.63332683 1.01562723 -3.13450799 +7 -0.63109905 -0.78238518 -2.59199650 +7 0.53063943 0.32047774 1.79455405 +7 0.12049476 -1.22387595 3.34125656 +8 -0.28077247 1.77523394 -2.60968173 +8 0.50821277 1.92922041 -0.52895719 diff --git a/tests/resources/issue93/d.xyz b/tests/resources/issue93/d.xyz new file mode 100644 index 0000000..064237f --- /dev/null +++ b/tests/resources/issue93/d.xyz @@ -0,0 +1,22 @@ +20 +b.xyz - modified +6 -0.43789836 -0.30253334 -1.23717746 +6 0.11094785 1.10318590 -1.57305854 +6 0.50063992 -1.10429331 -0.29630787 +6 0.39992447 -0.78124662 1.16310428 +6 0.08894976 -1.57679109 2.24904815 +6 0.48469770 0.37004052 3.05228551 +1 0.01882276 -1.54269123 -2.83801055 +1 -1.56033536 -1.60373840 -2.40443087 +1 -1.38810094 -0.12293143 -0.71155788 +1 1.53799278 -0.99306362 -0.65387426 +1 0.23808480 -2.16541809 -0.40219882 +1 -0.16267214 -2.63374746 2.24668396 +1 0.61636707 1.21773342 3.71669406 +1 0.86185680 1.28183964 1.13344692 +1 -0.60323400 0.73728341 -3.24573304 +7 -0.76377924 -0.98157261 -2.50618485 +7 0.65534023 0.46390036 1.70148391 +7 0.14534613 -0.85216749 3.42003187 +8 0.71471651 1.80437288 -0.78585771 +8 -0.15770200 1.50846860 -2.81734749 diff --git a/tests/test_reorder_print.py b/tests/test_reorder_print.py new file mode 100644 index 0000000..de80ffe --- /dev/null +++ b/tests/test_reorder_print.py @@ -0,0 +1,41 @@ + +from context import RESOURCE_PATH, call_main + +from rmsd.calculate_rmsd import get_coordinates_xyz_lines, get_coordinates_xyz +from rmsd.calculate_rmsd import rmsd as get_rmsd + + +def test_reorder_print_and_rmsd(): + + # TODO Calculate rmsd with --reorder (structure a and b) + # TODO Calculate --print and --reorder to structure c.xyz + # TODO Calculate normal rmsd a.xyz and c.xyz + + filename_a = RESOURCE_PATH / "issue93" / "a.xyz" + filename_b = RESOURCE_PATH / "issue93" / "b.xyz" + + # Get reorder rmsd + args = ["--reorder", f"{filename_a}", f"{filename_b}"] + stdout = call_main(args) + rmsd_ab = float(stdout[-1]) + print(rmsd_ab) + + # Get printed structure + stdout = call_main(args + ["--print"]) + + atoms_a, coord_a = get_coordinates_xyz(filename_a) + atoms_c, coord_c = get_coordinates_xyz_lines(stdout) + + print(coord_a) + print(atoms_a) + + print(coord_c) + print(atoms_c) + + rmsd_ac = get_rmsd(coord_a, coord_c) + print(rmsd_ac) + + assert rmsd_ac == rmsd_ab + + assert False + From b13b991258ea0b21f4dcea803f333b4ba3c57634 Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Fri, 16 Dec 2022 17:06:33 +0100 Subject: [PATCH 03/10] Bug found --- tests/test_reorder_print.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test_reorder_print.py b/tests/test_reorder_print.py index de80ffe..9dedf6c 100644 --- a/tests/test_reorder_print.py +++ b/tests/test_reorder_print.py @@ -7,9 +7,10 @@ def test_reorder_print_and_rmsd(): - # TODO Calculate rmsd with --reorder (structure a and b) - # TODO Calculate --print and --reorder to structure c.xyz - # TODO Calculate normal rmsd a.xyz and c.xyz + # Issue 93, problem with printed structure after reorder. + # - Calculate rmsd with --reorder (structure a and b) + # - Calculate --print and --reorder to structure c.xyz + # - Calculate normal rmsd a.xyz and c.xyz filename_a = RESOURCE_PATH / "issue93" / "a.xyz" filename_b = RESOURCE_PATH / "issue93" / "b.xyz" @@ -36,6 +37,3 @@ def test_reorder_print_and_rmsd(): print(rmsd_ac) assert rmsd_ac == rmsd_ab - - assert False - From 6c7a06658b10d4bfa0098161f3207102067a7cdd Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Tue, 20 Dec 2022 16:54:23 +0100 Subject: [PATCH 04/10] add type, remove comments, fix np test --- rmsd/calculate_rmsd.py | 7 ------- tests/test_reorder_print.py | 8 ++++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/rmsd/calculate_rmsd.py b/rmsd/calculate_rmsd.py index 8adee2d..f2ae13c 100644 --- a/rmsd/calculate_rmsd.py +++ b/rmsd/calculate_rmsd.py @@ -2029,11 +2029,6 @@ def main(args: Optional[List[str]] = None) -> None: # print result if settings.output: - # print(q_coord) - # print(q_swap) - # print(q_reflection) - # print(q_review) - if q_swap is not None: q_coord = q_coord[:, q_swap] @@ -2057,8 +2052,6 @@ def main(args: Optional[List[str]] = None) -> None: xyz = set_coordinates(q_all_atoms, q_coord, title=f"{settings.structure_b} - modified") print(xyz) - # print(kabsch_rmsd(q_coord, p_coord, translate=True)) - # assert False else: if not result_rmsd: diff --git a/tests/test_reorder_print.py b/tests/test_reorder_print.py index 9dedf6c..a4a9fdb 100644 --- a/tests/test_reorder_print.py +++ b/tests/test_reorder_print.py @@ -1,11 +1,11 @@ - +import numpy as np from context import RESOURCE_PATH, call_main -from rmsd.calculate_rmsd import get_coordinates_xyz_lines, get_coordinates_xyz +from rmsd.calculate_rmsd import get_coordinates_xyz, get_coordinates_xyz_lines from rmsd.calculate_rmsd import rmsd as get_rmsd -def test_reorder_print_and_rmsd(): +def test_reorder_print_and_rmsd() -> None: # Issue 93, problem with printed structure after reorder. # - Calculate rmsd with --reorder (structure a and b) @@ -36,4 +36,4 @@ def test_reorder_print_and_rmsd(): rmsd_ac = get_rmsd(coord_a, coord_c) print(rmsd_ac) - assert rmsd_ac == rmsd_ab + np.testing.assert_almost_equal(rmsd_ab, rmsd_ac, decimal=8) From 5c812ba7cc18411565147871bb042dffc329ebbe Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Tue, 20 Dec 2022 17:11:49 +0100 Subject: [PATCH 05/10] Fixed rmsd naming convention consistency --- rmsd/__init__.py | 43 ++++++++++++++++++++++------------- tests/test_centroid.py | 4 ++-- tests/test_file_reading.py | 30 ++++++++++++------------ tests/test_kabsch.py | 20 ++++++++-------- tests/test_kabsch_weighted.py | 14 ++++++------ tests/test_main.py | 28 ++++------------------- tests/test_quaternion.py | 25 ++++++++++---------- tests/test_reflections.py | 36 ++++++++++++++--------------- tests/test_reorder.py | 22 +++++++++--------- tests/test_reorder_inertia.py | 12 +++++----- tests/test_reorder_print.py | 6 ++--- tests/test_reorder_qml.py | 18 +++++++-------- 12 files changed, 123 insertions(+), 135 deletions(-) diff --git a/rmsd/__init__.py b/rmsd/__init__.py index f296242..9721f35 100644 --- a/rmsd/__init__.py +++ b/rmsd/__init__.py @@ -1,34 +1,45 @@ # flake8: noqa -from . import calculate_rmsd from .calculate_rmsd import * from .calculate_rmsd import __doc__, __version__ __all__ = [ - "brute_permutation", - "centroid", - "check_reflections", - "generate_permutations", - "get_coordinates", - "get_coordinates_pdb", - "get_coordinates_xyz", - "hungarian", + "str_atom", "int_atom", - "kabsch", + "rmsd", "kabsch_rmsd", "kabsch_rotate", "kabsch_fit", + "kabsch", + "kabsch_weighted", + "kabsch_weighted_fit", + "kabsch_weighted_rmsd", "quaternion_rmsd", - "quaternion_rotate", "quaternion_transform", - "reorder_brute", + "makeW", + "makeQ", + "quaternion_rotate", + "centroid", + "hungarian_vectors", + "reorder_similarity", "reorder_distance", + "hungarian", "reorder_hungarian", "reorder_inertia_hungarian", - "reorder_similarity", - "rmsd", + "generate_permutations", + "brute_permutation", + "reorder_brute", + "check_reflections", + "rotation_matrix_vectors", + "get_cm", + "get_inertia_tensor", + "get_principal_axis", "set_coordinates", - "str_atom", + "get_coordinates", + "get_coordinates_pdb", + "get_coordinates_xyz_lines", + "get_coordinates_xyz", + "main", ] if __name__ == "__main__": - calculate_rmsd.main() # pragma: no cover + main() # pragma: no cover diff --git a/tests/test_centroid.py b/tests/test_centroid.py index 925f3aa..8243573 100644 --- a/tests/test_centroid.py +++ b/tests/test_centroid.py @@ -1,6 +1,6 @@ import numpy as np -import rmsd +import rmsd as rmsdlib def test_centroid() -> None: @@ -9,7 +9,7 @@ def test_centroid() -> None: a3 = np.array([-22.018, 17.551, 26.0], dtype=float) atms = np.asarray([a1, a2, a3]) - centroid = rmsd.centroid(atms) + centroid = rmsdlib.centroid(atms) assert 3 == len(centroid) diff --git a/tests/test_file_reading.py b/tests/test_file_reading.py index 2c2a4cd..da20aaa 100644 --- a/tests/test_file_reading.py +++ b/tests/test_file_reading.py @@ -5,13 +5,13 @@ import pytest from context import RESOURCE_PATH -import rmsd +import rmsd as rmsdlib def test_get_coordinates_pdb_hetatm() -> None: filename = Path(RESOURCE_PATH) / "issue88" / "native.pdb" - atoms, _ = rmsd.get_coordinates_pdb(filename) + atoms, _ = rmsdlib.get_coordinates_pdb(filename) assert len(atoms) assert atoms[0] == "C" @@ -21,7 +21,7 @@ def test_get_coordinates_pdb_hetatm() -> None: def test_get_coordinates_pdb() -> None: filename = RESOURCE_PATH / "ci2_1.pdb" - atoms, coords = rmsd.get_coordinates_pdb(filename) + atoms, coords = rmsdlib.get_coordinates_pdb(filename) assert "N" == atoms[0] assert [-7.173, -13.891, -6.266] == coords[0].tolist() @@ -29,13 +29,13 @@ def test_get_coordinates_pdb() -> None: def test_get_coordinates_wrong() -> None: filename = RESOURCE_PATH / "ci2_1.pdb" with pytest.raises(ValueError): - _, _ = rmsd.get_coordinates(filename, "qqq") + _, _ = rmsdlib.get_coordinates(filename, "qqq") def test_get_coordinates_xyz() -> None: filename = RESOURCE_PATH / "ethane.xyz" - atoms, coords = rmsd.get_coordinates_xyz(filename) + atoms, coords = rmsdlib.get_coordinates_xyz(filename) assert "C" == atoms[0] assert [-0.98353, 1.81095, -0.0314] == coords[0].tolist() @@ -43,13 +43,13 @@ def test_get_coordinates_xyz() -> None: def test_get_coordinates_xyz_bad() -> None: filename = RESOURCE_PATH / "bad_format.xyz" - _, _ = rmsd.get_coordinates(filename, "xyz") + _, _ = rmsdlib.get_coordinates(filename, "xyz") def test_get_coordinates() -> None: filename = RESOURCE_PATH / "ethane.xyz" - atoms, coords = rmsd.get_coordinates(filename, "xyz") + atoms, coords = rmsdlib.get_coordinates(filename, "xyz") assert "C" == atoms[0] assert [-0.98353, 1.81095, -0.0314] == coords[0].tolist() @@ -68,7 +68,7 @@ def test_get_coordinates_gzip(tmp_path: Path) -> None: with gzip.open(filename_gzip, "wb") as f: # type: ignore f.write(content_byte) # type: ignore - atoms, coords = rmsd.get_coordinates( + atoms, coords = rmsdlib.get_coordinates( filename_gzip, "pdb", is_gzip=True, return_atoms_as_int=True ) assert 7 == atoms[0] @@ -88,7 +88,7 @@ def test_get_coordinates_gzip_pdb(tmp_path: Path) -> None: with gzip.open(filename_gzip, "wb") as f: # type: ignore f.write(content_byte) # type: ignore - atoms, coords = rmsd.get_coordinates(filename_gzip, "xyz", is_gzip=True) + atoms, coords = rmsdlib.get_coordinates(filename_gzip, "xyz", is_gzip=True) assert "C" == atoms[0] assert [-0.98353, 1.81095, -0.0314] == coords[0].tolist() @@ -99,10 +99,10 @@ def test_rmsd_pdb() -> None: filename_1 = RESOURCE_PATH / "ci2_1.pdb" filename_2 = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_1) - _, q_coord = rmsd.get_coordinates_pdb(filename_2) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_1) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_2) - pure_rmsd = rmsd.rmsd(p_coord, q_coord) + pure_rmsd = rmsdlib.rmsd(p_coord, q_coord) np.testing.assert_almost_equal(26.9750, pure_rmsd, decimal=3) @@ -112,9 +112,9 @@ def test_rmsd_xyz() -> None: filename_1 = RESOURCE_PATH / "ethane.xyz" filename_2 = RESOURCE_PATH / "ethane_mini.xyz" - _, p_coord = rmsd.get_coordinates_xyz(filename_1) - _, q_coord = rmsd.get_coordinates_xyz(filename_2) + _, p_coord = rmsdlib.get_coordinates_xyz(filename_1) + _, q_coord = rmsdlib.get_coordinates_xyz(filename_2) - pure_rmsd = rmsd.rmsd(p_coord, q_coord) + pure_rmsd = rmsdlib.rmsd(p_coord, q_coord) np.testing.assert_almost_equal(0.33512, pure_rmsd, decimal=3) diff --git a/tests/test_kabsch.py b/tests/test_kabsch.py index bbf11ad..8640927 100644 --- a/tests/test_kabsch.py +++ b/tests/test_kabsch.py @@ -1,7 +1,7 @@ import numpy as np from context import RESOURCE_PATH -import rmsd +import rmsd as rmsdlib def test_kabash_algorith_rmsd() -> None: @@ -9,10 +9,10 @@ def test_kabash_algorith_rmsd() -> None: filename_1 = RESOURCE_PATH / "ci2_1.pdb" filename_2 = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates(filename_1, "pdb") - _, q_coord = rmsd.get_coordinates(filename_2, "pdb") + _, p_coord = rmsdlib.get_coordinates(filename_1, "pdb") + _, q_coord = rmsdlib.get_coordinates(filename_2, "pdb") - value = rmsd.kabsch_rmsd(p_coord, q_coord, translate=True) + value = rmsdlib.kabsch_rmsd(p_coord, q_coord, translate=True) np.testing.assert_almost_equal(value, 11.7768, decimal=4) @@ -22,10 +22,10 @@ def test_kabash_algorith_pdb() -> None: filename_1 = RESOURCE_PATH / "ci2_1.pdb" filename_2 = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_1) - _, q_coord = rmsd.get_coordinates_pdb(filename_2) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_1) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_2) - rotation_matrix = rmsd.kabsch(p_coord, q_coord) + rotation_matrix = rmsdlib.kabsch(p_coord, q_coord) np.testing.assert_array_almost_equal([-0.5124, 0.8565, 0.0608], rotation_matrix[0], decimal=3) @@ -35,9 +35,9 @@ def test_kabash_rotate_pdb() -> None: filename_1 = RESOURCE_PATH / "ci2_1.pdb" filename_2 = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_1) - _, q_coord = rmsd.get_coordinates_pdb(filename_2) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_1) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_2) - new_p_coord = rmsd.kabsch_rotate(p_coord, q_coord) + new_p_coord = rmsdlib.kabsch_rotate(p_coord, q_coord) np.testing.assert_array_almost_equal([10.6822, -2.8867, 12.6977], new_p_coord[0], decimal=3) diff --git a/tests/test_kabsch_weighted.py b/tests/test_kabsch_weighted.py index a022eb2..05ad144 100644 --- a/tests/test_kabsch_weighted.py +++ b/tests/test_kabsch_weighted.py @@ -1,7 +1,7 @@ import numpy as np from context import RESOURCE_PATH -import rmsd +import rmsd as rmsdlib def test_kabash_fit_pdb() -> None: @@ -9,10 +9,10 @@ def test_kabash_fit_pdb() -> None: filename_p = RESOURCE_PATH / "ci2_1r+t.pdb" filename_q = RESOURCE_PATH / "ci2_1.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_p) - _, q_coord = rmsd.get_coordinates_pdb(filename_q) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_p) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_q) - new_p_coord = rmsd.kabsch_fit(p_coord, q_coord) + new_p_coord = rmsdlib.kabsch_fit(p_coord, q_coord) np.testing.assert_array_almost_equal(q_coord[0], new_p_coord[0], decimal=2) @@ -22,8 +22,8 @@ def test_kabash_weighted_fit_pdb() -> None: filename_1 = RESOURCE_PATH / "ci2_12.pdb" filename_2 = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_1) - _, q_coord = rmsd.get_coordinates_pdb(filename_2) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_1) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_2) weights = np.zeros(len(p_coord)) residue13_start = 200 @@ -31,6 +31,6 @@ def test_kabash_weighted_fit_pdb() -> None: weights[residue13_start:residue24_start] = 1.0 - new_p_coord = rmsd.kabsch_fit(p_coord, q_coord, weights) + new_p_coord = rmsdlib.kabsch_fit(p_coord, q_coord, weights) np.testing.assert_array_almost_equal(q_coord[300], new_p_coord[300], decimal=2) diff --git a/tests/test_main.py b/tests/test_main.py index 7fede1d..c639214 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,33 +1,13 @@ import copy -import subprocess -from pathlib import Path -from typing import List import numpy as np import pytest -from context import RESOURCE_PATH +from context import RESOURCE_PATH, call_main import rmsd as rmsdlib -def _call_main(args: List[str]) -> str: - - root_path = Path("./") - filename = root_path / "rmsd/calculate_rmsd.py" - - cmd = ["python", f"{filename}", *args] - print(cmd) - - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - stdout, stderr = proc.communicate() - - if stderr is not None: - print(stderr.decode()) - - return stdout.decode().strip() - - -def test_print_reflection_reorder(): +def test_print_reflection_reorder() -> None: # Test issue 78 filename_a = RESOURCE_PATH / "issue78" / "a.xyz" @@ -71,14 +51,14 @@ def test_print_reflection_reorder(): # Main call rmsd value args = f"--use-reflections --reorder {filename_a} {filename_b}" - stdout = _call_main(args.split()).split("\n") + stdout = call_main(args.split()) value = float(stdout[-1]) assert value is not None np.testing.assert_almost_equal(result_rmsd, value) # Main call print, check rmsd is still the same args = f"--use-reflections --reorder --print {filename_a} {filename_b}" - stdout = _call_main(args.split()).split("\n") + stdout = call_main(args.split()) _, coord = rmsdlib.get_coordinates_xyz_lines(stdout[-(n_atoms + 2) :]) rmsd_check = rmsdlib.kabsch_rmsd(coord, coord_a, translate=True) np.testing.assert_almost_equal(result_rmsd, rmsd_check) diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index f5622fe..a9d8f25 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -1,8 +1,7 @@ import numpy as np from context import RESOURCE_PATH -import rmsd -from rmsd import calculate_rmsd +import rmsd as rmsdlib def test_quaternion_rmsd_pdb() -> None: @@ -10,15 +9,15 @@ def test_quaternion_rmsd_pdb() -> None: filename_p = RESOURCE_PATH / "ci2_1.pdb" filename_q = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_p) - _, q_coord = rmsd.get_coordinates_pdb(filename_q) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_p) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_q) - p_center = rmsd.centroid(p_coord) - q_center = rmsd.centroid(q_coord) + p_center = rmsdlib.centroid(p_coord) + q_center = rmsdlib.centroid(q_coord) p_coord -= p_center q_coord -= q_center - result = rmsd.quaternion_rmsd(p_coord, q_coord) + result = rmsdlib.quaternion_rmsd(p_coord, q_coord) np.testing.assert_almost_equal(11.7768, result, decimal=3) @@ -28,10 +27,10 @@ def test_quaternion_rotate_pdb() -> None: filename_p = RESOURCE_PATH / "ci2_1.pdb" filename_q = RESOURCE_PATH / "ci2_2.pdb" - _, p_coord = rmsd.get_coordinates_pdb(filename_p) - _, q_coord = rmsd.get_coordinates_pdb(filename_q) + _, p_coord = rmsdlib.get_coordinates_pdb(filename_p) + _, q_coord = rmsdlib.get_coordinates_pdb(filename_q) - new_p_coord = rmsd.quaternion_rotate(p_coord, q_coord) + new_p_coord = rmsdlib.quaternion_rotate(p_coord, q_coord) np.testing.assert_array_almost_equal([-0.5124, 0.8565, 0.0608], new_p_coord[0], decimal=3) @@ -39,7 +38,7 @@ def test_quaternion_rotate_pdb() -> None: def test_quaternion_transform() -> None: r = np.array([-0.31019, -0.59291, 0.63612, -0.38415]) - U = rmsd.quaternion_transform(r) + U = rmsdlib.quaternion_transform(r) np.testing.assert_array_almost_equal([-0.5124, 0.8565, 0.0608], U[0], decimal=3) @@ -47,13 +46,13 @@ def test_quaternion_transform() -> None: def test_makeQ() -> None: r = [-0.31019, -0.59291, 0.63612, -0.38415] - Q_r = calculate_rmsd.makeQ(*r) + Q_r = rmsdlib.makeQ(*r) np.testing.assert_array_almost_equal([-0.3841, -0.6361, -0.5929, -0.3101], Q_r[0], decimal=3) def test_makeW() -> None: r = [-0.31019, -0.59291, 0.63612, -0.38415] - Wt_r = calculate_rmsd.makeW(*r) + Wt_r = rmsdlib.makeW(*r) np.testing.assert_array_almost_equal([-0.3841, 0.6361, 0.5929, -0.3101], Wt_r[0], decimal=3) diff --git a/tests/test_reflections.py b/tests/test_reflections.py index f6eda67..aafdc66 100644 --- a/tests/test_reflections.py +++ b/tests/test_reflections.py @@ -3,7 +3,7 @@ import numpy as np from context import RESOURCE_PATH -import rmsd +import rmsd as rmsdlib def test_reflections() -> None: @@ -26,7 +26,9 @@ def test_reflections() -> None: # TODO Insert a rotation on q q_coord[:, [0, 2]] = q_coord[:, [2, 0]] - min_rmsd, _, _, _ = rmsd.check_reflections(atoms, atoms, p_coord, q_coord, reorder_method=None) + min_rmsd, _, _, _ = rmsdlib.check_reflections( + atoms, atoms, p_coord, q_coord, reorder_method=None + ) assert np.isclose(min_rmsd, 0.0, atol=1e-6) @@ -50,7 +52,7 @@ def test_reflections_norotation() -> None: # Insert reflection q_coord[:, [0, 2]] = q_coord[:, [2, 0]] - min_rmsd, _, _, _ = rmsd.check_reflections( + min_rmsd, _, _, _ = rmsdlib.check_reflections( atoms, atoms, p_coord, @@ -85,8 +87,8 @@ def test_reflections_reorder() -> None: q_coord = q_coord[review] q_atoms = p_atoms[review] - min_rmsd, _, _, _ = rmsd.check_reflections( - p_atoms, q_atoms, p_coord, q_coord, reorder_method=rmsd.reorder_hungarian + min_rmsd, _, _, _ = rmsdlib.check_reflections( + p_atoms, q_atoms, p_coord, q_coord, reorder_method=rmsdlib.reorder_hungarian ) assert np.isclose(min_rmsd, 0.0, atol=1e-6) @@ -114,7 +116,7 @@ def test_reflections_keep_stereo() -> None: # If keep_stereo is off, enantiomer coordinates of q_coord are considered, # resulting into identical coordinates of p_coord. - min_rmsd, _, _, _ = rmsd.check_reflections( + min_rmsd, _, _, _ = rmsdlib.check_reflections( atoms, atoms, p_coord, q_coord, reorder_method=None, keep_stereo=False ) @@ -122,8 +124,8 @@ def test_reflections_keep_stereo() -> None: # with the original molecule. assert np.isclose(min_rmsd, 0.0, atol=1e-6) - # No enantiomer coordinates, non-zero RMSD. - min_rmsd, _, _, _ = rmsd.check_reflections( + # No enantiomer coordinates, non-zero rmsdlib. + min_rmsd, _, _, _ = rmsdlib.check_reflections( atoms, atoms, p_coord, q_coord, reorder_method=None, keep_stereo=True ) @@ -143,33 +145,29 @@ def test_reflection_issue_78(): """ - # TODO Check print consistency - - print(rmsd, __file__) - xyz_a = RESOURCE_PATH / "ethane-1-2-diolate_a.xyz" xyz_b = RESOURCE_PATH / "ethane-1-2-diolate_b.xyz" - atoms_a, coordinates_a = rmsd.get_coordinates_xyz(xyz_a) - atoms_b, coordinates_b = rmsd.get_coordinates_xyz(xyz_b) + atoms_a, coordinates_a = rmsdlib.get_coordinates_xyz(xyz_a) + atoms_b, coordinates_b = rmsdlib.get_coordinates_xyz(xyz_b) - coordinates_a -= rmsd.centroid(coordinates_a) - coordinates_b -= rmsd.centroid(coordinates_b) + coordinates_a -= rmsdlib.centroid(coordinates_a) + coordinates_b -= rmsdlib.centroid(coordinates_b) reorder_method = None - rmsd_method = rmsd.kabsch_rmsd + rmsd_method = rmsdlib.kabsch_rmsd print(np.sum(coordinates_a)) print(np.sum(coordinates_b)) - result_rmsd = rmsd.kabsch_rmsd( + result_rmsd = rmsdlib.kabsch_rmsd( coordinates_a, coordinates_b, ) print(result_rmsd) - result_rmsd, _, _, q_review = rmsd.check_reflections( + result_rmsd, _, _, q_review = rmsdlib.check_reflections( atoms_a, atoms_b, coordinates_a, diff --git a/tests/test_reorder.py b/tests/test_reorder.py index bc6f769..44c548e 100644 --- a/tests/test_reorder.py +++ b/tests/test_reorder.py @@ -2,7 +2,7 @@ import numpy as np -import rmsd +import rmsd as rmsdlib def test_reorder_distance() -> None: @@ -16,7 +16,7 @@ def test_reorder_distance() -> None: np.random.seed(6) np.random.shuffle(q_coord) - review = rmsd.reorder_hungarian(atoms, atoms, p_coord, q_coord) + review = rmsdlib.reorder_hungarian(atoms, atoms, p_coord, q_coord) assert p_coord.tolist() == q_coord[review].tolist() @@ -31,7 +31,7 @@ def test_reorder_brute() -> None: np.random.seed(6) np.random.shuffle(q_coord) - review = rmsd.reorder_brute(atoms, atoms, p_coord, q_coord) + review = rmsdlib.reorder_brute(atoms, atoms, p_coord, q_coord) assert p_coord.tolist() == q_coord[review].tolist() @@ -39,7 +39,7 @@ def test_reorder_brute_ch() -> None: N = 6 p_atoms_str = ["C"] * 3 + ["H"] * 3 - p_atoms_int = [rmsd.int_atom(atom) for atom in p_atoms_str] + p_atoms_int = [rmsdlib.int_atom(atom) for atom in p_atoms_str] p_atoms = np.array(p_atoms_int) p_coord = np.arange(N * 3) p_coord = p_coord.reshape((N, 3)) @@ -55,7 +55,7 @@ def test_reorder_brute_ch() -> None: q_coord = q_coord[idx] q_atoms = q_atoms[idx] - review = rmsd.reorder_brute(p_atoms, q_atoms, p_coord, q_coord) + review = rmsdlib.reorder_brute(p_atoms, q_atoms, p_coord, q_coord) assert p_coord.tolist() == q_coord[review].tolist() assert p_atoms.tolist() == q_atoms[review].tolist() @@ -72,7 +72,7 @@ def test_reorder_hungarian() -> None: np.random.seed(6) np.random.shuffle(q_coord) - review = rmsd.reorder_distance(atoms, atoms, p_coord, q_coord) + review = rmsdlib.reorder_distance(atoms, atoms, p_coord, q_coord) assert p_coord.tolist() == q_coord[review].tolist() @@ -80,7 +80,7 @@ def test_reorder_inertia_hungarian() -> None: # coordinates of scrambled and rotated butane atoms = np.array(["C", "C", "C", "C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"]) - atoms_ = [rmsd.int_atom(atom) for atom in atoms] + atoms_ = [rmsdlib.int_atom(atom) for atom in atoms] atoms = np.array(atoms_) p_coord = np.array( @@ -121,11 +121,11 @@ def test_reorder_inertia_hungarian() -> None: ] ) - p_coord -= rmsd.centroid(p_coord) - q_coord -= rmsd.centroid(q_coord) + p_coord -= rmsdlib.centroid(p_coord) + q_coord -= rmsdlib.centroid(q_coord) - review = rmsd.reorder_inertia_hungarian(atoms, atoms, p_coord, q_coord) + review = rmsdlib.reorder_inertia_hungarian(atoms, atoms, p_coord, q_coord) - result_rmsd = rmsd.kabsch_rmsd(p_coord, q_coord[review]) + result_rmsd = rmsdlib.kabsch_rmsd(p_coord, q_coord[review]) np.testing.assert_almost_equal(0, result_rmsd, decimal=2) diff --git a/tests/test_reorder_inertia.py b/tests/test_reorder_inertia.py index a136f55..1b2e946 100644 --- a/tests/test_reorder_inertia.py +++ b/tests/test_reorder_inertia.py @@ -1,13 +1,13 @@ import numpy as np -import rmsd +import rmsd as rmsdlib def test_reorder_inertia_hungarian() -> None: # coordinates of scrambled and rotated butane atoms = np.array(["C", "C", "C", "C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"]) - atoms_ = [rmsd.int_atom(atom) for atom in atoms] + atoms_ = [rmsdlib.int_atom(atom) for atom in atoms] atoms = np.array(atoms_) p_coord = np.array( @@ -48,10 +48,10 @@ def test_reorder_inertia_hungarian() -> None: ] ) - p_coord -= rmsd.centroid(p_coord) - q_coord -= rmsd.centroid(q_coord) + p_coord -= rmsdlib.centroid(p_coord) + q_coord -= rmsdlib.centroid(q_coord) - review = rmsd.reorder_inertia_hungarian(atoms, atoms, p_coord, q_coord) - result_rmsd = rmsd.kabsch_rmsd(p_coord, q_coord[review]) + review = rmsdlib.reorder_inertia_hungarian(atoms, atoms, p_coord, q_coord) + result_rmsd = rmsdlib.kabsch_rmsd(p_coord, q_coord[review]) np.testing.assert_almost_equal(0, result_rmsd, decimal=2) diff --git a/tests/test_reorder_print.py b/tests/test_reorder_print.py index a4a9fdb..6002292 100644 --- a/tests/test_reorder_print.py +++ b/tests/test_reorder_print.py @@ -1,8 +1,8 @@ import numpy as np from context import RESOURCE_PATH, call_main -from rmsd.calculate_rmsd import get_coordinates_xyz, get_coordinates_xyz_lines -from rmsd.calculate_rmsd import rmsd as get_rmsd +import rmsd as rmsdlib +from rmsd import get_coordinates_xyz, get_coordinates_xyz_lines def test_reorder_print_and_rmsd() -> None: @@ -33,7 +33,7 @@ def test_reorder_print_and_rmsd() -> None: print(coord_c) print(atoms_c) - rmsd_ac = get_rmsd(coord_a, coord_c) + rmsd_ac = rmsdlib.rmsd(coord_a, coord_c) print(rmsd_ac) np.testing.assert_almost_equal(rmsd_ab, rmsd_ac, decimal=8) diff --git a/tests/test_reorder_qml.py b/tests/test_reorder_qml.py index 6e7eb53..bafb80d 100644 --- a/tests/test_reorder_qml.py +++ b/tests/test_reorder_qml.py @@ -4,7 +4,7 @@ import pytest from context import RESOURCE_PATH -import rmsd +import rmsd as rmsdlib qml = pytest.importorskip("qml") @@ -13,7 +13,7 @@ def test_reorder_qml() -> None: filename_1 = RESOURCE_PATH / "CHEMBL3039407.xyz" - p_atoms, p_coord = rmsd.get_coordinates_xyz(filename_1, return_atoms_as_int=True) + p_atoms, p_coord = rmsdlib.get_coordinates_xyz(filename_1, return_atoms_as_int=True) # Reorder atoms n_atoms = len(p_atoms) @@ -40,20 +40,20 @@ def test_reorder_qml() -> None: # Reorder with standard hungarian, this will fail reorder and give large # RMSD - view_dist = rmsd.reorder_hungarian(p_atoms, q_atoms, p_coord, q_coord) + view_dist = rmsdlib.reorder_hungarian(p_atoms, q_atoms, p_coord, q_coord) q_atoms_dist = q_atoms[view_dist] q_coord_dist = q_coord[view_dist] - _rmsd_dist = rmsd.kabsch_rmsd(p_coord, q_coord_dist) + _rmsd_dist = rmsdlib.kabsch_rmsd(p_coord, q_coord_dist) assert q_atoms_dist.tolist() == p_atoms.tolist() assert _rmsd_dist > 3.0 # Reorder based in chemical similarity - view = rmsd.reorder_similarity(p_atoms, q_atoms, p_coord, q_coord) + view = rmsdlib.reorder_similarity(p_atoms, q_atoms, p_coord, q_coord) q_atoms = q_atoms[view] q_coord = q_coord[view] # Calculate new RMSD with correct atom order - _rmsd = rmsd.kabsch_rmsd(p_coord, q_coord) + _rmsd = rmsdlib.kabsch_rmsd(p_coord, q_coord) # Assert correct atom order assert q_atoms.tolist() == p_atoms.tolist() @@ -66,7 +66,7 @@ def test_reorder_qml_distmat() -> None: filename_1 = RESOURCE_PATH / "CHEMBL3039407.xyz" - p_atoms, p_coord = rmsd.get_coordinates_xyz(filename_1, return_atoms_as_int=True) + p_atoms, p_coord = rmsdlib.get_coordinates_xyz(filename_1, return_atoms_as_int=True) # Reorder atoms n_atoms = len(p_atoms) @@ -92,12 +92,12 @@ def test_reorder_qml_distmat() -> None: q_coord = np.dot(q_coord, rotation_y) # Reorder based in chemical similarity - view = rmsd.reorder_similarity(p_atoms, q_atoms, p_coord, q_coord, use_kernel=False) + view = rmsdlib.reorder_similarity(p_atoms, q_atoms, p_coord, q_coord, use_kernel=False) q_atoms = q_atoms[view] q_coord = q_coord[view] # Calculate new RMSD with correct atom order - _rmsd = rmsd.kabsch_rmsd(p_coord, q_coord) + _rmsd = rmsdlib.kabsch_rmsd(p_coord, q_coord) # Assert correct atom order assert q_atoms.tolist() == p_atoms.tolist() From 59a5616df80ff2db946b1de042d70d4eb1f42565 Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Tue, 20 Dec 2022 17:13:47 +0100 Subject: [PATCH 06/10] Format --- tests/context.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/context.py b/tests/context.py index fff703d..0137514 100644 --- a/tests/context.py +++ b/tests/context.py @@ -1,8 +1,9 @@ -from pathlib import Path import subprocess +from pathlib import Path RESOURCE_PATH = Path("tests/resources") + def call_main(args: list[str]) -> list[str]: root_path = Path("./") From 3696d4dcb68f91b5f72acb6d9619779d63b5c201 Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Tue, 20 Dec 2022 17:14:40 +0100 Subject: [PATCH 07/10] Backward compatibility --- tests/context.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/context.py b/tests/context.py index 0137514..6f6ccea 100644 --- a/tests/context.py +++ b/tests/context.py @@ -1,10 +1,11 @@ import subprocess from pathlib import Path +from typing import List RESOURCE_PATH = Path("tests/resources") -def call_main(args: list[str]) -> list[str]: +def call_main(args: List[str]) -> List[str]: root_path = Path("./") filename = root_path / "rmsd/calculate_rmsd.py" From 31537d20b58aa103f55c45c18c2971bbacaed1c3 Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Tue, 20 Dec 2022 17:18:55 +0100 Subject: [PATCH 08/10] Added qml installer to makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index e80aecd..aa2bdb3 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ env: conda env create -f ./environment.yml -p ./env --quiet ./env/bin/python -m pip install -e . +env-qml: + ./env/bin/pip install git+https://github.com/qmlcode/qml@develop + test: python -m pytest -vrs tests From 34c2e9a7ae6367384bf638a19ed615d097ca3ae3 Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Thu, 22 Dec 2022 15:50:25 +0100 Subject: [PATCH 09/10] Fixed reorder inconsistency --- rmsd/calculate_rmsd.py | 12 ++++++------ tests/test_main.py | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/rmsd/calculate_rmsd.py b/rmsd/calculate_rmsd.py index f2ae13c..ccc453b 100644 --- a/rmsd/calculate_rmsd.py +++ b/rmsd/calculate_rmsd.py @@ -2017,10 +2017,14 @@ def main(args: Optional[List[str]] = None) -> None: elif settings.reorder: assert reorder_method is not None, "Cannot reorder without selecting --reorder method" - q_review = reorder_method(p_atoms, q_atoms, p_coord, q_coord) - q_coord = q_coord[q_review] + + # If there is a reorder, then apply before print + if q_review is not None: + + q_all_atoms = q_all_atoms[q_review] q_atoms = q_atoms[q_review] + q_coord = q_coord[q_review] assert all( p_atoms == q_atoms @@ -2037,10 +2041,6 @@ def main(args: Optional[List[str]] = None) -> None: q_coord -= centroid(q_coord) - if q_review is not None: - q_coord = q_coord[q_review] - q_all_atoms = q_all_atoms[q_review] - # Rotate q coordinates # TODO Should actually follow rotation method q_coord = kabsch_rotate(q_coord, p_coord) diff --git a/tests/test_main.py b/tests/test_main.py index c639214..87f8095 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -17,8 +17,7 @@ def test_print_reflection_reorder() -> None: atoms_a, coord_a = rmsdlib.get_coordinates_xyz(filename_a, return_atoms_as_int=True) atoms_b, coord_b = rmsdlib.get_coordinates_xyz(filename_b, return_atoms_as_int=True) - n_atoms = len(atoms_a) - + # re-center molecules coord_a -= rmsdlib.centroid(coord_a) coord_b -= rmsdlib.centroid(coord_b) @@ -39,7 +38,7 @@ def test_print_reflection_reorder() -> None: print(q_reflection) print(q_review) - # tmp_atoms = copy.copy(atoms_b) + # Apply the swap, reflection and review tmp_coord = copy.deepcopy(coord_b) tmp_coord = tmp_coord[:, q_swap] tmp_coord = np.dot(tmp_coord, np.diag(q_reflection)) @@ -48,20 +47,30 @@ def test_print_reflection_reorder() -> None: tmp_coord = rmsdlib.kabsch_rotate(tmp_coord, coord_a) rmsd_ = rmsdlib.rmsd(coord_a, tmp_coord) print(rmsd_) + print(tmp_coord) # Main call rmsd value args = f"--use-reflections --reorder {filename_a} {filename_b}" stdout = call_main(args.split()) value = float(stdout[-1]) + print(value) assert value is not None np.testing.assert_almost_equal(result_rmsd, value) # Main call print, check rmsd is still the same + # Note, that --print is translating b to a center args = f"--use-reflections --reorder --print {filename_a} {filename_b}" stdout = call_main(args.split()) - _, coord = rmsdlib.get_coordinates_xyz_lines(stdout[-(n_atoms + 2) :]) - rmsd_check = rmsdlib.kabsch_rmsd(coord, coord_a, translate=True) - np.testing.assert_almost_equal(result_rmsd, rmsd_check) + _, coord = rmsdlib.get_coordinates_xyz_lines(stdout) + coord -= rmsdlib.centroid(coord) # fix translation + print(coord) + + rmsd_check1 = rmsdlib.kabsch_rmsd(coord, coord_a) + rmsd_check2 = rmsdlib.rmsd(coord, coord_a) + print(rmsd_check1) + print(rmsd_check2) + np.testing.assert_almost_equal(rmsd_check2, rmsd_check1) + np.testing.assert_almost_equal(rmsd_check2, result_rmsd) def test_bad_different_molcules() -> None: From d27e5c4b3dd8261752f9431d2d50e076ff389a1b Mon Sep 17 00:00:00 2001 From: Jimmy Charnley Kromann Date: Fri, 23 Dec 2022 12:02:48 +0100 Subject: [PATCH 10/10] Used github instead of gitlab --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4dcda35..9c8671b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,7 +54,7 @@ repos: args: ["--line-length=99"] - - repo: https://gitlab.com/pycqa/flake8 + - repo: https://github.com/pycqa/flake8 rev: 4.0.1 hooks: - id: flake8