Skip to content

Commit

Permalink
update: add test fro interface displacement
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Aug 28, 2024
1 parent 572f0f1 commit de7e911
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 1 deletion.
174 changes: 174 additions & 0 deletions tests/py/unit/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,180 @@
INTERFACE_STRUCTURE.interface_properties = INTERFACE_PROPERTIES_MOCK
INTERFACE_NAME = "Cu4(001)-Si8(001), Interface, Strain 0.062pct"

GRAPHENE_NICKEL_INTERFACE = {
"name": "C2(001)-Ni4(111), Interface, Strain 0.105pct",
"basis": {
"elements": [
{"id": 0, "value": "Ni"},
{"id": 1, "value": "Ni"},
{"id": 2, "value": "Ni"},
{"id": 3, "value": "C"},
{"id": 4, "value": "C"},
],
"coordinates": [
{"id": 0, "value": [0.666666667, 0.666666667, 0.350869517]},
{"id": 1, "value": [1.0, 0.0, 0.425701769]},
{"id": 2, "value": [0.333333333, 0.333333333, 0.500534021]},
{"id": 3, "value": [0.333333333, 0.333333333, 0.611447347]},
{"id": 4, "value": [0.666666667, 0.666666667, 0.611447347]},
],
"units": "crystal",
"cell": [[2.478974, 0.0, 0.0], [1.239487, 2.14685446, 0.0], [0.0, 0.0, 27.048147591]],
"constraints": [],
"labels": [
{"id": 0, "value": 0},
{"id": 1, "value": 0},
{"id": 2, "value": 0},
{"id": 3, "value": 1},
{"id": 4, "value": 1},
],
},
"lattice": {
"a": 2.478974,
"b": 2.478974,
"c": 27.048147591,
"alpha": 90.0,
"beta": 90.0,
"gamma": 60.0,
"units": {"length": "angstrom", "angle": "degree"},
"type": "TRI",
"vectors": {
"a": [2.478974, 0.0, 0.0],
"b": [1.239487, 2.14685446, 0.0],
"c": [0.0, 0.0, 27.048147591],
"alat": 1,
"units": "angstrom",
},
},
"isNonPeriodic": False,
"_id": "",
"metadata": {
"interface_properties": {
"film_sl_vectors": [[2.467291, 0.0, 0.0], [1.2336455, -2.136736685, -0.0]],
"substrate_sl_vectors": [[-1.752899326, 1.752899326, 0.0], [-1.752899326, 0.0, 1.752899326]],
"film_vectors": [[2.467291, 0.0, 0.0], [-1.2336455, 2.136736685, 0.0]],
"substrate_vectors": [[-1.752899326, 1.752899326, 0.0], [-1.752899326, 0.0, 1.752899326]],
"film_transformation": [[1.0, 0.0], [0.0, 1.0]],
"substrate_transformation": [[1.0, 0.0], [0.0, 1.0]],
"strain": [[0.004746364, -0.0, -0.0], [-0.0, 0.004746364, -0.0], [-0.0, -0.0, 0.0]],
"von_mises_strain": 0.003164242537164297,
"termination": "('C_P6/mmm_2', 'Ni_R-3m_1')",
"film_thickness": 1,
"substrate_thickness": 3,
"mean_abs_strain": 0.0010500000000000002,
},
"boundaryConditions": {"type": "pbc", "offset": 0},
"mean_abs_strain": 0.0010500000000000002,
"build": {
"configuration": {
"type": "InterfaceConfiguration",
"film_configuration": {
"type": "SlabConfiguration",
"bulk": {
"name": "C2",
"basis": {
"elements": [{"id": 0, "value": "C"}, {"id": 1, "value": "C"}],
"coordinates": [
{"id": 0, "value": [0.333333333, 0.666666667, 0.0]},
{"id": 1, "value": [0.666666667, 0.333333333, 0.0]},
],
"units": "crystal",
"cell": [[1.2336455, -2.136736685, 0.0], [1.2336455, 2.136736685, 0.0], [0.0, 0.0, 20.0]],
"constraints": [],
"labels": [],
},
"lattice": {
"a": 2.467291,
"b": 2.467291,
"c": 20.0,
"alpha": 90.0,
"beta": 90.0,
"gamma": 120.0,
"units": {"length": "angstrom", "angle": "degree"},
"type": "TRI",
"vectors": {
"a": [1.2336455, -2.136736685, 0.0],
"b": [1.2336455, 2.136736685, 0.0],
"c": [0.0, 0.0, 20.0],
"alat": 1,
"units": "angstrom",
},
},
"isNonPeriodic": False,
"_id": "",
"metadata": {"boundaryConditions": {"type": "pbc", "offset": 0}},
"isUpdated": True,
},
"miller_indices": [0, 0, 1],
"thickness": 1,
"vacuum": 0,
"xy_supercell_matrix": [[1, 0], [0, 1]],
"use_conventional_cell": True,
"use_orthogonal_z": True,
"make_primitive": False,
},
"substrate_configuration": {
"type": "SlabConfiguration",
"bulk": {
"name": "Ni4",
"basis": {
"elements": [
{"id": 0, "value": "Ni"},
{"id": 1, "value": "Ni"},
{"id": 2, "value": "Ni"},
{"id": 3, "value": "Ni"},
],
"coordinates": [
{"id": 0, "value": [0.0, 0.0, 0.0]},
{"id": 1, "value": [0.0, 0.5, 0.5]},
{"id": 2, "value": [0.5, 0.0, 0.5]},
{"id": 3, "value": [0.5, 0.5, 0.0]},
],
"units": "crystal",
"cell": [[3.505798652, 0.0, 0.0], [-0.0, 3.505798652, 0.0], [0.0, 0.0, 3.505798652]],
"constraints": [],
"labels": [],
},
"lattice": {
"a": 3.505798652,
"b": 3.505798652,
"c": 3.505798652,
"alpha": 90.0,
"beta": 90.0,
"gamma": 90.0,
"units": {"length": "angstrom", "angle": "degree"},
"type": "TRI",
"vectors": {
"a": [3.505798652, 0.0, 0.0],
"b": [-0.0, 3.505798652, 0.0],
"c": [0.0, 0.0, 3.505798652],
"alat": 1,
"units": "angstrom",
},
},
"isNonPeriodic": False,
"_id": "",
"metadata": {"boundaryConditions": {"type": "pbc", "offset": 0}},
"isUpdated": True,
},
"miller_indices": [1, 1, 1],
"thickness": 3,
"vacuum": 3,
"xy_supercell_matrix": [[1, 0], [0, 1]],
"use_conventional_cell": True,
"use_orthogonal_z": True,
"make_primitive": False,
},
"film_termination": "C_P6/mmm_2",
"substrate_termination": "Ni_P6/mmm_4",
"distance_z": 3.0,
"vacuum": 20.0,
}
},
},
"isUpdated": True,
}

