diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..cac54a3 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,84 @@ +import tempfile + +import numpy as np +import pytest + +from ConservedWaterSearch.water_clustering import WaterClustering + + +@pytest.fixture() +def orientations_normalized(): + return np.asarray([[1, 0, 0], [-0.25038 * 2, 0.96814764 * 2, 0]]) + + +@pytest.fixture() +def orientations_not_normalized(): + return np.asarray([[1, 0, 0], [-0.25038, 0.96814764, 0]]) + + +@pytest.fixture( + params=[ + "tests/data/conserved_sample_FCW.dat", + "tests/data/conserved_sample_FCW2.dat", + "tests/data/dispersed_sample_HCW.dat", + "tests/data/dispersed_sample_HCW2.dat", + "tests/data/circ_sample_HCW.dat", + "tests/data/circ_sample_HCW2.dat", + "tests/data/circ_sample_HCW3.dat", + "tests/data/sample_WCW.dat", + "tests/data/sample_circular_only_WCW.dat", + "tests/data/dispersed_sample_WCW.dat", + "tests/data/2_by_2_WCW.dat", + "tests/data/dispersed_sample_not_conserved.dat", + "tests/data/not_conserved.dat", + ] +) +def water_data(request): + return np.loadtxt(request.param), request.param.split("/")[-1].split(".")[0] + + +@pytest.fixture(autouse=True) +def _pymol_skip(): + pytest.importorskip("pymol") + + +@pytest.fixture(params=[{"onlyO": False}, {"onlyO": True}]) +def water_clustering_setup(request): + wc = WaterClustering(10) + # Common setup for both cases + wc._waterO.append(np.asarray([0.0, 0.0, 0.0])) + wc._waterO.append(np.asarray([0.0, 2.0, 0.0])) + + if request.param["onlyO"]: + # Only oxygen scenario + wc._water_type.append("O_clust") + wc._water_type.append("O_clust") + else: + # Full water type clustering + wc._waterH1.append(np.asarray([1.0, 0.0, 0.0])) + wc._waterH1.append(np.asarray([0.0, 0.8, 0.5])) + wc._waterH2.append(np.asarray([2.5, 2.0, 2.8])) + wc._waterH2.append(np.asarray([0.0, 3.0, 0.0])) + wc._water_type.append("FCW") + wc._water_type.append("HCW") + + return wc, request.param["onlyO"] + + +@pytest.fixture() +def water_clustering_setup_for_deletion(): + with tempfile.NamedTemporaryFile( + mode="w+", delete=True + ) as dat, tempfile.NamedTemporaryFile(mode="w+", delete=True) as res: + wc = WaterClustering(10, output_file=res.name, restart_data_file=dat.name) + Odata = np.asarray([[0.1, 0.1, 0.1], [1.5, 1.6, 1.7], [1.9, 5.8, 5.6]]) + H1 = np.asarray([[0.8, 0.5, 0.8], [1.4, 0.6, 3.7], [3.9, 5.1, 5.9]]) + H2 = np.asarray([[0.4, 0.7, 0.1], [1.7, 3.6, 2.7], [1.8, 3.8, 5.1]]) + yield wc, dat.name, Odata, H1, H2 + + +@pytest.fixture() +def water_clustering_data(): + Opos = np.loadtxt("tests/data/testdataO.dat") + Hpos = np.loadtxt("tests/data/testdataH.dat") + return Opos, Hpos diff --git a/tests/data/CWS_input_3T73.dat b/tests/data/CWS_input_3T73.dat new file mode 100644 index 0000000..861e3cd --- /dev/null +++ b/tests/data/CWS_input_3T73.dat @@ -0,0 +1,147 @@ +3.865000152587890625e+01 2.919000244140625000e+01 4.484000396728515625e+01 5.900001525878906250e-01 3.999900817871093750e-02 -7.500000000000000000e-01 -7.799987792968750000e-01 4.799995422363281250e-01 -2.799987792968750000e-01 +3.997000122070312500e+01 2.854000091552734375e+01 4.242000198364257812e+01 -7.599983215332031250e-01 -9.998321533203125000e-03 -5.800018310546875000e-01 6.400032043457031250e-01 5.599994659423828125e-01 -4.500007629394531250e-01 +4.306000137329101562e+01 2.670000076293945312e+01 4.698000335693359375e+01 -6.399993896484375000e-01 -4.099998474121093750e-01 -5.800018310546875000e-01 -8.999633789062500000e-02 9.400005340576171875e-01 -1.800003051757812500e-01 +4.552000045776367188e+01 2.603000259399414062e+01 4.575000381469726562e+01 -8.399963378906250000e-01 9.999847412109375000e-02 4.599990844726562500e-01 -2.399978637695312500e-01 -3.500022888183593750e-01 -8.600006103515625000e-01 +4.156999969482421875e+01 3.037000274658203125e+01 4.131999969482421875e+01 7.000045776367187500e-01 5.999946594238281250e-02 6.500015258789062500e-01 3.800010681152343750e-01 -4.900016784667968750e-01 -7.199935913085937500e-01 +4.635000228881835938e+01 3.625000381469726562e+01 4.763000106811523438e+01 -6.699981689453125000e-01 -6.599998474121093750e-01 -1.799964904785156250e-01 4.000091552734375000e-02 5.299987792968750000e-01 -7.900009155273437500e-01 +4.098999786376953125e+01 2.628000068664550781e+01 4.524000167846679688e+01 -2.999954223632812500e-01 -6.299991607666015625e-01 -6.599998474121093750e-01 -7.999954223632812500e-01 2.899990081787109375e-01 4.300041198730468750e-01 +4.073000335693359375e+01 2.994000244140625000e+01 5.089000320434570312e+01 -9.100036621093750000e-01 0.000000000000000000e+00 -3.100013732910156250e-01 -1.000213623046875000e-02 5.900001525878906250e-01 7.499961853027343750e-01 +4.666000366210937500e+01 2.863000106811523438e+01 4.624000167846679688e+01 -1.700019836425781250e-01 4.500007629394531250e-01 8.300018310546875000e-01 -2.200012207031250000e-01 -9.099998474121093750e-01 1.700019836425781250e-01 +4.503000259399414062e+01 3.380000305175781250e+01 4.958000183105468750e+01 -3.100013732910156250e-01 3.099975585937500000e-01 -8.499984741210937500e-01 -1.800003051757812500e-01 7.199974060058593750e-01 5.999984741210937500e-01 +4.235000228881835938e+01 2.923999977111816406e+01 4.672000503540039062e+01 -9.200019836425781250e-01 -1.599979400634765625e-01 1.899948120117187500e-01 2.799987792968750000e-01 6.300029754638671875e-01 6.699981689453125000e-01 +3.968000030517578125e+01 2.860000228881835938e+01 4.749000167846679688e+01 -3.799972534179687500e-01 4.500007629394531250e-01 -7.599983215332031250e-01 -5.599975585937500000e-01 2.399978637695312500e-01 7.299995422363281250e-01 +4.661000061035156250e+01 3.257000350952148438e+01 5.146000289916992188e+01 -5.499954223632812500e-01 3.099975585937500000e-01 -7.099990844726562500e-01 1.000213623046875000e-02 7.099952697753906250e-01 6.399955749511718750e-01 +4.773000335693359375e+01 3.356999969482421875e+01 5.004000091552734375e+01 -9.499969482421875000e-01 -9.998321533203125000e-03 -1.399993896484375000e-01 2.500000000000000000e-01 9.100036621093750000e-01 -1.199989318847656250e-01 +4.650000000000000000e+01 2.873000144958496094e+01 4.619000244140625000e+01 2.000427246093750000e-02 5.099983215332031250e-01 8.100013732910156250e-01 -4.899978637695312500e-01 -7.899990081787109375e-01 2.399978637695312500e-01 +4.142000198364257812e+01 3.046000289916992188e+01 4.090000152587890625e+01 6.300010681152343750e-01 -4.200019836425781250e-01 -5.900001525878906250e-01 3.599967956542968750e-01 -1.300010681152343750e-01 8.699989318847656250e-01 +4.360000228881835938e+01 2.634000015258789062e+01 4.344000244140625000e+01 -4.799995422363281250e-01 8.199996948242187500e-01 1.300010681152343750e-01 4.200019836425781250e-01 -1.699981689453125000e-01 8.399963378906250000e-01 +4.625000000000000000e+01 3.617000198364257812e+01 4.816000366210937500e+01 -6.599998474121093750e-01 -6.499977111816406250e-01 -2.300033569335937500e-01 1.000213623046875000e-02 6.100006103515625000e-01 -7.400016784667968750e-01 +4.486000061035156250e+01 3.444000244140625000e+01 5.008000183105468750e+01 3.000259399414062500e-02 9.199981689453125000e-01 2.799987792968750000e-01 -2.199974060058593750e-01 4.000091552734375000e-02 -9.299964904785156250e-01 +4.247000122070312500e+01 2.589000320434570312e+01 4.674000167846679688e+01 -6.799964904785156250e-01 5.699977874755859375e-01 -3.600006103515625000e-01 1.000213623046875000e-02 1.899967193603515625e-01 9.399986267089843750e-01 +3.859000396728515625e+01 2.903000068664550781e+01 4.632000350952148438e+01 2.299995422363281250e-01 6.999988555908203125e-01 6.199989318847656250e-01 -6.200027465820312500e-01 4.100017547607421875e-01 -6.100044250488281250e-01 +4.126000213623046875e+01 2.995000076293945312e+01 4.750000000000000000e+01 -4.000091552734375000e-02 -8.399982452392578125e-01 4.599990844726562500e-01 7.599983215332031250e-01 4.399986267089843750e-01 3.800010681152343750e-01 +3.985000228881835938e+01 2.739000129699707031e+01 4.454000091552734375e+01 -2.299995422363281250e-01 6.800003051757812500e-01 6.300010681152343750e-01 -5.499992370605468750e-01 -7.399997711181640625e-01 2.400016784667968750e-01 +4.512000274658203125e+01 2.620000076293945312e+01 4.576000213623046875e+01 5.799980163574218750e-01 -7.299995422363281250e-01 2.400016784667968750e-01 -8.000030517578125000e-01 -1.699981689453125000e-01 5.000000000000000000e-01 +4.058000183105468750e+01 3.023000335693359375e+01 5.090999984741210938e+01 -9.000015258789062500e-01 -1.100025177001953125e-01 -2.899971008300781250e-01 1.800003051757812500e-01 -7.800025939941406250e-01 5.200004577636718750e-01 +3.913000106811523438e+01 2.805000114440917969e+01 4.516000366210937500e+01 -5.099983215332031250e-01 -1.000022888183593750e-02 7.999992370605468750e-01 -5.299987792968750000e-01 5.100002288818359375e-01 -6.200027465820312500e-01 +4.424000167846679688e+01 2.705000114440917969e+01 4.778000259399414062e+01 -5.000000000000000000e-01 -7.999992370605468750e-01 -1.500015258789062500e-01 -3.499984741210937500e-01 3.600006103515625000e-01 8.100013732910156250e-01 +4.148000335693359375e+01 2.761000061035156250e+01 4.304000473022460938e+01 6.999969482421875000e-02 4.200019836425781250e-01 8.599967956542968750e-01 1.299972534179687500e-01 7.099990844726562500e-01 -6.200027465820312500e-01 +4.138000106811523438e+01 2.922000122070312500e+01 4.568000411987304688e+01 -7.999801635742187500e-02 1.599998474121093750e-01 9.399986267089843750e-01 -8.500022888183593750e-01 -3.600006103515625000e-01 -2.500038146972656250e-01 +4.614000320434570312e+01 3.606000137329101562e+01 4.752000427246093750e+01 -7.100028991699218750e-01 -6.399993896484375000e-01 -1.200027465820312500e-01 7.999801635742187500e-02 4.300003051757812500e-01 -8.500022888183593750e-01 +4.994000244140625000e+01 3.095000076293945312e+01 4.233000183105468750e+01 1.199989318847656250e-01 9.500007629394531250e-01 0.000000000000000000e+00 -7.300033569335937500e-01 -1.399993896484375000e-01 -6.099967956542968750e-01 +4.508000183105468750e+01 3.379000091552734375e+01 4.947000122070312500e+01 -4.999923706054687500e-02 7.900009155273437500e-01 5.400009155273437500e-01 -5.400009155273437500e-01 2.000007629394531250e-01 -7.599983215332031250e-01 +4.569000244140625000e+01 3.654000091552734375e+01 5.029000091552734375e+01 -4.300003051757812500e-01 8.499984741210937500e-01 2.999877929687500000e-02 1.200027465820312500e-01 -1.800003051757812500e-01 -9.299964904785156250e-01 +4.124000167846679688e+01 2.939000129699707031e+01 4.114000320434570312e+01 2.800025939941406250e-01 8.400020599365234375e-01 3.599967956542968750e-01 6.900024414062500000e-01 -2.399997711181640625e-01 -6.200027465820312500e-01 +4.041000366210937500e+01 2.850000190734863281e+01 4.832000350952148438e+01 8.600006103515625000e-01 7.999801635742187500e-02 4.099998474121093750e-01 -6.000022888183593750e-01 3.999996185302734375e-01 6.199989318847656250e-01 +4.667000198364257812e+01 3.268000030517578125e+01 5.141000366210937500e+01 -5.200004577636718750e-01 3.100013732910156250e-01 -7.399978637695312500e-01 1.900024414062500000e-01 7.900009155273437500e-01 5.000000000000000000e-01 +4.645000457763671875e+01 2.613000106811523438e+01 4.650000000000000000e+01 -5.300064086914062500e-01 -1.999988555908203125e-01 -7.699966430664062500e-01 -6.300010681152343750e-01 3.400001525878906250e-01 6.400032043457031250e-01 +4.276000213623046875e+01 2.854999923706054688e+01 4.952000045776367188e+01 2.299995422363281250e-01 9.200019836425781250e-01 -1.599960327148437500e-01 -4.300003051757812500e-01 1.000213623046875000e-02 8.500022888183593750e-01 +4.687000274658203125e+01 2.879000091552734375e+01 4.590000152587890625e+01 -3.300018310546875000e-01 5.400009155273437500e-01 7.299995422363281250e-01 -8.999633789062500000e-02 -9.000015258789062500e-01 3.100013732910156250e-01 +4.485000228881835938e+01 2.724000167846679688e+01 4.590000152587890625e+01 -8.199996948242187500e-01 -2.600002288818359375e-01 4.300003051757812500e-01 1.000022888183593750e-01 -6.100006103515625000e-01 -7.200012207031250000e-01 +3.839000320434570312e+01 2.851000022888183594e+01 4.591999816894531250e+01 -2.000007629394531250e-01 -9.099979400634765625e-01 -2.199974060058593750e-01 -3.300018310546875000e-01 5.000000000000000000e-01 -7.499961853027343750e-01 +4.584000015258789062e+01 2.603000259399414062e+01 4.373000335693359375e+01 -1.399993896484375000e-01 -2.500019073486328125e-01 -9.100036621093750000e-01 1.600036621093750000e-01 -8.299999237060546875e-01 4.599990844726562500e-01 +4.222999954223632812e+01 2.714000320434570312e+01 4.695000076293945312e+01 -2.099990844726562500e-01 3.499984741210937500e-01 8.699989318847656250e-01 -2.599983215332031250e-01 6.999988555908203125e-01 -5.999984741210937500e-01 +4.199000549316406250e+01 2.883000183105468750e+01 4.940000152587890625e+01 3.699951171875000000e-01 8.599987030029296875e-01 -1.799964904785156250e-01 -8.200035095214843750e-01 1.699981689453125000e-01 4.500007629394531250e-01 +4.625000000000000000e+01 3.597000122070312500e+01 4.765000152587890625e+01 -7.900009155273437500e-01 -4.499969482421875000e-01 -2.800025939941406250e-01 2.200012207031250000e-01 5.800018310546875000e-01 -7.400016784667968750e-01 +4.131000137329101562e+01 2.939000129699707031e+01 4.568000411987304688e+01 -6.999969482421875000e-01 -1.399993896484375000e-01 6.399993896484375000e-01 -2.799987792968750000e-01 -4.800014495849609375e-01 -7.800025939941406250e-01 +4.853000259399414062e+01 3.293000030517578125e+01 5.006000137329101562e+01 4.699974060058593750e-01 8.200035095214843750e-01 1.700019836425781250e-01 -9.300003051757812500e-01 2.400016784667968750e-01 6.999969482421875000e-02 +4.538000106811523438e+01 3.346000289916992188e+01 4.958000183105468750e+01 -1.599998474121093750e-01 7.399978637695312500e-01 5.900001525878906250e-01 -4.899978637695312500e-01 2.099990844726562500e-01 -7.900009155273437500e-01 +4.096000289916992188e+01 3.097000122070312500e+01 4.091999816894531250e+01 4.199981689453125000e-01 1.500015258789062500e-01 -8.399963378906250000e-01 7.199974060058593750e-01 -1.900005340576171875e-01 6.000061035156250000e-01 +4.131999969482421875e+01 2.735000228881835938e+01 4.378000259399414062e+01 7.900009155273437500e-01 -3.200016021728515625e-01 4.400024414062500000e-01 1.700019836425781250e-01 -1.399993896484375000e-01 -9.300003051757812500e-01 +4.568000411987304688e+01 3.669000244140625000e+01 5.033000564575195312e+01 -6.599998474121093750e-01 6.800003051757812500e-01 -1.500053405761718750e-01 2.700004577636718750e-01 -2.700004577636718750e-01 -8.700065612792968750e-01 +4.593000411987304688e+01 3.215000152587890625e+01 5.197000122070312500e+01 -1.400032043457031250e-01 3.500022888183593750e-01 -8.799972534179687500e-01 -5.700035095214843750e-01 -7.699985504150390625e-01 4.000091552734375000e-02 +4.669000244140625000e+01 2.905000305175781250e+01 4.550000000000000000e+01 1.999664306640625000e-02 4.199981689453125000e-01 8.600006103515625000e-01 -6.299972534179687500e-01 -7.100028991699218750e-01 9.000015258789062500e-02 +4.455000305175781250e+01 2.624000167846679688e+01 4.284000396728515625e+01 -7.200012207031250000e-01 -6.300010681152343750e-01 6.999969482421875000e-02 5.999984741210937500e-01 -2.500000000000000000e-01 6.899986267089843750e-01 +4.173000335693359375e+01 2.918000221252441406e+01 4.596000289916992188e+01 -4.800033569335937500e-01 -1.000213623046875000e-02 8.300018310546875000e-01 7.399978637695312500e-01 5.900001525878906250e-01 1.499977111816406250e-01 +4.565000152587890625e+01 3.692000198364257812e+01 5.017000198364257812e+01 -4.099998474121093750e-01 8.600006103515625000e-01 1.199989318847656250e-01 2.699966430664062500e-01 -9.998321533203125000e-03 -9.200019836425781250e-01 +3.981000137329101562e+01 2.863000106811523438e+01 4.366000366210937500e+01 -2.700004577636718750e-01 1.399993896484375000e-01 9.099998474121093750e-01 9.200019836425781250e-01 2.600002288818359375e-01 -2.000045776367187500e-02 +4.267000198364257812e+01 2.906999969482421875e+01 5.011000061035156250e+01 3.800010681152343750e-01 7.600002288818359375e-01 -4.400024414062500000e-01 -7.499961853027343750e-01 3.500022888183593750e-01 4.900054931640625000e-01 +4.747000122070312500e+01 3.308000183105468750e+01 5.004000091552734375e+01 4.599990844726562500e-01 8.100013732910156250e-01 -2.400016784667968750e-01 -9.199981689453125000e-01 1.899986267089843750e-01 -1.999969482421875000e-01 +4.632000350952148438e+01 3.627000045776367188e+01 4.770000457763671875e+01 -7.000007629394531250e-01 -6.399993896484375000e-01 -7.000350952148437500e-02 2.999877929687500000e-02 4.099998474121093750e-01 -8.600044250488281250e-01 +4.990000152587890625e+01 3.103000259399414062e+01 4.241000366210937500e+01 -7.900009155273437500e-01 -9.000205993652343750e-02 -5.400009155273437500e-01 2.000045776367187500e-02 9.299983978271484375e-01 2.299995422363281250e-01 +4.496000289916992188e+01 3.404000091552734375e+01 4.942000579833984375e+01 1.800003051757812500e-01 9.099998474121093750e-01 2.599983215332031250e-01 -2.599983215332031250e-01 6.999969482421875000e-02 -9.200019836425781250e-01 +4.505000305175781250e+01 2.715999984741210938e+01 4.729999923706054688e+01 -7.700042724609375000e-01 -5.599994659423828125e-01 -1.999664306640625000e-02 6.699981689453125000e-01 -5.299987792968750000e-01 4.300041198730468750e-01 +4.049000167846679688e+01 2.908000183105468750e+01 4.837000274658203125e+01 6.500015258789062500e-01 -1.200008392333984375e-01 6.899986267089843750e-01 -8.300018310546875000e-01 1.300010681152343750e-01 4.700012207031250000e-01 +4.104000091552734375e+01 3.002000045776367188e+01 4.087000274658203125e+01 6.699981689453125000e-01 -2.699985504150390625e-01 -6.200027465820312500e-01 4.900016784667968750e-01 3.999996185302734375e-01 7.200012207031250000e-01 +4.654000091552734375e+01 2.901000022888183594e+01 4.560000610351562500e+01 -4.599990844726562500e-01 -5.099983215332031250e-01 6.799964904785156250e-01 5.400009155273437500e-01 6.200008392333984375e-01 4.899978637695312500e-01 +3.859000396728515625e+01 2.904000091552734375e+01 4.599000549316406250e+01 -3.500022888183593750e-01 -8.899993896484375000e-01 -2.000427246093750000e-02 6.499977111816406250e-01 -1.000022888183593750e-02 6.999969482421875000e-01 +3.863999938964843750e+01 2.932000160217285156e+01 4.190000152587890625e+01 -5.799980163574218750e-01 -2.399997711181640625e-01 -7.200012207031250000e-01 8.700027465820312500e-01 6.999969482421875000e-02 -4.000015258789062500e-01 +4.045000076293945312e+01 2.698000144958496094e+01 4.371000289916992188e+01 3.299980163574218750e-01 3.000011444091796875e-01 -8.400001525878906250e-01 -9.499969482421875000e-01 -3.999900817871093750e-02 -1.100006103515625000e-01 +4.048000335693359375e+01 2.980000305175781250e+01 5.063999938964843750e+01 -9.600028991699218750e-01 9.998321533203125000e-03 -2.999496459960937500e-02 2.600021362304687500e-01 -4.000015258789062500e-01 -8.199958801269531250e-01 +4.192000579833984375e+01 2.873000144958496094e+01 4.820999908447265625e+01 5.199966430664062500e-01 7.999992370605468750e-01 -9.998321533203125000e-03 -5.300025939941406250e-01 4.999923706054687500e-02 -7.899971008300781250e-01 +4.519000244140625000e+01 3.397000122070312500e+01 4.975000381469726562e+01 -1.800003051757812500e-01 8.000183105468750000e-02 -9.400024414062500000e-01 -2.099990844726562500e-01 8.600006103515625000e-01 3.599967956542968750e-01 +4.139000320434570312e+01 2.732000160217285156e+01 4.109000396728515625e+01 7.199974060058593750e-01 4.200000762939453125e-01 -4.799995422363281250e-01 -5.699996948242187500e-01 -3.600006103515625000e-01 -6.800003051757812500e-01 +4.072000122070312500e+01 2.889000129699707031e+01 4.583000183105468750e+01 -9.399986267089843750e-01 1.300010681152343750e-01 1.200027465820312500e-01 6.999969482421875000e-02 -4.899997711181640625e-01 -8.199996948242187500e-01 +4.742000198364257812e+01 3.281000137329101562e+01 5.049000167846679688e+01 -2.299995422363281250e-01 -3.799972534179687500e-01 8.500022888183593750e-01 -8.500022888183593750e-01 2.200012207031250000e-01 -3.899993896484375000e-01 +4.629000091552734375e+01 3.646000289916992188e+01 4.776000213623046875e+01 -6.199951171875000000e-01 -6.500015258789062500e-01 -3.199996948242187500e-01 2.099990844726562500e-01 5.299987792968750000e-01 -7.699966430664062500e-01 +3.810000228881835938e+01 2.892000198364257812e+01 4.580000305175781250e+01 -1.000022888183593750e-01 -7.400016784667968750e-01 -6.000022888183593750e-01 -6.699981689453125000e-01 -1.300010681152343750e-01 6.599998474121093750e-01 +4.104000091552734375e+01 3.031000137329101562e+01 4.134000396728515625e+01 5.999984741210937500e-01 -4.300003051757812500e-01 -5.999984741210937500e-01 4.500007629394531250e-01 -9.998321533203125000e-03 8.400001525878906250e-01 +4.503000259399414062e+01 2.710000038146972656e+01 4.623000335693359375e+01 -8.300018310546875000e-01 -6.999969482421875000e-02 4.699974060058593750e-01 9.998321533203125000e-03 -7.600002288818359375e-01 -5.900039672851562500e-01 +4.702999877929687500e+01 2.936000061035156250e+01 4.594000244140625000e+01 -5.499954223632812500e-01 -7.800006866455078125e-01 1.099967956542968750e-01 -8.999633789062500000e-02 4.699993133544921875e-01 8.299980163574218750e-01 +4.315999984741210938e+01 3.577999877929687500e+01 4.920000076293945312e+01 5.400047302246093750e-01 -4.099960327148437500e-01 -6.799964904785156250e-01 -8.699989318847656250e-01 -3.599967956542968750e-01 -1.399993896484375000e-01 +4.548000335693359375e+01 3.385000228881835938e+01 4.941000366210937500e+01 9.300003051757812500e-01 7.999801635742187500e-02 2.200012207031250000e-01 -6.000137329101562500e-02 2.999992370605468750e-01 -9.000015258789062500e-01 +4.188000106811523438e+01 2.860000228881835938e+01 4.640000152587890625e+01 1.100044250488281250e-01 -9.400024414062500000e-01 1.300010681152343750e-01 -1.800003051757812500e-01 3.500003814697265625e-01 8.700027465820312500e-01 +4.098999786376953125e+01 2.921000289916992188e+01 4.065000152587890625e+01 8.500022888183593750e-01 1.499977111816406250e-01 -4.000015258789062500e-01 0.000000000000000000e+00 5.099983215332031250e-01 7.999992370605468750e-01 +4.229999923706054688e+01 2.593000221252441406e+01 4.561000442504882812e+01 7.400054931640625000e-01 1.099987030029296875e-01 -6.000022888183593750e-01 -7.699966430664062500e-01 9.998321533203125000e-03 -5.700035095214843750e-01 +4.620000457763671875e+01 3.647000122070312500e+01 4.760000228881835938e+01 -5.800018310546875000e-01 -6.900024414062500000e-01 -3.100013732910156250e-01 3.499984741210937500e-01 3.899993896484375000e-01 -8.099975585937500000e-01 +4.802000045776367188e+01 3.353000259399414062e+01 5.017000198364257812e+01 7.299995422363281250e-01 6.199989318847656250e-01 -1.100006103515625000e-01 3.800010681152343750e-01 -7.299995422363281250e-01 5.000038146972656250e-01 +4.242000198364257812e+01 2.686000061035156250e+01 4.183000183105468750e+01 -4.299964904785156250e-01 -8.199996948242187500e-01 2.099990844726562500e-01 -6.999969482421875000e-01 5.800018310546875000e-01 -2.799987792968750000e-01 +4.161000061035156250e+01 2.932000160217285156e+01 4.904000091552734375e+01 4.799995422363281250e-01 8.299999237060546875e-01 2.000045776367187500e-02 -4.900016784667968750e-01 -1.000022888183593750e-02 8.199996948242187500e-01 +4.440999984741210938e+01 2.613000106811523438e+01 4.386000061035156250e+01 -5.999984741210937500e-01 3.400001525878906250e-01 -6.599998474121093750e-01 4.700050354003906250e-01 -6.999988555908203125e-01 -4.500007629394531250e-01 +4.452000045776367188e+01 2.794000244140625000e+01 4.680000305175781250e+01 -8.199958801269531250e-01 4.399986267089843750e-01 -2.200012207031250000e-01 -2.199974060058593750e-01 -5.699996948242187500e-01 7.399978637695312500e-01 +3.906000137329101562e+01 2.850000190734863281e+01 4.569000244140625000e+01 -5.600013732910156250e-01 -3.400001525878906250e-01 6.899986267089843750e-01 7.800025939941406250e-01 3.099994659423828125e-01 4.500007629394531250e-01 +4.705000305175781250e+01 2.898000335693359375e+01 4.621000289916992188e+01 -9.199981689453125000e-01 -1.500015258789062500e-01 2.000007629394531250e-01 3.199958801269531250e-01 5.299987792968750000e-01 7.399978637695312500e-01 +4.121000289916992188e+01 3.049000167846679688e+01 4.089000320434570312e+01 4.699974060058593750e-01 -1.100006103515625000e-01 -8.200035095214843750e-01 6.599998474121093750e-01 -1.800003051757812500e-01 6.799964904785156250e-01 +4.791000366210937500e+01 3.309000396728515625e+01 5.026000213623046875e+01 7.799987792968750000e-01 -5.600013732910156250e-01 0.000000000000000000e+00 -7.000007629394531250e-01 -5.600013732910156250e-01 -3.400001525878906250e-01 +4.243000030517578125e+01 2.894000053405761719e+01 4.873000335693359375e+01 2.700004577636718750e-01 9.100017547607421875e-01 -6.999969482421875000e-02 1.600036621093750000e-01 -2.299995422363281250e-01 9.199981689453125000e-01 +4.520000076293945312e+01 3.399000167846679688e+01 4.976000213623046875e+01 2.000045776367187500e-02 3.800010681152343750e-01 -8.800010681152343750e-01 -7.599983215332031250e-01 -5.800018310546875000e-01 -9.998321533203125000e-03 +4.205000305175781250e+01 2.596000289916992188e+01 4.498000335693359375e+01 -7.000007629394531250e-01 -6.400032043457031250e-01 9.998321533203125000e-03 1.399993896484375000e-01 2.199974060058593750e-01 9.199981689453125000e-01 +4.266000366210937500e+01 2.675000190734863281e+01 4.190000152587890625e+01 -1.000213623046875000e-02 7.199993133544921875e-01 -6.299972534179687500e-01 -1.800003051757812500e-01 4.200000762939453125e-01 8.400001525878906250e-01 +3.880000305175781250e+01 2.776000022888183594e+01 4.552000045776367188e+01 2.999992370605468750e-01 -8.399982452392578125e-01 -3.299980163574218750e-01 2.899971008300781250e-01 2.000045776367187500e-02 9.099998474121093750e-01 +4.634000396728515625e+01 3.628000259399414062e+01 4.793000030517578125e+01 -8.600006103515625000e-01 -4.200019836425781250e-01 -1.399993896484375000e-01 1.699981689453125000e-01 4.599990844726562500e-01 -8.199958801269531250e-01 +3.957000350952148438e+01 2.798000144958496094e+01 4.827000045776367188e+01 9.199981689453125000e-01 1.399993896484375000e-01 2.200050354003906250e-01 -4.800033569335937500e-01 5.799999237060546875e-01 6.000022888183593750e-01 +4.042000198364257812e+01 2.835000038146972656e+01 4.297000503540039062e+01 -5.900001525878906250e-01 -6.999969482421875000e-02 -7.600021362304687500e-01 -5.699996948242187500e-01 2.500019073486328125e-01 7.199974060058593750e-01 +4.512000274658203125e+01 2.731000137329101562e+01 4.604999923706054688e+01 7.999801635742187500e-02 -7.199993133544921875e-01 -6.299972534179687500e-01 -6.000022888183593750e-01 -3.400001525878906250e-01 6.700057983398437500e-01 +4.662000274658203125e+01 2.944000244140625000e+01 4.577000045776367188e+01 1.499977111816406250e-01 2.499980926513671875e-01 9.099998474121093750e-01 -3.600006103515625000e-01 -8.800010681152343750e-01 5.000305175781250000e-02 +4.301000213623046875e+01 2.634000015258789062e+01 4.754000091552734375e+01 9.998321533203125000e-03 -7.399978637695312500e-01 5.999984741210937500e-01 -1.500015258789062500e-01 7.600002288818359375e-01 5.600051879882812500e-01 +4.142000198364257812e+01 2.893000030517578125e+01 4.638000106811523438e+01 -7.100028991699218750e-01 -3.800010681152343750e-01 -5.099983215332031250e-01 -4.099998474121093750e-01 2.399997711181640625e-01 8.300018310546875000e-01 +4.550000000000000000e+01 2.670000076293945312e+01 4.468000411987304688e+01 1.000213623046875000e-02 -2.199974060058593750e-01 -9.300041198730468750e-01 7.500000000000000000e-01 -4.799995422363281250e-01 3.699989318847656250e-01 +3.914000320434570312e+01 2.809000015258789062e+01 4.511000061035156250e+01 -2.800025939941406250e-01 -5.099983215332031250e-01 -7.599945068359375000e-01 -4.500007629394531250e-01 8.400001525878906250e-01 -9.999847412109375000e-02 +4.336000442504882812e+01 3.556999969482421875e+01 4.954000473022460938e+01 -9.300041198730468750e-01 -1.699981689453125000e-01 1.699981689453125000e-01 2.000007629394531250e-01 -5.499992370605468750e-01 -7.600021362304687500e-01 +4.609000396728515625e+01 3.347999954223632812e+01 4.920999908447265625e+01 -6.000022888183593750e-01 3.600006103515625000e-01 -6.499938964843750000e-01 -4.000473022460937500e-02 -9.499969482421875000e-01 -1.399993896484375000e-01 +4.123000335693359375e+01 3.017000198364257812e+01 4.111000061035156250e+01 5.399971008300781250e-01 2.399997711181640625e-01 -7.500000000000000000e-01 5.799980163574218750e-01 6.000137329101562500e-02 7.600021362304687500e-01 +4.630000305175781250e+01 3.638000106811523438e+01 4.815000152587890625e+01 -6.600036621093750000e-01 -6.299972534179687500e-01 -2.700004577636718750e-01 1.500015258789062500e-01 5.499992370605468750e-01 -7.699966430664062500e-01 +4.018000030517578125e+01 3.745000076293945312e+01 4.261000061035156250e+01 -4.999923706054687500e-02 8.500022888183593750e-01 4.500007629394531250e-01 1.000022888183593750e-01 2.299995422363281250e-01 -9.199981689453125000e-01 +4.561000442504882812e+01 3.461000061035156250e+01 5.153000259399414062e+01 1.099967956542968750e-01 -5.400009155273437500e-01 -7.799987792968750000e-01 -8.200035095214843750e-01 -2.999992370605468750e-01 3.900032043457031250e-01 +4.049000167846679688e+01 2.902000236511230469e+01 4.889000320434570312e+01 2.400016784667968750e-01 -7.800006866455078125e-01 4.999961853027343750e-01 -9.300003051757812500e-01 1.299991607666015625e-01 1.900024414062500000e-01 +4.845000457763671875e+01 3.342000198364257812e+01 5.051000213623046875e+01 5.299987792968750000e-01 7.000007629394531250e-01 -3.899993896484375000e-01 -8.600006103515625000e-01 9.000015258789062500e-02 -4.000015258789062500e-01 +4.638000106811523438e+01 2.921000289916992188e+01 4.586000442504882812e+01 -2.199974060058593750e-01 -8.700027465820312500e-01 -3.500022888183593750e-01 -1.799964904785156250e-01 -7.000350952148437500e-02 9.300003051757812500e-01 +4.245000457763671875e+01 2.659000205993652344e+01 4.729999923706054688e+01 -3.300018310546875000e-01 7.800006866455078125e-01 -4.399948120117187500e-01 -1.900024414062500000e-01 1.499977111816406250e-01 9.300041198730468750e-01 +4.540000534057617188e+01 2.564000129699707031e+01 4.413999938964843750e+01 -6.900024414062500000e-01 5.200004577636718750e-01 -3.999977111816406250e-01 1.199951171875000000e-01 3.900012969970703125e-01 8.700027465820312500e-01 +4.588000488281250000e+01 3.399000167846679688e+01 4.933000183105468750e+01 -6.600036621093750000e-01 3.299980163574218750e-01 -6.199989318847656250e-01 8.199958801269531250e-01 4.099998474121093750e-01 -2.900009155273437500e-01 +4.334000015258789062e+01 3.531999969482421875e+01 4.948000335693359375e+01 -9.499969482421875000e-01 -8.999633789062500000e-02 -1.100006103515625000e-01 3.600044250488281250e-01 -1.399993896484375000e-01 -8.800010681152343750e-01 +4.070999908447265625e+01 3.017000198364257812e+01 5.083000183105468750e+01 -8.599967956542968750e-01 -3.299999237060546875e-01 -2.600021362304687500e-01 -1.699943542480468750e-01 8.899993896484375000e-01 3.000030517578125000e-01 +4.172000503540039062e+01 2.957000350952148438e+01 4.651000213623046875e+01 -9.099998474121093750e-01 -1.600017547607421875e-01 2.800025939941406250e-01 4.299964904785156250e-01 3.499984741210937500e-01 7.799987792968750000e-01 +4.084999847412109375e+01 2.778000068664550781e+01 4.406000137329101562e+01 1.600036621093750000e-01 8.100013732910156250e-01 4.900016784667968750e-01 -4.299964904785156250e-01 2.800006866455078125e-01 -7.999992370605468750e-01 +3.965000152587890625e+01 2.913999938964843750e+01 4.184000015258789062e+01 2.700004577636718750e-01 -5.099983215332031250e-01 -7.699966430664062500e-01 4.500007629394531250e-01 8.400020599365234375e-01 -1.099967956542968750e-01 +4.611000061035156250e+01 3.641000366210937500e+01 4.775000000000000000e+01 -6.500015258789062500e-01 -6.599998474121093750e-01 -2.199974060058593750e-01 1.900024414062500000e-01 4.399986267089843750e-01 -8.299942016601562500e-01 +3.918000030517578125e+01 2.898000335693359375e+01 4.736999893188476562e+01 -1.800003051757812500e-01 2.699985504150390625e-01 9.000015258789062500e-01 -7.999954223632812500e-01 -4.500007629394531250e-01 -2.799987792968750000e-01 +4.556999969482421875e+01 2.647000122070312500e+01 4.695000076293945312e+01 1.000213623046875000e-02 -8.899993896484375000e-01 3.700027465820312500e-01 -9.199981689453125000e-01 2.600002288818359375e-01 4.000473022460937500e-02 +4.327999877929687500e+01 2.688000106811523438e+01 4.277000427246093750e+01 -3.199996948242187500e-01 -5.900001525878906250e-01 -6.900024414062500000e-01 -7.899971008300781250e-01 2.500000000000000000e-01 4.799995422363281250e-01 +4.663000106811523438e+01 2.878000068664550781e+01 4.591999816894531250e+01 4.000091552734375000e-02 -8.399982452392578125e-01 4.700050354003906250e-01 1.399993896484375000e-01 6.600017547607421875e-01 6.800041198730468750e-01 +4.291000366210937500e+01 2.700000000000000000e+01 4.744000244140625000e+01 -7.500038146972656250e-01 -5.900001525878906250e-01 1.300010681152343750e-01 -3.899993896484375000e-01 8.300018310546875000e-01 -2.700042724609375000e-01 +4.140000152587890625e+01 3.104000091552734375e+01 4.114000320434570312e+01 6.600036621093750000e-01 -3.799991607666015625e-01 5.900001525878906250e-01 3.699989318847656250e-01 -1.099987030029296875e-01 -8.800010681152343750e-01 +4.531999969482421875e+01 2.722000122070312500e+01 4.547000503540039062e+01 4.200057983398437500e-01 -5.000000000000000000e-01 -7.100028991699218750e-01 -4.699974060058593750e-01 -6.500015258789062500e-01 5.099945068359375000e-01 +4.457000350952148438e+01 3.476000213623046875e+01 5.005000305175781250e+01 -2.099990844726562500e-01 -1.100006103515625000e-01 -9.200019836425781250e-01 -7.999992370605468750e-01 -2.700004577636718750e-01 4.599990844726562500e-01 +4.143000030517578125e+01 2.780000305175781250e+01 4.094000244140625000e+01 3.400001525878906250e-01 7.199993133544921875e-01 -5.200004577636718750e-01 -8.499984741210937500e-01 2.999992370605468750e-01 3.099975585937500000e-01 +4.370000457763671875e+01 2.640000152587890625e+01 4.827000045776367188e+01 -2.500000000000000000e-01 8.899993896484375000e-01 -2.399940490722656250e-01 -2.100067138671875000e-01 -6.000137329101562500e-02 9.300003051757812500e-01 +4.061000442504882812e+01 3.003000259399414062e+01 4.995000457763671875e+01 -8.800010681152343750e-01 -3.500003814697265625e-01 1.399993896484375000e-01 3.599967956542968750e-01 -5.200004577636718750e-01 -7.100028991699218750e-01 +3.910000228881835938e+01 2.810000228881835938e+01 4.753000259399414062e+01 -4.300003051757812500e-01 4.499969482421875000e-01 7.299995422363281250e-01 -7.199974060058593750e-01 -2.500019073486328125e-01 -5.900001525878906250e-01 +4.631000137329101562e+01 3.635000228881835938e+01 4.794000244140625000e+01 -6.800003051757812500e-01 -6.300010681152343750e-01 -2.399978637695312500e-01 6.999969482421875000e-02 5.699996948242187500e-01 -7.599983215332031250e-01 +4.264000320434570312e+01 2.894000053405761719e+01 5.125000381469726562e+01 -7.500038146972656250e-01 4.200000762939453125e-01 -4.100036621093750000e-01 -3.000259399414062500e-02 -9.099979400634765625e-01 -3.100013732910156250e-01 +3.945999908447265625e+01 2.875000190734863281e+01 4.361000061035156250e+01 -6.499977111816406250e-01 -6.499996185302734375e-01 -2.799987792968750000e-01 -1.999664306640625000e-02 6.599998474121093750e-01 -6.999969482421875000e-01 +4.687000274658203125e+01 2.944000244140625000e+01 4.570000076293945312e+01 -6.300010681152343750e-01 -7.200012207031250000e-01 -6.999969482421875000e-02 9.998321533203125000e-03 2.199974060058593750e-01 9.300003051757812500e-01 +4.267000198364257812e+01 2.902000236511230469e+01 4.815000152587890625e+01 -5.900001525878906250e-01 2.600002288818359375e-01 -7.099990844726562500e-01 1.199989318847656250e-01 8.099975585937500000e-01 5.100021362304687500e-01 +4.146000289916992188e+01 3.121000099182128906e+01 4.059000015258789062e+01 4.700012207031250000e-01 -4.099998474121093750e-01 -7.299957275390625000e-01 5.900001525878906250e-01 -6.999969482421875000e-02 7.400016784667968750e-01 +3.937000274658203125e+01 2.972000122070312500e+01 4.106000518798828125e+01 5.499992370605468750e-01 7.100009918212890625e-01 -3.100013732910156250e-01 -4.799995422363281250e-01 -2.999992370605468750e-01 -7.700042724609375000e-01 +4.093000411987304688e+01 2.939000129699707031e+01 4.590999984741210938e+01 -6.300010681152343750e-01 -4.500007629394531250e-01 5.700035095214843750e-01 -2.000007629394531250e-01 -3.299999237060546875e-01 -8.799972534179687500e-01 diff --git a/tests/data/Clustering_results_HDBSCAN_MSRC.dat b/tests/data/Clustering_results_HDBSCAN_MSRC.dat new file mode 100644 index 0000000..26bb719 --- /dev/null +++ b/tests/data/Clustering_results_HDBSCAN_MSRC.dat @@ -0,0 +1,42 @@ +10 +HDBSCAN +FCW HCW WCW +True +10 9 8 7 6 5 4 3 2 +0.0 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +FCW 41.068180084228516 30.142730712890625 41.10182189941406 41.66721725463867 29.93570899963379 40.32832336425781 41.67447280883789 30.349889755249023 41.86960983276367 +FCW 46.2599983215332 36.27909469604492 47.799095153808594 46.40528106689453 36.8060188293457 46.96168899536133 45.53178024291992 35.63311004638672 47.5701789855957 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.57703399658203 29.518451690673828 46.76020050048828 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.7336540222168 29.52460289001465 46.767112731933594 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 46.796688079833984 29.28479766845703 46.859107971191406 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 47.06808090209961 29.681392669677734 46.571876525878906 +WCW 41.64666748046875 29.21222686767578 46.958892822265625 41.335205078125 29.523826599121094 47.85660934448242 41.68410873413086 28.263580322265625 47.273006439208984 +WCW 41.64666748046875 29.21222686767578 46.958892822265625 40.76143264770508 28.935361862182617 47.33266067504883 42.02277755737305 29.73078155517578 47.72677230834961 +WCW 41.64666748046875 29.21222686767578 46.958892822265625 41.139888763427734 29.2017765045166 47.82090759277344 42.43814468383789 29.755647659301758 47.23863220214844 +WCW 41.64666748046875 29.21222686767578 46.958892822265625 41.139888763427734 29.2017765045166 47.82090759277344 42.16964340209961 30.064558029174805 46.96408462524414 +WCW 41.64666748046875 29.21222686767578 46.958892822265625 41.139888763427734 29.2017765045166 47.82090759277344 41.111446380615234 28.96769142150879 46.150352478027344 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 46.20960998535156 34.230098724365234 49.565521240234375 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 45.35662841796875 34.91427230834961 49.88496398925781 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.22610855102539 34.317527770996094 48.66962814331055 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.11109161376953 34.746253967285156 50.20753479003906 diff --git a/tests/data/Clustering_results_HDBSCAN_QMSRC.dat b/tests/data/Clustering_results_HDBSCAN_QMSRC.dat new file mode 100644 index 0000000..cf4e536 --- /dev/null +++ b/tests/data/Clustering_results_HDBSCAN_QMSRC.dat @@ -0,0 +1,51 @@ +10 +HDBSCAN +FCW HCW WCW +False +10 9 8 7 6 5 4 3 2 +0.0 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +FCW 41.068180084228516 30.142730712890625 41.10182189941406 41.66721725463867 29.93570899963379 40.32832336425781 41.67447280883789 30.349889755249023 41.86960983276367 +FCW 46.2599983215332 36.27909469604492 47.799095153808594 46.40528106689453 36.8060188293457 46.96168899536133 45.53178024291992 35.63311004638672 47.5701789855957 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.57703399658203 29.518451690673828 46.76020050048828 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.7336540222168 29.52460289001465 46.767112731933594 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 46.796688079833984 29.28479766845703 46.859107971191406 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 47.06808090209961 29.681392669677734 46.571876525878906 +WCW 39.01727294921875 28.470001220703125 45.4654541015625 39.796817779541016 28.641372680664062 46.067901611328125 38.63682556152344 27.556671142578125 45.32023620605469 +WCW 39.01727294921875 28.470001220703125 45.4654541015625 38.598297119140625 28.485820770263672 46.373313903808594 38.417484283447266 29.076522827148438 44.94355010986328 +WCW 41.53099822998047 29.199005126953125 47.10000228881836 40.590145111083984 29.131559371948242 47.43204116821289 41.907108306884766 29.717559814453125 47.867881774902344 +WCW 41.53099822998047 29.199005126953125 47.10000228881836 41.02421951293945 29.188554763793945 47.96201705932617 42.32247543334961 29.7424259185791 47.37974166870117 +WCW 41.53099822998047 29.199005126953125 47.10000228881836 41.02421951293945 29.188554763793945 47.96201705932617 42.05397415161133 30.05133628845215 47.105194091796875 +WCW 41.53099822998047 29.199005126953125 47.10000228881836 41.02421951293945 29.188554763793945 47.96201705932617 40.99577713012695 28.954469680786133 46.29146194458008 +WCW 41.38667297363281 29.2388916015625 49.453338623046875 40.45566177368164 29.181554794311523 49.09288024902344 41.444602966308594 29.98031234741211 50.12187194824219 +WCW 41.38667297363281 29.2388916015625 49.453338623046875 40.38933563232422 29.288846969604492 49.400211334228516 41.74907684326172 30.13817596435547 49.20848846435547 +WCW 41.38667297363281 29.2388916015625 49.453338623046875 40.38933563232422 29.288846969604492 49.400211334228516 41.71467208862305 28.75216293334961 48.64370346069336 +WCW 41.38667297363281 29.2388916015625 49.453338623046875 40.61896896362305 29.564220428466797 50.00541687011719 41.91059875488281 28.852718353271484 50.21253204345703 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 46.20960998535156 34.230098724365234 49.565521240234375 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 45.35662841796875 34.91427230834961 49.88496398925781 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.22610855102539 34.317527770996094 48.66962814331055 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.11109161376953 34.746253967285156 50.20753479003906 +WCW 40.217777252197266 28.26666831970215 42.95000457763672 40.36005783081055 27.290151596069336 43.111778259277344 40.27594757080078 28.985763549804688 42.257530212402344 +WCW 40.217777252197266 28.26666831970215 42.95000457763672 40.36005783081055 27.290151596069336 43.111778259277344 40.48881530761719 28.353918075561523 41.991397857666016 +WCW 40.217777252197266 28.26666831970215 42.95000457763672 40.36005783081055 27.290151596069336 43.111778259277344 40.08379364013672 28.8424129486084 43.7565803527832 +WCW 40.217777252197266 28.26666831970215 42.95000457763672 39.507957458496094 28.19581413269043 42.24919509887695 40.97538375854492 28.760726928710938 42.523460388183594 diff --git a/tests/data/Clustering_results_HDBSCAN_QMSRC_onlyO.dat b/tests/data/Clustering_results_HDBSCAN_QMSRC_onlyO.dat new file mode 100644 index 0000000..47e4e87 --- /dev/null +++ b/tests/data/Clustering_results_HDBSCAN_QMSRC_onlyO.dat @@ -0,0 +1,32 @@ +10 +HDBSCAN +onlyO +False +10 9 8 7 6 5 4 3 2 +0.0 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +O_clust 46.712730407714844 29.038183212280273 45.893638610839844 +O_clust 41.068180084228516 30.142730712890625 41.10182189941406 +O_clust 41.64666748046875 29.21222686767578 46.958892822265625 +O_clust 46.2599983215332 36.27909469604492 47.799095153808594 +O_clust 45.247276306152344 33.96091079711914 49.6036376953125 diff --git a/tests/data/Clustering_results_HDBSCAN_SC.dat b/tests/data/Clustering_results_HDBSCAN_SC.dat new file mode 100644 index 0000000..5b43cee --- /dev/null +++ b/tests/data/Clustering_results_HDBSCAN_SC.dat @@ -0,0 +1,37 @@ +10 +HDBSCAN +FCW HCW WCW +False +8 +0.0 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +FCW 46.2599983215332 36.27909469604492 47.799095153808594 46.40528106689453 36.8060188293457 46.96168899536133 45.53178024291992 35.63311004638672 47.5701789855957 +FCW 41.23272705078125 30.330909729003906 40.98818588256836 41.84754180908203 30.135316848754883 40.22415542602539 41.8143424987793 30.42807960510254 41.79582595825195 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.57703399658203 29.518451690673828 46.76020050048828 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.7336540222168 29.52460289001465 46.767112731933594 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 46.796688079833984 29.28479766845703 46.859107971191406 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 47.06808090209961 29.681392669677734 46.571876525878906 +WCW 38.71666717529297 28.565555572509766 45.59444808959961 39.27976989746094 28.85868263244629 46.36709976196289 39.268402099609375 28.068113327026367 44.925018310546875 +WCW 38.71666717529297 28.565555572509766 45.59444808959961 39.27976989746094 28.85868263244629 46.36709976196289 38.426761627197266 27.61688995361328 45.46800231933594 +WCW 38.71666717529297 28.565555572509766 45.59444808959961 38.116878509521484 29.172077178955078 45.07254409790039 38.5151252746582 27.902780532836914 44.873260498046875 +WCW 38.71666717529297 28.565555572509766 45.59444808959961 38.116878509521484 29.172077178955078 45.07254409790039 38.096839904785156 28.39474105834961 46.36037063598633 diff --git a/tests/data/Clustering_results_OPTICS_MSRC.dat b/tests/data/Clustering_results_OPTICS_MSRC.dat new file mode 100644 index 0000000..8501793 --- /dev/null +++ b/tests/data/Clustering_results_OPTICS_MSRC.dat @@ -0,0 +1,57 @@ +10 +OPTICS +FCW HCW WCW +True +10 9 8 7 6 5 4 3 2 +0.1 0.05 0.01 0.005 0.001 0.0005 0.0001 1e-05 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +FCW 41.23272705078125 30.330909729003906 40.98818588256836 41.84754180908203 30.135316848754883 40.22415542602539 41.8143424987793 30.42807960510254 41.79582595825195 +FCW 46.2599983215332 36.27909469604492 47.799095153808594 46.40528106689453 36.8060188293457 46.96168899536133 45.53178024291992 35.63311004638672 47.5701789855957 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.57703399658203 29.518451690673828 46.76020050048828 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.7336540222168 29.52460289001465 46.767112731933594 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 46.796688079833984 29.28479766845703 46.859107971191406 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 47.06808090209961 29.681392669677734 46.571876525878906 +WCW 41.665000915527344 29.24900245666504 46.48900604248047 41.0498161315918 29.52010154724121 45.74869918823242 41.19739532470703 29.277957916259766 47.37247085571289 +WCW 41.665000915527344 29.24900245666504 46.48900604248047 40.7099609375 29.082006454467773 46.73397445678711 41.96389389038086 29.89197540283203 47.19416427612305 +WCW 41.665000915527344 29.24900245666504 46.48900604248047 42.456478118896484 29.792423248291016 46.76874542236328 41.70244216918945 28.300355911254883 46.80311965942383 +WCW 38.83000564575195 28.447998046875 45.4890022277832 39.38174057006836 27.9505558013916 44.81957244873047 39.46666717529297 28.566635131835938 46.2509651184082 +WCW 38.83000564575195 28.447998046875 45.4890022277832 39.38174057006836 27.9505558013916 44.81957244873047 38.23021697998047 29.054519653320312 44.967098236083984 +WCW 38.83000564575195 28.447998046875 45.4890022277832 38.62846374511719 27.78522300720215 44.76781463623047 38.21017837524414 28.277183532714844 46.25492477416992 +WCW 40.85199737548828 27.82000160217285 43.040000915527344 40.67170333862305 28.283079147338867 43.90778732299805 40.88725280761719 28.550844192504883 42.35836410522461 +WCW 40.85199737548828 27.82000160217285 43.040000915527344 40.67170333862305 28.283079147338867 43.90778732299805 40.26106262207031 27.014118194580078 43.00326919555664 +WCW 45.27727508544922 26.86363983154297 46.12636184692383 44.44940948486328 26.706167221069336 46.664730072021484 45.97956466674805 26.252676010131836 46.491756439208984 +WCW 45.27727508544922 26.86363983154297 46.12636184692383 44.44940948486328 26.706167221069336 46.664730072021484 45.003814697265625 26.586687088012695 45.2052116394043 +WCW 45.27727508544922 26.86363983154297 46.12636184692383 45.43928527832031 26.17399024963379 45.42057418823242 44.90922546386719 26.213802337646484 46.7913818359375 +WCW 45.27727508544922 26.86363983154297 46.12636184692383 45.43928527832031 26.17399024963379 45.42057418823242 44.353797912597656 27.235193252563477 46.030784606933594 +WCW 42.93000411987305 26.560001373291016 47.17888641357422 42.991546630859375 26.679779052734375 48.169776916503906 42.173213958740234 26.345054626464844 46.56157684326172 +WCW 42.93000411987305 26.560001373291016 47.17888641357422 42.261905670166016 25.81601333618164 47.16757583618164 42.56803512573242 27.41203498840332 46.80070877075195 +WCW 42.93000411987305 26.560001373291016 47.17888641357422 42.261905670166016 25.81601333618164 47.16757583618164 42.63617706298828 26.932165145874023 48.05931854248047 +WCW 43.17110824584961 26.85555648803711 42.74555969238281 42.3840217590332 26.301883697509766 42.47364044189453 43.57135009765625 26.591943740844727 43.623233795166016 +WCW 43.17110824584961 26.85555648803711 42.74555969238281 42.735599517822266 26.46652603149414 41.933780670166016 42.30861282348633 27.14484405517578 43.160789489746094 +WCW 43.17110824584961 26.85555648803711 42.74555969238281 42.735599517822266 26.46652603149414 41.933780670166016 43.8919563293457 27.3093204498291 42.221656799316406 +WCW 47.64555740356445 33.075557708740234 50.49333572387695 46.68040084838867 33.10683822631836 50.23353576660156 48.1732177734375 33.91178512573242 50.34400177001953 +WCW 47.64555740356445 33.075557708740234 50.49333572387695 46.68040084838867 33.10683822631836 50.23353576660156 47.751216888427734 33.867313385009766 51.094966888427734 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 46.20960998535156 34.230098724365234 49.565521240234375 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 45.35662841796875 34.91427230834961 49.88496398925781 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.22610855102539 34.317527770996094 48.66962814331055 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.11109161376953 34.746253967285156 50.20753479003906 diff --git a/tests/data/Clustering_results_OPTICS_QMSRC.dat b/tests/data/Clustering_results_OPTICS_QMSRC.dat new file mode 100644 index 0000000..d1875aa --- /dev/null +++ b/tests/data/Clustering_results_OPTICS_QMSRC.dat @@ -0,0 +1,55 @@ +10 +OPTICS +FCW HCW WCW +False +10 9 8 7 6 5 4 3 2 +0.1 0.05 0.01 0.005 0.001 0.0005 0.0001 1e-05 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +FCW 41.23272705078125 30.330909729003906 40.98818588256836 41.84754180908203 30.135316848754883 40.22415542602539 41.8143424987793 30.42807960510254 41.79582595825195 +FCW 46.2599983215332 36.27909469604492 47.799095153808594 46.40528106689453 36.8060188293457 46.96168899536133 45.53178024291992 35.63311004638672 47.5701789855957 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.57703399658203 29.518451690673828 46.76020050048828 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.7336540222168 29.52460289001465 46.767112731933594 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 46.796688079833984 29.28479766845703 46.859107971191406 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 47.06808090209961 29.681392669677734 46.571876525878906 +WCW 41.665000915527344 29.24900245666504 46.48900604248047 41.0498161315918 29.52010154724121 45.74869918823242 41.19739532470703 29.277957916259766 47.37247085571289 +WCW 41.665000915527344 29.24900245666504 46.48900604248047 40.7099609375 29.082006454467773 46.73397445678711 41.96389389038086 29.89197540283203 47.19416427612305 +WCW 41.665000915527344 29.24900245666504 46.48900604248047 42.456478118896484 29.792423248291016 46.76874542236328 41.70244216918945 28.300355911254883 46.80311965942383 +WCW 38.83000564575195 28.447998046875 45.4890022277832 39.38174057006836 27.9505558013916 44.81957244873047 39.46666717529297 28.566635131835938 46.2509651184082 +WCW 38.83000564575195 28.447998046875 45.4890022277832 39.38174057006836 27.9505558013916 44.81957244873047 38.23021697998047 29.054519653320312 44.967098236083984 +WCW 38.83000564575195 28.447998046875 45.4890022277832 38.62846374511719 27.78522300720215 44.76781463623047 38.21017837524414 28.277183532714844 46.25492477416992 +WCW 45.122222900390625 26.963335037231445 46.24555587768555 44.29435729980469 26.805862426757812 46.7839241027832 45.78128433227539 26.29950714111328 46.599063873291016 +WCW 45.122222900390625 26.963335037231445 46.24555587768555 44.29435729980469 26.805862426757812 46.7839241027832 45.202430725097656 26.323347091674805 45.48136901855469 +WCW 40.20499801635742 28.2450008392334 43.0989990234375 40.3472785949707 27.268484115600586 43.260772705078125 40.26316833496094 28.964096069335938 42.406524658203125 +WCW 40.20499801635742 28.2450008392334 43.0989990234375 40.3472785949707 27.268484115600586 43.260772705078125 40.49272918701172 28.11602020263672 42.1500129699707 +WCW 40.20499801635742 28.2450008392334 43.0989990234375 40.3472785949707 27.268484115600586 43.260772705078125 40.02693557739258 28.71464729309082 43.96371078491211 +WCW 40.20499801635742 28.2450008392334 43.0989990234375 39.460975646972656 28.22747802734375 42.43107223510742 40.79069137573242 28.9976863861084 42.79829025268555 +WCW 42.842002868652344 26.500003814697266 46.95899963378906 42.92344284057617 26.58877182006836 47.951717376708984 42.08521270751953 26.285057067871094 46.34169006347656 +WCW 42.842002868652344 26.500003814697266 46.95899963378906 42.149417877197266 25.77867889404297 46.95509338378906 42.48003387451172 27.35203742980957 46.5808219909668 +WCW 42.842002868652344 26.500003814697266 46.95899963378906 42.149417877197266 25.77867889404297 46.95509338378906 42.54817581176758 26.872167587280273 47.83943176269531 +WCW 42.842002868652344 26.500003814697266 46.95899963378906 42.149417877197266 25.77867889404297 46.95509338378906 42.920616149902344 26.714622497558594 47.93252944946289 +WCW 47.64555740356445 33.075557708740234 50.49333572387695 46.68040084838867 33.10683822631836 50.23353576660156 48.1732177734375 33.91178512573242 50.34400177001953 +WCW 47.64555740356445 33.075557708740234 50.49333572387695 46.68040084838867 33.10683822631836 50.23353576660156 47.751216888427734 33.867313385009766 51.094966888427734 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 46.20960998535156 34.230098724365234 49.565521240234375 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 45.019012451171875 33.98157501220703 48.63025665283203 45.35662841796875 34.91427230834961 49.88496398925781 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.22610855102539 34.317527770996094 48.66962814331055 +WCW 45.247276306152344 33.96091079711914 49.6036376953125 44.58808135986328 33.21979522705078 49.73096466064453 45.11109161376953 34.746253967285156 50.20753479003906 diff --git a/tests/data/Clustering_results_OPTICS_SC.dat b/tests/data/Clustering_results_OPTICS_SC.dat new file mode 100644 index 0000000..3c95370 --- /dev/null +++ b/tests/data/Clustering_results_OPTICS_SC.dat @@ -0,0 +1,34 @@ +10 +OPTICS +FCW HCW WCW +False +8 +0.05 +0.8 +True +0.85 +120.0 +0.4 +5.0 +17.0 +0.15 +15.0 +17.0 +20.0 +0.7 +0.03 +0.05 0.01 +0.05 0.001 +1 +0 +0 +0 +False +False +WCW 38.83000564575195 28.447998046875 45.4890022277832 39.38174057006836 27.9505558013916 44.81957244873047 39.46666717529297 28.566635131835938 46.2509651184082 +WCW 38.83000564575195 28.447998046875 45.4890022277832 39.38174057006836 27.9505558013916 44.81957244873047 38.23021697998047 29.054519653320312 44.967098236083984 +WCW 38.83000564575195 28.447998046875 45.4890022277832 38.62846374511719 27.78522300720215 44.76781463623047 38.21017837524414 28.277183532714844 46.25492477416992 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.57703399658203 29.518451690673828 46.76020050048828 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.107078552246094 28.24843406677246 45.991004943847656 46.7336540222168 29.52460289001465 46.767112731933594 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 46.796688079833984 29.28479766845703 46.859107971191406 +WCW 46.712730407714844 29.038183212280273 45.893638610839844 46.524566650390625 28.066614151000977 46.03733444213867 47.06808090209961 29.681392669677734 46.571876525878906 diff --git a/tests/data/sample_circular_only.dat b/tests/data/sample_circular_only_WCW.dat similarity index 100% rename from tests/data/sample_circular_only.dat rename to tests/data/sample_circular_only_WCW.dat diff --git a/tests/test_hydrogen_orientation.py b/tests/test_hydrogen_orientation.py index 2605223..b8eff16 100644 --- a/tests/test_hydrogen_orientation.py +++ b/tests/test_hydrogen_orientation.py @@ -10,246 +10,81 @@ make_ho_plots = 0 -def test_orientation_normalization(): - orientations = np.asarray([[1, 0, 0], [-0.25038 * 2, 0.96814764 * 2, 0]]) - orientations2 = np.asarray([[1, 0, 0], [-0.25038, 0.96814764, 0]]) - w1 = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, normalize_orientations=True - ) - w2 = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations2 - ) - print(w1, w2) - assert w1 == w2 - - -def test_orientation_shape(): - orientations = np.asarray([[[1]]]) - with pytest.raises(ValueError, match="Orientations have to be a 2D array"): - ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations - ) - - -def test_orientation_dimensions(): - orientations = np.asarray([[1, 0], [0, 1]]) - with pytest.raises(ValueError, match="Orientations must be vectors of dimension 3"): - ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations - ) - - -def test_orientation_valid_input(): - orientations = np.asarray([[1, 0, 0], [0, 1, 0]]) - ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations +def test_water_types(water_data): + orientations, data_label = water_data + res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( + orientations, debugH=make_ho_plots ) + if make_ho_plots > 0: + import matplotlib.pyplot as plt - -def test_orientation_size(): - orientations = np.asarray([[1, 0, 0]]) - with pytest.raises( - ValueError, - match=( - "Number of orientations must be even! " - "Each water molecule has 2 hydrogen atoms!" + plt.show() + if "not_conserved" in data_label: + assert len(res) == 0 + else: + assert len(res) > 0 + assert res[0][2] in data_label.upper() + + +@pytest.mark.parametrize( + ("orientations", "expected"), + [ + ( + np.asarray([[[1]]]), + pytest.raises(ValueError, match="Orientations have to be a 2D array"), ), - ): - ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations - ) - - -def test_orientation_array_odd(): - orientations = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - with pytest.raises( - ValueError, - match=( - "Number of orientations must be even! " - "Each water molecule has 2 hydrogen atoms!" + ( + np.asarray([[1, 0], [0, 1]]), + pytest.raises( + ValueError, match="Orientations must be vectors of dimension 3" + ), ), - ): + ( + np.asarray([[1, 0, 0]]), + pytest.raises( + ValueError, + match=( + "Number of orientations must be even!" + " Each water molecule has 2 hydrogen atoms!" + ), + ), + ), + ( + np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), + pytest.raises( + ValueError, + match=( + "Number of orientations must be even!" + " Each water molecule has 2 hydrogen atoms!" + ), + ), + ), + ], +) +def test_invalid_orientations(orientations, expected): + with expected: ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( orientations ) -def test_conserved_FCW(): - orientations = np.loadtxt("tests/data/conserved_sample_FCW.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "FCW" - - -def test_conserved_FCW2(): - orientations = np.loadtxt("tests/data/conserved_sample_FCW2.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "FCW" - - -def test_dispersed_HCW(): - orientations = np.loadtxt("tests/data/dispersed_sample_HCW.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "HCW" - - -def test_dispersed_HCW2(): - orientations = np.loadtxt("tests/data/dispersed_sample_HCW2.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "HCW" - - -def test_circular_HCW(): - orientations = np.loadtxt("tests/data/circ_sample_HCW.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "HCW" - - -def test_circular_HCW2(): - orientations = np.loadtxt("tests/data/circ_sample_HCW2.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "HCW" - - -def test_circular_HCW3(): - orientations = np.loadtxt("tests/data/circ_sample_HCW3.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "HCW" - - -def test_WCW(): - orientations = np.loadtxt("tests/data/sample_WCW.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "WCW" - - -def test_circular_only(): - orientations = np.loadtxt("tests/data/sample_circular_only.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "WCW" - - -def test_dispersed_WCW(): - orientations = np.loadtxt("tests/data/dispersed_sample_WCW.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) > 0 - assert res[0][2] == "WCW" - - -def test_2x2_WCW(): - orientations = np.loadtxt("tests/data/2_by_2_WCW.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, +@pytest.mark.parametrize("normalize_orientations", [True, False]) +def test_orientation_normalization( + orientations_normalized, orientations_not_normalized, normalize_orientations +): + w1 = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( + orientations_normalized + if normalize_orientations + else orientations_not_normalized ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) == 2 - assert res[0][2] == "WCW" - - -def test_not_conserved(): - orientations = np.loadtxt("tests/data/dispersed_sample_not_conserved.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, + w2 = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( + orientations_not_normalized, normalize_orientations=normalize_orientations ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) == 0 + assert w1 == w2 -def test_not_conserved2(): - orientations = np.loadtxt("tests/data/not_conserved.dat") - res = ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( - orientations, - debugH=make_ho_plots, - verbose=2, +def test_orientation_valid_input(): + orientations = np.asarray([[1, 0, 0], [0, 1, 0]]) + ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( + orientations ) - if make_ho_plots > 0: - import matplotlib.pyplot as plt - - plt.show() - assert len(res) == 0 diff --git a/tests/test_utils.py b/tests/test_utils.py index 5e1a661..b9f6393 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,99 +13,89 @@ ) -@pytest.fixture(autouse=True) -def _pymol_skip(): - pytest.importorskip("pymol") - - -def test_append_new_result(): - # Create a temporary file using with for writing and reading +@pytest.mark.parametrize( + ("water_type", "waterO", "waterH1", "waterH2", "expected"), + [ + ("FCW", [1, 2, 3], [4, 5, 6], [7, 8, 9], "FCW 1 2 3 4 5 6 7 8 9\n"), + ("HCW", [10, 11, 12], None, None, "HCW 10 11 12\n"), + ], +) +def test_append_new_result(water_type, waterO, waterH1, waterH2, expected): with tempfile.NamedTemporaryFile(mode="w+", delete=True) as f: - # Call the function with some test data - _append_new_result("FCW", [1, 2, 3], [4, 5, 6], [7, 8, 9], f.name) + _append_new_result(water_type, waterO, waterH1, waterH2, f.name) - # Read the contents of the file - with open(f.name) as file: - contents = file.read() + # Ensure file pointer is at the beginning + f.seek(0) + contents = f.read() - # Check that the contents are as expected - expected = "FCW 1 2 3 4 5 6 7 8 9\n" assert contents == expected - # Call the function again with different test data - _append_new_result("HCW", [10, 11, 12], None, None, f.name) - # Read the contents of the file again - with open(f.name) as file: - contents = file.read() +def test_append_multiple_results(): + with tempfile.NamedTemporaryFile(mode="w+", delete=True) as f: + # First append + _append_new_result("FCW", [1, 2, 3], [4, 5, 6], [7, 8, 9], f.name) + # Second append + _append_new_result("HCW", [10, 11, 12], None, None, f.name) - # Check that the contents are as expected - expected += "HCW 10 11 12\n" + # Ensure file pointer is at the beginning + f.seek(0) + contents = f.read() + expected = "FCW 1 2 3 4 5 6 7 8 9\nHCW 10 11 12\n" assert contents == expected -def test_read_results_with_hydrogens(): - water_type, waterO, waterH1, waterH2 = read_results( - "tests/data/merged_new_clustering_results.dat", - ) - assert len(water_type) == 20 - assert len(waterO) == 20 - assert len(waterH1) == 20 - assert len(waterH2) == 20 - assert water_type[0] == "FCW" - npt.assert_allclose( - waterO[0], - np.array( - [ - -8.498636033210043905e00, - -8.528824215611816584e00, - -8.558124911970363513e00, - ] - ), - ) - npt.assert_allclose( - waterH1[0], - np.array( - [ - -8.612760033927649772e00, - -8.398256579537193289e00, - -9.542974039943826980e00, - ] - ), - ) - npt.assert_allclose( - waterH2[0], - np.array( - [ - -7.847825970288877961e00, - -7.856730538101417416e00, - -8.204944574676375169e00, - ] - ), - ) +# Fixture for reading results from different files +@pytest.fixture( + params=[ + { + "filename": "tests/data/merged_new_clustering_results.dat", + "has_hydrogens": True, + }, + { + "filename": "tests/data/merged_new_clustering_results_noH.dat", + "has_hydrogens": False, + }, + ] +) +def water_results(request): + # Read results from the specified file + water_type, waterO, waterH1, waterH2 = read_results(request.param["filename"]) + return water_type, waterO, waterH1, waterH2, request.param["has_hydrogens"] -def test_read_results_without_hydrogens(): - water_type, waterO, waterH1, waterH2 = read_results( - "tests/data/merged_new_clustering_results_noH.dat", - ) +# Parametrized test to handle both scenarios +def test_read_results(water_results): + water_type, waterO, waterH1, waterH2, has_hydrogens = water_results assert len(water_type) == 20 assert len(waterO) == 20 assert len(waterH1) == 20 assert len(waterH2) == 20 - assert water_type[0] == "O_clust" - npt.assert_allclose( - waterO[0], - np.array( - [ - -8.498636033210043905e00, - -8.528824215611816584e00, - -8.558124911970363513e00, - ] - ), + + # Expected first type based on whether the dataset includes hydrogens + expected_first_type = "FCW" if has_hydrogens else "O_clust" + assert water_type[0] == expected_first_type + + # Expected coordinates of waterO + expected_waterO = np.array( + [-8.498636033210043905, -8.528824215611816584, -8.558124911970363513] ) - assert waterH1[0] == [] - assert waterH2[0] == [] + npt.assert_allclose(waterO[0], expected_waterO, atol=1e-6) + + if has_hydrogens: + # Expected coordinates for waterH1 and waterH2 if hydrogens are present + expected_waterH1 = np.array( + [-8.612760033927649772, -8.398256579537193289, -9.542974039943826980] + ) + expected_waterH2 = np.array( + [-7.847825970288877961, -7.856730538101417416, -8.204944574676375169] + ) + npt.assert_allclose(waterH1[0], expected_waterH1, atol=1e-6) + npt.assert_allclose(waterH2[0], expected_waterH2, atol=1e-6) + else: + # Ensure waterH1 and waterH2 are empty if hydrogens are not present + assert waterH1[0] == [] + assert waterH2[0] == [] def test_visualise_pymol(): @@ -142,32 +132,19 @@ def test_visualise_pymol2(): ) -def test_visualise_pymol3(): - visualise_pymol( - *read_results( - "tests/data/merged_new_clustering_results.dat", - ), - aligned_protein=None, - lunch_pymol=False, - ) - - -def test_visualise_pymol4(): - visualise_pymol( - *read_results( - "tests/data/merged_new_clustering_results.dat", - ), - aligned_protein="tests/data/aligned.pdb", - lunch_pymol=False, - ) - - -def test_visualise_pymol5(): +# Visualise pymol tests +@pytest.mark.parametrize( + ("output_file", "align_file"), + [ + ("tests/data/merged_new_clustering_results.dat", None), + ("tests/data/merged_new_clustering_results.dat", "tests/data/aligned.pdb"), + ("tests/data/merged_new_clustering_results_noH.dat", "tests/data/aligned.pdb"), + ], +) +def test_visualise_pymol_with_align_protein(output_file, align_file): visualise_pymol( - *read_results( - "tests/data/merged_new_clustering_results_noH.dat", - ), - aligned_protein="tests/data/aligned.pdb", + *read_results(output_file), + aligned_protein=align_file, lunch_pymol=False, ) @@ -180,4 +157,4 @@ def test_visualise_nglview(): aligned_protein=None, crystal_waters="3T74", ) - assert type(vv) is nglview.NGLWidget + assert isinstance(vv, nglview.NGLWidget) diff --git a/tests/test_water_clustering.py b/tests/test_water_clustering.py index 3f64def..ade95a8 100644 --- a/tests/test_water_clustering.py +++ b/tests/test_water_clustering.py @@ -12,66 +12,24 @@ from ConservedWaterSearch.water_clustering import WaterClustering -def test_save_results_water_types(): +def test_save_results(water_clustering_setup): + wc, onlyO = water_clustering_setup with tempfile.NamedTemporaryFile(mode="w+", delete=True) as f: - wc = WaterClustering(10) - wc._waterO.append(np.asarray([0.0, 0.0, 0.0])) - wc._waterO.append(np.asarray([0.0, 2.0, 0.0])) - wc._waterH1.append(np.asarray([1.0, 0.0, 0.0])) - wc._waterH1.append(np.asarray([0.0, 0.8, 0.5])) - wc._waterH2.append(np.asarray([2.5, 2.0, 2.8])) - wc._waterH2.append(np.asarray([0.0, 3.0, 0.0])) - wc._water_type.append("FCW") - wc._water_type.append("HCW") wc.save_results(f.name) a, b, c, d = read_results(f.name) - for i, j in zip(a, wc.water_type): - assert i == j - for i, j in zip(b, wc.waterO): - npt.assert_allclose(i, j) - for i, j in zip(c, wc.waterH1): - npt.assert_allclose(i, j) - for i, j in zip(d, wc.waterH2): - npt.assert_allclose(i, j) - -def test_save_results_onlyO(): - with tempfile.NamedTemporaryFile(mode="w+", delete=True) as f: - wc = WaterClustering(10) - wc._waterO.append(np.asarray([0.0, 0.0, 0.0])) - wc._waterO.append(np.asarray([0.0, 2.0, 0.0])) - wc._water_type.append("O_clust") - wc._water_type.append("O_clust") - wc.save_results(f.name) - a, b, _, _ = read_results(f.name) + # Assertions for both scenarios for i, j in zip(a, wc.water_type): assert i == j for i, j in zip(b, wc.waterO): npt.assert_allclose(i, j) - -def test_delete_data_onlyO(): - with tempfile.NamedTemporaryFile(mode="w+", delete=True) as dat: - with tempfile.NamedTemporaryFile(mode="w+", delete=True) as res: - wc = WaterClustering(10, output_file=res, restart_data_file=dat) - Odata = np.asarray([[0.1, 0.1, 0.1], [1.5, 1.6, 1.7], [1.9, 5.8, 5.6]]) - Onew, _, _ = wc._delete_data([0, 2], Odata=Odata) - npt.assert_allclose(Onew[0], Odata[1]) - assert os.path.isfile(dat.name) - - -def test_delete_data_all_waters(): - with tempfile.NamedTemporaryFile(mode="w+", delete=True) as dat: - with tempfile.NamedTemporaryFile(mode="w+", delete=True) as res: - wc = WaterClustering(10, output_file=res, restart_data_file=dat) - Odata = np.asarray([[0.1, 0.1, 0.1], [1.5, 1.6, 1.7], [1.9, 5.8, 5.6]]) - H1 = np.asarray([[0.8, 0.5, 0.8], [1.4, 0.6, 3.7], [3.9, 5.1, 5.9]]) - H2 = np.asarray([[0.4, 0.7, 0.1], [1.7, 3.6, 2.7], [1.8, 3.8, 5.1]]) - Onew, H1new, H2new = wc._delete_data([1, 2], Odata, H1, H2) - npt.assert_allclose(Onew[0], Odata[0]) - npt.assert_allclose(H1new[0], H1[0]) - npt.assert_allclose(H2new[0], H2[0]) - assert os.path.isfile(dat.name) + if not onlyO: + # Additional assertions for hydrogen presence + for i, j in zip(c, wc.waterH1): + npt.assert_allclose(i, j) + for i, j in zip(d, wc.waterH2): + npt.assert_allclose(i, j) def test_delete_data_not_restart(): @@ -84,6 +42,22 @@ def test_delete_data_not_restart(): assert os.path.isfile(dat.name) +def test_delete_data_onlyO(water_clustering_setup_for_deletion): + wc, dat_name, Odata, _, _ = water_clustering_setup_for_deletion + Onew, _, _ = wc._delete_data([0, 2], Odata=Odata) + npt.assert_allclose(Onew, np.asarray([Odata[1]])) + assert os.path.isfile(dat_name) + + +def test_delete_data_all_waters(water_clustering_setup_for_deletion): + wc, dat_name, Odata, H1, H2 = water_clustering_setup_for_deletion + Onew, H1new, H2new = wc._delete_data([1, 2], Odata, H1, H2) + npt.assert_allclose(Onew, np.asarray([Odata[0]])) + npt.assert_allclose(H1new, np.asarray([H1[0]])) + npt.assert_allclose(H2new, np.asarray([H2[0]])) + assert os.path.isfile(dat_name) + + def test_save_clustering_options(): ca = "OPTICS" whichH = ["onlyO"] @@ -203,145 +177,95 @@ def test_restart_cluster_and_create_class_from_file(): ) -def test_single_clustering_OPTICS(): - Nsnap = 20 - Opos = np.loadtxt("tests/data/testdataO.dat") - Hpos = np.loadtxt("tests/data/testdataH.dat") - wc = WaterClustering(Nsnap) - wc.single_clustering(*get_orientations_from_positions(Opos, Hpos)) - a, b, c, d = read_results("tests/data/Single_OPTICS.dat") - npt.assert_allclose(b, wc.waterO) - npt.assert_allclose(c, wc.waterH1) - npt.assert_allclose(d, wc.waterH2) - assert all(wc.water_type[i] == a[i] for i in range(len(wc.water_type))) - - -def test_single_clustering_HDBSCAN(): - Nsnap = 20 - Opos = np.loadtxt("tests/data/testdataO.dat") - Hpos = np.loadtxt("tests/data/testdataH.dat") - wc = WaterClustering(Nsnap) - wc.single_clustering( - *get_orientations_from_positions(Opos, Hpos), clustering_algorithm="HDBSCAN" - ) - a, b, c, d = read_results("tests/data/Single_HDBSCAN.dat") - assert all(wc.water_type[i] == a[i] for i in range(len(wc.water_type))) - # sort wc.waterO according to b - # b is xyz coordinates of water Oxygen. Sort them according to x - b = np.asarray(b) - b = b[b[:, 0].argsort()] - c = np.asarray(c) - c = c[c[:, 0].argsort()] - d = np.asarray(d) - d = d[d[:, 0].argsort()] - # now dothe same for water - b1 = np.asarray(wc.waterO) - b1 = b1[b1[:, 0].argsort()] - c1 = np.asarray(wc.waterH1) - c1 = c1[c1[:, 0].argsort()] - d1 = np.asarray(wc.waterH2) - d1 = d1[d1[:, 0].argsort()] - npt.assert_allclose(b, b1) - npt.assert_allclose(c, c1) - npt.assert_allclose(d, d1) - - -def test_multistage_reclustering_OPTICS(): - Nsnap = 20 - Opos = np.loadtxt("tests/data/testdataO.dat") - Hpos = np.loadtxt("tests/data/testdataH.dat") - wc = WaterClustering(Nsnap) - wc.multi_stage_reclustering(*get_orientations_from_positions(Opos, Hpos)) - a, b, c, d = read_results("tests/data/MSR_OPTICS.dat") - npt.assert_allclose(b, wc.waterO) - npt.assert_allclose(c, wc.waterH1) - npt.assert_allclose(d, wc.waterH2) - assert all(wc.water_type[i] == a[i] for i in range(len(wc.water_type))) +def sort_data_by_x(data): + data = np.asarray(data) + return data[data[:, 0].argsort()] -def test_multistage_reclustering_HDBSCAN(): - Nsnap = 20 - Opos = np.loadtxt("tests/data/testdataO.dat") - Hpos = np.loadtxt("tests/data/testdataH.dat") - wc = WaterClustering(Nsnap) - wc.multi_stage_reclustering( - *get_orientations_from_positions(Opos, Hpos), clustering_algorithm="HDBSCAN" - ) - a, b, c, d = read_results("tests/data/MSR_HDBSCAN.dat") +def compare_results(wc, result_file, tol=1e-4): + a, b, c, d = read_results(result_file) assert all(wc.water_type[i] == a[i] for i in range(len(wc.water_type))) - tol = 1e-1 - # b is xyz coordinates of water Oxygen. Sort them according to x - b = np.asarray(b) - b = b[b[:, 0].argsort()] - c = np.asarray(c) - c = c[c[:, 0].argsort()] - d = np.asarray(d) - d = d[d[:, 0].argsort()] - # now dothe same for water - b1 = np.asarray(wc.waterO) - b1 = b1[b1[:, 0].argsort()] - c1 = np.asarray(wc.waterH1) - c1 = c1[c1[:, 0].argsort()] - d1 = np.asarray(wc.waterH2) - d1 = d1[d1[:, 0].argsort()] - npt.assert_allclose(b, b1, atol=tol) - npt.assert_allclose(c, c1, atol=tol) - npt.assert_allclose(d, d1, atol=tol) - - -def test_quick_multistage_reclustering_OPTICS(): + npt.assert_allclose(sort_data_by_x(b), sort_data_by_x(wc.waterO), atol=tol) + npt.assert_allclose(sort_data_by_x(c), sort_data_by_x(wc.waterH1), atol=tol) + npt.assert_allclose(sort_data_by_x(d), sort_data_by_x(wc.waterH2), atol=tol) + + +@pytest.mark.parametrize( + ("clustering_func", "algorithm", "result_file", "tol"), + [ + ("single_clustering", None, "tests/data/Single_OPTICS.dat", 1e-4), + ("single_clustering", "HDBSCAN", "tests/data/Single_HDBSCAN.dat", 1e-4), + ("multi_stage_reclustering", None, "tests/data/MSR_OPTICS.dat", 1e-4), + ("multi_stage_reclustering", "HDBSCAN", "tests/data/MSR_HDBSCAN.dat", 1e-1), + ("quick_multi_stage_reclustering", None, "tests/data/MSR_OPTICS.dat", 1e-4), + ( + "quick_multi_stage_reclustering", + "HDBSCAN", + "tests/data/MSR_HDBSCAN.dat", + 1e-1, + ), + ], +) +def test_clustering_methods( + water_clustering_data, clustering_func, algorithm, result_file, tol +): Nsnap = 20 - Opos = np.loadtxt("tests/data/testdataO.dat") - Hpos = np.loadtxt("tests/data/testdataH.dat") + Opos, Hpos = water_clustering_data wc = WaterClustering(Nsnap) - wc.quick_multi_stage_reclustering(*get_orientations_from_positions(Opos, Hpos)) - a, b, c, d = read_results("tests/data/MSR_OPTICS.dat") - tol = 1e-4 - # b is xyz coordinates of water Oxygen. Sort them according to x - b = np.asarray(b) - b = b[b[:, 0].argsort()] - c = np.asarray(c) - c = c[c[:, 0].argsort()] - d = np.asarray(d) - d = d[d[:, 0].argsort()] - # now do the same for water - b1 = np.asarray(wc.waterO) - b1 = b1[b1[:, 0].argsort()] - c1 = np.asarray(wc.waterH1) - c1 = c1[c1[:, 0].argsort()] - d1 = np.asarray(wc.waterH2) - d1 = d1[d1[:, 0].argsort()] - npt.assert_allclose(b, b1, atol=tol) - npt.assert_allclose(c, c1, atol=tol) - npt.assert_allclose(d, d1, atol=tol) - assert all(wc.water_type[i] == a[i] for i in range(len(wc.water_type))) - - -def test_quick_multistage_reclustering_HDBSCAN(): - Nsnap = 20 - Opos = np.loadtxt("tests/data/testdataO.dat") - Hpos = np.loadtxt("tests/data/testdataH.dat") + func = getattr(wc, clustering_func) + if algorithm: + func( + *get_orientations_from_positions(Opos, Hpos), clustering_algorithm=algorithm + ) + else: + func(*get_orientations_from_positions(Opos, Hpos)) + compare_results(wc, result_file, tol) + + +QMSRC_HDBSCAN_results_file = "tests/data/Clustering_results_HDBSCAN_QMSRC.dat" + + +@pytest.mark.parametrize( + ("clustering_func", "algorithm", "result_file", "tol"), + [ + ("single_clustering", "OPTICS", "SC", 1e-4), + ("single_clustering", "HDBSCAN", "SC", 1e-4), + ("multi_stage_reclustering", "OPTICS", "MSRC", 1e-4), + ("multi_stage_reclustering", "HDBSCAN", "MSRC", 1e-4), + ("quick_multi_stage_reclustering", "OPTICS", "QMSRC", 1e-4), + ("quick_multi_stage_reclustering", "HDBSCAN", "QMSRC", 1e-4), + ], +) +def test_from_files_input_clustering(clustering_func, algorithm, result_file, tol): + Nsnap = 10 + data = np.loadtxt("tests/data/CWS_input_3T73.dat") + O_coords = data[:, :3] + H1 = data[:, 3:6] + H2 = data[:, 6:9] wc = WaterClustering(Nsnap) - wc.quick_multi_stage_reclustering( - *get_orientations_from_positions(Opos, Hpos), clustering_algorithm="HDBSCAN" - ) - a, b, c, d = read_results("tests/data/MSR_HDBSCAN.dat") - assert all(wc.water_type[i] == a[i] for i in range(len(wc.water_type))) - tol = 1e-1 - # b is xyz coordinates of water Oxygen. Sort them according to x - b = np.asarray(b) - b = b[b[:, 0].argsort()] - c = np.asarray(c) - c = c[c[:, 0].argsort()] - d = np.asarray(d) - d = d[d[:, 0].argsort()] - # now do the same for water - b1 = np.asarray(wc.waterO) - b1 = b1[b1[:, 0].argsort()] - c1 = np.asarray(wc.waterH1) - c1 = c1[c1[:, 0].argsort()] - d1 = np.asarray(wc.waterH2) - d1 = d1[d1[:, 0].argsort()] - npt.assert_allclose(b, b1, atol=tol) - npt.assert_allclose(c, c1, atol=tol) - npt.assert_allclose(d, d1, atol=tol) + # make temporary result file name but dont create it + temp_file_output_results = tempfile.NamedTemporaryFile(mode="w+", delete=True).name + func = getattr(wc, clustering_func) + func(O_coords, H1, H2, clustering_algorithm=algorithm) + wc.save_results(temp_file_output_results) + solution = f"tests/data/Clustering_results_{algorithm}_{result_file}.dat" + + # Check if the temp file is the same as original files + with open(temp_file_output_results) as f1, open(solution) as f2: + data1 = f1.read().split("\n") + data2 = f2.read().split("\n") + assert len(data1) == len(data2) + for l1, l2 in zip(data1[27:], data2[27:]): + computed_l1 = l1.strip().split() + original_l2 = l2.strip().split() + if len(computed_l1) == 0 and len(original_l2) == 0: + continue + # first element is STRING - compare these + assert computed_l1[0] == original_l2[0] + # rest are floats + npt.assert_allclose( + list(map(float, computed_l1[1:])), + list(map(float, original_l2[1:])), + rtol=1e-5, + atol=1e-5, + )