================================================================================
 ccNAO: CORRELATION-CONSISTENT LAYERED CONSTRUCTION OF NATURAL ATOMIC ORBITALS
 Method description and implementation record -- 2026-08-15
================================================================================

STATUS   : IMPLEMENTED 2026-08-15 as `--nao-algorithm cc-layers` (aliases:
           `cclayers`, `cc`), alongside `rigorous` (one-cycle, NBO7-equivalent)
           and `frozen-nmb` (two-cycle, the default). Constant
           NAO_ALG_CC_LAYERS = 3 in snvo_nao_types.f90.
SCOPE    : All wavefunction inputs that go through the internal NAO builder
           (.fchk/.fch, .json, .molden, .tmol, .gms, and the xTB lane).
           .49 archives bypass every constructor (NAOs come from NBO7).
PURPOSE  : (1) Natural atomic orbitals whose radial occupation ladders are
           MONOTONIC for correlated (post-HF) one-electron densities;
           (2) an atomic-orbital representation whose shell structure mirrors
           the construction logic of Dunning's correlation-consistent basis
           sets, providing a natural, physically motivated truncation
           hierarchy for virtual-space reduction in correlation-energy
           calculations (the SNVO programme).


--------------------------------------------------------------------------------
1. ONE-PARAGRAPH SUMMARY
--------------------------------------------------------------------------------

The ccNAO construction generalises the two-cycle frozen-NMB algorithm to a
multi-cycle, layer-by-layer scheme. Cycle 1 (identical to frozen-NMB) yields
the natural minimal basis (NMB) of core + valence NAOs, which is frozen. Each
subsequent cycle k = 1, 2, ... then extracts from the residual orbital space --
everything S-orthogonal to all previously frozen functions -- exactly ONE
ANO-like natural radial function per (atom, l) channel with l <= l_val + k,
orthonormalises the resulting shell layer WITHIN ITSELF ONLY, and freezes it
before the next cycle begins. For carbon the progression reads

    ( ( ( NMB(1s 2s 2p) )+ 3s 3p 3d )+ 4s 4p 4d 4f )+ 5s 5p 5d 5f 5g ...

i.e. exactly the shell progression by which Dunning's cc-pVXZ sets are built
(and, for hydrogen, 1s -> 2s2p -> 3s3p3d -> ...). Because every layer is
selected from a SUBSPACE of the previous layer's complement, the per-channel
occupations are non-increasing from layer to layer -- the monotonic radial
ladder (3s >= 4s >= 5s >= ...) that the single-shot frozen-NMB Rydberg
construction loses for correlated densities.


--------------------------------------------------------------------------------
2. MOTIVATION
--------------------------------------------------------------------------------

2.1 The defect being fixed

The frozen-NMB algorithm builds the entire Rydberg complement in ONE shot:
all residual directions are diagonalised per (atom, l) block, and a single
occupation-weighted symmetric orthogonalisation (OWSO) then runs across the
WHOLE Rydberg set. For HF/DFT densities the Rydberg occupations are tiny and
strongly hierarchical, so their ordering survives. For post-HF densities the
Rydberg occupations are larger and much flatter, and the global OWSO
redistributes occupation between near-degenerate directions across channels
and atoms. The result is radial ladders that are not monotonic, e.g.

    1s -> 2s -> 3s -> 4s   =   2.000 -> 1.800 -> 0.010 -> 0.018   (WRONG order)

where the standard NBO7-type construction gives 0.015 -> 0.004 -> 0.0005.
Observed in practice (this repository, HF molecule, CCSD/cc-pV7Z linearised
densities): frozen-nmb F 3d = 0.00018 < 4d = 0.00063; even at RHF the deep
tail can invert (F 3p = 0.00003 < 4p = 0.00004 < 5p = 0.00005).

2.2 The constructive idea

