royallgroup / TCC

The Topological Cluster Classification algorithm
https://royallgroup.github.io/TCC/
GNU General Public License v3.0
12 stars 5 forks source link

Pytest Failure #107

Closed yangyushi closed 5 years ago

yangyushi commented 5 years ago

I successfully built TCC on my Mac but I got 6 failed test. Here is the message I got.

$ pytest
========================================================= test session starts ==========================================================
platform darwin -- Python 3.7.0, pytest-3.7.4, py-1.6.0, pluggy-0.7.1
rootdir: /Users/yushi/OneDrive/Learn/GitHub/royallGroup/TCC, inifile:
collected 88 items                                                                                                                     

test/file_readers/test_file_readers.py ........                                                                                  [  9%]
test/integration_tests/test_tcc_integration.py .....                                                                             [ 14%]
test/net_tcc_script/test_net_script.py .                                                                                         [ 15%]
test/unit_tests/test_tcc_clusters.py .F.F.F.......................F......F.............................F.......                  [100%]

=============================================================== FAILURES ===============================================================
_____________________________________ test_voronoi_long_clusters[test/unit_tests/clusters/6A.xyz] ______________________________________

path = 'test/unit_tests/clusters/6A.xyz'

    @pytest.mark.parametrize('path', structures_to_test)
    def test_voronoi_long_clusters(path):
>       run_unit_test(path, "voronoi_long")

test/unit_tests/test_tcc_clusters.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cluster_path = 'test/unit_tests/clusters/6A.xyz', bond_type = 'voronoi_long'

    def run_unit_test(cluster_path, bond_type):
        """
        Run a unit test on a single structure
        Test will fail if the number of detected clusters does not match known composition of a given structure.
        :param cluster_path: path to isolated structure geometry to run TCC on
        :param bond_type: the type of bond to be used by the TCC
        """

        xyz_frames = xyz.read(cluster_path)
        particle_coordinates = next(xyz_frames).particle_coordinates
        cluster_name = os.path.split(cluster_path)[1].rstrip(".xyz")

        tcc_parameters = wrapper.TCCWrapper()
        tcc_parameters.input_parameters['Run']['xyzfilename'] = 'sample.xyz'
        if bond_type == "voronoi_short":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 0.82
        elif bond_type == "voronoi_long":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 1
        else:
            print("Unknown bond type.")
            raise TypeError()

        tcc_result_report = tcc_parameters.run((100., 100., 100.), particle_coordinates)

        report = pandas.DataFrame(tcc_result_report['Number of clusters'])

        try:
            if bond_type == "voronoi_short":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_short_clusters[cluster_name]
            elif bond_type == "voronoi_long":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_long_clusters[cluster_name]
            else:
                print("Unknown bond type.")
                raise TypeError()
        except AssertionError:
            print(report)
>           raise AssertionError from None
E           AssertionError

test/unit_tests/test_tcc_clusters.py:50: AssertionError
--------------------------------------------------------- Captured stdout call ---------------------------------------------------------
              Number of clusters
Cluster type                    
sp3a                          20
sp3b                           0
sp3c                           0
sp4a                           0
sp4b                           0
sp4c                           0
sp5a                           0
sp5b                           0
sp5c                           0
6A                             0
6Z                             0
7K                             0
7T_a                           0
7T_s                           0
8A                             0
8B                             0
8K                             0
9A                             0
9B                             0
9K                             0
10A                            0
10B                            0
10K                            0
10W                            0
11A                            0
11B                            0
11C                            0
11E                            0
11F                            0
11W                            0
12A                            0
12B                            0
12D                            0
12E                            0
12K                            0
13A                            0
13B                            0
13K                            0
FCC                            0
HCP                            0
BCC_9                          0
_____________________________________ test_voronoi_long_clusters[test/unit_tests/clusters/FCC.xyz] _____________________________________

path = 'test/unit_tests/clusters/FCC.xyz'

    @pytest.mark.parametrize('path', structures_to_test)
    def test_voronoi_long_clusters(path):
>       run_unit_test(path, "voronoi_long")

