LCOV - code coverage report
Current view: top level - src/motion/mc - mc_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 91.4 % 856 782
Test Date: 2026-11-24 01:22:08 Functions: 58.3 % 24 14

            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 holds all the structure types needed for Monte Carlo, except
      10              : !>      the mc_environment_type
      11              : !> \par History
      12              : !>      none
      13              : !> \author MJM
      14              : ! **************************************************************************************************
      15              : MODULE mc_types
      16              :    USE atomic_kind_types,               ONLY: atomic_kind_type,&
      17              :                                               get_atomic_kind
      18              :    USE cell_types,                      ONLY: cell_type,&
      19              :                                               get_cell
      20              :    USE cp_files,                        ONLY: close_file,&
      21              :                                               open_file
      22              :    USE cp_log_handling,                 ONLY: cp_logger_get_default_io_unit
      23              :    USE cp_subsys_types,                 ONLY: cp_subsys_get,&
      24              :                                               cp_subsys_type
      25              :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      26              :    USE fist_environment_types,          ONLY: fist_env_get,&
      27              :                                               fist_environment_type
      28              :    USE fist_nonbond_env_types,          ONLY: fist_nonbond_env_get,&
      29              :                                               fist_nonbond_env_type
      30              :    USE force_env_types,                 ONLY: force_env_get,&
      31              :                                               force_env_p_type,&
      32              :                                               force_env_type,&
      33              :                                               use_fist_force,&
      34              :                                               use_qs_force
      35              :    USE input_constants,                 ONLY: do_fist,&
      36              :                                               do_qs
      37              :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      38              :                                               section_vals_type,&
      39              :                                               section_vals_val_get,&
      40              :                                               section_vals_val_set
      41              :    USE kinds,                           ONLY: default_path_length,&
      42              :                                               default_string_length,&
      43              :                                               dp
      44              :    USE mathconstants,                   ONLY: pi
      45              :    USE message_passing,                 ONLY: mp_comm_type,&
      46              :                                               mp_para_env_type
      47              :    USE molecule_kind_list_types,        ONLY: molecule_kind_list_p_type
      48              :    USE molecule_kind_types,             ONLY: atom_type,&
      49              :                                               get_molecule_kind,&
      50              :                                               molecule_kind_type
      51              :    USE pair_potential_types,            ONLY: pair_potential_pp_type
      52              :    USE particle_list_types,             ONLY: particle_list_p_type
      53              :    USE physcon,                         ONLY: boltzmann,&
      54              :                                               joule
      55              :    USE string_utilities,                ONLY: uppercase,&
      56              :                                               xstring
      57              : #include "../../base/base_uses.f90"
      58              : 
      59              :    IMPLICIT NONE
      60              : 
      61              :    PRIVATE
      62              : 
      63              : ! *** Global parameters ***
      64              : 
      65              :    PUBLIC :: mc_simpar_type, &
      66              :              mc_simulation_parameters_p_type, &
      67              :              mc_averages_type, mc_averages_p_type, &
      68              :              mc_moves_type, mc_moves_p_type, accattempt, &
      69              :              get_mc_par, set_mc_par, read_mc_section, &
      70              :              find_mc_rcut, mc_molecule_info_type, &
      71              :              mc_determine_molecule_info, mc_molecule_info_destroy, &
      72              :              mc_sim_par_create, mc_sim_par_destroy, &
      73              :              get_mc_molecule_info, &
      74              :              mc_input_file_type, mc_input_file_create, &
      75              :              get_mc_input_file, mc_input_file_destroy, &
      76              :              mc_input_parameters_check, &
      77              :              mc_ekin_type
      78              : 
      79              : ! **************************************************************************************************
      80              :    TYPE mc_simpar_type
      81              : ! contains all the parameters needed for running Monte Carlo simulations
      82              :       PRIVATE
      83              :       INTEGER, DIMENSION(:), POINTER :: avbmc_atom => NULL()
      84              :       INTEGER :: nstep = 0
      85              :       INTEGER :: iupvolume = 0
      86              :       INTEGER :: iuptrans = 0
      87              :       INTEGER :: iupcltrans = 0
      88              :       INTEGER :: nvirial = 0
      89              :       INTEGER :: nbox = 0
      90              :       INTEGER :: nmoves = 0
      91              :       INTEGER :: nswapmoves = 0
      92              :       INTEGER :: rm = 0
      93              :       INTEGER :: cl = 0
      94              :       INTEGER :: diff = 0
      95              :       INTEGER :: nstart = 0
      96              :       INTEGER :: source = 0
      97              :       TYPE(mp_comm_type) :: group = mp_comm_type()
      98              :       INTEGER :: iprint = 0
      99              :       LOGICAL :: ldiscrete = .FALSE.
     100              :       LOGICAL :: lbias = .FALSE.
     101              :       LOGICAL :: ionode = .FALSE.
     102              :       LOGICAL :: lrestart = .FALSE.
     103              :       LOGICAL :: lstop = .FALSE.
     104              :       LOGICAL :: lhmc = .FALSE.
     105              :       CHARACTER(LEN=20) :: ensemble = ""
     106              :       CHARACTER(LEN=default_path_length) :: restart_file_name = ""
     107              :       CHARACTER(LEN=default_path_length) :: molecules_file = ""
     108              :       CHARACTER(LEN=default_path_length) :: moves_file = ""
     109              :       CHARACTER(LEN=default_path_length) :: coords_file = ""
     110              :       CHARACTER(LEN=default_path_length) :: energy_file = ""
     111              :       CHARACTER(LEN=default_path_length) :: displacement_file = ""
     112              :       CHARACTER(LEN=default_path_length) :: cell_file = ""
     113              :       CHARACTER(LEN=default_path_length) :: dat_file = ""
     114              :       CHARACTER(LEN=default_path_length) :: data_file = ""
     115              :       CHARACTER(LEN=default_path_length) :: box2_file = ""
     116              :       CHARACTER(LEN=50) :: PROGRAM = ""
     117              :       REAL(dp), DIMENSION(:), POINTER :: pmtraion_mol => NULL(), pmtrans_mol => NULL(), &
     118              :                                          pmrot_mol => NULL(), pmswap_mol => NULL(), &
     119              :                                          pbias => NULL(), pmavbmc_mol => NULL()
     120              :       REAL(dp) :: discrete_step = 0.0_dp
     121              :       REAL(dp) :: rmvolume = 0.0_dp, rmcltrans = 0.0_dp
     122              :       REAL(dp), DIMENSION(:), POINTER :: rmbond => NULL(), rmangle => NULL(), rmdihedral => NULL(), &
     123              :                                          rmrot => NULL(), rmtrans => NULL()
     124              :       REAL(dp), DIMENSION(:), POINTER :: eta => NULL()
     125              :       REAL(dp) :: temperature = 0.0_dp
     126              :       REAL(dp) :: pressure = 0.0_dp
     127              :       REAL(dp) :: rclus = 0.0_dp
     128              :       REAL(dp) :: pmavbmc = 0.0_dp
     129              :       REAL(dp) :: pmswap = 0.0_dp
     130              :       REAL(dp) :: pmvolume = 0.0_dp, pmvol_box = 0.0_dp, pmclus_box = 0.0_dp
     131              :       REAL(dp) :: pmhmc = 0.0_dp, pmhmc_box = 0.0_dp
     132              :       REAL(dp) :: pmtraion = 0.0_dp
     133              :       REAL(dp) :: pmtrans = 0.0_dp
     134              :       REAL(dp) :: pmcltrans = 0.0_dp
     135              :       REAL(dp) :: BETA = 0.0_dp
     136              :       REAL(dp) :: rcut = 0.0_dp
     137              :       REAL(dp), DIMENSION(:), POINTER :: avbmc_rmin => NULL(), avbmc_rmax => NULL()
     138              :       REAL(dp), DIMENSION(:), POINTER :: virial_temps => NULL()
     139              :       TYPE(mc_input_file_type), POINTER :: &
     140              :          mc_input_file => NULL(), mc_bias_file => NULL()
     141              :       TYPE(section_vals_type), POINTER :: input_file => NULL()
     142              :       TYPE(mc_molecule_info_type), POINTER :: mc_molecule_info => NULL()
     143              :       REAL(dp) :: exp_min_val = 0.0_dp, exp_max_val = 0.0_dp, min_val = 0.0_dp, max_val = 0.0_dp
     144              :       INTEGER     :: rand2skip = 0
     145              :    END TYPE mc_simpar_type
     146              : 
     147              : ! **************************************************************************************************
     148              :    TYPE mc_ekin_type
     149              : ! contains the kinetic energy of an MD sequence from hybrid MC
     150              :       REAL(dp) :: initial_ekin = 0.0_dp, final_ekin = 0.0_dp
     151              :    END TYPE mc_ekin_type
     152              : ! **************************************************************************************************
     153              :    TYPE mc_input_file_type
     154              : ! contains all the text of the input file
     155              :       PRIVATE
     156              :       INTEGER :: run_type_row = 0, run_type_column = 0, coord_row_start = 0, coord_row_end = 0, &
     157              :                  cell_row = 0, cell_column = 0, force_eval_row_start = 0, force_eval_row_end = 0, &
     158              :                  global_row_start = 0, global_row_end = 0, in_use = 0, nunits_empty = 0, &
     159              :                  motion_row_end = 0, motion_row_start = 0
     160              :       INTEGER, DIMENSION(:), POINTER :: mol_set_nmol_row => NULL(), mol_set_nmol_column => NULL()
     161              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: text => NULL()
     162              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: atom_names_empty => NULL()
     163              :       REAL(dp), DIMENSION(:, :), POINTER :: coordinates_empty => NULL()
     164              :    END TYPE mc_input_file_type
     165              : 
     166              : ! **************************************************************************************************
     167              :    TYPE mc_molecule_info_type
     168              : ! contains information on molecules...I had to do this because I use multiple force
     169              : ! environments, and they know nothing about each other
     170              :       PRIVATE
     171              :       INTEGER :: nboxes = 0
     172              :       CHARACTER(LEN=default_string_length), DIMENSION(:), POINTER :: names => NULL()
     173              :       CHARACTER(LEN=default_string_length), &
     174              :          DIMENSION(:, :), POINTER :: atom_names => NULL()
     175              :       REAL(dp), DIMENSION(:, :), POINTER :: conf_prob => NULL(), mass => NULL()
     176              :       INTEGER, DIMENSION(:, :), POINTER :: nchains => NULL()
     177              :       INTEGER :: nmol_types = 0, nchain_total = 0
     178              :       INTEGER, DIMENSION(:), POINTER :: nunits => NULL(), mol_type => NULL(), nunits_tot => NULL(), in_box => NULL()
     179              :    END TYPE mc_molecule_info_type
     180              : 
     181              : ! **************************************************************************************************
     182              :    TYPE mc_simulation_parameters_p_type
     183              : ! a pointer for multiple boxes
     184              :       TYPE(mc_simpar_type), POINTER :: mc_par => NULL()
     185              :    END TYPE mc_simulation_parameters_p_type
     186              : 
     187              : ! **************************************************************************************************
     188              :    TYPE mc_averages_type
     189              : ! contains some data that is averaged throughout the course of a run
     190              :       REAL(KIND=dp) :: ave_energy = 0.0_dp
     191              :       REAL(KIND=dp) :: ave_energy_squared = 0.0_dp
     192              :       REAL(KIND=dp) :: ave_volume = 0.0_dp
     193              :       REAL(KIND=dp) :: molecules = 0.0_dp
     194              :    END TYPE mc_averages_type
     195              : 
     196              : ! **************************************************************************************************
     197              :    TYPE mc_averages_p_type
     198              :       TYPE(mc_averages_type), POINTER :: averages => NULL()
     199              :    END TYPE mc_averages_p_type
     200              : 
     201              : ! **************************************************************************************************
     202              :    TYPE mc_moves_type
     203              : ! contains data for how many moves of a give type we've accepted/rejected
     204              :       TYPE(accattempt), POINTER :: bias_bond => NULL()
     205              :       TYPE(accattempt), POINTER :: bias_angle => NULL()
     206              :       TYPE(accattempt), POINTER :: bias_dihedral => NULL()
     207              :       TYPE(accattempt), POINTER :: bias_trans => NULL()
     208              :       TYPE(accattempt), POINTER :: bias_cltrans => NULL()
     209              :       TYPE(accattempt), POINTER :: bias_rot => NULL()
     210              :       TYPE(accattempt), POINTER :: bond => NULL()
     211              :       TYPE(accattempt), POINTER :: angle => NULL()
     212              :       TYPE(accattempt), POINTER :: dihedral => NULL()
     213              :       TYPE(accattempt), POINTER :: trans => NULL()
     214              :       TYPE(accattempt), POINTER :: cltrans => NULL()
     215              :       TYPE(accattempt), POINTER :: rot => NULL()
     216              :       TYPE(accattempt), POINTER :: swap => NULL()
     217              :       TYPE(accattempt), POINTER :: volume => NULL()
     218              :       TYPE(accattempt), POINTER :: hmc => NULL()
     219              :       TYPE(accattempt), POINTER :: avbmc_inin => NULL()
     220              :       TYPE(accattempt), POINTER :: avbmc_outin => NULL()
     221              :       TYPE(accattempt), POINTER :: avbmc_inout => NULL()
     222              :       TYPE(accattempt), POINTER :: avbmc_outout => NULL()
     223              :       TYPE(accattempt), POINTER :: Quickstep => NULL()
     224              :       REAL(KIND=dp) :: trans_dis = 0.0_dp, qtrans_dis = 0.0_dp
     225              :       REAL(KIND=dp) :: cltrans_dis = 0.0_dp, qcltrans_dis = 0.0_dp
     226              :       INTEGER :: empty = 0, grown = 0, empty_conf = 0, empty_avbmc = 0
     227              :    END TYPE mc_moves_type
     228              : 
     229              : ! **************************************************************************************************
     230              :    TYPE accattempt
     231              :       INTEGER :: successes = 0
     232              :       INTEGER :: qsuccesses = 0
     233              :       INTEGER :: attempts = 0
     234              :    END TYPE accattempt
     235              : 
     236              : ! **************************************************************************************************
     237              :    TYPE mc_moves_p_type
     238              :       TYPE(mc_moves_type), POINTER :: moves => NULL()
     239              :    END TYPE mc_moves_p_type
     240              : 
     241              : ! *** Global parameters ***
     242              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mc_types'
     243              : 
     244              : CONTAINS
     245              : 
     246              : ! **************************************************************************************************
     247              : !> \brief accesses the private elements of the mc_input_file_type
     248              : !> \param mc_input_file the input file you want data for
     249              : !>
     250              : !>    Suitable for parallel.
     251              : !> \param run_type_row ...
     252              : !> \param run_type_column ...
     253              : !> \param coord_row_start ...
     254              : !> \param coord_row_end ...
     255              : !> \param cell_row ...
     256              : !> \param cell_column ...
     257              : !> \param force_eval_row_start ...
     258              : !> \param force_eval_row_end ...
     259              : !> \param global_row_start ...
     260              : !> \param global_row_end ...
     261              : !> \param mol_set_nmol_row ...
     262              : !> \param mol_set_nmol_column ...
     263              : !> \param in_use ...
     264              : !> \param text ...
     265              : !> \param atom_names_empty ...
     266              : !> \param nunits_empty ...
     267              : !> \param coordinates_empty ...
     268              : !> \param motion_row_end ...
     269              : !> \param motion_row_start ...
     270              : !> \author MJM
     271              : ! **************************************************************************************************
     272          102 :    SUBROUTINE get_mc_input_file(mc_input_file, run_type_row, run_type_column, &
     273              :                                 coord_row_start, coord_row_end, cell_row, cell_column, &
     274              :                                 force_eval_row_start, force_eval_row_end, global_row_start, global_row_end, &
     275              :                                 mol_set_nmol_row, mol_set_nmol_column, in_use, text, atom_names_empty, &
     276              :                                 nunits_empty, coordinates_empty, motion_row_end, motion_row_start)
     277              : 
     278              :       TYPE(mc_input_file_type), POINTER                  :: mc_input_file
     279              :       INTEGER, INTENT(OUT), OPTIONAL :: run_type_row, run_type_column, coord_row_start, &
     280              :          coord_row_end, cell_row, cell_column, force_eval_row_start, force_eval_row_end, &
     281              :          global_row_start, global_row_end
     282              :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: mol_set_nmol_row, mol_set_nmol_column
     283              :       INTEGER, INTENT(OUT), OPTIONAL                     :: in_use
     284              :       CHARACTER(LEN=default_string_length), &
     285              :          DIMENSION(:), OPTIONAL, POINTER                 :: text, atom_names_empty
     286              :       INTEGER, INTENT(OUT), OPTIONAL                     :: nunits_empty
     287              :       REAL(dp), DIMENSION(:, :), OPTIONAL, POINTER       :: coordinates_empty
     288              :       INTEGER, INTENT(OUT), OPTIONAL                     :: motion_row_end, motion_row_start
     289              : 
     290          102 :       IF (PRESENT(in_use)) in_use = mc_input_file%in_use
     291          102 :       IF (PRESENT(run_type_row)) run_type_row = mc_input_file%run_type_row
     292          102 :       IF (PRESENT(run_type_column)) run_type_column = mc_input_file%run_type_column
     293          102 :       IF (PRESENT(coord_row_start)) coord_row_start = mc_input_file%coord_row_start
     294          102 :       IF (PRESENT(coord_row_end)) coord_row_end = mc_input_file%coord_row_end
     295          102 :       IF (PRESENT(cell_row)) cell_row = mc_input_file%cell_row
     296          102 :       IF (PRESENT(cell_column)) cell_column = mc_input_file%cell_column
     297          102 :       IF (PRESENT(force_eval_row_start)) force_eval_row_start = mc_input_file%force_eval_row_start
     298          102 :       IF (PRESENT(force_eval_row_end)) force_eval_row_end = mc_input_file%force_eval_row_end
     299          102 :       IF (PRESENT(global_row_start)) global_row_start = mc_input_file%global_row_start
     300          102 :       IF (PRESENT(global_row_end)) global_row_end = mc_input_file%global_row_end
     301          102 :       IF (PRESENT(nunits_empty)) nunits_empty = mc_input_file%nunits_empty
     302          102 :       IF (PRESENT(motion_row_start)) motion_row_start = mc_input_file%motion_row_start
     303          102 :       IF (PRESENT(motion_row_end)) motion_row_end = mc_input_file%motion_row_end
     304              : 
     305          102 :       IF (PRESENT(mol_set_nmol_row)) mol_set_nmol_row => mc_input_file%mol_set_nmol_row
     306          102 :       IF (PRESENT(mol_set_nmol_column)) mol_set_nmol_column => mc_input_file%mol_set_nmol_column
     307          102 :       IF (PRESENT(text)) text => mc_input_file%text
     308          102 :       IF (PRESENT(atom_names_empty)) atom_names_empty => mc_input_file%atom_names_empty
     309          102 :       IF (PRESENT(coordinates_empty)) coordinates_empty => mc_input_file%coordinates_empty
     310              : 
     311          102 :    END SUBROUTINE GET_MC_INPUT_FILE
     312              : ! **************************************************************************************************
     313              : !> \brief ...
     314              : !> \param mc_par ...
     315              : !> \param nstep ...
     316              : !> \param nvirial ...
     317              : !> \param iuptrans ...
     318              : !> \param iupcltrans ...
     319              : !> \param iupvolume ...
     320              : !> \param nmoves ...
     321              : !> \param nswapmoves ...
     322              : !> \param rm ...
     323              : !> \param cl ...
     324              : !> \param diff ...
     325              : !> \param nstart ...
     326              : !> \param source ...
     327              : !> \param group ...
     328              : !> \param lbias ...
     329              : !> \param ionode ...
     330              : !> \param lrestart ...
     331              : !> \param lstop ...
     332              : !> \param rmvolume ...
     333              : !> \param rmcltrans ...
     334              : !> \param rmbond ...
     335              : !> \param rmangle ...
     336              : !> \param rmrot ...
     337              : !> \param rmtrans ...
     338              : !> \param temperature ...
     339              : !> \param pressure ...
     340              : !> \param rclus ...
     341              : !> \param BETA ...
     342              : !> \param pmswap ...
     343              : !> \param pmvolume ...
     344              : !> \param pmtraion ...
     345              : !> \param pmtrans ...
     346              : !> \param pmcltrans ...
     347              : !> \param ensemble ...
     348              : !> \param PROGRAM ...
     349              : !> \param restart_file_name ...
     350              : !> \param molecules_file ...
     351              : !> \param moves_file ...
     352              : !> \param coords_file ...
     353              : !> \param energy_file ...
     354              : !> \param displacement_file ...
     355              : !> \param cell_file ...
     356              : !> \param dat_file ...
     357              : !> \param data_file ...
     358              : !> \param box2_file ...
     359              : !> \param iprint ...
     360              : !> \param rcut ...
     361              : !> \param ldiscrete ...
     362              : !> \param discrete_step ...
     363              : !> \param pmavbmc ...
     364              : !> \param pbias ...
     365              : !> \param avbmc_atom ...
     366              : !> \param avbmc_rmin ...
     367              : !> \param avbmc_rmax ...
     368              : !> \param rmdihedral ...
     369              : !> \param input_file ...
     370              : !> \param mc_molecule_info ...
     371              : !> \param pmswap_mol ...
     372              : !> \param pmavbmc_mol ...
     373              : !> \param pmtrans_mol ...
     374              : !> \param pmrot_mol ...
     375              : !> \param pmtraion_mol ...
     376              : !> \param mc_input_file ...
     377              : !> \param mc_bias_file ...
     378              : !> \param pmvol_box ...
     379              : !> \param pmclus_box ...
     380              : !> \param virial_temps ...
     381              : !> \param exp_min_val ...
     382              : !> \param exp_max_val ...
     383              : !> \param min_val ...
     384              : !> \param max_val ...
     385              : !> \param eta ...
     386              : !> \param pmhmc ...
     387              : !> \param pmhmc_box ...
     388              : !> \param lhmc ...
     389              : !> \param rand2skip ...
     390              : ! **************************************************************************************************
     391         2646 :    SUBROUTINE get_mc_par(mc_par, nstep, nvirial, iuptrans, iupcltrans, iupvolume, &
     392              :                          nmoves, nswapmoves, rm, cl, diff, nstart, &
     393              :                          source, group, lbias, ionode, lrestart, lstop, rmvolume, rmcltrans, rmbond, rmangle, &
     394              :                          rmrot, rmtrans, temperature, pressure, rclus, BETA, pmswap, pmvolume, pmtraion, pmtrans, &
     395              :                          pmcltrans, ensemble, PROGRAM, restart_file_name, molecules_file, moves_file, coords_file, &
     396              :                          energy_file, displacement_file, cell_file, dat_file, data_file, box2_file, &
     397              :                          iprint, rcut, ldiscrete, discrete_step, &
     398              :                          pmavbmc, pbias, avbmc_atom, avbmc_rmin, avbmc_rmax, rmdihedral, &
     399              :                          input_file, mc_molecule_info, pmswap_mol, pmavbmc_mol, pmtrans_mol, pmrot_mol, &
     400              :                          pmtraion_mol, mc_input_file, mc_bias_file, pmvol_box, pmclus_box, virial_temps, &
     401              :                          exp_min_val, exp_max_val, min_val, max_val, eta, pmhmc, pmhmc_box, lhmc, rand2skip)
     402              : 
     403              : ! **************************************************************************************************
     404              : !> \brief accesses the private elements of the mc_parameters_type
     405              : !> \param mc_par the structure mc parameters you want
     406              : !>
     407              : !>    Suitable for parallel.
     408              : !> \author MJM
     409              :       TYPE(mc_simpar_type), POINTER                      :: mc_par
     410              :       INTEGER, INTENT(OUT), OPTIONAL                     :: nstep, nvirial, iuptrans, iupcltrans, &
     411              :                                                             iupvolume, nmoves, nswapmoves, rm, cl, &
     412              :                                                             diff, nstart, source
     413              :       TYPE(mp_comm_type), INTENT(OUT), OPTIONAL          :: group
     414              :       LOGICAL, INTENT(OUT), OPTIONAL                     :: lbias, ionode, lrestart, lstop
     415              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: rmvolume, rmcltrans
     416              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: rmbond, rmangle, rmrot, rmtrans
     417              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: temperature, pressure, rclus, BETA, &
     418              :                                                             pmswap, pmvolume, pmtraion, pmtrans, &
     419              :                                                             pmcltrans
     420              :       CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: ensemble, PROGRAM, restart_file_name, &
     421              :          molecules_file, moves_file, coords_file, energy_file, displacement_file, cell_file, &
     422              :          dat_file, data_file, box2_file
     423              :       INTEGER, INTENT(OUT), OPTIONAL                     :: iprint
     424              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: rcut
     425              :       LOGICAL, INTENT(OUT), OPTIONAL                     :: ldiscrete
     426              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: discrete_step, pmavbmc
     427              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: pbias
     428              :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: avbmc_atom
     429              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: avbmc_rmin, avbmc_rmax, rmdihedral
     430              :       TYPE(section_vals_type), OPTIONAL, POINTER         :: input_file
     431              :       TYPE(mc_molecule_info_type), OPTIONAL, POINTER     :: mc_molecule_info
     432              :       REAL(dp), DIMENSION(:), OPTIONAL, POINTER          :: pmswap_mol
     433              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: pmavbmc_mol, pmtrans_mol, pmrot_mol, &
     434              :                                                             pmtraion_mol
     435              :       TYPE(mc_input_file_type), OPTIONAL, POINTER        :: mc_input_file, mc_bias_file
     436              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: pmvol_box, pmclus_box
     437              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: virial_temps
     438              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: exp_min_val, exp_max_val, min_val, &
     439              :                                                             max_val
     440              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: eta
     441              :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: pmhmc, pmhmc_box
     442              :       LOGICAL, INTENT(OUT), OPTIONAL                     :: lhmc
     443              :       INTEGER, INTENT(OUT), OPTIONAL                     :: rand2skip
     444              : 
     445         3295 :       IF (PRESENT(nstep)) nstep = mc_par%nstep
     446         3295 :       IF (PRESENT(nvirial)) nvirial = mc_par%nvirial
     447         3295 :       IF (PRESENT(iuptrans)) iuptrans = mc_par%iuptrans
     448         3295 :       IF (PRESENT(iupcltrans)) iupcltrans = mc_par%iupcltrans
     449         3295 :       IF (PRESENT(iupvolume)) iupvolume = mc_par%iupvolume
     450         3295 :       IF (PRESENT(nmoves)) nmoves = mc_par%nmoves
     451         3295 :       IF (PRESENT(nswapmoves)) nswapmoves = mc_par%nswapmoves
     452         3295 :       IF (PRESENT(rm)) rm = mc_par%rm
     453         3295 :       IF (PRESENT(cl)) cl = mc_par%cl
     454         3295 :       IF (PRESENT(diff)) diff = mc_par%diff
     455         3295 :       IF (PRESENT(nstart)) nstart = mc_par%nstart
     456         3295 :       IF (PRESENT(source)) source = mc_par%source
     457         3295 :       IF (PRESENT(group)) group = mc_par%group
     458         3295 :       IF (PRESENT(iprint)) iprint = mc_par%iprint
     459              : 
     460         3295 :       IF (PRESENT(lbias)) lbias = mc_par%lbias
     461         3295 :       IF (PRESENT(ionode)) ionode = mc_par%ionode
     462         3295 :       IF (PRESENT(lrestart)) lrestart = mc_par%lrestart
     463         3295 :       IF (PRESENT(lstop)) lstop = mc_par%lstop
     464         3295 :       IF (PRESENT(ldiscrete)) ldiscrete = mc_par%ldiscrete
     465              : 
     466         3295 :       IF (PRESENT(virial_temps)) virial_temps => mc_par%virial_temps
     467         3295 :       IF (PRESENT(avbmc_atom)) avbmc_atom => mc_par%avbmc_atom
     468         3295 :       IF (PRESENT(avbmc_rmin)) avbmc_rmin => mc_par%avbmc_rmin
     469         3295 :       IF (PRESENT(avbmc_rmax)) avbmc_rmax => mc_par%avbmc_rmax
     470         3295 :       IF (PRESENT(rcut)) rcut = mc_par%rcut
     471         3295 :       IF (PRESENT(discrete_step)) discrete_step = mc_par%discrete_step
     472         3295 :       IF (PRESENT(rmvolume)) rmvolume = mc_par%rmvolume
     473         3295 :       IF (PRESENT(rmcltrans)) rmcltrans = mc_par%rmcltrans
     474         3295 :       IF (PRESENT(temperature)) temperature = mc_par%temperature
     475         3295 :       IF (PRESENT(pressure)) pressure = mc_par%pressure
     476         3295 :       IF (PRESENT(rclus)) rclus = mc_par%rclus
     477         3295 :       IF (PRESENT(BETA)) BETA = mc_par%BETA
     478         3295 :       IF (PRESENT(exp_max_val)) exp_max_val = mc_par%exp_max_val
     479         3295 :       IF (PRESENT(exp_min_val)) exp_min_val = mc_par%exp_min_val
     480         3295 :       IF (PRESENT(max_val)) max_val = mc_par%max_val
     481         3295 :       IF (PRESENT(min_val)) min_val = mc_par%min_val
     482         3295 :       IF (PRESENT(pmswap)) pmswap = mc_par%pmswap
     483         3295 :       IF (PRESENT(pmvolume)) pmvolume = mc_par%pmvolume
     484         3295 :       IF (PRESENT(lhmc)) lhmc = mc_par%lhmc
     485         3295 :       IF (PRESENT(pmhmc)) pmhmc = mc_par%pmhmc
     486         3295 :       IF (PRESENT(pmhmc_box)) pmhmc_box = mc_par%pmhmc_box
     487         3295 :       IF (PRESENT(pmvol_box)) pmvol_box = mc_par%pmvol_box
     488         3295 :       IF (PRESENT(pmclus_box)) pmclus_box = mc_par%pmclus_box
     489         3295 :       IF (PRESENT(pmtraion)) pmtraion = mc_par%pmtraion
     490         3295 :       IF (PRESENT(pmtrans)) pmtrans = mc_par%pmtrans
     491         3295 :       IF (PRESENT(pmcltrans)) pmcltrans = mc_par%pmcltrans
     492         3295 :       IF (PRESENT(pmavbmc)) pmavbmc = mc_par%pmavbmc
     493         3295 :       IF (PRESENT(pmrot_mol)) pmrot_mol => mc_par%pmrot_mol
     494         3295 :       IF (PRESENT(pmtrans_mol)) pmtrans_mol => mc_par%pmtrans_mol
     495         3295 :       IF (PRESENT(pmtraion_mol)) pmtraion_mol => mc_par%pmtraion_mol
     496         3295 :       IF (PRESENT(pmavbmc_mol)) pmavbmc_mol => mc_par%pmavbmc_mol
     497         3295 :       IF (PRESENT(pbias)) pbias => mc_par%pbias
     498              : 
     499         3295 :       IF (PRESENT(rmbond)) rmbond => mc_par%rmbond
     500         3295 :       IF (PRESENT(rmangle)) rmangle => mc_par%rmangle
     501         3295 :       IF (PRESENT(rmdihedral)) rmdihedral => mc_par%rmdihedral
     502         3295 :       IF (PRESENT(rmrot)) rmrot => mc_par%rmrot
     503         3295 :       IF (PRESENT(rmtrans)) rmtrans => mc_par%rmtrans
     504              : 
     505         3295 :       IF (PRESENT(eta)) eta => mc_par%eta
     506              : 
     507         3295 :       IF (PRESENT(ensemble)) ensemble = mc_par%ensemble
     508         3295 :       IF (PRESENT(PROGRAM)) PROGRAM = mc_par%program
     509         3295 :       IF (PRESENT(restart_file_name)) restart_file_name = &
     510           32 :          mc_par%restart_file_name
     511         3295 :       IF (PRESENT(moves_file)) moves_file = mc_par%moves_file
     512         3295 :       IF (PRESENT(coords_file)) coords_file = mc_par%coords_file
     513         3295 :       IF (PRESENT(molecules_file)) molecules_file = mc_par%molecules_file
     514         3295 :       IF (PRESENT(energy_file)) energy_file = mc_par%energy_file
     515         3295 :       IF (PRESENT(displacement_file)) displacement_file = &
     516           24 :          mc_par%displacement_file
     517         3295 :       IF (PRESENT(cell_file)) cell_file = mc_par%cell_file
     518         3295 :       IF (PRESENT(dat_file)) dat_file = mc_par%dat_file
     519         3295 :       IF (PRESENT(data_file)) data_file = mc_par%data_file
     520         3295 :       IF (PRESENT(box2_file)) box2_file = mc_par%box2_file
     521              : 
     522         3295 :       IF (PRESENT(input_file)) input_file => mc_par%input_file
     523         3295 :       IF (PRESENT(mc_molecule_info)) mc_molecule_info => mc_par%mc_molecule_info
     524         3295 :       IF (PRESENT(mc_input_file)) mc_input_file => mc_par%mc_input_file
     525         3295 :       IF (PRESENT(mc_bias_file)) mc_bias_file => mc_par%mc_bias_file
     526              : 
     527         3295 :       IF (PRESENT(pmswap_mol)) pmswap_mol => mc_par%pmswap_mol
     528         3295 :       IF (PRESENT(rand2skip)) rand2skip = mc_par%rand2skip
     529         3295 :    END SUBROUTINE get_mc_par
     530              : 
     531              : ! **************************************************************************************************
     532              : !> \brief ...
     533              : !> \param mc_molecule_info ...
     534              : !> \param nmol_types ...
     535              : !> \param nchain_total ...
     536              : !> \param nboxes ...
     537              : !> \param names ...
     538              : !> \param conf_prob ...
     539              : !> \param nchains ...
     540              : !> \param nunits ...
     541              : !> \param mol_type ...
     542              : !> \param nunits_tot ...
     543              : !> \param in_box ...
     544              : !> \param atom_names ...
     545              : !> \param mass ...
     546              : ! **************************************************************************************************
     547         3616 :    SUBROUTINE get_mc_molecule_info(mc_molecule_info, nmol_types, nchain_total, nboxes, &
     548              :                                    names, conf_prob, nchains, nunits, mol_type, nunits_tot, in_box, atom_names, &
     549              :                                    mass)
     550              : 
     551              : ! **************************************************************************************************
     552              : !> \brief accesses the private elements of the mc_molecule_info_type
     553              : !> \param mc_molecule_info the structure you want the parameters for
     554              : !>
     555              : !>    Suitable for parallel.
     556              : !> \author MJM
     557              :       TYPE(mc_molecule_info_type), POINTER               :: mc_molecule_info
     558              :       INTEGER, INTENT(OUT), OPTIONAL                     :: nmol_types, nchain_total, nboxes
     559              :       CHARACTER(LEN=default_string_length), &
     560              :          DIMENSION(:), OPTIONAL, POINTER                 :: names
     561              :       REAL(dp), DIMENSION(:, :), OPTIONAL, POINTER       :: conf_prob
     562              :       INTEGER, DIMENSION(:, :), OPTIONAL, POINTER        :: nchains
     563              :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: nunits, mol_type, nunits_tot, in_box
     564              :       CHARACTER(LEN=default_string_length), &
     565              :          DIMENSION(:, :), OPTIONAL, POINTER              :: atom_names
     566              :       REAL(dp), DIMENSION(:, :), OPTIONAL, POINTER       :: mass
     567              : 
     568         3616 :       IF (PRESENT(nboxes)) nboxes = mc_molecule_info%nboxes
     569         3616 :       IF (PRESENT(nchain_total)) nchain_total = mc_molecule_info%nchain_total
     570         3616 :       IF (PRESENT(nmol_types)) nmol_types = mc_molecule_info%nmol_types
     571              : 
     572         3616 :       IF (PRESENT(names)) names => mc_molecule_info%names
     573         3616 :       IF (PRESENT(atom_names)) atom_names => mc_molecule_info%atom_names
     574              : 
     575         3616 :       IF (PRESENT(conf_prob)) conf_prob => mc_molecule_info%conf_prob
     576         3616 :       IF (PRESENT(mass)) mass => mc_molecule_info%mass
     577              : 
     578         3616 :       IF (PRESENT(nchains)) nchains => mc_molecule_info%nchains
     579         3616 :       IF (PRESENT(nunits)) nunits => mc_molecule_info%nunits
     580         3616 :       IF (PRESENT(mol_type)) mol_type => mc_molecule_info%mol_type
     581         3616 :       IF (PRESENT(nunits_tot)) nunits_tot => mc_molecule_info%nunits_tot
     582         3616 :       IF (PRESENT(in_box)) in_box => mc_molecule_info%in_box
     583              : 
     584         3616 :    END SUBROUTINE get_mc_molecule_info
     585              : 
     586              : ! **************************************************************************************************
     587              : !> \brief changes the private elements of the mc_parameters_type
     588              : !> \param mc_par the structure mc parameters you want
     589              : !> \param rm ...
     590              : !> \param cl ...
     591              : !> \param diff ...
     592              : !> \param nstart ...
     593              : !> \param rmvolume ...
     594              : !> \param rmcltrans ...
     595              : !> \param rmbond ...
     596              : !> \param rmangle ...
     597              : !> \param rmdihedral ...
     598              : !> \param rmrot ...
     599              : !> \param rmtrans ...
     600              : !> \param PROGRAM ...
     601              : !> \param nmoves ...
     602              : !> \param nswapmoves ...
     603              : !> \param lstop ...
     604              : !> \param temperature ...
     605              : !> \param pressure ...
     606              : !> \param rclus ...
     607              : !> \param iuptrans ...
     608              : !> \param iupcltrans ...
     609              : !> \param iupvolume ...
     610              : !> \param pmswap ...
     611              : !> \param pmvolume ...
     612              : !> \param pmtraion ...
     613              : !> \param pmtrans ...
     614              : !> \param pmcltrans ...
     615              : !> \param BETA ...
     616              : !> \param rcut ...
     617              : !> \param iprint ...
     618              : !> \param lbias ...
     619              : !> \param nstep ...
     620              : !> \param lrestart ...
     621              : !> \param ldiscrete ...
     622              : !> \param discrete_step ...
     623              : !> \param pmavbmc ...
     624              : !> \param mc_molecule_info ...
     625              : !> \param pmavbmc_mol ...
     626              : !> \param pmtrans_mol ...
     627              : !> \param pmrot_mol ...
     628              : !> \param pmtraion_mol ...
     629              : !> \param pmswap_mol ...
     630              : !> \param avbmc_rmin ...
     631              : !> \param avbmc_rmax ...
     632              : !> \param avbmc_atom ...
     633              : !> \param pbias ...
     634              : !> \param ensemble ...
     635              : !> \param pmvol_box ...
     636              : !> \param pmclus_box ...
     637              : !> \param eta ...
     638              : !> \param mc_input_file ...
     639              : !> \param mc_bias_file ...
     640              : !> \param exp_max_val ...
     641              : !> \param exp_min_val ...
     642              : !> \param min_val ...
     643              : !> \param max_val ...
     644              : !> \param pmhmc ...
     645              : !> \param pmhmc_box ...
     646              : !> \param lhmc ...
     647              : !> \param ionode ...
     648              : !> \param source ...
     649              : !> \param group ...
     650              : !> \param rand2skip ...
     651              : !>    Suitable for parallel.
     652              : !> \author MJM
     653              : ! **************************************************************************************************
     654          154 :    SUBROUTINE set_mc_par(mc_par, rm, cl, &
     655              :                          diff, nstart, rmvolume, rmcltrans, rmbond, rmangle, rmdihedral, rmrot, rmtrans, PROGRAM, &
     656              :                          nmoves, nswapmoves, lstop, temperature, pressure, rclus, iuptrans, iupcltrans, iupvolume, &
     657              :                          pmswap, pmvolume, pmtraion, pmtrans, pmcltrans, BETA, rcut, iprint, lbias, nstep, &
     658              :                          lrestart, ldiscrete, discrete_step, pmavbmc, mc_molecule_info, &
     659              :                          pmavbmc_mol, pmtrans_mol, pmrot_mol, pmtraion_mol, pmswap_mol, &
     660              :                          avbmc_rmin, avbmc_rmax, avbmc_atom, pbias, ensemble, pmvol_box, pmclus_box, eta, &
     661              :                          mc_input_file, mc_bias_file, exp_max_val, exp_min_val, min_val, max_val, &
     662              :                          pmhmc, pmhmc_box, lhmc, ionode, source, group, rand2skip)
     663              : 
     664              :       TYPE(mc_simpar_type), POINTER                      :: mc_par
     665              :       INTEGER, INTENT(IN), OPTIONAL                      :: rm, cl, diff, nstart
     666              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: rmvolume, rmcltrans
     667              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: rmbond, rmangle, rmdihedral, rmrot, &
     668              :                                                             rmtrans
     669              :       CHARACTER(LEN=*), INTENT(IN), OPTIONAL             :: PROGRAM
     670              :       INTEGER, INTENT(IN), OPTIONAL                      :: nmoves, nswapmoves
     671              :       LOGICAL, INTENT(IN), OPTIONAL                      :: lstop
     672              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: temperature, pressure, rclus
     673              :       INTEGER, INTENT(IN), OPTIONAL                      :: iuptrans, iupcltrans, iupvolume
     674              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: pmswap, pmvolume, pmtraion, pmtrans, &
     675              :                                                             pmcltrans, BETA, rcut
     676              :       INTEGER, INTENT(IN), OPTIONAL                      :: iprint
     677              :       LOGICAL, INTENT(IN), OPTIONAL                      :: lbias
     678              :       INTEGER, INTENT(IN), OPTIONAL                      :: nstep
     679              :       LOGICAL, INTENT(IN), OPTIONAL                      :: lrestart, ldiscrete
     680              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: discrete_step, pmavbmc
     681              :       TYPE(mc_molecule_info_type), OPTIONAL, POINTER     :: mc_molecule_info
     682              :       REAL(dp), DIMENSION(:), OPTIONAL, POINTER          :: pmavbmc_mol, pmtrans_mol, pmrot_mol, &
     683              :                                                             pmtraion_mol, pmswap_mol, avbmc_rmin, &
     684              :                                                             avbmc_rmax
     685              :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: avbmc_atom
     686              :       REAL(dp), DIMENSION(:), OPTIONAL, POINTER          :: pbias
     687              :       CHARACTER(LEN=*), INTENT(IN), OPTIONAL             :: ensemble
     688              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: pmvol_box, pmclus_box
     689              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: eta
     690              :       TYPE(mc_input_file_type), OPTIONAL, POINTER        :: mc_input_file, mc_bias_file
     691              :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: exp_max_val, exp_min_val, min_val, &
     692              :                                                             max_val, pmhmc, pmhmc_box
     693              :       LOGICAL, INTENT(IN), OPTIONAL                      :: lhmc, ionode
     694              :       INTEGER, INTENT(IN), OPTIONAL                      :: source
     695              : 
     696              :       CLASS(mp_comm_type), INTENT(IN), OPTIONAL           :: group
     697              :       INTEGER, INTENT(IN), OPTIONAL                      :: rand2skip
     698              : 
     699              :       INTEGER                                            :: iparm
     700              : 
     701              : ! These are the only values that change during the course of the simulation
     702              : ! or are computed outside of this module
     703              : 
     704            8 :       IF (PRESENT(nstep)) mc_par%nstep = nstep
     705          154 :       IF (PRESENT(rm)) mc_par%rm = rm
     706          154 :       IF (PRESENT(cl)) mc_par%cl = cl
     707          154 :       IF (PRESENT(diff)) mc_par%diff = diff
     708          154 :       IF (PRESENT(nstart)) mc_par%nstart = nstart
     709          154 :       IF (PRESENT(nmoves)) mc_par%nmoves = nmoves
     710          154 :       IF (PRESENT(nswapmoves)) mc_par%nswapmoves = nswapmoves
     711          154 :       IF (PRESENT(iprint)) mc_par%iprint = iprint
     712          154 :       IF (PRESENT(iuptrans)) mc_par%iuptrans = iuptrans
     713          154 :       IF (PRESENT(iupcltrans)) mc_par%iupcltrans = iupcltrans
     714          154 :       IF (PRESENT(iupvolume)) mc_par%iupvolume = iupvolume
     715              : 
     716          154 :       IF (PRESENT(ldiscrete)) mc_par%ldiscrete = ldiscrete
     717          154 :       IF (PRESENT(lstop)) mc_par%lstop = lstop
     718          154 :       IF (PRESENT(lbias)) mc_par%lbias = lbias
     719          154 :       IF (PRESENT(lrestart)) mc_par%lrestart = lrestart
     720              : 
     721          154 :       IF (PRESENT(exp_max_val)) mc_par%exp_max_val = exp_max_val
     722          154 :       IF (PRESENT(exp_min_val)) mc_par%exp_min_val = exp_min_val
     723          154 :       IF (PRESENT(max_val)) mc_par%max_val = max_val
     724          154 :       IF (PRESENT(min_val)) mc_par%min_val = min_val
     725          154 :       IF (PRESENT(BETA)) mc_par%BETA = BETA
     726          154 :       IF (PRESENT(temperature)) mc_par%temperature = temperature
     727          154 :       IF (PRESENT(rcut)) mc_par%rcut = rcut
     728          154 :       IF (PRESENT(pressure)) mc_par%pressure = pressure
     729          154 :       IF (PRESENT(rclus)) mc_par%rclus = rclus
     730          154 :       IF (PRESENT(pmvolume)) mc_par%pmvolume = pmvolume
     731          154 :       IF (PRESENT(lhmc)) mc_par%lhmc = lhmc
     732          154 :       IF (PRESENT(pmhmc)) mc_par%pmhmc = pmhmc
     733          154 :       IF (PRESENT(pmhmc_box)) mc_par%pmhmc_box = pmhmc_box
     734          154 :       IF (PRESENT(pmvol_box)) mc_par%pmvol_box = pmvol_box
     735          154 :       IF (PRESENT(pmclus_box)) mc_par%pmclus_box = pmclus_box
     736          154 :       IF (PRESENT(pmswap)) mc_par%pmswap = pmswap
     737          154 :       IF (PRESENT(pmtrans)) mc_par%pmtrans = pmtrans
     738          154 :       IF (PRESENT(pmcltrans)) mc_par%pmcltrans = pmcltrans
     739          154 :       IF (PRESENT(pmtraion)) mc_par%pmtraion = pmtraion
     740          154 :       IF (PRESENT(pmavbmc)) mc_par%pmavbmc = pmavbmc
     741              : 
     742          154 :       IF (PRESENT(discrete_step)) mc_par%discrete_step = discrete_step
     743          154 :       IF (PRESENT(rmvolume)) mc_par%rmvolume = rmvolume
     744          154 :       IF (PRESENT(rmcltrans)) mc_par%rmcltrans = rmcltrans
     745              : 
     746          154 :       IF (PRESENT(mc_input_file)) mc_par%mc_input_file => mc_input_file
     747          154 :       IF (PRESENT(mc_bias_file)) mc_par%mc_bias_file => mc_bias_file
     748              : 
     749              : ! cannot just change the pointers, because then we have memory leaks
     750              : ! and the program crashes if we try to release it (in certain cases)
     751          154 :       IF (PRESENT(eta)) THEN
     752            0 :          DO iparm = 1, SIZE(eta)
     753            0 :             mc_par%eta(iparm) = eta(iparm)
     754              :          END DO
     755              :       END IF
     756          154 :       IF (PRESENT(rmbond)) THEN
     757            0 :          DO iparm = 1, SIZE(rmbond)
     758            0 :             mc_par%rmbond(iparm) = rmbond(iparm)
     759              :          END DO
     760              :       END IF
     761          154 :       IF (PRESENT(rmangle)) THEN
     762            0 :          DO iparm = 1, SIZE(rmangle)
     763            0 :             mc_par%rmangle(iparm) = rmangle(iparm)
     764              :          END DO
     765              :       END IF
     766          154 :       IF (PRESENT(rmdihedral)) THEN
     767            0 :          DO iparm = 1, SIZE(rmdihedral)
     768            0 :             mc_par%rmdihedral(iparm) = rmdihedral(iparm)
     769              :          END DO
     770              :       END IF
     771          154 :       IF (PRESENT(rmrot)) THEN
     772            0 :          DO iparm = 1, SIZE(rmrot)
     773            0 :             mc_par%rmrot(iparm) = rmrot(iparm)
     774              :          END DO
     775              :       END IF
     776          154 :       IF (PRESENT(rmtrans)) THEN
     777            0 :          DO iparm = 1, SIZE(rmtrans)
     778            0 :             mc_par%rmtrans(iparm) = rmtrans(iparm)
     779              :          END DO
     780              :       END IF
     781              : 
     782          154 :       IF (PRESENT(pmavbmc_mol)) THEN
     783           18 :          DO iparm = 1, SIZE(pmavbmc_mol)
     784           18 :             mc_par%pmavbmc_mol(iparm) = pmavbmc_mol(iparm)
     785              :          END DO
     786              :       END IF
     787          154 :       IF (PRESENT(pmtrans_mol)) THEN
     788           18 :          DO iparm = 1, SIZE(pmtrans_mol)
     789           18 :             mc_par%pmtrans_mol(iparm) = pmtrans_mol(iparm)
     790              :          END DO
     791              :       END IF
     792          154 :       IF (PRESENT(pmrot_mol)) THEN
     793           18 :          DO iparm = 1, SIZE(pmrot_mol)
     794           18 :             mc_par%pmrot_mol(iparm) = pmrot_mol(iparm)
     795              :          END DO
     796              :       END IF
     797          154 :       IF (PRESENT(pmtraion_mol)) THEN
     798           18 :          DO iparm = 1, SIZE(pmtraion_mol)
     799           18 :             mc_par%pmtraion_mol(iparm) = pmtraion_mol(iparm)
     800              :          END DO
     801              :       END IF
     802          154 :       IF (PRESENT(pmswap_mol)) THEN
     803           18 :          DO iparm = 1, SIZE(pmswap_mol)
     804           18 :             mc_par%pmswap_mol(iparm) = pmswap_mol(iparm)
     805              :          END DO
     806              :       END IF
     807              : 
     808          154 :       IF (PRESENT(avbmc_atom)) THEN
     809           18 :          DO iparm = 1, SIZE(avbmc_atom)
     810           18 :             mc_par%avbmc_atom(iparm) = avbmc_atom(iparm)
     811              :          END DO
     812              :       END IF
     813          154 :       IF (PRESENT(avbmc_rmin)) THEN
     814           18 :          DO iparm = 1, SIZE(avbmc_rmin)
     815           18 :             mc_par%avbmc_rmin(iparm) = avbmc_rmin(iparm)
     816              :          END DO
     817              :       END IF
     818          154 :       IF (PRESENT(avbmc_rmax)) THEN
     819           18 :          DO iparm = 1, SIZE(avbmc_rmax)
     820           18 :             mc_par%avbmc_rmax(iparm) = avbmc_rmax(iparm)
     821              :          END DO
     822              :       END IF
     823          154 :       IF (PRESENT(pbias)) THEN
     824           18 :          DO iparm = 1, SIZE(pbias)
     825           18 :             mc_par%pbias(iparm) = pbias(iparm)
     826              :          END DO
     827              :       END IF
     828              : 
     829          154 :       IF (PRESENT(PROGRAM)) mc_par%program = PROGRAM
     830          154 :       IF (PRESENT(ensemble)) mc_par%ensemble = ensemble
     831              : 
     832          154 :       IF (PRESENT(mc_molecule_info)) mc_par%mc_molecule_info => mc_molecule_info
     833          154 :       IF (PRESENT(source)) mc_par%source = source
     834          154 :       IF (PRESENT(group)) mc_par%group = group
     835          154 :       IF (PRESENT(ionode)) mc_par%ionode = ionode
     836              : 
     837          154 :       IF (PRESENT(rand2skip)) mc_par%rand2skip = rand2skip
     838          154 :    END SUBROUTINE set_mc_par
     839              : 
     840              : ! **************************************************************************************************
     841              : !> \brief creates (allocates) the mc_simulation_parameters type
     842              : !> \param mc_par the structure that will be created (allocated)
     843              : !> \param nmol_types the number of molecule types in the system
     844              : !> \author MJM
     845              : ! **************************************************************************************************
     846           26 :    SUBROUTINE mc_sim_par_create(mc_par, nmol_types)
     847              : 
     848              :       TYPE(mc_simpar_type), POINTER                      :: mc_par
     849              :       INTEGER, INTENT(IN)                                :: nmol_types
     850              : 
     851              :       NULLIFY (mc_par)
     852              : 
     853           26 :       ALLOCATE (mc_par)
     854           78 :       ALLOCATE (mc_par%pmtraion_mol(1:nmol_types))
     855           52 :       ALLOCATE (mc_par%pmtrans_mol(1:nmol_types))
     856           52 :       ALLOCATE (mc_par%pmrot_mol(1:nmol_types))
     857           52 :       ALLOCATE (mc_par%pmswap_mol(1:nmol_types))
     858              : 
     859           52 :       ALLOCATE (mc_par%eta(1:nmol_types))
     860              : 
     861           52 :       ALLOCATE (mc_par%rmbond(1:nmol_types))
     862           52 :       ALLOCATE (mc_par%rmangle(1:nmol_types))
     863           52 :       ALLOCATE (mc_par%rmdihedral(1:nmol_types))
     864           52 :       ALLOCATE (mc_par%rmtrans(1:nmol_types))
     865           52 :       ALLOCATE (mc_par%rmrot(1:nmol_types))
     866              : 
     867           78 :       ALLOCATE (mc_par%avbmc_atom(1:nmol_types))
     868           52 :       ALLOCATE (mc_par%avbmc_rmin(1:nmol_types))
     869           52 :       ALLOCATE (mc_par%avbmc_rmax(1:nmol_types))
     870           52 :       ALLOCATE (mc_par%pmavbmc_mol(1:nmol_types))
     871           52 :       ALLOCATE (mc_par%pbias(1:nmol_types))
     872              : 
     873           26 :       ALLOCATE (mc_par%mc_input_file)
     874           26 :       ALLOCATE (mc_par%mc_bias_file)
     875              : 
     876           26 :    END SUBROUTINE mc_sim_par_create
     877              : 
     878              : ! **************************************************************************************************
     879              : !> \brief destroys (deallocates) the mc_simulation_parameters type
     880              : !> \param mc_par the structure that will be destroyed
     881              : !> \author MJM
     882              : ! **************************************************************************************************
     883           26 :    SUBROUTINE mc_sim_par_destroy(mc_par)
     884              : 
     885              :       TYPE(mc_simpar_type), POINTER                      :: mc_par
     886              : 
     887           26 :       DEALLOCATE (mc_par%mc_input_file)
     888           26 :       DEALLOCATE (mc_par%mc_bias_file)
     889              : 
     890           26 :       DEALLOCATE (mc_par%pmtraion_mol)
     891           26 :       DEALLOCATE (mc_par%pmtrans_mol)
     892           26 :       DEALLOCATE (mc_par%pmrot_mol)
     893           26 :       DEALLOCATE (mc_par%pmswap_mol)
     894              : 
     895           26 :       DEALLOCATE (mc_par%eta)
     896              : 
     897           26 :       DEALLOCATE (mc_par%rmbond)
     898           26 :       DEALLOCATE (mc_par%rmangle)
     899           26 :       DEALLOCATE (mc_par%rmdihedral)
     900           26 :       DEALLOCATE (mc_par%rmtrans)
     901           26 :       DEALLOCATE (mc_par%rmrot)
     902              : 
     903           26 :       DEALLOCATE (mc_par%avbmc_atom)
     904           26 :       DEALLOCATE (mc_par%avbmc_rmin)
     905           26 :       DEALLOCATE (mc_par%avbmc_rmax)
     906           26 :       DEALLOCATE (mc_par%pmavbmc_mol)
     907           26 :       DEALLOCATE (mc_par%pbias)
     908           26 :       IF (mc_par%ensemble == "VIRIAL") THEN
     909            2 :          DEALLOCATE (mc_par%virial_temps)
     910              :       END IF
     911              : 
     912           26 :       DEALLOCATE (mc_par)
     913              :       NULLIFY (mc_par)
     914              : 
     915           26 :    END SUBROUTINE mc_sim_par_destroy
     916              : 
     917              : ! **************************************************************************************************
     918              : !> \brief creates (allocates) the mc_input_file_type
     919              : !> \param mc_input_file the structure that will be created (allocated)
     920              : !> \param input_file_name the name of the file to read
     921              : !> \param mc_molecule_info ...
     922              : !> \param empty_coords ...
     923              : !> \param lhmc ...
     924              : !> \author MJM
     925              : ! **************************************************************************************************
     926           40 :    SUBROUTINE mc_input_file_create(mc_input_file, input_file_name, &
     927           40 :                                    mc_molecule_info, empty_coords, lhmc)
     928              : 
     929              :       TYPE(mc_input_file_type), POINTER                  :: mc_input_file
     930              :       CHARACTER(LEN=*), INTENT(IN)                       :: input_file_name
     931              :       TYPE(mc_molecule_info_type), POINTER               :: mc_molecule_info
     932              :       REAL(dp), DIMENSION(:, :)                          :: empty_coords
     933              :       LOGICAL, INTENT(IN)                                :: lhmc
     934              : 
     935              :       CHARACTER(default_string_length)                   :: cdum, line, method_name
     936              :       CHARACTER(default_string_length), &
     937           40 :          DIMENSION(:, :), POINTER                        :: atom_names
     938              :       INTEGER :: abc_column, abc_row, cell_column, cell_row, idum, iline, io_stat, irep, iunit, &
     939              :          iw, line_number, nlines, nmol_types, nstart, row_number, unit
     940           40 :       INTEGER, DIMENSION(:), POINTER                     :: nunits
     941              : 
     942              : ! some stuff in case we need to write error messages to the screen
     943              : 
     944           80 :       iw = cp_logger_get_default_io_unit()
     945              : 
     946              : ! allocate the array we'll need in case we have an empty box
     947              :       CALL get_mc_molecule_info(mc_molecule_info, nmol_types=nmol_types, &
     948           40 :                                 nunits=nunits, atom_names=atom_names)
     949          120 :       ALLOCATE (mc_input_file%coordinates_empty(1:3, 1:nunits(1)))
     950          120 :       ALLOCATE (mc_input_file%atom_names_empty(1:nunits(1)))
     951          154 :       DO iunit = 1, nunits(1)
     952          114 :          mc_input_file%atom_names_empty(iunit) = atom_names(iunit, 1)
     953          496 :          mc_input_file%coordinates_empty(1:3, iunit) = empty_coords(1:3, iunit)
     954              :       END DO
     955           40 :       mc_input_file%nunits_empty = nunits(1)
     956              : 
     957              : ! allocate some arrays
     958          120 :       ALLOCATE (mc_input_file%mol_set_nmol_row(1:nmol_types))
     959           80 :       ALLOCATE (mc_input_file%mol_set_nmol_column(1:nmol_types))
     960              : 
     961              : ! now read in and store the input file, first finding out how many lines it is
     962              :       CALL open_file(file_name=input_file_name, &
     963           40 :                      unit_number=unit, file_action='READ', file_status='OLD')
     964              : 
     965           40 :       nlines = 0
     966         9240 :       DO
     967         9280 :          READ (unit, '(A)', IOSTAT=io_stat) line
     968         9280 :          IF (io_stat /= 0) EXIT
     969         9240 :          nlines = nlines + 1
     970              :       END DO
     971              : 
     972          120 :       ALLOCATE (mc_input_file%text(1:nlines))
     973              : 
     974           40 :       REWIND (unit)
     975         9280 :       DO iline = 1, nlines
     976         9280 :          READ (unit, '(A)') mc_input_file%text(iline)
     977              :       END DO
     978              : 
     979              : ! close the input file
     980           40 :       CALL close_file(unit_number=unit)
     981              : 
     982              : ! now we need to find the row and column numbers of a variety of things
     983              : ! first, Let's find the first END after GLOBAL
     984              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "&GLOBAL", .TRUE., &
     985           40 :                          mc_input_file%global_row_end, idum, start_row_number=mc_input_file%global_row_start)
     986           40 :       IF (mc_input_file%global_row_end == 0) THEN
     987            0 :          IF (iw > 0) THEN
     988            0 :             WRITE (iw, *)
     989            0 :             WRITE (iw, *) 'File name ', input_file_name
     990              :          END IF
     991              :          CALL cp_abort(__LOCATION__, &
     992            0 :                        'Could not find &END after &GLOBAL (make sure & is in the same column) and last line is blank')
     993              :       END IF
     994              : 
     995              : ! Let's find the first END after MOTION...we might need this whole section
     996              : ! because of hybrid MD/MC moves, which requires the MD information to always
     997              : ! be attached to the force env
     998              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "&MOTION", .TRUE., &
     999           40 :                          mc_input_file%motion_row_end, idum, start_row_number=mc_input_file%motion_row_start)
    1000           40 :       IF (mc_input_file%motion_row_end == 0) THEN
    1001            0 :          IF (iw > 0) THEN
    1002            0 :             WRITE (iw, *)
    1003            0 :             WRITE (iw, *) 'File name ', input_file_name, mc_input_file%motion_row_start
    1004              :          END IF
    1005              :          CALL cp_abort(__LOCATION__, &
    1006            0 :                        'Could not find &END after &MOTION (make sure & is in the same column) and last line is blank')
    1007              :       END IF
    1008              : 
    1009              : ! find &FORCE_EVAL sections
    1010              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "&FORCE_EVAL", .TRUE., &
    1011           40 :                          mc_input_file%force_eval_row_end, idum, start_row_number=mc_input_file%force_eval_row_start)
    1012              : 
    1013              : ! first, let's find the first END after &COORD, and the line of &COORD
    1014              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "&COORD", .TRUE., &
    1015           40 :                          mc_input_file%coord_row_end, idum)
    1016              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "&COORD", .FALSE., &
    1017           40 :                          mc_input_file%coord_row_start, idum)
    1018              : 
    1019           40 :       IF (mc_input_file%coord_row_end == 0) THEN
    1020            0 :          IF (iw > 0) THEN
    1021            0 :             WRITE (iw, *)
    1022            0 :             WRITE (iw, *) 'File name ', input_file_name
    1023              :          END IF
    1024              :          CALL cp_abort(__LOCATION__, &
    1025            0 :                        'Could not find &END after &COORD (make sure & is the first in the same column after &COORD)')
    1026              :       END IF
    1027              : 
    1028              : ! now the RUN_TYPE
    1029              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "RUN_TYPE", .FALSE., &
    1030           40 :                          mc_input_file%run_type_row, mc_input_file%run_type_column)
    1031           40 :       mc_input_file%run_type_column = mc_input_file%run_type_column + 9
    1032           40 :       IF (mc_input_file%run_type_row == 0) THEN
    1033            0 :          IF (iw > 0) THEN
    1034            0 :             WRITE (iw, *)
    1035            0 :             WRITE (iw, *) 'File name ', input_file_name
    1036              :          END IF
    1037              :          CALL cp_abort(__LOCATION__, &
    1038            0 :                        'Could not find RUN_TYPE in the input file (should be in the &GLOBAL section).')
    1039              :       END IF
    1040              : 
    1041              : ! now the CELL stuff..we don't care about REF_CELL since that should
    1042              : ! never change if it's there
    1043              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, "&CELL", .FALSE., &
    1044           40 :                          mc_input_file%cell_row, mc_input_file%cell_column)
    1045              : ! now find the ABC input line after CELL
    1046              :       CALL mc_parse_text(mc_input_file%text, mc_input_file%cell_row + 1, nlines, &
    1047           40 :                          "ABC", .FALSE., abc_row, abc_column)
    1048              : ! is there a &CELL inbetween?  If so, that ABC will be for the ref_cell
    1049              : ! and we need to find the next one
    1050              :       CALL mc_parse_text(mc_input_file%text, mc_input_file%cell_row + 1, abc_row, &
    1051           40 :                          "&CELL", .FALSE., cell_row, cell_column)
    1052           40 :       IF (cell_row == 0) THEN ! nothing in between...we found the correct ABC
    1053           40 :          mc_input_file%cell_row = abc_row
    1054           40 :          mc_input_file%cell_column = abc_column + 4
    1055              :       ELSE
    1056              :          CALL mc_parse_text(mc_input_file%text, abc_row + 1, nlines, &
    1057            0 :                             "ABC", .FALSE., mc_input_file%cell_row, mc_input_file%cell_column)
    1058              :       END IF
    1059           40 :       IF (mc_input_file%cell_row == 0) THEN
    1060            0 :          IF (iw > 0) THEN
    1061            0 :             WRITE (iw, *)
    1062            0 :             WRITE (iw, *) 'File name ', input_file_name
    1063              :          END IF
    1064              :          CALL cp_abort(__LOCATION__, &
    1065            0 :                        'Could not find &CELL section in the input file.  Or could not find the ABC line after it.')
    1066              :       END IF
    1067              : 
    1068              : ! now we need all the MOL_SET NMOLS indices
    1069           40 :       IF (.NOT. lhmc) THEN
    1070           38 :          irep = 0
    1071           38 :          nstart = 1
    1072           68 :          DO
    1073              :             CALL mc_parse_text(mc_input_file%text, nstart, nlines, "&MOLECULE", &
    1074          106 :                                .FALSE., row_number, idum)
    1075          106 :             IF (row_number == 0) EXIT
    1076           68 :             nstart = row_number + 1
    1077           68 :             irep = irep + 1
    1078              :             CALL mc_parse_text(mc_input_file%text, nstart, nlines, "NMOL", &
    1079              :                                .FALSE., mc_input_file%mol_set_nmol_row(irep), &
    1080           68 :                                mc_input_file%mol_set_nmol_column(irep))
    1081           68 :             mc_input_file%mol_set_nmol_column(irep) = mc_input_file%mol_set_nmol_column(irep) + 5
    1082              : 
    1083              :          END DO
    1084           38 :          IF (irep /= nmol_types) THEN
    1085            0 :             IF (iw > 0) THEN
    1086            0 :                WRITE (iw, *)
    1087            0 :                WRITE (iw, *) 'File name ', input_file_name
    1088            0 :                WRITE (iw, *) 'Number of molecule types ', nmol_types
    1089            0 :                WRITE (iw, *) '&MOLECULE sections found ', irep
    1090              :             END IF
    1091              :             CALL cp_abort( &
    1092              :                __LOCATION__, &
    1093            0 :                'Did not find MOLECULE sections for every molecule in the simulation (make sure both input files have all types)')
    1094              :          END IF
    1095              :       END IF
    1096              : 
    1097              : ! now let's find the type of force_env...right now, I'm only concerned with
    1098              : ! QS, and Fist, though it should be trivial to add others
    1099              :       CALL mc_parse_text(mc_input_file%text, 1, nlines, &
    1100           40 :                          "METHOD", .FALSE., line_number, idum)
    1101           40 :       READ (mc_input_file%text(line_number), *) cdum, method_name
    1102           40 :       CALL uppercase(method_name)
    1103           80 :       SELECT CASE (TRIM(ADJUSTL(method_name)))
    1104              :       CASE ("FIST")
    1105           34 :          mc_input_file%in_use = use_fist_force
    1106              :       CASE ("QS", "QUICKSTEP")
    1107            6 :          mc_input_file%in_use = use_qs_force
    1108              :       CASE default
    1109           80 :          CPABORT('Cannot determine the type of force_env we are using (check METHOD)')
    1110              :       END SELECT
    1111              : 
    1112           80 :    END SUBROUTINE mc_input_file_create
    1113              : 
    1114              : ! **************************************************************************************************
    1115              : !> \brief destroys (deallocates) things in the mc_input_file_type
    1116              : !> \param mc_input_file the structure that will be released (deallocated)
    1117              : !> \author MJM
    1118              : ! **************************************************************************************************
    1119           40 :    SUBROUTINE mc_input_file_destroy(mc_input_file)
    1120              : 
    1121              :       TYPE(mc_input_file_type), POINTER                  :: mc_input_file
    1122              : 
    1123           40 :       DEALLOCATE (mc_input_file%mol_set_nmol_row)
    1124           40 :       DEALLOCATE (mc_input_file%mol_set_nmol_column)
    1125           40 :       DEALLOCATE (mc_input_file%text)
    1126           40 :       DEALLOCATE (mc_input_file%atom_names_empty)
    1127           40 :       DEALLOCATE (mc_input_file%coordinates_empty)
    1128              : 
    1129           40 :    END SUBROUTINE mc_input_file_destroy
    1130              : 
    1131              : ! **************************************************************************************************
    1132              : !> \brief a basic text parser used to find the row and column numbers of various strings
    1133              : !>      in the input file, to store as indices for when we create a dat_file...
    1134              : !>      returns 0 for the row if nothing is found
    1135              : !> \param text the text to parse
    1136              : !> \param nstart the line to start searching from
    1137              : !> \param nend the line to end searching
    1138              : !> \param string_search the text we're looking for
    1139              : !> \param lend if .TRUE., find the &END that comes after string_search...assumes that
    1140              : !>            the row is the first row with & in the same column as the search string
    1141              : !> \param row_number the row the string is first found on
    1142              : !> \param column_number the column number that the string first appears on
    1143              : !> \param start_row_number ...
    1144              : !> \author MJM
    1145              : ! **************************************************************************************************
    1146          574 :    SUBROUTINE mc_parse_text(text, nstart, nend, string_search, lend, &
    1147              :                             row_number, column_number, start_row_number)
    1148              : 
    1149              :       CHARACTER(LEN=*), DIMENSION(:), INTENT(IN)         :: text
    1150              :       INTEGER, INTENT(IN)                                :: nstart, nend
    1151              :       CHARACTER(LEN=*), INTENT(IN)                       :: string_search
    1152              :       LOGICAL, INTENT(IN)                                :: lend
    1153              :       INTEGER, INTENT(OUT)                               :: row_number, column_number
    1154              :       INTEGER, INTENT(OUT), OPTIONAL                     :: start_row_number
    1155              : 
    1156              :       CHARACTER(default_string_length)                   :: text_temp
    1157              :       INTEGER                                            :: iline, index_string, jline, string_size
    1158              : 
    1159              : ! did not see any string utilities in the code to help, so here I go
    1160              : 
    1161          574 :       row_number = 0
    1162          574 :       column_number = 0
    1163              : 
    1164              : ! how long is our string to search for?
    1165          574 :       string_size = LEN_TRIM(string_search)
    1166        29728 :       whole_file: DO iline = nstart, nend
    1167              : 
    1168        29650 :          index_string = -1
    1169        29650 :          index_string = INDEX(text(iline), string_search(1:string_size))
    1170              : 
    1171        29728 :          IF (index_string > 0) THEN ! we found one
    1172          496 :             IF (.NOT. lend) THEN
    1173          336 :                row_number = iline
    1174          336 :                column_number = index_string
    1175              :             ELSE
    1176          160 :                IF (PRESENT(start_row_number)) start_row_number = iline
    1177          160 :                column_number = index_string
    1178        12034 :                DO jline = iline + 1, nend
    1179              : ! now we find the &END that matches up with this one...
    1180              : ! I need proper indentation because I'm not very smart
    1181        12034 :                   text_temp = text(jline)
    1182        12034 :                   IF (text_temp(column_number:column_number) == "&") THEN
    1183          160 :                      row_number = jline
    1184          160 :                      EXIT
    1185              :                   END IF
    1186              :                END DO
    1187              :             END IF
    1188              :             EXIT whole_file
    1189              :          END IF
    1190              :       END DO whole_file
    1191              : 
    1192          574 :    END SUBROUTINE mc_parse_text
    1193              : 
    1194              : ! **************************************************************************************************
    1195              : !> \brief reads in the Monte Carlo simulation parameters from an input file
    1196              : !> \param mc_par the structure that will store the parameters
    1197              : !> \param para_env ...
    1198              : !> \param input_file_name the name of the input_file
    1199              : !> \param input_file the structure that contains all the keywords in the input file
    1200              : !> \param force_env_section used to grab the type of force_env
    1201              : !> \author MJM
    1202              : ! **************************************************************************************************
    1203           78 :    SUBROUTINE read_mc_section(mc_par, para_env, input_file_name, input_file, force_env_section)
    1204              : 
    1205              :       TYPE(mc_simpar_type), POINTER                      :: mc_par
    1206              :       TYPE(mp_para_env_type), POINTER                    :: para_env
    1207              :       CHARACTER(LEN=*), INTENT(IN)                       :: input_file_name
    1208              :       TYPE(section_vals_type), POINTER                   :: input_file, force_env_section
    1209              : 
    1210              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'read_mc_section'
    1211              : 
    1212              :       CHARACTER(LEN=5)                                   :: box_string, molecule_string, &
    1213              :                                                             tab_box_string, tab_string, &
    1214              :                                                             tab_string_int
    1215              :       CHARACTER(LEN=default_string_length)               :: format_box_string, format_string, &
    1216              :                                                             format_string_int
    1217              :       INTEGER                                            :: handle, ia, ie, imol, itype, iw, &
    1218              :                                                             method_name_id, nmol_types, stop_num
    1219           26 :       INTEGER, DIMENSION(:), POINTER                     :: temp_i_array
    1220           26 :       REAL(dp), DIMENSION(:), POINTER                    :: temp_r_array
    1221              :       TYPE(section_vals_type), POINTER                   :: mc_section
    1222              : 
    1223              : ! begin the timing of the subroutine
    1224              : 
    1225            0 :       CPASSERT(ASSOCIATED(input_file))
    1226              : 
    1227           26 :       CALL timeset(routineN, handle)
    1228              : 
    1229           26 :       NULLIFY (mc_section)
    1230              :       mc_section => section_vals_get_subs_vals(input_file, &
    1231           26 :                                                "MOTION%MC")
    1232              : 
    1233              : ! need the input file sturcutre that we're reading from for when we make
    1234              : ! dat files
    1235           26 :       mc_par%input_file => input_file
    1236              : 
    1237              : ! set the ionode and mepos
    1238           26 :       mc_par%ionode = para_env%is_source()
    1239           26 :       mc_par%group = para_env
    1240           26 :       mc_par%source = para_env%source
    1241              : 
    1242              : ! for convenience
    1243           26 :       nmol_types = mc_par%mc_molecule_info%nmol_types
    1244              : 
    1245              : !..defaults...most are set in input_cp2k_motion
    1246           26 :       mc_par%nstart = 0
    1247           26 :       CALL section_vals_val_get(force_env_section, "METHOD", i_val=method_name_id)
    1248           20 :       SELECT CASE (method_name_id)
    1249              :       CASE (do_fist)
    1250           20 :          mc_par%iprint = 100
    1251              :       CASE (do_qs)
    1252           26 :          mc_par%iprint = 1
    1253              :       END SELECT
    1254              : 
    1255           26 :       iw = cp_logger_get_default_io_unit()
    1256           26 :       IF (iw > 0) WRITE (iw, *)
    1257              : 
    1258              : !..filenames
    1259           26 :       mc_par%program = input_file_name
    1260           26 :       CALL xstring(mc_par%program, ia, ie)
    1261           26 :       mc_par%coords_file = mc_par%program(ia:ie)//'.coordinates'
    1262           26 :       mc_par%molecules_file = mc_par%program(ia:ie)//'.molecules'
    1263           26 :       mc_par%moves_file = mc_par%program(ia:ie)//'.moves'
    1264           26 :       mc_par%energy_file = mc_par%program(ia:ie)//'.energy'
    1265           26 :       mc_par%cell_file = mc_par%program(ia:ie)//'.cell'
    1266              :       mc_par%displacement_file = mc_par%program(ia:ie) &
    1267           26 :                                  //'.max_displacements'
    1268           26 :       mc_par%data_file = mc_par%program(ia:ie)//'.data'
    1269           26 :       stop_num = ie - 3
    1270           26 :       mc_par%dat_file = mc_par%program(ia:stop_num)//'dat'
    1271              : 
    1272              : ! set them into the input parameter structure as the new defaults
    1273              :       CALL section_vals_val_set(mc_section, "COORDINATE_FILE_NAME", &
    1274           26 :                                 c_val=mc_par%coords_file)
    1275              :       CALL section_vals_val_set(mc_section, "DATA_FILE_NAME", &
    1276           26 :                                 c_val=mc_par%data_file)
    1277              :       CALL section_vals_val_set(mc_section, "CELL_FILE_NAME", &
    1278           26 :                                 c_val=mc_par%cell_file)
    1279              :       CALL section_vals_val_set(mc_section, "MAX_DISP_FILE_NAME", &
    1280           26 :                                 c_val=mc_par%displacement_file)
    1281              :       CALL section_vals_val_set(mc_section, "MOVES_FILE_NAME", &
    1282           26 :                                 c_val=mc_par%moves_file)
    1283              :       CALL section_vals_val_set(mc_section, "MOLECULES_FILE_NAME", &
    1284           26 :                                 c_val=mc_par%molecules_file)
    1285              :       CALL section_vals_val_set(mc_section, "ENERGY_FILE_NAME", &
    1286           26 :                                 c_val=mc_par%energy_file)
    1287              : 
    1288              : ! get all the move probabilities first...if we are not doing certain types of moves, we don't care
    1289              : ! if the values for those move parameters are strange
    1290              : 
    1291              : ! find out if we're only doing HMC moves...we can ignore a lot of extra information
    1292              : ! then, which would ordinarily be cause for concern
    1293           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMHMC", r_val=mc_par%pmhmc)
    1294           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMSWAP", r_val=mc_par%pmswap)
    1295           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMVOLUME", r_val=mc_par%pmvolume)
    1296           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMAVBMC", r_val=mc_par%pmavbmc)
    1297           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMTRANS", r_val=mc_par%pmtrans)
    1298           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMTRAION", r_val=mc_par%pmtraion)
    1299           26 :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%PMCLTRANS", r_val=mc_par%pmcltrans)
    1300              : 
    1301              :       ! first, grab all the integer values
    1302           26 :       CALL section_vals_val_get(mc_section, "NSTEP", i_val=mc_par%nstep)
    1303           26 :       CALL section_vals_val_get(mc_section, "NMOVES", i_val=mc_par%nmoves)
    1304           26 :       CALL section_vals_val_get(mc_section, "NSWAPMOVES", i_val=mc_par%nswapmoves)
    1305              :       CALL section_vals_val_get(mc_section, "MOVE_UPDATES%IUPVOLUME", &
    1306           26 :                                 i_val=mc_par%iupvolume)
    1307           26 :       CALL section_vals_val_get(mc_section, "NVIRIAL", i_val=mc_par%nvirial)
    1308              :       CALL section_vals_val_get(mc_section, "MOVE_UPDATES%IUPTRANS", &
    1309           26 :                                 i_val=mc_par%iuptrans)
    1310              :       CALL section_vals_val_get(mc_section, "MOVE_UPDATES%IUPCLTRANS", &
    1311           26 :                                 i_val=mc_par%iupcltrans)
    1312           26 :       CALL section_vals_val_get(mc_section, "IPRINT", i_val=mc_par%iprint)
    1313              : ! now an integer array
    1314           26 :       CALL section_vals_val_get(mc_section, "AVBMC%AVBMC_ATOM", i_vals=temp_i_array)
    1315              : 
    1316           26 :       IF (mc_par%pmhmc - mc_par%pmswap >= 1.0_dp .AND. mc_par%pmhmc == 1.0_dp) THEN
    1317            2 :          mc_par%lhmc = .TRUE.
    1318              :       ELSE
    1319           24 :          mc_par%lhmc = .FALSE.
    1320              :       END IF
    1321              : 
    1322           26 :       IF (.NOT. mc_par%lhmc) THEN
    1323           24 :          IF (SIZE(temp_i_array) /= nmol_types) THEN
    1324            0 :             CPABORT('AVBMC_ATOM must have as many values as there are molecule types.')
    1325              :          END IF
    1326              :       END IF
    1327           68 :       DO imol = 1, SIZE(temp_i_array)
    1328           68 :          mc_par%avbmc_atom(imol) = temp_i_array(imol)
    1329              :       END DO
    1330              : 
    1331              : ! now the real values
    1332           26 :       CALL section_vals_val_get(mc_section, "PRESSURE", r_val=mc_par%pressure)
    1333           26 :       CALL section_vals_val_get(mc_section, "TEMPERATURE", r_val=mc_par%temperature)
    1334           26 :       CALL section_vals_val_get(mc_section, "RCLUS", r_val=mc_par%rclus)
    1335              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%BOX_PROBABILITIES%PMCLUS_BOX", &
    1336           26 :                                 r_val=mc_par%pmclus_box)
    1337              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%BOX_PROBABILITIES%PMHMC_BOX", &
    1338           26 :                                 r_val=mc_par%pmhmc_box)
    1339              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%BOX_PROBABILITIES%PMVOL_BOX", &
    1340           26 :                                 r_val=mc_par%pmvol_box)
    1341           26 :       CALL section_vals_val_get(mc_section, "DISCRETE_STEP", r_val=mc_par%discrete_step)
    1342              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%BOX_DISPLACEMENTS%RMVOLUME", &
    1343           26 :                                 r_val=mc_par%rmvolume)
    1344              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%BOX_DISPLACEMENTS%RMCLTRANS", &
    1345           26 :                                 r_val=mc_par%rmcltrans)
    1346              : 
    1347              : ! finally the character values
    1348           26 :       CALL section_vals_val_get(mc_section, "ENSEMBLE", c_val=mc_par%ensemble)
    1349           26 :       CALL section_vals_val_get(mc_section, "RESTART_FILE_NAME", c_val=mc_par%restart_file_name)
    1350           26 :       CALL section_vals_val_get(mc_section, "COORDINATE_FILE_NAME", c_val=mc_par%coords_file)
    1351           26 :       CALL section_vals_val_get(mc_section, "ENERGY_FILE_NAME", c_val=mc_par%energy_file)
    1352           26 :       CALL section_vals_val_get(mc_section, "MOVES_FILE_NAME", c_val=mc_par%moves_file)
    1353           26 :       CALL section_vals_val_get(mc_section, "MOLECULES_FILE_NAME", c_val=mc_par%molecules_file)
    1354           26 :       CALL section_vals_val_get(mc_section, "CELL_FILE_NAME", c_val=mc_par%cell_file)
    1355           26 :       CALL section_vals_val_get(mc_section, "DATA_FILE_NAME", c_val=mc_par%data_file)
    1356           26 :       CALL section_vals_val_get(mc_section, "MAX_DISP_FILE_NAME", c_val=mc_par%displacement_file)
    1357           26 :       CALL section_vals_val_get(mc_section, "BOX2_FILE_NAME", c_val=mc_par%box2_file)
    1358              : 
    1359              : ! set the values of the arrays...if we just point, we have problems when we start fooling around
    1360              : ! with releasing force_envs and wonky values get set (despite that these are private)
    1361           26 :       IF (mc_par%ensemble == "VIRIAL") THEN
    1362            2 :          CALL section_vals_val_get(mc_section, "VIRIAL_TEMPS", r_vals=temp_r_array)
    1363              : ! yes, I'm allocating here...I cannot find a better place to do it, though
    1364            6 :          ALLOCATE (mc_par%virial_temps(1:SIZE(temp_r_array)))
    1365            6 :          DO imol = 1, SIZE(temp_r_array)
    1366            6 :             mc_par%virial_temps(imol) = temp_r_array(imol)
    1367              :          END DO
    1368              :       END IF
    1369              : ! all of these arrays should have one value for each type of molecule...so check that
    1370           26 :       CALL section_vals_val_get(mc_section, "AVBMC%AVBMC_RMIN", r_vals=temp_r_array)
    1371           26 :       IF (.NOT. mc_par%lhmc) THEN
    1372           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1373            0 :             CPABORT('AVBMC_RMIN must have as many values as there are molecule types.')
    1374              :          END IF
    1375              :       END IF
    1376           68 :       DO imol = 1, SIZE(temp_r_array)
    1377           68 :          mc_par%avbmc_rmin(imol) = temp_r_array(imol)
    1378              :       END DO
    1379           26 :       CALL section_vals_val_get(mc_section, "AVBMC%AVBMC_RMAX", r_vals=temp_r_array)
    1380           26 :       IF (.NOT. mc_par%lhmc) THEN
    1381           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1382            0 :             CPABORT('AVBMC_RMAXL must have as many values as there are molecule types.')
    1383              :          END IF
    1384              :       END IF
    1385           68 :       DO imol = 1, SIZE(temp_r_array)
    1386           68 :          mc_par%avbmc_rmax(imol) = temp_r_array(imol)
    1387              :       END DO
    1388           26 :       CALL section_vals_val_get(mc_section, "AVBMC%PBIAS", r_vals=temp_r_array)
    1389           26 :       IF (.NOT. mc_par%lhmc) THEN
    1390           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1391            0 :             CPABORT('PBIAS must have as many values as there are molecule types.')
    1392              :          END IF
    1393              :       END IF
    1394           68 :       DO imol = 1, SIZE(temp_r_array)
    1395           68 :          mc_par%pbias(imol) = temp_r_array(imol)
    1396              :       END DO
    1397              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%MOL_PROBABILITIES%PMAVBMC_MOL", &
    1398           26 :                                 r_vals=temp_r_array)
    1399           26 :       IF (.NOT. mc_par%lhmc) THEN
    1400           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1401            0 :             CPABORT('PMAVBMC_MOL must have as many values as there are molecule types.')
    1402              :          END IF
    1403              :       END IF
    1404           68 :       DO imol = 1, SIZE(temp_r_array)
    1405           68 :          mc_par%pmavbmc_mol(imol) = temp_r_array(imol)
    1406              :       END DO
    1407           26 :       CALL section_vals_val_get(mc_section, "ETA", r_vals=temp_r_array)
    1408           26 :       IF (.NOT. mc_par%lhmc) THEN
    1409           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1410            0 :             CPABORT('ETA must have as many values as there are molecule types.')
    1411              :          END IF
    1412              :       END IF
    1413           68 :       DO imol = 1, SIZE(temp_r_array)
    1414           68 :          mc_par%eta(imol) = temp_r_array(imol)
    1415              :       END DO
    1416              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%MOL_DISPLACEMENTS%RMBOND", &
    1417           26 :                                 r_vals=temp_r_array)
    1418           26 :       IF (.NOT. mc_par%lhmc) THEN
    1419           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1420            0 :             CPABORT('RMBOND must have as many values as there are molecule types.')
    1421              :          END IF
    1422              :       END IF
    1423           68 :       DO imol = 1, SIZE(temp_r_array)
    1424           68 :          mc_par%rmbond(imol) = temp_r_array(imol)
    1425              :       END DO
    1426              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%MOL_DISPLACEMENTS%RMANGLE", &
    1427           26 :                                 r_vals=temp_r_array)
    1428           26 :       IF (.NOT. mc_par%lhmc) THEN
    1429           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1430            0 :             CPABORT('RMANGLE must have as many values as there are molecule types.')
    1431              :          END IF
    1432              :       END IF
    1433           68 :       DO imol = 1, SIZE(temp_r_array)
    1434           68 :          mc_par%rmangle(imol) = temp_r_array(imol)
    1435              :       END DO
    1436              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%MOL_DISPLACEMENTS%RMDIHEDRAL", &
    1437           26 :                                 r_vals=temp_r_array)
    1438           26 :       IF (.NOT. mc_par%lhmc) THEN
    1439           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1440            0 :             CPABORT('RMDIHEDRAL must have as many values as there are molecule types.')
    1441              :          END IF
    1442              :       END IF
    1443           68 :       DO imol = 1, SIZE(temp_r_array)
    1444           68 :          mc_par%rmdihedral(imol) = temp_r_array(imol)
    1445              :       END DO
    1446              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%MOL_DISPLACEMENTS%RMROT", &
    1447           26 :                                 r_vals=temp_r_array)
    1448           26 :       IF (.NOT. mc_par%lhmc) THEN
    1449           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1450            0 :             CPABORT('RMROT must have as many values as there are molecule types.')
    1451              :          END IF
    1452              :       END IF
    1453           68 :       DO imol = 1, SIZE(temp_r_array)
    1454           68 :          mc_par%rmrot(imol) = temp_r_array(imol)
    1455              :       END DO
    1456              :       CALL section_vals_val_get(mc_section, "MAX_DISPLACEMENTS%MOL_DISPLACEMENTS%RMTRANS", &
    1457           26 :                                 r_vals=temp_r_array)
    1458           26 :       IF (.NOT. mc_par%lhmc) THEN
    1459           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1460            0 :             CPABORT('RMTRANS must have as many values as there are molecule types.')
    1461              :          END IF
    1462              :       END IF
    1463           68 :       DO imol = 1, SIZE(temp_r_array)
    1464           68 :          mc_par%rmtrans(imol) = temp_r_array(imol)
    1465              :       END DO
    1466              : 
    1467              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%MOL_PROBABILITIES%PMTRAION_MOL", &
    1468           26 :                                 r_vals=temp_r_array)
    1469           26 :       IF (.NOT. mc_par%lhmc) THEN
    1470           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1471            0 :             CPABORT('PMTRAION_MOL must have as many values as there are molecule types.')
    1472              :          END IF
    1473              :       END IF
    1474           68 :       DO imol = 1, SIZE(temp_r_array)
    1475           68 :          mc_par%pmtraion_mol(imol) = temp_r_array(imol)
    1476              :       END DO
    1477              : 
    1478              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%MOL_PROBABILITIES%PMTRANS_MOL", &
    1479           26 :                                 r_vals=temp_r_array)
    1480           26 :       IF (.NOT. mc_par%lhmc) THEN
    1481           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1482            0 :             CPABORT('PMTRANS_MOL must have as many values as there are molecule types.')
    1483              :          END IF
    1484              :       END IF
    1485           68 :       DO imol = 1, SIZE(temp_r_array)
    1486           68 :          mc_par%pmtrans_mol(imol) = temp_r_array(imol)
    1487              :       END DO
    1488              : 
    1489              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%MOL_PROBABILITIES%PMROT_MOL", &
    1490           26 :                                 r_vals=temp_r_array)
    1491           26 :       IF (.NOT. mc_par%lhmc) THEN
    1492           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1493            0 :             CPABORT('PMROT_MOL must have as many values as there are molecule types.')
    1494              :          END IF
    1495              :       END IF
    1496           68 :       DO imol = 1, SIZE(temp_r_array)
    1497           68 :          mc_par%pmrot_mol(imol) = temp_r_array(imol)
    1498              :       END DO
    1499              : 
    1500              :       CALL section_vals_val_get(mc_section, "MOVE_PROBABILITIES%MOL_PROBABILITIES%PMSWAP_MOL", &
    1501           26 :                                 r_vals=temp_r_array)
    1502           26 :       IF (.NOT. mc_par%lhmc) THEN
    1503           24 :          IF (SIZE(temp_r_array) /= nmol_types) THEN
    1504            0 :             CPABORT('PMSWAP_MOL must have as many values as there are molecule types.')
    1505              :          END IF
    1506              :       END IF
    1507           68 :       DO imol = 1, SIZE(temp_r_array)
    1508           68 :          mc_par%pmswap_mol(imol) = temp_r_array(imol)
    1509              :       END DO
    1510              : 
    1511              : ! now some logical values
    1512           26 :       CALL section_vals_val_get(mc_section, "LBIAS", l_val=mc_par%lbias)
    1513           26 :       CALL section_vals_val_get(mc_section, "LDISCRETE", l_val=mc_par%ldiscrete)
    1514           26 :       CALL section_vals_val_get(mc_section, "LSTOP", l_val=mc_par%lstop)
    1515           26 :       CALL section_vals_val_get(mc_section, "RESTART", l_val=mc_par%lrestart)
    1516           26 :       CALL section_vals_val_get(mc_section, "LBIAS", l_val=mc_par%lbias)
    1517              : 
    1518              : !..end of parsing the input section
    1519              : 
    1520              : !..write some information to output
    1521           26 :       IF (iw > 0) THEN
    1522           13 :          WRITE (box_string, '(I2)') mc_par%mc_molecule_info%nboxes
    1523           13 :          WRITE (molecule_string, '(I2)') mc_par%mc_molecule_info%nmol_types
    1524           13 :          WRITE (tab_string, '(I4)') 81 - 10*mc_par%mc_molecule_info%nmol_types
    1525           13 :          WRITE (tab_box_string, '(I4)') 81 - 10*mc_par%mc_molecule_info%nboxes
    1526           13 :          WRITE (tab_string_int, '(I4)') 81 - 5*mc_par%mc_molecule_info%nmol_types
    1527           13 :          format_string = "(A,T"//TRIM(ADJUSTL(tab_string))//","//TRIM(ADJUSTL(molecule_string))//"(2X,F8.4))"
    1528           13 :          format_box_string = "(A,T"//TRIM(ADJUSTL(tab_box_string))//","//TRIM(ADJUSTL(box_string))//"(2X,F8.4))"
    1529           13 :          format_string_int = "(A,T"//TRIM(ADJUSTL(tab_string))//","//TRIM(ADJUSTL(molecule_string))//"(I3,2X))"
    1530           13 :          WRITE (iw, '( A )') ' MC| Monte Carlo Protocol '
    1531           13 :          WRITE (iw, '( A,T71,I10 )') ' MC| total number of steps ', &
    1532           26 :             mc_par%nstep
    1533           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmvolume ', &
    1534           26 :             mc_par%pmvolume
    1535           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmvol_box ', &
    1536           26 :             mc_par%pmvol_box
    1537           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmclus_box ', &
    1538           26 :             mc_par%pmclus_box
    1539           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmhmc ', &
    1540           26 :             mc_par%pmhmc
    1541           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmhmc_box ', &
    1542           26 :             mc_par%pmhmc_box
    1543           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmswap ', &
    1544           26 :             mc_par%pmswap
    1545           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmavbmc ', &
    1546           26 :             mc_par%pmavbmc
    1547           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmtraion ', &
    1548           26 :             mc_par%pmtraion
    1549           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmtrans ', &
    1550           26 :             mc_par%pmtrans
    1551           13 :          WRITE (iw, '( A,T71,F10.3 )') ' MC| pmcltrans ', &
    1552           26 :             mc_par%pmcltrans
    1553           13 :          WRITE (iw, '( A,T71,I10 )') ' MC| iupvolume ', &
    1554           26 :             mc_par%iupvolume
    1555           13 :          WRITE (iw, '( A,T71,I10 )') ' MC| nvirial ', &
    1556           26 :             mc_par%nvirial
    1557           13 :          WRITE (iw, '( A,T71,I10 )') ' MC| iuptrans ', &
    1558           26 :             mc_par%iuptrans
    1559           13 :          WRITE (iw, '( A,T71,I10 )') ' MC| iupcltrans ', &
    1560           26 :             mc_par%iupcltrans
    1561           13 :          WRITE (iw, '( A,T71,I10 )') ' MC| iprint ', &
    1562           26 :             mc_par%iprint
    1563           13 :          WRITE (iw, '( A,T61,A20 )') ' MC| ensemble ', &
    1564           26 :             ADJUSTR(mc_par%ensemble)
    1565              : ! format string may not be valid if all the molecules are atomic,
    1566              : ! like in HMC
    1567           13 :          IF (.NOT. mc_par%lhmc) THEN
    1568           12 :             WRITE (iw, format_string) ' MC| pmswap_mol ', &
    1569           44 :                mc_par%pmswap_mol
    1570           12 :             WRITE (iw, format_string) ' MC| pmavbmc_mol ', &
    1571           44 :                mc_par%pmavbmc_mol
    1572           12 :             WRITE (iw, format_string) ' MC| pbias ', &
    1573           44 :                mc_par%pbias
    1574           12 :             WRITE (iw, format_string) ' MC| pmtraion_mol ', &
    1575           44 :                mc_par%pmtraion_mol
    1576           12 :             WRITE (iw, format_string) ' MC| pmtrans_mol ', &
    1577           44 :                mc_par%pmtrans_mol
    1578           12 :             WRITE (iw, format_string) ' MC| pmrot_mol ', &
    1579           44 :                mc_par%pmrot_mol
    1580           12 :             WRITE (iw, format_string) ' MC| eta [K]', &
    1581           44 :                mc_par%eta
    1582           12 :             WRITE (iw, format_string) ' MC| rmbond [angstroms]', &
    1583           44 :                mc_par%rmbond
    1584           12 :             WRITE (iw, format_string) ' MC| rmangle [degrees]', &
    1585           44 :                mc_par%rmangle
    1586           12 :             WRITE (iw, format_string) ' MC| rmdihedral [degrees]', &
    1587           44 :                mc_par%rmdihedral
    1588           12 :             WRITE (iw, format_string) ' MC| rmtrans [angstroms]', &
    1589           44 :                mc_par%rmtrans
    1590           12 :             WRITE (iw, format_string) ' MC| rmcltrans [angstroms]', &
    1591           24 :                mc_par%rmcltrans
    1592           12 :             WRITE (iw, format_string) ' MC| rmrot [degrees]', &
    1593           44 :                mc_par%rmrot
    1594           12 :             WRITE (iw, format_string_int) ' MC| AVBMC target atom ', &
    1595           44 :                mc_par%avbmc_atom
    1596           12 :             WRITE (iw, format_string) ' MC| AVBMC inner cutoff [ang]', &
    1597           44 :                mc_par%avbmc_rmin
    1598           12 :             WRITE (iw, format_string) ' MC| AVBMC outer cutoff [ang]', &
    1599           44 :                mc_par%avbmc_rmax
    1600              :          END IF
    1601           13 :          IF (mc_par%ensemble == 'GEMC-NVT') THEN
    1602            0 :             WRITE (iw, '( A,T58,A)') ' MC| Box 2 file', &
    1603            0 :                TRIM(mc_par%box2_file)
    1604              :          END IF
    1605           13 :          WRITE (iw, '( A,T58,A )') ' MC| Name of restart file:', &
    1606           26 :             TRIM(mc_par%restart_file_name)
    1607           13 :          WRITE (iw, '( A,A,T44,A )') ' MC| Name of output ', &
    1608           13 :             'coordinate file:', &
    1609           26 :             TRIM(mc_par%coords_file)
    1610           13 :          WRITE (iw, '( A,T44,A )') ' MC| Name of output data file:', &
    1611           26 :             TRIM(mc_par%data_file)
    1612           13 :          WRITE (iw, '( A,A,T44,A )') ' MC| Name of output ', &
    1613           13 :             'molecules file:', &
    1614           26 :             TRIM(mc_par%molecules_file)
    1615           13 :          WRITE (iw, '( A,T44,A )') ' MC| Name of output moves file:', &
    1616           26 :             TRIM(mc_par%moves_file)
    1617           13 :          WRITE (iw, '( A,T44,A )') ' MC| Name of output energy file:', &
    1618           26 :             TRIM(mc_par%energy_file)
    1619           13 :          WRITE (iw, '( A,T44,A )') ' MC| Name of output cell file:', &
    1620           26 :             TRIM(mc_par%cell_file)
    1621           13 :          WRITE (iw, '( A,A,T44,A )') ' MC| Name of output', &
    1622           13 :             ' displacement file:', &
    1623           26 :             TRIM(mc_par%displacement_file)
    1624           13 :          IF (mc_par%ldiscrete) THEN
    1625            0 :             WRITE (iw, '(A,A,T71,F10.3)') ' MC| discrete step size', &
    1626            0 :                '[angstroms]', &
    1627            0 :                mc_par%discrete_step
    1628              :          ELSE
    1629           13 :             WRITE (iw, '( A,A,T71,F10.3 )') ' MC| rmvolume ', &
    1630           13 :                '[cubic angstroms]', &
    1631           26 :                mc_par%rmvolume
    1632              :          END IF
    1633           13 :          WRITE (iw, '( A,T71,F10.2 )') ' MC| Temperature [K] ', &
    1634           26 :             mc_par%temperature
    1635           13 :          WRITE (iw, '( A,T71,F10.5 )') ' MC| Pressure [bar] ', &
    1636           26 :             mc_par%pressure
    1637           13 :          WRITE (iw, '( A,T71,F10.5 )') ' MC| Rclus [ang] ', &
    1638           26 :             mc_par%rclus
    1639           13 :          IF (mc_par%lrestart) THEN
    1640            1 :             WRITE (iw, '(A,A)') ' MC| Initial data will be read from a', &
    1641            2 :                ' restart file.'
    1642              :          END IF
    1643           13 :          IF (mc_par%lbias) THEN
    1644            7 :             WRITE (iw, '(A)') ' MC| The moves will be biased.'
    1645              :          ELSE
    1646            6 :             WRITE (iw, '(A)') ' MC| The moves will not be biased,'
    1647              :          END IF
    1648           13 :          IF (mc_par%nmoves == 1) THEN
    1649           10 :             WRITE (iw, '(A,A)') ' MC| A full energy calculation ', &
    1650           20 :                'will be done at every step.'
    1651              :          ELSE
    1652            3 :             WRITE (iw, '(A,I4,A,A)') ' MC| ', mc_par%nmoves, &
    1653            3 :                ' moves will be attempted ', &
    1654            6 :                'before a Quickstep energy calculation'
    1655            3 :             WRITE (iw, '(A)') ' MC|      takes place.'
    1656              :          END IF
    1657              : 
    1658           13 :          WRITE (iw, '(A,I4,A,A)') ' MC| ', mc_par%nswapmoves, &
    1659           13 :             ' swap insertions will be attempted ', &
    1660           26 :             'per molecular swap move'
    1661              : 
    1662           13 :          IF (mc_par%lhmc) THEN
    1663            1 :             WRITE (iw, '(A)') '********************************************************'
    1664            1 :             WRITE (iw, '(A)') '************** ONLY DOING HYBRID MONTE CARLO MOVES **************************'
    1665            1 :             WRITE (iw, '(A)') '********************************************************'
    1666              : 
    1667              :          END IF
    1668              :       END IF
    1669              : 
    1670              : ! figure out what beta (1/kT) is in atomic units (1/Hartree)
    1671           26 :       mc_par%BETA = 1/mc_par%temperature/boltzmann*joule
    1672              : 
    1673              :       ! 0.9_dp is to avoid overflow or underflow
    1674           26 :       mc_par%exp_max_val = 0.9_dp*LOG(HUGE(0.0_dp))
    1675           26 :       mc_par%exp_min_val = 0.9_dp*LOG(TINY(0.0_dp))
    1676           26 :       mc_par%max_val = EXP(mc_par%exp_max_val)
    1677           26 :       mc_par%min_val = 0.0_dp
    1678              : 
    1679              : ! convert from bar to a.u.
    1680           26 :       mc_par%pressure = cp_unit_to_cp2k(mc_par%pressure, "bar")
    1681           26 :       mc_par%rclus = cp_unit_to_cp2k(mc_par%rclus, "angstrom")
    1682              : ! convert from angstrom to a.u.
    1683           68 :       DO itype = 1, mc_par%mc_molecule_info%nmol_types
    1684              : ! convert from Kelvin to a.u.
    1685              : !         mc_par % eta = mc_par%eta(itype) * boltzmann / joule
    1686              : ! convert from degrees to radians
    1687           42 :          mc_par%rmrot(itype) = mc_par%rmrot(itype)/180.0e0_dp*pi
    1688           42 :          mc_par%rmangle(itype) = mc_par%rmangle(itype)/180.0e0_dp*pi
    1689           42 :          mc_par%rmdihedral(itype) = mc_par%rmdihedral(itype)/180.0e0_dp*pi
    1690           42 :          mc_par%rmtrans(itype) = cp_unit_to_cp2k(mc_par%rmtrans(itype), "angstrom")
    1691           42 :          mc_par%rmbond(itype) = cp_unit_to_cp2k(mc_par%rmbond(itype), "angstrom")
    1692           42 :          mc_par%eta(itype) = cp_unit_to_cp2k(mc_par%eta(itype), "K_e")
    1693           42 :          mc_par%avbmc_rmin(itype) = cp_unit_to_cp2k(mc_par%avbmc_rmin(itype), "angstrom")
    1694           68 :          mc_par%avbmc_rmax(itype) = cp_unit_to_cp2k(mc_par%avbmc_rmax(itype), "angstrom")
    1695              :       END DO
    1696           26 :       mc_par%rmvolume = cp_unit_to_cp2k(mc_par%rmvolume, "angstrom^3")
    1697           26 :       mc_par%rmcltrans = cp_unit_to_cp2k(mc_par%rmcltrans, "angstrom")
    1698           26 :       mc_par%discrete_step = cp_unit_to_cp2k(mc_par%discrete_step, "angstrom")
    1699              : 
    1700              : ! end the timing
    1701           26 :       CALL timestop(handle)
    1702              : 
    1703           26 :    END SUBROUTINE read_mc_section
    1704              : 
    1705              : ! **************************************************************************************************
    1706              : !> \brief finds the largest interaction cutoff value in a classical simulation
    1707              : !>      so we know the smallest size we can make the box in a volume move
    1708              : !> \param mc_par the structure that will store the parameters
    1709              : !> \param force_env the force environment that we'll grab the rcut parameter
    1710              : !>                   out of
    1711              : !> \param lterminate set to .TRUE. if one of the sides of the box is
    1712              : !>            less than twice the cutoff
    1713              : !>
    1714              : !>    Suitable for parallel.
    1715              : !> \author MJM
    1716              : ! **************************************************************************************************
    1717           14 :    SUBROUTINE find_mc_rcut(mc_par, force_env, lterminate)
    1718              : 
    1719              :       TYPE(mc_simpar_type), INTENT(INOUT)                :: mc_par
    1720              :       TYPE(force_env_type), POINTER                      :: force_env
    1721              :       LOGICAL, INTENT(OUT)                               :: lterminate
    1722              : 
    1723              :       INTEGER                                            :: itype, jtype
    1724              :       REAL(KIND=dp)                                      :: rcutsq_max
    1725              :       REAL(KIND=dp), DIMENSION(1:3)                      :: abc
    1726              :       TYPE(cell_type), POINTER                           :: cell
    1727              :       TYPE(fist_environment_type), POINTER               :: fist_env
    1728              :       TYPE(fist_nonbond_env_type), POINTER               :: fist_nonbond_env
    1729              :       TYPE(pair_potential_pp_type), POINTER              :: potparm
    1730              : 
    1731           14 :       NULLIFY (cell, potparm, fist_nonbond_env, fist_env)
    1732              : 
    1733           14 :       lterminate = .FALSE.
    1734           14 :       CALL force_env_get(force_env, fist_env=fist_env)
    1735              :       CALL fist_env_get(fist_env, cell=cell, &
    1736           14 :                         fist_nonbond_env=fist_nonbond_env)
    1737           14 :       CALL fist_nonbond_env_get(fist_nonbond_env, potparm=potparm)
    1738           14 :       CALL get_cell(cell, abc=abc)
    1739              : 
    1740              : ! find the largest value of rcutsq
    1741           14 :       rcutsq_max = 0.0e0_dp
    1742           50 :       DO itype = 1, SIZE(potparm%pot, 1)
    1743          118 :          DO jtype = itype, SIZE(potparm%pot, 2)
    1744          104 :             IF (potparm%pot(itype, jtype)%pot%rcutsq > rcutsq_max) THEN
    1745              :                rcutsq_max = potparm%pot(itype, jtype)%pot%rcutsq
    1746              :             END IF
    1747              :          END DO
    1748              :       END DO
    1749              : 
    1750              : ! check to make sure all box dimensions are greater than two times this
    1751              : ! value
    1752           14 :       mc_par%rcut = rcutsq_max**0.5_dp
    1753           56 :       DO itype = 1, 3
    1754           56 :          IF (abc(itype) < 2.0_dp*mc_par%rcut) THEN
    1755            0 :             lterminate = .TRUE.
    1756              :          END IF
    1757              :       END DO
    1758              : 
    1759           14 :    END SUBROUTINE find_mc_rcut
    1760              : 
    1761              : ! **************************************************************************************************
    1762              : !> \brief figures out the number of total molecules, the number of atoms in each
    1763              : !>      molecule, an array with the molecule types, etc...a lot of information
    1764              : !>      that we need.  I did this because I use multiple force_env (simulation
    1765              : !>      boxes) for MC, and they don't know about each other.
    1766              : !> \param force_env the pointer containing all the force environments in the
    1767              : !>        simulation
    1768              : !> \param mc_molecule_info the structure that will hold all the information
    1769              : !>          for the molecule types
    1770              : !>
    1771              : !>    Suitable for parallel.
    1772              : !> \param box_number ...
    1773              : !> \param coordinates_empty ...
    1774              : !> \author MJM
    1775              : ! **************************************************************************************************
    1776           62 :    SUBROUTINE mc_determine_molecule_info(force_env, mc_molecule_info, box_number, &
    1777              :                                          coordinates_empty)
    1778              : 
    1779              :       TYPE(force_env_p_type), DIMENSION(:), POINTER      :: force_env
    1780              :       TYPE(mc_molecule_info_type), POINTER               :: mc_molecule_info
    1781              :       INTEGER, INTENT(IN), OPTIONAL                      :: box_number
    1782              :       REAL(dp), DIMENSION(:, :), OPTIONAL, POINTER       :: coordinates_empty
    1783              : 
    1784              :       CHARACTER(LEN=default_string_length)               :: name
    1785              :       CHARACTER(LEN=default_string_length), &
    1786           62 :          ALLOCATABLE, DIMENSION(:)                       :: names_init
    1787              :       INTEGER :: first_mol, iatom, ibox, imol, imolecule, itype, iunique, iunit, jtype, last_mol, &
    1788              :          natom, natoms_large, nbend, nbond, nboxes, nmol_types, nmolecule, ntorsion, ntypes, &
    1789              :          skip_box, this_molecule, total
    1790           62 :       INTEGER, DIMENSION(:), POINTER                     :: molecule_list
    1791              :       LOGICAL                                            :: lnew_type
    1792           62 :       TYPE(atom_type), DIMENSION(:), POINTER             :: atom_list
    1793              :       TYPE(atomic_kind_type), POINTER                    :: atomic_kind
    1794              :       TYPE(cp_subsys_type), POINTER                      :: subsys
    1795              :       TYPE(molecule_kind_list_p_type), DIMENSION(:), &
    1796           62 :          POINTER                                         :: molecule_kinds
    1797              :       TYPE(molecule_kind_type), POINTER                  :: molecule_kind
    1798           62 :       TYPE(particle_list_p_type), DIMENSION(:), POINTER  :: particles
    1799              : 
    1800              : ! how many simulation boxes do we have?
    1801              : 
    1802           62 :       nboxes = SIZE(force_env(:))
    1803              : 
    1804              : ! allocate the pointer
    1805            0 :       ALLOCATE (mc_molecule_info)
    1806           62 :       mc_molecule_info%nboxes = nboxes
    1807              : 
    1808              : ! if box_number is present, that box is supposed to be empty,
    1809              : ! so we don't count it in anything
    1810           62 :       IF (PRESENT(box_number)) THEN
    1811           20 :          skip_box = box_number
    1812              :       ELSE
    1813              :          skip_box = 0
    1814              :       END IF
    1815              : 
    1816              : ! we need to figure out how many different kinds of molecules we have...
    1817              : ! the fun stuff comes in when box 1 is missing a molecule type...I'll
    1818              : ! distinguish molecules based on names from the .psf files...
    1819              : ! this is only really a problem when we have more than one simulation
    1820              : ! box
    1821           62 :       NULLIFY (subsys, molecule_kinds, molecule_kind)
    1822              : 
    1823          282 :       ALLOCATE (particles(1:nboxes))
    1824          220 :       ALLOCATE (molecule_kinds(1:nboxes))
    1825              : 
    1826              :       ! find out how many types we have
    1827              :       ntypes = 0
    1828          158 :       DO ibox = 1, nboxes
    1829           96 :          IF (ibox == skip_box) CYCLE
    1830              :          CALL force_env_get(force_env(ibox)%force_env, &
    1831           96 :                             subsys=subsys)
    1832              :          CALL cp_subsys_get(subsys, &
    1833              :                             molecule_kinds=molecule_kinds(ibox)%list, &
    1834           96 :                             particles=particles(ibox)%list)
    1835          158 :          ntypes = ntypes + SIZE(molecule_kinds(ibox)%list%els(:))
    1836              :       END DO
    1837              : 
    1838          186 :       ALLOCATE (names_init(1:ntypes))
    1839              : 
    1840              : ! now get the names of all types so we can figure out how many distinct
    1841              : ! types we have
    1842          158 :       itype = 1
    1843          158 :       natoms_large = 0
    1844          158 :       DO ibox = 1, nboxes
    1845           96 :          IF (ibox == skip_box) CYCLE
    1846          330 :          DO imolecule = 1, SIZE(molecule_kinds(ibox)%list%els(:))
    1847          172 :             molecule_kind => molecule_kinds(ibox)%list%els(imolecule)
    1848              :             CALL get_molecule_kind(molecule_kind, name=names_init(itype), &
    1849          172 :                                    natom=natom)
    1850          172 :             IF (natom > natoms_large) natoms_large = natom
    1851          268 :             itype = itype + 1
    1852              :          END DO
    1853              :       END DO
    1854              : 
    1855              :       nmol_types = 0
    1856          234 :       DO itype = 1, ntypes
    1857              :          lnew_type = .TRUE.
    1858          384 :          DO jtype = 1, itype - 1
    1859          384 :             IF (TRIM(names_init(itype)) == TRIM(names_init(jtype))) THEN
    1860           68 :                lnew_type = .FALSE.
    1861              :             END IF
    1862              :          END DO
    1863          234 :          IF (lnew_type) THEN
    1864          104 :             nmol_types = nmol_types + 1
    1865              :          ELSE
    1866           68 :             names_init(itype) = ''
    1867              :          END IF
    1868              :       END DO
    1869              : 
    1870              : ! allocate arrays for the names of the molecules, the number of atoms, and
    1871              : ! the conformational probabilities
    1872           62 :       mc_molecule_info%nmol_types = nmol_types
    1873          186 :       ALLOCATE (mc_molecule_info%names(1:nmol_types))
    1874          186 :       ALLOCATE (mc_molecule_info%nunits(1:nmol_types))
    1875          186 :       ALLOCATE (mc_molecule_info%conf_prob(1:3, 1:nmol_types))
    1876          248 :       ALLOCATE (mc_molecule_info%nchains(1:nmol_types, 1:nboxes))
    1877          186 :       ALLOCATE (mc_molecule_info%nunits_tot(1:nboxes))
    1878          248 :       ALLOCATE (mc_molecule_info%atom_names(1:natoms_large, 1:nmol_types))
    1879          248 :       ALLOCATE (mc_molecule_info%mass(1:natoms_large, 1:nmol_types))
    1880              : 
    1881              : ! now record all the information for every molecule type
    1882           62 :       iunique = 0
    1883           62 :       itype = 0
    1884          158 :       DO ibox = 1, nboxes
    1885           96 :          IF (ibox == skip_box) CYCLE
    1886          330 :          DO imolecule = 1, SIZE(molecule_kinds(ibox)%list%els(:))
    1887          172 :             itype = itype + 1
    1888          172 :             IF (names_init(itype) == '') CYCLE
    1889          104 :             iunique = iunique + 1
    1890          104 :             mc_molecule_info%names(iunique) = names_init(itype)
    1891          104 :             molecule_kind => molecule_kinds(ibox)%list%els(imolecule)
    1892              :             CALL get_molecule_kind(molecule_kind, natom=mc_molecule_info%nunits(iunique), &
    1893          104 :                                    nbond=nbond, nbend=nbend, ntorsion=ntorsion, atom_list=atom_list)
    1894              : 
    1895          320 :             DO iatom = 1, mc_molecule_info%nunits(iunique)
    1896          216 :                atomic_kind => atom_list(iatom)%atomic_kind
    1897              :                CALL get_atomic_kind(atomic_kind=atomic_kind, &
    1898              :                                     name=mc_molecule_info%atom_names(iatom, iunique), &
    1899          320 :                                     mass=mc_molecule_info%mass(iatom, iunique))
    1900              :             END DO
    1901              : 
    1902              : ! compute the probabilities of doing any particular kind of conformation change
    1903          104 :             total = nbond + nbend + ntorsion
    1904              : 
    1905          304 :             IF (total == 0) THEN
    1906          184 :                mc_molecule_info%conf_prob(:, iunique) = 0.0e0_dp
    1907              :             ELSE
    1908           58 :                mc_molecule_info%conf_prob(1, iunique) = REAL(nbond, dp)/REAL(total, dp)
    1909           58 :                mc_molecule_info%conf_prob(2, iunique) = REAL(nbend, dp)/REAL(total, dp)
    1910           58 :                mc_molecule_info%conf_prob(3, iunique) = REAL(ntorsion, dp)/REAL(total, dp)
    1911              :             END IF
    1912              : 
    1913              :          END DO
    1914              :       END DO
    1915              : 
    1916              : ! figure out the empty coordinates
    1917           62 :       IF (PRESENT(coordinates_empty)) THEN
    1918           60 :          ALLOCATE (coordinates_empty(1:3, 1:mc_molecule_info%nunits(1)))
    1919           74 :          DO iunit = 1, mc_molecule_info%nunits(1)
    1920          236 :             coordinates_empty(1:3, iunit) = particles(1)%list%els(iunit)%r(1:3)
    1921              :          END DO
    1922              :       END IF
    1923              : 
    1924              : ! now we need to figure out the total number of molecules of each kind in
    1925              : ! each box, and the total number of interaction sites in each box
    1926          330 :       mc_molecule_info%nchains(:, :) = 0
    1927          166 :       DO iunique = 1, nmol_types
    1928          338 :          DO ibox = 1, nboxes
    1929          172 :             IF (ibox == skip_box) CYCLE
    1930          600 :             DO imolecule = 1, SIZE(molecule_kinds(ibox)%list%els(:))
    1931          324 :                molecule_kind => molecule_kinds(ibox)%list%els(imolecule)
    1932              :                CALL get_molecule_kind(molecule_kind, nmolecule=nmolecule, &
    1933          324 :                                       name=name)
    1934          324 :                IF (TRIM(name) /= mc_molecule_info%names(iunique)) CYCLE
    1935          668 :                mc_molecule_info%nchains(iunique, ibox) = mc_molecule_info%nchains(iunique, ibox) + nmolecule
    1936              :             END DO
    1937              :          END DO
    1938              :       END DO
    1939           62 :       mc_molecule_info%nchain_total = 0
    1940          158 :       DO ibox = 1, nboxes
    1941           96 :          mc_molecule_info%nunits_tot(ibox) = 0
    1942           96 :          IF (ibox == skip_box) CYCLE
    1943          268 :          DO iunique = 1, nmol_types
    1944              :             mc_molecule_info%nunits_tot(ibox) = mc_molecule_info%nunits_tot(ibox) + &
    1945          268 :                                                 mc_molecule_info%nunits(iunique)*mc_molecule_info%nchains(iunique, ibox)
    1946              :          END DO
    1947          330 :          mc_molecule_info%nchain_total = mc_molecule_info%nchain_total + SUM(mc_molecule_info%nchains(:, ibox))
    1948              :       END DO
    1949              : 
    1950              : ! now we need to figure out which type every molecule is,
    1951              : ! and which force_env (box) it's in
    1952          186 :       ALLOCATE (mc_molecule_info%mol_type(1:mc_molecule_info%nchain_total))
    1953          186 :       ALLOCATE (mc_molecule_info%in_box(1:mc_molecule_info%nchain_total))
    1954              : 
    1955           62 :       last_mol = 0
    1956          158 :       DO ibox = 1, nboxes
    1957           96 :          IF (ibox == skip_box) CYCLE
    1958           96 :          first_mol = last_mol + 1
    1959          268 :          last_mol = first_mol + SUM(mc_molecule_info%nchains(:, ibox)) - 1
    1960         5404 :          mc_molecule_info%in_box(first_mol:last_mol) = ibox
    1961          330 :          DO imolecule = 1, SIZE(molecule_kinds(ibox)%list%els(:))
    1962          172 :             molecule_kind => molecule_kinds(ibox)%list%els(imolecule)
    1963              :             CALL get_molecule_kind(molecule_kind, nmolecule=nmolecule, &
    1964          172 :                                    name=name, molecule_list=molecule_list)
    1965              : ! figure out which molecule number this is
    1966          172 :             this_molecule = 0
    1967          496 :             DO iunique = 1, nmol_types
    1968          496 :                IF (TRIM(name) == TRIM(mc_molecule_info%names(iunique))) THEN
    1969          172 :                   this_molecule = iunique
    1970              :                END IF
    1971              :             END DO
    1972         5748 :             DO imol = 1, SIZE(molecule_list(:))
    1973         5480 :                mc_molecule_info%mol_type(first_mol + molecule_list(imol) - 1) = this_molecule
    1974              :             END DO
    1975              :          END DO
    1976              :       END DO
    1977              : 
    1978              : ! get rid of stuff we don't need
    1979           62 :       DEALLOCATE (names_init)
    1980           62 :       DEALLOCATE (molecule_kinds)
    1981           62 :       DEALLOCATE (particles)
    1982              : 
    1983           62 :    END SUBROUTINE MC_DETERMINE_MOLECULE_INFO
    1984              : 
    1985              : ! **************************************************************************************************
    1986              : !> \brief deallocates all the arrays in the mc_molecule_info_type
    1987              : !> \param mc_molecule_info the structure we wish to deallocate
    1988              : !>
    1989              : !>    Suitable for parallel.
    1990              : !> \author MJM
    1991              : ! **************************************************************************************************
    1992           62 :    SUBROUTINE mc_molecule_info_destroy(mc_molecule_info)
    1993              : 
    1994              :       TYPE(mc_molecule_info_type), POINTER               :: mc_molecule_info
    1995              : 
    1996           62 :       DEALLOCATE (mc_molecule_info%nchains)
    1997           62 :       DEALLOCATE (mc_molecule_info%nunits)
    1998           62 :       DEALLOCATE (mc_molecule_info%mol_type)
    1999           62 :       DEALLOCATE (mc_molecule_info%in_box)
    2000           62 :       DEALLOCATE (mc_molecule_info%names)
    2001           62 :       DEALLOCATE (mc_molecule_info%atom_names)
    2002           62 :       DEALLOCATE (mc_molecule_info%conf_prob)
    2003           62 :       DEALLOCATE (mc_molecule_info%nunits_tot)
    2004           62 :       DEALLOCATE (mc_molecule_info%mass)
    2005              : 
    2006           62 :       DEALLOCATE (mc_molecule_info)
    2007              :       NULLIFY (mc_molecule_info)
    2008              : 
    2009           62 :    END SUBROUTINE mc_molecule_info_destroy
    2010              : 
    2011              : ! **************************************************************************************************
    2012              : !> \brief ...
    2013              : !> \param mc_par ...
    2014              : ! **************************************************************************************************
    2015           52 :    SUBROUTINE mc_input_parameters_check(mc_par)
    2016              : 
    2017              : ! **************************************************************************************************
    2018              : !> \brief accesses the private elements of the mc_molecule_info_type
    2019              : !> \param mc_molecule_info the structure you want the parameters for
    2020              : !> \param nmol_types the number of molecule types in the simulation
    2021              : !>
    2022              : !>    Suitable for parallel.
    2023              : !> \author MJM
    2024              :       TYPE(mc_simpar_type), POINTER                      :: mc_par
    2025              : 
    2026              :       INTEGER                                            :: imol_type, nboxes, nchain_total, &
    2027              :                                                             nmol_types
    2028           26 :       INTEGER, DIMENSION(:), POINTER                     :: nunits
    2029              :       LOGICAL                                            :: lhmc
    2030              :       TYPE(mc_molecule_info_type), POINTER               :: mc_molecule_info
    2031              : 
    2032           26 :       CALL get_mc_par(mc_par, mc_molecule_info=mc_molecule_info, lhmc=lhmc)
    2033              : 
    2034              :       CALL get_mc_molecule_info(mc_molecule_info, nmol_types=nmol_types, &
    2035           26 :                                 nboxes=nboxes, nunits=nunits, nchain_total=nchain_total)
    2036              : 
    2037              : ! if we're only doing HMC, we can skip these checks
    2038           26 :       IF (lhmc) RETURN
    2039              : 
    2040              : ! the final value of these arrays needs to be 1.0, otherwise there is
    2041              : ! a chance we won't select a molecule type for a move
    2042           24 :       IF (mc_par%pmavbmc_mol(nmol_types) < 0.9999E0_dp) THEN
    2043            0 :          CPABORT('The last value of PMAVBMC_MOL needs to be 1.0')
    2044              :       END IF
    2045           24 :       IF (mc_par%pmswap_mol(nmol_types) < 0.9999E0_dp) THEN
    2046            0 :          CPABORT('The last value of PMSWAP_MOL needs to be 1.0')
    2047              :       END IF
    2048           24 :       IF (mc_par%pmtraion_mol(nmol_types) < 0.9999E0_dp) THEN
    2049            0 :          CPABORT('The last value of PMTRAION_MOL needs to be 1.0')
    2050              :       END IF
    2051           24 :       IF (mc_par%pmtrans_mol(nmol_types) < 0.9999E0_dp) THEN
    2052            0 :          CPABORT('The last value of PMTRANS_MOL needs to be 1.0')
    2053              :       END IF
    2054           24 :       IF (mc_par%pmrot_mol(nmol_types) < 0.9999E0_dp) THEN
    2055            0 :          CPABORT('The last value of PMROT_MOL needs to be 1.0')
    2056              :       END IF
    2057              : 
    2058              : ! check to make sure we have all the desired values for various
    2059              : 
    2060              :       ! some ensembles require multiple boxes or molecule types
    2061           28 :       SELECT CASE (mc_par%ensemble)
    2062              :       CASE ("GEMC_NPT")
    2063            4 :          IF (nmol_types <= 1) THEN
    2064            0 :             CPABORT('Cannot have GEMC-NPT simulation with only one molecule type')
    2065              :          END IF
    2066            4 :          IF (nboxes <= 1) THEN
    2067            0 :             CPABORT('Cannot have GEMC-NPT simulation with only one box')
    2068              :          END IF
    2069              :       CASE ("GEMC_NVT")
    2070            8 :          IF (nboxes <= 1) THEN
    2071            0 :             CPABORT('Cannot have GEMC-NVT simulation with only one box')
    2072              :          END IF
    2073              :       CASE ("TRADITIONAL")
    2074           10 :          IF (mc_par%pmswap > 0.0E0_dp) THEN
    2075            0 :             CPABORT('You cannot do swap moves in a system with only one box')
    2076              :          END IF
    2077              :       CASE ("VIRIAL")
    2078           24 :          IF (nchain_total /= 2) THEN
    2079            0 :             CPABORT('You need exactly two molecules in the box to compute the second virial.')
    2080              :          END IF
    2081              :       END SELECT
    2082              : 
    2083              : ! can't choose an AVBMC target atom number higher than the number
    2084              : ! of units in that molecule
    2085           64 :       DO imol_type = 1, nmol_types
    2086           64 :          IF (mc_par%avbmc_atom(imol_type) > nunits(imol_type)) THEN
    2087            0 :             CPABORT('Cannot have avbmc_atom higher than the number of atoms for that molecule type!')
    2088              :          END IF
    2089              :       END DO
    2090              : 
    2091           26 :    END SUBROUTINE mc_input_parameters_check
    2092              : 
    2093            0 : END MODULE mc_types
    2094              : 
        

Generated by: LCOV version 2.0-1