-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
src/py/mat3ra/made/tools/build/grain_boundary/configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |