(git:ba1d7ca)
Loading...
Searching...
No Matches
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-2026 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
19 USE cell_types, ONLY: cell_clone,&
29 USE input_constants, ONLY: fix_none,&
30 fix_x,&
31 fix_xy,&
32 fix_xz,&
33 fix_y,&
34 fix_yz,&
35 fix_z
38 USE kinds, ONLY: dp
39#include "../base/base_uses.f90"
40
41 IMPLICIT NONE
42 PRIVATE
43
44 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
45 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_opt_types'
46
47 PUBLIC :: cell_opt_env_type, &
50
51! **************************************************************************************************
52!> \brief Type containing all informations abour the simulation cell optimization
53!> \par History
54!> none
55!> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
56! **************************************************************************************************
58 ! Simulation cell optimization parameters
59 INTEGER :: constraint_id = fix_none
60 LOGICAL :: keep_angles = .false., &
61 keep_symmetry = .false., &
62 keep_volume = .false.
63 REAL(kind=dp) :: pres_ext = 0.0_dp, pres_int = 0.0_dp, pres_tol = 0.0_dp, pres_constr = 0.0_dp
64 REAL(kind=dp), DIMENSION(3, 3) :: mtrx = 0.0_dp
65 ! Fixed rotations between the user's Cartesian frame and the canonical
66 ! frame used for the six independent cell optimization variables.
67 REAL(kind=dp), DIMENSION(3, 3) :: input_to_opt = 0.0_dp, &
68 opt_to_input = 0.0_dp
69 TYPE(cell_type), POINTER :: opt_cell => null()
70 END TYPE cell_opt_env_type
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief ...
76!> \param cell_env ...
77!> \param force_env ...
78!> \param geo_section ...
79!> \par History
80!> none
81!> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
82! **************************************************************************************************
83 SUBROUTINE cell_opt_env_create(cell_env, force_env, geo_section)
84 TYPE(cell_opt_env_type), INTENT(OUT) :: cell_env
85 TYPE(force_env_type), POINTER :: force_env
86 TYPE(section_vals_type), POINTER :: geo_section
87
88 CHARACTER(LEN=4) :: label
89 INTEGER :: output_unit, required_constraint_id
90 LOGICAL :: constraint_explicit, valid_constraint
91 TYPE(cell_type), POINTER :: cell
92 TYPE(cp_logger_type), POINTER :: logger
93
94 NULLIFY (cell_env%opt_cell, cell)
95 CALL force_env_get(force_env, cell=cell)
96 CALL cell_create(cell_env%opt_cell)
97 CALL cell_clone(cell, cell_env%opt_cell, tag="CELL_OPT_CANONICAL")
98 CALL canonicalize_cell_matrix(cell_env%opt_cell)
99 ! Keep the physical cell in the input orientation while the optimizer
100 ! works with the canonical cell and its six non-redundant components.
101 cell_env%input_to_opt = matmul(cell_env%opt_cell%hmat, cell%h_inv)
102 cell_env%opt_to_input = matmul(cell%hmat, cell_env%opt_cell%h_inv)
103 CALL section_vals_val_get(geo_section, "KEEP_VOLUME", l_val=cell_env%keep_volume)
104 CALL section_vals_val_get(geo_section, "KEEP_ANGLES", l_val=cell_env%keep_angles)
105 CALL section_vals_val_get(geo_section, "KEEP_SYMMETRY", l_val=cell_env%keep_symmetry)
106 CALL section_vals_val_get(geo_section, "PRESSURE_TOLERANCE", r_val=cell_env%pres_tol)
107 CALL section_vals_val_get(geo_section, "CONSTRAINT", &
108 i_val=cell_env%constraint_id, explicit=constraint_explicit)
109 IF (count(cell%perd /= 0) == 2) THEN
110 required_constraint_id = fix_none
111 IF (cell%perd(1) == 0) required_constraint_id = fix_x
112 IF (cell%perd(2) == 0) required_constraint_id = fix_y
113 IF (cell%perd(3) == 0) required_constraint_id = fix_z
114
115 SELECT CASE (required_constraint_id)
116 CASE (fix_x)
117 valid_constraint = cell_env%constraint_id == fix_x .OR. &
118 cell_env%constraint_id == fix_xy .OR. &
119 cell_env%constraint_id == fix_xz
120 CASE (fix_y)
121 valid_constraint = cell_env%constraint_id == fix_y .OR. &
122 cell_env%constraint_id == fix_xy .OR. &
123 cell_env%constraint_id == fix_yz
124 CASE (fix_z)
125 valid_constraint = cell_env%constraint_id == fix_z .OR. &
126 cell_env%constraint_id == fix_xz .OR. &
127 cell_env%constraint_id == fix_yz
128 CASE DEFAULT
129 valid_constraint = .false.
130 END SELECT
131
132 IF (cell_env%constraint_id == fix_none .AND. .NOT. constraint_explicit) THEN
133 cell_env%constraint_id = required_constraint_id
134 CALL cp_warn(__location__, &
135 "2D CELL_OPT: constraining non-periodic cell direction.")
136 ELSE IF (.NOT. valid_constraint) THEN
137 CALL cp_abort(__location__, &
138 "2D CELL_OPT needs constrained non-periodic cell direction.")
139 END IF
140 END IF
141
142 ! Get the external pressure
143 CALL read_external_press_tensor(geo_section, cell_env%opt_cell, cell_env%pres_ext, &
144 cell_env%mtrx, cell_env%input_to_opt)
145
146 ! Print cell optimisation setup
147 NULLIFY (logger)
148 logger => cp_get_default_logger()
149 output_unit = cp_print_key_unit_nr(logger, geo_section, "PRINT%CELL", extension=".Log")
150 IF (output_unit > 0) THEN
151 WRITE (unit=output_unit, fmt="(/,T2,A,T61,F20.1)") &
152 "CELL_OPT| Pressure tolerance [bar]: ", cp_unit_from_cp2k(cell_env%pres_tol, "bar")
153 IF (cell_env%keep_volume) THEN
154 WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
155 "CELL_OPT| Keep volume of cell: ", "YES"
156 ELSE
157 WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
158 "CELL_OPT| Keep volume of cell: ", " NO"
159 END IF
160 IF (cell_env%keep_angles) THEN
161 WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
162 "CELL_OPT| Keep angles between the cell vectors: ", "YES"
163 ELSE
164 WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
165 "CELL_OPT| Keep angles between the cell vectors: ", " NO"
166 END IF
167 IF (cell_env%keep_symmetry) THEN
168 WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
169 "CELL_OPT| Keep cell symmetry: ", "YES"
170 ELSE
171 WRITE (unit=output_unit, fmt="(T2,A,T78,A3)") &
172 "CELL_OPT| Keep cell symmetry: ", " NO"
173 END IF
174 SELECT CASE (cell_env%constraint_id)
175 CASE (fix_x)
176 label = " X"
177 CASE (fix_y)
178 label = " Y"
179 CASE (fix_z)
180 label = " Z"
181 CASE (fix_xy)
182 label = " XY"
183 CASE (fix_xz)
184 label = " XZ"
185 CASE (fix_yz)
186 label = " YZ"
187 CASE (fix_none)
188 label = "NONE"
189 END SELECT
190 WRITE (unit=output_unit, fmt="(T2,A,T77,A4)") &
191 "CELL_OPT| Constraint: ", label
192 END IF
193 CALL cp_print_key_finished_output(output_unit, logger, geo_section, "PRINT%CELL")
194
195 END SUBROUTINE cell_opt_env_create
196
197! **************************************************************************************************
198!> \brief ...
199!> \param cell_env ...
200!> \par History
201!> none
202!> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
203! **************************************************************************************************
204 SUBROUTINE cell_opt_env_release(cell_env)
205 TYPE(cell_opt_env_type), INTENT(INOUT) :: cell_env
206
207 CALL cell_release(cell_env%opt_cell)
208
209 END SUBROUTINE cell_opt_env_release
210
211END MODULE cell_opt_types
Handles all functions related to the CELL.
subroutine, public canonicalize_cell_matrix(cell)
Canonicalize a general cell matrix without changing lengths and angles.
subroutine, public cell_create(cell, hmat, periodic, tag)
allocates and initializes a cell
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, input_to_opt)
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:668
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
Definition cell_types.F:141
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,...
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:1251
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, ipi_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
Type containing all informations abour the simulation cell optimization.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
wrapper to abstract the force evaluation of the various methods