test/unit_tests/test_tcc_clusters.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cluster_path = 'test/unit_tests/clusters/FCC.xyz', bond_type = 'voronoi_long'

    def run_unit_test(cluster_path, bond_type):
        """
        Run a unit test on a single structure
        Test will fail if the number of detected clusters does not match known composition of a given structure.
        :param cluster_path: path to isolated structure geometry to run TCC on
        :param bond_type: the type of bond to be used by the TCC
        """

        xyz_frames = xyz.read(cluster_path)
        particle_coordinates = next(xyz_frames).particle_coordinates
        cluster_name = os.path.split(cluster_path)[1].rstrip(".xyz")

        tcc_parameters = wrapper.TCCWrapper()
        tcc_parameters.input_parameters['Run']['xyzfilename'] = 'sample.xyz'
        if bond_type == "voronoi_short":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 0.82
        elif bond_type == "voronoi_long":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 1
        else:
            print("Unknown bond type.")
            raise TypeError()

        tcc_result_report = tcc_parameters.run((100., 100., 100.), particle_coordinates)

        report = pandas.DataFrame(tcc_result_report['Number of clusters'])

        try:
            if bond_type == "voronoi_short":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_short_clusters[cluster_name]
            elif bond_type == "voronoi_long":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_long_clusters[cluster_name]
            else:
                print("Unknown bond type.")
                raise TypeError()
        except AssertionError:
            print(report)
>           raise AssertionError from None
E           AssertionError

test/unit_tests/test_tcc_clusters.py:50: AssertionError
--------------------------------------------------------- Captured stdout call ---------------------------------------------------------
              Number of clusters
Cluster type                    
sp3a                           4
sp3b                          24
sp3c                          16
sp4a                           0
sp4b                           3
sp4c                           2
sp5a                           0
sp5b                           6
sp5c                           0
6A                             2
6Z                            14
7K                            12
7T_a                          16
7T_s                          12
8A                             0
8B                             0
8K                             2
9A                             0
9B                             0
9K                             0
10A                            0
10B                            0
10K                            0
10W                            0
11A                            0
11B                            0
11C                            0
11E                            0
11F                            0
11W                            0
12A                            0
12B                            0
12D                            0
12E                            0
12K                            0
13A                            0
13B                            0
13K                            0
FCC                            1
HCP                            0
BCC_9                          0
____________________________________ test_voronoi_long_clusters[test/unit_tests/clusters/sp4c.xyz] _____________________________________

path = 'test/unit_tests/clusters/sp4c.xyz'

    @pytest.mark.parametrize('path', structures_to_test)
    def test_voronoi_long_clusters(path):
>       run_unit_test(path, "voronoi_long")

test/unit_tests/test_tcc_clusters.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cluster_path = 'test/unit_tests/clusters/sp4c.xyz', bond_type = 'voronoi_long'

    def run_unit_test(cluster_path, bond_type):
        """
        Run a unit test on a single structure
        Test will fail if the number of detected clusters does not match known composition of a given structure.
        :param cluster_path: path to isolated structure geometry to run TCC on
        :param bond_type: the type of bond to be used by the TCC
        """

        xyz_frames = xyz.read(cluster_path)
        particle_coordinates = next(xyz_frames).particle_coordinates
        cluster_name = os.path.split(cluster_path)[1].rstrip(".xyz")

        tcc_parameters = wrapper.TCCWrapper()
        tcc_parameters.input_parameters['Run']['xyzfilename'] = 'sample.xyz'
        if bond_type == "voronoi_short":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 0.82
        elif bond_type == "voronoi_long":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 1
        else:
            print("Unknown bond type.")
            raise TypeError()

        tcc_result_report = tcc_parameters.run((100., 100., 100.), particle_coordinates)

        report = pandas.DataFrame(tcc_result_report['Number of clusters'])

        try:
            if bond_type == "voronoi_short":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_short_clusters[cluster_name]
            elif bond_type == "voronoi_long":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_long_clusters[cluster_name]
            else:
                print("Unknown bond type.")
                raise TypeError()
        except AssertionError:
            print(report)
>           raise AssertionError from None
E           AssertionError

test/unit_tests/test_tcc_clusters.py:50: AssertionError
--------------------------------------------------------- Captured stdout call ---------------------------------------------------------
              Number of clusters
Cluster type                    
sp3a                          20
sp3b                           0
sp3c                           0
sp4a                           0
sp4b                           0
sp4c                           0
sp5a                           0
sp5b                           0
sp5c                           0
6A                             0
6Z                             0
7K                             0
7T_a                           0
7T_s                           0
8A                             0
8B                             0
8K                             0
9A                             0
9B                             0
9K                             0
10A                            0
10B                            0
10K                            0
10W                            0
11A                            0
11B                            0
11C                            0
11E                            0
11F                            0
11W                            0
12A                            0
12B                            0
12D                            0
12E                            0
12K                            0
13A                            0
13B                            0
13K                            0
FCC                            0
HCP                            0
BCC_9                          0
_____________________________________ test_voronoi_long_clusters[test/unit_tests/clusters/12E.xyz] _____________________________________