# TODO: Use fixtures package when available
SI_CONVENTIONAL_CELL: Dict[str, Any] = {
"name": "Si8",
Expand Down
19 changes: 18 additions & 1 deletion tests/py/unit/test_tools_modify.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from ase.build import bulk
from mat3ra.made.material import Material
from mat3ra.made.tools.convert import from_ase
from mat3ra.made.tools.convert.utils import InterfacePartsEnum
from mat3ra.made.tools.modify import (
add_vacuum,
displace_interface,
filter_by_circle_projection,
filter_by_label,
filter_by_layers,
Expand All @@ -15,7 +17,7 @@
)
from mat3ra.utils import assertion as assertion_utils

from .fixtures import SI_CONVENTIONAL_CELL, SI_SLAB, SI_SLAB_VACUUM
from .fixtures import GRAPHENE_NICKEL_INTERFACE, SI_CONVENTIONAL_CELL, SI_SLAB, SI_SLAB_VACUUM

COMMON_PART = {
"units": "crystal",
Expand Down Expand Up @@ -170,3 +172,18 @@ def test_rotate_material():
material.basis.coordinates.values.sort(), rotated_material.basis.coordinates.values.sort()
)
assertion_utils.assert_deep_almost_equal(material.lattice, rotated_material.lattice)


def test_displace_interface():
material = Material(GRAPHENE_NICKEL_INTERFACE)
expected_coordinates = [
{"id": 0, "value": [0.666666667, 0.666666667, 0.350869517]},
{"id": 1, "value": [-0.0, 0.0, 0.425701769]},
{"id": 2, "value": [0.333333333, 0.333333333, 0.500534021]},
{"id": 3, "value": [0.433333333, 0.533333333, 0.911447347]},
{"id": 4, "value": [0.766666667, 0.866666667, 0.911447347]},
]
expected_labels = GRAPHENE_NICKEL_INTERFACE["basis"]["labels"]
displaced_material = displace_interface(material, [0.1, 0.2, 0.3], InterfacePartsEnum.FILM)
assertion_utils.assert_deep_almost_equal(expected_coordinates, displaced_material.basis.coordinates.to_dict())
assertion_utils.assert_deep_almost_equal(expected_labels, displaced_material.basis.labels.to_dict())

0 comments on commit de7e911

Please sign in to comment.