LCOV - code coverage report
Current view: top level - src - nnp_environment_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 101 148 68.2 %
Date: 2024-11-21 06:45:46 Functions: 3 17 17.6 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 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             : !> \date   2020-10-10
      12             : ! **************************************************************************************************
      13             : MODULE nnp_environment_types
      14             :    USE atomic_kind_list_types,          ONLY: atomic_kind_list_create,&
      15             :                                               atomic_kind_list_release,&
      16             :                                               atomic_kind_list_type
      17             :    USE atomic_kind_types,               ONLY: atomic_kind_type
      18             :    USE cell_types,                      ONLY: cell_release,&
      19             :                                               cell_retain,&
      20             :                                               cell_type
      21             :    USE cp_subsys_types,                 ONLY: cp_subsys_get,&
      22             :                                               cp_subsys_release,&
      23             :                                               cp_subsys_set,&
      24             :                                               cp_subsys_type
      25             :    USE distribution_1d_types,           ONLY: distribution_1d_type
      26             :    USE input_section_types,             ONLY: section_vals_type
      27             :    USE kinds,                           ONLY: default_string_length,&
      28             :                                               dp
      29             :    USE molecule_kind_list_types,        ONLY: molecule_kind_list_create,&
      30             :                                               molecule_kind_list_release,&
      31             :                                               molecule_kind_list_type
      32             :    USE molecule_kind_types,             ONLY: molecule_kind_type
      33             :    USE molecule_list_types,             ONLY: molecule_list_create,&
      34             :                                               molecule_list_release,&
      35             :                                               molecule_list_type
      36             :    USE molecule_types,                  ONLY: molecule_type
      37             :    USE particle_list_types,             ONLY: particle_list_create,&
      38             :                                               particle_list_release,&
      39             :                                               particle_list_type
      40             :    USE particle_types,                  ONLY: particle_type
      41             :    USE virial_types,                    ONLY: virial_type
      42             : #include "./base/base_uses.f90"
      43             : 
      44             :    IMPLICIT NONE
      45             : 
      46             :    PRIVATE
      47             : 
      48             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      49             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'nnp_environment_types'
      50             : 
      51             :    !> derived data types
      52             :    PUBLIC :: nnp_type
      53             :    PUBLIC :: nnp_arc_type
      54             :    PUBLIC :: nnp_neighbor_type
      55             :    PUBLIC :: nnp_acsf_rad_type
      56             :    PUBLIC :: nnp_acsf_ang_type
      57             : 
      58             :    ! Public subroutines ***
      59             :    PUBLIC :: nnp_env_release, &
      60             :              nnp_env_set, &
      61             :              nnp_env_get
      62             : 
      63             :    INTEGER, PARAMETER, PUBLIC :: &
      64             :       nnp_cut_cos = 1, &
      65             :       nnp_cut_tanh = 2
      66             : 
      67             :    INTEGER, PARAMETER, PUBLIC :: &
      68             :       nnp_actfnct_tanh = 1, &
      69             :       nnp_actfnct_gaus = 2, &
      70             :       nnp_actfnct_lin = 3, &
      71             :       nnp_actfnct_cos = 4, &
      72             :       nnp_actfnct_sig = 5, &
      73             :       nnp_actfnct_invsig = 6, &
      74             :       nnp_actfnct_exp = 7, &
      75             :       nnp_actfnct_softplus = 8, &
      76             :       nnp_actfnct_quad = 9
      77             : 
      78             : ! **************************************************************************************************
      79             : !> \brief Main data type collecting all relevant data for neural network potentials
      80             : !> \author Christoph Schran (christoph.schran@rub.de)
      81             : !> \date   2020-10-10
      82             : ! **************************************************************************************************
      83             :    TYPE nnp_type
      84             :       TYPE(nnp_acsf_rad_type), DIMENSION(:), POINTER      :: rad => NULL() ! DIM(n_ele)
      85             :       TYPE(nnp_acsf_ang_type), DIMENSION(:), POINTER      :: ang => NULL() ! DIM(n_ele)
      86             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_rad ! # radial symfnct for this element
      87             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_ang ! # angular symfnct for this element
      88             :       INTEGER                                             :: n_ele = -1 ! # elements
      89             :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele ! elements(n_ele)
      90             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele ! elements(n_ele)
      91             :       LOGICAL                                             :: scale_acsf = .FALSE.
      92             :       LOGICAL                                             :: scale_sigma_acsf = .FALSE.
      93             :       LOGICAL                                             :: center_acsf = .FALSE.
      94             :       LOGICAL                                             :: normnodes = .FALSE.
      95             :       INTEGER                                             :: n_radgrp = -1
      96             :       INTEGER                                             :: n_anggrp = -1
      97             :       INTEGER                                             :: cut_type = -1 ! cutofftype
      98             :       REAL(KIND=dp)                                       :: eshortmin = -1.0_dp
      99             :       REAL(KIND=dp)                                       :: eshortmax = -1.0_dp
     100             :       REAL(KIND=dp)                                       :: scmax = -1.0_dp !scale
     101             :       REAL(KIND=dp)                                       :: scmin = -1.0_dp !scale
     102             :       REAL(KIND=dp)                                       :: max_cut = -1.0_dp !largest cutoff
     103             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: atom_energies !DIM(n_ele)
     104             :       TYPE(nnp_arc_type), POINTER, DIMENSION(:)           :: arc => NULL() ! DIM(n_ele)
     105             :       INTEGER                                             :: n_committee = -1
     106             :       INTEGER                                             :: n_hlayer = -1
     107             :       INTEGER                                             :: n_layer = -1
     108             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_hnodes
     109             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: actfnct
     110             :       INTEGER                                             :: expol = -1 ! extrapolation coutner
     111             :       LOGICAL                                             :: output_expol = .FALSE. ! output extrapolation
     112             :       ! structures for calculation
     113             :       INTEGER                                             :: num_atoms = -1
     114             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: atomic_energy
     115             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: committee_energy
     116             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: ele_ind, nuc_atoms, sort, sort_inv
     117             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: coord
     118             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: myforce
     119             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: committee_forces, committee_stress
     120             :       CHARACTER(len=default_string_length), &
     121             :          ALLOCATABLE, DIMENSION(:)                        :: atoms
     122             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE         :: nnp_forces
     123             :       REAL(KIND=dp)                                       :: nnp_potential_energy = -1.0_dp
     124             :       TYPE(cp_subsys_type), POINTER                       :: subsys => NULL()
     125             :       TYPE(section_vals_type), POINTER                    :: nnp_input => NULL()
     126             :       TYPE(section_vals_type), POINTER                    :: force_env_input => NULL()
     127             :       TYPE(cell_type), POINTER                            :: cell => NULL()
     128             :       TYPE(cell_type), POINTER                            :: cell_ref => NULL()
     129             :       LOGICAL                                             :: use_ref_cell = .FALSE.
     130             :       ! bias
     131             :       LOGICAL                                             :: bias = .FALSE.
     132             :       LOGICAL                                             :: bias_align = .FALSE.
     133             :       REAL(KIND=dp)                                       :: bias_energy = -1.0_dp
     134             :       REAL(KIND=dp)                                       :: bias_kb = -1.0_dp
     135             :       REAL(KIND=dp)                                       :: bias_sigma0 = -1.0_dp
     136             :       REAL(KIND=dp)                                       :: bias_sigma = -1.0_dp
     137             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE         :: bias_forces
     138             :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE            :: bias_e_avrg
     139             :    END TYPE nnp_type
     140             : 
     141             : ! **************************************************************************************************
     142             : !> \brief Symmetry functions group type
     143             : !> \param n_symf - # of associated sym fncts
     144             : !> \param symf   - indices of associated sym fncts       DIM(nsymf)
     145             : !> \param ele    - elements indices          rad:DIM(2), ang:DIM(3)
     146             : !> \param cutoff - associated cutoff value
     147             : !> \author Christoph Schran (christoph.schran@rub.de)
     148             : !> \date   2020-10-10
     149             : ! **************************************************************************************************
     150             :    TYPE nnp_symfgrp_type
     151             :       INTEGER                                             :: n_symf = -1
     152             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: symf
     153             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: ele_ind
     154             :       CHARACTER(LEN=2), DIMENSION(:), ALLOCATABLE         :: ele
     155             :       REAL(KIND=dp)                                       :: cutoff = -1.0_dp
     156             :    END TYPE
     157             : 
     158             : ! **************************************************************************************************
     159             : !> \brief Set of radial symmetry function type
     160             : !> \param y       - acsf value                                     - DIM(n_rad)
     161             : !> \param funccut - distance cutoff                           bohr - DIM(n_rad)
     162             : !> \param eta     - eta parameter of radial sym fncts      bohr^-2 - DIM(n_rad)
     163             : !> \param rs      - r shift parameter of radial sym fncts     bohr - DIM(n_rad)
     164             : !> \param loc_min - minimum of the sym fnct                          DIM(n_rad)
     165             : !> \param loc_max - maximum of the sym fnct                          DIM(n_rad)
     166             : !> \param loc_av  - average of the sym fnct                          DIM(n_rad)
     167             : !> \param sigma   - SD of the sym fnc                                DIM(n_rad)
     168             : !> \param ele     - element associated to the sym fnct               DIM(n_rad)
     169             : !> \param nuc_ele - associated atomic number                         DIM(n_rad)
     170             : !> \author Christoph Schran (christoph.schran@rub.de)
     171             : !> \date   2020-10-10
     172             : ! **************************************************************************************************
     173             :    TYPE nnp_acsf_rad_type
     174             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: y
     175             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: funccut
     176             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: eta
     177             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: rs
     178             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_min
     179             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_max
     180             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_av
     181             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: sigma
     182             :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele
     183             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele
     184             :       INTEGER                                             :: n_symfgrp = -1
     185             :       TYPE(nnp_symfgrp_type), DIMENSION(:), ALLOCATABLE   :: symfgrp
     186             :    END TYPE
     187             : 
     188             : ! **************************************************************************************************
     189             : !> \brief Set of angular symmetry function type
     190             : !> \param y         - acsf value                                  - DIM(n_ang)
     191             : !> \param funccut   - distance cutoff                        bohr - DIM(n_ang)
     192             : !> \param eta       - eta  param. of angular sym fncts    bohr^-2 - DIM(n_ang)
     193             : !> \param zeta      - zeta param. of angular sym fncts              DIM(n_ang)
     194             : !> \param lam       - lambda  param. of angular sym fncts           DIM(n_ang)
     195             : !> \param loc_min   - minimum of the sym fnct                       DIM(n_ang)
     196             : !> \param loc_max   - maximum of the sym fnct                       DIM(n_ang)
     197             : !> \param loc_av    - average of the sym fnct                       DIM(n_ang)
     198             : !> \param sigma     - SD of the sym fnc                             DIM(n_ang)
     199             : !> \param ele1,ele2 - elements associated to the sym fnct           DIM(n_ang)
     200             : !> \param nuc_ele2, nuc_ele2 - associated atomic numbers            DIM(n_ang)
     201             : !> \author Christoph Schran (christoph.schran@rub.de)
     202             : !> \date   2020-10-10
     203             : ! **************************************************************************************************
     204             :    TYPE nnp_acsf_ang_type
     205             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: y
     206             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: funccut
     207             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: eta
     208             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: zeta
     209             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: prefzeta
     210             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: lam
     211             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_min
     212             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_max
     213             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: loc_av
     214             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: sigma
     215             :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele1
     216             :       CHARACTER(len=2), ALLOCATABLE, DIMENSION(:)         :: ele2
     217             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele1
     218             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: nuc_ele2
     219             :       INTEGER                                             :: n_symfgrp = -1
     220             :       TYPE(nnp_symfgrp_type), DIMENSION(:), ALLOCATABLE   :: symfgrp
     221             :    END TYPE
     222             : 
     223             : ! **************************************************************************************************
     224             : !> \brief Contains neighbors list of an atom
     225             : !> \param dist - distance vectors + norm                      DIM(4,nat)
     226             : !> \param n    - number of neighbors
     227             : !> \author Christoph Schran (christoph.schran@rub.de)
     228             : !> \date   2020-10-10
     229             : ! **************************************************************************************************
     230             :    TYPE nnp_neighbor_type
     231             :       INTEGER, DIMENSION(3)                               :: pbc_copies = -1
     232             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_rad
     233             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_ang1
     234             :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: n_ang2
     235             :       INTEGER, DIMENSION(:, :), ALLOCATABLE               :: ind_rad
     236             :       INTEGER, DIMENSION(:, :), ALLOCATABLE               :: ind_ang1
     237             :       INTEGER, DIMENSION(:, :), ALLOCATABLE               :: ind_ang2
     238             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE      :: dist_rad
     239             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE      :: dist_ang1
     240             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE      :: dist_ang2
     241             :    END TYPE
     242             : 
     243             : ! **************************************************************************************************
     244             : !> \brief Data type for artificial neural networks
     245             : !> \author Christoph Schran (christoph.schran@rub.de)
     246             : !> \date   2020-10-10
     247             : ! **************************************************************************************************
     248             :    TYPE nnp_arc_type
     249             :       TYPE(nnp_arc_layer_type), POINTER, DIMENSION(:)     :: layer => NULL() ! DIM(n_layer)
     250             :       INTEGER, ALLOCATABLE, DIMENSION(:)                  :: n_nodes
     251             :    END TYPE
     252             : 
     253             : ! **************************************************************************************************
     254             : !> \brief Data type for individual layer
     255             : !> \author Christoph Schran (christoph.schran@rub.de)
     256             : !> \date   2020-10-10
     257             : ! **************************************************************************************************
     258             :    TYPE nnp_arc_layer_type
     259             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)      :: weights ! node weights
     260             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: bweights ! bias weights
     261             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: node ! DIM(n_nodes)
     262             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)            :: node_grad ! DIM(n_nodes)
     263             :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)         :: tmp_der ! DIM(n_sym,n_nodes)
     264             :    END TYPE
     265             : 
     266             : CONTAINS
     267             : 
     268             : ! **************************************************************************************************
     269             : !> \brief Release data structure that holds all the information for neural
     270             : !>        network potentials
     271             : !> \param nnp_env ...
     272             : !> \date   2020-10-10
     273             : !> \author Christoph Schran (christoph.schran@rub.de)
     274             : ! **************************************************************************************************
     275          15 :    SUBROUTINE nnp_env_release(nnp_env)
     276             :       TYPE(nnp_type), INTENT(INOUT)                      :: nnp_env
     277             : 
     278             :       INTEGER                                            :: i, j
     279             : 
     280          15 :       IF (ASSOCIATED(nnp_env%rad)) THEN
     281          46 :          DO i = 1, nnp_env%n_ele
     282          94 :             DO j = 1, nnp_env%rad(i)%n_symfgrp
     283           0 :                DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%symf, &
     284           0 :                            nnp_env%rad(i)%symfgrp(j)%ele, &
     285          94 :                            nnp_env%rad(i)%symfgrp(j)%ele_ind)
     286             :             END DO
     287           0 :             DEALLOCATE (nnp_env%rad(i)%y, &
     288           0 :                         nnp_env%rad(i)%funccut, &
     289           0 :                         nnp_env%rad(i)%eta, &
     290           0 :                         nnp_env%rad(i)%rs, &
     291           0 :                         nnp_env%rad(i)%loc_min, &
     292           0 :                         nnp_env%rad(i)%loc_max, &
     293           0 :                         nnp_env%rad(i)%loc_av, &
     294           0 :                         nnp_env%rad(i)%sigma, &
     295           0 :                         nnp_env%rad(i)%ele, &
     296           0 :                         nnp_env%rad(i)%nuc_ele, &
     297         109 :                         nnp_env%rad(i)%symfgrp)
     298             :          END DO
     299          15 :          DEALLOCATE (nnp_env%rad)
     300             :       END IF
     301             : 
     302          15 :       IF (ASSOCIATED(nnp_env%ang)) THEN
     303          46 :          DO i = 1, nnp_env%n_ele
     304         107 :             DO j = 1, nnp_env%ang(i)%n_symfgrp
     305           0 :                DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%symf, &
     306           0 :                            nnp_env%ang(i)%symfgrp(j)%ele, &
     307         107 :                            nnp_env%ang(i)%symfgrp(j)%ele_ind)
     308             :             END DO
     309           0 :             DEALLOCATE (nnp_env%ang(i)%y, &
     310           0 :                         nnp_env%ang(i)%funccut, &
     311           0 :                         nnp_env%ang(i)%eta, &
     312           0 :                         nnp_env%ang(i)%zeta, &
     313           0 :                         nnp_env%ang(i)%prefzeta, &
     314           0 :                         nnp_env%ang(i)%lam, &
     315           0 :                         nnp_env%ang(i)%loc_min, &
     316           0 :                         nnp_env%ang(i)%loc_max, &
     317           0 :                         nnp_env%ang(i)%loc_av, &
     318           0 :                         nnp_env%ang(i)%sigma, &
     319           0 :                         nnp_env%ang(i)%ele1, &
     320           0 :                         nnp_env%ang(i)%ele2, &
     321           0 :                         nnp_env%ang(i)%nuc_ele1, &
     322           0 :                         nnp_env%ang(i)%nuc_ele2, &
     323         122 :                         nnp_env%ang(i)%symfgrp)
     324             :          END DO
     325          15 :          DEALLOCATE (nnp_env%ang)
     326             :       END IF
     327             : 
     328          15 :       IF (ASSOCIATED(nnp_env%arc)) THEN
     329          46 :          DO i = 1, nnp_env%n_ele
     330          46 :             IF (ASSOCIATED(nnp_env%arc(i)%layer)) THEN
     331         155 :                DO j = 1, nnp_env%n_layer
     332         124 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%node)) THEN
     333         124 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%node)
     334             :                   END IF
     335         124 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%node_grad)) THEN
     336         124 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%node_grad)
     337             :                   END IF
     338         124 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%weights)) THEN
     339          93 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%weights)
     340             :                   END IF
     341         124 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%bweights)) THEN
     342          93 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%bweights)
     343             :                   END IF
     344         155 :                   IF (ALLOCATED(nnp_env%arc(i)%layer(j)%tmp_der)) THEN
     345         124 :                      DEALLOCATE (nnp_env%arc(i)%layer(j)%tmp_der)
     346             :                   END IF
     347             :                END DO
     348           0 :                DEALLOCATE (nnp_env%arc(i)%layer, &
     349          31 :                            nnp_env%arc(i)%n_nodes)
     350             :             END IF
     351             :          END DO
     352          15 :          DEALLOCATE (nnp_env%arc)
     353             :       END IF
     354             : 
     355          15 :       IF (ALLOCATED(nnp_env%ele)) DEALLOCATE (nnp_env%ele)
     356          15 :       IF (ALLOCATED(nnp_env%nuc_ele)) DEALLOCATE (nnp_env%nuc_ele)
     357          15 :       IF (ALLOCATED(nnp_env%n_hnodes)) DEALLOCATE (nnp_env%n_hnodes)
     358          15 :       IF (ALLOCATED(nnp_env%actfnct)) DEALLOCATE (nnp_env%actfnct)
     359          15 :       IF (ALLOCATED(nnp_env%nnp_forces)) DEALLOCATE (nnp_env%nnp_forces)
     360          15 :       IF (ALLOCATED(nnp_env%atomic_energy)) DEALLOCATE (nnp_env%atomic_energy)
     361          15 :       IF (ALLOCATED(nnp_env%committee_energy)) DEALLOCATE (nnp_env%committee_energy)
     362          15 :       IF (ALLOCATED(nnp_env%ele_ind)) DEALLOCATE (nnp_env%ele_ind)
     363          15 :       IF (ALLOCATED(nnp_env%nuc_atoms)) DEALLOCATE (nnp_env%nuc_atoms)
     364          15 :       IF (ALLOCATED(nnp_env%sort)) DEALLOCATE (nnp_env%sort)
     365          15 :       IF (ALLOCATED(nnp_env%sort_inv)) DEALLOCATE (nnp_env%sort_inv)
     366          15 :       IF (ALLOCATED(nnp_env%coord)) DEALLOCATE (nnp_env%coord)
     367          15 :       IF (ALLOCATED(nnp_env%myforce)) DEALLOCATE (nnp_env%myforce)
     368          15 :       IF (ALLOCATED(nnp_env%committee_forces)) DEALLOCATE (nnp_env%committee_forces)
     369          15 :       IF (ALLOCATED(nnp_env%committee_stress)) DEALLOCATE (nnp_env%committee_stress)
     370          15 :       IF (ALLOCATED(nnp_env%atoms)) DEALLOCATE (nnp_env%atoms)
     371          15 :       IF (ALLOCATED(nnp_env%nnp_forces)) DEALLOCATE (nnp_env%nnp_forces)
     372             : 
     373          15 :       IF (ASSOCIATED(nnp_env%subsys)) THEN
     374          14 :          CALL cp_subsys_release(nnp_env%subsys)
     375             :       END IF
     376          15 :       IF (ASSOCIATED(nnp_env%subsys)) THEN
     377           0 :          CALL cp_subsys_release(nnp_env%subsys)
     378             :       END IF
     379          15 :       IF (ASSOCIATED(nnp_env%cell)) THEN
     380           1 :          CALL cell_release(nnp_env%cell)
     381             :       END IF
     382          15 :       IF (ASSOCIATED(nnp_env%cell_ref)) THEN
     383          14 :          CALL cell_release(nnp_env%cell_ref)
     384             :       END IF
     385             : 
     386          15 :    END SUBROUTINE nnp_env_release
     387             : 
     388             : ! **************************************************************************************************
     389             : !> \brief Returns various attributes of the nnp environment
     390             : !> \param nnp_env ...
     391             : !> \param nnp_forces ...
     392             : !> \param subsys the particles, molecules,... of this environment
     393             : !> \param atomic_kind_set The set of all atomic kinds involved
     394             : !> \param particle_set The set of all particles
     395             : !> \param local_particles All particles on this particular node
     396             : !> \param molecule_kind_set The set of all different molecule kinds involved
     397             : !> \param molecule_set The set of all molecules
     398             : !> \param local_molecules All molecules on this particular node
     399             : !> \param nnp_input ...
     400             : !> \param force_env_input Pointer to the force_env input section
     401             : !> \param cell The simulation cell
     402             : !> \param cell_ref The reference simulation cell
     403             : !> \param use_ref_cell Logical which indicates if reference
     404             : !>                      simulation cell is used
     405             : !> \param nnp_potential_energy ...
     406             : !> \param virial Dummy virial pointer
     407             : !> \date   2020-10-10
     408             : !> \author Christoph Schran (christoph.schran@rub.de)
     409             : !> \note
     410             : !>      For possible missing arguments see the attributes of
     411             : !>      nnp_type
     412             : ! **************************************************************************************************
     413      502454 :    SUBROUTINE nnp_env_get(nnp_env, nnp_forces, subsys, &
     414             :                           atomic_kind_set, particle_set, local_particles, &
     415             :                           molecule_kind_set, molecule_set, local_molecules, &
     416             :                           nnp_input, force_env_input, cell, cell_ref, &
     417             :                           use_ref_cell, nnp_potential_energy, virial)
     418             : 
     419             :       TYPE(nnp_type), INTENT(IN)                         :: nnp_env
     420             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: nnp_forces
     421             :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: subsys
     422             :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     423             :          POINTER                                         :: atomic_kind_set
     424             :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     425             :          POINTER                                         :: particle_set
     426             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles
     427             :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     428             :          POINTER                                         :: molecule_kind_set
     429             :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     430             :          POINTER                                         :: molecule_set
     431             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_molecules
     432             :       TYPE(section_vals_type), OPTIONAL, POINTER         :: nnp_input, force_env_input
     433             :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell, cell_ref
     434             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: use_ref_cell
     435             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: nnp_potential_energy
     436             :       TYPE(virial_type), OPTIONAL, POINTER               :: virial
     437             : 
     438             :       TYPE(atomic_kind_list_type), POINTER               :: atomic_kinds
     439             :       TYPE(molecule_kind_list_type), POINTER             :: molecule_kinds
     440             :       TYPE(molecule_list_type), POINTER                  :: molecules
     441             :       TYPE(particle_list_type), POINTER                  :: particles
     442             : 
     443      502454 :       NULLIFY (atomic_kinds, particles, molecules, molecule_kinds)
     444             : 
     445      502454 :       IF (PRESENT(nnp_potential_energy)) THEN
     446         594 :          nnp_potential_energy = nnp_env%nnp_potential_energy
     447             :       END IF
     448      502454 :       IF (PRESENT(nnp_forces)) nnp_forces = nnp_env%nnp_forces
     449             : 
     450             :       ! note cell will be overwritten if subsys is associated
     451             :       ! helium_env uses nnp without subsys
     452      502454 :       IF (PRESENT(cell)) cell => nnp_env%cell
     453             : 
     454      502454 :       IF (PRESENT(subsys)) subsys => nnp_env%subsys
     455      502454 :       IF (ASSOCIATED(nnp_env%subsys)) THEN
     456             :          CALL cp_subsys_get(nnp_env%subsys, &
     457             :                             atomic_kinds=atomic_kinds, &
     458             :                             particles=particles, &
     459             :                             molecule_kinds=molecule_kinds, &
     460             :                             molecules=molecules, &
     461             :                             local_molecules=local_molecules, &
     462             :                             local_particles=local_particles, &
     463             :                             virial=virial, &
     464       61078 :                             cell=cell)
     465             :       END IF
     466      502454 :       IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
     467      502454 :       IF (PRESENT(particle_set)) particle_set => particles%els
     468      502454 :       IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
     469      502454 :       IF (PRESENT(molecule_set)) molecule_set => molecules%els
     470             : 
     471      502454 :       IF (PRESENT(nnp_input)) nnp_input => nnp_env%nnp_input
     472      502454 :       IF (PRESENT(force_env_input)) force_env_input => nnp_env%force_env_input
     473      502454 :       IF (PRESENT(cell_ref)) cell_ref => nnp_env%cell_ref
     474      502454 :       IF (PRESENT(use_ref_cell)) use_ref_cell = nnp_env%use_ref_cell
     475             : 
     476      502454 :    END SUBROUTINE nnp_env_get
     477             : 
     478             : ! **************************************************************************************************
     479             : !> \brief Sets various attributes of the nnp environment
     480             : !> \param nnp_env ...
     481             : !> \param nnp_forces ...
     482             : !> \param subsys the particles, molecules,... of this environment
     483             : !> \param atomic_kind_set The set of all atomic kinds involved
     484             : !> \param particle_set The set of all particles
     485             : !> \param local_particles All particles on this particular node
     486             : !> \param molecule_kind_set The set of all different molecule kinds involved
     487             : !> \param molecule_set The set of all molecules
     488             : !> \param local_molecules All molecules on this particular node
     489             : !> \param nnp_input ...
     490             : !> \param force_env_input Pointer to the force_env input section
     491             : !> \param cell ...
     492             : !> \param cell_ref The reference simulation cell
     493             : !> \param use_ref_cell Logical which indicates if reference
     494             : !>                      simulation cell is used
     495             : !> \param nnp_potential_energy ...
     496             : !> \date   2020-10-10
     497             : !> \author Christoph Schran (christoph.schran@rub.de)
     498             : !> \note
     499             : !>   For possible missing arguments see the attributes of nnp_type
     500             : ! **************************************************************************************************
     501          30 :    SUBROUTINE nnp_env_set(nnp_env, nnp_forces, subsys, &
     502             :                           atomic_kind_set, particle_set, local_particles, &
     503             :                           molecule_kind_set, molecule_set, local_molecules, &
     504             :                           nnp_input, force_env_input, cell, cell_ref, &
     505             :                           use_ref_cell, nnp_potential_energy)
     506             : 
     507             :       TYPE(nnp_type), INTENT(INOUT)                      :: nnp_env
     508             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: nnp_forces
     509             :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: subsys
     510             :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     511             :          POINTER                                         :: atomic_kind_set
     512             :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     513             :          POINTER                                         :: particle_set
     514             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles
     515             :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     516             :          POINTER                                         :: molecule_kind_set
     517             :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     518             :          POINTER                                         :: molecule_set
     519             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_molecules
     520             :       TYPE(section_vals_type), OPTIONAL, POINTER         :: nnp_input, force_env_input
     521             :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell, cell_ref
     522             :       LOGICAL, INTENT(IN), OPTIONAL                      :: use_ref_cell
     523             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: nnp_potential_energy
     524             : 
     525             :       TYPE(atomic_kind_list_type), POINTER               :: atomic_kinds
     526             :       TYPE(molecule_kind_list_type), POINTER             :: molecule_kinds
     527             :       TYPE(molecule_list_type), POINTER                  :: molecules
     528             :       TYPE(particle_list_type), POINTER                  :: particles
     529             : 
     530          30 :       IF (PRESENT(nnp_potential_energy)) THEN
     531           0 :          nnp_env%nnp_potential_energy = nnp_potential_energy
     532             :       END IF
     533          30 :       IF (PRESENT(nnp_forces)) nnp_env%nnp_forces(:, :) = nnp_forces
     534             : 
     535          30 :       IF (PRESENT(subsys)) THEN
     536          14 :          IF (ASSOCIATED(nnp_env%subsys)) THEN
     537           0 :          IF (.NOT. ASSOCIATED(nnp_env%subsys, subsys)) THEN
     538           0 :             CALL cp_subsys_release(nnp_env%subsys)
     539             :          END IF
     540             :          END IF
     541          14 :          nnp_env%subsys => subsys
     542             :       END IF
     543          30 :       IF (PRESENT(cell)) THEN
     544           1 :          IF (ASSOCIATED(cell)) THEN
     545           1 :             CALL cell_retain(cell)
     546           1 :             CALL cell_release(nnp_env%cell)
     547           1 :             nnp_env%cell => cell
     548             :          END IF
     549           1 :          IF (ASSOCIATED(nnp_env%subsys)) THEN
     550           0 :             CALL cp_subsys_set(nnp_env%subsys, cell=cell)
     551             :          END IF
     552             :       END IF
     553          30 :       IF (PRESENT(atomic_kind_set)) THEN
     554           0 :          CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
     555           0 :          CALL cp_subsys_set(nnp_env%subsys, atomic_kinds=atomic_kinds)
     556           0 :          CALL atomic_kind_list_release(atomic_kinds)
     557             :       END IF
     558          30 :       IF (PRESENT(particle_set)) THEN
     559           0 :          CALL particle_list_create(particles, els_ptr=particle_set)
     560           0 :          CALL cp_subsys_set(nnp_env%subsys, particles=particles)
     561           0 :          CALL particle_list_release(particles)
     562             :       END IF
     563          30 :       IF (PRESENT(molecule_kind_set)) THEN
     564           0 :          CALL molecule_kind_list_create(molecule_kinds, els_ptr=molecule_kind_set)
     565           0 :          CALL cp_subsys_set(nnp_env%subsys, molecule_kinds=molecule_kinds)
     566           0 :          CALL molecule_kind_list_release(molecule_kinds)
     567             :       END IF
     568          30 :       IF (PRESENT(molecule_set)) THEN
     569           0 :          CALL molecule_list_create(molecules, els_ptr=molecule_set)
     570           0 :          CALL cp_subsys_set(nnp_env%subsys, molecules=molecules)
     571           0 :          CALL molecule_list_release(molecules)
     572             :       END IF
     573          30 :       IF (PRESENT(local_particles)) THEN
     574          14 :          CALL cp_subsys_set(nnp_env%subsys, local_particles=local_particles)
     575             :       END IF
     576          30 :       IF (PRESENT(local_molecules)) THEN
     577          14 :          CALL cp_subsys_set(nnp_env%subsys, local_molecules=local_molecules)
     578             :       END IF
     579             : 
     580          30 :       IF (PRESENT(nnp_input)) nnp_env%nnp_input => nnp_input
     581          30 :       IF (PRESENT(force_env_input)) THEN
     582          14 :          nnp_env%force_env_input => force_env_input
     583             :       END IF
     584          30 :       IF (PRESENT(cell_ref)) THEN
     585          14 :          CALL cell_retain(cell_ref)
     586          14 :          CALL cell_release(nnp_env%cell_ref)
     587          14 :          nnp_env%cell_ref => cell_ref
     588             :       END IF
     589          30 :       IF (PRESENT(use_ref_cell)) nnp_env%use_ref_cell = use_ref_cell
     590          30 :    END SUBROUTINE nnp_env_set
     591             : 
     592           0 : END MODULE nnp_environment_types

Generated by: LCOV version 1.15