Repository navigation
Fix(cell): require LATTICE_PARAMETERS for non-cubic named lattices - #8355
DanielZhao0432 wants to merge 7 commits into
Conversation
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.
…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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
… 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
left a comment
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
Fixes #8354.
What's changed?
In
unitcell::read_lattice_constant():latnamevalues exceptsc/fcc/bcc) now require theLATTICE_PARAMETERSline; if it is missing, the run quits with a clear error naming the lattice type.LATTICE_VECTORSpath as well.trigonalbranch validates thecos(alpha)extraction explicitly: a failed read previously leftcosab = 0and 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:hexagonalwithoutLATTICE_PARAMETERS-> third lattice vector = 0, cell volume = 0, function returns successtriclinicwithoutLATTICE_PARAMETERS-> lattice vectors contain NaN (0/0 in the shape formula)After the fix, both cases exit with the new error message; valid inputs (hexagonal with c/a, trigonal with cos(alpha),
scwithout parameters, explicitLATTICE_VECTORS) are unaffected.User-visible behavior changes
A run whose STRU selects a non-cubic
latnamebut omitsLATTICE_PARAMETERSnow 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 thatLATTICE_PARAMETERSmust 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
source/source_cell/unittests/test_read_atom_species.cpp(6 cases: missing params rejected for hexagonal and trigonal, malformed trigonal parameter value, degenerateLATTICE_VECTORSrejected, valid hexagonal and cubic controls).python3 tools/03_code_analysis/agent_governance_check.py --staged— pass.Governance Notes
source_cellSTRU input parsing only; no interface changes.