Skip to content

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

Closed

Description

@DanielZhao0432

Problem

STRU can define the cell by a Bravais lattice name (latname in INPUT) instead of explicit LATTICE_VECTORS. Non-cubic lattice names (hexagonal, trigonal, st, bct, so, baco, fco, bco, sm, bacm, triclinic) need shape parameters (c/a ratio, angles) supplied via the LATTICE_PARAMETERS line. In unitcell::read_lattice_constant() (source/source_cell/read_atom_species.cpp), that line is treated as optional: when it is missing (or mis-typed so the keyword is not found), the local shape variables stay zero and the function silently builds a degenerate cell.

Confirmed with a small driver on current develop (11e4b2b):

  • latname = hexagonal, no LATTICE_PARAMETERS → third lattice vector is zero, cell volume = 0
  • latname = triclinic, no LATTICE_PARAMETERS → lattice vectors contain NaN (0/0 in the shape formula), volume NaN
  • same pattern for the other non-cubic names: all shape-parameter locals default to 0

The degenerate cell is not rejected at the input boundary; the reciprocal-lattice inversion and everything downstream (Ewald sums, symmetry analysis, SCF) then produce NaN, or the program crashes far from the actual mistake.

This code path is load-bearing beyond hand-written STRU files: fixed_ibrav constrained vc-relaxation rebuilds the cell from latname every ionic step (remake_cell).

Proposed fix

  • Require the LATTICE_PARAMETERS line for all non-cubic named lattices (all except sc/fcc/bcc); if missing, quit with a clear error naming the lattice type. This changes no currently-working input: without the line, every one of these lattices currently produces a zero-volume or NaN cell that cannot yield a meaningful run.
  • After lattice construction, reject degenerate or non-finite cells (det(latvec) == 0 or non-finite), covering malformed parameter values and the LATTICE_VECTORS path as well.
  • Unit tests in source/source_cell/unittests/test_read_atom_species.cpp: missing-parameter rejection for representative lattice names, a valid-cell control, and a degenerate LATTICE_VECTORS case.

