-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/SOF-7433 feat: add grain boundary #161
Merged
Merged
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5c7234e
feat: add gb configuration
VsevolodX 9b4c86e
feat: first implementation of slab grain boundary
VsevolodX af92c2f
chore: run lint fix
VsevolodX 59d90c6
update: add crucial control over selection in base builder
VsevolodX d4a5354
update: use OOP beauty to remove duplication
VsevolodX 5e955df
update: structure folders as builder
VsevolodX 69e2ee4
update: add top level function to create gb
VsevolodX 30981a6
chore: run lint fix and types
VsevolodX 153ed93
chore: add docstring
VsevolodX 6b651e1
update: various fixes for types and imports
VsevolodX d36a741
chore: types and pydantic
VsevolodX aa3ece9
update: fix default values usage
VsevolodX e5e881c
Merge branch 'main' into feature/SOF-7433
VsevolodX a18918c
update: move rotation down the chain
VsevolodX a47b537
update: working code -- forgoes slab creation in favor of supercell w…
VsevolodX 0be8666
update: fix an error
VsevolodX 13bac90
chore: docstring
VsevolodX 72c9bdd
chore: docstring 2
VsevolodX 1ed2a98
update: add test for slab gb -- wip
VsevolodX 115aefb
update: return correct creation of slab from interface in gb
VsevolodX 9de7611
chore: imports
VsevolodX 4efc52a
update: fix test
VsevolodX fafdbd8
update: add more assertions to test
VsevolodX ad2e4c2
chore: round to 0
VsevolodX 3010b5a
chore: rename gb -> slabgb
VsevolodX 89e8f9b
chore: update test
VsevolodX c55a200
try: types
VsevolodX da17d90
try: types analogous to slab builder
VsevolodX 7bbdcef
try: debug print
VsevolodX 62e0cee
try: invariant config
VsevolodX 7e79fe9
try: pass gha
VsevolodX d297b18
Merge branch 'main' into feature/SOF-7433
VsevolodX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,15 @@ | ||
from typing import Optional | ||
|
||
from mat3ra.made.material import Material | ||
|
||
from .builders import GrainBoundaryBuilder | ||
from .configuration import GrainBoundaryConfiguration | ||
|
||
|
||
def create_grain_boundary( | ||
configuration: GrainBoundaryConfiguration, | ||
builder: Optional[GrainBoundaryBuilder] = None, | ||
) -> Material: | ||
if builder is None: | ||
builder = GrainBoundaryBuilder() | ||
return builder.get_material(configuration) |
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,84 @@ | ||
from typing import List | ||
|
||
from mat3ra.made.material import Material | ||
|
||
from ...analyze import get_chemical_formula | ||
from ..interface import ZSLStrainMatchingInterfaceBuilderParameters, InterfaceConfiguration | ||
from ..interface.builders import ZSLStrainMatchingInterfaceBuilder | ||
from ..supercell import create_supercell | ||
from ..slab import SlabConfiguration, get_terminations, SlabBuilder, SlabSelectorParameters | ||
from .configuration import GrainBoundaryConfiguration | ||
|
||
|
||
class GrainBoundaryBuilderParameters(ZSLStrainMatchingInterfaceBuilderParameters): | ||
selected_interface_index: int = 0 | ||
|
||
|
||
class GrainBoundaryBuilder(ZSLStrainMatchingInterfaceBuilder): | ||
""" | ||
A builder for creating grain boundaries. | ||
|
||
The grain boundary is created by: | ||
1. creating an interface between two phases, | ||
2. then rotating the interface by 90 degrees. | ||
3. Finally, creating a slab from the rotated interface. | ||
""" | ||
|
||
_BuildParametersType: type(GrainBoundaryBuilderParameters) = GrainBoundaryBuilderParameters # type: ignore | ||
_ConfigurationType: type(GrainBoundaryConfiguration) = GrainBoundaryConfiguration # type: ignore | ||
_GeneratedItemType: type(Material) = Material # type: ignore | ||
selector_parameters: type( # type: ignore | ||
GrainBoundaryBuilderParameters | ||
) = GrainBoundaryBuilderParameters().selected_interface_index # type: ignore | ||
|
||
def _generate(self, configuration: _ConfigurationType) -> List[Material]: | ||
interface_config = InterfaceConfiguration( | ||
film_configuration=configuration.phase_1_configuration, | ||
substrate_configuration=configuration.phase_2_configuration, | ||
film_termination=configuration.phase_1_termination, | ||
substrate_termination=configuration.phase_2_termination, | ||
distance_z=configuration.gap, | ||
vacuum=configuration.gap, | ||
) | ||
interfaces = super()._generate(interface_config) | ||
rot_90_degree_matrix = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]] | ||
rotated_interfaces = [ | ||
create_supercell(interface, xy_supercell_matrix=rot_90_degree_matrix) for interface in interfaces | ||
] | ||
return rotated_interfaces | ||
|
||
def _finalize(self, materials: List[Material], configuration: _ConfigurationType) -> List[Material]: | ||
final_slabs = [] | ||
for interface in materials: | ||
slab_config = SlabConfiguration( | ||
bulk=interface, | ||
miller_indices=configuration.slab_configuration.miller_indices, | ||
thickness=configuration.slab_configuration.thickness, | ||
vacuum=configuration.slab_configuration.vacuum, | ||
xy_supercell_matrix=configuration.slab_configuration.xy_supercell_matrix, | ||
use_conventional_cell=True, | ||
use_orthogonal_z=True, | ||
) | ||
slab_builder = SlabBuilder() | ||
slab_termination = ( | ||
configuration.slab_termination if configuration.slab_termination else get_terminations(slab_config)[0] | ||
) | ||
final_slab = slab_builder.get_material( | ||
configuration, | ||
selector_parameters=SlabSelectorParameters(termination=slab_termination), | ||
) | ||
final_slabs.append(final_slab) | ||
|
||
materials = super()._finalize(final_slabs, configuration) | ||
return materials | ||
|
||
def _update_material_name(self, material: Material, configuration: _ConfigurationType) -> Material: | ||
phase_1_formula = get_chemical_formula(configuration.phase_1_configuration.bulk) | ||
phase_2_formula = get_chemical_formula(configuration.phase_2_configuration.bulk) | ||
phase_1_miller_indices = "".join([str(i) for i in configuration.phase_1_configuration.miller_indices]) | ||
phase_2_miller_indices = "".join([str(i) for i in configuration.phase_2_configuration.miller_indices]) | ||
new_name = ( | ||
f"{phase_1_formula}({phase_1_miller_indices})-{phase_2_formula}({phase_2_miller_indices}), Grain Boundary" | ||
) | ||
material.name = new_name | ||
return material |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
from typing import Optional | ||
|
||
from .. import BaseConfiguration | ||
from ..slab.configuration import SlabConfiguration | ||
from ..slab.termination import Termination | ||
|
||
|
||
class GrainBoundaryConfiguration(BaseConfiguration): | ||
""" | ||
Configuration for a grain boundary in a slab material. | ||
|
||
Attributes: | ||
phase_1_configuration: SlabConfiguration | ||
phase_2_configuration: SlabConfiguration | ||
phase_1_termination: Termination | ||
phase_2_termination: Termination | ||
gap: float | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need units |
||
slab_configuration: SlabConfiguration | ||
slab_termination: Termination | ||
|
||
""" | ||
|
||
phase_1_configuration: SlabConfiguration | ||
phase_2_configuration: SlabConfiguration | ||
phase_1_termination: Termination | ||
phase_2_termination: Termination | ||
gap: float = 3.0 | ||
slab_configuration: SlabConfiguration | ||
slab_termination: Optional[Termination] | ||
|
||
@property | ||
def _json(self): | ||
return { | ||
"type": "GrainBoundaryConfiguration", | ||
"phase_1_configuration": self.phase_1_configuration.to_json(), | ||
"phase_2_configuration": self.phase_2_configuration.to_json(), | ||
"phase_1_termination": str(self.phase_1_termination), | ||
"phase_2_termination": str(self.phase_2_termination), | ||
"gap": self.gap, | ||
"slab_configuration": self.slab_configuration.to_json(), | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring