|
1 | 1 | """Unit tests for bulk-crystal query resolution.""" |
2 | 2 |
|
3 | 3 | import pytest |
4 | | -from mat3ra.notebooks_utils.core.entity.material.analysis import resolve_bulk_query_from_crystal |
| 4 | +from mat3ra.made.material import Material |
| 5 | +from mat3ra.made.tools.analyze.lattice_planes import CrystalLatticePlanesMaterialAnalyzer |
| 6 | +from mat3ra.made.tools.helpers import create_slab |
| 7 | +from mat3ra.notebooks_utils.core.entity.material.analysis import get_slab_bulk_crystal, resolve_bulk_query_from_crystal |
5 | 8 | from mat3ra.standata.materials import Materials |
6 | 9 |
|
7 | 10 | SILICON = Materials.get_by_name_first_match("Silicon") |
|
12 | 15 | [ |
13 | 16 | ( |
14 | 17 | {"scaledHash": "scaled-hash-value", "hash": "hash-value", "_id": "material-id"}, |
15 | | - {"scaledHash": "scaled-hash-value"}, |
| 18 | + {"_id": "material-id"}, |
16 | 19 | ), |
17 | | - ({"hash": "hash-value", "_id": "material-id"}, {"hash": "hash-value"}), |
18 | | - ({"_id": "material-id"}, {"_id": "material-id"}), |
| 20 | + ({"scaledHash": "scaled-hash-value", "hash": "hash-value"}, {"hash": "hash-value"}), |
| 21 | + ({"scaledHash": "scaled-hash-value"}, {"scaledHash": "scaled-hash-value"}), |
19 | 22 | ], |
20 | 23 | ) |
21 | | -def test_resolve_bulk_query_prefers_scaled_hash_then_hash_then_id(extra_keys, expected): |
| 24 | +def test_resolve_bulk_query_prefers_id_then_hash_then_scaled_hash(extra_keys, expected): |
22 | 25 | assert resolve_bulk_query_from_crystal({**SILICON, **extra_keys}) == expected |
23 | 26 |
|
24 | 27 |
|
25 | 28 | def test_resolve_bulk_query_computes_hash_when_none_present(): |
26 | 29 | query = resolve_bulk_query_from_crystal(SILICON) |
27 | 30 | assert set(query) == {"hash"} |
28 | 31 | assert query["hash"] |
| 32 | + |
| 33 | + |
| 34 | +def test_slab_bulk_crystal_is_the_material_the_slab_was_built_from(): |
| 35 | + """ |
| 36 | + A slab built from a primitive bulk must resolve back to that primitive bulk, not to the |
| 37 | + conventional cell -- otherwise the Total Energy job run on the input is unreachable and |
| 38 | + surface energy combines a slab SCF with a bulk reference from a different cell. |
| 39 | + """ |
| 40 | + primitive = Material.create(Materials.get_by_name_first_match("Nickel")) |
| 41 | + conventional = CrystalLatticePlanesMaterialAnalyzer( |
| 42 | + material=primitive, miller_indices=(0, 0, 1) |
| 43 | + ).material_with_conventional_lattice |
| 44 | + assert conventional.hash != primitive.hash |
| 45 | + |
| 46 | + slab = create_slab(crystal=primitive, miller_indices=(0, 0, 1), number_of_layers=3) |
| 47 | + |
| 48 | + assert get_slab_bulk_crystal(slab)["hash"] == primitive.hash |
0 commit comments