Activity

  1. ABACUS-PR-BOT commented on Nov 21, 2026

    @ABACUS-PR-BOT
    Collaborator

    Source inspection at 153ad6290f confirms the input-validation defect in all eleven non-cubic branches: missing parameters leave singular geometry (or division by zero for triclinic), yet read_lattice_constant returns true.

    The fix also needs successful numeric extraction. An empty trigonal block can leave a zero cosine and produce a finite, nonsingular cell, so a determinant check alone misses malformed input. Validate before atom-coordinate processing; setup_cell currently ignores the reader’s return value, and rank-0 parsing means error propagation needs an MPI check. Preserve parameter-free sc/fcc/bcc and valid left-handed explicit cells.

    Two qualifications to the reported impact: missing-block scans can warn, and full setup already rejects zero volume later; NaN bypasses that comparison. Also, remake_cell reconstructs from the current vectors rather than rereading STRU each step.

    Focused regressions should cover missing/malformed blocks, singular/nonfinite geometry and valid cubic/non-cubic controls. This is a source-supported diagnosis; the reported 11e4b2b driver and full-run/MPI symptoms were not reproduced.

  2. added
    Bugs
    on Nov 21, 2026
  3. DanielZhao0432 commented on Nov 21, 2026

    @DanielZhao0432
    CollaboratorAuthor

    Thanks for the careful diagnosis. Status update on the upcoming fix (branch fix/named_lattice_params):

    • Missing parameter line: rejected up front for all 11 non-cubic names with an error naming the lattice type. Confirmed empirically that every one of them (including trigonal) builds a zero-volume or NaN cell without the line — there is no currently-working input that this change breaks.
    • Degenerate/non-finite geometry: rejected via det(latvec) after construction, which also covers malformed LATTICE_VECTORS.
    • Malformed trigonal parameter value: agreed and fixed — READ_VALUE hid the extraction failure and left cosab = 0 (the simple-cubic special case, finite and nonsingular, so the determinant check misses it). The trigonal branch now checks the extraction explicitly. The other ten branches collapse to a zero-volume cell on a failed read, which the determinant check catches.
    • Cubic names and left-handed explicit cells: preserved, as you noted they should be.
    • MPI error propagation / ignored return value: the fix follows this function's existing WARNING_QUIT convention (same as "latname not supported"); improving rank-0 error propagation is out of scope here.

    Tests: 6 cases in source/source_cell/unittests/test_read_atom_species.cpp (missing-block rejection for hexagonal/trigonal, malformed trigonal value, degenerate LATTICE_VECTORS, valid hexagonal and cubic controls), built and run locally — 6/6 pass.

  4. ABACUS-PR-BOT commented on Nov 21, 2026

    @ABACUS-PR-BOT
    Collaborator

    The change at 8d8396057531 addresses the missing-block and malformed-trigonal cases, but the determinant check still misses some failed reads.

    For sm, LATTICE_PARAMETERS values 2 3 bad leave the cosine at zero and produce diag(1, 2, 3), with determinant 6. bacm and partially read triclinic angles have the same gap; these branches do not always collapse to zero volume on failed extraction.

    Malformed explicit vectors can also pass: rows 1 0 0 / 0 1 0 / 0 bad 1 leave the final diagonal entry at its default 1 after extraction fails, giving determinant 1. Please validate all required numeric extractions before using the values, retain the geometry check, and add malformed/partial/EOF regressions for these finite-determinant cases. Preserve successfully read final values at EOF. The six submitted tests do not cover these failures.

    This is source inspection of #8355 at that revision; the reported tests were not rerun.

  5. DanielZhao0432 commented on Nov 21, 2026

    @DanielZhao0432
    CollaboratorAuthor

    Confirmed with the driver first: sm with 2 3 bad indeed returned success with det = 6, and triclinic with 0.5 0.5 bad returned success with det = 0.25 — the determinant check alone misses partially-malformed multi-value lines, as you said.

    Fixed in 29bfe66 (pushed to #8355): the sm, bacm and triclinic branches now read their parameter values with a single extraction chain and quit on failure. The remaining two-parameter branches (so, baco, fco, bco) collapse to zero volume on a failed read and stay covered by the determinant check. New death tests cover the three branches (plus a valid sm control); the local test binary passes 10/10.

  6. ABACUS-PR-BOT commented on Nov 21, 2026

    @ABACUS-PR-BOT
    Collaborator

    The sm, bacm, and triclinic extraction checks at 29bfe6660f address those cases, but determinant-only validation still misses range errors in the remaining ratio reads. Under the inspected GNU libstdc++ 13.3 conversion path with ordinary IEEE double arithmetic, latname so, lattice constant 1, and parameters 1 1e999 can set failbit while storing finite DBL_MAX. The resulting diag(1,1,DBL_MAX) has a finite nonzero determinant, so the reader can return success.

    Please validate those required extractions directly and add a range-error regression; the previously noted explicit-vector checks also remain outstanding. This is source analysis under the stated library assumptions, not an executed reproduction.

  7. DanielZhao0432 commented on Nov 22, 2026

    @DanielZhao0432
    CollaboratorAuthor

    Confirmed with the driver first, as before: so with 1 1e999 indeed set failbit while storing DBL_MAX and returned success with a finite det = DBL_MAX. Our "collapses to zero volume" reasoning only covers non-numeric input, not range errors.

    Fixed in 6cb61e0 (pushed to #8355): every LATTICE_PARAMETERS extraction in read_lattice_constant now validates the stream state directly and quits with a message naming the lattice type. While auditing the branches we found the same range-error hole in the single-value hexagonal, st, and bct reads, so those are covered too — the rule is now uniform across all named-lattice parameter reads in this function. Two range-error regressions added (SoRangeOverflowRejected, StRangeOverflowRejected); the CMake test target passes 12/12 locally.

    The explicit-vector (LATTICE_VECTORS) extraction checks noted earlier are covered by the follow-up fix for #8356, deliberately kept in a separate PR scoped to core STRU field validation.

  8. ABACUS-PR-BOT commented on Nov 22, 2026

    @ABACUS-PR-BOT
    Collaborator

    Source inspection at 6cb61e08f648 confirms that the remaining named-lattice range-extraction gap is addressed: all 11 parameter-reading branches now check fail() before using the values. The geometry guard is retained, and the new so/st tests target the reported range-error cases.

    The reported 12/12 pass was not independently rerun. The separate explicit-vector follow-up associated with #8356 has not been assessed here.

  9. DanielZhao0432 commented on Nov 22, 2026

    @DanielZhao0432
    CollaboratorAuthor

    Thanks for confirming — the remaining range-extraction gap is covered by the added regressions, and the follow-up review points on #8355 are addressed at ecc269b and 66701ce.

  10. ABACUS-PR-BOT commented on Nov 22, 2026

    @ABACUS-PR-BOT
    Collaborator

    At 66701cedf7, inline-comment mentions no longer satisfy or shadow LATTICE_PARAMETERS, and unsupported lattice names reach the correct diagnostic before the missing-parameter check. The later merge f84bc6cbb4 retains these parser changes.

    The separate explicit-vector extraction gap is now addressed in develop by #8361 (e2b9082fc8) and inherited by this branch. #8355 remains unmerged. This is a static source assessment; tests and MPI behavior were not rerun.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions