Skip to content

Fix(cell): require LATTICE_PARAMETERS for non-cubic named lattices - #8355

Open
DanielZhao0432 wants to merge 7 commits into
deepmodeling:developfrom
DanielZhao0432:fix/named_lattice_params
Open

DanielZhao0432 wants to merge 7 commits into
deepmodeling:developfrom
DanielZhao0432:fix/named_lattice_params

Conversation

@DanielZhao0432

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Fixes #8354.

What's changed?

In unitcell::read_lattice_constant():

  1. Non-cubic named lattices (all latname values except sc/fcc/bcc) now require the LATTICE_PARAMETERS line; if it is missing, the run quits with a clear error naming the lattice type.
  2. After lattice construction, a degenerate (zero-volume) or non-finite cell is rejected, covering malformed parameter values and the LATTICE_VECTORS path as well.
  3. The trigonal branch validates the cos(alpha) extraction explicitly: a failed read previously left cosab = 0 and silently built the simple-cubic (alpha = 90 degree) special case — the only branch where a malformed parameter line still yields a finite, nonzero-volume cell.

Bug confirmation (empirical)

A small throwaway driver calling read_lattice_constant() directly, compiled against current develop sources, confirmed before the fix:

  • hexagonal without LATTICE_PARAMETERS -> third lattice vector = 0, cell volume = 0, function returns success
  • triclinic without LATTICE_PARAMETERS -> lattice vectors contain NaN (0/0 in the shape formula)
  • (all 11 non-cubic names behave this way; the shape-parameter locals default to 0)

After the fix, both cases exit with the new error message; valid inputs (hexagonal with c/a, trigonal with cos(alpha), sc without parameters, explicit LATTICE_VECTORS) are unaffected.

User-visible behavior changes

A run whose STRU selects a non-cubic latname but omits LATTICE_PARAMETERS now stops at the input stage with an explicit message, instead of silently building a zero-volume/NaN cell and failing (or producing NaN) far downstream. This changes no currently-meaningful input: without the line, every one of these lattices produces a degenerate cell today. The documented STRU format already states that LATTICE_PARAMETERS must be present for these lattice types — this PR makes the code enforce the documented contract, so no documentation change is needed.

Unit Tests and/or Case Tests

  • New source/source_cell/unittests/test_read_atom_species.cpp (6 cases: missing params rejected for hexagonal and trigonal, malformed trigonal parameter value, degenerate LATTICE_VECTORS rejected, valid hexagonal and cubic controls).
  • Commands run locally: the throwaway driver above (before/after behavior); the new test binary compiled against system gtest and run — 6/6 pass; python3 tools/03_code_analysis/agent_governance_check.py --staged — pass.
  • No full-project build or ctest run was performed locally; the full matrix is delegated to CI.

Governance Notes

  • Core module impact: source_cell STRU input parsing only; no interface changes.
  • Exceptions requested: none.

Confirmed empirically on current develop: a named non-cubic lattice
without LATTICE_PARAMETERS silently builds a zero-volume cell
(hexagonal, trigonal, ...: shape factors stay zero) or a NaN cell
(triclinic: 0/0 in the shape formula), and the reciprocal-lattice
inversion then fails far from the actual input mistake.

- read_lattice_constant(): require the LATTICE_PARAMETERS line for all
  non-cubic named lattices and quit with a clear message naming the
  lattice type otherwise;
- reject degenerate (zero-volume) or non-finite lattice vectors after
  construction, covering malformed parameter values and the
  LATTICE_VECTORS path as well.

Refs deepmodeling#8354.
A failed extraction left cosab = 0 and silently built the simple-cubic
(alpha = 90 degree) special case instead of the intended trigonal cell;
this is the only named-lattice branch where a malformed parameter line
still yields a finite, nonzero-volume cell, so the determinant check
alone does not catch it.

Also add the corresponding death test and run the new test binary
locally: 6/6 pass.
…riclinic

Address review on deepmodeling#8354: a partially malformed parameter line such as
'2 3 bad' leaves the earlier values in place and the failed one at zero,
producing a finite nonzero-volume cell (e.g. sm gives a diag(1,2,3)-like
lattice with det = 6) that the determinant check alone accepts. Read the
parameter values with a single extraction chain and reject on failure.

Add death tests for the three branches plus a valid sm control; the
local test binary passes 10/10.
@DanielZhao0432 DanielZhao0432 added the Refactor Refactor ABACUS codes label Nov 21, 2026
…errors

An out-of-range value such as 1e999 sets failbit but stores DBL_MAX,
leaving a finite nonzero determinant that escaped both the unchecked
READ_VALUE extraction and the determinant check. Every named-lattice
parameter read (hexagonal, st, bct, so, baco, fco, bco) now validates
extraction directly, matching the sm/bacm/triclinic branches.

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The missing-block checks improve the ordinary cases, but an inline comment can still satisfy the new guard; details are inline. Static review covered the complete diff and affected callers at 29bfe6660f; no build or runtime tests were run, and CI diagnostics were unavailable.

Non-blocking: Please update the PR description from six tests to the ten present at this head, include the sm/bacm/triclinic checks, and give the exact build/run commands for the reported results.

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new stream checks reject the remaining named-lattice range errors by source inspection. Static review at 6cb61e08f6; no builds or runtime/MPI tests were run.

@mohanchen mohanchen added the Bugs Bugs that only solvable with sufficient knowledge of DFT label Nov 22, 2026
DanielZhao0432 and others added 3 commits November 22, 2026 18:04
… fix/named_lattice_params

Require LATTICE_PARAMETERS to begin a line: SCAN_LINE_BEGIN matches the
keyword as any token, so a comment mention satisfied the parameter-section
lookup and shadowed the real section. Combine the lattice-validation tests
with the merged malformed-input suite and adopt its file-I/O logging helper;
add a NaN-detector regression for a parsed but impossible trigonal angle.
…TERS

The parameter-section guard ran before the lattice-name cascade, so an
unsupported latname was met with a demand for LATTICE_PARAMETERS instead
of 'latname not supported' (caught by legacy ReadAtomSpeciesWarning5).
Move the guard after the branches so the name validates first.

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The comment-marker lookup, fixture read logging and non-finite-angle regression are addressed in source. One nonblocking test suggestion remains for unsupported-name diagnostic ordering. Static review of f84bc6cbb431bfa9a49a7eb1dbf3f9c2a9a477e1; no build, runtime tests or CI verification.

// parameters in LATTICE_PARAMETERS; without them the shape variables
// stay zero and produce a zero-volume or NaN cell. The check comes
// after the branches so an unsupported latName reports itself first.
if(latName != "sc" && latName != "fcc" && latName != "bcc")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: Please add an unsupported latName case without LATTICE_PARAMETERS, asserting latname not supported. The legacy ReadAtomSpeciesWarning5 fixture already has that section, so it also passes with the guard before the name cascade and does not protect this diagnostic-ordering fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [source_cell] named Bravais lattices without LATTICE_PARAMETERS silently build zero-volume or NaN cells

3 participants