Coupled-cluster tools

ElemCo.CCToolsModule
CCTools

A collection of tools for working with coupled cluster theory.

source

Exported functions

ElemCo.CCTools.calc_deco_doubles_normFunction
calc_deco_doubles_norm(T2, tT2=Float64[])

Calculate squared norm of doubles (for decomposed doubles: without contravariant!) T2 are decomposed doubles amplitudes T2[X,Y]=$T_{XY}$ or full doubles amplitudes T2[a,b,i,j]=$T^{ij}_{ab}$.

If the contravariant amplitude tT2 is provided, the norm will be calculated as $T_{XY} T̃_{XY}$.

source
ElemCo.CCTools.calc_singles_energy_using_dfockMethod
calc_singles_energy_using_dfock(EC::ECInfo, T1; fock_only=false)

Calculate coupled-cluster closed-shell singles energy using dressed fock matrix.

if fock_only is true, the energy will be calculated using only non-dressed fock matrix. Returns total energy, SS, OS, and Openshell (0.0) contributions as OutDict with keys (E, ESS, EOS, EO).

source
ElemCo.CCTools.check_projection_rankMethod
check_projection_rank(P, expected_rank::Int, space_name::String)

Check if the projection matrix P has full rank for the expected dimension.

Returns (is_full_rank::Bool, actual_rank::Int). Prints a warning if the rank is less than expected.

source
ElemCo.CCTools.dump_wavefunction_with_amplitudes!Method
dump_wavefunction_with_amplitudes!(EC::ECInfo, T1, T2; orbopt=false)

Dump orbitals and CC amplitudes to the TREXIO file specified in wf.store.

Does nothing if EC.options.wf.store is empty. For closed-shell case with singles T1 and doubles T2.

If orbopt=true, the orbitals are rotated using the T1 amplitudes via rotation_matrix and stored instead of the original orbitals. T1 amplitudes are not stored in that case.

source
ElemCo.CCTools.dump_wavefunction_with_amplitudes!Method
dump_wavefunction_with_amplitudes!(EC::ECInfo, T1a, T1b, T2a, T2b, T2ab; orbopt=false)

Dump orbitals and unrestricted CC amplitudes to the TREXIO file.

Does nothing if EC.options.wf.store is empty.

If orbopt=true, the orbitals are rotated using the T1 amplitudes via rotation_matrix and stored instead of the original orbitals. T1 amplitudes are not stored in that case.

source
ElemCo.CCTools.dump_wavefunction_with_determinants!Method
dump_wavefunction_with_determinants!(EC::ECInfo, dets, coeffs; nstates=0)

Dump orbitals and CIPHI determinants with CI coefficients to TREXIO file(s).

For single-state (nstates=0 or nstates=1), writes to wf.store. For multi-state, writes each state to a separate file per TREXIO standard:

  • State 1: wf.store
  • State n>1: wf.store with _stateN suffix

Does nothing if EC.options.wf.store is empty.

Arguments

  • dets::Vector{<:AbstractDeterminant}: Determinants
  • coeffs::AbstractVecOrMat{<:Number}: CI coefficients (vector for 1 state, matrix for multi-state)
  • nstates::Int=0: Number of states (0 = infer from coeffs)
source
ElemCo.CCTools.project_amplitudesMethod
project_amplitudes(EC::ECInfo, T1_old, T2_old, cMO_old::SpinMatrix, cMO_new::SpinMatrix, 
                   basis_old::BasisSet, basis_new::BasisSet; 
                   classes_old::Tuple{Vector{String},Vector{String}}=(String[], String[]),
                   classes_new::Tuple{Vector{String},Vector{String}}=(String[], String[]))

Project CC amplitudes from an old orbital basis to a new one.

The projection is performed as:

  • Singles: $T_{a}^{i,\text{new}} = P_v^{a'} T_{a'}^{i',\text{old}} P_o^{i'}$
  • Doubles: $T_{ab}^{ij,\text{new}} = P_v^{a'} P_v^{b'} T_{a'b'}^{i'j',\text{old}} P_o^{i'} P_o^{j'}$

where $P$ are projection matrices between old and new orbital spaces.

