Skip to content

Commit

Permalink
update: optimize and genetalize
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Sep 13, 2024
1 parent 283f364 commit def1ca7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/py/mat3ra/made/tools/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def calculate_on_xy_grid(
grid_range_x: Tuple[float, float] = (-0.5, 0.5),
grid_range_y: Tuple[float, float] = (-0.5, 0.5),
use_cartesian_coordinates: bool = False,
) -> np.ndarray:
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Calculate a property on a grid of x-y positions.
Expand All @@ -538,7 +538,7 @@ def calculate_on_xy_grid(
use_cartesian_coordinates (bool): Whether to use Cartesian coordinates.
Returns:
np.ndarray: The calculated values on the grid.
Tuple[np.ndarray, np.ndarray, np.ndarray]: The x-values, y-values, and the results matrix.
"""
x_values = np.linspace(grid_range_x[0], grid_range_x[1], grid_size_xy[0]) + grid_offset_position[0]
y_values = np.linspace(grid_range_y[0], grid_range_y[1], grid_size_xy[1]) + grid_offset_position[1]
Expand All @@ -556,4 +556,4 @@ def calculate_on_xy_grid(
result = calculator(modified_material, **calculator_parameters)
results_matrix[i, j] = result

return results_matrix
return x_values, y_values, results_matrix
13 changes: 4 additions & 9 deletions src/py/mat3ra/made/tools/build/interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,23 @@ def get_optimal_film_displacement(
grid_range_x=(-0.5, 0.5),
grid_range_y=(-0.5, 0.5),
use_cartesian_coordinates=False,
calculator: Callable = get_sum_of_inverse_distances_squared,
calculator: Callable = calculate_film_substrate_interaction_metric,
):
results_matrix = calculate_on_xy_grid(
x_values, y_values, results_matrix = calculate_on_xy_grid(
material,
modifier=displace_interface,
modifier_parameters={},
calculator=calculator,
calculator_parameters={},
calculator_parameters={"shadowing_radius": 2.5, "metric_function": get_sum_of_inverse_distances_squared},
grid_size_xy=grid_size_xy,
grid_offset_position=grid_offset_position,
grid_range_x=grid_range_x,
grid_range_y=grid_range_y,
use_cartesian_coordinates=use_cartesian_coordinates,
)
min_index = np.unravel_index(np.argmin(results_matrix), results_matrix.shape)
min_value = results_matrix[min_index]

# Calculate the corresponding x, y coordinates
x_values = np.linspace(grid_range_x[0], grid_range_x[1], grid_size_xy[0]) + grid_offset_position[0]
y_values = np.linspace(grid_range_y[0], grid_range_y[1], grid_size_xy[1]) + grid_offset_position[1]

optimal_x = x_values[min_index[0]]
optimal_y = y_values[min_index[1]]

return [optimal_x, optimal_y, 0], min_value
return [optimal_x, optimal_y, 0]

0 comments on commit def1ca7

Please sign in to comment.