Skip to content
Draft
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
13 changes: 6 additions & 7 deletions mace/data/neighborhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ def get_neighborhood(
pbc_y = pbc[1]
pbc_z = pbc[2]
identity = np.identity(3, dtype=float)
max_positions = np.max(np.absolute(positions)) + 1
# Extend cell in non-periodic directions
# For models with more than 5 layers, the multiplicative constant needs to be increased.
# temp_cell = np.copy(cell)
max_positions = np.max(positions, axis=0) - np.min(positions, axis=0)
padding = 1 # 1 angstrom padding

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding is a hard-coded magic number and is currently an int while the rest of the computation is floating-point. Consider using 1.0 and/or factoring this into a named constant (or parameter) so it’s easier to tune/document and consistent with the cell’s float dtype.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +28

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_positions now stores the per-axis position span (max-min), not a maximum. Renaming it (e.g., position_span / extent) would avoid confusion and make the subsequent indexing (max_positions[0], etc.) clearer.

Copilot uses AI. Check for mistakes.

Comment on lines +28 to +29

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding = 1 is a new hard-coded magic number. Consider making this a module-level constant or a function parameter (and use 1.0 to keep everything explicitly float in Angstrom units) so callers/tests can tune it if needed.

Copilot uses AI. Check for mistakes.
if not pbc_x:
cell[0, :] = max_positions * 5 * cutoff * identity[0, :]
cell[0, :] = (max_positions[0] + cutoff + padding) * identity[0, :]
if not pbc_y:
cell[1, :] = max_positions * 5 * cutoff * identity[1, :]
cell[1, :] = (max_positions[1] + cutoff + padding) * identity[1, :]
if not pbc_z:
cell[2, :] = max_positions * 5 * cutoff * identity[2, :]
cell[2, :] = (max_positions[2] + cutoff + padding) * identity[2, :]
Comment on lines +27 to +35

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR fixes a concrete failure mode for pbc=False, but there’s no regression test covering the “large absolute coordinates” example from the PR description. Adding a focused test that constructs a translated cluster (e.g., +5000 Å shift) and asserts get_neighborhood succeeds (and returns a reasonable non-pathological cell / neighbor list) would prevent reintroducing the oversized-cell behavior.

Copilot uses AI. Check for mistakes.

sender, receiver, unit_shifts = neighbour_list(
quantities="ijS",
Expand Down
Loading