path = 'test/unit_tests/clusters/12E.xyz'

    @pytest.mark.parametrize('path', structures_to_test)
    def test_voronoi_long_clusters(path):
>       run_unit_test(path, "voronoi_long")

test/unit_tests/test_tcc_clusters.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cluster_path = 'test/unit_tests/clusters/12E.xyz', bond_type = 'voronoi_long'

    def run_unit_test(cluster_path, bond_type):
        """
        Run a unit test on a single structure
        Test will fail if the number of detected clusters does not match known composition of a given structure.
        :param cluster_path: path to isolated structure geometry to run TCC on
        :param bond_type: the type of bond to be used by the TCC
        """

        xyz_frames = xyz.read(cluster_path)
        particle_coordinates = next(xyz_frames).particle_coordinates
        cluster_name = os.path.split(cluster_path)[1].rstrip(".xyz")

        tcc_parameters = wrapper.TCCWrapper()
        tcc_parameters.input_parameters['Run']['xyzfilename'] = 'sample.xyz'
        if bond_type == "voronoi_short":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 0.82
        elif bond_type == "voronoi_long":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 1
        else:
            print("Unknown bond type.")
            raise TypeError()

        tcc_result_report = tcc_parameters.run((100., 100., 100.), particle_coordinates)

        report = pandas.DataFrame(tcc_result_report['Number of clusters'])

        try:
            if bond_type == "voronoi_short":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_short_clusters[cluster_name]
            elif bond_type == "voronoi_long":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_long_clusters[cluster_name]
            else:
                print("Unknown bond type.")
                raise TypeError()
        except AssertionError:
            print(report)
>           raise AssertionError from None
E           AssertionError

test/unit_tests/test_tcc_clusters.py:50: AssertionError
--------------------------------------------------------- Captured stdout call ---------------------------------------------------------
              Number of clusters
Cluster type                    
sp3a                           9
sp3b                          18
sp3c                           3
sp4a                           0
sp4b                           0
sp4c                           6
sp5a                           0
sp5b                           0
sp5c                           0
6A                             2
6Z                             0
7K                             0
7T_a                           0
7T_s                           0
8A                             0
8B                             0
8K                             0
9A                             0
9B                             0
9K                             3
10A                            0
10B                            0
10K                            0
10W                            0
11A                            0
11B                            0
11C                            0
11E                            0
11F                            3
11W                            0
12A                            0
12B                            0
12D                            0
12E                            3
12K                            0
13A                            0
13B                            0
13K                            0
FCC                            0
HCP                            0
BCC_9                          0
_____________________________________ test_voronoi_long_clusters[test/unit_tests/clusters/7K.xyz] ______________________________________

path = 'test/unit_tests/clusters/7K.xyz'

    @pytest.mark.parametrize('path', structures_to_test)
    def test_voronoi_long_clusters(path):
>       run_unit_test(path, "voronoi_long")

test/unit_tests/test_tcc_clusters.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cluster_path = 'test/unit_tests/clusters/7K.xyz', bond_type = 'voronoi_long'

    def run_unit_test(cluster_path, bond_type):
        """
        Run a unit test on a single structure
        Test will fail if the number of detected clusters does not match known composition of a given structure.
        :param cluster_path: path to isolated structure geometry to run TCC on
        :param bond_type: the type of bond to be used by the TCC
        """

        xyz_frames = xyz.read(cluster_path)
        particle_coordinates = next(xyz_frames).particle_coordinates
        cluster_name = os.path.split(cluster_path)[1].rstrip(".xyz")

        tcc_parameters = wrapper.TCCWrapper()
        tcc_parameters.input_parameters['Run']['xyzfilename'] = 'sample.xyz'
        if bond_type == "voronoi_short":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 0.82
        elif bond_type == "voronoi_long":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 1
        else:
            print("Unknown bond type.")
            raise TypeError()

        tcc_result_report = tcc_parameters.run((100., 100., 100.), particle_coordinates)

        report = pandas.DataFrame(tcc_result_report['Number of clusters'])

        try:
            if bond_type == "voronoi_short":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_short_clusters[cluster_name]
            elif bond_type == "voronoi_long":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_long_clusters[cluster_name]
            else:
                print("Unknown bond type.")
                raise TypeError()
        except AssertionError:
            print(report)
