Passed
Push — master ( 19222a...8b29fb )
by Daniel
03:04
created

test_CifReader.test_CifReader_gemmi()   B

Complexity

Conditions 7

Size

Total Lines 14
Code Lines 12

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 12
dl 14
loc 14
rs 8
c 0
b 0
f 0
cc 7
nop 2
1
import pytest
2
import os
3
import amd
4
5
6
@pytest.fixture(scope='module')
7
def cif_paths(root_dir):
8
    cif_names = [
9
        'cubic',
10
        'T2_experimental',
11
    ]
12
    return {name: os.path.join(root_dir, f'{name}.cif') for name in cif_names}
13
14
def test_CifReader_ase(cif_paths, reference_data):
15
    for name in cif_paths:
16
        references = reference_data[name]
17
        read_in = list(amd.CifReader(cif_paths[name]))
18
19
        if (not len(references) == len(read_in)) or len(read_in) == 0:
20
            pytest.fail(f'There are {len(references)} references, but {len(read_in)} structures were read.')
21
22
        for s, s_ in zip(read_in, references):
23
            if not s == s_['PeriodicSet']:
24
                pytest.fail(f'Structure {s.name} read with CifReader disagrees with reference.')
25
26
27 View Code Duplication
def test_CifReader_pymatgen(cif_paths, reference_data):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
28
    for name in cif_paths:
29
        references = reference_data[name]
30
        try:
31
            read_in = list(amd.CifReader(cif_paths[name], reader='pymatgen'))
32
        except ImportError as _:
33
            pytest.skip('Skipping pymatgen reader test as pymatgen is not installed.')
34
35
        if (not len(references) == len(read_in)) or len(read_in) == 0:
36
            pytest.fail(f'There are {len(references)} references, but {len(read_in)} structures were read.')
37
38
        for s, s_ in zip(read_in, references):
39
            if not s == s_['PeriodicSet']:
40
                pytest.fail(f'Structure {s.name} read with CifReader disagrees with reference.')
41
42
43
# def test_CifReader_gemmi(cif_paths, reference_data):
44
#     for name in cif_paths:
45
#         references = reference_data[name]
46
#         try:
47
#             read_in = list(amd.CifReader(cif_paths[name], reader='gemmi'))
48
#         except ImportError as _:
49
#             pytest.skip('Skipping gemmi reader test as gemmi is not installed.')
50
51
#         if (not len(references) == len(read_in)) or len(read_in) == 0:
52
#             pytest.fail(f'There are {len(references)} references, but {len(read_in)} structures were read.')
53
54
#         for s, s_ in zip(read_in, references):
55
#             if not s == s_['PeriodicSet']:
56
#                 pytest.fail(f'Structure {s.name} read with CifReader disagrees with reference.')
57
58
59 View Code Duplication
def test_CifReader_ccdc(cif_paths, reference_data):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
60
    for name in cif_paths:
61
        references = reference_data[name]
62
        try:
63
            read_in = list(amd.CifReader(cif_paths[name], reader='ccdc'))
64
        except ImportError as _:
65
            pytest.skip('Skipping ccdc reader test as ccdc is not installed.')
66
67
        if (not len(references) == len(read_in)) or len(read_in) == 0:
68
            pytest.fail(f'There are {len(references)} references, but {len(read_in)} structures were read.')
69
70
        for s, s_ in zip(read_in, references):
71
            if not s == s_['PeriodicSet']:
72
                pytest.fail(f'Structure {s.name} read with CifReader disagrees with reference.')
73
74
75
@pytest.fixture(scope='module')
76
def asym_unit_test_cif_path(root_dir):
77
    return os.path.join(root_dir, 'OJIGOG.cif')
78
79
def test_CifReader_equiv_structs(asym_unit_test_cif_path):
80
    pdds = [amd.PDD(struct, 100) for struct in amd.CifReader(asym_unit_test_cif_path, show_warnings=False)]
81
    if amd.emd(pdds[0], pdds[1]) > 0:
82
        pytest.fail(f'Asymmetric structure was read differently than identical expanded version.')
83
84
85
@pytest.fixture(scope='module')
86
def equiv_sites_cif_path(root_dir):
87
    return os.path.join(root_dir, 'BABMUQ.cif')
88
89
def test_equiv_sites(equiv_sites_cif_path):
90
    pdds = [amd.PDD(s, 100) for s in amd.CifReader(equiv_sites_cif_path, show_warnings=False)]
91
    if amd.PDD_pdist(pdds):
92
        pytest.fail(f'Equivalent structures by symmetry differ by PDD.')
93
94
95
@pytest.fixture(scope='module')
96
def T2_alpha_cif_path(root_dir):
97
    return os.path.join(root_dir, 'T2-alpha-solvent.cif')
98
99
def test_heaviest_component(T2_alpha_cif_path, ccdc_enabled):
100
101
    if not ccdc_enabled:
102
        pytest.skip('Skipping test_CSDReader as csd-python-api is not installed.')
103
104
    s = amd.CifReader(
105
        T2_alpha_cif_path, 
106
        reader='ccdc',
107
        disorder='all_sites',
108
        heaviest_component=True
109
    ).read()
110
111
    if not s.asymmetric_unit.shape[0] == 26:
112
        pytest.fail(f'Heaviest component test failed.')
113