If classes_old is provided, it is used to determine which orbitals in the old basis were occupied ("Inactive"/"Active") vs virtual ("Virtual"). This is essential when core orbitals are frozen, as the MO coefficient matrix includes all orbitals but amplitudes only involve active orbitals.

If classes_new is provided, it is used similarly for the new basis. Otherwise, EC.space['o'] and EC.space['v'] are used (which may have frozen core indices renumbered from FCIDUMP).

Returns (T1_new, T2_new) for closed-shell case.

source
ElemCo.CCTools.project_amplitudesMethod
project_amplitudes(EC::ECInfo, T1a_old, T1b_old, T2a_old, T2b_old, T2ab_old,
                   cMO_old::SpinMatrix, cMO_new::SpinMatrix,
                   basis_old::BasisSet, basis_new::BasisSet;
                   classes_old=(String[], String[]), occupations_old=(Float64[], Float64[]))

Project unrestricted CC amplitudes from an old orbital basis to a new one.

Arguments

  • classes_old: Tuple of (alphaclasses, betaclasses) orbital class vectors from old calculation. Used to identify Core/Deleted orbitals to exclude.
  • occupations_old: Tuple of (alphaoccupations, betaoccupations) from old calculation. If provided, used to determine occupied/virtual orbitals (more reliable for UHF). If empty, falls back to classes_old or assumes contiguous occupied orbitals.

Returns (T1a_new, T1b_new, T2a_new, T2b_new, T2ab_new).

source
ElemCo.CCTools.read_starting_guess4amplitudesMethod
read_starting_guess4amplitudes(EC::ECInfo, ::Val{level}, spins...)

Read starting guess for excitation level.

The guess will be read from T_vo, T_VO, T_vvoo etc files. If the file does not exist, the guess will be a zeroed-vector.

source
ElemCo.CCTools.rotation_matrixMethod
rotation_matrix(EC::ECInfo, T1; full=false, beta=false)

Make the integrals rotation matrix with T1.

If full is true, the rotation matrix will be made with core and deleted orbitals included.

source
ElemCo.CCTools.save_current_doublesMethod
save_current_doubles(EC::ECInfo, T2a, T2b, T2ab; prefix="T")

Save current doubles amplitudes T2a, T2b, and T2ab to files prefix*"_vvoo", prefix*"_VVOO", and prefix*"_vVoO"

source
ElemCo.CCTools.save_or_start_fileFunction
save_or_start_file(EC::ECInfo, type, excitation_level, save=true)

Return filename and description for saving or starting amplitudes/lagrange multipliers.

type is either "T" for amplitudes or "LM" for Lagrange multipliers. excitation_level is the excitation level of the amplitudes (1, 2 etc.) If save is true, the filename for saving is returned, otherwise the filename for starting.

source
ElemCo.CCTools.spin_project!Method
spin_project!(EC::ECInfo, T1a, T1b, T2a, T2b, T2ab)

Spin-project singles and doubles amplitudes/residuals.

Only possible for high-spin states.

source
ElemCo.CCTools.spin_project_amplitudesFunction
spin_project_amplitudes(EC::ECInfo, with_singles=true)

Spin-project singles (if withsingles) and doubles amplitudes from files `"Tvo","TVO","Tvvoo","TVVOO"and"TvVoO"`.

source
ElemCo.CCTools.triples_4ext_aa!Method
triples_4ext_aa!(EC::ECInfo, R3a, R3aab, T3a, T3aab)

Calculate αα 4-external contractions with triples amplitudes for the unrestricted case. Uses antisymmetrized integrals $\langle cd||ab\rangle$ compressed to $a<b$.

$R^{ijk}_{cde} += \sum_{a<b} \langle cd||ab\rangle T^{ijk}_{eab}$ $R^{ijK}_{cdA} += \sum_{a<b} \langle cd||ab\rangle T^{ijK}_{abA}$

source
ElemCo.CCTools.triples_4ext_aab_ab!Method
triples_4ext_aab_ab!(EC::ECInfo, R3aab, T3aab)

Calculate αβ 4-external contraction of $d_{vVvV}$ with $T^{ijK}_{abC}$ for the unrestricted case. No integral compression (different-spin contracted indices), but loops over one occupied index to reduce intermediate size.