>           raise AssertionError from None
E           AssertionError

test/unit_tests/test_tcc_clusters.py:50: AssertionError
--------------------------------------------------------- Captured stdout call ---------------------------------------------------------
              Number of clusters
Cluster type                    
sp3a                           7
sp3b                           0
sp3c                          15
sp4a                           0
sp4b                           0
sp4c                           0
sp5a                           0
sp5b                           0
sp5c                           0
6A                             0
6Z                             0
7K                             3
7T_a                           0
7T_s                           0
8A                             0
8B                             0
8K                             0
9A                             0
9B                             0
9K                             0
10A                            0
10B                            0
10K                            0
10W                            0
11A                            0
11B                            0
11C                            0
11E                            0
11F                            0
11W                            0
12A                            0
12B                            0
12D                            0
12E                            0
12K                            0
13A                            0
13B                            0
13K                            0
FCC                            0
HCP                            0
BCC_9                          0
____________________________________ test_voronoi_short_clusters[test/unit_tests/clusters/12E.xyz] _____________________________________

path = 'test/unit_tests/clusters/12E.xyz'

    @pytest.mark.parametrize('path', structures_to_test)
    def test_voronoi_short_clusters(path):
>       run_unit_test(path, "voronoi_short")

test/unit_tests/test_tcc_clusters.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cluster_path = 'test/unit_tests/clusters/12E.xyz', bond_type = 'voronoi_short'

    def run_unit_test(cluster_path, bond_type):
        """
        Run a unit test on a single structure
        Test will fail if the number of detected clusters does not match known composition of a given structure.
        :param cluster_path: path to isolated structure geometry to run TCC on
        :param bond_type: the type of bond to be used by the TCC
        """

        xyz_frames = xyz.read(cluster_path)
        particle_coordinates = next(xyz_frames).particle_coordinates
        cluster_name = os.path.split(cluster_path)[1].rstrip(".xyz")

        tcc_parameters = wrapper.TCCWrapper()
        tcc_parameters.input_parameters['Run']['xyzfilename'] = 'sample.xyz'
        if bond_type == "voronoi_short":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 0.82
        elif bond_type == "voronoi_long":
            tcc_parameters.input_parameters['Simulation']['voronoi_parameter'] = 1
        else:
            print("Unknown bond type.")
            raise TypeError()

        tcc_result_report = tcc_parameters.run((100., 100., 100.), particle_coordinates)

        report = pandas.DataFrame(tcc_result_report['Number of clusters'])

        try:
            if bond_type == "voronoi_short":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_short_clusters[cluster_name]
            elif bond_type == "voronoi_long":
                assert report['Number of clusters'][cluster_name] == structures.voronoi_long_clusters[cluster_name]
            else:
                print("Unknown bond type.")
                raise TypeError()
        except AssertionError:
            print(report)
>           raise AssertionError from None
E           AssertionError

test/unit_tests/test_tcc_clusters.py:50: AssertionError
--------------------------------------------------------- Captured stdout call ---------------------------------------------------------
              Number of clusters
Cluster type                    
sp3a                           9
sp3b                          18
sp3c                           3
sp4a                           0
sp4b                           0
sp4c                           6
sp5a                           0
sp5b                           0
sp5c                           0
6A                             2
6Z                             0
7K                             0
7T_a                           0
7T_s                           0
8A                             0
8B                             0
8K                             0
9A                             0
9B                             0
9K                             3
10A                            0
10B                            0
10K                            0
10W                            0
11A                            0
11B                            0
11C                            0
11E                            0
11F                            3
11W                            0
12A                            0
12B                            0
12D                            0
12E                            3
12K                            0
13A                            0
13B                            0
13K                            0
FCC                            0
HCP                            0
BCC_9                          0
================================================= 6 failed, 82 passed in 14.76 seconds =================================================
merrygoat commented 5 years ago

Yes, 6 failures are expected for the current version. Those specific cluster detections are currently not working as designed! These can be split into cases where there is a clear bug and cases where the original cluster detection specification has to be looked at more clearly.

7K and 12E are both detected 3 times for each cluster due to symmetry, this is a bug. sp4c/6A are not detected when fc is 1, this is expected due to perfect squares being decomposed into two triangles but this is not as originally documented by Alex. FCC was not originally expected to be detected with fc set to 1 though I am not sure why.

merrygoat commented 5 years ago

The last of the problems with the unit tests have now been ironed out. All tests should pass from now on!