Skip to content
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/special adsorbtion sites #173

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/py/mat3ra/made/tools/build/defect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ def create_slab_defect(

Args:
configuration: The configuration of the defect to be added.
builder: The builder to be used to create the defect.
builder: Optional builder to be used to create the defect.
If None, builder will be selected based on configuration.

Returns:
The material with the defect added.
"""
if builder is None:
builder = AdatomSlabDefectBuilder(build_parameters=SlabDefectBuilderParameters())
if configuration.defect_type == PointDefectTypeEnum.ADATOM:
builder_key = f"adatom:{configuration.placement_method.lower()}"
else:
builder_key = configuration.defect_type.lower()

BuilderClass = DefectBuilderFactory.get_class_by_name(builder_key)
builder = BuilderClass(build_parameters=SlabDefectBuilderParameters())

return builder.get_material(configuration)
30 changes: 30 additions & 0 deletions src/py/mat3ra/made/tools/build/defect/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
PointDefectPairConfiguration,
)
from .factories import DefectBuilderFactory
from pymatgen.analysis.adsorption import AdsorbateSiteFinder


class PointDefectBuilderParameters(BaseModel):
Expand Down Expand Up @@ -434,6 +435,35 @@ def create_adatom(
return self.merge_slab_and_defect(new_material, only_adatom_material)


class HollowSiteAdatomSlabDefectBuilder(AdatomSlabDefectBuilder):
"""
Builder class for generating adatoms at hollow sites.

The adatom is placed at the hollow site closest to the specified position on the surface of the material.

"""

def _calculate_coordinate_from_position_and_distance(
self, material: Material, position_on_surface: List[float], distance_z: float
) -> List[float]:
coordinate = super()._calculate_coordinate_from_position_and_distance(material, position_on_surface, distance_z)
pymatgen_structure = to_pymatgen(material)
asf = AdsorbateSiteFinder(pymatgen_structure)

sites = asf.find_adsorption_sites(
positions=[
"hollow",
],
no_obtuse_hollow=False,
)
hollow_coordinates = [array.tolist() for array in sites["hollow"]]
print("Hollow site coordinates:\n", hollow_coordinates)
closest_hollow_site_coordinate = min(
hollow_coordinates, key=lambda x: np.linalg.norm(np.array(x) - np.array(coordinate))
)
return closest_hollow_site_coordinate[0:2] + [coordinate[2]]


class DefectPairBuilder(DefectBuilder):
def create_defect_pair(
self,
Expand Down
6 changes: 6 additions & 0 deletions src/py/mat3ra/made/tools/build/defect/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class AtomPlacementMethodEnum(str, Enum):
EQUIDISTANT = "equidistant"
# Places the atom at the existing or extrapolated crystal site closest to the given coordinate.
CRYSTAL_SITE = "crystal_site"
# Places the atom at the hollow site of the surface (for HEX)
HOLLOW_SITE = "hollow"
# Places the atom at the bridge site of the surface (for HEX)
BRIDGE_SITE = "bridge"
# Places the atom at the on-top site of the surface (for HEX)
ON_TOP_SITE = "on_top"


class CoordinatesShapeEnum(str, Enum):
Expand Down
Loading