|
22 | 22 | import pytest |
23 | 23 | from nomad.datamodel import EntryArchive |
24 | 24 |
|
| 25 | +from nomad_simulations.schema_packages.atoms_state import AtomsState |
25 | 26 | from nomad_simulations.schema_packages.model_system import ( |
| 27 | + AtomicCell, |
| 28 | + Cell, |
26 | 29 | ChemicalFormula, |
27 | 30 | ModelSystem, |
28 | 31 | Symmetry, |
|
32 | 35 | from .conftest import generate_atomic_cell |
33 | 36 |
|
34 | 37 |
|
| 38 | +class TestCell: |
| 39 | + """ |
| 40 | + Test the `Cell` section defined in model_system.py |
| 41 | + """ |
| 42 | + |
| 43 | + @pytest.mark.parametrize( |
| 44 | + 'cell_1, cell_2, result', |
| 45 | + [ |
| 46 | + (Cell(), None, False), # one cell is None |
| 47 | + (Cell(), Cell(), False), # both cells are empty |
| 48 | + ( |
| 49 | + Cell(positions=[[1, 0, 0]]), |
| 50 | + Cell(), |
| 51 | + False, |
| 52 | + ), # one cell has positions, the other is empty |
| 53 | + ( |
| 54 | + Cell(positions=[[1, 0, 0], [0, 1, 0]]), |
| 55 | + Cell(positions=[[1, 0, 0]]), |
| 56 | + False, |
| 57 | + ), # length mismatch |
| 58 | + ( |
| 59 | + Cell(positions=[[1, 0, 0], [0, 1, 0]]), |
| 60 | + Cell(positions=[[1, 0, 0], [0, -1, 0]]), |
| 61 | + False, |
| 62 | + ), # different positions |
| 63 | + ( |
| 64 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 65 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 66 | + True, |
| 67 | + ), # same ordered positions |
| 68 | + ( |
| 69 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 70 | + Cell(positions=[[1, 0, 0], [0, 0, 1], [0, 1, 0]]), |
| 71 | + True, |
| 72 | + ), # different ordered positions but same cell |
| 73 | + ], |
| 74 | + ) |
| 75 | + def test_eq_ne(self, cell_1: Cell, cell_2: Cell, result: bool): |
| 76 | + """ |
| 77 | + Test the `__eq__` and `__ne__` operator functions of `Cell`. |
| 78 | + """ |
| 79 | + assert (cell_1 == cell_2) == result |
| 80 | + assert (cell_1 != cell_2) != result |
| 81 | + |
| 82 | + |
35 | 83 | class TestAtomicCell: |
36 | 84 | """ |
37 | 85 | Test the `AtomicCell`, `Cell` and `GeometricSpace` classes defined in model_system.py |
38 | 86 | """ |
39 | 87 |
|
| 88 | + @pytest.mark.parametrize( |
| 89 | + 'cell_1, cell_2, result', |
| 90 | + [ |
| 91 | + (Cell(), None, False), # one cell is None |
| 92 | + (Cell(), Cell(), False), # both cells are empty |
| 93 | + ( |
| 94 | + Cell(positions=[[1, 0, 0]]), |
| 95 | + Cell(), |
| 96 | + False, |
| 97 | + ), # one cell has positions, the other is empty |
| 98 | + ( |
| 99 | + Cell(positions=[[1, 0, 0], [0, 1, 0]]), |
| 100 | + Cell(positions=[[1, 0, 0]]), |
| 101 | + False, |
| 102 | + ), # length mismatch |
| 103 | + ( |
| 104 | + Cell(positions=[[1, 0, 0], [0, 1, 0]]), |
| 105 | + Cell(positions=[[1, 0, 0], [0, -1, 0]]), |
| 106 | + False, |
| 107 | + ), # different positions |
| 108 | + ( |
| 109 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 110 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 111 | + True, |
| 112 | + ), # same ordered positions |
| 113 | + ( |
| 114 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 115 | + Cell(positions=[[1, 0, 0], [0, 0, 1], [0, 1, 0]]), |
| 116 | + True, |
| 117 | + ), # different ordered positions but same cell |
| 118 | + ( |
| 119 | + AtomicCell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 120 | + Cell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 121 | + False, |
| 122 | + ), # one atomic cell and another cell (missing chemical symbols) |
| 123 | + ( |
| 124 | + AtomicCell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 125 | + AtomicCell(positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]), |
| 126 | + False, |
| 127 | + ), # missing chemical symbols |
| 128 | + ( |
| 129 | + AtomicCell( |
| 130 | + positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], |
| 131 | + atoms_state=[ |
| 132 | + AtomsState(chemical_symbol='H'), |
| 133 | + AtomsState(chemical_symbol='H'), |
| 134 | + AtomsState(chemical_symbol='O'), |
| 135 | + ], |
| 136 | + ), |
| 137 | + AtomicCell( |
| 138 | + positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], |
| 139 | + atoms_state=[ |
| 140 | + AtomsState(chemical_symbol='H'), |
| 141 | + AtomsState(chemical_symbol='H'), |
| 142 | + AtomsState(chemical_symbol='O'), |
| 143 | + ], |
| 144 | + ), |
| 145 | + True, |
| 146 | + ), # same ordered positions and chemical symbols |
| 147 | + ( |
| 148 | + AtomicCell( |
| 149 | + positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], |
| 150 | + atoms_state=[ |
| 151 | + AtomsState(chemical_symbol='H'), |
| 152 | + AtomsState(chemical_symbol='H'), |
| 153 | + AtomsState(chemical_symbol='O'), |
| 154 | + ], |
| 155 | + ), |
| 156 | + AtomicCell( |
| 157 | + positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], |
| 158 | + atoms_state=[ |
| 159 | + AtomsState(chemical_symbol='H'), |
| 160 | + AtomsState(chemical_symbol='Cu'), |
| 161 | + AtomsState(chemical_symbol='O'), |
| 162 | + ], |
| 163 | + ), |
| 164 | + False, |
| 165 | + ), # same ordered positions but different chemical symbols |
| 166 | + ( |
| 167 | + AtomicCell( |
| 168 | + positions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], |
| 169 | + atoms_state=[ |
| 170 | + AtomsState(chemical_symbol='H'), |
| 171 | + AtomsState(chemical_symbol='H'), |
| 172 | + AtomsState(chemical_symbol='O'), |
| 173 | + ], |
| 174 | + ), |
| 175 | + AtomicCell( |
| 176 | + positions=[[1, 0, 0], [0, 0, 1], [0, 1, 0]], |
| 177 | + atoms_state=[ |
| 178 | + AtomsState(chemical_symbol='H'), |
| 179 | + AtomsState(chemical_symbol='O'), |
| 180 | + AtomsState(chemical_symbol='H'), |
| 181 | + ], |
| 182 | + ), |
| 183 | + True, |
| 184 | + ), # different ordered positions but same chemical symbols |
| 185 | + ], |
| 186 | + ) |
| 187 | + def test_eq_ne(self, cell_1: Cell, cell_2: Cell, result: bool): |
| 188 | + """ |
| 189 | + Test the `__eq__` and `__ne__` operator functions of `AtomicCell`. |
| 190 | + """ |
| 191 | + assert (cell_1 == cell_2) == result |
| 192 | + assert (cell_1 != cell_2) != result |
| 193 | + |
40 | 194 | @pytest.mark.parametrize( |
41 | 195 | 'chemical_symbols, atomic_numbers, formula, lattice_vectors, positions, periodic_boundary_conditions', |
42 | 196 | [ |
|
0 commit comments