Dunning's correlation-consistent basis sets are built by adding CORRELATING
FUNCTIONS IN SHELLS of near-equal energy contribution: cc-pVDZ adds {1s1p1d}
beyond the atomic HF set, cc-pVTZ adds {2s2p2d1f}, and so on -- each cardinal
adds one function to every existing correlating channel plus one new highest-l
channel. The ccNAO construction transplants that logic to the NAO problem:
instead of tuning the basis set, generate the NAOs so that their radial/
angular hierarchy is consistent with how the correlation-consistent sets
themselves are organised. The resulting representation

    * has monotonically ordered, ANO-like radial functions per channel,
    * converges smoothly with the cardinal number of the underlying basis,
    * and provides a natural layer index for TRUNCATING the virtual space:
      keeping NMB + layer1 + ... + layerK is the NAO-space analogue of
      evaluating correlation in a cc-pV(K+1)Z-quality virtual space.

The last point is the SNVO use case: cheap correlation-energy estimates from
a reduced virtual space whose composition is basis-set-consistent by design
rather than by per-system tuning (cf. frozen natural orbitals, but atom-
resolved, shell-structured, and independent of a molecular NO threshold).


--------------------------------------------------------------------------------
3. NOTATION AND PREREQUISITES
--------------------------------------------------------------------------------

    S               AO overlap matrix (n x n)
    D               spinless one-electron density matrix in the AO basis
                    (alpha + beta for unrestricted; natural-orbital expansion
                    for post-HF: CASSCF / MPn / CC relaxed or unrelaxed)
    M = S D S       the occupation quadratic form: for an S-normalised vector
                    v (v^T S v = 1) expressed in AO coefficients, its
                    occupation is the Rayleigh quotient  n_v = v^T M v
    channel (A, l)  the set of all radial basis functions of angular momentum
                    l on atom A, each carrying 2l+1 magnetic components; the
                    parser-side Cartesian decomposition contributes its
                    augmented sub-shells (r^2-type radial powers) as ordinary
                    members of the channel
    l_val(A)        highest l of the occupied valence shells of atom A
                    (from nao_core_val_shells, Z_eff/ECP-aware)
    l_core(A)       highest l among core shells (relevant with ECPs)
    m-averaging     every per-channel eigenproblem is solved ONCE on matrices
                    averaged over the 2l+1 magnetic components, and the
                    resulting radial rotation is replicated identically over
                    all m. This is what makes the construction covariant under
                    molecular rotations (the same device is used throughout
                    the NBO machinery and in frozen-NMB cycle 2).

All orthogonality statements below are in the S metric.


--------------------------------------------------------------------------------
4. THE CONSTRUCTION
--------------------------------------------------------------------------------

4.1 Cycle 1 -- the NMB (identical to frozen-NMB)

  (a) Truncate the basis per atom to l <= l_val(A) + 1 (never below
      l_core(A)); polarisation channels (l > l_val) keep only their 3
      tightest contractions (constants FROZEN_L_OFFSET = 1,
      FROZEN_POL_CAP = 3).
  (b) Compress the density onto the truncated space by the Galerkin
      S-metric projection
          D_t = S_kk^-1 S_kf D S_fk S_kk^-1 ,
      an operator compression whose (D_t, S_t) occupations are generalized
      Rayleigh quotients of (D, S) -- Pauli bounds cannot be violated by the
      truncation itself.
  (c) Run the UNMODIFIED rigorous (NBO7-equivalent) pipeline on (D_t, S_t).
      Its Core + Valence NAOs constitute the NMB.
  (d) LIFT: zero-pad the NMB coefficient columns back to the full basis.
      Because S_t is a principal submatrix of S, the padded columns are
      EXACTLY S-orthonormal and carry EXACTLY zero high-l coefficients; no
      re-orthonormalisation is applied or needed.

  The NMB is now FROZEN: no later step ever modifies these columns. By
  construction it is identical -- to the last digit -- to the frozen-NMB
  algorithm's NMB.

4.2 The residual bookkeeping

  A working copy of all n AO unit vectors is kept and maintained
  S-orthogonal to everything frozen so far by twice-iterated classical
  Gram-Schmidt (CGS2): initially projected against the NMB, and after each
  frozen layer projected against that layer's columns (a vector already
  orthogonal to the older frozen sets remains so under CGS2 against the new
  layer -- see 4.4(f) for the drift-cleanup pass that removes the residual
  numerical error of this incremental scheme).

  Per channel (A, l) the integer used(A, l) counts how many radial
  directions the channel has donated so far (initialised to the channel's
  NMB membership), and nrad(A, l) is the channel's total number of radial
  functions in the computational basis. A channel is retired ("dead") when
  its independent residual directions are exhausted.

