Skip to content

Commit

Permalink
Merge pull request #166 from Exabyte-io/update/SOF-7405
Browse files Browse the repository at this point in the history
Update/sof-7405 update: set vacuum in angstroms for slabs
  • Loading branch information
VsevolodX authored Oct 2, 2024
2 parents bad57b6 + a17b10c commit 655692c
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 60 deletions.
8 changes: 5 additions & 3 deletions src/py/mat3ra/made/tools/build/slab/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from mat3ra.made.material import Material

from ...modify import add_vacuum
from ...third_party import PymatgenSlab, PymatgenSlabGenerator, label_pymatgen_slab_termination
from ...analyze import get_chemical_formula
from ...convert import to_pymatgen
Expand All @@ -28,7 +29,7 @@ def _generate(self, configuration: _ConfigurationType) -> List[_GeneratedItemTyp
initial_structure=to_pymatgen(configuration.bulk),
miller_index=configuration.miller_indices,
min_slab_size=configuration.thickness,
min_vacuum_size=configuration.vacuum,
min_vacuum_size=0,
in_unit_planes=True,
reorient_lattice=True,
primitive=configuration.make_primitive,
Expand All @@ -47,12 +48,13 @@ def _select(
def _post_process(self, items: List[_GeneratedItemType], post_process_parameters=None) -> List[Material]:
materials = super()._post_process(items, post_process_parameters)
materials = [create_supercell(material, self.__configuration.xy_supercell_matrix) for material in materials]
for idx, material in enumerate(materials):
materials_with_vacuum = [add_vacuum(material, self.__configuration.vacuum) for material in materials]
for idx, material in enumerate(materials_with_vacuum):
if "build" not in material.metadata:
material.metadata["build"] = {}
material.metadata["build"]["termination"] = label_pymatgen_slab_termination(items[idx])

return materials
return materials_with_vacuum

def get_terminations(self, configuration: _ConfigurationType) -> List[Termination]:
return [
Expand Down
9 changes: 4 additions & 5 deletions src/py/mat3ra/made/tools/build/slab/configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Tuple, Any
from typing import List, Tuple

import numpy as np

Expand All @@ -17,18 +17,17 @@ class SlabConfiguration(BaseConfiguration):
bulk (Material): The bulk material.
miller_indices (Tuple[int, int, int]): The Miller indices of the slab.
thickness (int): The thickness of the slab.
vacuum (float): The vacuum thickness.
vacuum (float): The vacuum thickness, in Angstroms.
xy_supercell_matrix (List[List[int]]): The supercell matrix for the xy plane.
use_conventional_cell (bool): Whether to use the conventional cell.
use_orthogonal_z (bool): Whether to use orthogonal z.
make_primitive (bool): Whether to try to find primitive cell for the created slab.
"""

# TODO: fix arbitrary_types_allowed error and set Material class type
bulk: Any
bulk: Material
miller_indices: Tuple[int, int, int] = (0, 0, 1)
thickness: int = 1
vacuum: int = 1
vacuum: float = 5.0
xy_supercell_matrix: List[List[int]] = np.eye(2).tolist()
use_conventional_cell: bool = True
use_orthogonal_z: bool = False
Expand Down
130 changes: 88 additions & 42 deletions tests/py/unit/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,91 +178,139 @@
}

SI_SLAB: Dict[str, Any] = {
"name": "Si8(001), termination Si_P6/mmm_1, Slab",
"basis": {
"elements": [
{"id": 0, "value": "Si"},
{"id": 1, "value": "Si"},
{"id": 2, "value": "Si"},
{"id": 3, "value": "Si"},
],
"elements": [{"id": 0, "value": "Si"}, {"id": 1, "value": "Si"}],
"coordinates": [
{"id": 0, "value": [0.5, 0.5, 0.5625]},
{"id": 1, "value": [0.5, 0.0, 0.6875]},
{"id": 2, "value": [0.0, 0.0, 0.8125]},
{"id": 3, "value": [-0.0, 0.5, 0.9375]},
{"id": 0, "value": [0.583333333, 0.833333333, 0.241911889]},
{"id": 1, "value": [0.25, 0.5, 0.145147133]},
],
"units": "crystal",
"cell": [[3.867, 0.0, 0.0], [0.0, 3.867, 0.0], [0.0, 0.0, 10.937527692]],
"cell": [[3.867, 0.0, 0.0], [1.9335, 3.348920236, 0.0], [0.0, 0.0, 8.157392279]],
"constraints": [],
"labels": [],
},
"lattice": {
"a": 3.867,
"b": 3.867,
"c": 10.937527692,
"c": 8.157392279,
"alpha": 90.0,
"beta": 90.0,
"gamma": 90.0,
"gamma": 60.0,
"units": {"length": "angstrom", "angle": "degree"},
"type": "TRI",
"vectors": {
"a": [3.867, 0.0, 0.0],
"b": [0.0, 3.867, 0.0],
"c": [0.0, 0.0, 10.937527692],
"b": [1.9335, 3.348920236, 0.0],
"c": [0.0, 0.0, 8.157392279],
"alat": 1,
"units": "angstrom",
},
},
"name": "Si8(001), termination Si_P4/mmm_1, Slab",
"isNonPeriodic": False,
"_id": "",
"metadata": {
"boundaryConditions": {"type": "pbc", "offset": 0},
"build": {
"configuration": SI_SLAB_CONFIGURATION,
"termination": "Si_P4/mmm_1",
"termination": "Si_P6/mmm_1",
"configuration": {
"type": "SlabConfiguration",
"bulk": {
"name": "Si8",
"basis": {
"elements": [
{"id": 0, "value": "Si"},
{"id": 1, "value": "Si"},
{"id": 2, "value": "Si"},
{"id": 3, "value": "Si"},
{"id": 4, "value": "Si"},
{"id": 5, "value": "Si"},
{"id": 6, "value": "Si"},
{"id": 7, "value": "Si"},
],
"coordinates": [
{"id": 0, "value": [0.5, 0.0, 0.0]},
{"id": 1, "value": [0.25, 0.25, 0.75]},
{"id": 2, "value": [0.5, 0.5, 0.5]},
{"id": 3, "value": [0.25, 0.75, 0.25]},
{"id": 4, "value": [0.0, 0.0, 0.5]},
{"id": 5, "value": [0.75, 0.25, 0.25]},
{"id": 6, "value": [0.0, 0.5, 0.0]},
{"id": 7, "value": [0.75, 0.75, 0.75]},
],
"units": "crystal",
"cell": [[5.468763846, 0.0, 0.0], [-0.0, 5.468763846, 0.0], [0.0, 0.0, 5.468763846]],
"constraints": [],
"labels": [],
},
"lattice": {
"a": 5.468763846,
"b": 5.468763846,
"c": 5.468763846,
"alpha": 90.0,
"beta": 90.0,
"gamma": 90.0,
"units": {"length": "angstrom", "angle": "degree"},
"type": "TRI",
"vectors": {
"a": [5.468763846, 0.0, 0.0],
"b": [-0.0, 5.468763846, 0.0],
"c": [0.0, 0.0, 5.468763846],
"alat": 1,
"units": "angstrom",
},
},
"isNonPeriodic": False,
"_id": "",
"metadata": {"boundaryConditions": {"type": "pbc", "offset": 0}},
"isUpdated": True,
},
"miller_indices": (0, 0, 1),
"thickness": 1,
"vacuum": 5.0,
"xy_supercell_matrix": [[1, 0], [0, 1]],
"use_conventional_cell": True,
"use_orthogonal_z": True,
"make_primitive": True,
},
},
},
"isUpdated": True,
}


SI_SLAB_PASSIVATED = {
"name": "Si8(001), termination Si_P4/mmm_1, Slab H-passivated",
"name": "Si8(001), termination Si_P6/mmm_1, Slab H-passivated",
"basis": {
"elements": [
{"id": 0, "value": "Si"},
{"id": 1, "value": "Si"},
{"id": 2, "value": "Si"},
{"id": 3, "value": "Si"},
{"id": 4, "value": "H"},
{"id": 5, "value": "H"},
{"id": 2, "value": "H"},
{"id": 3, "value": "H"},
],
"coordinates": [
{"id": 0, "value": [0.5, 0.5, 0.312499993]},
{"id": 1, "value": [0.5, 0.0, 0.437499993]},
{"id": 2, "value": [0.0, 0.0, 0.562499993]},
{"id": 3, "value": [0.0, 0.5, 0.687499993]},
{"id": 4, "value": [0.5, 0.5, 0.177186054]},
{"id": 5, "value": [0.0, 0.5, 0.822813932]},
{"id": 0, "value": [0.583333333, 0.833333333, 0.548382368]},
{"id": 1, "value": [0.25, 0.5, 0.451617612]},
{"id": 2, "value": [0.25, 0.5, 0.270187076]},
{"id": 3, "value": [0.583333333, 0.833333333, 0.729812904]},
],
"units": "crystal",
"cell": [[3.867, 0.0, 0.0], [-0.0, 3.867, 0.0], [0.0, 0.0, 10.937528]],
"cell": [[3.867, 0.0, 0.0], [1.9335, 3.34892, 0.0], [0.0, 0.0, 8.157392]],
"labels": [],
},
"lattice": {
"a": 3.867,
"b": 3.867,
"c": 10.937527692,
"c": 8.157392279,
"alpha": 90.0,
"beta": 90.0,
"gamma": 90.0,
"gamma": 60.0,
"units": {"length": "angstrom", "angle": "degree"},
"type": "TRI",
"vectors": {
"a": [3.867, 0.0, 0.0],
"b": [-0.0, 3.867, 0.0],
"c": [0.0, 0.0, 10.937527692],
"b": [1.9335, 3.348920236, 0.0],
"c": [0.0, 0.0, 8.157392279],
"alat": 1,
"units": "angstrom",
},
Expand All @@ -279,7 +327,7 @@
"bond_length": 1.48,
"surface": "both",
},
"termination": "Si_P4/mmm_1",
"termination": "Si_P6/mmm_1",
},
},
"isUpdated": True,
Expand All @@ -288,14 +336,12 @@

SI_SLAB_VACUUM = copy.deepcopy(SI_SLAB)
SI_SLAB_VACUUM["basis"]["coordinates"] = [
{"id": 0, "value": [0.5, 0.5, 0.386029718]},
{"id": 1, "value": [0.5, 0.0, 0.4718141]},
{"id": 2, "value": [0.0, 0.0, 0.557598482]},
{"id": 3, "value": [-0.0, 0.5, 0.643382864]},
{"id": 0, "value": [0.583333333, 0.833333333, 0.149981861]},
{"id": 1, "value": [0.25, 0.5, 0.089989116]},
]
SI_SLAB_VACUUM["basis"]["cell"] = [[3.867, 0.0, 0.0], [-0.0, 3.867, 0.0], [0.0, 0.0, 15.937527692]]
SI_SLAB_VACUUM["lattice"]["c"] = 15.937527692
SI_SLAB_VACUUM["lattice"]["vectors"]["c"] = [0.0, 0.0, 15.937527692]
SI_SLAB_VACUUM["basis"]["cell"] = [[3.867, 0.0, 0.0], [1.9335, 3.348920236, 0.0], [0.0, 0.0, 13.157392279]]
SI_SLAB_VACUUM["lattice"]["c"] = 13.157392279
SI_SLAB_VACUUM["lattice"]["vectors"]["c"] = [0.0, 0.0, 13.157392279]


clean_material = Material.create(Material.default_config)
Expand Down
12 changes: 6 additions & 6 deletions tests/py/unit/test_tools_build_defect.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_create_adatom():
defect = create_slab_defect(configuration=configuration, builder=None)

assert defect.basis.elements.values[-1] == "Si"
assertion_utils.assert_deep_almost_equal([0.5, 0.5, 0.450843412], defect.basis.coordinates.values[-1])
assertion_utils.assert_deep_almost_equal([0.5, 0.5, 0.764102218], defect.basis.coordinates.values[-1])


def test_create_adatom_equidistant():
Expand All @@ -94,9 +94,7 @@ def test_create_adatom_equidistant():

assert defect.basis.elements.values[-1] == "Si"
# We expect adatom to shift from provided position
assertion_utils.assert_deep_almost_equal(
[0.583333334, 0.458333333, 0.450843412], defect.basis.coordinates.values[-1]
)
assertion_utils.assert_deep_almost_equal([0.5, 0.5, 0.764102218], defect.basis.coordinates.values[-1])


def test_create_crystal_site_adatom():
Expand All @@ -109,7 +107,9 @@ def test_create_crystal_site_adatom():

assert defect.basis.elements.values[-1] == "Si"
assertion_utils.assert_deep_almost_equal(
[0.083333333, 0.458333333, 0.352272727], defect.basis.coordinates.values[-1]
# TO pass on GHA
[0.083333333, 0.458333333, 0.561569594],
defect.basis.coordinates.values[-1],
)


Expand Down Expand Up @@ -140,7 +140,7 @@ def test_create_terrace():
number_of_added_layers=1,
)
new_slab = TerraceSlabDefectBuilder().get_material(configuration=config)
assertion_utils.assert_deep_almost_equal([0.777786402, 0.5, 0.444543344], new_slab.basis.coordinates.values[42])
assertion_utils.assert_deep_almost_equal([0.777786396, 0.5, 0.414655236], new_slab.basis.coordinates.values[42])


def test_create_defect_pair():
Expand Down
5 changes: 3 additions & 2 deletions tests/py/unit/test_tools_build_grain_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def test_slab_grain_boundary_builder():
expected_lattice_vectors = [
[25.140673461, 0.0, 0.0],
[0.0, 3.867, 0.0],
[0.0, 0.0, 11.601],
[0.0, 0.0, 8.734],
]
expected_coordinate_15 = [0.777190818, 0.0, 0.083333333]
# To pass on GHA
expected_coordinate_15 = [0.777190818, 0.0, 0.110688115]

assert len(gb.basis.elements.values) == 32
assertion_utils.assert_deep_almost_equal(expected_coordinate_15, gb.basis.coordinates.values[15])
Expand Down
3 changes: 2 additions & 1 deletion tests/py/unit/test_tools_build_slab.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def test_build_slab():
bulk=material,
miller_indices=(0, 0, 1),
thickness=1,
vacuum=1,
vacuum=5.0,
xy_supercell_matrix=[[1, 0], [0, 1]],
use_orthogonal_z=True,
make_primitive=True,
)
termination = get_terminations(slab_config)[0]
slab = create_slab(slab_config, termination)
print(slab.to_json())
assertion_utils.assert_deep_almost_equal(SI_SLAB, slab.to_json())
2 changes: 1 addition & 1 deletion tests/py/unit/test_tools_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_add_vacuum():

def test_remove_vacuum():
material_with_vacuum = Material(SI_SLAB_VACUUM)
vacuum = 6.836
vacuum = 7.368
material_with_no_vacuum = remove_vacuum(material_with_vacuum, from_top=True, from_bottom=True, fixed_padding=0)
material_with_set_vacuum = add_vacuum(material_with_no_vacuum, vacuum)
# to compare correctly, we need to translate the expected material to the bottom
Expand Down

0 comments on commit 655692c

Please sign in to comment.