LCOV - code coverage report
Current view: top level - src - nnp_environment_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:21ef868) Lines: 82.5 % 246 203
Test Date: 2026-08-14 07:04:57 Functions: 18.8 % 32 6

            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  Data types for neural network potentials
      10              : !> \author Christoph Schran (christoph.schran@rub.de)
      11              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
      12              : !> \date   2020-10-10
      13              : ! **************************************************************************************************
      14              : MODULE nnp_environment_types
      15              :    USE atomic_kind_list_types,          ONLY: atomic_kind_list_create,&
      16              :                                               atomic_kind_list_release,&
      17              :                                               atomic_kind_list_type
      18              :    USE atomic_kind_types,               ONLY: atomic_kind_type
      19              :    USE cell_types,                      ONLY: cell_release,&
      20              :                                               cell_retain,&
      21              :                                               cell_type
      22              :    USE cp_subsys_types,                 ONLY: cp_subsys_get,&
      23              :                                               cp_subsys_release,&
      24              :                                               cp_subsys_set,&
      25              :                                               cp_subsys_type
      26              :    USE distribution_1d_types,           ONLY: distribution_1d_type
      27              :    USE input_section_types,             ONLY: section_vals_type
      28              :    USE kinds,                           ONLY: default_string_length,&
      29              :                                               dp
      30              :    USE molecule_kind_list_types,        ONLY: molecule_kind_list_create,&
      31              :                                               molecule_kind_list_release,&
      32              :                                               molecule_kind_list_type
      33              :    USE molecule_kind_types,             ONLY: molecule_kind_type
      34              :    USE molecule_list_types,             ONLY: molecule_list_create,&
      35              :                                               molecule_list_release,&
      36              :                                               molecule_list_type
      37              :    USE molecule_types,                  ONLY: molecule_type
      38              :    USE particle_list_types,             ONLY: particle_list_create,&
      39              :                                               particle_list_release,&
      40              :                                               particle_list_type
      41              :    USE particle_types,                  ONLY: particle_type
      42              :    USE virial_types,                    ONLY: virial_type
      43              : #include "./base/base_uses.f90"
      44              : 
      45              :    IMPLICIT NONE
      46              : 
      47              :    PRIVATE
      48              : 
      49              :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .FALSE.
      50              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'nnp_environment_types'
      51              : 
      52              :    !> derived data types
      53              :    PUBLIC :: nnp_type
      54              :    PUBLIC :: nnp_arc_type
      55              :    PUBLIC :: nnp_neighbor_type
      56              :    PUBLIC :: nnp_neigh_grp_type
      57              :    PUBLIC :: nnp_symfgrp_type
      58              :    PUBLIC :: nnp_acsf_rad_type
      59              :    PUBLIC :: nnp_acsf_ang_type
      60              :    PUBLIC :: nnp_cell_list_cache_type
      61              :    PUBLIC :: nnp_neighbor_pair_map_type
      62              :    PUBLIC :: nnp_dGdr_grp_type
      63              :    PUBLIC :: nnp_neighbor_workspace_type
      64              :    PUBLIC :: nnp_neighbor_interface_state_type
      65              : 
      66              :    ! Public subroutines ***
      67              :    PUBLIC :: nnp_env_release, &
      68              :              nnp_env_set, &
      69              :              nnp_env_get, &
      70              :              nnp_cell_list_cache_release, &
      71              :              nnp_neighbor_interface_state_release
      72              : 
      73              :    INTEGER, PARAMETER, PUBLIC :: &
      74              :       nnp_cut_cos = 1, &
      75              :       nnp_cut_tanh = 2
      76              : 
      77              :    INTEGER, PARAMETER, PUBLIC :: &
      78              :       nnp_actfnct_tanh = 1, &
      79              :       nnp_actfnct_gaus = 2, &
      80              :       nnp_actfnct_lin = 3, &
      81              :       nnp_actfnct_cos = 4, &
      82              :       nnp_actfnct_sig = 5, &
      83              :       nnp_actfnct_invsig = 6, &
      84              :       nnp_actfnct_exp = 7, &
      85              :       nnp_actfnct_softplus = 8, &
      86              :       nnp_actfnct_quad = 9
      87              : 
      88              : ! **************************************************************************************************
      89              : !> \brief Main data type collecting all relevant data for neural network potentials
      90              : !> \author Christoph Schran (christoph.schran@rub.de)
      91              : !> \date   2020-10-10
      92              : ! **************************************************************************************************
      93              :    TYPE nnp_type
      94              :       TYPE(nnp_acsf_rad_type), DIMENSION(:), POINTER      :: rad => NULL() ! DIM(n_ele)
      95              :       TYPE(nnp_acsf_ang_type), DIMENSION(:), POINTER      :: ang => NULL() ! DIM(n_ele)
      96              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_rad ! # radial symfnct for this element
      97              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_ang ! # angular symfnct for this element
      98              :       INTEGER                                             :: n_ele = -1 ! # elements
      99              :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele ! elements(n_ele)
     100              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele ! elements(n_ele)
     101              :       LOGICAL                                             :: scale_acsf = .FALSE.
     102              :       LOGICAL                                             :: scale_sigma_acsf = .FALSE.
     103              :       LOGICAL                                             :: center_acsf = .FALSE.
     104              :       LOGICAL                                             :: normnodes = .FALSE.
     105              :       INTEGER                                             :: n_radgrp = -1
     106              :       INTEGER                                             :: n_anggrp = -1
     107              :       INTEGER                                             :: cut_type = -1 ! cutofftype
     108              :       REAL(KIND=dp)                                       :: eshortmin = -1.0_dp
     109              :       REAL(KIND=dp)                                       :: eshortmax = -1.0_dp
     110              :       REAL(KIND=dp)                                       :: scmax = -1.0_dp !scale
     111              :       REAL(KIND=dp)                                       :: scmin = -1.0_dp !scale
     112              :       REAL(KIND=dp)                                       :: max_cut = -1.0_dp !largest cutoff
     113              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: atom_energies !DIM(n_ele)
     114              :       TYPE(nnp_arc_type), POINTER, DIMENSION(:)           :: arc => NULL() ! DIM(n_ele)
     115              :       INTEGER                                             :: n_committee = -1
     116              :       INTEGER                                             :: n_hlayer = -1
     117              :       INTEGER                                             :: n_layer = -1
     118              :       INTEGER                                             :: rad_spline_n = 8192 ! knots/radial group (RAD_SPLINE_N)
     119              :       REAL(KIND=dp)                                       :: verlet_skin = -1.0_dp ! cell-list skin, bohr (VERLET_SKIN; <0 = auto)
     120              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_hnodes
     121              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: actfnct
     122              :       INTEGER                                             :: expol = -1 ! extrapolation counter
     123              :       LOGICAL                                             :: output_expol = .FALSE. ! output extrapolation
     124              :       ! structures for calculation
     125              :       INTEGER                                             :: num_atoms = -1
     126              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: atomic_energy
     127              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: committee_energy
     128              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: ele_ind, nuc_atoms, sort, sort_inv
     129              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: coord
     130              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: myforce
     131              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: committee_forces, committee_stress
     132              :       CHARACTER(len=default_string_length), &
     133              :          ALLOCATABLE, DIMENSION(:)                        :: atoms
     134              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE         :: nnp_forces
     135              :       REAL(KIND=dp)                                       :: nnp_potential_energy = -1.0_dp
     136              :       TYPE(cp_subsys_type), POINTER                       :: subsys => NULL()
     137              :       TYPE(section_vals_type), POINTER                    :: nnp_input => NULL()
     138              :       TYPE(section_vals_type), POINTER                    :: force_env_input => NULL()
     139              :       TYPE(cell_type), POINTER                            :: cell => NULL()
     140              :       TYPE(cell_type), POINTER                            :: cell_ref => NULL()
     141              :       LOGICAL                                             :: use_ref_cell = .FALSE.
     142              :       ! bias
     143              :       LOGICAL                                             :: bias = .FALSE.
     144              :       LOGICAL                                             :: bias_align = .FALSE.
     145              :       REAL(KIND=dp)                                       :: bias_energy = -1.0_dp
     146              :       REAL(KIND=dp)                                       :: bias_kb = -1.0_dp
     147              :       REAL(KIND=dp)                                       :: bias_sigma0 = -1.0_dp
     148              :       REAL(KIND=dp)                                       :: bias_sigma = -1.0_dp
     149              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE         :: bias_forces
     150              :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE            :: bias_e_avrg
     151              :       ! Per-nnp persistent neighbour-finder state, owned by nnp_type so committee
     152              :       ! and MIX force_evals carry independent caches whose lifetime tracks
     153              :       ! nnp_env_release. Allocated by nnp_prepare_neighbor_cache, freed in
     154              :       ! nnp_env_release; operated on by nnp_cell_list and nnp_neighbor_interface.
     155              :       TYPE(nnp_cell_list_cache_type), ALLOCATABLE         :: cell_list_cache
     156              :       TYPE(nnp_neighbor_interface_state_type), ALLOCATABLE :: neighbor_interface_state
     157              :    END TYPE nnp_type
     158              : 
     159              : ! **************************************************************************************************
     160              : !> \brief Symmetry functions group type
     161              : !> \param n_symf - # of associated sym fncts
     162              : !> \param symf   - indices of associated sym fncts       DIM(nsymf)
     163              : !> \param ele    - elements indices          rad:DIM(2), ang:DIM(3)
     164              : !> \param cutoff - associated cutoff value
     165              : !> \author Christoph Schran (christoph.schran@rub.de)
     166              : !> \date   2020-10-10
     167              : ! **************************************************************************************************
     168              :    TYPE nnp_symfgrp_type
     169              :       INTEGER                                             :: n_symf = -1
     170              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: symf
     171              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: ele_ind
     172              :       CHARACTER(LEN=2), DIMENSION(:), ALLOCATABLE         :: ele
     173              :       REAL(KIND=dp)                                       :: cutoff = -1.0_dp
     174              :       ! Packed per-member parameters: contiguous arrays sized n_symf so the inner
     175              :       ! SF loop streams memory instead of indexing ang(ind)%{eta,zeta,lam,prefzeta}
     176              :       ! through symf(sf). pack_izeta/pack_use_int_zeta skip NINT in the inner loop.
     177              :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE            :: pack_eta
     178              :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE            :: pack_zeta
     179              :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE            :: pack_lam
     180              :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE            :: pack_prefzeta
     181              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: pack_izeta
     182              :       LOGICAL, DIMENSION(:), ALLOCATABLE                  :: pack_use_int_zeta
     183              :       ! Group-shared Hermite cubic spline tables (radial groups only). All SFs in
     184              :       ! a group share grp%cutoff, hence one uniform grid (spline_n nodes, spacing
     185              :       ! spline_dx). y(r) and y'(r) are packed sf-first so nnp_calc_rad streams them
     186              :       ! after computing the interpolation parameters once per call.
     187              :       LOGICAL                                             :: spline_built = .FALSE.
     188              :       INTEGER                                             :: spline_n = 0
     189              :       REAL(KIND=dp)                                       :: spline_dx = 1.0_dp
     190              :       REAL(KIND=dp)                                       :: spline_dx_inv = 1.0_dp
     191              :       REAL(KIND=dp)                                       :: spline_x_max = 0.0_dp
     192              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE         :: spline_y    ! (n_symf, n_grid)
     193              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE         :: spline_dy   ! (n_symf, n_grid)
     194              :    END TYPE nnp_symfgrp_type
     195              : 
     196              : ! **************************************************************************************************
     197              : !> \brief Set of radial symmetry function type
     198              : !> \param y       - acsf value                                     - DIM(n_rad)
     199              : !> \param funccut - distance cutoff                           bohr - DIM(n_rad)
     200              : !> \param eta     - eta parameter of radial sym fncts      bohr^-2 - DIM(n_rad)
     201              : !> \param rs      - r shift parameter of radial sym fncts     bohr - DIM(n_rad)
     202              : !> \param loc_min - minimum of the sym fnct                          DIM(n_rad)
     203              : !> \param loc_max - maximum of the sym fnct                          DIM(n_rad)
     204              : !> \param loc_av  - average of the sym fnct                          DIM(n_rad)
     205              : !> \param sigma   - SD of the sym fnc                                DIM(n_rad)
     206              : !> \param ele     - element associated to the sym fnct               DIM(n_rad)
     207              : !> \param nuc_ele - associated atomic number                         DIM(n_rad)
     208              : !> \author Christoph Schran (christoph.schran@rub.de)
     209              : !> \date   2020-10-10
     210              : ! **************************************************************************************************
     211              :    TYPE nnp_acsf_rad_type
     212              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: y
     213              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: funccut
     214              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: eta
     215              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: rs
     216              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_min
     217              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_max
     218              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_av
     219              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: sigma
     220              :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele
     221              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele
     222              :       INTEGER                                             :: n_symfgrp = -1
     223              :       TYPE(nnp_symfgrp_type), DIMENSION(:), ALLOCATABLE   :: symfgrp
     224              :    END TYPE nnp_acsf_rad_type
     225              : 
     226              : ! **************************************************************************************************
     227              : !> \brief Set of angular symmetry function type
     228              : !> \param y         - acsf value                                  - DIM(n_ang)
     229              : !> \param funccut   - distance cutoff                        bohr - DIM(n_ang)
     230              : !> \param eta       - eta  param. of angular sym fncts    bohr^-2 - DIM(n_ang)
     231              : !> \param zeta      - zeta param. of angular sym fncts              DIM(n_ang)
     232              : !> \param lam       - lambda  param. of angular sym fncts           DIM(n_ang)
     233              : !> \param loc_min   - minimum of the sym fnct                       DIM(n_ang)
     234              : !> \param loc_max   - maximum of the sym fnct                       DIM(n_ang)
     235              : !> \param loc_av    - average of the sym fnct                       DIM(n_ang)
     236              : !> \param sigma     - SD of the sym fnc                             DIM(n_ang)
     237              : !> \param ele1,ele2 - elements associated to the sym fnct           DIM(n_ang)
     238              : !> \param nuc_ele2, nuc_ele2 - associated atomic numbers            DIM(n_ang)
     239              : !> \author Christoph Schran (christoph.schran@rub.de)
     240              : !> \date   2020-10-10
     241              : ! **************************************************************************************************
     242              :    TYPE nnp_acsf_ang_type
     243              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: y
     244              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: funccut
     245              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: eta
     246              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: zeta
     247              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: prefzeta
     248              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: lam
     249              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_min
     250              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_max
     251              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_av
     252              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: sigma
     253              :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele1
     254              :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele2
     255              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele1
     256              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele2
     257              :       INTEGER                                             :: n_symfgrp = -1
     258              :       TYPE(nnp_symfgrp_type), DIMENSION(:), ALLOCATABLE   :: symfgrp
     259              :    END TYPE nnp_acsf_ang_type
     260              : 
     261              : ! **************************************************************************************************
     262              : !> \brief Per-SF-group dense neighbour container. cap is the allocated slab size;
     263              : !>        the live count is nnp_neighbor_type%n_rad/n_ang1/n_ang2 for the matching
     264              : !>        group. ind(j) is the j-th neighbour's atom index; dist(1:3, j) is its
     265              : !>        displacement and dist(4, j) its norm. Sized lazily by nnp_neigh_grp_grow.
     266              : ! **************************************************************************************************
     267              :    TYPE nnp_neigh_grp_type
     268              :       INTEGER                                             :: cap = 0
     269              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: ind   ! (cap)
     270              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: dist  ! (4, cap)
     271              :    END TYPE nnp_neigh_grp_type
     272              : 
     273              : ! **************************************************************************************************
     274              : !> \brief Contains neighbors list of an atom (per-group dense layout).
     275              : !> \param n_rad/n_ang1/n_ang2 - live neighbor counts per symfgrp
     276              : !> \param rad/ang1/ang2       - per-group dense (ind, dist) containers
     277              : !> \author Christoph Schran (christoph.schran@rub.de)
     278              : !> \date   2020-10-10
     279              : ! **************************************************************************************************
     280              :    TYPE nnp_neighbor_type
     281              :       INTEGER, DIMENSION(3)                                :: pbc_copies = -1
     282              :       INTEGER, DIMENSION(:), ALLOCATABLE                   :: n_rad
     283              :       INTEGER, DIMENSION(:), ALLOCATABLE                   :: n_ang1
     284              :       INTEGER, DIMENSION(:), ALLOCATABLE                   :: n_ang2
     285              :       TYPE(nnp_neigh_grp_type), ALLOCATABLE, DIMENSION(:)  :: rad
     286              :       TYPE(nnp_neigh_grp_type), ALLOCATABLE, DIMENSION(:)  :: ang1
     287              :       TYPE(nnp_neigh_grp_type), ALLOCATABLE, DIMENSION(:)  :: ang2
     288              :    END TYPE nnp_neighbor_type
     289              : 
     290              : ! **************************************************************************************************
     291              : !> \brief Linked-cell + Verlet-skin cache for the NNP descriptor neighbour walk.
     292              : !>        Persisted across MD steps so the image pool, bin geometry, and
     293              : !>        reference positions survive between force evaluations and the
     294              : !>        head/next chain can be reused as long as no atom has drifted more
     295              : !>        than skin/2. Operated on by nnp_cell_list.F.
     296              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     297              : ! **************************************************************************************************
     298              :    TYPE nnp_cell_list_cache_type
     299              :       LOGICAL                                             :: initialized = .FALSE.
     300              :       INTEGER                                             :: num_atoms = -1
     301              :       INTEGER                                             :: n_images = 0
     302              :       INTEGER                                             :: n_cells = 1
     303              :       INTEGER, DIMENSION(3)                               :: exact_pbc_copies = 0
     304              :       INTEGER, DIMENSION(3)                               :: list_pbc_copies = 0
     305              :       INTEGER, DIMENSION(3)                               :: image_copies = 0
     306              :       INTEGER, DIMENSION(3)                               :: nbin = 1
     307              :       INTEGER, DIMENSION(3)                               :: bin_span = 0
     308              :       INTEGER, DIMENSION(3)                               :: perd = 0
     309              :       LOGICAL                                             :: orthorhombic = .FALSE.
     310              :       REAL(KIND=dp)                                       :: exact_cutoff = -1.0_dp
     311              :       REAL(KIND=dp)                                       :: list_cutoff = -1.0_dp
     312              :       REAL(KIND=dp)                                       :: verlet_skin = 0.0_dp
     313              :       REAL(KIND=dp), DIMENSION(3)                         :: lower = 0.0_dp
     314              :       REAL(KIND=dp), DIMENSION(3)                         :: upper = 0.0_dp
     315              :       REAL(KIND=dp), DIMENSION(3)                         :: bin_width = 1.0_dp
     316              :       REAL(KIND=dp), DIMENSION(3, 3)                      :: hmat = 0.0_dp
     317              :       REAL(KIND=dp), DIMENSION(3, 3)                      :: h_inv = 0.0_dp
     318              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: coord_primary
     319              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: coord_scaled
     320              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: ref_coord_primary
     321              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: image_atom
     322              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: head
     323              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: next
     324              :       INTEGER, ALLOCATABLE, DIMENSION(:, :)               :: image_shift
     325              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: image_translation
     326              :    END TYPE nnp_cell_list_cache_type
     327              : 
     328              : ! **************************************************************************************************
     329              : !> \brief Species-pair routing table. For one (central element, neighbour element)
     330              : !>        pair, lists which radial / angular symmetry-function groups need that
     331              : !>        neighbour and the worst-case relevant cutoff.
     332              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     333              : ! **************************************************************************************************
     334              :    TYPE nnp_neighbor_pair_map_type
     335              :       INTEGER                                             :: n_rad = 0
     336              :       INTEGER                                             :: n_ang1 = 0
     337              :       INTEGER                                             :: n_ang2 = 0
     338              :       REAL(KIND=dp)                                       :: max_relevant_cutoff = 0.0_dp
     339              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: rad_groups
     340              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: ang1_groups
     341              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: ang2_groups
     342              :    END TYPE nnp_neighbor_pair_map_type
     343              : 
     344              : ! **************************************************************************************************
     345              : !> \brief Per-(element, SF-group) dG_k/dr buffer, sized to the group's n_symf (no
     346              : !>        max_*_symf padding) and the observed peak neighbour count for the group.
     347              : !>        Grown lazily (1.5x) so it settles at the true peak.
     348              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     349              : ! **************************************************************************************************
     350              :    TYPE nnp_dGdr_grp_type
     351              :       INTEGER                                             :: cap = 0
     352              :       INTEGER                                             :: n_symf = 0
     353              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: data    ! (3, n_symf, cap)
     354              :    END TYPE nnp_dGdr_grp_type
     355              : 
     356              : ! **************************************************************************************************
     357              : !> \brief Reusable per-element scratch / persistent caches for the ACSF
     358              : !>        descriptor and force assembly. See nnp_neighbor_interface for the
     359              : !>        routines that populate and grow these buffers.
     360              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     361              : ! **************************************************************************************************
     362              :    TYPE nnp_neighbor_workspace_type
     363              :       INTEGER                                             :: max_rad_symf = 0
     364              :       INTEGER                                             :: max_ang_symf = 0
     365              :       INTEGER                                             :: n_input_nodes = 0
     366              :       ! High-water mark of the per-element angular-cache slab, tracked so the 1D
     367              :       ! cutoff caches settle at the true per-element peak.
     368              :       INTEGER                                             :: cache_cap = 0
     369              :       ! There is a bug with some older compilers preventing requiring an explicit
     370              :       ! initialization of allocatable components (see mp2_types.F).
     371              : #if defined(FTN_NO_DEFAULT_INIT)
     372              :       TYPE(nnp_neighbor_type)                             :: neighbor = nnp_neighbor_type( &
     373              :                                                              pbc_copies=-1, n_rad=NULL(), &
     374              :                                                              n_ang1=NULL(), n_ang2=NULL(), &
     375              :                                                              rad=NULL(), ang1=NULL(), ang2=NULL())
     376              : #else
     377              :       TYPE(nnp_neighbor_type)                             :: neighbor = nnp_neighbor_type()
     378              : #endif
     379              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: radial_sym
     380              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: radial_force
     381              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: angular_sym
     382              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: angular_force
     383              :       ! Per-element persistent cutoff caches reused across this element's central
     384              :       ! atoms. Sized lazily by nnp_workspace_grow_caches to MAX(n_ang1)/MAX(n_ang2).
     385              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: fc_cache1
     386              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: dfc_cache1
     387              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: fc_cache2
     388              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: dfc_cache2
     389              :       ! Per-neighbour dG_k/dr storage, replacing the global
     390              :       ! dsymdxyz(3, n_input_nodes, num_atoms) slab. The per-group buffers are
     391              :       ! dense in (3, n_symf_for_group, n_neighbors_in_group), which shrinks the
     392              :       ! working set and keeps each group walk a contiguous stride.
     393              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: self_dGdr
     394              :       TYPE(nnp_dGdr_grp_type), ALLOCATABLE, DIMENSION(:)  :: dGdr_rad
     395              :       TYPE(nnp_dGdr_grp_type), ALLOCATABLE, DIMENSION(:)  :: dGdr_ang_jj
     396              :       TYPE(nnp_dGdr_grp_type), ALLOCATABLE, DIMENSION(:)  :: dGdr_ang_kk
     397              :    END TYPE nnp_neighbor_workspace_type
     398              : 
     399              : ! **************************************************************************************************
     400              : !> \brief Persistent neighbour-interface state. Owned by nnp_type so that the
     401              : !>        per-nnp pair-routing tables and per-element workspaces survive
     402              : !>        across MD steps without leaking between independent &NNP
     403              : !>        force_evals. Operated on by nnp_neighbor_interface.F.
     404              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     405              : ! **************************************************************************************************
     406              :    TYPE nnp_neighbor_interface_state_type
     407              :       LOGICAL                                             :: initialized = .FALSE.
     408              :       INTEGER                                             :: n_ele = 0
     409              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_rad
     410              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_ang
     411              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_radgrp
     412              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_anggrp
     413              :       TYPE(nnp_neighbor_pair_map_type), ALLOCATABLE, &
     414              :          DIMENSION(:, :)                                  :: pair_map
     415              :       TYPE(nnp_neighbor_workspace_type), ALLOCATABLE, &
     416              :          DIMENSION(:)                                     :: workspace
     417              :    END TYPE nnp_neighbor_interface_state_type
     418              : 
     419              : ! **************************************************************************************************
     420              : !> \brief Data type for artificial neural networks
     421              : !> \author Christoph Schran (christoph.schran@rub.de)
     422              : !> \date   2020-10-10
     423              : ! **************************************************************************************************
     424              :    TYPE nnp_arc_type
     425              :       TYPE(nnp_arc_layer_type), POINTER, DIMENSION(:)     :: layer => NULL() ! DIM(n_layer)
     426              :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_nodes
     427              :    END TYPE nnp_arc_type
     428              : 
     429              : ! **************************************************************************************************
     430              : !> \brief Data type for individual layer
     431              : !> \author Christoph Schran (christoph.schran@rub.de)
     432              : !> \date   2020-10-10
     433              : ! **************************************************************************************************
     434              :    TYPE nnp_arc_layer_type
     435              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: weights ! node weights
     436              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: bweights ! bias weights
     437              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: node ! DIM(n_nodes)
     438              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: node_grad ! DIM(n_nodes)
     439              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: tmp_der ! DIM(n_sym,n_nodes)
     440              :    END TYPE nnp_arc_layer_type
     441              : 
     442              : CONTAINS
     443              : 
     444              : ! **************************************************************************************************
     445              : !> \brief Release data structure that holds all the information for neural
     446              : !>        network potentials
     447              : !> \param nnp_env ...
     448              : !> \date   2020-10-10
     449              : !> \author Christoph Schran (christoph.schran@rub.de)
     450              : ! **************************************************************************************************
     451           17 :    SUBROUTINE nnp_env_release(nnp_env)
     452              :       TYPE(nnp_type), INTENT(INOUT)                      :: nnp_env
     453              : 
     454              :       INTEGER                                            :: i, j
     455              : 
     456           17 :       IF (ASSOCIATED(nnp_env%rad)) THEN
     457           52 :          DO i = 1, nnp_env%n_ele
     458          106 :             DO j = 1, nnp_env%rad(i)%n_symfgrp
     459           71 :                IF (ALLOCATED(nnp_env%rad(i)%symfgrp(j)%symf)) THEN
     460              :                   DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%symf, &
     461            0 :                               nnp_env%rad(i)%symfgrp(j)%ele, &
     462           71 :                               nnp_env%rad(i)%symfgrp(j)%ele_ind)
     463              :                END IF
     464           71 :                IF (ALLOCATED(nnp_env%rad(i)%symfgrp(j)%spline_y)) THEN
     465           71 :                   DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%spline_y)
     466              :                END IF
     467           71 :                IF (ALLOCATED(nnp_env%rad(i)%symfgrp(j)%spline_dy)) THEN
     468           71 :                   DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%spline_dy)
     469              :                END IF
     470          106 :                nnp_env%rad(i)%symfgrp(j)%spline_built = .FALSE.
     471              :             END DO
     472            0 :             DEALLOCATE (nnp_env%rad(i)%y, &
     473            0 :                         nnp_env%rad(i)%funccut, &
     474            0 :                         nnp_env%rad(i)%eta, &
     475            0 :                         nnp_env%rad(i)%rs, &
     476            0 :                         nnp_env%rad(i)%loc_min, &
     477            0 :                         nnp_env%rad(i)%loc_max, &
     478            0 :                         nnp_env%rad(i)%loc_av, &
     479            0 :                         nnp_env%rad(i)%sigma, &
     480            0 :                         nnp_env%rad(i)%ele, &
     481            0 :                         nnp_env%rad(i)%nuc_ele, &
     482          123 :                         nnp_env%rad(i)%symfgrp)
     483              :          END DO
     484           17 :          DEALLOCATE (nnp_env%rad)
     485              :       END IF
     486              : 
     487           17 :       IF (ASSOCIATED(nnp_env%ang)) THEN
     488           52 :          DO i = 1, nnp_env%n_ele
     489          121 :             DO j = 1, nnp_env%ang(i)%n_symfgrp
     490           86 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%symf)) THEN
     491              :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%symf, &
     492            0 :                               nnp_env%ang(i)%symfgrp(j)%ele, &
     493           86 :                               nnp_env%ang(i)%symfgrp(j)%ele_ind)
     494              :                END IF
     495           86 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_eta)) THEN
     496           86 :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_eta)
     497              :                END IF
     498           86 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_zeta)) THEN
     499           86 :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_zeta)
     500              :                END IF
     501           86 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_lam)) THEN
     502           86 :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_lam)
     503              :                END IF
     504           86 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_prefzeta)) THEN
     505           86 :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_prefzeta)
     506              :                END IF
     507           86 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_izeta)) THEN
     508           86 :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_izeta)
     509              :                END IF
     510          121 :                IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_use_int_zeta)) THEN
     511           86 :                   DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_use_int_zeta)
     512              :                END IF
     513              :             END DO
     514            0 :             DEALLOCATE (nnp_env%ang(i)%y, &
     515            0 :                         nnp_env%ang(i)%funccut, &
     516            0 :                         nnp_env%ang(i)%eta, &
     517            0 :                         nnp_env%ang(i)%zeta, &
     518            0 :                         nnp_env%ang(i)%prefzeta, &
     519            0 :                         nnp_env%ang(i)%lam, &
     520            0 :                         nnp_env%ang(i)%loc_min, &
     521            0 :                         nnp_env%ang(i)%loc_max, &
     522            0 :                         nnp_env%ang(i)%loc_av, &
     523            0 :                         nnp_env%ang(i)%sigma, &
     524            0 :                         nnp_env%ang(i)%ele1, &
     525            0 :                         nnp_env%ang(i)%ele2, &
     526            0 :                         nnp_env%ang(i)%nuc_ele1, &
     527            0 :                         nnp_env%ang(i)%nuc_ele2, &
     528          138 :                         nnp_env%ang(i)%symfgrp)
     529              :          END DO
     530           17 :          DEALLOCATE (nnp_env%ang)
     531              :       END IF
     532              : 
     533           17 :       IF (ASSOCIATED(nnp_env%arc)) THEN
     534           52 :          DO i = 1, nnp_env%n_ele
     535           52 :             IF (ASSOCIATED(nnp_env%arc(i)%layer)) THEN
     536          175 :                DO j = 1, nnp_env%n_layer
     537          140 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%node)) THEN
     538          140 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%node)
     539              :                   END IF
     540          140 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%node_grad)) THEN
     541          140 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%node_grad)
     542              :                   END IF
     543          140 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%weights)) THEN
     544          105 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%weights)
     545              :                   END IF
     546          140 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%bweights)) THEN
     547          105 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%bweights)
     548              :                   END IF
     549          175 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%tmp_der)) THEN
     550          140 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%tmp_der)
     551              :                   END IF
     552              :                END DO
     553            0 :                DEALLOCATE (nnp_env%arc(i)%layer, &
     554           35 :                            nnp_env%arc(i)%n_nodes)
     555              :             END IF
     556              :          END DO
     557           17 :          DEALLOCATE (nnp_env%arc)
     558              :       END IF
     559              : 
     560           17 :       IF (ALLOCATED(nnp_env%ele)) DEALLOCATE (nnp_env%ele)
     561           17 :       IF (ALLOCATED(nnp_env%nuc_ele)) DEALLOCATE (nnp_env%nuc_ele)
     562           17 :       IF (ALLOCATED(nnp_env%n_hnodes)) DEALLOCATE (nnp_env%n_hnodes)
     563           17 :       IF (ALLOCATED(nnp_env%actfnct)) DEALLOCATE (nnp_env%actfnct)
     564           17 :       IF (ALLOCATED(nnp_env%nnp_forces)) DEALLOCATE (nnp_env%nnp_forces)
     565           17 :       IF (ALLOCATED(nnp_env%atomic_energy)) DEALLOCATE (nnp_env%atomic_energy)
     566           17 :       IF (ALLOCATED(nnp_env%committee_energy)) DEALLOCATE (nnp_env%committee_energy)
     567           17 :       IF (ALLOCATED(nnp_env%ele_ind)) DEALLOCATE (nnp_env%ele_ind)
     568           17 :       IF (ALLOCATED(nnp_env%nuc_atoms)) DEALLOCATE (nnp_env%nuc_atoms)
     569           17 :       IF (ALLOCATED(nnp_env%sort)) DEALLOCATE (nnp_env%sort)
     570           17 :       IF (ALLOCATED(nnp_env%sort_inv)) DEALLOCATE (nnp_env%sort_inv)
     571           17 :       IF (ALLOCATED(nnp_env%coord)) DEALLOCATE (nnp_env%coord)
     572           17 :       IF (ALLOCATED(nnp_env%myforce)) DEALLOCATE (nnp_env%myforce)
     573           17 :       IF (ALLOCATED(nnp_env%committee_forces)) DEALLOCATE (nnp_env%committee_forces)
     574           17 :       IF (ALLOCATED(nnp_env%committee_stress)) DEALLOCATE (nnp_env%committee_stress)
     575           17 :       IF (ALLOCATED(nnp_env%atoms)) DEALLOCATE (nnp_env%atoms)
     576              : 
     577           17 :       IF (ALLOCATED(nnp_env%cell_list_cache)) THEN
     578           17 :          CALL nnp_cell_list_cache_release(nnp_env%cell_list_cache)
     579           17 :          DEALLOCATE (nnp_env%cell_list_cache)
     580              :       END IF
     581           17 :       IF (ALLOCATED(nnp_env%neighbor_interface_state)) THEN
     582           17 :          CALL nnp_neighbor_interface_state_release(nnp_env%neighbor_interface_state)
     583           17 :          DEALLOCATE (nnp_env%neighbor_interface_state)
     584              :       END IF
     585              : 
     586           17 :       IF (ASSOCIATED(nnp_env%subsys)) THEN
     587           16 :          CALL cp_subsys_release(nnp_env%subsys)
     588              :       END IF
     589           17 :       IF (ASSOCIATED(nnp_env%cell)) THEN
     590           17 :          CALL cell_release(nnp_env%cell)
     591              :       END IF
     592           17 :       IF (ASSOCIATED(nnp_env%cell_ref)) THEN
     593           16 :          CALL cell_release(nnp_env%cell_ref)
     594              :       END IF
     595              : 
     596           17 :    END SUBROUTINE nnp_env_release
     597              : 
     598              : ! **************************************************************************************************
     599              : !> \brief Free the allocatable parts of a cell-list cache. Co-located with the
     600              : !>        type definition to avoid creating a USE-cycle through nnp_cell_list.
     601              : !> \param cache cell-list cache whose allocatable image-pool and bin arrays are freed
     602              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     603              : ! **************************************************************************************************
     604           17 :    SUBROUTINE nnp_cell_list_cache_release(cache)
     605              :       TYPE(nnp_cell_list_cache_type), INTENT(INOUT)      :: cache
     606              : 
     607           17 :       IF (ALLOCATED(cache%coord_primary)) DEALLOCATE (cache%coord_primary)
     608           17 :       IF (ALLOCATED(cache%coord_scaled)) DEALLOCATE (cache%coord_scaled)
     609           17 :       IF (ALLOCATED(cache%ref_coord_primary)) DEALLOCATE (cache%ref_coord_primary)
     610           17 :       IF (ALLOCATED(cache%image_atom)) DEALLOCATE (cache%image_atom)
     611           17 :       IF (ALLOCATED(cache%head)) DEALLOCATE (cache%head)
     612           17 :       IF (ALLOCATED(cache%next)) DEALLOCATE (cache%next)
     613           17 :       IF (ALLOCATED(cache%image_shift)) DEALLOCATE (cache%image_shift)
     614           17 :       IF (ALLOCATED(cache%image_translation)) DEALLOCATE (cache%image_translation)
     615           17 :       cache%initialized = .FALSE.
     616           17 :       cache%num_atoms = -1
     617           17 :       cache%n_images = 0
     618           17 :    END SUBROUTINE nnp_cell_list_cache_release
     619              : 
     620              : ! **************************************************************************************************
     621              : !> \brief Free the allocatable parts of a neighbour-interface state. Co-located
     622              : !>        with the type definition to avoid creating a USE-cycle through
     623              : !>        nnp_neighbor_interface.
     624              : !> \param state neighbour-interface state whose pair maps and per-element workspaces are freed
     625              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     626              : ! **************************************************************************************************
     627           34 :    SUBROUTINE nnp_neighbor_interface_state_release(state)
     628              :       TYPE(nnp_neighbor_interface_state_type), &
     629              :          INTENT(INOUT)                                   :: state
     630              : 
     631              :       INTEGER                                            :: i, j
     632              : 
     633           34 :       IF (ALLOCATED(state%pair_map)) THEN
     634           52 :          DO i = 1, SIZE(state%pair_map, 1)
     635          125 :             DO j = 1, SIZE(state%pair_map, 2)
     636           73 :                IF (ALLOCATED(state%pair_map(i, j)%rad_groups)) DEALLOCATE (state%pair_map(i, j)%rad_groups)
     637           73 :                IF (ALLOCATED(state%pair_map(i, j)%ang1_groups)) DEALLOCATE (state%pair_map(i, j)%ang1_groups)
     638          108 :                IF (ALLOCATED(state%pair_map(i, j)%ang2_groups)) DEALLOCATE (state%pair_map(i, j)%ang2_groups)
     639              :             END DO
     640              :          END DO
     641           90 :          DEALLOCATE (state%pair_map)
     642              :       END IF
     643              : 
     644           34 :       IF (ALLOCATED(state%workspace)) THEN
     645           52 :          DO i = 1, SIZE(state%workspace)
     646           52 :             CALL nnp_workspace_release(state%workspace(i))
     647              :          END DO
     648           52 :          DEALLOCATE (state%workspace)
     649              :       END IF
     650              : 
     651           34 :       IF (ALLOCATED(state%n_rad)) DEALLOCATE (state%n_rad)
     652           34 :       IF (ALLOCATED(state%n_ang)) DEALLOCATE (state%n_ang)
     653           34 :       IF (ALLOCATED(state%n_radgrp)) DEALLOCATE (state%n_radgrp)
     654           34 :       IF (ALLOCATED(state%n_anggrp)) DEALLOCATE (state%n_anggrp)
     655              : 
     656           34 :       state%initialized = .FALSE.
     657           34 :       state%n_ele = 0
     658           34 :    END SUBROUTINE nnp_neighbor_interface_state_release
     659              : 
     660              : ! **************************************************************************************************
     661              : !> \brief Free the allocatable parts of one per-element workspace.
     662              : !> \param workspace per-element workspace whose scratch, cutoff caches and dGdr buffers are freed
     663              : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
     664              : ! **************************************************************************************************
     665           35 :    SUBROUTINE nnp_workspace_release(workspace)
     666              :       TYPE(nnp_neighbor_workspace_type), INTENT(INOUT)   :: workspace
     667              : 
     668              :       INTEGER                                            :: s
     669              : 
     670           35 :       IF (ALLOCATED(workspace%neighbor%rad)) THEN
     671          106 :          DO s = 1, SIZE(workspace%neighbor%rad)
     672           71 :             IF (ALLOCATED(workspace%neighbor%rad(s)%ind)) DEALLOCATE (workspace%neighbor%rad(s)%ind)
     673          106 :             IF (ALLOCATED(workspace%neighbor%rad(s)%dist)) DEALLOCATE (workspace%neighbor%rad(s)%dist)
     674              :          END DO
     675          106 :          DEALLOCATE (workspace%neighbor%rad)
     676              :       END IF
     677           35 :       IF (ALLOCATED(workspace%neighbor%ang1)) THEN
     678          121 :          DO s = 1, SIZE(workspace%neighbor%ang1)
     679           86 :             IF (ALLOCATED(workspace%neighbor%ang1(s)%ind)) DEALLOCATE (workspace%neighbor%ang1(s)%ind)
     680          121 :             IF (ALLOCATED(workspace%neighbor%ang1(s)%dist)) DEALLOCATE (workspace%neighbor%ang1(s)%dist)
     681              :          END DO
     682          121 :          DEALLOCATE (workspace%neighbor%ang1)
     683              :       END IF
     684           35 :       IF (ALLOCATED(workspace%neighbor%ang2)) THEN
     685          121 :          DO s = 1, SIZE(workspace%neighbor%ang2)
     686           86 :             IF (ALLOCATED(workspace%neighbor%ang2(s)%ind)) DEALLOCATE (workspace%neighbor%ang2(s)%ind)
     687          121 :             IF (ALLOCATED(workspace%neighbor%ang2(s)%dist)) DEALLOCATE (workspace%neighbor%ang2(s)%dist)
     688              :          END DO
     689          121 :          DEALLOCATE (workspace%neighbor%ang2)
     690              :       END IF
     691           35 :       IF (ALLOCATED(workspace%neighbor%n_rad)) DEALLOCATE (workspace%neighbor%n_rad)
     692           35 :       IF (ALLOCATED(workspace%neighbor%n_ang1)) DEALLOCATE (workspace%neighbor%n_ang1)
     693           35 :       IF (ALLOCATED(workspace%neighbor%n_ang2)) DEALLOCATE (workspace%neighbor%n_ang2)
     694          140 :       workspace%neighbor%pbc_copies = -1
     695              : 
     696           35 :       IF (ALLOCATED(workspace%radial_sym)) DEALLOCATE (workspace%radial_sym)
     697           35 :       IF (ALLOCATED(workspace%radial_force)) DEALLOCATE (workspace%radial_force)
     698           35 :       IF (ALLOCATED(workspace%angular_sym)) DEALLOCATE (workspace%angular_sym)
     699           35 :       IF (ALLOCATED(workspace%angular_force)) DEALLOCATE (workspace%angular_force)
     700           35 :       IF (ALLOCATED(workspace%fc_cache1)) DEALLOCATE (workspace%fc_cache1)
     701           35 :       IF (ALLOCATED(workspace%dfc_cache1)) DEALLOCATE (workspace%dfc_cache1)
     702           35 :       IF (ALLOCATED(workspace%fc_cache2)) DEALLOCATE (workspace%fc_cache2)
     703           35 :       IF (ALLOCATED(workspace%dfc_cache2)) DEALLOCATE (workspace%dfc_cache2)
     704           35 :       IF (ALLOCATED(workspace%self_dGdr)) DEALLOCATE (workspace%self_dGdr)
     705              : 
     706           35 :       IF (ALLOCATED(workspace%dGdr_rad)) THEN
     707          106 :          DO s = 1, SIZE(workspace%dGdr_rad)
     708          106 :             IF (ALLOCATED(workspace%dGdr_rad(s)%data)) DEALLOCATE (workspace%dGdr_rad(s)%data)
     709              :          END DO
     710          106 :          DEALLOCATE (workspace%dGdr_rad)
     711              :       END IF
     712           35 :       IF (ALLOCATED(workspace%dGdr_ang_jj)) THEN
     713          121 :          DO s = 1, SIZE(workspace%dGdr_ang_jj)
     714          121 :             IF (ALLOCATED(workspace%dGdr_ang_jj(s)%data)) DEALLOCATE (workspace%dGdr_ang_jj(s)%data)
     715              :          END DO
     716          121 :          DEALLOCATE (workspace%dGdr_ang_jj)
     717              :       END IF
     718           35 :       IF (ALLOCATED(workspace%dGdr_ang_kk)) THEN
     719          121 :          DO s = 1, SIZE(workspace%dGdr_ang_kk)
     720          121 :             IF (ALLOCATED(workspace%dGdr_ang_kk(s)%data)) DEALLOCATE (workspace%dGdr_ang_kk(s)%data)
     721              :          END DO
     722          121 :          DEALLOCATE (workspace%dGdr_ang_kk)
     723              :       END IF
     724              : 
     725           35 :       workspace%max_rad_symf = 0
     726           35 :       workspace%max_ang_symf = 0
     727           35 :       workspace%n_input_nodes = 0
     728           35 :       workspace%cache_cap = 0
     729           35 :    END SUBROUTINE nnp_workspace_release
     730              : 
     731              : ! **************************************************************************************************
     732              : !> \brief Returns various attributes of the nnp environment
     733              : !> \param nnp_env ...
     734              : !> \param nnp_forces ...
     735              : !> \param subsys the particles, molecules,... of this environment
     736              : !> \param atomic_kind_set The set of all atomic kinds involved
     737              : !> \param particle_set The set of all particles
     738              : !> \param local_particles All particles on this particular node
     739              : !> \param molecule_kind_set The set of all different molecule kinds involved
     740              : !> \param molecule_set The set of all molecules
     741              : !> \param local_molecules All molecules on this particular node
     742              : !> \param nnp_input ...
     743              : !> \param force_env_input Pointer to the force_env input section
     744              : !> \param cell The simulation cell
     745              : !> \param cell_ref The reference simulation cell
     746              : !> \param use_ref_cell Logical which indicates if reference
     747              : !>                      simulation cell is used
     748              : !> \param nnp_potential_energy ...
     749              : !> \param virial Dummy virial pointer
     750              : !> \date   2020-10-10
     751              : !> \author Christoph Schran (christoph.schran@rub.de)
     752              : !> \note
     753              : !>      For possible missing arguments see the attributes of
     754              : !>      nnp_type
     755              : ! **************************************************************************************************
     756        61998 :    SUBROUTINE nnp_env_get(nnp_env, nnp_forces, subsys, &
     757              :                           atomic_kind_set, particle_set, local_particles, &
     758              :                           molecule_kind_set, molecule_set, local_molecules, &
     759              :                           nnp_input, force_env_input, cell, cell_ref, &
     760              :                           use_ref_cell, nnp_potential_energy, virial)
     761              : 
     762              :       TYPE(nnp_type), INTENT(IN)                         :: nnp_env
     763              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: nnp_forces
     764              :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: subsys
     765              :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     766              :          POINTER                                         :: atomic_kind_set
     767              :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     768              :          POINTER                                         :: particle_set
     769              :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles
     770              :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     771              :          POINTER                                         :: molecule_kind_set
     772              :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     773              :          POINTER                                         :: molecule_set
     774              :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_molecules
     775              :       TYPE(section_vals_type), OPTIONAL, POINTER         :: nnp_input, force_env_input
     776              :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell, cell_ref
     777              :       LOGICAL, INTENT(OUT), OPTIONAL                     :: use_ref_cell
     778              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: nnp_potential_energy
     779              :       TYPE(virial_type), OPTIONAL, POINTER               :: virial
     780              : 
     781              :       TYPE(atomic_kind_list_type), POINTER               :: atomic_kinds
     782              :       TYPE(molecule_kind_list_type), POINTER             :: molecule_kinds
     783              :       TYPE(molecule_list_type), POINTER                  :: molecules
     784              :       TYPE(particle_list_type), POINTER                  :: particles
     785              : 
     786        61998 :       NULLIFY (atomic_kinds, particles, molecules, molecule_kinds)
     787              : 
     788        61998 :       IF (PRESENT(nnp_potential_energy)) THEN
     789          618 :          nnp_potential_energy = nnp_env%nnp_potential_energy
     790              :       END IF
     791        61998 :       IF (PRESENT(nnp_forces)) nnp_forces = nnp_env%nnp_forces
     792              : 
     793              :       ! note cell will be overwritten if subsys is associated
     794              :       ! helium_env uses nnp without subsys
     795        61998 :       IF (PRESENT(cell)) cell => nnp_env%cell
     796              : 
     797        61998 :       IF (PRESENT(subsys)) subsys => nnp_env%subsys
     798        61998 :       IF (ASSOCIATED(nnp_env%subsys)) THEN
     799              :          CALL cp_subsys_get(nnp_env%subsys, &
     800              :                             atomic_kinds=atomic_kinds, &
     801              :                             particles=particles, &
     802              :                             molecule_kinds=molecule_kinds, &
     803              :                             molecules=molecules, &
     804              :                             local_molecules=local_molecules, &
     805              :                             local_particles=local_particles, &
     806              :                             virial=virial, &
     807         6826 :                             cell=cell)
     808              :       END IF
     809        61998 :       IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
     810        61998 :       IF (PRESENT(particle_set)) particle_set => particles%els
     811        61998 :       IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
     812        61998 :       IF (PRESENT(molecule_set)) molecule_set => molecules%els
     813              : 
     814        61998 :       IF (PRESENT(nnp_input)) nnp_input => nnp_env%nnp_input
     815        61998 :       IF (PRESENT(force_env_input)) force_env_input => nnp_env%force_env_input
     816        61998 :       IF (PRESENT(cell_ref)) cell_ref => nnp_env%cell_ref
     817        61998 :       IF (PRESENT(use_ref_cell)) use_ref_cell = nnp_env%use_ref_cell
     818              : 
     819        61998 :    END SUBROUTINE nnp_env_get
     820              : 
     821              : ! **************************************************************************************************
     822              : !> \brief Sets various attributes of the nnp environment
     823              : !> \param nnp_env ...
     824              : !> \param nnp_forces ...
     825              : !> \param subsys the particles, molecules,... of this environment
     826              : !> \param atomic_kind_set The set of all atomic kinds involved
     827              : !> \param particle_set The set of all particles
     828              : !> \param local_particles All particles on this particular node
     829              : !> \param molecule_kind_set The set of all different molecule kinds involved
     830              : !> \param molecule_set The set of all molecules
     831              : !> \param local_molecules All molecules on this particular node
     832              : !> \param nnp_input ...
     833              : !> \param force_env_input Pointer to the force_env input section
     834              : !> \param cell ...
     835              : !> \param cell_ref The reference simulation cell
     836              : !> \param use_ref_cell Logical which indicates if reference
     837              : !>                      simulation cell is used
     838              : !> \param nnp_potential_energy ...
     839              : !> \date   2020-10-10
     840              : !> \author Christoph Schran (christoph.schran@rub.de)
     841              : !> \note
     842              : !>   For possible missing arguments see the attributes of nnp_type
     843              : ! **************************************************************************************************
     844           50 :    SUBROUTINE nnp_env_set(nnp_env, nnp_forces, subsys, &
     845              :                           atomic_kind_set, particle_set, local_particles, &
     846              :                           molecule_kind_set, molecule_set, local_molecules, &
     847              :                           nnp_input, force_env_input, cell, cell_ref, &
     848              :                           use_ref_cell, nnp_potential_energy)
     849              : 
     850              :       TYPE(nnp_type), INTENT(INOUT)                      :: nnp_env
     851              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: nnp_forces
     852              :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: subsys
     853              :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     854              :          POINTER                                         :: atomic_kind_set
     855              :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     856              :          POINTER                                         :: particle_set
     857              :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles
     858              :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     859              :          POINTER                                         :: molecule_kind_set
     860              :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     861              :          POINTER                                         :: molecule_set
     862              :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_molecules
     863              :       TYPE(section_vals_type), OPTIONAL, POINTER         :: nnp_input, force_env_input
     864              :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell, cell_ref
     865              :       LOGICAL, INTENT(IN), OPTIONAL                      :: use_ref_cell
     866              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: nnp_potential_energy
     867              : 
     868              :       TYPE(atomic_kind_list_type), POINTER               :: atomic_kinds
     869              :       TYPE(molecule_kind_list_type), POINTER             :: molecule_kinds
     870              :       TYPE(molecule_list_type), POINTER                  :: molecules
     871              :       TYPE(particle_list_type), POINTER                  :: particles
     872              : 
     873           50 :       IF (PRESENT(nnp_potential_energy)) THEN
     874            0 :          nnp_env%nnp_potential_energy = nnp_potential_energy
     875              :       END IF
     876           50 :       IF (PRESENT(nnp_forces)) nnp_env%nnp_forces(:, :) = nnp_forces
     877              : 
     878           50 :       IF (PRESENT(subsys)) THEN
     879           16 :          IF (ASSOCIATED(nnp_env%subsys)) THEN
     880            0 :          IF (.NOT. ASSOCIATED(nnp_env%subsys, subsys)) THEN
     881            0 :             CALL cp_subsys_release(nnp_env%subsys)
     882              :          END IF
     883              :          END IF
     884           16 :          nnp_env%subsys => subsys
     885              :       END IF
     886           50 :       IF (PRESENT(cell)) THEN
     887           17 :          IF (ASSOCIATED(cell)) THEN
     888           17 :             CALL cell_retain(cell)
     889           17 :             CALL cell_release(nnp_env%cell)
     890           17 :             nnp_env%cell => cell
     891              :          END IF
     892           17 :          IF (ASSOCIATED(nnp_env%subsys)) THEN
     893           16 :             CALL cp_subsys_set(nnp_env%subsys, cell=cell)
     894              :          END IF
     895              :       END IF
     896           50 :       IF (PRESENT(atomic_kind_set)) THEN
     897            0 :          CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
     898            0 :          CALL cp_subsys_set(nnp_env%subsys, atomic_kinds=atomic_kinds)
     899            0 :          CALL atomic_kind_list_release(atomic_kinds)
     900              :       END IF
     901           50 :       IF (PRESENT(particle_set)) THEN
     902            0 :          CALL particle_list_create(particles, els_ptr=particle_set)
     903            0 :          CALL cp_subsys_set(nnp_env%subsys, particles=particles)
     904            0 :          CALL particle_list_release(particles)
     905              :       END IF
     906           50 :       IF (PRESENT(molecule_kind_set)) THEN
     907            0 :          CALL molecule_kind_list_create(molecule_kinds, els_ptr=molecule_kind_set)
     908            0 :          CALL cp_subsys_set(nnp_env%subsys, molecule_kinds=molecule_kinds)
     909            0 :          CALL molecule_kind_list_release(molecule_kinds)
     910              :       END IF
     911           50 :       IF (PRESENT(molecule_set)) THEN
     912            0 :          CALL molecule_list_create(molecules, els_ptr=molecule_set)
     913            0 :          CALL cp_subsys_set(nnp_env%subsys, molecules=molecules)
     914            0 :          CALL molecule_list_release(molecules)
     915              :       END IF
     916           50 :       IF (PRESENT(local_particles)) THEN
     917           16 :          CALL cp_subsys_set(nnp_env%subsys, local_particles=local_particles)
     918              :       END IF
     919           50 :       IF (PRESENT(local_molecules)) THEN
     920           16 :          CALL cp_subsys_set(nnp_env%subsys, local_molecules=local_molecules)
     921              :       END IF
     922              : 
     923           50 :       IF (PRESENT(nnp_input)) nnp_env%nnp_input => nnp_input
     924           50 :       IF (PRESENT(force_env_input)) THEN
     925           16 :          nnp_env%force_env_input => force_env_input
     926              :       END IF
     927           50 :       IF (PRESENT(cell_ref)) THEN
     928           16 :          CALL cell_retain(cell_ref)
     929           16 :          CALL cell_release(nnp_env%cell_ref)
     930           16 :          nnp_env%cell_ref => cell_ref
     931              :       END IF
     932           50 :       IF (PRESENT(use_ref_cell)) nnp_env%use_ref_cell = use_ref_cell
     933           50 :    END SUBROUTINE nnp_env_set
     934              : 
     935            0 : END MODULE nnp_environment_types
        

Generated by: LCOV version 2.0-1