4.3 The layer l-cap (the Dunning rule)

  In cycle k, channel (A, l) is eligible iff

      l  <=  max( l_val(A) + k , l_core(A) )        and nrad(A, l) > 0 .

  So carbon (l_val = 1) unlocks d in layer 1, f in layer 2, g in layer 3;
  hydrogen (l_val = 0) unlocks p in layer 1, d in layer 2, ... -- exactly the
  cc-pVXZ polarisation pattern. Channels whose l is absent from the basis
  simply never appear: layers are INCOMPLETE BY DEFINITION whenever the
  computational basis lacks the corresponding functions (a free-primitive
  12s6p3d set yields layer 4 = 4s 4p 4d and nothing else -- no f).

4.4 One cycle k, step by step

  For every eligible, live channel (A, l):

  (a) Collect the channel's residual block: the working columns of its
      nrad x (2l+1) basis functions. Form the block Gram G = X^T S X and
      occupation Q = X^T M X, and m-average both to nrad x nrad matrices
      G_avg, Q_avg.

  (b) Canonical orthonormalisation of the radial space: diagonalise G_avg
      (eigenvalues ascending). Drop exactly used(A, l) directions
      (count-based: the directions already donated to frozen sets have been
      projected out, so the residual Gram has exactly that many null
      directions), plus any further direction whose eigenvalue falls below
      the relative linear-dependence threshold

          g_j < FROZEN_EPS_LD * g_max ,      FROZEN_EPS_LD = 1e-7 .

      If nothing survives, the channel is exhausted: retire it and count its
      remaining directions as dropped linear dependencies.

  (c) Natural radial selection: in the canonically orthonormalised residual,
      diagonalise the m-averaged occupation form and keep ONLY the
      eigenvector with the LARGEST eigenvalue -- the channel's ANO-like
      natural radial function of this layer, with occupation
      n = max Rayleigh quotient of (D, S) over the channel's residual.
      Replicate the radial rotation over the 2l+1 magnetic components.

  (d) Label it n(l) = l + 1 + used(A, l) (e.g. carbon s: {1s, 2s} in the
      NMB -> 3s in layer 1, 4s in layer 2; first d -> 3d), then increment
      used(A, l).

  (e) LAYER ASSEMBLY. All vectors selected in this cycle -- at most one
      radial function per channel, each carrying its 2l+1 components -- form
      the layer.

  (f) DRIFT CLEANUP. CGS2-project the assembled layer against the ENTIRE
      frozen set. (The incremental residual maintenance of 4.2 is exact in
      theory but accumulates rounding over many cycles; one CGS2 pass over
      the layer's few columns bounds the orthogonality error of each layer
      independently of history. Observed effect: max |T^T S T - I| improves
      by 1-2 orders of magnitude on cardinal-7 bases.)

  (g) WITHIN-LAYER ORTHONORMALISATION -- never across layers:
        * occupation-weighted symmetric orthogonalisation (OWSO) over the
          layer, weights w = max(n, 1e-6) (the floor mirrors the rigorous
          pipeline's low-occupancy Rydberg rule);
        * if the weighted overlap is singular (cross-atom degeneracy among
          diffuse members -- rare), drop the lowest-occupation channel group
          of the layer, retire that channel, count its remainder as linear
          dependencies, and retry;
        * symmetric (Lowdin) polish to machine precision.
      Both operations form linear combinations INSIDE the layer subspace, so
      every previously frozen function -- NMB and earlier layers -- stays
      bit-exact.

  (h) FREEZE the layer; CGS2 the working residuals against it; proceed to
      cycle k+1. The loop terminates when every channel is retired (the
      l-cap grows with k, so every live channel is eventually unlocked and
      donates one direction per cycle; a safety bound of n + l_max + 2
      cycles exists but is unreachable).

4.5 Packaging and finalisation

  NAOs are ordered atom-major (the ll/lu/norbs contiguity contract):
  for each atom, its NMB functions first, then its Rydberg functions in
  FREEZE ORDER -- so per channel the principal labels ascend with the layer
  index, and `--table shell` prints the layer structure directly
  (3s 3p 3d | 4s 4p 4d 4f | ...). The assembled transform is handed to the
  SAME stage_finalize (D_NAO = T^T S D S T, occupations = diagonal,
  T^T S T retained as diagnostic) and stage_fixdm (Pauli enforcement for
  post-HF densities) used by the other constructions.


--------------------------------------------------------------------------------
5. FORMAL PROPERTIES
--------------------------------------------------------------------------------

  P1 (NMB exactness). The NMB is identical to frozen-NMB's: cycle 1 is the
     same code path, and no later step touches frozen columns.

  P2 (monotonicity). Let C_k be the residual complement from which layer k
     selects, and n_k(A, l) the occupation of the vector channel (A, l)
     donates in layer k. Since C_(k+1) is a SUBSPACE of C_k (the layer is
     removed and nothing is added), the maximum Rayleigh quotient of (D, S)
     over the channel's residual cannot increase:

         n_1(A, l)  >=  n_2(A, l)  >=  n_3(A, l)  >=  ...

     at selection time, for ANY density -- HF, DFT, or post-HF. CAVEAT: the
     guarantee is exact for the SELECTED vectors; the within-layer OWSO
     (4.4g) subsequently deforms weakly-occupied members that overlap
     strongly with other atoms' members of the SAME layer, and the final
     (post-deformation) occupations can invert by the amount OWSO moved.
     In practice this is confined to near-zero-occupied polarisation
     channels of hydrogens in molecules (observed <= 7e-4 electrons, see
     section 7); for ISOLATED ATOMS there is no cross-atom overlap and the
     monotonic ladder is exact -- which is the reference-system regime of
     the virtual-space-reduction application.

  P3 (rotational covariance). Every eigenproblem is m-averaged and its
     radial rotation replicated over the magnetic components (4.4a/c), so
     the construction commutes with molecular rotations to numerical
     precision; symmetry-equivalent atoms receive equivalent NAOs.

  P4 (Pauli bounds). Every occupation produced by the construction is a
     Rayleigh quotient of (D, S), hence confined to the eigenvalue range of
     the input density; the truncation of cycle 1 (Galerkin compression) and
     the selection of 4.4(c) cannot manufacture occupations outside [0, 2]
     (spinless). Genuine N-representability violations of post-HF input
     densities are handled downstream by the shared fixdm stage, as for the
     other constructions.

  P5 (completeness / rank). Apart from directions dropped as linear
     dependencies (the count-based drops are exact rank bookkeeping; the
     eps-drops use FROZEN_EPS_LD), the construction consumes the whole AO
     space: n_NAO = n_AO - n_LD. Note that ccNAO currently applies NO global
     inter-atomic LD sweep (frozen-NMB's ryd_ld_sweep analogue): on heavily
     redundant bases it therefore retains near-dependent directions that
     frozen-NMB would drop, trading a somewhat looser final orthonormality
     for strict full rank (see sections 7-8).

  P6 (basis-set consistency). For a family of correlation-consistent bases
     of increasing cardinal, the layer composition is stable by
     construction: enlarging the basis refines existing layers and appends
     new ones rather than reshuffling the hierarchy. (This is the property
     that makes NMB + K layers a meaningful, transferable virtual-space
     truncation; systematic CBS-convergence benchmarks are part of the
     SNVO project.)


--------------------------------------------------------------------------------
6. RELATION TO EXISTING CONSTRUCTIONS
--------------------------------------------------------------------------------

  rigorous (NBO7-equivalent)   One cycle on the full basis; protected
                               core/valence/Rydberg cascade; global Rydberg
                               treatment. Monotonic ladders in practice, but
                               subject to High-L Redundancy Leakage on
                               polarised cardinal >= 4 bases (see
                               NAO_issue_high-L.txt) and no layer structure.

  frozen-nmb (default)         Two cycles: frozen NMB + single-shot Rydberg
                               complement with GLOBAL occupation-weighted
                               OWSO. HLRL-free, CBS-smooth NMB; Rydberg
                               ladders can reorder (sec. 2.1).

  cc-layers (ccNAO, this doc)  N cycles: frozen NMB + one frozen shell-layer
                               per cycle, orthogonalisation confined within
                               each layer. Monotonic ladders (P2), Dunning-
                               consistent layer hierarchy, designed for
                               virtual-space truncation.

  Conceptual relatives: atomic natural orbitals (Almlof & Taylor) -- ccNAO's
  per-channel selection is an ANO step performed in the molecular
  environment, on the m-averaged atomic-block density, under a frozen-
  subspace constraint; frozen natural orbitals (FNO) virtual-space
  truncation -- ccNAO provides an atom-resolved, shell-structured
  alternative whose truncation parameter is a LAYER INDEX rather than a
  molecular NO occupation threshold; and, of course, the construction logic
  of the correlation-consistent basis sets themselves (Dunning).


--------------------------------------------------------------------------------
7. NUMERICAL VALIDATION (2026-08-15, this repository)
--------------------------------------------------------------------------------

Systems: Ne atom (RHF and CCSD-unrelaxed, aug-cc-pV7Z); HF molecule (RHF and
CCSD-linearised, cc-pV7Z; ORCA 6.1.1 JSON); benzene (RHF/UHF def2-TZVPP, RHF
aug-cc-pV5Z); C7H7WCl2 (ECP, Gaussian fchk). All runs: -b nao.

  (i) Electron-count exactness: Tr[D_NAO] equals N to all printed digits on
      every system (10, 42, 82 with the 60-e ECP).

 (ii) Orthonormality, max|T^T S T - I| (via --nao-debug "full set" check):

          C7H7WCl2 / ECP fchk        (n = 182)     1.5e-13
          HF / cc-pV7Z RHF + CCSD    (n = 376)     1.2e-11
          benzene / aug-cc-pV5Z      (n = 1242)    9.5e-09   [full rank kept;
                                                   frozen-nmb: 2.3e-10 at
                                                   n = 1194, 48 LD dropped]

(iii) Monotonicity of radial ladders (per (atom, l) channel, tolerance
      1.5e-5 = table display rounding):

          system                     frozen-nmb           cc-layers
          Ne CCSD aug-cc-pV7Z        OK (atom)            OK (exact, P2)
          HF CCSD cc-pV7Z            3d < 4d (x3.5)       OK
          HF RHF cc-pV7Z             2s < 3s              3p < 4p (2e-5)
          benzene RHF aug-cc-pV5Z    H 3s < 4s            OK
          benzene RHF/UHF TZVPP      H 2p < 3p (x2.9)     H 2p < 3p (x2.0)

      Residual cc-layers inversions are the P2 caveat: within-layer
      cross-atom OWSO on near-zero-occupied H polarisation channels
      (absolute size 2e-5 ... 7e-4 electrons).

 (iv) Downstream stability: benzene EDDB_G = 6.048 (TZVPP) / 6.018 (a5Z),
      in family with rigorous and frozen-nmb (6.05 / 6.00); W-complex
      EDDB_G = 9.977 vs 9.974 (frozen-nmb).

  (v) Cost: benzene/aug-cc-pV5Z (1242 AOs, 66 channels, tens of layers)
      completes the full construction + EDDB analysis in ~8 s wall
      (Linux, OpenBLAS); the layer loop is dominated by the same BLAS-3
      kernels as frozen-NMB cycle 2.


--------------------------------------------------------------------------------
8. KNOWN LIMITATIONS AND OPEN DESIGN KNOBS
--------------------------------------------------------------------------------

  L1  Within-layer cross-atom OWSO can invert near-zero-occupied channels
      (P2 caveat). Candidate refinement: sequential CGS2 within the layer in
      DESCENDING occupation order (highest-occupation member kept exact), or
      an occupation-preserving Jacobi sweep. Not implemented; the symmetric
      OWSO matches the established NBO practice and the observed deviations
      are far below chemical relevance.

  L2  No global inter-atomic LD sweep: on heavily redundant bases ccNAO
      keeps full rank at the price of ~1e-9 orthonormality (sec. 7.ii). If
      rank-reduction parity with frozen-nmb is wanted, port ryd_ld_sweep as
      a per-layer guard (drop the dominating channel group when the layer-
      plus-frozen Gram develops a near-null direction).

  L3  The l-cap uses l_val + k with the 0:3 core/valence tables of
      nao_core_val_shells; superheavy/exotic ECP configurations beyond
      l = 3 valence would need those tables extended (shared limitation
      with frozen-nmb cycle 1).

  L4  Layer index is implicit (recoverable as n - n_val(l) from the labels);
      no explicit per-NAO layer array is exported yet. Add one to NAOData if
      the SNVO truncation driver wants it directly.

  L5  The construction operates on the SPINLESS density (alpha + beta), as
      do the other constructions; spin-resolved layer variants (separate
      alpha/beta selection) are unexplored.


--------------------------------------------------------------------------------
9. IMPLEMENTATION MAP
--------------------------------------------------------------------------------

  snvo_nao_types.f90    NAO_ALG_CC_LAYERS = 3 (+ doc comment)
  snvo_cli_parser.f90   --nao-algorithm cc-layers|cclayers|cc; help text
  snvo_nao_driver.f90   compute_nao: dispatch;
                           compute_nao_cc_layers: cycle-1 reuse
                             (frozen_truncate_wf -> rigorous -> lift) +
                             cc_layers_assemble + stage_finalize/stage_fixdm;
                           cc_layers_assemble: sections 4.2-4.5 verbatim
                             (block machinery shared in style with
                             frozen_assemble; CGS2/OWSO from
                             snvo_nao_orth; frozen_lowdin_polish reused);
                           --nao-debug prints per-construction "full set"
                             orthonormality checks (cc-layers AND frozen-NMB)
  snvo_main.f90         stage message, info-block label, --export-fchk ao
                           header tag "| cc-layers", citation routing
                           (npa1985 + fnmb: cycle 1 is the frozen-NMB NMB)

  Thresholds (shared with frozen-NMB, declared in snvo_nao_driver.f90):
      FROZEN_L_OFFSET = 1, FROZEN_POL_CAP = 3   (cycle 1)
      FROZEN_EPS_LD   = 1e-7                    (relative Gram LD drop)
      OWSO weight floor 1e-6                    (within-layer OWSO)

  Usage:
      runEDDB -i file.json -b nao --nao-algorithm cc-layers --table shell
      runEDDB -i file.json -b nao --nao-algorithm cc-layers \
              --export-fchk ao          # NAO vectors in layer order per atom
      ... --nao-debug                   # layer count, LD count, T^T S T check

  The `--table shell` view (subshell-resolved populations) prints the layer
  hierarchy directly; `--table ao,shell` adds the per-NAO resolution with
  AO indices matching the exported .fchk.


--------------------------------------------------------------------------------
10. REFERENCES
--------------------------------------------------------------------------------

  [1] A. E. Reed, R. B. Weinstock, F. Weinhold, "Natural population
      analysis", J. Chem. Phys. 83 (1985) 735. DOI 10.1063/1.449486.
      (The NAO definition; the rigorous pipeline follows this algorithm.)
  [2] E. D. Glendening, C. R. Landis, F. Weinhold, "NBO 7.0", J. Comput.
      Chem. 40 (2019) 2234. DOI 10.1002/jcc.25873. (Reference
      implementation for the rigorous construction.)
  [3] D. W. Szczepanik, "Natural Atomic Orbitals at the Complete-Basis-Set
      Limit: A Frozen Natural-Minimal-Basis Construction", J. Comput.
      Chem., under review. (Cycle 1 / the NMB; the frozen-NMB two-cycle
      construction that ccNAO generalises.)
  [4] T. H. Dunning, Jr., "Gaussian basis sets for use in correlated
      molecular calculations. I.", J. Chem. Phys. 90 (1989) 1007.
      DOI 10.1063/1.456153. (The correlation-consistent shell progression
      the layers mirror.)
  [5] J. Almlof, P. R. Taylor, "General contraction of Gaussian basis sets.
      I. Atomic natural orbitals", J. Chem. Phys. 86 (1987) 4070.
      DOI 10.1063/1.451917. (ANO selection; sec. 6.)
  [6] C. Sosa, J. Geertsen, G. W. Trucks, R. J. Bartlett, J. A. Franz,
      "Selection of the reduced virtual space for correlated calculations",
      Chem. Phys. Lett. 159 (1989) 148. DOI 10.1016/0009-2614(89)87399-3.
      (Virtual-space truncation by natural orbitals; the FNO family, cf.
      sec. 6.)

================================================================================
