Skip to content

Commit

Permalink
update: restrucutre gb directory
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Sep 26, 2024
1 parent d023f28 commit 7e3f4f5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 73 deletions.
75 changes: 2 additions & 73 deletions src/py/mat3ra/made/tools/build/grain_boundary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,2 @@
from typing import List

import numpy as np

from mat3ra.made.material import Material

from ..interface.configuration import TwistedInterfaceConfiguration
from ..interface.builders import (
CommensurateLatticeTwistedInterfaceBuilder,
CommensurateLatticeTwistedInterfaceBuilderParameters,
)
from ..supercell import create_supercell
from ..utils import merge_two_materials_laterally


class SurfaceGrainBoundaryConfiguration(TwistedInterfaceConfiguration):
"""
Configuration for creating a surface grain boundary.
Args:
gap (float): The gap between the two phases.
xy_supercell_matrix (List[List[int]]): The supercell matrix to apply for both phases.
"""

gap: float = 0.0
xy_supercell_matrix: List[List[int]] = [[1, 0], [0, 1]]

@property
def _json(self):
return {
"type": self.get_cls_name(),
"gap": self.gap,
"xy_supercell_matrix": self.xy_supercell_matrix,
}


class SurfaceGrainBoundaryBuilderParameters(CommensurateLatticeTwistedInterfaceBuilderParameters):
"""
Parameters for creating a grain boundary between two surface phases.
Args:
distance_tolerance (float): The distance tolerance to remove atoms that are too close, in angstroms.
"""

distance_tolerance: float = 1.0


class SurfaceGrainBoundaryBuilder(CommensurateLatticeTwistedInterfaceBuilder):
_ConfigurationType: type(SurfaceGrainBoundaryConfiguration) = SurfaceGrainBoundaryConfiguration # type: ignore
_BuildParametersType = SurfaceGrainBoundaryBuilderParameters
_DefaultBuildParameters = SurfaceGrainBoundaryBuilderParameters()

def _post_process(self, items: List[Material], post_process_parameters=None) -> List[Material]:
grain_boundaries = []
for item in items:
matrix1 = np.dot(np.array(item.configuration.xy_supercell_matrix), item.matrix1)
matrix2 = np.dot(np.array(item.configuration.xy_supercell_matrix), item.matrix2)
phase_1_material_initial = create_supercell(item.configuration.film, matrix1.tolist())
phase_2_material_initial = create_supercell(item.configuration.film, matrix2.tolist())

interface = merge_two_materials_laterally(
phase_1_material_initial,
phase_2_material_initial,
gap=item.configuration.gap,
distance_tolerance=self.build_parameters.distance_tolerance,
)
grain_boundaries.append(interface)

return grain_boundaries

def _update_material_name(self, material: Material, configuration: SurfaceGrainBoundaryConfiguration) -> Material:
material.name = f"Surface Grain Boundary ({configuration.twist_angle:.2f}°)"
return material
from .configuration import SurfaceGrainBoundaryConfiguration
from .builders import SurfaceGrainBoundaryBuilder, SurfaceGrainBoundaryBuilderParameters
53 changes: 53 additions & 0 deletions src/py/mat3ra/made/tools/build/grain_boundary/builders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from typing import List

import numpy as np

from mat3ra.made.material import Material


from ..interface.builders import (
CommensurateLatticeTwistedInterfaceBuilder,
CommensurateLatticeTwistedInterfaceBuilderParameters,
)
from ..supercell import create_supercell
from ..utils import merge_two_materials_laterally
from .configuration import SurfaceGrainBoundaryConfiguration


class SurfaceGrainBoundaryBuilderParameters(CommensurateLatticeTwistedInterfaceBuilderParameters):
"""
Parameters for creating a grain boundary between two surface phases.
Args:
distance_tolerance (float): The distance tolerance to remove atoms that are too close, in angstroms.
"""

distance_tolerance: float = 1.0


class SurfaceGrainBoundaryBuilder(CommensurateLatticeTwistedInterfaceBuilder):
_ConfigurationType: type(SurfaceGrainBoundaryConfiguration) = SurfaceGrainBoundaryConfiguration # type: ignore
_BuildParametersType = SurfaceGrainBoundaryBuilderParameters
_DefaultBuildParameters = SurfaceGrainBoundaryBuilderParameters()

def _post_process(self, items: List[Material], post_process_parameters=None) -> List[Material]:
grain_boundaries = []
for item in items:
matrix1 = np.dot(np.array(item.configuration.xy_supercell_matrix), item.matrix1)
matrix2 = np.dot(np.array(item.configuration.xy_supercell_matrix), item.matrix2)
phase_1_material_initial = create_supercell(item.configuration.film, matrix1.tolist())
phase_2_material_initial = create_supercell(item.configuration.film, matrix2.tolist())

interface = merge_two_materials_laterally(
phase_1_material_initial,
phase_2_material_initial,
gap=item.configuration.gap,
distance_tolerance=self.build_parameters.distance_tolerance,
)
grain_boundaries.append(interface)

return grain_boundaries

def _update_material_name(self, material: Material, configuration: SurfaceGrainBoundaryConfiguration) -> Material:
material.name = f"Surface Grain Boundary ({configuration.twist_angle:.2f}°)"
return material
24 changes: 24 additions & 0 deletions src/py/mat3ra/made/tools/build/grain_boundary/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import List

from ..interface.configuration import TwistedInterfaceConfiguration


class SurfaceGrainBoundaryConfiguration(TwistedInterfaceConfiguration):
"""
Configuration for creating a surface grain boundary.
Args:
gap (float): The gap between the two phases.
xy_supercell_matrix (List[List[int]]): The supercell matrix to apply for both phases.
"""

gap: float = 0.0
xy_supercell_matrix: List[List[int]] = [[1, 0], [0, 1]]

@property
def _json(self):
return {
"type": self.get_cls_name(),
"gap": self.gap,
"xy_supercell_matrix": self.xy_supercell_matrix,
}

0 comments on commit 7e3f4f5

Please sign in to comment.