(git:b279b6b)
cell_opt_types.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Contains type used for a Simulation Cell Optimization
10 !> \par History
11 !> none
12 !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
13 ! **************************************************************************************************
15 
16  USE cell_methods, ONLY: cell_create
18  USE cell_types, ONLY: cell_clone,&
19  cell_release,&
20  cell_type
22  cp_logger_type
25  USE cp_subsys_types, ONLY: cp_subsys_get,&
26  cp_subsys_type
27  USE cp_units, ONLY: cp_unit_from_cp2k
28  USE force_env_types, ONLY: force_env_get,&
29  force_env_type
30  USE input_constants, ONLY: fix_none,&
31  fix_x,&
32  fix_xy,&
33  fix_xz,&
34  fix_y,&
35  fix_yz,&
36  fix_z
37  USE input_section_types, ONLY: section_vals_type,&
39  USE kinds, ONLY: dp
40  USE particle_list_types, ONLY: particle_list_type
41 #include "../base/base_uses.f90"
42 
43  IMPLICIT NONE
44  PRIVATE
45 
46  LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
47  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_opt_types'
48 
49  PUBLIC :: cell_opt_env_type, &
52 
53 ! **************************************************************************************************
54 !> \brief Type containing all informations abour the simulation cell optimization
55 !> \par History
56 !> none
57 !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
58 ! **************************************************************************************************
59  TYPE cell_opt_env_type
60  ! Simulation cell optimization parameters
61  INTEGER :: constraint_id = fix_none
62  LOGICAL :: keep_angles = .false., &
63  keep_symmetry = .false.
64  REAL(KIND=dp) :: pres_ext = 0.0_dp, pres_int = 0.0_dp, pres_tol = 0.0_dp, pres_constr = 0.0_dp
65  REAL(KIND=dp), DIMENSION(3, 3) :: mtrx = 0.0_dp
66  REAL(KIND=dp), DIMENSION(3, 3) :: rot_matrix = 0.0_dp
67  TYPE(cell_type), POINTER :: ref_cell => null()
68  END TYPE cell_opt_env_type
69 
70 CONTAINS
71 
72 ! **************************************************************************************************
73 !> \brief ...
74 !> \param cell_env ...
75 !> \param force_env ...
76 !> \param geo_section ...
77 !> \par History
78 !> none
79 !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
80 ! **************************************************************************************************
81  SUBROUTINE cell_opt_env_create(cell_env, force_env, geo_section)
82  TYPE(cell_opt_env_type), INTENT(OUT) :: cell_env
83  TYPE(force_env_type), POINTER :: force_env
84  TYPE(section_vals_type), POINTER :: geo_section
85 
86  CHARACTER(LEN=4) :: label
87  INTEGER :: ip, output_unit
88  REAL(kind=dp), DIMENSION(3) :: r
89  TYPE(cell_type), POINTER :: cell
90  TYPE(cp_logger_type), POINTER :: logger
91  TYPE(cp_subsys_type), POINTER :: subsys
92  TYPE(particle_list_type), POINTER :: particles
93 
94  NULLIFY (cell_env%ref_cell, cell, subsys, particles)
95  CALL force_env_get(force_env, cell=cell, subsys=subsys)
96  CALL cell_create(cell_env%ref_cell)
97  CALL cell_clone(cell, cell_env%ref_cell, tag="REF_CELL_OPT")
98  CALL section_vals_val_get(geo_section, "KEEP_ANGLES", l_val=cell_env%keep_angles)
99  CALL section_vals_val_get(geo_section, "KEEP_SYMMETRY", l_val=cell_env%keep_symmetry)
100  CALL section_vals_val_get(geo_section, "PRESSURE_TOLERANCE", r_val=cell_env%pres_tol)
101  CALL section_vals_val_get(geo_section, "CONSTRAINT", i_val=cell_env%constraint_id)
102 
103  ! Compute the rotation matrix that give the cell vectors in the "canonical" orientation
104  cell_env%rot_matrix = matmul(cell_env%ref_cell%hmat, cell%h_inv)
105 
106  ! Get the external pressure
107  CALL read_external_press_tensor(geo_section, cell, cell_env%pres_ext, cell_env%mtrx, &
108  cell_env%rot_matrix)
109 
110  ! Rotate particles accordingly
111  CALL cp_subsys_get(subsys, particles=particles)
112  DO ip = 1, particles%n_els
113  r = matmul(transpose(cell_env%rot_matrix), particles%els(ip)%r)
114  particles%els(ip)%r = r
115  END DO
116 
117  ! Print cell optimisation setup
118  NULLIFY (logger)
119  logger => cp_get_default_logger()
120  output_unit = cp_print_key_unit_nr(logger, geo_section, "PRINT%CELL", extension=".Log")
121  IF (output_unit > 0) THEN
122  WRITE (unit=output_unit, fmt="(/,T2,A,T61,F20.1)") &
123  "CELL_OPT| Pressure tolerance [bar]: ", cp_unit_from_cp2k(cell_env%pres_tol, "bar")
124  IF (cell_env%keep_angles) THEN
125  WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
126  "CELL_OPT| Keep angles between the cell vectors: ", "YES"
127  ELSE
128  WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
129  "CELL_OPT| Keep angles between the cell vectors: ", " NO"
130  END IF
131  IF (cell_env%keep_symmetry) THEN
132  WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
133  "CELL_OPT| Keep cell symmetry: ", "YES"
134  ELSE
135  WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
136  "CELL_OPT| Keep cell symmetry: ", " NO"
137  END IF
138  SELECT CASE (cell_env%constraint_id)
139  CASE (fix_x)
140  label = " X"
141  CASE (fix_y)
142  label = " Y"
143  CASE (fix_z)
144  label = " Z"
145  CASE (fix_xy)
146  label = " XY"
147  CASE (fix_xz)
148  label = " XZ"
149  CASE (fix_yz)
150  label = " YZ"
151  CASE (fix_none)
152  label = "NONE"
153  END SELECT
154  WRITE (unit=output_unit, fmt="(T2,A,T77,A4)") &
155  "CELL_OPT| Constraint: ", label
156  END IF
157  CALL cp_print_key_finished_output(output_unit, logger, geo_section, "PRINT%CELL")
158 
159  END SUBROUTINE cell_opt_env_create
160 
161 ! **************************************************************************************************
162 !> \brief ...
163 !> \param cell_env ...
164 !> \par History
165 !> none
166 !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
167 ! **************************************************************************************************
168  SUBROUTINE cell_opt_env_release(cell_env)
169  TYPE(cell_opt_env_type), INTENT(INOUT) :: cell_env
170 
171  CALL cell_release(cell_env%ref_cell)
172 
173  END SUBROUTINE cell_opt_env_release
174 
175 END MODULE cell_opt_types
Handles all functions related to the CELL.
Definition: cell_methods.F:15
subroutine, public cell_create(cell, hmat, periodic, tag)
allocates and initializes a cell
Definition: cell_methods.F:85
Contains type used for a Simulation Cell Optimization.
subroutine, public cell_opt_env_release(cell_env)
...
subroutine, public cell_opt_env_create(cell_env, force_env, geo_section)
...
contains a functional that calculates the energy and its derivatives for the geometry optimizer
subroutine, public read_external_press_tensor(geo_section, cell, pres_ext, mtrx, rot)
Reads the external pressure tensor.
Handles all functions related to the CELL.
Definition: cell_types.F:15
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
Definition: cell_types.F:559
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
Definition: cell_types.F:107
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell)
returns information about various attributes of the given subsys
unit conversion facility
Definition: cp_units.F:30
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Definition: cp_units.F:1179
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env)
returns various attributes about the force environment
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public fix_xz
integer, parameter, public fix_y
integer, parameter, public fix_none
integer, parameter, public fix_z
integer, parameter, public fix_xy
integer, parameter, public fix_yz
integer, parameter, public fix_x
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
represent a simple array based list of the given type