From 7f9f381d550dc1c691da08f09fe05632ec3e3e45 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 13 Sep 2024 12:22:45 -0700 Subject: [PATCH] update: use class to pass exact properties --- src/py/mat3ra/made/tools/build/interface/__init__.py | 6 ++++-- src/py/mat3ra/made/tools/calculate.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/py/mat3ra/made/tools/build/interface/__init__.py b/src/py/mat3ra/made/tools/build/interface/__init__.py index 96b23080..bda37268 100644 --- a/src/py/mat3ra/made/tools/build/interface/__init__.py +++ b/src/py/mat3ra/made/tools/build/interface/__init__.py @@ -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 ( @@ -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, diff --git a/src/py/mat3ra/made/tools/calculate.py b/src/py/mat3ra/made/tools/calculate.py index 87007fec..34893ec9 100644 --- a/src/py/mat3ra/made/tools/calculate.py +++ b/src/py/mat3ra/made/tools/calculate.py @@ -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 @@ -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. @@ -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)