$R^{ijK}_{bcB} -= X_{bcB}^{ijK} - X_{cbB}^{ijK}$ where $X_{bcB}^{ijK} = \sum_{a,A} \langle bB|aA\rangle T^{ijK}_{caA}$

source
ElemCo.CCTools.triples_4ext_abb_ab!Method
triples_4ext_abb_ab!(EC::ECInfo, R3abb, T3abb)

Calculate αβ 4-external contraction of $d_{vVvV}$ with $T^{iIJ}_{aCB}$ for the unrestricted case. No integral compression (different-spin contracted indices), but loops over one occupied index to reduce intermediate size.

$R^{iIJ}_{bBC} -= X_{bBC}^{iIJ} - X_{bCB}^{iIJ}$ where $X_{bBC}^{iIJ} = \sum_{a,A} \langle bB|aA\rangle T^{iIJ}_{aCA}$

source
ElemCo.CCTools.triples_4ext_bb!Method
triples_4ext_bb!(EC::ECInfo, R3b, R3abb, T3b, T3abb)

Calculate ββ 4-external contractions with triples amplitudes for the unrestricted case. Uses antisymmetrized integrals $\langle CD||AB\rangle$ compressed to $A<B$.

$R^{IJK}_{CDE} += \sum_{A<B} \langle CD||AB\rangle T^{IJK}_{EAB}$ $R^{iIJ}_{aCB} += \sum_{A<B} \langle CD||AB\rangle T^{iIJ}_{aAB}$

source
ElemCo.CCTools.try2save_amps!Method
try2save_amps!(EC::ECInfo, ::Val{excitation_level}, amps...; type="T")

Save amplitudes (type="T") or Lagrange multipliers (type="LM") to file EC.options.cc.save[_lm]*"_excitation_level".

source
ElemCo.CCTools.try2save_doubles!Method
try2save_doubles!(EC::ECInfo, doubles...; type="T")

Save doubles amplitudes (type="T") or Lagrange multipliers (type="LM") to file EC.options.cc.save[_lm]*"_2".

source
ElemCo.CCTools.try2save_singles!Method
try2save_singles!(EC::ECInfo, singles...; type="T")

Save singles amplitudes (type="T") or Lagrange multipliers (type="LM") to file EC.options.cc.save[_lm]*"_1".

source
ElemCo.CCTools.try2start_ampsMethod
try2start_amps(EC::ECInfo, ::Val{excitation_level}; type="T")

Read amplitudes (type="T") or Lagrange multipliers (type="LM") from file EC.options.cc.start[_lm]*"_excitation_level".

source
ElemCo.CCTools.try2start_doublesMethod
try2start_doubles(EC::ECInfo; type="T")

Read doubles amplitudes (type="T") or Lagrange multipliers (type="LM") from file EC.options.cc.start[_lm]*"_2".

source
ElemCo.CCTools.try2start_singlesMethod
try2start_singles(EC::ECInfo; type="T")

Read singles amplitudes (type="T") or Lagrange multipliers (type="LM") from file EC.options.cc.start[_lm]*"_1".

source
ElemCo.CCTools.try_fetch_restricted_starting_amplitudesMethod
try_fetch_restricted_starting_amplitudes(EC::ECInfo)

Try to read and project restricted amplitudes from a TREXIO file.

The logic is:

  • If wf.start is not empty: read amplitudes, MOs, and basis from wf.start, then project amplitudes to the current MO basis (obtained via fetch_orbitals from wf.dump).
  • If wf.start is empty: try to read amplitudes from wf.dump (no projection needed).

The occupied space projection rank is checked and a warning is printed if not full rank.

Returns (T1, T2, success::Bool) for closed-shell case.

source
ElemCo.CCTools.try_fetch_starting_determinantsMethod
try_fetch_starting_determinants(EC::ECInfo; OPattern=UInt64, nstates=1)

Try to read determinants and CI coefficients from a TREXIO file for CIPHI restart.

The logic follows CC amplitude restart:

  • If wf.start is not empty: read from wf.start file(s)
  • If wf.start is empty: try to read from wf.dump file(s)

For multi-state, reads from separate files per TREXIO standard.

Returns (dets, coeffs, success::Bool).

source
ElemCo.CCTools.try_fetch_unrestricted_starting_amplitudesMethod
try_fetch_unrestricted_starting_amplitudes(EC::ECInfo)

