LCOV - code coverage report
Current view: top level - src - topology_state_io.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:92574dc) Lines: 97.6 % 42 41
Test Date: 2026-09-24 01:27:39 Functions: 100.0 % 2 2

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Versioned Gaussian-basis snapshots for cross-geometry topology overlaps.
      10              : !>        Atomic units, full contraction coefficients, CP2K periodic atom images.
      11              : ! **************************************************************************************************
      12              : MODULE topology_state_io
      13              :    USE atomic_kind_types,               ONLY: get_atomic_kind
      14              :    USE basis_set_types,                 ONLY: gto_basis_set_type
      15              :    USE cell_types,                      ONLY: cell_type,&
      16              :                                               pbc
      17              :    USE cp_files,                        ONLY: open_file
      18              :    USE kinds,                           ONLY: dp
      19              :    USE message_passing,                 ONLY: mp_para_env_type
      20              :    USE orbital_pointers,                ONLY: indco,&
      21              :                                               ncoset
      22              :    USE particle_types,                  ONLY: particle_type
      23              :    USE qs_environment_types,            ONLY: get_qs_env,&
      24              :                                               qs_environment_type
      25              :    USE qs_kind_types,                   ONLY: get_qs_kind,&
      26              :                                               qs_kind_type
      27              : #include "./base/base_uses.f90"
      28              : 
      29              :    IMPLICIT NONE
      30              :    PRIVATE
      31              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'topology_state_io'
      32              :    PUBLIC :: topology_state_begin, topology_state_point
      33              : CONTAINS
      34              : 
      35              : ! **************************************************************************************************
      36              : !> \brief Write basis metadata; all ranks call, only the source writes.
      37              : !> \param qs_env electronic structure environment
      38              : !> \param filename snapshot file
      39              : !> \param nao number of AO functions
      40              : !> \param nband retained states
      41              : !> \param npoint k-points
      42              : !> \param nspin spinor components, one for a selected collinear channel
      43              : !> \param ntotal all computed eigenvalues
      44              : !> \param spin_channel collinear channel label
      45              : !> \param bands retained band indices
      46              : !> \param unit source output unit, -1 on other ranks
      47              : ! **************************************************************************************************
      48            4 :    SUBROUTINE topology_state_begin(qs_env, filename, nao, nband, npoint, nspin, ntotal, spin_channel, bands, unit)
      49              :       TYPE(qs_environment_type), POINTER                 :: qs_env
      50              :       CHARACTER(len=*), INTENT(IN)                       :: filename
      51              :       INTEGER, INTENT(IN)                                :: nao, nband, npoint, nspin, ntotal, &
      52              :                                                             spin_channel, bands(:)
      53              :       INTEGER, INTENT(OUT)                               :: unit
      54              : 
      55              :       INTEGER                                            :: count_ao, first, ia, ic, ik, ip, iset, &
      56              :                                                             j, ncart, ns, row
      57              :       TYPE(cell_type), POINTER                           :: cell
      58              :       TYPE(gto_basis_set_type), POINTER                  :: basis
      59              :       TYPE(mp_para_env_type), POINTER                    :: para_env
      60            4 :       TYPE(particle_type), POINTER                       :: particles(:)
      61            4 :       TYPE(qs_kind_type), POINTER                        :: kinds_set(:)
      62              : 
      63            4 :       CALL get_qs_env(qs_env, cell=cell, particle_set=particles, qs_kind_set=kinds_set, para_env=para_env)
      64            4 :       unit = -1
      65            4 :       IF (.NOT. para_env%is_source()) RETURN
      66            2 :       CALL open_file(filename, unit_number=unit, file_status="UNKNOWN", file_action="WRITE")
      67            2 :       WRITE (unit, '(A)') 'CP2K_TOPOLOGY_STATE 1'
      68            2 :       WRITE (unit, '(7I12)') SIZE(particles), nao, nband, npoint, nspin, ntotal, spin_channel
      69            2 :       WRITE (unit, '(*(I12))') bands
      70            8 :       DO j = 1, 3
      71           26 :          WRITE (unit, '(3ES26.17)') cell%hmat(:, j)
      72              :       END DO
      73            8 :       WRITE (unit, '(3I12)') cell%perd
      74            2 :       count_ao = 0
      75            4 :       DO ia = 1, SIZE(particles)
      76            2 :          CALL get_atomic_kind(particles(ia)%atomic_kind, kind_number=ik)
      77            2 :          CALL get_qs_kind(kinds_set(ik), basis_set=basis)
      78            2 :          IF (.NOT. ASSOCIATED(basis)) THEN
      79            0 :             CPABORT("STATE_EXPORT requires a Gaussian orbital basis on every atom.")
      80              :          END IF
      81            2 :          WRITE (unit, '(4I12)') ia, ik, basis%nset, basis%nsgf
      82            8 :          WRITE (unit, '(3ES26.17)') pbc(particles(ia)%r, cell)
      83            6 :          DO iset = 1, basis%nset
      84            4 :             first = basis%first_sgf(1, iset)
      85            4 :             ns = basis%nsgf_set(iset)
      86            4 :             ncart = ncoset(basis%lmax(iset))
      87            4 :             WRITE (unit, '(5I12,ES26.17)') first, ns, basis%npgf(iset), ncart, basis%lmin(iset), &
      88            8 :                basis%set_radius(iset)
      89           30 :             DO ip = 1, basis%npgf(iset)
      90           24 :                WRITE (unit, '(2ES26.17)') basis%zet(ip, iset), basis%pgf_radius(ip, iset)
      91           76 :                DO ic = 1, ncart
      92           48 :                   row = (ip - 1)*ncart + ic
      93          200 :                   WRITE (unit, '(3I5,*(ES26.17))') indco(:, ic), basis%sphi(row, first:first + ns - 1)
      94              :                END DO
      95              :             END DO
      96              :          END DO
      97            6 :          count_ao = count_ao + basis%nsgf
      98              :       END DO
      99            2 :       IF (count_ao /= nao) CPABORT("STATE_EXPORT: inconsistent atom/AO dimensions.")
     100            4 :    END SUBROUTINE topology_state_begin
     101              : 
     102              : ! **************************************************************************************************
     103              : !> \brief Write one point with eigenvalues in Hartree and physical AO coefficients.
     104              : !> \param unit snapshot output unit, -1 skips output
     105              : !> \param point one-based point index
     106              : !> \param k fractional reciprocal coordinates
     107              : !> \param eigenvalues all computed eigenvalues, including excluded states
     108              : !> \param coefficients selected states; spinor components are stacked by AO
     109              : ! **************************************************************************************************
     110          136 :    SUBROUTINE topology_state_point(unit, point, k, eigenvalues, coefficients)
     111              :       INTEGER, INTENT(IN)                                :: unit, point
     112              :       REAL(KIND=dp), INTENT(IN)                          :: k(3), eigenvalues(:)
     113              :       COMPLEX(KIND=dp), INTENT(IN)                       :: coefficients(:, :)
     114              : 
     115              :       INTEGER                                            :: i, j
     116              : 
     117          136 :       IF (unit < 0) RETURN
     118           52 :       WRITE (unit, '(I12,3ES26.17)') point, k
     119           52 :       WRITE (unit, '(*(ES26.17))') eigenvalues
     120          104 :       DO j = 1, SIZE(coefficients, 2)
     121          364 :          DO i = 1, SIZE(coefficients, 1)
     122          312 :             WRITE (unit, '(2ES26.17)') REAL(coefficients(i, j), dp), AIMAG(coefficients(i, j))
     123              :          END DO
     124              :       END DO
     125              :    END SUBROUTINE topology_state_point
     126              : END MODULE topology_state_io
        

Generated by: LCOV version 2.0-1