Skip to content

Commit

Permalink
update: use class to pass exact properties
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Sep 13, 2024
1 parent 61ab1e1 commit 7f9f381
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/py/mat3ra/made/tools/build/interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from mat3ra.made.material import Material
from ...calculate import calculate_film_substrate_interaction_metric
from ...calculate import calculate_film_substrate_interaction_metric, InteractionCalculatorParameters
from ...modify import displace_interface_part
from ...analyze import calculate_on_xy_grid
from .builders import (
Expand Down Expand Up @@ -40,13 +40,15 @@ def get_optimal_film_displacement(
grid_range_y=(-0.5, 0.5),
use_cartesian_coordinates=False,
calculator: Callable = calculate_film_substrate_interaction_metric,
calculator_parameters: InteractionCalculatorParameters = InteractionCalculatorParameters(),
):
calculator_parameters_dict = calculator_parameters.dict()
x_values, y_values, results_matrix = calculate_on_xy_grid(
material,
modifier=displace_interface_part,
modifier_parameters={},
calculator=calculator,
calculator_parameters={"shadowing_radius": 2.5, "metric_function": get_sum_of_inverse_distances_squared},
calculator_parameters=calculator_parameters_dict,
grid_size_xy=grid_size_xy,
grid_offset_position=grid_offset_position,
grid_range_x=grid_range_x,
Expand Down
12 changes: 9 additions & 3 deletions src/py/mat3ra/made/tools/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
from mat3ra.made.tools.convert.utils import InterfacePartsEnum
from pydantic import BaseModel

from ..material import Material
from .analyze import get_surface_area, get_surface_atom_indices
Expand Down Expand Up @@ -132,18 +133,23 @@ def calculate_interfacial_energy(
return surface_energy_film + surface_energy_substrate - adhesion_energy


class InteractionCalculatorParameters(BaseModel):
shadowing_radius: float = 2.5
interaction_function: Callable = get_sum_of_inverse_distances_squared


@decorator_handle_periodic_boundary_conditions(cutoff=0.25)
def calculate_film_substrate_interaction_metric(
material: Material,
shadowing_radius: float = 2.5,
metric_function: Callable = get_sum_of_inverse_distances_squared,
interaction_function: Callable = get_sum_of_inverse_distances_squared,
) -> float:
"""
Calculate the interaction metric between the film and substrate.
Args:
material (Material): The interface Material object.
shadowing_radius (float): The shadowing radius to detect the surface atoms, in Angstroms.
metric_function (Callable): The metric function to use for the calculation of the interaction.
interaction_function (Callable): The metric function to use for the calculation of the interaction.
Returns:
float: The calculated norm.
Expand All @@ -170,4 +176,4 @@ def calculate_film_substrate_interaction_metric(
film_coordinates_values = np.array(film_atoms_surface_coordinates.values)
substrate_coordinates_values = np.array(substrate_atoms_surface_coordinates.values)

return metric_function(film_coordinates_values, substrate_coordinates_values)
return interaction_function(film_coordinates_values, substrate_coordinates_values)

0 comments on commit 7f9f381

Please sign in to comment.