Try to read and project unrestricted amplitudes from a TREXIO file.

The logic is:

  • If wf.start is not empty: read amplitudes, MOs, and basis from wf.start, then project amplitudes to the current MO basis (obtained via fetch_orbitals from wf.dump).
  • If wf.start is empty: try to read amplitudes from wf.dump (no projection needed).

The occupied space projection rank is checked and a warning is printed if not full rank.

Returns (T1a, T1b, T2a, T2b, T2ab, success::Bool) for unrestricted case.

source
ElemCo.CCTools.update_deco_doublesMethod
update_deco_doubles(EC, R2; use_shift=true)

Update decomposed doubles amplitudes.

If R2 is $R^{ij}_{ab}$, the update is calculated using update_doubles(EC, R2, use_shift=use_shift).

source
ElemCo.CCTools.update_deco_triplesFunction
update_deco_triples(EC, R3, use_shift=true)

Update decomposed triples amplitudes.

Note that the sign of the residual is opposite to the usual definition of the triples residual and therefore the update is calculated using a positive denominator...

source
ElemCo.CCTools.update_doublesMethod
update_doubles(EC::ECInfo, R2; spincase::Symbol=:α, antisymmetrize=false, use_shift=true)

Calculate update for doubles amplitudes for a given spincase∈{,,:αβ}.

source
ElemCo.CCTools.update_singles!Method
update_singles!(EC::ECInfo, T1, R1; damp=1.0)

Update singles amplitudes in T1 with R1. The update is scaled by damp (1.0 = full step; used e.g. as the orbital-rotation damping in OQV methods).

source
ElemCo.CCTools.update_singlesMethod
update_singles(EC::ECInfo, R1; spincase::Symbol=:α, use_shift=true)

Calculate update for singles amplitudes for a given spincase∈{,}.

source
ElemCo.CCTools.update_triples!Method
update_triples!(EC::ECInfo, T3a, T3b, T3aab, T3abb, R3a, R3b, R3aab, R3abb)

Update triples amplitudes in T3a, T3b, T3aab and T3abb with R3a, R3b, R3aab and R3abb.

source

Internal functions

ElemCo.CCTools.add_singles2doubles!Method
add_singles2doubles!(T2, T1; make_contravariant=true)

Add singles to doubles amplitudes.

If make_contravariant is true, the amplitudes will be made contravariant.

source
ElemCo.CCTools.antisymmetrize_34!Method
antisymmetrize_34!(d, trivv)

Antisymmetrize dims 3 and 4 of d in-place and compress to triangular. Returns d[:,:,trivv] where d[p,q,a,b] → d[p,q,a,b] - d[p,q,b,a] for a < b.

source
ElemCo.CCTools.correlation_reference_orbital_dataMethod
correlation_reference_orbital_data(EC::ECInfo)

Pre-fetch the orbital data to store with a restarted wavefunction, using the correlation reference orbitals — the ones the FCIDUMP was actually built from (load_orbitals_for_correlation) — rather than the raw orbitals on file.

For a plain restart (the dump already holds the reference in the current AO basis) the two coincide. But for a dump=""+start restart across a geometry (or basis) change, the reference is the projected and re-orthonormalized orbital set expressed in the current AO basis, while the raw orbitals on file are still in the old basis. Storing the raw orbitals then writes old-basis coefficients tagged with the new AO basis — inconsistent with both the current geometry and the stored (reference-basis) amplitudes — so a subsequent same-geometry restart cannot resume at the stored solution and re-optimizes over several iterations. Storing the correlation reference keeps the orbitals, amplitudes, and AO basis mutually consistent, so the restart resumes in one iteration.

Returns the raw data unchanged for an FCIDUMP-only run (no molecular system) or a rotation-only dump (no AO basis stored), where there are no orbital coefficients to re-express — the caller then stores a rotation as before. Must be called before opening the store file for writing (dump == store case).

source
ElemCo.CCTools.update_triplesMethod
update_triples(EC::ECInfo, R3; spincase::Symbol=:α, antisymmetrize=false, use_shift=true)

Calculate update for triples amplitudes for a given spincase∈{,,:ααβ,:αββ}.

source