8000 Support 1D/2D periodic boundary conditions in cutoff and Wigner-Seitz routines by marvinfriede · Pull Request #155 · grimme-lab/mctc-lib · GitHub
[go: up one dir, main page]

Skip to content

Support 1D/2D periodic boundary conditions in cutoff and Wigner-Seitz routines - #155

Merged
marvinfriede merged 32 commits into
mainfrom
feat/periodic-1d-2d
Nov 8, 2026
Merged

marvinfriede merged 32 commits into
mainfrom
feat/periodic-1d-2d

Conversation

@marvinfriede
@marvinfriede marvinfriede commented Nov 4, 2026 •
Copy link
Copy Markdown
Member

Extend real-space cutoff lattice generation, central-cell coordinate wrapping, and Wigner–Seitz cell construction to arbitrary 1D and 2D periodic boundary conditions alongside 0D and 3D systems, with explicit error_type error handling.

I made the error argument required for most functions. However, since some are in the public API, I added legacy overloads that retain the old behavior (no or optional error propagation). In the future, we can just delete these.

@codecov
codecov Bot commented Nov 4, 2026 •
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 9.70%. Comparing base (73fc4ca) to head (5e4b7df).

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #155      +/-   ##
=========================================
- Coverage   11.84%   9.70%   -2.14%     
=========================================
  Files           5       4       -1     
  Lines         211     206       -5     
  Branches       97      97              
=========================================
- Hits           25      20       -5     
  Misses        176     176              
  Partials       10      10              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lmseidler lmseidler left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and regarding all the legacy methods: do we really want to keep them? i think for us it's not common practice, especially since these are not really exposed to a public api in this case.

Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/cutoff.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/cutoff.f90 Resolved
Comment thread src/mctc/cutoff.f90 Resolved
@marvinfriede
Copy link
Copy Markdown
Member Author

and regarding all the legacy methods: do we really want to keep them? i think for us it's not common practice, especially since these are not really exposed to a public api in this case.

Only temporarily. The get_cn and new_wignerseitz_cell subroutines are used in upstream packages already and I did not want to break them. We should only remove them once we replaced everything upstream.

marvinfriede and others added 5 commits November 4, 2026 20:38
Replace the per-dimension LLL/Babai/Fincke-Pohst repetition bounds by one
conservative bound in the periodic subspace. For the inverse metric G^-1 of
the periodic lattice vectors and the fractional coordinates s of a pair, all
competing images satisfy |n_k - s_k| <= sqrt((d0^2 + tol) G^-1_kk), where d0
is the parallel distance to an admissible (non-self) candidate image.

- Add get_inverse_metric to mctc_cutoff and use it for cutoff repetitions,
  wrapping, and the Wigner-Seitz bound, handling 1D/2D/3D alike. A
  one-element periodicity mask again applies to all three directions.
- Drop structure validation from the Wigner-Seitz construction, keep the
  degenerate-lattice check and a single candidate-count limit.
- Keep only integer-range checks for lattice point generation.
- Generate the CSR Wigner-Seitz translations with the dense generator and
  size the image buffers by the number of translations instead of 27.
- Add dense versus CSR image parity tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
The conservative translation bound grows quickly for strongly skewed bases
and rejected valid sheared cells with too many candidate translations.
Apply a pairwise size reduction to the periodic lattice vectors and
generate the candidate translations in the reduced basis. Only physical
translation vectors are used, so no basis transformation is tracked.

Compare cross-basis distances in the exhaustive reference test with a
round-off tolerance and add a strongly sheared 3D regression test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
Rounding of the fractional coordinates of distant unwrapped atoms could
place an image on the edge of the switching interval just outside the
translation box, while the image search on a larger box accepts it. Widen
the bound by a small relative tolerance before the integer conversion.

Add finite difference tests of the image weight derivatives with respect to
the pair vector and to strain for competing images with unequal weights,
matching images by their physical translation, and a regression test for
images on the edge of the switching interval.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
The linked-cell grid inverted the full lattice matrix and failed for
partially periodic structures with zero nonperiodic lattice vectors.
Track the periodicity of each grid direction, replace nonperiodic lattice
vectors by orthogonal directions spanning the structure perpendicular to
the periodic subspace, and only wrap periodic directions in the stencil.
Fully periodic and molecular grids are unchanged.

Add dense versus CSR Wigner-Seitz parity and CSR versus Verlet tests for a
slab and a wire with zero and arbitrary nonperiodic lattice vectors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
The multicharge Ewald and EEQ implementations use get_periodic_axes from
mctc_cutoff. Keep it with its explicit loop and use it for the inverse
metric and the linked-cell grid. A one-element periodicity mask applies to
all three directions, consistent with the lattice point generation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
marvinfriede and others added 5 commits November 4, 2026 21:40
Add wrapped slab and wire structures with three linked cells along every
periodic direction to the CSR versus Verlet tests, which use the direct
translation lookup of the linked cells instead of the general stencil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
Check the cutoff before returning the origin for nonperiodic structures,
such that a negative or NaN cutoff fails the same way for every
periodicity mask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
The generic get_pairs and its two wrappers only adapted calling
conventions around find_wsc_pairs. Callers now use find_wsc_pairs
directly, which returns the total number of competing images, stores
the nearest min(nimg, size(list)) of them, and only counts them for a
zero-length list.

This removes get_pairs from the public API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
Keep one representative case per behavior and remove overlapping
variants:

- Wigner-Seitz: drop the separate robustness and 65 degree tests, reduce
  the exhaustive reference to an oblique slab and a triclinic cell, and
  the limits to one degenerate basis and one oversized search. Image
  storage beyond 27 entries uses a small cell with 56 images instead of
  738.
- find_wsc_pairs: one test for counting and storing tied images.
- Cutoff: one failure each for a negative cutoff, the integer range, and
  a degenerate basis; partial periodicity checks one wire and one slab
  instead of every mask.
- CSR: drop the pyrazole parity case, which the dense test covers against
  the exhaustive reference, and reduce slab and wire variants to one
  general stencil and one direct translation lookup each.

The slab and wire geometries now contain a pair of neighbors across a
periodic boundary after wrapping. Before, the direct translation lookup
was reached but never had to resolve a periodic shift.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: marvinfriede <51965259+marvinfriede@users.noreply.github.com>
@lmseidler lmseidler left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overall this looks much better. there are only some minor things to check

Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
Comment thread src/mctc/wignerseitz.f90 Resolved
@timchem1508
Copy link
Copy Markdown
Contributor

Marvin, can you also, probably add the "problematic" periodic examples to the mstore?

@marvinfriede
marvinfriede commented Nov 6, 2026 •
Copy link
Copy Markdown
Member Author

Marvin, can you also, probably add the "problematic" periodic examples to the mstore?

mstore only holds chemically meaningful structures. Therefore, I would not add the constructed cases from this PR to mstore.

@timchem1508
Copy link
Copy Markdown
Contributor

I've made a small test of this mctc-lib version for the EEQBC charges, and it worked without errors for both dense and sparse implementations.

@marvinfriede
marvinfriede merged commit 25a345f into main Nov 8, 2026
30 of 31 checks passed
@marvinfriede
marvinfriede deleted the feat/periodic-1d-2d branch November 8, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0