|
| 1 | +# ********************************************************************************* |
| 2 | +# * Copyright (C) 2026 Alexey V. Akimov |
| 3 | +# * |
| 4 | +# * This file is distributed under the terms of the GNU General Public License |
| 5 | +# * as published by the Free Software Foundation, either version 3 of |
| 6 | +# * the License, or (at your option) any later version. |
| 7 | +# * See the file LICENSE in the root directory of this distribution |
| 8 | +# * or <http://www.gnu.org/licenses/>. |
| 9 | +# * |
| 10 | +# *********************************************************************************/ |
| 11 | + |
| 12 | +""" |
| 13 | +.. module:: ci |
| 14 | + :platform: Unix, Windows |
| 15 | + :synopsis: this module implements functions for computing ci-level time-overlaps |
| 16 | +.. moduleauthor:: Alexey V. Akimov, ChatGPT |
| 17 | +
|
| 18 | +""" |
| 19 | + |
| 20 | +import numpy as np |
| 21 | +from . import interfaces |
| 22 | +#from .import |
| 23 | + |
| 24 | +def overlap(st_mo, data1, data2, params): |
| 25 | + """ |
| 26 | + Compute the CI-state overlap matrix between two electronic-structure |
| 27 | + datasets using molecular-orbital time overlaps. |
| 28 | +
|
| 29 | + This routine: |
| 30 | + 1. Builds a common Slater-determinant basis from excited-state |
| 31 | + configurations of both datasets |
| 32 | + 2. Constructs CI coefficient matrices in that common basis |
| 33 | + 3. Computes SD and CSF overlap matrices (singlet) |
| 34 | + 4. Projects the overlaps into the CI-state representation |
| 35 | +
|
| 36 | + Parameters |
| 37 | + ---------- |
| 38 | + st_mo : sparse matrix or array-like, shape (2*norb, 2*norb) |
| 39 | + Molecular-orbital time-overlap matrix in the spin–orbital basis. |
| 40 | +
|
| 41 | + data1, data2 : tuple or list |
| 42 | + Electronic-structure data containers with the following layout:: |
| 43 | +
|
| 44 | + dataX[1] : list of list |
| 45 | + State-resolved configuration lists for excited states. |
| 46 | + dataX[1][i] contains configurations for excited state i+1. |
| 47 | +
|
| 48 | + dataX[2] : list of list |
| 49 | + Corresponding CI amplitudes. |
| 50 | + dataX[2][i][j] is the amplitude of configuration j in |
| 51 | + excited state i+1. |
| 52 | +
|
| 53 | + The ground state is assumed to be a pure reference determinant |
| 54 | + and is not included explicitly. |
| 55 | +
|
| 56 | + params : dict |
| 57 | + Dictionary of required parameters: |
| 58 | + homo_indx : int |
| 59 | + HOMO index (1-based spatial orbital index) |
| 60 | + nocc : int |
| 61 | + Number of occupied orbitals below HOMO included in the window |
| 62 | + nvirt : int |
| 63 | + Number of virtual orbitals above HOMO included in the window |
| 64 | + nelec : int |
| 65 | + Total number of electrons |
| 66 | + nstates : int |
| 67 | + Total number of electronic states, including the ground state |
| 68 | +
|
| 69 | + Returns |
| 70 | + ------- |
| 71 | + numpy.ndarray |
| 72 | + CI-state overlap matrix of shape `(nstates, nstates)`. |
| 73 | +
|
| 74 | + Notes |
| 75 | + ----- |
| 76 | + - This routine is restricted to closed-shell singlet states. |
| 77 | + - Only singly excited configurations are assumed. |
| 78 | + - The CI overlap is computed as:: |
| 79 | +
|
| 80 | + S_CI = C1ᵀ · S_CSF · C2 |
| 81 | +
|
| 82 | + where `C1` and `C2` are CI coefficient matrices in a common CSF basis. |
| 83 | + """ |
| 84 | + # ------------------------------------------------------------------ |
| 85 | + # Extract and validate parameters |
| 86 | + # ------------------------------------------------------------------ |
| 87 | + required_keys = {"homo_indx", "nocc", "nvirt", "nelec", "nstates"} |
| 88 | + missing = required_keys - params.keys() |
| 89 | + if missing: |
| 90 | + raise KeyError(f"Missing required parameters: {missing}") |
| 91 | + |
| 92 | + homo_indx = params["homo_indx"] |
| 93 | + nocc = params["nocc"] |
| 94 | + nvirt = params["nvirt"] |
| 95 | + nelec = params["nelec"] |
| 96 | + nstates = params["nstates"] |
| 97 | + |
| 98 | + if nstates <= 1: |
| 99 | + raise ValueError("nstates must include at least one excited state") |
| 100 | + |
| 101 | + # Orbital window (1-based spatial indices) |
| 102 | + lowest_orbital = homo_indx - nocc |
| 103 | + highest_orbital = homo_indx + nvirt |
| 104 | + |
| 105 | + # ------------------------------------------------------------------ |
| 106 | + # Build common SD basis from excited states only |
| 107 | + # ------------------------------------------------------------------ |
| 108 | + n_excited_states = nstates - 1 |
| 109 | + |
| 110 | + common_sd_basis = interfaces.unique_confs( |
| 111 | + data1[1], data2[1], n_excited_states |
| 112 | + ) |
| 113 | + |
| 114 | + # ------------------------------------------------------------------ |
| 115 | + # CI coefficient matrices in the common SD basis |
| 116 | + # ------------------------------------------------------------------ |
| 117 | + C1 = interfaces.ci_amplitudes_mtx( |
| 118 | + nstates, common_sd_basis, data1[1], data1[2] |
| 119 | + ) |
| 120 | + C2 = interfaces.ci_amplitudes_mtx( |
| 121 | + nstates, common_sd_basis, data2[1], data2[2] |
| 122 | + ) |
| 123 | + |
| 124 | + # ------------------------------------------------------------------ |
| 125 | + # SD and CSF overlap matrices (singlet) |
| 126 | + # ------------------------------------------------------------------ |
| 127 | + csf_ovlp, sd_ovlp = interfaces.sd_and_csf_overlaps_singlet( |
| 128 | + st_mo, |
| 129 | + lowest_orbital, |
| 130 | + highest_orbital, |
| 131 | + nelec, |
| 132 | + homo_indx, |
| 133 | + common_sd_basis, |
| 134 | + ) |
| 135 | + |
| 136 | + # ------------------------------------------------------------------ |
| 137 | + # CI-state overlap matrix |
| 138 | + # ------------------------------------------------------------------ |
| 139 | + st_ci = C1.T @ csf_ovlp @ C2 |
| 140 | + |
| 141 | + return st_ci |
| 142 | + |
0 commit comments