LCOV - code coverage report
Current view: top level - src/subsys - colvar_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:24d69ee) Lines: 69.1 % 987 682
Test Date: 2026-09-03 07:32:15 Functions: 26.5 % 49 13

            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 Initialize the collective variables types
      10              : !> \par History
      11              : !>      5.2004 created [fawzi and alessandro]
      12              : !>      1.2009 Fabio Sterpone : added the population COLVAR
      13              : !> \author Teodoro Laino
      14              : ! **************************************************************************************************
      15              : MODULE colvar_types
      16              : 
      17              :    USE input_section_types,             ONLY: section_vals_type
      18              :    USE kinds,                           ONLY: default_path_length,&
      19              :                                               default_string_length,&
      20              :                                               dp
      21              :    USE particle_types,                  ONLY: particle_type
      22              : #include "../base/base_uses.f90"
      23              : 
      24              :    IMPLICIT NONE
      25              : 
      26              :    PRIVATE
      27              : 
      28              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'colvar_types'
      29              : 
      30              :    INTEGER, PARAMETER, PUBLIC               :: plane_def_atoms = 0, &
      31              :                                                plane_def_vec = 1
      32              : 
      33              :    INTEGER, PARAMETER, PUBLIC               :: do_clv_geo_center = 0, &
      34              :                                                do_clv_fix_point = 1, &
      35              :                                                do_clv_xyz = 0, &
      36              :                                                do_clv_x = 1, &
      37              :                                                do_clv_y = 2, &
      38              :                                                do_clv_z = 3, &
      39              :                                                do_clv_xy = 4, &
      40              :                                                do_clv_xz = 5, &
      41              :                                                do_clv_yz = 6
      42              :    PUBLIC :: colvar_type, &
      43              :              colvar_p_type, &
      44              :              colvar_p_reallocate, &
      45              :              colvar_p_release, &
      46              :              colvar_create, &
      47              :              colvar_clone, &
      48              :              colvar_setup, &
      49              :              colvar_release, &
      50              :              colvar_counters, &
      51              :              eval_point_der, &
      52              :              eval_point_pos, &
      53              :              eval_point_mass, &
      54              :              diff_colvar
      55              : 
      56              :    INTEGER, PARAMETER, PUBLIC :: no_colvar_id = -2, &
      57              :                                  dist_colvar_id = 1, &
      58              :                                  coord_colvar_id = 2, &
      59              :                                  torsion_colvar_id = 3, &
      60              :                                  angle_colvar_id = 4, &
      61              :                                  plane_distance_colvar_id = 5, &
      62              :                                  rotation_colvar_id = 6, &
      63              :                                  dfunct_colvar_id = 7, &
      64              :                                  qparm_colvar_id = 8, &
      65              :                                  hydronium_shell_colvar_id = 9, &
      66              :                                  reaction_path_colvar_id = 10, &
      67              :                                  combine_colvar_id = 11, &
      68              :                                  population_colvar_id = 12, &
      69              :                                  plane_plane_angle_colvar_id = 13, &
      70              :                                  gyration_colvar_id = 14, &
      71              :                                  rmsd_colvar_id = 15, &
      72              :                                  distance_from_path_colvar_id = 16, &
      73              :                                  xyz_diag_colvar_id = 17, &
      74              :                                  xyz_outerdiag_colvar_id = 18, &
      75              :                                  u_colvar_id = 19, &
      76              :                                  Wc_colvar_id = 20, &
      77              :                                  hbp_colvar_id = 21, &
      78              :                                  ring_puckering_colvar_id = 22, &
      79              :                                  mindist_colvar_id = 23, &
      80              :                                  acid_hyd_dist_colvar_id = 24, &
      81              :                                  acid_hyd_shell_colvar_id = 25, &
      82              :                                  hydronium_dist_colvar_id = 26, &
      83              :                                  voronoiipz_colvar_id = 27
      84              : 
      85              : ! **************************************************************************************************
      86              : !> \brief parameters for the distance collective variable
      87              : !> \param i_at ,j_at: indexes of the two atoms between which you calculate
      88              : !>        the distance
      89              : !> \author alessandro laio and fawzi mohamed
      90              : ! **************************************************************************************************
      91              :    TYPE dist_colvar_type
      92              :       INTEGER       :: i_at = 0, j_at = 0, axis_id = 0
      93              :       LOGICAL       :: sign_d = .FALSE.
      94              :    END TYPE dist_colvar_type
      95              : 
      96              : ! **************************************************************************************************
      97              :    TYPE coord_colvar_type
      98              :       LOGICAL                    :: do_chain = .FALSE., use_kinds_from = .FALSE., use_kinds_to = .FALSE., &
      99              :                                     use_kinds_to_b = .FALSE.
     100              :       INTEGER                         :: n_atoms_to = 0, &
     101              :                                          n_atoms_from = 0, &
     102              :                                          nncrd = 0, &
     103              :                                          ndcrd = 0, &
     104              :                                          n_atoms_to_b = 0, &
     105              :                                          nncrd_b = 0, &
     106              :                                          ndcrd_b = 0
     107              :       INTEGER, POINTER, DIMENSION(:) :: i_at_from => NULL(), &
     108              :                                         i_at_to => NULL(), &
     109              :                                         i_at_to_b => NULL()
     110              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: c_kinds_from => NULL(), &
     111              :                                                                      c_kinds_to => NULL(), &
     112              :                                                                      c_kinds_to_b => NULL()
     113              :       REAL(KIND=dp)                   :: r_0 = 0.0_dp, r_0_b = 0.0_dp
     114              :    END TYPE coord_colvar_type
     115              : 
     116              : ! **************************************************************************************************
     117              :    TYPE population_colvar_type
     118              :       LOGICAL                         :: use_kinds_from = .FALSE., use_kinds_to = .FALSE.
     119              :       INTEGER                         :: n_atoms_to = 0, &
     120              :                                          n_atoms_from = 0, &
     121              :                                          nncrd = 0, &
     122              :                                          ndcrd = 0, &
     123              :                                          n0 = 0
     124              :       INTEGER, POINTER, DIMENSION(:) :: i_at_from => NULL(), &
     125              :                                         i_at_to => NULL()
     126              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: c_kinds_from => NULL(), &
     127              :                                                                      c_kinds_to => NULL()
     128              :       REAL(KIND=dp)                   :: r_0 = 0.0_dp, sigma = 0.0_dp
     129              :    END TYPE population_colvar_type
     130              : 
     131              : ! **************************************************************************************************
     132              :    TYPE gyration_colvar_type
     133              :       LOGICAL                         :: use_kinds = .FALSE.
     134              :       INTEGER                         :: n_atoms = 0
     135              :       INTEGER, POINTER, DIMENSION(:) :: i_at => NULL()
     136              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: c_kinds => NULL()
     137              :    END TYPE gyration_colvar_type
     138              : 
     139              : ! **************************************************************************************************
     140              :    TYPE torsion_colvar_type
     141              :       REAL(KIND=dp)                   :: o0 = 0.0_dp
     142              :       INTEGER, DIMENSION(4)          :: i_at_tors = 0
     143              :    END TYPE torsion_colvar_type
     144              : 
     145              : ! **************************************************************************************************
     146              :    TYPE plane_distance_colvar_type
     147              :       LOGICAL               :: use_pbc = .FALSE.
     148              :       INTEGER, DIMENSION(3) :: plane = -1
     149              :       INTEGER               :: point = -1
     150              :    END TYPE plane_distance_colvar_type
     151              : 
     152              : ! **************************************************************************************************
     153              :    TYPE plane_def_type
     154              :       INTEGER                     :: type_of_def = -1
     155              :       INTEGER, DIMENSION(3)       :: points = 0
     156              :       REAL(KIND=dp), DIMENSION(3) :: normal_vec = 0.0_dp
     157              :    END TYPE plane_def_type
     158              : 
     159              :    TYPE plane_plane_angle_colvar_type
     160              :       TYPE(plane_def_type)        :: plane1 = plane_def_type(), plane2 = plane_def_type()
     161              :    END TYPE plane_plane_angle_colvar_type
     162              : 
     163              : ! **************************************************************************************************
     164              :    TYPE angle_colvar_type
     165              :       INTEGER, DIMENSION(3) :: i_at_angle = 0
     166              :    END TYPE angle_colvar_type
     167              : 
     168              : ! **************************************************************************************************
     169              :    TYPE rotation_colvar_type
     170              :       INTEGER :: i_at1_bond1 = 0, &
     171              :                  i_at2_bond1 = 0, &
     172              :                  i_at1_bond2 = 0, &
     173              :                  i_at2_bond2 = 0
     174              :    END TYPE rotation_colvar_type
     175              : 
     176              : ! **************************************************************************************************
     177              :    TYPE dfunct_colvar_type
     178              :       INTEGER, DIMENSION(4)         :: i_at_dfunct = 0
     179              :       LOGICAL                       :: use_pbc = .FALSE.
     180              :       REAL(KIND=dp)                 :: coeff = 0.0_dp
     181              :    END TYPE dfunct_colvar_type
     182              : 
     183              : ! **************************************************************************************************
     184              :    TYPE qparm_colvar_type
     185              :       INTEGER                         :: l = 0
     186              :       INTEGER                         :: n_atoms_to = 0, &
     187              :                                          n_atoms_from = 0
     188              :       INTEGER, POINTER, DIMENSION(:)  :: i_at_from => NULL(), &
     189              :                                          i_at_to => NULL()
     190              :       REAL(KIND=dp)                   :: rcut = 0.0_dp, rstart = 0.0_dp
     191              :       LOGICAL                         :: include_images = .FALSE.
     192              :    END TYPE qparm_colvar_type
     193              : 
     194              : ! **************************************************************************************************
     195              :    TYPE hydronium_shell_colvar_type
     196              :       INTEGER                         :: n_oxygens = -1, &
     197              :                                          n_hydrogens = -1, &
     198              :                                          poh = -1, qoh = -1, poo = -1, qoo = -1, &
     199              :                                          pm = -1, qm = -1
     200              :       INTEGER, POINTER, DIMENSION(:)  :: i_oxygens => NULL(), &
     201              :                                          i_hydrogens => NULL()
     202              :       REAL(KIND=dp)                   :: roo = 0.0_dp, roh = 0.0_dp, lambda = 0.0_dp, nh = 0.0_dp
     203              :    END TYPE hydronium_shell_colvar_type
     204              : 
     205              : ! **************************************************************************************************
     206              :    TYPE hydronium_dist_colvar_type
     207              :       INTEGER                         :: n_oxygens = -1, &
     208              :                                          n_hydrogens = -1, &
     209              :                                          poh = -1, qoh = -1, &
     210              :                                          pf = -1, qf = -1, pm = -1, qm = -1
     211              :       INTEGER, POINTER, DIMENSION(:)  :: i_oxygens => NULL(), &
     212              :                                          i_hydrogens => NULL()
     213              :       REAL(KIND=dp)                   :: roh = 0.0_dp, lambda = 0.0_dp, nh = 0.0_dp, nn = 0.0_dp
     214              :    END TYPE hydronium_dist_colvar_type
     215              : 
     216              : ! **************************************************************************************************
     217              :    TYPE acid_hyd_dist_colvar_type
     218              :       INTEGER                         :: n_oxygens_water = -1, &
     219              :                                          n_oxygens_acid = -1, &
     220              :                                          n_hydrogens = -1, &
     221              :                                          pwoh = -1, qwoh = -1, paoh = -1, qaoh = -1, pcut = -1, qcut = -1
     222              :       INTEGER, POINTER, DIMENSION(:)  :: i_oxygens_water => NULL(), i_oxygens_acid => NULL(), &
     223              :                                          i_hydrogens => NULL()
     224              :       REAL(KIND=dp)                   :: rwoh = 0.0_dp, raoh = 0.0_dp, lambda = 0.0_dp, nc = 0.0_dp
     225              :    END TYPE acid_hyd_dist_colvar_type
     226              : 
     227              : ! **************************************************************************************************
     228              :    TYPE voronoiipz_colvar_type
     229              :       INTEGER, DIMENSION(:), POINTER :: group_a => NULL(), group_b => NULL()
     230              :       INTEGER                        :: nrx = 0, zidx = 3
     231              :       REAL(KIND=dp)                  :: d0 = 2.0_dp, d1 = 2.0_dp, d2 = 2.0_dp, d3 = 2.0_dp, &
     232              :                                         lambda = -8.0_dp, nl_cutoff = 4.536862_dp, zmid = 0.0_dp
     233              :    END TYPE voronoiipz_colvar_type
     234              : 
     235              : ! **************************************************************************************************
     236              :    TYPE acid_hyd_shell_colvar_type
     237              :       INTEGER                         :: n_oxygens_water = -1, &
     238              :                                          n_oxygens_acid = -1, &
     239              :                                          n_hydrogens = -1, &
     240              :                                          pwoh = -1, qwoh = -1, paoh = -1, qaoh = -1, &
     241              :                                          poo = -1, qoo = -1, pcut = -1, qcut = -1, pm = -1, qm = -1
     242              :       INTEGER, POINTER, DIMENSION(:)  :: i_oxygens_water => NULL(), i_oxygens_acid => NULL(), &
     243              :                                          i_hydrogens => NULL()
     244              :       REAL(KIND=dp)                   :: rwoh = 0.0_dp, raoh = 0.0_dp, roo = 0.0_dp, lambda = 0.0_dp, nc = 0.0_dp, nh = 0.0_dp
     245              :    END TYPE acid_hyd_shell_colvar_type
     246              : 
     247              : ! **************************************************************************************************
     248              :    TYPE reaction_path_colvar_type
     249              :       INTEGER                                    :: type_id = -1
     250              :       INTEGER                                    :: n_components = -1, nr_frames = -1, subset = -1
     251              :       INTEGER, DIMENSION(2)                      :: function_bounds = -1
     252              :       INTEGER, POINTER, DIMENSION(:)             :: i_rmsd => NULL()
     253              :       LOGICAL                                    :: align_frames = .FALSE., dist_rmsd = .FALSE., rmsd = .FALSE.
     254              :       REAL(KIND=dp), DIMENSION(:, :), POINTER    :: f_vals => NULL()
     255              :       REAL(KIND=dp), DIMENSION(:, :), POINTER    :: r_ref => NULL()
     256              :       REAL(KIND=dp)                              :: lambda = 0.0_dp
     257              :       REAL(KIND=dp)                              :: step_size = 0.0_dp
     258              :       TYPE(colvar_p_type), POINTER, DIMENSION(:) :: colvar_p => NULL()
     259              :    END TYPE reaction_path_colvar_type
     260              : 
     261              : ! **************************************************************************************************
     262              :    TYPE combine_colvar_type
     263              :       INTEGER                                    :: type_id = -1
     264              :       TYPE(colvar_p_type), POINTER, DIMENSION(:) :: colvar_p => NULL()
     265              :       REAL(KIND=dp)                              :: lerr = 0.0_dp, dx = 0.0_dp
     266              :       CHARACTER(LEN=default_path_length)         :: FUNCTION = ""
     267              :       CHARACTER(LEN=default_string_length), &
     268              :          DIMENSION(:), POINTER                   :: c_parameters => NULL(), variables => NULL()
     269              :       REAL(KIND=dp), DIMENSION(:), POINTER       :: v_parameters => NULL()
     270              :    END TYPE combine_colvar_type
     271              : ! **************************************************************************************************
     272              :    TYPE rmsd_colvar_type
     273              :       INTEGER                                  :: n_atoms = 0, nr_frames = 0, subset = 0
     274              :       INTEGER, POINTER, DIMENSION(:)           :: i_rmsd => NULL()
     275              :       LOGICAL                                  :: align_frames = .FALSE.
     276              :       REAL(KIND=dp), DIMENSION(:), POINTER     :: weights => NULL()
     277              :       REAL(KIND=dp), DIMENSION(:, :), POINTER  :: r_ref => NULL()
     278              :    END TYPE rmsd_colvar_type
     279              : 
     280              : ! **************************************************************************************************
     281              :    TYPE point_type
     282              :       INTEGER :: type_id = -1
     283              :       INTEGER, DIMENSION(:), POINTER          :: atoms => NULL()
     284              :       REAL(KIND=dp), DIMENSION(:), POINTER    :: weights => NULL()
     285              :       REAL(KIND=dp), DIMENSION(3)             :: r = 0.0_dp
     286              :    END TYPE point_type
     287              : 
     288              : ! **************************************************************************************************
     289              :    TYPE xyz_diag_colvar_type
     290              :       LOGICAL                                  :: use_pbc = .FALSE.
     291              :       LOGICAL                                  :: use_absolute_position = .FALSE.
     292              :       INTEGER                                  :: i_atom = 0
     293              :       INTEGER                                  :: component = 0
     294              :       REAL(KIND=dp), DIMENSION(3)              :: r0 = 0.0_dp
     295              :    END TYPE xyz_diag_colvar_type
     296              : 
     297              : ! **************************************************************************************************
     298              :    TYPE xyz_outerdiag_colvar_type
     299              :       LOGICAL                                  :: use_pbc = .FALSE.
     300              :       INTEGER, DIMENSION(2)                    :: i_atoms = 0
     301              :       INTEGER, DIMENSION(2)                    :: components = 0
     302              :       REAL(KIND=dp), DIMENSION(3, 2)           :: r0 = 0.0_dp
     303              :    END TYPE xyz_outerdiag_colvar_type
     304              : 
     305              : ! **************************************************************************************************
     306              :    TYPE u_colvar_type
     307              :       TYPE(section_vals_type), POINTER         :: mixed_energy_section => NULL()
     308              :       INTEGER       :: natom = -1
     309              :    END TYPE u_colvar_type
     310              : 
     311              : ! **************************************************************************************************
     312              :    TYPE Wc_colvar_type
     313              :       INTEGER                         :: ids(3) = -1 ! first is the Od, second the H, third the Oa
     314              :       REAL(KIND=dp)                   :: ewc = 0.0_dp
     315              :       REAL(KIND=dp)                   :: rcut = 0.0_dp
     316              :    END TYPE Wc_colvar_type
     317              : 
     318              : ! **************************************************************************************************
     319              :    TYPE HBP_colvar_type
     320              :       INTEGER                         :: nPoints = -1 ! number of the points in the path
     321              :       INTEGER, POINTER                :: ids(:, :) => NULL() ! first is the Od, second the H,
     322              :       ! third the Oa and contains a row for each intermediate point in the path
     323              :       REAL(KIND=dp), POINTER          :: ewc(:) => NULL() ! one for each point in the path
     324              :       REAL(KIND=dp)                   :: rcut = 0.0_dp
     325              :       REAL(KIND=dp)                   :: shift = 0.0_dp ! shift applied for each term in the collective variable
     326              :    END TYPE HBP_colvar_type
     327              : 
     328              : ! **************************************************************************************************
     329              :    TYPE ring_puckering_colvar_type
     330              :       INTEGER                         :: nring = -1
     331              :       INTEGER, POINTER, DIMENSION(:) :: atoms => NULL()
     332              :       INTEGER                         :: iq = -1
     333              :    END TYPE ring_puckering_colvar_type
     334              : 
     335              : ! **************************************************************************************************
     336              :    TYPE mindist_colvar_type
     337              :       LOGICAL                         :: use_kinds_from = .FALSE., use_kinds_to = .FALSE.
     338              :       INTEGER                         :: n_coord_to = 0, &
     339              :                                          n_coord_from = 0, &
     340              :                                          n_dist_from = 0, &
     341              :                                          p_exp = 0, &
     342              :                                          q_exp = 0
     343              :       INTEGER, POINTER, DIMENSION(:)  :: i_coord_from => NULL(), &
     344              :                                          i_coord_to => NULL(), &
     345              :                                          i_dist_from => NULL()
     346              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: k_coord_from => NULL(), &
     347              :                                                                      k_coord_to => NULL()
     348              :       REAL(KIND=dp)                   :: lambda = 0.0_dp, r_cut = 0.0_dp
     349              :    END TYPE mindist_colvar_type
     350              : 
     351              : ! **************************************************************************************************
     352              : !> \brief parameters for a collective variable
     353              : !> \author alessandro laio and fawzi mohamed
     354              : ! **************************************************************************************************
     355              :    TYPE colvar_type
     356              :       INTEGER                                     :: type_id = -1
     357              :       LOGICAL                                     :: use_points = .FALSE.
     358              :       REAL(kind=dp)                               :: ss = 0.0_dp ! Value of the colvar
     359              :       REAL(kind=dp), DIMENSION(:, :), POINTER     :: dsdr => NULL() ! Derivative of colvar (3,:)
     360              :       INTEGER, DIMENSION(:), POINTER              :: i_atom => NULL() ! Mapping of dsdr
     361              :       INTEGER                                     :: n_atom_s = -1
     362              :       ! Available COLVAR types
     363              :       TYPE(dist_colvar_type), POINTER              :: dist_param => NULL()
     364              :       TYPE(coord_colvar_type), POINTER             :: coord_param => NULL()
     365              :       TYPE(population_colvar_type), POINTER        :: population_param => NULL()
     366              :       TYPE(gyration_colvar_type), POINTER          :: gyration_param => NULL()
     367              :       TYPE(torsion_colvar_type), POINTER           :: torsion_param => NULL()
     368              :       TYPE(angle_colvar_type), POINTER             :: angle_param => NULL()
     369              :       TYPE(plane_distance_colvar_type), POINTER    :: plane_distance_param => NULL()
     370              :       TYPE(plane_plane_angle_colvar_type), POINTER :: plane_plane_angle_param => NULL()
     371              :       TYPE(rotation_colvar_type), POINTER          :: rotation_param => NULL()
     372              :       TYPE(dfunct_colvar_type), POINTER            :: dfunct_param => NULL()
     373              :       TYPE(qparm_colvar_type), POINTER             :: qparm_param => NULL()
     374              :       TYPE(hydronium_shell_colvar_type), POINTER   :: hydronium_shell_param => NULL()
     375              :       TYPE(hydronium_dist_colvar_type), POINTER    :: hydronium_dist_param => NULL()
     376              :       TYPE(acid_hyd_dist_colvar_type), POINTER     :: acid_hyd_dist_param => NULL()
     377              :       TYPE(acid_hyd_shell_colvar_type), POINTER    :: acid_hyd_shell_param => NULL()
     378              :       TYPE(reaction_path_colvar_type), POINTER     :: reaction_path_param => NULL()
     379              :       TYPE(combine_colvar_type), POINTER           :: combine_cvs_param => NULL()
     380              :       TYPE(rmsd_colvar_type), POINTER              :: rmsd_param => NULL()
     381              :       TYPE(xyz_diag_colvar_type), POINTER          :: xyz_diag_param => NULL()
     382              :       TYPE(xyz_outerdiag_colvar_type), POINTER     :: xyz_outerdiag_param => NULL()
     383              :       TYPE(u_colvar_type), POINTER                 :: u_param => NULL()
     384              :       TYPE(point_type), DIMENSION(:), POINTER      :: points => NULL()
     385              :       TYPE(Wc_colvar_type), POINTER                :: Wc => NULL()
     386              :       TYPE(HBP_colvar_type), POINTER               :: HBP => NULL()
     387              :       TYPE(ring_puckering_colvar_type), POINTER    :: ring_puckering_param => NULL()
     388              :       TYPE(mindist_colvar_type), POINTER           :: mindist_param => NULL()
     389              :       TYPE(voronoiipz_colvar_type), POINTER        :: voronoiipz_params => NULL()
     390              :    END TYPE colvar_type
     391              : 
     392              : ! **************************************************************************************************
     393              :    TYPE colvar_p_type
     394              :       TYPE(colvar_type), POINTER :: colvar => NULL()
     395              :    END TYPE colvar_p_type
     396              : 
     397              : ! **************************************************************************************************
     398              :    TYPE colvar_counters
     399              :       INTEGER :: ndist = 0
     400              :       INTEGER :: nangle = 0
     401              :       INTEGER :: ntorsion = 0
     402              :       INTEGER :: ncoord = 0
     403              :       INTEGER :: nplane_dist = 0
     404              :       INTEGER :: nplane_angle = 0
     405              :       INTEGER :: nrot = 0
     406              :       INTEGER :: ndfunct = 0
     407              :       INTEGER :: nqparm = 0
     408              :       INTEGER :: nhydronium_shell = 0
     409              :       INTEGER :: nhydronium_dist = 0
     410              :       INTEGER :: nacid_hyd_dist = 0
     411              :       INTEGER :: nacid_hyd_shell = 0
     412              :       INTEGER :: nreactionpath = 0
     413              :       INTEGER :: ncombinecvs = 0
     414              :       INTEGER :: nrestraint = 0
     415              :       INTEGER :: npopulation = 0
     416              :       INTEGER :: ngyration = 0
     417              :       INTEGER :: nxyz_diag = 0
     418              :       INTEGER :: nxyz_outerdiag = 0
     419              :       INTEGER :: nvoronoiipz = 0
     420              :       INTEGER :: ntot = 0
     421              :    END TYPE colvar_counters
     422              : 
     423              : CONTAINS
     424              : 
     425              : ! **************************************************************************************************
     426              : !> \brief initializes a colvar_param type
     427              : !> \param colvar the colvat to initialize
     428              : !> \param colvar_id ...
     429              : !> \author alessandro laio and fawzi mohamed
     430              : ! **************************************************************************************************
     431         5694 :    SUBROUTINE colvar_create(colvar, colvar_id)
     432              :       TYPE(colvar_type), POINTER                         :: colvar
     433              :       INTEGER, INTENT(in)                                :: colvar_id
     434              : 
     435         5694 :       CPASSERT(.NOT. ASSOCIATED(colvar))
     436         5694 :       ALLOCATE (colvar)
     437         5694 :       colvar%type_id = colvar_id
     438              :       colvar%use_points = .FALSE.
     439         5000 :       SELECT CASE (colvar_id)
     440              :       CASE (dist_colvar_id)
     441         5000 :          ALLOCATE (colvar%dist_param)
     442              :          colvar%dist_param%axis_id = do_clv_xyz
     443         5000 :          colvar%dist_param%sign_d = .FALSE.
     444              :       CASE (coord_colvar_id)
     445           64 :          ALLOCATE (colvar%coord_param)
     446              :       CASE (population_colvar_id)
     447            8 :          ALLOCATE (colvar%population_param)
     448              :       CASE (gyration_colvar_id)
     449            2 :          ALLOCATE (colvar%gyration_param)
     450              :       CASE (angle_colvar_id)
     451         1100 :          ALLOCATE (colvar%angle_param)
     452              :       CASE (torsion_colvar_id)
     453          972 :          ALLOCATE (colvar%torsion_param)
     454              :       CASE (plane_distance_colvar_id)
     455          140 :          ALLOCATE (colvar%plane_distance_param)
     456              :       CASE (plane_plane_angle_colvar_id)
     457          272 :          ALLOCATE (colvar%plane_plane_angle_param)
     458              :       CASE (rotation_colvar_id)
     459            2 :          ALLOCATE (colvar%rotation_param)
     460              :       CASE (dfunct_colvar_id)
     461          108 :          ALLOCATE (colvar%dfunct_param)
     462              :       CASE (qparm_colvar_id)
     463            2 :          ALLOCATE (colvar%qparm_param)
     464              :       CASE (xyz_diag_colvar_id)
     465          150 :          ALLOCATE (colvar%xyz_diag_param)
     466              :          ! Initialize r0 with dummy..
     467          120 :          colvar%xyz_diag_param%r0 = HUGE(0.0_dp)
     468              :       CASE (xyz_outerdiag_colvar_id)
     469          480 :          ALLOCATE (colvar%xyz_outerdiag_param)
     470              :          ! Initialize r0 with dummy..
     471          270 :          colvar%xyz_outerdiag_param%r0 = HUGE(0.0_dp)
     472              :       CASE (u_colvar_id)
     473            6 :          ALLOCATE (colvar%u_param)
     474            6 :          NULLIFY (colvar%u_param%mixed_energy_section)
     475              :       CASE (hydronium_shell_colvar_id)
     476            2 :          ALLOCATE (colvar%hydronium_shell_param)
     477              :       CASE (hydronium_dist_colvar_id)
     478            2 :          ALLOCATE (colvar%hydronium_dist_param)
     479              :       CASE (acid_hyd_dist_colvar_id)
     480            2 :          ALLOCATE (colvar%acid_hyd_dist_param)
     481              :       CASE (acid_hyd_shell_colvar_id)
     482            2 :          ALLOCATE (colvar%acid_hyd_shell_param)
     483              :       CASE (reaction_path_colvar_id)
     484           80 :          ALLOCATE (colvar%reaction_path_param)
     485              :       CASE (distance_from_path_colvar_id)
     486           32 :          ALLOCATE (colvar%reaction_path_param)
     487              :       CASE (combine_colvar_id)
     488           20 :          ALLOCATE (colvar%combine_cvs_param)
     489              :       CASE (rmsd_colvar_id)
     490            4 :          ALLOCATE (colvar%rmsd_param)
     491              :       CASE (Wc_colvar_id)
     492            0 :          ALLOCATE (colvar%Wc)
     493              :       CASE (HBP_colvar_id)
     494            2 :          ALLOCATE (colvar%HBP)
     495              :       CASE (ring_puckering_colvar_id)
     496           36 :          ALLOCATE (colvar%ring_puckering_param)
     497              :       CASE (mindist_colvar_id)
     498            0 :          ALLOCATE (colvar%mindist_param)
     499              :       CASE (voronoiipz_colvar_id)
     500            8 :          ALLOCATE (colvar%voronoiipz_params)
     501              :       CASE (no_colvar_id)
     502              :          ! Do nothing
     503              :       CASE DEFAULT
     504         5694 :          CPABORT("Unknown colvar type")
     505              :       END SELECT
     506              : 
     507         5694 :    END SUBROUTINE colvar_create
     508              : 
     509              : ! **************************************************************************************************
     510              : !> \brief Finalize the setup of the collective variable
     511              : !> \param colvar the colvar to initialize
     512              : !> \author Teodoro Laino, [teo] 09.03.2006
     513              : ! **************************************************************************************************
     514         5742 :    SUBROUTINE colvar_setup(colvar)
     515              :       TYPE(colvar_type), INTENT(INOUT)                   :: colvar
     516              : 
     517              :       INTEGER                                            :: i, idum, iend, ii, istart, j, np
     518         5742 :       INTEGER, DIMENSION(:), POINTER                     :: list
     519              : 
     520        10742 :       SELECT CASE (colvar%type_id)
     521              :       CASE (dist_colvar_id)
     522         5000 :          np = 2
     523         5000 :          i = colvar%dist_param%i_at
     524         5000 :          j = colvar%dist_param%j_at
     525              :          ! Number of real atoms involved in the colvar
     526              :          colvar%n_atom_s = COLV_SIZE(colvar, i) + &
     527         5000 :                            COLV_SIZE(colvar, j)
     528              :          ! Create a List of points...
     529         5000 :          ALLOCATE (list(np))
     530         5000 :          list(1) = colvar%dist_param%i_at
     531         5000 :          list(2) = colvar%dist_param%j_at
     532              :       CASE (coord_colvar_id)
     533              :          np = colvar%coord_param%n_atoms_from + colvar%coord_param%n_atoms_to &
     534           74 :               + colvar%coord_param%n_atoms_to_b
     535              :          ! Number of real atoms involved in the colvar
     536           74 :          colvar%n_atom_s = 0
     537          142 :          DO ii = 1, colvar%coord_param%n_atoms_from
     538           68 :             i = colvar%coord_param%i_at_from(ii)
     539          142 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     540              :          END DO
     541          182 :          DO ii = 1, colvar%coord_param%n_atoms_to
     542          108 :             i = colvar%coord_param%i_at_to(ii)
     543          182 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     544              :          END DO
     545           74 :          IF (colvar%coord_param%n_atoms_to_b /= 0) THEN
     546            8 :             DO ii = 1, colvar%coord_param%n_atoms_to_b
     547            4 :                i = colvar%coord_param%i_at_to_b(ii)
     548            8 :                colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     549              :             END DO
     550              :          END IF
     551              :          ! Create a List of points...
     552          214 :          ALLOCATE (list(np))
     553           74 :          idum = 0
     554          142 :          DO ii = 1, colvar%coord_param%n_atoms_from
     555           68 :             idum = idum + 1
     556           68 :             i = colvar%coord_param%i_at_from(ii)
     557          142 :             list(idum) = i
     558              :          END DO
     559          182 :          DO ii = 1, colvar%coord_param%n_atoms_to
     560          108 :             idum = idum + 1
     561          108 :             i = colvar%coord_param%i_at_to(ii)
     562          182 :             list(idum) = i
     563              :          END DO
     564           74 :          IF (colvar%coord_param%n_atoms_to_b /= 0) THEN
     565            8 :             DO ii = 1, colvar%coord_param%n_atoms_to_b
     566            4 :                idum = idum + 1
     567            4 :                i = colvar%coord_param%i_at_to_b(ii)
     568            8 :                list(idum) = i
     569              :             END DO
     570              :          END IF
     571           74 :          CPASSERT(idum == np)
     572              :       CASE (population_colvar_id)
     573           16 :          np = colvar%population_param%n_atoms_from + colvar%population_param%n_atoms_to
     574              :          ! Number of real atoms involved in the colvar
     575           16 :          colvar%n_atom_s = 0
     576           32 :          DO ii = 1, colvar%population_param%n_atoms_from
     577           16 :             i = colvar%population_param%i_at_from(ii)
     578           32 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     579              :          END DO
     580           32 :          DO ii = 1, colvar%population_param%n_atoms_to
     581           16 :             i = colvar%population_param%i_at_to(ii)
     582           32 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     583              :          END DO
     584              :          ! Create a List of points...
     585           48 :          ALLOCATE (list(np))
     586           16 :          idum = 0
     587           32 :          DO ii = 1, colvar%population_param%n_atoms_from
     588           16 :             idum = idum + 1
     589           16 :             i = colvar%population_param%i_at_from(ii)
     590           32 :             list(idum) = i
     591              :          END DO
     592           32 :          DO ii = 1, colvar%population_param%n_atoms_to
     593           16 :             idum = idum + 1
     594           16 :             i = colvar%population_param%i_at_to(ii)
     595           32 :             list(idum) = i
     596              :          END DO
     597           16 :          CPASSERT(idum == np)
     598              :       CASE (gyration_colvar_id)
     599            4 :          np = colvar%gyration_param%n_atoms
     600              :          ! Number of real atoms involved in the colvar
     601            4 :          colvar%n_atom_s = 0
     602           30 :          DO ii = 1, colvar%gyration_param%n_atoms
     603           26 :             i = colvar%gyration_param%i_at(ii)
     604           30 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     605              :          END DO
     606              :          ! Create a List of points...
     607           10 :          ALLOCATE (list(np))
     608            4 :          idum = 0
     609           30 :          DO ii = 1, colvar%gyration_param%n_atoms
     610           26 :             idum = idum + 1
     611           26 :             i = colvar%gyration_param%i_at(ii)
     612           30 :             list(idum) = i
     613              :          END DO
     614            4 :          CPASSERT(idum == np)
     615              :       CASE (angle_colvar_id)
     616          220 :          np = 3
     617              :          ! Number of real atoms involved in the colvar
     618          220 :          colvar%n_atom_s = 0
     619          880 :          DO ii = 1, 3
     620          660 :             i = colvar%angle_param%i_at_angle(ii)
     621          880 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     622              :          END DO
     623              :          ! Create a List of points...
     624          220 :          ALLOCATE (list(np))
     625          220 :          idum = 0
     626          880 :          DO ii = 1, 3
     627          660 :             idum = idum + 1
     628          660 :             i = colvar%angle_param%i_at_angle(ii)
     629          880 :             list(idum) = i
     630              :          END DO
     631          220 :          CPASSERT(idum == np)
     632              :       CASE (torsion_colvar_id)
     633          162 :          np = 4
     634              :          ! Number of real atoms involved in the colvar
     635          162 :          colvar%n_atom_s = 0
     636          810 :          DO ii = 1, 4
     637          648 :             i = colvar%torsion_param%i_at_tors(ii)
     638          810 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     639              :          END DO
     640              :          ! Create a List of points...
     641          162 :          ALLOCATE (list(np))
     642          162 :          idum = 0
     643          810 :          DO ii = 1, 4
     644          648 :             idum = idum + 1
     645          648 :             i = colvar%torsion_param%i_at_tors(ii)
     646          810 :             list(idum) = i
     647              :          END DO
     648          162 :          CPASSERT(idum == np)
     649              :       CASE (plane_distance_colvar_id)
     650           28 :          np = 4
     651              :          ! Number of real atoms involved in the colvar
     652           28 :          colvar%n_atom_s = 0
     653          112 :          DO ii = 1, 3
     654           84 :             i = colvar%plane_distance_param%plane(ii)
     655          112 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     656              :          END DO
     657           28 :          i = colvar%plane_distance_param%point
     658           28 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     659              :          ! Create a List of points...
     660           28 :          ALLOCATE (list(np))
     661           28 :          idum = 0
     662          112 :          DO ii = 1, 3
     663           84 :             idum = idum + 1
     664           84 :             i = colvar%plane_distance_param%plane(ii)
     665          112 :             list(idum) = i
     666              :          END DO
     667           28 :          i = colvar%plane_distance_param%point
     668           28 :          list(4) = i
     669           28 :          idum = idum + 1
     670           28 :          CPASSERT(idum == np)
     671              :       CASE (plane_plane_angle_colvar_id)
     672           16 :          np = 0
     673           16 :          IF (colvar%plane_plane_angle_param%plane1%type_of_def == plane_def_atoms) np = np + 3
     674           16 :          IF (colvar%plane_plane_angle_param%plane2%type_of_def == plane_def_atoms) np = np + 3
     675              :          ! if np is equal to zero this means that this is not a COLLECTIVE variable..
     676            8 :          IF (np == 0) THEN
     677              :             CALL cp_abort(__LOCATION__, &
     678              :                           "PLANE_PLANE_ANGLE Colvar defined using two normal vectors! This is "// &
     679              :                           "not a COLLECTIVE VARIABLE! One of the two planes must be defined "// &
     680            0 :                           "using atomic positions.")
     681              :          END IF
     682              : 
     683              :          ! Number of real atoms involved in the colvar
     684           16 :          colvar%n_atom_s = 0
     685           16 :          IF (colvar%plane_plane_angle_param%plane1%type_of_def == plane_def_atoms) THEN
     686           64 :             DO ii = 1, 3
     687           48 :                i = colvar%plane_plane_angle_param%plane1%points(ii)
     688           64 :                colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     689              :             END DO
     690              :          END IF
     691           16 :          IF (colvar%plane_plane_angle_param%plane2%type_of_def == plane_def_atoms) THEN
     692           32 :             DO ii = 1, 3
     693           24 :                i = colvar%plane_plane_angle_param%plane2%points(ii)
     694           32 :                colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     695              :             END DO
     696              :          END IF
     697              : 
     698              :          ! Create a List of points...
     699           32 :          ALLOCATE (list(np))
     700           16 :          idum = 0
     701           16 :          IF (colvar%plane_plane_angle_param%plane1%type_of_def == plane_def_atoms) THEN
     702           64 :             DO ii = 1, 3
     703           48 :                idum = idum + 1
     704           48 :                i = colvar%plane_plane_angle_param%plane1%points(ii)
     705           64 :                list(idum) = i
     706              :             END DO
     707              :          END IF
     708           16 :          IF (colvar%plane_plane_angle_param%plane2%type_of_def == plane_def_atoms) THEN
     709           32 :             DO ii = 1, 3
     710           24 :                idum = idum + 1
     711           24 :                i = colvar%plane_plane_angle_param%plane2%points(ii)
     712           32 :                list(idum) = i
     713              :             END DO
     714              :          END IF
     715           16 :          CPASSERT(idum == np)
     716              :       CASE (dfunct_colvar_id)
     717           18 :          np = 4
     718              :          ! Number of real atoms involved in the colvar
     719           18 :          colvar%n_atom_s = 0
     720           90 :          DO ii = 1, 4
     721           72 :             i = colvar%dfunct_param%i_at_dfunct(ii)
     722           90 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     723              :          END DO
     724              :          ! Create a List of points...
     725           18 :          ALLOCATE (list(np))
     726           18 :          idum = 0
     727           90 :          DO ii = 1, 4
     728           72 :             idum = idum + 1
     729           72 :             i = colvar%dfunct_param%i_at_dfunct(ii)
     730           90 :             list(idum) = i
     731              :          END DO
     732           18 :          CPASSERT(idum == np)
     733              :       CASE (rotation_colvar_id)
     734            2 :          np = 4
     735              :          ! Number of real atoms involved in the colvar
     736            2 :          colvar%n_atom_s = 0
     737            2 :          i = colvar%rotation_param%i_at1_bond1
     738            2 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     739            2 :          i = colvar%rotation_param%i_at2_bond1
     740            2 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     741            2 :          i = colvar%rotation_param%i_at1_bond2
     742            2 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     743            2 :          i = colvar%rotation_param%i_at2_bond2
     744            2 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     745              :          ! Create a List of points...
     746            2 :          ALLOCATE (list(np))
     747              :          i = colvar%rotation_param%i_at1_bond1
     748            2 :          list(1) = i
     749            2 :          i = colvar%rotation_param%i_at2_bond1
     750            2 :          list(2) = i
     751            2 :          i = colvar%rotation_param%i_at1_bond2
     752            2 :          list(3) = i
     753            2 :          i = colvar%rotation_param%i_at2_bond2
     754            2 :          list(4) = i
     755              :       CASE (qparm_colvar_id)
     756            2 :          np = colvar%qparm_param%n_atoms_from + colvar%qparm_param%n_atoms_to
     757              :          ! Number of real atoms involved in the colvar
     758            2 :          colvar%n_atom_s = 0
     759          218 :          DO ii = 1, colvar%qparm_param%n_atoms_from
     760          216 :             i = colvar%qparm_param%i_at_from(ii)
     761          218 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     762              :          END DO
     763          218 :          DO ii = 1, colvar%qparm_param%n_atoms_to
     764          216 :             i = colvar%qparm_param%i_at_to(ii)
     765          218 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     766              :          END DO
     767              :          ! Create a List of points...
     768            6 :          ALLOCATE (list(np))
     769            2 :          idum = 0
     770          218 :          DO ii = 1, colvar%qparm_param%n_atoms_from
     771          216 :             idum = idum + 1
     772          216 :             i = colvar%qparm_param%i_at_from(ii)
     773          218 :             list(idum) = i
     774              :          END DO
     775          218 :          DO ii = 1, colvar%qparm_param%n_atoms_to
     776          216 :             idum = idum + 1
     777          216 :             i = colvar%qparm_param%i_at_to(ii)
     778          218 :             list(idum) = i
     779              :          END DO
     780            2 :          CPASSERT(idum == np)
     781              :       CASE (hydronium_shell_colvar_id)
     782            2 :          np = colvar%hydronium_shell_param%n_oxygens + colvar%hydronium_shell_param%n_hydrogens
     783            6 :          ALLOCATE (list(np))
     784            2 :          CALL setup_hydronium_colvars(colvar, hydronium_shell_colvar_id, list)
     785              :       CASE (hydronium_dist_colvar_id)
     786            2 :          np = colvar%hydronium_dist_param%n_oxygens + colvar%hydronium_dist_param%n_hydrogens
     787            6 :          ALLOCATE (list(np))
     788            2 :          CALL setup_hydronium_colvars(colvar, hydronium_dist_colvar_id, list)
     789              :       CASE (acid_hyd_dist_colvar_id)
     790              :          np = colvar%acid_hyd_dist_param%n_oxygens_water &
     791              :               + colvar%acid_hyd_dist_param%n_oxygens_acid &
     792            2 :               + colvar%acid_hyd_dist_param%n_hydrogens
     793            6 :          ALLOCATE (list(np))
     794            2 :          CALL setup_acid_hydronium_colvars(colvar, acid_hyd_dist_colvar_id, list)
     795              :       CASE (acid_hyd_shell_colvar_id)
     796              :          np = colvar%acid_hyd_shell_param%n_oxygens_water &
     797              :               + colvar%acid_hyd_shell_param%n_oxygens_acid &
     798            2 :               + colvar%acid_hyd_shell_param%n_hydrogens
     799            6 :          ALLOCATE (list(np))
     800            2 :          CALL setup_acid_hydronium_colvars(colvar, acid_hyd_shell_colvar_id, list)
     801              :       CASE (rmsd_colvar_id)
     802            4 :          np = colvar%rmsd_param%n_atoms
     803              :          ! Number of real atoms involved in the colvar
     804            4 :          colvar%n_atom_s = 0
     805           28 :          DO ii = 1, colvar%rmsd_param%n_atoms
     806           24 :             i = colvar%rmsd_param%i_rmsd(ii)
     807           28 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     808              :          END DO
     809              :          ! Create a List of points...
     810           12 :          ALLOCATE (list(np))
     811            4 :          idum = 0
     812           28 :          DO ii = 1, colvar%rmsd_param%n_atoms
     813           24 :             idum = idum + 1
     814           24 :             i = colvar%rmsd_param%i_rmsd(ii)
     815           28 :             list(idum) = i
     816              :          END DO
     817              :       CASE (reaction_path_colvar_id, distance_from_path_colvar_id)
     818           44 :          colvar%n_atom_s = 0
     819           44 :          IF (colvar%reaction_path_param%dist_rmsd .OR. colvar%reaction_path_param%rmsd) THEN
     820            8 :             colvar%n_atom_s = colvar%reaction_path_param%n_components
     821              :          ELSE
     822          100 :             DO ii = 1, SIZE(colvar%reaction_path_param%colvar_p)
     823          100 :                colvar%n_atom_s = colvar%n_atom_s + colvar%reaction_path_param%colvar_p(ii)%colvar%n_atom_s
     824              :             END DO
     825              :          END IF
     826          132 :          ALLOCATE (list(colvar%n_atom_s))
     827           44 :          idum = 0
     828           44 :          IF (colvar%reaction_path_param%dist_rmsd .OR. colvar%reaction_path_param%rmsd) THEN
     829           80 :             DO ii = 1, SIZE(colvar%reaction_path_param%i_rmsd)
     830           72 :                idum = idum + 1
     831           72 :                i = colvar%reaction_path_param%i_rmsd(ii)
     832           80 :                list(idum) = i
     833              :             END DO
     834              :          ELSE
     835          100 :             DO ii = 1, SIZE(colvar%reaction_path_param%colvar_p)
     836          232 :                DO j = 1, colvar%reaction_path_param%colvar_p(ii)%colvar%n_atom_s
     837          132 :                   idum = idum + 1
     838          196 :                   list(idum) = colvar%reaction_path_param%colvar_p(ii)%colvar%i_atom(j)
     839              :                END DO
     840              :             END DO
     841              :          END IF
     842              :       CASE (xyz_diag_colvar_id)
     843           30 :          np = 1
     844              :          ! Number of real atoms involved in the colvar
     845           30 :          colvar%n_atom_s = 0
     846           30 :          i = colvar%xyz_diag_param%i_atom
     847           30 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     848              :          ! Create a List of points...
     849           30 :          ALLOCATE (list(np))
     850              :          i = colvar%xyz_diag_param%i_atom
     851           30 :          list(1) = i
     852              :       CASE (xyz_outerdiag_colvar_id)
     853           30 :          np = 2
     854              :          ! Number of real atoms involved in the colvar
     855           30 :          colvar%n_atom_s = 0
     856           30 :          i = colvar%xyz_outerdiag_param%i_atoms(1)
     857           30 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     858           30 :          i = colvar%xyz_outerdiag_param%i_atoms(2)
     859           30 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     860              :          ! Create a List of points...
     861           30 :          ALLOCATE (list(np))
     862              :          i = colvar%xyz_outerdiag_param%i_atoms(1)
     863           30 :          list(1) = i
     864           30 :          i = colvar%xyz_outerdiag_param%i_atoms(2)
     865           30 :          list(2) = i
     866              :       CASE (u_colvar_id)
     867            6 :          np = 1
     868            6 :          ALLOCATE (list(np))
     869            6 :          colvar%n_atom_s = np; list(1) = 1
     870              :       CASE (Wc_colvar_id)
     871            0 :          np = 3
     872              :          ! Number of real atoms involved in the colvar
     873            0 :          colvar%n_atom_s = 0
     874            0 :          DO ii = 1, 3
     875            0 :             i = colvar%Wc%ids(ii)
     876            0 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     877              :          END DO
     878              :          ! Create a List of points...
     879            0 :          ALLOCATE (list(np))
     880            0 :          idum = 0
     881            0 :          DO ii = 1, 3
     882            0 :             idum = idum + 1
     883            0 :             i = colvar%Wc%ids(ii)
     884            0 :             list(idum) = i
     885              :          END DO
     886            0 :          CPASSERT(idum == np)
     887              :       CASE (HBP_colvar_id)
     888            2 :          np = 3*colvar%HBP%nPoints
     889              :          ! Number of real atoms involved in the colvar
     890            2 :          colvar%n_atom_s = 0
     891            4 :          DO j = 1, colvar%HBP%nPoints
     892           10 :             DO ii = 1, 3
     893            6 :                i = colvar%HBP%ids(j, ii)
     894            8 :                colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     895              :             END DO
     896              :          END DO
     897              :          ! Create a List of points...
     898            6 :          ALLOCATE (list(np))
     899            2 :          idum = 0
     900            4 :          DO j = 1, colvar%HBP%nPoints
     901           10 :             DO ii = 1, 3
     902            6 :                idum = idum + 1
     903            6 :                i = colvar%HBP%ids(j, ii)
     904            8 :                list(idum) = i
     905              :             END DO
     906              :          END DO
     907            2 :          CPASSERT(idum == np)
     908              :       CASE (ring_puckering_colvar_id)
     909           36 :          np = colvar%ring_puckering_param%nring
     910              :          ! Number of real atoms involved in the colvar
     911           36 :          colvar%n_atom_s = 0
     912          238 :          DO ii = 1, colvar%ring_puckering_param%nring
     913          202 :             i = colvar%ring_puckering_param%atoms(ii)
     914          238 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     915              :          END DO
     916              :          ! Create a List of points...
     917          108 :          ALLOCATE (list(np))
     918           36 :          idum = 0
     919          238 :          DO ii = 1, colvar%ring_puckering_param%nring
     920          202 :             idum = idum + 1
     921          202 :             i = colvar%ring_puckering_param%atoms(ii)
     922          238 :             list(idum) = i
     923              :          END DO
     924           36 :          CPASSERT(idum == np)
     925              :       CASE (mindist_colvar_id)
     926              :          np = colvar%mindist_param%n_dist_from + &
     927            0 :               colvar%mindist_param%n_coord_from + colvar%mindist_param%n_coord_to
     928              :          ! Number of real atoms involved in the colvar
     929            0 :          colvar%n_atom_s = 0
     930            0 :          DO ii = 1, colvar%mindist_param%n_dist_from
     931            0 :             i = colvar%mindist_param%i_dist_from(ii)
     932            0 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     933              :          END DO
     934            0 :          DO ii = 1, colvar%mindist_param%n_coord_from
     935            0 :             i = colvar%mindist_param%i_coord_from(ii)
     936            0 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     937              :          END DO
     938            0 :          DO ii = 1, colvar%mindist_param%n_coord_to
     939            0 :             i = colvar%mindist_param%i_coord_to(ii)
     940            0 :             colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
     941              :          END DO
     942              :          ! Create a List of points...
     943            0 :          ALLOCATE (list(np))
     944            0 :          idum = 0
     945            0 :          DO ii = 1, colvar%mindist_param%n_dist_from
     946            0 :             idum = idum + 1
     947            0 :             i = colvar%mindist_param%i_dist_from(ii)
     948            0 :             list(idum) = i
     949              :          END DO
     950            0 :          DO ii = 1, colvar%mindist_param%n_coord_from
     951            0 :             idum = idum + 1
     952            0 :             i = colvar%mindist_param%i_coord_from(ii)
     953            0 :             list(idum) = i
     954              :          END DO
     955            0 :          DO ii = 1, colvar%mindist_param%n_coord_to
     956            0 :             idum = idum + 1
     957            0 :             i = colvar%mindist_param%i_coord_to(ii)
     958            0 :             list(idum) = i
     959              :          END DO
     960            0 :          CPASSERT(idum == np)
     961              :       CASE (combine_colvar_id)
     962           32 :          colvar%n_atom_s = 0
     963           96 :          DO ii = 1, SIZE(colvar%combine_cvs_param%colvar_p)
     964           96 :             colvar%n_atom_s = colvar%n_atom_s + colvar%combine_cvs_param%colvar_p(ii)%colvar%n_atom_s
     965              :          END DO
     966           96 :          ALLOCATE (list(colvar%n_atom_s))
     967           32 :          idum = 0
     968           96 :          DO ii = 1, SIZE(colvar%combine_cvs_param%colvar_p)
     969          352 :             DO j = 1, colvar%combine_cvs_param%colvar_p(ii)%colvar%n_atom_s
     970          256 :                idum = idum + 1
     971          320 :                list(idum) = colvar%combine_cvs_param%colvar_p(ii)%colvar%i_atom(j)
     972              :             END DO
     973              :          END DO
     974              :       CASE (voronoiipz_colvar_id)
     975            8 :          colvar%use_points = .FALSE.
     976           24 :          ALLOCATE (list(SIZE(colvar%voronoiipz_params%group_a) + SIZE(colvar%voronoiipz_params%group_b)))
     977           24 :          list(1:SIZE(colvar%voronoiipz_params%group_a)) = colvar%voronoiipz_params%group_a(:)
     978           48 :          list(SIZE(colvar%voronoiipz_params%group_a) + 1:SIZE(list)) = colvar%voronoiipz_params%group_b(:)
     979            8 :          colvar%n_atom_s = SIZE(list)
     980              :       END SELECT
     981              : 
     982         5742 :       IF (ASSOCIATED(colvar%dsdr)) THEN
     983           48 :          DEALLOCATE (colvar%dsdr)
     984              :       END IF
     985         5742 :       IF (ASSOCIATED(colvar%i_atom)) THEN
     986           48 :          DEALLOCATE (colvar%i_atom)
     987              :       END IF
     988        17216 :       ALLOCATE (colvar%dsdr(3, colvar%n_atom_s))
     989        17216 :       ALLOCATE (colvar%i_atom(colvar%n_atom_s))
     990              :       ! And now map real atoms
     991         5742 :       istart = 0
     992         5742 :       iend = 0
     993        18916 :       DO i = 1, SIZE(list)
     994        18916 :          IF (.NOT. colvar%use_points) THEN
     995              :             ! No point centers
     996        12908 :             colvar%i_atom(i) = list(i)
     997        12908 :             iend = iend + 1
     998              :          ELSE
     999          266 :             IF (ASSOCIATED(colvar%points(list(i))%atoms)) THEN
    1000          256 :                iend = istart + SIZE(colvar%points(list(i))%atoms)
    1001          616 :                colvar%i_atom(istart + 1:iend) = colvar%points(list(i))%atoms
    1002              :                istart = iend
    1003              :             END IF
    1004              :          END IF
    1005              :       END DO
    1006         5742 :       CPASSERT(iend == colvar%n_atom_s)
    1007         5742 :       DEALLOCATE (list)
    1008              : 
    1009         5742 :    END SUBROUTINE colvar_setup
    1010              : 
    1011              : ! **************************************************************************************************
    1012              : !> \brief Finalize the setup of the collective variable for the autoionization of water
    1013              : !> \param colvar the colvar to initialize
    1014              : !> \param colvar_id ...
    1015              : !> \param list ...
    1016              : !> \author Dorothea Golze
    1017              : ! **************************************************************************************************
    1018            4 :    SUBROUTINE setup_hydronium_colvars(colvar, colvar_id, list)
    1019              :       TYPE(colvar_type), INTENT(INOUT)                   :: colvar
    1020              :       INTEGER, INTENT(IN)                                :: colvar_id
    1021              :       INTEGER, DIMENSION(:), INTENT(INOUT)               :: list
    1022              : 
    1023              :       INTEGER                                            :: i, idum, ii, n_hydrogens, n_oxygens, np
    1024            4 :       INTEGER, DIMENSION(:), POINTER                     :: i_hydrogens, i_oxygens
    1025              : 
    1026            4 :       NULLIFY (i_oxygens, i_hydrogens)
    1027              : 
    1028            6 :       SELECT CASE (colvar_id)
    1029              :       CASE (hydronium_shell_colvar_id)
    1030            2 :          n_oxygens = colvar%hydronium_shell_param%n_oxygens
    1031            2 :          n_hydrogens = colvar%hydronium_shell_param%n_hydrogens
    1032            2 :          i_oxygens => colvar%hydronium_shell_param%i_oxygens
    1033            2 :          i_hydrogens => colvar%hydronium_shell_param%i_hydrogens
    1034              :       CASE (hydronium_dist_colvar_id)
    1035            2 :          n_oxygens = colvar%hydronium_dist_param%n_oxygens
    1036            2 :          n_hydrogens = colvar%hydronium_dist_param%n_hydrogens
    1037            2 :          i_oxygens => colvar%hydronium_dist_param%i_oxygens
    1038            2 :          i_hydrogens => colvar%hydronium_dist_param%i_hydrogens
    1039              :       END SELECT
    1040              : 
    1041            4 :       np = n_oxygens + n_hydrogens
    1042              :       ! Number of real atoms involved in the colvar
    1043            4 :       colvar%n_atom_s = 0
    1044           20 :       DO ii = 1, n_oxygens
    1045           16 :          i = i_oxygens(ii)
    1046           20 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
    1047              :       END DO
    1048           40 :       DO ii = 1, n_hydrogens
    1049           36 :          i = i_hydrogens(ii)
    1050           40 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
    1051              :       END DO
    1052              :       idum = 0
    1053           20 :       DO ii = 1, n_oxygens
    1054           16 :          idum = idum + 1
    1055           16 :          i = i_oxygens(ii)
    1056           16 :          list(idum) = i
    1057          164 :          IF (ANY(i_hydrogens == i)) THEN
    1058            0 :             CPABORT("COLVAR: atoms doubled in OXYGENS and HYDROGENS list")
    1059              :          END IF
    1060              :       END DO
    1061           40 :       DO ii = 1, n_hydrogens
    1062           36 :          idum = idum + 1
    1063           36 :          i = i_hydrogens(ii)
    1064           40 :          list(idum) = i
    1065              :       END DO
    1066            4 :       CPASSERT(idum == np)
    1067           56 :       DO i = 1, np
    1068          368 :          DO ii = i + 1, np
    1069          364 :             IF (list(i) == list(ii)) THEN
    1070            0 :                IF (i <= n_oxygens) THEN
    1071            0 :                   CPABORT("atoms doubled in OXYGENS list")
    1072              :                END IF
    1073            0 :                IF (i > n_oxygens) THEN
    1074            0 :                   CPABORT("atoms doubled in HYDROGENS list")
    1075              :                END IF
    1076              :             END IF
    1077              :          END DO
    1078              :       END DO
    1079              : 
    1080            4 :    END SUBROUTINE setup_hydronium_colvars
    1081              : 
    1082              : ! **************************************************************************************************
    1083              : !> \brief Finalize the setup of the collective variable for the dissociation
    1084              : !>        of a carboxylic acid in water
    1085              : !> \param colvar the colvar to initialize
    1086              : !> \param colvar_id ...
    1087              : !> \param list ...
    1088              : !> \author Dorothea Golze
    1089              : ! **************************************************************************************************
    1090            4 :    SUBROUTINE setup_acid_hydronium_colvars(colvar, colvar_id, list)
    1091              :       TYPE(colvar_type), INTENT(INOUT)                   :: colvar
    1092              :       INTEGER, INTENT(IN)                                :: colvar_id
    1093              :       INTEGER, DIMENSION(:), INTENT(INOUT)               :: list
    1094              : 
    1095              :       INTEGER                                            :: i, idum, ii, n_hydrogens, &
    1096              :                                                             n_oxygens_acid, n_oxygens_water, np
    1097            4 :       INTEGER, DIMENSION(:), POINTER                     :: i_hydrogens, i_oxygens_acid, &
    1098            4 :                                                             i_oxygens_water
    1099              : 
    1100            4 :       NULLIFY (i_oxygens_water, i_oxygens_acid, i_hydrogens)
    1101              : 
    1102            6 :       SELECT CASE (colvar_id)
    1103              :       CASE (acid_hyd_dist_colvar_id)
    1104            2 :          n_oxygens_water = colvar%acid_hyd_dist_param%n_oxygens_water
    1105            2 :          n_oxygens_acid = colvar%acid_hyd_dist_param%n_oxygens_acid
    1106            2 :          n_hydrogens = colvar%acid_hyd_dist_param%n_hydrogens
    1107            2 :          i_oxygens_water => colvar%acid_hyd_dist_param%i_oxygens_water
    1108            2 :          i_oxygens_acid => colvar%acid_hyd_dist_param%i_oxygens_acid
    1109            2 :          i_hydrogens => colvar%acid_hyd_dist_param%i_hydrogens
    1110              :       CASE (acid_hyd_shell_colvar_id)
    1111            2 :          n_oxygens_water = colvar%acid_hyd_shell_param%n_oxygens_water
    1112            2 :          n_oxygens_acid = colvar%acid_hyd_shell_param%n_oxygens_acid
    1113            2 :          n_hydrogens = colvar%acid_hyd_shell_param%n_hydrogens
    1114            2 :          i_oxygens_water => colvar%acid_hyd_shell_param%i_oxygens_water
    1115            2 :          i_oxygens_acid => colvar%acid_hyd_shell_param%i_oxygens_acid
    1116            2 :          i_hydrogens => colvar%acid_hyd_shell_param%i_hydrogens
    1117              :       END SELECT
    1118              : 
    1119            4 :       np = n_oxygens_water + n_oxygens_acid + n_hydrogens
    1120              :       ! Number of real atoms involved in the colvar
    1121            4 :       colvar%n_atom_s = 0
    1122           12 :       DO ii = 1, n_oxygens_water
    1123            8 :          i = i_oxygens_water(ii)
    1124           12 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
    1125              :       END DO
    1126           12 :       DO ii = 1, n_oxygens_acid
    1127            8 :          i = i_oxygens_acid(ii)
    1128           12 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
    1129              :       END DO
    1130           24 :       DO ii = 1, n_hydrogens
    1131           20 :          i = i_hydrogens(ii)
    1132           24 :          colvar%n_atom_s = colvar%n_atom_s + COLV_SIZE(colvar, i)
    1133              :       END DO
    1134              :       idum = 0
    1135           12 :       DO ii = 1, n_oxygens_water
    1136            8 :          idum = idum + 1
    1137            8 :          i = i_oxygens_water(ii)
    1138            8 :          list(idum) = i
    1139           48 :          IF (ANY(i_hydrogens == i)) THEN
    1140            0 :             CPABORT("COLVAR: atoms doubled in OXYGENS_WATER and HYDROGENS list")
    1141              :          END IF
    1142           28 :          IF (ANY(i_oxygens_acid == i)) THEN
    1143            0 :             CPABORT("COLVAR: atoms doubled in OXYGENS_WATER and OXYGENS_ACID list")
    1144              :          END IF
    1145              :       END DO
    1146           12 :       DO ii = 1, n_oxygens_acid
    1147            8 :          idum = idum + 1
    1148            8 :          i = i_oxygens_acid(ii)
    1149            8 :          list(idum) = i
    1150           52 :          IF (ANY(i_hydrogens == i)) THEN
    1151            0 :             CPABORT("COLVAR: atoms doubled in OXYGENS_ACID and HYDROGENS list")
    1152              :          END IF
    1153              :       END DO
    1154           24 :       DO ii = 1, n_hydrogens
    1155           20 :          idum = idum + 1
    1156           20 :          i = i_hydrogens(ii)
    1157           24 :          list(idum) = i
    1158              :       END DO
    1159            4 :       CPASSERT(idum == np)
    1160           40 :       DO i = 1, np
    1161          184 :          DO ii = i + 1, np
    1162          180 :             IF (list(i) == list(ii)) THEN
    1163            0 :                IF (i <= n_oxygens_water) THEN
    1164            0 :                   CPABORT("atoms doubled in OXYGENS_WATER list")
    1165              :                END IF
    1166            0 :                IF (i > n_oxygens_water .AND. i <= n_oxygens_water + n_oxygens_acid) THEN
    1167            0 :                   CPABORT("atoms doubled in OXYGENS_ACID list")
    1168              :                END IF
    1169            0 :                IF (i > n_oxygens_water + n_oxygens_acid) THEN
    1170            0 :                   CPABORT("atoms doubled in HYDROGENS list")
    1171              :                END IF
    1172              :             END IF
    1173              :          END DO
    1174              :       END DO
    1175              : 
    1176            4 :    END SUBROUTINE setup_acid_hydronium_colvars
    1177              : 
    1178              : ! **************************************************************************************************
    1179              : !> \brief Gives back the size of an array of integer. If not associated gives back 1
    1180              : !> \param colvar ...
    1181              : !> \param i ...
    1182              : !> \return ...
    1183              : !> \author Teodoro Laino - 03.2007
    1184              : ! **************************************************************************************************
    1185        12652 :    FUNCTION colv_size(colvar, i) RESULT(my_size)
    1186              :       TYPE(colvar_type), INTENT(IN)                      :: colvar
    1187              :       INTEGER                                            :: i, my_size
    1188              : 
    1189        12652 :       my_size = 1
    1190        12652 :       IF (ASSOCIATED(colvar%points)) THEN
    1191          266 :          IF (ASSOCIATED(colvar%points(i)%atoms)) THEN
    1192          256 :             my_size = SIZE(colvar%points(i)%atoms)
    1193              :          ELSE
    1194              :             my_size = 0
    1195              :          END IF
    1196              :       END IF
    1197        12652 :    END FUNCTION colv_size
    1198              : 
    1199              : ! **************************************************************************************************
    1200              : !> \brief releases the memory that might have been allocated by the colvar
    1201              : !> \param colvar the colvar to deallocate
    1202              : !> \author alessandro laio and fawzi mohamed
    1203              : ! **************************************************************************************************
    1204         5694 :    RECURSIVE SUBROUTINE colvar_release(colvar)
    1205              :       TYPE(colvar_type), POINTER                         :: colvar
    1206              : 
    1207              :       INTEGER                                            :: i
    1208              : 
    1209         5694 :       CPASSERT(ASSOCIATED(colvar))
    1210         5694 :       IF (ASSOCIATED(colvar%dsdr)) THEN
    1211         5694 :          DEALLOCATE (colvar%dsdr)
    1212              :       END IF
    1213         5694 :       IF (ASSOCIATED(colvar%i_atom)) THEN
    1214         5694 :          DEALLOCATE (colvar%i_atom)
    1215              :       END IF
    1216         5694 :       IF (ASSOCIATED(colvar%points)) THEN
    1217          366 :          DO i = 1, SIZE(colvar%points)
    1218          266 :             IF (ASSOCIATED(colvar%points(i)%atoms)) THEN
    1219          256 :                DEALLOCATE (colvar%points(i)%atoms)
    1220              :             END IF
    1221          366 :             IF (ASSOCIATED(colvar%points(i)%weights)) THEN
    1222          256 :                DEALLOCATE (colvar%points(i)%weights)
    1223              :             END IF
    1224              :          END DO
    1225          100 :          DEALLOCATE (colvar%points)
    1226              :       END IF
    1227        10694 :       SELECT CASE (colvar%type_id)
    1228              :       CASE (dist_colvar_id)
    1229         5000 :          DEALLOCATE (colvar%dist_param)
    1230              :       CASE (coord_colvar_id)
    1231           64 :          IF (ASSOCIATED(colvar%coord_param%i_at_from)) THEN
    1232           64 :             DEALLOCATE (colvar%coord_param%i_at_from)
    1233              :          END IF
    1234           64 :          IF (ASSOCIATED(colvar%coord_param%i_at_to)) THEN
    1235           64 :             DEALLOCATE (colvar%coord_param%i_at_to)
    1236              :          END IF
    1237           64 :          IF (ASSOCIATED(colvar%coord_param%c_kinds_from)) THEN
    1238            8 :             DEALLOCATE (colvar%coord_param%c_kinds_from)
    1239              :          END IF
    1240           64 :          IF (ASSOCIATED(colvar%coord_param%c_kinds_to)) THEN
    1241           10 :             DEALLOCATE (colvar%coord_param%c_kinds_to)
    1242              :          END IF
    1243           64 :          IF (ASSOCIATED(colvar%coord_param%i_at_to_b)) THEN
    1244            4 :             DEALLOCATE (colvar%coord_param%i_at_to_b)
    1245              :          END IF
    1246           64 :          IF (ASSOCIATED(colvar%coord_param%c_kinds_to_b)) THEN
    1247            2 :             DEALLOCATE (colvar%coord_param%c_kinds_to_b)
    1248              :          END IF
    1249           64 :          DEALLOCATE (colvar%coord_param)
    1250              :       CASE (population_colvar_id)
    1251            8 :          IF (ASSOCIATED(colvar%population_param%i_at_from)) THEN
    1252            8 :             DEALLOCATE (colvar%population_param%i_at_from)
    1253              :          END IF
    1254            8 :          IF (ASSOCIATED(colvar%population_param%i_at_to)) THEN
    1255            8 :             DEALLOCATE (colvar%population_param%i_at_to)
    1256              :          END IF
    1257            8 :          IF (ASSOCIATED(colvar%population_param%c_kinds_from)) THEN
    1258            0 :             DEALLOCATE (colvar%population_param%c_kinds_from)
    1259              :          END IF
    1260            8 :          IF (ASSOCIATED(colvar%population_param%c_kinds_to)) THEN
    1261            8 :             DEALLOCATE (colvar%population_param%c_kinds_to)
    1262              :          END IF
    1263            8 :          DEALLOCATE (colvar%population_param)
    1264              :       CASE (gyration_colvar_id)
    1265            2 :          IF (ASSOCIATED(colvar%gyration_param%i_at)) THEN
    1266            2 :             DEALLOCATE (colvar%gyration_param%i_at)
    1267              :          END IF
    1268            2 :          IF (ASSOCIATED(colvar%gyration_param%c_kinds)) THEN
    1269            2 :             DEALLOCATE (colvar%gyration_param%c_kinds)
    1270              :          END IF
    1271            2 :          DEALLOCATE (colvar%gyration_param)
    1272              :       CASE (angle_colvar_id)
    1273          220 :          DEALLOCATE (colvar%angle_param)
    1274              :       CASE (torsion_colvar_id)
    1275          162 :          DEALLOCATE (colvar%torsion_param)
    1276              :       CASE (plane_distance_colvar_id)
    1277           28 :          DEALLOCATE (colvar%plane_distance_param)
    1278              :       CASE (plane_plane_angle_colvar_id)
    1279           16 :          DEALLOCATE (colvar%plane_plane_angle_param)
    1280              :       CASE (dfunct_colvar_id)
    1281           18 :          DEALLOCATE (colvar%dfunct_param)
    1282              :       CASE (rotation_colvar_id)
    1283            2 :          DEALLOCATE (colvar%rotation_param)
    1284              :       CASE (qparm_colvar_id)
    1285            2 :          DEALLOCATE (colvar%qparm_param%i_at_from)
    1286            2 :          DEALLOCATE (colvar%qparm_param%i_at_to)
    1287            2 :          DEALLOCATE (colvar%qparm_param)
    1288              :       CASE (xyz_diag_colvar_id)
    1289           30 :          DEALLOCATE (colvar%xyz_diag_param)
    1290              :       CASE (xyz_outerdiag_colvar_id)
    1291           30 :          DEALLOCATE (colvar%xyz_outerdiag_param)
    1292              :       CASE (u_colvar_id)
    1293            6 :          NULLIFY (colvar%u_param%mixed_energy_section)
    1294            6 :          DEALLOCATE (colvar%u_param)
    1295              :       CASE (hydronium_shell_colvar_id)
    1296            2 :          DEALLOCATE (colvar%hydronium_shell_param%i_oxygens)
    1297            2 :          DEALLOCATE (colvar%hydronium_shell_param%i_hydrogens)
    1298            2 :          DEALLOCATE (colvar%hydronium_shell_param)
    1299              :       CASE (hydronium_dist_colvar_id)
    1300            2 :          DEALLOCATE (colvar%hydronium_dist_param%i_oxygens)
    1301            2 :          DEALLOCATE (colvar%hydronium_dist_param%i_hydrogens)
    1302            2 :          DEALLOCATE (colvar%hydronium_dist_param)
    1303              :       CASE (acid_hyd_dist_colvar_id)
    1304            2 :          DEALLOCATE (colvar%acid_hyd_dist_param%i_oxygens_water)
    1305            2 :          DEALLOCATE (colvar%acid_hyd_dist_param%i_oxygens_acid)
    1306            2 :          DEALLOCATE (colvar%acid_hyd_dist_param%i_hydrogens)
    1307            2 :          DEALLOCATE (colvar%acid_hyd_dist_param)
    1308              :       CASE (acid_hyd_shell_colvar_id)
    1309            2 :          DEALLOCATE (colvar%acid_hyd_shell_param%i_oxygens_water)
    1310            2 :          DEALLOCATE (colvar%acid_hyd_shell_param%i_oxygens_acid)
    1311            2 :          DEALLOCATE (colvar%acid_hyd_shell_param%i_hydrogens)
    1312            2 :          DEALLOCATE (colvar%acid_hyd_shell_param)
    1313              :       CASE (reaction_path_colvar_id, distance_from_path_colvar_id)
    1314           28 :          IF (colvar%reaction_path_param%dist_rmsd .OR. colvar%reaction_path_param%rmsd) THEN
    1315            8 :             DEALLOCATE (colvar%reaction_path_param%r_ref)
    1316            8 :             DEALLOCATE (colvar%reaction_path_param%i_rmsd)
    1317              :          ELSE
    1318           56 :             DO i = 1, SIZE(colvar%reaction_path_param%colvar_p)
    1319           56 :                CALL colvar_release(colvar%reaction_path_param%colvar_p(i)%colvar)
    1320              :             END DO
    1321           20 :             DEALLOCATE (colvar%reaction_path_param%colvar_p)
    1322           20 :             DEALLOCATE (colvar%reaction_path_param%f_vals)
    1323              :          END IF
    1324           28 :          DEALLOCATE (colvar%reaction_path_param)
    1325              :       CASE (combine_colvar_id)
    1326           60 :          DO i = 1, SIZE(colvar%combine_cvs_param%colvar_p)
    1327           60 :             CALL colvar_release(colvar%combine_cvs_param%colvar_p(i)%colvar)
    1328              :          END DO
    1329           20 :          DEALLOCATE (colvar%combine_cvs_param%colvar_p)
    1330           20 :          DEALLOCATE (colvar%combine_cvs_param%c_parameters)
    1331           20 :          DEALLOCATE (colvar%combine_cvs_param%v_parameters)
    1332           20 :          DEALLOCATE (colvar%combine_cvs_param%variables)
    1333           20 :          DEALLOCATE (colvar%combine_cvs_param)
    1334              :       CASE (rmsd_colvar_id)
    1335            4 :          DEALLOCATE (colvar%rmsd_param%weights)
    1336            4 :          DEALLOCATE (colvar%rmsd_param%r_ref)
    1337            4 :          DEALLOCATE (colvar%rmsd_param%i_rmsd)
    1338            4 :          DEALLOCATE (colvar%rmsd_param)
    1339              :       CASE (Wc_colvar_id)
    1340            0 :          DEALLOCATE (colvar%Wc)
    1341              :       CASE (HBP_colvar_id)
    1342            2 :          DEALLOCATE (colvar%HBP%ewc)
    1343            2 :          DEALLOCATE (colvar%HBP%ids)
    1344            2 :          DEALLOCATE (colvar%HBP)
    1345              :       CASE (ring_puckering_colvar_id)
    1346           36 :          DEALLOCATE (colvar%ring_puckering_param%atoms)
    1347           36 :          DEALLOCATE (colvar%ring_puckering_param)
    1348              :       CASE (mindist_colvar_id)
    1349            0 :          IF (ASSOCIATED(colvar%mindist_param%i_dist_from)) THEN
    1350            0 :             DEALLOCATE (colvar%mindist_param%i_dist_from)
    1351              :          END IF
    1352            0 :          IF (ASSOCIATED(colvar%mindist_param%i_coord_from)) THEN
    1353            0 :             DEALLOCATE (colvar%mindist_param%i_coord_from)
    1354              :          END IF
    1355            0 :          IF (ASSOCIATED(colvar%mindist_param%i_coord_to)) THEN
    1356            0 :             DEALLOCATE (colvar%mindist_param%i_coord_to)
    1357              :          END IF
    1358            0 :          IF (ASSOCIATED(colvar%mindist_param%k_coord_from)) THEN
    1359            0 :             DEALLOCATE (colvar%mindist_param%k_coord_from)
    1360              :          END IF
    1361            0 :          IF (ASSOCIATED(colvar%mindist_param%k_coord_to)) THEN
    1362            0 :             DEALLOCATE (colvar%mindist_param%k_coord_to)
    1363              :          END IF
    1364            0 :          DEALLOCATE (colvar%mindist_param)
    1365              : 
    1366              :       CASE (voronoiipz_colvar_id)
    1367            8 :          DEALLOCATE (colvar%voronoiipz_params%group_a)
    1368            8 :          DEALLOCATE (colvar%voronoiipz_params%group_b)
    1369            8 :          DEALLOCATE (colvar%voronoiipz_params)
    1370              :       CASE (no_colvar_id)
    1371              :          ! Do nothing
    1372              :       CASE default
    1373         5694 :          CPABORT("Unknown colvar type")
    1374              :       END SELECT
    1375         5694 :       DEALLOCATE (colvar)
    1376              : 
    1377         5694 :    END SUBROUTINE colvar_release
    1378              : 
    1379              : ! **************************************************************************************************
    1380              : !> \brief Clone a colvar type
    1381              : !> \param colvar_out ...
    1382              : !> \param colvar_in the colvar to deallocate
    1383              : !> \param i_atom_offset ...
    1384              : !> \author Teodoro Laino [tlaino] 04.2006
    1385              : ! **************************************************************************************************
    1386         4992 :    RECURSIVE SUBROUTINE colvar_clone(colvar_out, colvar_in, i_atom_offset)
    1387              :       TYPE(colvar_type), INTENT(INOUT), POINTER          :: colvar_out
    1388              :       TYPE(colvar_type), INTENT(IN)                      :: colvar_in
    1389              :       INTEGER, INTENT(IN), OPTIONAL                      :: i_atom_offset
    1390              : 
    1391              :       INTEGER                                            :: i, my_offset, ndim, ndim2
    1392              : 
    1393         4992 :       my_offset = 0
    1394         4992 :       IF (PRESENT(i_atom_offset)) my_offset = i_atom_offset
    1395         4992 :       CALL colvar_create(colvar_out, colvar_in%type_id)
    1396         4992 :       CALL colvar_clone_points(colvar_out, colvar_in, my_offset)
    1397         4992 :       IF (colvar_in%use_points) my_offset = 0
    1398         4998 :       SELECT CASE (colvar_out%type_id)
    1399              :       CASE (voronoiipz_colvar_id)
    1400            6 :          colvar_out%voronoiipz_params%lambda = colvar_in%voronoiipz_params%lambda
    1401            6 :          colvar_out%voronoiipz_params%zidx = colvar_in%voronoiipz_params%zidx
    1402            6 :          colvar_out%voronoiipz_params%nrx = colvar_in%voronoiipz_params%nrx
    1403            6 :          colvar_out%voronoiipz_params%zmid = colvar_in%voronoiipz_params%zmid
    1404            6 :          colvar_out%voronoiipz_params%d0 = colvar_in%voronoiipz_params%d0
    1405            6 :          colvar_out%voronoiipz_params%d1 = colvar_in%voronoiipz_params%d1
    1406            6 :          colvar_out%voronoiipz_params%d2 = colvar_in%voronoiipz_params%d2
    1407            6 :          colvar_out%voronoiipz_params%d3 = colvar_in%voronoiipz_params%d3
    1408            6 :          colvar_out%voronoiipz_params%nl_cutoff = colvar_in%voronoiipz_params%nl_cutoff
    1409           18 :          ALLOCATE (colvar_out%voronoiipz_params%group_a(SIZE(colvar_in%voronoiipz_params%group_a)))
    1410           18 :          ALLOCATE (colvar_out%voronoiipz_params%group_b(SIZE(colvar_in%voronoiipz_params%group_b)))
    1411           18 :          colvar_out%voronoiipz_params%group_a = colvar_in%voronoiipz_params%group_a + my_offset
    1412           36 :          colvar_out%voronoiipz_params%group_b = colvar_in%voronoiipz_params%group_b + my_offset
    1413              :       CASE (dist_colvar_id)
    1414         4612 :          colvar_out%dist_param%i_at = colvar_in%dist_param%i_at + my_offset
    1415         4612 :          colvar_out%dist_param%j_at = colvar_in%dist_param%j_at + my_offset
    1416         4612 :          colvar_out%dist_param%axis_id = colvar_in%dist_param%axis_id
    1417         4612 :          colvar_out%dist_param%sign_d = colvar_in%dist_param%sign_d
    1418              :       CASE (coord_colvar_id)
    1419            6 :          colvar_out%coord_param%n_atoms_to = colvar_in%coord_param%n_atoms_to
    1420            6 :          colvar_out%coord_param%n_atoms_to_b = colvar_in%coord_param%n_atoms_to_b
    1421            6 :          colvar_out%coord_param%n_atoms_from = colvar_in%coord_param%n_atoms_from
    1422            6 :          colvar_out%coord_param%nncrd = colvar_in%coord_param%nncrd
    1423            6 :          colvar_out%coord_param%ndcrd = colvar_in%coord_param%ndcrd
    1424            6 :          colvar_out%coord_param%r_0 = colvar_in%coord_param%r_0
    1425            6 :          colvar_out%coord_param%nncrd_b = colvar_in%coord_param%nncrd_b
    1426            6 :          colvar_out%coord_param%ndcrd_b = colvar_in%coord_param%ndcrd_b
    1427            6 :          colvar_out%coord_param%r_0_b = colvar_in%coord_param%r_0_b
    1428            6 :          colvar_out%coord_param%use_kinds_from = colvar_in%coord_param%use_kinds_from
    1429            6 :          colvar_out%coord_param%use_kinds_to = colvar_in%coord_param%use_kinds_to
    1430            6 :          colvar_out%coord_param%use_kinds_to_b = colvar_in%coord_param%use_kinds_to_b
    1431            6 :          IF (colvar_in%coord_param%use_kinds_from) THEN
    1432              :             ! KINDS
    1433            0 :             ndim = SIZE(colvar_in%coord_param%c_kinds_from)
    1434            0 :             ALLOCATE (colvar_out%coord_param%c_kinds_from(ndim))
    1435            0 :             colvar_out%coord_param%c_kinds_from = colvar_in%coord_param%c_kinds_from
    1436              :          ELSE
    1437              :             ! INDEX
    1438            6 :             ndim = SIZE(colvar_in%coord_param%i_at_from)
    1439           18 :             ALLOCATE (colvar_out%coord_param%i_at_from(ndim))
    1440           12 :             colvar_out%coord_param%i_at_from = colvar_in%coord_param%i_at_from + my_offset
    1441              :          END IF
    1442            6 :          IF (colvar_in%coord_param%use_kinds_to) THEN
    1443              :             ! KINDS
    1444            0 :             ndim = SIZE(colvar_in%coord_param%c_kinds_to)
    1445            0 :             ALLOCATE (colvar_out%coord_param%c_kinds_to(ndim))
    1446            0 :             colvar_out%coord_param%c_kinds_to = colvar_in%coord_param%c_kinds_to
    1447              :          ELSE
    1448              :             ! INDEX
    1449            6 :             ndim = SIZE(colvar_in%coord_param%i_at_to)
    1450           18 :             ALLOCATE (colvar_out%coord_param%i_at_to(ndim))
    1451           18 :             colvar_out%coord_param%i_at_to = colvar_in%coord_param%i_at_to + my_offset
    1452              :          END IF
    1453            6 :          IF (colvar_in%coord_param%use_kinds_to_b) THEN
    1454              :             ! KINDS
    1455            0 :             ndim = SIZE(colvar_in%coord_param%c_kinds_to_b)
    1456            0 :             ALLOCATE (colvar_out%coord_param%c_kinds_to_b(ndim))
    1457            0 :             colvar_out%coord_param%c_kinds_to_b = colvar_in%coord_param%c_kinds_to_b
    1458            6 :          ELSE IF (ASSOCIATED(colvar_in%coord_param%i_at_to_b)) THEN
    1459              :             ! INDEX
    1460            0 :             ndim = SIZE(colvar_in%coord_param%i_at_to_b)
    1461            0 :             ALLOCATE (colvar_out%coord_param%i_at_to_b(ndim))
    1462            0 :             colvar_out%coord_param%i_at_to_b = colvar_in%coord_param%i_at_to_b + my_offset
    1463              :          END IF
    1464              : 
    1465              :       CASE (population_colvar_id)
    1466            0 :          colvar_out%population_param%n_atoms_to = colvar_in%population_param%n_atoms_to
    1467            0 :          colvar_out%population_param%n_atoms_from = colvar_in%population_param%n_atoms_from
    1468            0 :          colvar_out%population_param%nncrd = colvar_in%population_param%nncrd
    1469            0 :          colvar_out%population_param%ndcrd = colvar_in%population_param%ndcrd
    1470            0 :          colvar_out%population_param%r_0 = colvar_in%population_param%r_0
    1471            0 :          colvar_out%population_param%use_kinds_from = colvar_in%population_param%use_kinds_from
    1472            0 :          colvar_out%population_param%use_kinds_to = colvar_in%population_param%use_kinds_to
    1473            0 :          IF (colvar_in%population_param%use_kinds_from) THEN
    1474              :             ! KINDS
    1475            0 :             ndim = SIZE(colvar_in%population_param%c_kinds_from)
    1476            0 :             ALLOCATE (colvar_out%population_param%c_kinds_from(ndim))
    1477            0 :             colvar_out%population_param%c_kinds_from = colvar_in%population_param%c_kinds_from
    1478              :          ELSE
    1479              :             ! INDEX
    1480            0 :             ndim = SIZE(colvar_in%population_param%i_at_from)
    1481            0 :             ALLOCATE (colvar_out%population_param%i_at_from(ndim))
    1482            0 :             colvar_out%population_param%i_at_from = colvar_in%population_param%i_at_from + my_offset
    1483              :          END IF
    1484            0 :          IF (colvar_in%population_param%use_kinds_to) THEN
    1485              :             ! KINDS
    1486            0 :             ndim = SIZE(colvar_in%population_param%c_kinds_to)
    1487            0 :             ALLOCATE (colvar_out%population_param%c_kinds_to(ndim))
    1488            0 :             colvar_out%population_param%c_kinds_to = colvar_in%population_param%c_kinds_to
    1489              :          ELSE
    1490              :             ! INDEX
    1491            0 :             ndim = SIZE(colvar_in%population_param%i_at_to)
    1492            0 :             ALLOCATE (colvar_out%population_param%i_at_to(ndim))
    1493            0 :             colvar_out%population_param%i_at_to = colvar_in%population_param%i_at_to + my_offset
    1494              :          END IF
    1495              : 
    1496              :       CASE (gyration_colvar_id)
    1497            0 :          colvar_out%gyration_param%n_atoms = colvar_in%gyration_param%n_atoms
    1498            0 :          colvar_out%gyration_param%use_kinds = colvar_in%gyration_param%use_kinds
    1499            0 :          IF (colvar_in%gyration_param%use_kinds) THEN
    1500              :             ! KINDS
    1501            0 :             ndim = SIZE(colvar_in%gyration_param%c_kinds)
    1502            0 :             ALLOCATE (colvar_out%gyration_param%c_kinds(ndim))
    1503            0 :             colvar_out%gyration_param%c_kinds = colvar_in%gyration_param%c_kinds
    1504              :          ELSE
    1505              :             ! INDEX
    1506            0 :             ndim = SIZE(colvar_in%gyration_param%i_at)
    1507            0 :             ALLOCATE (colvar_out%gyration_param%i_at(ndim))
    1508            0 :             colvar_out%gyration_param%i_at = colvar_in%gyration_param%i_at + my_offset
    1509              :          END IF
    1510              :       CASE (angle_colvar_id)
    1511          672 :          colvar_out%angle_param%i_at_angle = colvar_in%angle_param%i_at_angle + my_offset
    1512              :       CASE (torsion_colvar_id)
    1513          570 :          colvar_out%torsion_param%i_at_tors = colvar_in%torsion_param%i_at_tors + my_offset
    1514          114 :          colvar_out%torsion_param%o0 = colvar_in%torsion_param%o0
    1515              :       CASE (plane_distance_colvar_id)
    1516            0 :          colvar_out%plane_distance_param%use_pbc = colvar_in%plane_distance_param%use_pbc
    1517            0 :          colvar_out%plane_distance_param%plane = colvar_in%plane_distance_param%plane + my_offset
    1518            0 :          colvar_out%plane_distance_param%point = colvar_in%plane_distance_param%point + my_offset
    1519              :       CASE (plane_plane_angle_colvar_id)
    1520           12 :          colvar_out%plane_plane_angle_param%plane1%type_of_def = colvar_in%plane_plane_angle_param%plane1%type_of_def
    1521           12 :          IF (colvar_out%plane_plane_angle_param%plane1%type_of_def == plane_def_vec) THEN
    1522            0 :             colvar_out%plane_plane_angle_param%plane1%normal_vec = colvar_in%plane_plane_angle_param%plane1%normal_vec
    1523              :          ELSE
    1524           48 :             colvar_out%plane_plane_angle_param%plane1%points = colvar_in%plane_plane_angle_param%plane1%points + my_offset
    1525              :          END IF
    1526              : 
    1527           12 :          colvar_out%plane_plane_angle_param%plane2%type_of_def = colvar_in%plane_plane_angle_param%plane2%type_of_def
    1528           12 :          IF (colvar_out%plane_plane_angle_param%plane2%type_of_def == plane_def_vec) THEN
    1529           24 :             colvar_out%plane_plane_angle_param%plane2%normal_vec = colvar_in%plane_plane_angle_param%plane2%normal_vec
    1530              :          ELSE
    1531           24 :             colvar_out%plane_plane_angle_param%plane2%points = colvar_in%plane_plane_angle_param%plane2%points + my_offset
    1532              :          END IF
    1533              :       CASE (rotation_colvar_id)
    1534            0 :          colvar_out%rotation_param%i_at1_bond1 = colvar_in%rotation_param%i_at1_bond1 + my_offset
    1535            0 :          colvar_out%rotation_param%i_at2_bond1 = colvar_in%rotation_param%i_at2_bond1 + my_offset
    1536            0 :          colvar_out%rotation_param%i_at1_bond2 = colvar_in%rotation_param%i_at1_bond2 + my_offset
    1537            0 :          colvar_out%rotation_param%i_at2_bond2 = colvar_in%rotation_param%i_at2_bond2 + my_offset
    1538              :       CASE (dfunct_colvar_id)
    1539           60 :          colvar_out%dfunct_param%i_at_dfunct = colvar_in%dfunct_param%i_at_dfunct + my_offset
    1540           12 :          colvar_out%dfunct_param%coeff = colvar_in%dfunct_param%coeff
    1541           12 :          colvar_out%dfunct_param%use_pbc = colvar_in%dfunct_param%use_pbc
    1542              :       CASE (qparm_colvar_id)
    1543            0 :          colvar_out%qparm_param%n_atoms_to = colvar_in%qparm_param%n_atoms_to
    1544            0 :          colvar_out%qparm_param%n_atoms_from = colvar_in%qparm_param%n_atoms_from
    1545            0 :          colvar_out%qparm_param%rcut = colvar_in%qparm_param%rcut
    1546            0 :          colvar_out%qparm_param%l = colvar_in%qparm_param%l
    1547            0 :          colvar_out%qparm_param%rstart = colvar_in%qparm_param%rstart
    1548            0 :          colvar_out%qparm_param%include_images = colvar_in%qparm_param%include_images
    1549            0 :          ndim = SIZE(colvar_in%qparm_param%i_at_from)
    1550            0 :          ALLOCATE (colvar_out%qparm_param%i_at_from(ndim))
    1551            0 :          ndim = SIZE(colvar_in%qparm_param%i_at_to)
    1552            0 :          ALLOCATE (colvar_out%qparm_param%i_at_to(ndim))
    1553            0 :          colvar_out%qparm_param%i_at_from = colvar_in%qparm_param%i_at_from + my_offset
    1554            0 :          colvar_out%qparm_param%i_at_to = colvar_in%qparm_param%i_at_from + my_offset
    1555              :       CASE (xyz_diag_colvar_id)
    1556           24 :          colvar_out%xyz_diag_param%i_atom = colvar_in%xyz_diag_param%i_atom + my_offset
    1557           24 :          colvar_out%xyz_diag_param%component = colvar_in%xyz_diag_param%component
    1558           96 :          colvar_out%xyz_diag_param%r0 = colvar_in%xyz_diag_param%r0
    1559           24 :          colvar_out%xyz_diag_param%use_pbc = colvar_in%xyz_diag_param%use_pbc
    1560           24 :          colvar_out%xyz_diag_param%use_absolute_position = colvar_in%xyz_diag_param%use_absolute_position
    1561              :       CASE (xyz_outerdiag_colvar_id)
    1562           72 :          colvar_out%xyz_outerdiag_param%i_atoms = colvar_in%xyz_outerdiag_param%i_atoms + my_offset
    1563           72 :          colvar_out%xyz_outerdiag_param%components = colvar_in%xyz_outerdiag_param%components
    1564          216 :          colvar_out%xyz_outerdiag_param%r0 = colvar_in%xyz_outerdiag_param%r0
    1565           24 :          colvar_out%xyz_outerdiag_param%use_pbc = colvar_in%xyz_outerdiag_param%use_pbc
    1566              :       CASE (u_colvar_id)
    1567            0 :          colvar_out%u_param%natom = colvar_in%u_param%natom
    1568              :       CASE (hydronium_shell_colvar_id)
    1569            0 :          colvar_out%hydronium_shell_param%n_hydrogens = colvar_in%hydronium_shell_param%n_hydrogens
    1570            0 :          colvar_out%hydronium_shell_param%n_oxygens = colvar_in%hydronium_shell_param%n_oxygens
    1571            0 :          colvar_out%hydronium_shell_param%nh = colvar_in%hydronium_shell_param%nh
    1572            0 :          colvar_out%hydronium_shell_param%poh = colvar_in%hydronium_shell_param%poh
    1573            0 :          colvar_out%hydronium_shell_param%poo = colvar_in%hydronium_shell_param%poo
    1574            0 :          colvar_out%hydronium_shell_param%qoh = colvar_in%hydronium_shell_param%qoh
    1575            0 :          colvar_out%hydronium_shell_param%qoo = colvar_in%hydronium_shell_param%qoo
    1576            0 :          colvar_out%hydronium_shell_param%pm = colvar_in%hydronium_shell_param%pm
    1577            0 :          colvar_out%hydronium_shell_param%qm = colvar_in%hydronium_shell_param%qm
    1578            0 :          colvar_out%hydronium_shell_param%roo = colvar_in%hydronium_shell_param%roo
    1579            0 :          colvar_out%hydronium_shell_param%roh = colvar_in%hydronium_shell_param%roh
    1580            0 :          colvar_out%hydronium_shell_param%lambda = colvar_in%hydronium_shell_param%lambda
    1581            0 :          ndim = SIZE(colvar_in%hydronium_shell_param%i_oxygens)
    1582            0 :          ALLOCATE (colvar_out%hydronium_shell_param%i_oxygens(ndim))
    1583            0 :          ndim = SIZE(colvar_in%hydronium_shell_param%i_hydrogens)
    1584            0 :          ALLOCATE (colvar_out%hydronium_shell_param%i_hydrogens(ndim))
    1585            0 :          colvar_out%hydronium_shell_param%i_oxygens = colvar_in%hydronium_shell_param%i_oxygens + my_offset
    1586            0 :          colvar_out%hydronium_shell_param%i_hydrogens = colvar_in%hydronium_shell_param%i_hydrogens + my_offset
    1587              :       CASE (hydronium_dist_colvar_id)
    1588            0 :          colvar_out%hydronium_dist_param%n_hydrogens = colvar_in%hydronium_dist_param%n_hydrogens
    1589            0 :          colvar_out%hydronium_dist_param%n_oxygens = colvar_in%hydronium_dist_param%n_oxygens
    1590            0 :          colvar_out%hydronium_dist_param%nh = colvar_in%hydronium_dist_param%nh
    1591            0 :          colvar_out%hydronium_dist_param%nn = colvar_in%hydronium_dist_param%nn
    1592            0 :          colvar_out%hydronium_dist_param%poh = colvar_in%hydronium_dist_param%poh
    1593            0 :          colvar_out%hydronium_dist_param%qoh = colvar_in%hydronium_dist_param%qoh
    1594            0 :          colvar_out%hydronium_dist_param%pf = colvar_in%hydronium_dist_param%pf
    1595            0 :          colvar_out%hydronium_dist_param%qf = colvar_in%hydronium_dist_param%qf
    1596            0 :          colvar_out%hydronium_dist_param%pm = colvar_in%hydronium_dist_param%pm
    1597            0 :          colvar_out%hydronium_dist_param%qm = colvar_in%hydronium_dist_param%qm
    1598            0 :          colvar_out%hydronium_dist_param%roh = colvar_in%hydronium_dist_param%roh
    1599            0 :          colvar_out%hydronium_dist_param%lambda = colvar_in%hydronium_dist_param%lambda
    1600            0 :          ndim = SIZE(colvar_in%hydronium_dist_param%i_oxygens)
    1601            0 :          ALLOCATE (colvar_out%hydronium_dist_param%i_oxygens(ndim))
    1602            0 :          ndim = SIZE(colvar_in%hydronium_dist_param%i_hydrogens)
    1603            0 :          ALLOCATE (colvar_out%hydronium_dist_param%i_hydrogens(ndim))
    1604            0 :          colvar_out%hydronium_dist_param%i_oxygens = colvar_in%hydronium_dist_param%i_oxygens + my_offset
    1605            0 :          colvar_out%hydronium_dist_param%i_hydrogens = colvar_in%hydronium_dist_param%i_hydrogens + my_offset
    1606              :       CASE (acid_hyd_dist_colvar_id)
    1607            0 :          colvar_out%acid_hyd_dist_param%n_hydrogens = colvar_in%acid_hyd_dist_param%n_hydrogens
    1608            0 :          colvar_out%acid_hyd_dist_param%n_oxygens_water = colvar_in%acid_hyd_dist_param%n_oxygens_water
    1609            0 :          colvar_out%acid_hyd_dist_param%n_oxygens_acid = colvar_in%acid_hyd_dist_param%n_oxygens_acid
    1610            0 :          colvar_out%acid_hyd_dist_param%nc = colvar_in%acid_hyd_dist_param%nc
    1611            0 :          colvar_out%acid_hyd_dist_param%pwoh = colvar_in%acid_hyd_dist_param%pwoh
    1612            0 :          colvar_out%acid_hyd_dist_param%qwoh = colvar_in%acid_hyd_dist_param%qwoh
    1613            0 :          colvar_out%acid_hyd_dist_param%paoh = colvar_in%acid_hyd_dist_param%paoh
    1614            0 :          colvar_out%acid_hyd_dist_param%qaoh = colvar_in%acid_hyd_dist_param%qaoh
    1615            0 :          colvar_out%acid_hyd_dist_param%pcut = colvar_in%acid_hyd_dist_param%pcut
    1616            0 :          colvar_out%acid_hyd_dist_param%qcut = colvar_in%acid_hyd_dist_param%qcut
    1617            0 :          colvar_out%acid_hyd_dist_param%rwoh = colvar_in%acid_hyd_dist_param%rwoh
    1618            0 :          colvar_out%acid_hyd_dist_param%raoh = colvar_in%acid_hyd_dist_param%raoh
    1619            0 :          colvar_out%acid_hyd_dist_param%lambda = colvar_in%acid_hyd_dist_param%lambda
    1620            0 :          ndim = SIZE(colvar_in%acid_hyd_dist_param%i_oxygens_water)
    1621            0 :          ALLOCATE (colvar_out%acid_hyd_dist_param%i_oxygens_water(ndim))
    1622            0 :          ndim = SIZE(colvar_in%acid_hyd_dist_param%i_oxygens_acid)
    1623            0 :          ALLOCATE (colvar_out%acid_hyd_dist_param%i_oxygens_acid(ndim))
    1624            0 :          ndim = SIZE(colvar_in%acid_hyd_dist_param%i_hydrogens)
    1625            0 :          ALLOCATE (colvar_out%acid_hyd_dist_param%i_hydrogens(ndim))
    1626            0 :          colvar_out%acid_hyd_dist_param%i_oxygens_water = colvar_in%acid_hyd_dist_param%i_oxygens_water + my_offset
    1627            0 :          colvar_out%acid_hyd_dist_param%i_oxygens_acid = colvar_in%acid_hyd_dist_param%i_oxygens_acid + my_offset
    1628            0 :          colvar_out%acid_hyd_dist_param%i_hydrogens = colvar_in%acid_hyd_dist_param%i_hydrogens + my_offset
    1629              :       CASE (acid_hyd_shell_colvar_id)
    1630            0 :          colvar_out%acid_hyd_shell_param%n_hydrogens = colvar_in%acid_hyd_shell_param%n_hydrogens
    1631            0 :          colvar_out%acid_hyd_shell_param%n_oxygens_water = colvar_in%acid_hyd_shell_param%n_oxygens_water
    1632            0 :          colvar_out%acid_hyd_shell_param%n_oxygens_acid = colvar_in%acid_hyd_shell_param%n_oxygens_acid
    1633            0 :          colvar_out%acid_hyd_shell_param%nc = colvar_in%acid_hyd_shell_param%nc
    1634            0 :          colvar_out%acid_hyd_shell_param%nh = colvar_in%acid_hyd_shell_param%nh
    1635            0 :          colvar_out%acid_hyd_shell_param%pwoh = colvar_in%acid_hyd_shell_param%pwoh
    1636            0 :          colvar_out%acid_hyd_shell_param%qwoh = colvar_in%acid_hyd_shell_param%qwoh
    1637            0 :          colvar_out%acid_hyd_shell_param%paoh = colvar_in%acid_hyd_shell_param%paoh
    1638            0 :          colvar_out%acid_hyd_shell_param%qaoh = colvar_in%acid_hyd_shell_param%qaoh
    1639            0 :          colvar_out%acid_hyd_shell_param%poo = colvar_in%acid_hyd_shell_param%poo
    1640            0 :          colvar_out%acid_hyd_shell_param%qoo = colvar_in%acid_hyd_shell_param%qoo
    1641            0 :          colvar_out%acid_hyd_shell_param%pm = colvar_in%acid_hyd_shell_param%pm
    1642            0 :          colvar_out%acid_hyd_shell_param%qm = colvar_in%acid_hyd_shell_param%qm
    1643            0 :          colvar_out%acid_hyd_shell_param%pcut = colvar_in%acid_hyd_shell_param%pcut
    1644            0 :          colvar_out%acid_hyd_shell_param%qcut = colvar_in%acid_hyd_shell_param%qcut
    1645            0 :          colvar_out%acid_hyd_shell_param%rwoh = colvar_in%acid_hyd_shell_param%rwoh
    1646            0 :          colvar_out%acid_hyd_shell_param%raoh = colvar_in%acid_hyd_shell_param%raoh
    1647            0 :          colvar_out%acid_hyd_shell_param%roo = colvar_in%acid_hyd_shell_param%roo
    1648            0 :          colvar_out%acid_hyd_shell_param%lambda = colvar_in%acid_hyd_shell_param%lambda
    1649            0 :          ndim = SIZE(colvar_in%acid_hyd_shell_param%i_oxygens_water)
    1650            0 :          ALLOCATE (colvar_out%acid_hyd_shell_param%i_oxygens_water(ndim))
    1651            0 :          ndim = SIZE(colvar_in%acid_hyd_shell_param%i_oxygens_acid)
    1652            0 :          ALLOCATE (colvar_out%acid_hyd_shell_param%i_oxygens_acid(ndim))
    1653            0 :          ndim = SIZE(colvar_in%acid_hyd_shell_param%i_hydrogens)
    1654            0 :          ALLOCATE (colvar_out%acid_hyd_shell_param%i_hydrogens(ndim))
    1655            0 :          colvar_out%acid_hyd_shell_param%i_oxygens_water = colvar_in%acid_hyd_shell_param%i_oxygens_water + my_offset
    1656            0 :          colvar_out%acid_hyd_shell_param%i_oxygens_acid = colvar_in%acid_hyd_shell_param%i_oxygens_acid + my_offset
    1657            0 :          colvar_out%acid_hyd_shell_param%i_hydrogens = colvar_in%acid_hyd_shell_param%i_hydrogens + my_offset
    1658              :       CASE (reaction_path_colvar_id, distance_from_path_colvar_id)
    1659            6 :          colvar_out%reaction_path_param%dist_rmsd = colvar_in%reaction_path_param%dist_rmsd
    1660            6 :          colvar_out%reaction_path_param%rmsd = colvar_in%reaction_path_param%rmsd
    1661            6 :          colvar_out%reaction_path_param%nr_frames = colvar_in%reaction_path_param%nr_frames
    1662            6 :          IF (colvar_in%reaction_path_param%dist_rmsd .OR. colvar_in%reaction_path_param%rmsd) THEN
    1663            0 :             colvar_out%reaction_path_param%align_frames = colvar_in%reaction_path_param%align_frames
    1664            0 :             colvar_out%reaction_path_param%subset = colvar_in%reaction_path_param%subset
    1665            0 :             ndim = SIZE(colvar_in%reaction_path_param%i_rmsd)
    1666            0 :             ALLOCATE (colvar_out%reaction_path_param%i_rmsd(ndim))
    1667            0 :             colvar_out%reaction_path_param%i_rmsd = colvar_in%reaction_path_param%i_rmsd
    1668            0 :             ndim = SIZE(colvar_in%reaction_path_param%r_ref, 1)
    1669            0 :             ndim2 = SIZE(colvar_in%reaction_path_param%r_ref, 2)
    1670            0 :             ALLOCATE (colvar_out%reaction_path_param%r_ref(ndim, ndim2))
    1671            0 :             colvar_out%reaction_path_param%r_ref = colvar_in%reaction_path_param%r_ref
    1672              :          ELSE
    1673            6 :             ndim = SIZE(colvar_in%reaction_path_param%colvar_p)
    1674           30 :             ALLOCATE (colvar_out%reaction_path_param%colvar_p(ndim))
    1675           18 :             DO i = 1, ndim
    1676              :                CALL colvar_clone(colvar_out%reaction_path_param%colvar_p(i)%colvar, &
    1677              :                                  colvar_in%reaction_path_param%colvar_p(i)%colvar, &
    1678           18 :                                  my_offset)
    1679              :             END DO
    1680           18 :             colvar_out%reaction_path_param%function_bounds = colvar_in%reaction_path_param%function_bounds
    1681            6 :             ndim = SIZE(colvar_in%reaction_path_param%f_vals, 1)
    1682            6 :             ndim2 = SIZE(colvar_in%reaction_path_param%f_vals, 2)
    1683           24 :             ALLOCATE (colvar_out%reaction_path_param%f_vals(ndim, ndim2))
    1684        70224 :             colvar_out%reaction_path_param%f_vals = colvar_in%reaction_path_param%f_vals
    1685              :          END IF
    1686            6 :          colvar_out%reaction_path_param%step_size = colvar_in%reaction_path_param%step_size
    1687            6 :          colvar_out%reaction_path_param%n_components = colvar_in%reaction_path_param%n_components
    1688            6 :          colvar_out%reaction_path_param%lambda = colvar_in%reaction_path_param%lambda
    1689              :       CASE (combine_colvar_id)
    1690            8 :          ndim = SIZE(colvar_in%combine_cvs_param%colvar_p)
    1691           40 :          ALLOCATE (colvar_out%combine_cvs_param%colvar_p(ndim))
    1692           24 :          DO i = 1, ndim
    1693              :             CALL colvar_clone(colvar_out%combine_cvs_param%colvar_p(i)%colvar, &
    1694              :                               colvar_in%combine_cvs_param%colvar_p(i)%colvar, &
    1695           24 :                               my_offset)
    1696              :          END DO
    1697            8 :          colvar_out%combine_cvs_param%lerr = colvar_in%combine_cvs_param%lerr
    1698            8 :          colvar_out%combine_cvs_param%dx = colvar_in%combine_cvs_param%dx
    1699            8 :          colvar_out%combine_cvs_param%function = colvar_in%combine_cvs_param%function
    1700              :          !
    1701            8 :          ndim = SIZE(colvar_in%combine_cvs_param%c_parameters)
    1702           24 :          ALLOCATE (colvar_out%combine_cvs_param%c_parameters(ndim))
    1703           16 :          colvar_out%combine_cvs_param%c_parameters = colvar_in%combine_cvs_param%c_parameters
    1704              :          !
    1705            8 :          ndim = SIZE(colvar_in%combine_cvs_param%v_parameters)
    1706           24 :          ALLOCATE (colvar_out%combine_cvs_param%v_parameters(ndim))
    1707           16 :          colvar_out%combine_cvs_param%v_parameters = colvar_in%combine_cvs_param%v_parameters
    1708              :          !
    1709            8 :          ndim = SIZE(colvar_in%combine_cvs_param%variables)
    1710           24 :          ALLOCATE (colvar_out%combine_cvs_param%variables(ndim))
    1711           24 :          colvar_out%combine_cvs_param%variables = colvar_in%combine_cvs_param%variables
    1712              :       CASE (rmsd_colvar_id)
    1713            0 :          colvar_out%rmsd_param%n_atoms = colvar_in%rmsd_param%n_atoms
    1714            0 :          colvar_out%rmsd_param%align_frames = colvar_in%rmsd_param%align_frames
    1715            0 :          colvar_out%rmsd_param%nr_frames = colvar_in%rmsd_param%nr_frames
    1716            0 :          colvar_out%rmsd_param%subset = colvar_in%rmsd_param%subset
    1717              :          ! INDEX
    1718            0 :          ndim = SIZE(colvar_in%rmsd_param%i_rmsd)
    1719            0 :          ALLOCATE (colvar_out%rmsd_param%i_rmsd(ndim))
    1720            0 :          colvar_out%rmsd_param%i_rmsd = colvar_in%rmsd_param%i_rmsd + my_offset
    1721              :          ! A and Bconfigurations and weights
    1722            0 :          ndim = SIZE(colvar_in%rmsd_param%weights)
    1723            0 :          ALLOCATE (colvar_out%rmsd_param%weights(ndim))
    1724            0 :          colvar_out%rmsd_param%weights = colvar_in%rmsd_param%weights
    1725            0 :          ndim = SIZE(colvar_in%rmsd_param%r_ref, 1)
    1726            0 :          ndim2 = SIZE(colvar_in%rmsd_param%r_ref, 2)
    1727            0 :          ALLOCATE (colvar_out%rmsd_param%r_ref(ndim, ndim2))
    1728            0 :          colvar_out%rmsd_param%r_ref = colvar_in%rmsd_param%r_ref
    1729              :       CASE (Wc_colvar_id)
    1730            0 :          colvar_out%Wc%ids = colvar_in%Wc%ids + my_offset
    1731            0 :          colvar_out%Wc%rcut = colvar_in%Wc%rcut
    1732              :       CASE (HBP_colvar_id)
    1733            0 :          ndim = colvar_out%HBP%nPoints
    1734            0 :          ALLOCATE (colvar_out%HBP%ids(ndim, 3))
    1735            0 :          ALLOCATE (colvar_out%HBP%ewc(ndim))
    1736            0 :          colvar_out%HBP%ids = colvar_in%HBP%ids + my_offset
    1737            0 :          colvar_out%HBP%ewc = colvar_in%HBP%ewc + my_offset
    1738            0 :          colvar_out%HBP%nPoints = colvar_in%HBP%nPoints
    1739            0 :          colvar_out%HBP%rcut = colvar_in%HBP%rcut
    1740            0 :          colvar_out%HBP%shift = colvar_in%HBP%shift
    1741              :       CASE (ring_puckering_colvar_id)
    1742            0 :          ndim = colvar_in%ring_puckering_param%nring
    1743            0 :          colvar_out%ring_puckering_param%nring = colvar_in%ring_puckering_param%nring
    1744            0 :          colvar_out%ring_puckering_param%iq = colvar_in%ring_puckering_param%iq
    1745            0 :          ALLOCATE (colvar_out%ring_puckering_param%atoms(ndim))
    1746            0 :          colvar_out%ring_puckering_param%atoms = colvar_in%ring_puckering_param%atoms + my_offset
    1747              :       CASE (mindist_colvar_id)
    1748            0 :          colvar_out%mindist_param%n_dist_from = colvar_in%mindist_param%n_dist_from
    1749            0 :          colvar_out%mindist_param%n_coord_to = colvar_in%mindist_param%n_coord_to
    1750            0 :          colvar_out%mindist_param%n_coord_from = colvar_in%mindist_param%n_coord_from
    1751            0 :          colvar_out%mindist_param%p_exp = colvar_in%mindist_param%p_exp
    1752            0 :          colvar_out%mindist_param%q_exp = colvar_in%mindist_param%q_exp
    1753            0 :          colvar_out%mindist_param%r_cut = colvar_in%mindist_param%r_cut
    1754            0 :          colvar_out%mindist_param%lambda = colvar_in%mindist_param%lambda
    1755            0 :          colvar_out%mindist_param%use_kinds_from = colvar_in%mindist_param%use_kinds_from
    1756            0 :          colvar_out%mindist_param%use_kinds_to = colvar_in%mindist_param%use_kinds_to
    1757              :          ! INDEX
    1758            0 :          ndim = SIZE(colvar_in%mindist_param%i_dist_from)
    1759            0 :          ALLOCATE (colvar_out%mindist_param%i_dist_from(ndim))
    1760            0 :          colvar_out%mindist_param%i_dist_from = colvar_in%mindist_param%i_dist_from + my_offset
    1761            0 :          IF (colvar_in%mindist_param%use_kinds_from) THEN
    1762              :             ! KINDS
    1763            0 :             ndim = SIZE(colvar_in%mindist_param%k_coord_from)
    1764            0 :             ALLOCATE (colvar_out%mindist_param%k_coord_from(ndim))
    1765            0 :             colvar_out%mindist_param%k_coord_from = colvar_in%mindist_param%k_coord_from
    1766              :          ELSE
    1767              :             ! INDEX
    1768            0 :             ndim = SIZE(colvar_in%mindist_param%i_coord_from)
    1769            0 :             ALLOCATE (colvar_out%mindist_param%i_coord_from(ndim))
    1770            0 :             colvar_out%mindist_param%i_coord_from = colvar_in%mindist_param%i_coord_from + my_offset
    1771              :          END IF
    1772         4992 :          IF (colvar_in%mindist_param%use_kinds_to) THEN
    1773              :             ! KINDS
    1774            0 :             ndim = SIZE(colvar_in%mindist_param%k_coord_to)
    1775            0 :             ALLOCATE (colvar_out%mindist_param%k_coord_to(ndim))
    1776            0 :             colvar_out%mindist_param%k_coord_to = colvar_in%mindist_param%k_coord_to
    1777              :          ELSE
    1778              :             ! INDEX
    1779            0 :             ndim = SIZE(colvar_in%mindist_param%i_coord_to)
    1780            0 :             ALLOCATE (colvar_out%mindist_param%i_coord_to(ndim))
    1781            0 :             colvar_out%mindist_param%i_coord_to = colvar_in%mindist_param%i_coord_to + my_offset
    1782              :          END IF
    1783              : 
    1784              :       END SELECT
    1785         4992 :       CALL colvar_setup(colvar_out)
    1786         4992 :    END SUBROUTINE colvar_clone
    1787              : 
    1788              : ! **************************************************************************************************
    1789              : !> \brief Clone points type of a colvar type
    1790              : !> \param colvar_out ...
    1791              : !> \param colvar_in the colvar to deallocate
    1792              : !> \param offset ...
    1793              : !> \author Teodoro Laino [tlaino] 03.2007
    1794              : ! **************************************************************************************************
    1795         4992 :    SUBROUTINE colvar_clone_points(colvar_out, colvar_in, offset)
    1796              :       TYPE(colvar_type), INTENT(INOUT)                   :: colvar_out
    1797              :       TYPE(colvar_type), INTENT(IN)                      :: colvar_in
    1798              :       INTEGER, INTENT(IN)                                :: offset
    1799              : 
    1800              :       INTEGER                                            :: i, natoms, npoints
    1801              : 
    1802         4992 :       colvar_out%use_points = colvar_in%use_points
    1803         4992 :       IF (colvar_in%use_points) THEN
    1804           74 :          CPASSERT(ASSOCIATED(colvar_in%points))
    1805           74 :          npoints = SIZE(colvar_in%points)
    1806          634 :          ALLOCATE (colvar_out%points(npoints))
    1807          264 :          DO i = 1, npoints
    1808          190 :             IF (ASSOCIATED(colvar_in%points(i)%atoms)) THEN
    1809          182 :                natoms = SIZE(colvar_in%points(i)%atoms)
    1810          546 :                ALLOCATE (colvar_out%points(i)%atoms(natoms))
    1811          444 :                colvar_out%points(i)%atoms = colvar_in%points(i)%atoms + offset
    1812              :             ELSE
    1813            8 :                NULLIFY (colvar_out%points(i)%atoms)
    1814              :             END IF
    1815          190 :             IF (ASSOCIATED(colvar_in%points(i)%weights)) THEN
    1816          182 :                natoms = SIZE(colvar_in%points(i)%weights)
    1817          546 :                ALLOCATE (colvar_out%points(i)%weights(natoms))
    1818          444 :                colvar_out%points(i)%weights = colvar_in%points(i)%weights
    1819              :             ELSE
    1820            8 :                NULLIFY (colvar_out%points(i)%weights)
    1821              :             END IF
    1822          190 :             colvar_out%points(i)%type_id = colvar_in%points(i)%type_id
    1823          834 :             colvar_out%points(i)%r = colvar_in%points(i)%r
    1824              :          END DO
    1825              :       ELSE
    1826         4918 :          NULLIFY (colvar_out%points)
    1827              :       END IF
    1828              : 
    1829         4992 :    END SUBROUTINE colvar_clone_points
    1830              : 
    1831              : ! **************************************************************************************************
    1832              : !> \brief Change the dimension of a colvar_p_type
    1833              : !> \param colvar_set ...
    1834              : !> \param lb1_new ...
    1835              : !> \param ub1_new ...
    1836              : !> \author Teodoro Laino [tlaino] 04.2006
    1837              : ! **************************************************************************************************
    1838           16 :    SUBROUTINE colvar_p_reallocate(colvar_set, lb1_new, ub1_new)
    1839              :       TYPE(colvar_p_type), DIMENSION(:), POINTER         :: colvar_set
    1840              :       INTEGER, INTENT(IN)                                :: lb1_new, ub1_new
    1841              : 
    1842              :       INTEGER                                            :: j, lb1, lb1_old, ub1, ub1_old
    1843           16 :       TYPE(colvar_p_type), DIMENSION(:), POINTER         :: work
    1844              : 
    1845           16 :       NULLIFY (work)
    1846           16 :       IF (ASSOCIATED(colvar_set)) THEN
    1847            0 :          lb1_old = LBOUND(colvar_set, 1)
    1848            0 :          ub1_old = UBOUND(colvar_set, 1)
    1849            0 :          lb1 = MAX(lb1_new, lb1_old)
    1850            0 :          ub1 = MIN(ub1_new, ub1_old)
    1851            0 :          ALLOCATE (work(lb1:ub1))
    1852            0 :          DO j = lb1, ub1
    1853            0 :             CALL colvar_clone(work(j)%colvar, colvar_set(j)%colvar)
    1854              :          END DO
    1855            0 :          DO j = lb1, ub1
    1856            0 :             CALL colvar_release(colvar_set(j)%colvar)
    1857              :          END DO
    1858            0 :          DEALLOCATE (colvar_set)
    1859              :       END IF
    1860              : 
    1861          228 :       ALLOCATE (colvar_set(lb1_new:ub1_new))
    1862              : 
    1863           16 :       IF (ASSOCIATED(work)) THEN
    1864            0 :          lb1 = MAX(lb1_new, lb1_old)
    1865            0 :          ub1 = MIN(ub1_new, ub1_old)
    1866            0 :          DO j = lb1, ub1
    1867            0 :             CALL colvar_clone(colvar_set(j)%colvar, work(j)%colvar)
    1868              :          END DO
    1869            0 :          DO j = lb1, ub1
    1870            0 :             CALL colvar_release(work(j)%colvar)
    1871              :          END DO
    1872            0 :          DEALLOCATE (work)
    1873              :       END IF
    1874           16 :    END SUBROUTINE colvar_p_reallocate
    1875              : 
    1876              : ! **************************************************************************************************
    1877              : !> \brief Deallocate a set of colvar_p_type
    1878              : !> \param colvar_p ...
    1879              : !> \par History
    1880              : !>      07.2003 created [fawzi]
    1881              : !>      01.2014 moved from cp_subsys_release() into separate routine.
    1882              : !> \author Ole Schuett
    1883              : ! **************************************************************************************************
    1884        11880 :    SUBROUTINE colvar_p_release(colvar_p)
    1885              :       TYPE(colvar_p_type), DIMENSION(:), POINTER         :: colvar_p
    1886              : 
    1887              :       INTEGER                                            :: i
    1888              : 
    1889              : ! Colvar info
    1890              : 
    1891        11880 :       IF (ASSOCIATED(colvar_p)) THEN
    1892        11797 :          DO i = 1, SIZE(colvar_p)
    1893        11797 :             IF (ASSOCIATED(colvar_p(i)%colvar)) THEN
    1894          474 :                CALL colvar_release(colvar_p(i)%colvar)
    1895              :             END IF
    1896              :          END DO
    1897        11323 :          DEALLOCATE (colvar_p)
    1898              :       END IF
    1899        11880 :    END SUBROUTINE colvar_p_release
    1900              : 
    1901              : ! **************************************************************************************************
    1902              : !> \brief Evaluate the position of the geometrical point
    1903              : !> \param point ...
    1904              : !> \param particles ...
    1905              : !> \param r ...
    1906              : !> \author Teodoro Laino - 03.2007
    1907              : ! **************************************************************************************************
    1908         8644 :    SUBROUTINE eval_point_pos(point, particles, r)
    1909              :       TYPE(point_type), INTENT(IN)                       :: point
    1910              :       TYPE(particle_type), DIMENSION(:), INTENT(IN)      :: particles
    1911              :       REAL(KIND=dp), DIMENSION(3), INTENT(OUT)           :: r
    1912              : 
    1913              :       INTEGER                                            :: i
    1914              : 
    1915        17186 :       SELECT CASE (point%type_id)
    1916              :       CASE (do_clv_geo_center)
    1917         8542 :          r = 0.0_dp
    1918        18088 :          DO i = 1, SIZE(point%atoms)
    1919        46726 :             r = r + particles(point%atoms(i))%r*point%weights(i)
    1920              :          END DO
    1921              :       CASE (do_clv_fix_point)
    1922         9052 :          r = point%r
    1923              :       END SELECT
    1924              : 
    1925         8644 :    END SUBROUTINE eval_point_pos
    1926              : 
    1927              : ! **************************************************************************************************
    1928              : !> \brief ...
    1929              : !> \param point ...
    1930              : !> \param particles ...
    1931              : !> \param m ...
    1932              : ! **************************************************************************************************
    1933            0 :    SUBROUTINE eval_point_mass(point, particles, m)
    1934              :       TYPE(point_type), INTENT(IN)                       :: point
    1935              :       TYPE(particle_type), DIMENSION(:), INTENT(IN)      :: particles
    1936              :       REAL(KIND=dp), INTENT(OUT)                         :: m
    1937              : 
    1938              :       INTEGER                                            :: i
    1939              : 
    1940            0 :       SELECT CASE (point%type_id)
    1941              :       CASE (do_clv_geo_center)
    1942            0 :          m = 0.0_dp
    1943            0 :          DO i = 1, SIZE(point%atoms)
    1944            0 :             m = m + particles(point%atoms(i))%atomic_kind%mass*point%weights(i)
    1945              :          END DO
    1946              :       CASE (do_clv_fix_point)
    1947            0 :          m = 0.0_dp
    1948              :       END SELECT
    1949              : 
    1950            0 :    END SUBROUTINE eval_point_mass
    1951              : 
    1952              : ! **************************************************************************************************
    1953              : !> \brief Evaluate the position of the geometrical point
    1954              : !> \param points ...
    1955              : !> \param i ...
    1956              : !> \param dsdr ...
    1957              : !> \param f ...
    1958              : !> \author Teodoro Laino - 03.2007
    1959              : ! **************************************************************************************************
    1960         8664 :    SUBROUTINE eval_point_der(points, i, dsdr, f)
    1961              :       TYPE(point_type), DIMENSION(:), INTENT(IN)         :: points
    1962              :       INTEGER, INTENT(IN)                                :: i
    1963              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT)      :: dsdr
    1964              :       REAL(KIND=dp), DIMENSION(3), INTENT(IN)            :: f
    1965              : 
    1966              :       INTEGER                                            :: ind, j
    1967              :       REAL(KIND=dp)                                      :: fac
    1968              : 
    1969         8664 :       SELECT CASE (points(i)%type_id)
    1970              :       CASE (do_clv_geo_center)
    1971              :          ind = 0
    1972        17054 :          DO j = 1, i - 1
    1973        17054 :             IF (ASSOCIATED(points(j)%atoms)) THEN
    1974         8492 :                ind = ind + SIZE(points(j)%atoms)
    1975              :             END IF
    1976              :          END DO
    1977        26792 :          DO j = 1, SIZE(points(i)%atoms)
    1978         9566 :             fac = points(i)%weights(j)
    1979        46826 :             dsdr(:, ind + j) = dsdr(:, ind + j) + f*fac
    1980              :          END DO
    1981              :       CASE (do_clv_fix_point)
    1982              :          ! Do nothing if it's a fixed point in space
    1983              :       END SELECT
    1984              : 
    1985         8664 :    END SUBROUTINE eval_point_der
    1986              : 
    1987              : ! **************************************************************************************************
    1988              : !> \brief subtract b from the ss value of a colvar: general function for handling
    1989              : !>        periodic/non-periodic colvar
    1990              : !> \param colvar ...
    1991              : !> \param b ...
    1992              : !> \return ...
    1993              : !> \author Teodoro Laino [tlaino] - University of Zurich 10.2008
    1994              : ! **************************************************************************************************
    1995       366777 :    FUNCTION diff_colvar(colvar, b) RESULT(diff)
    1996              :       TYPE(colvar_type), INTENT(IN)                      :: colvar
    1997              :       REAL(KIND=dp), INTENT(IN)                          :: b
    1998              :       REAL(KIND=dp)                                      :: diff
    1999              : 
    2000       366777 :       diff = colvar%ss - b
    2001       366777 :       IF (colvar%type_id == torsion_colvar_id) THEN
    2002              :          ! The difference of a periodic COLVAR is always within [-pi,pi]
    2003         1584 :          diff = SIGN(1.0_dp, ASIN(SIN(diff)))*ACOS(COS(diff))
    2004              :       END IF
    2005       366777 :    END FUNCTION diff_colvar
    2006              : 
    2007            0 : END MODULE colvar_types
        

Generated by: LCOV version 2.0-1