45#include "../base/base_uses.f90"
50 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cell_opt_types'
51 REAL(KIND=
dp),
PARAMETER,
PRIVATE :: canonical_frame_warn_tol = 1.0e-6_dp
69 LOGICAL :: keep_angles = .false., &
70 keep_symmetry = .false., &
72 REAL(kind=
dp) :: pres_ext = 0.0_dp, pres_int = 0.0_dp, pres_tol = 0.0_dp, pres_constr = 0.0_dp
73 REAL(kind=
dp),
DIMENSION(3, 3) :: mtrx = 0.0_dp
76 REAL(kind=
dp),
DIMENSION(3, 3) :: input_to_opt = 0.0_dp, &
99 CHARACTER(LEN=default_string_length) :: label
100 CHARACTER(LEN=default_string_length), &
101 DIMENSION(:),
POINTER :: canonical_tokens, constraint_tokens
102 INTEGER :: i, output_unit
103 LOGICAL :: constraint_explicit, &
104 has_frame_dep_constraint
108 NULLIFY (cell_env%opt_cell, cell, canonical_tokens, constraint_tokens)
111 CALL cell_clone(cell, cell_env%opt_cell, tag=
"CELL_OPT_CANONICAL")
115 cell_env%input_to_opt = matmul(cell_env%opt_cell%hmat, cell%h_inv)
116 cell_env%opt_to_input = matmul(cell%hmat, cell_env%opt_cell%h_inv)
122 c_vals=constraint_tokens, explicit=constraint_explicit)
124 cell_env%constraint_id)
126 IF (cell_env%keep_symmetry .AND. cell_env%opt_cell%symmetry_id ==
cell_sym_none)
THEN
128 CALL cp_warn(__location__, &
129 "CELL_OPT: KEEP_SYMMETRY is active, but &SUBSYS/&CELL SYMMETRY "// &
130 "is NONE. CELL_OPT applies no symmetry constraint. Set "// &
131 "&SUBSYS/&CELL SYMMETRY to specify the crystal system.")
134 has_frame_dep_constraint = (.NOT. constraint_explicit .AND. &
138 IF (constraint_explicit)
THEN
139 ALLOCATE (canonical_tokens(
SIZE(constraint_tokens)))
140 canonical_tokens = constraint_tokens
142 DO i = 1,
SIZE(canonical_tokens)
143 SELECT CASE (trim(adjustl(canonical_tokens(i))))
144 CASE (
"NONE",
"A",
"B",
"C",
"ALPHA",
"BETA",
"GAMMA")
147 has_frame_dep_constraint = .true.
153 IF (has_frame_dep_constraint .AND. &
154 maxval(abs(cell%hmat - cell_env%opt_cell%hmat)) > &
155 canonical_frame_warn_tol*max(1.0_dp, maxval(abs(cell%hmat))))
THEN
156 CALL cp_warn(__location__, &
157 "CELL_OPT: Axis and component constraints act on the canonical "// &
158 "upper-triangular cell, not on the rotated input axes.")
163 cell_env%mtrx, cell_env%input_to_opt)
169 IF (output_unit > 0)
THEN
170 WRITE (unit=output_unit, fmt=
"(/,T2,A,T61,F20.1)") &
171 "CELL_OPT| Pressure tolerance [bar]: ",
cp_unit_from_cp2k(cell_env%pres_tol,
"bar")
172 IF (cell_env%keep_volume)
THEN
173 WRITE (unit=output_unit, fmt=
"(T2,A,T78,A3)") &
174 "CELL_OPT| Keep volume of cell: ",
"YES"
176 WRITE (unit=output_unit, fmt=
"(T2,A,T78,A3)") &
177 "CELL_OPT| Keep volume of cell: ",
" NO"
179 IF (cell_env%keep_angles)
THEN
180 WRITE (unit=output_unit, fmt=
"(T2,A,T78,A3)") &
181 "CELL_OPT| Keep angles between the cell vectors: ",
"YES"
183 WRITE (unit=output_unit, fmt=
"(T2,A,T78,A3)") &
184 "CELL_OPT| Keep angles between the cell vectors: ",
" NO"
186 IF (cell_env%keep_symmetry)
THEN
187 WRITE (unit=output_unit, fmt=
"(T2,A,T78,A3)") &
188 "CELL_OPT| Keep cell symmetry: ",
"YES"
190 WRITE (unit=output_unit, fmt=
"(T2,A,T78,A3)") &
191 "CELL_OPT| Keep cell symmetry: ",
" NO"
194 IF (count(cell%perd /= 0) == 2 .AND. .NOT. constraint_explicit)
THEN
195 label = trim(label)//
" (auto)"
197 WRITE (unit=output_unit, fmt=
"(T2,A,T77,A)") &
198 "CELL_OPT| Constraint: ", trim(label)
211 LOGICAL,
INTENT(IN),
OPTIONAL :: emit_warnings
213 INTEGER :: angle_bits, info
218 IF (
PRESENT(emit_warnings)) do_warn = emit_warnings
224 CALL cp_abort(__location__, &
225 "CELL_OPT: initial cell or CONSTRAINT is invalid ("// &
228 CALL try_add_mask_bits(cell_env%manifold, iand(cell_env%constraint_id,
gfix_all), &
229 "CONSTRAINT", do_warn)
231 IF (cell_env%keep_symmetry)
THEN
233 emit_warnings=do_warn)
236 IF (cell_env%keep_angles)
THEN
239 IF (cell_env%opt_cell%orthorhombic)
THEN
244 CALL try_add_mask_bits(cell_env%manifold, angle_bits,
"KEEP_ANGLES", do_warn)
247 IF (cell_env%keep_volume)
THEN
248 CALL try_add_mask_bits(cell_env%manifold,
gfix_v,
"KEEP_VOLUME", do_warn)
265 INTEGER,
INTENT(IN) :: symmetry_id
266 LOGICAL,
INTENT(IN),
OPTIONAL :: emit_warnings
268 INTEGER :: cand_eq_pair(2,
n_geom), cand_n_eq, &
269 cand_n_lin, i, info, n_next, &
270 probe_eq_pair(2,
n_geom), sym_bits
277 IF (
PRESENT(emit_warnings)) do_warn = emit_warnings
280 cand_eq_pair, cand_n_eq)
281 CALL try_add_mask_bits(cell_env%manifold, sym_bits,
"symmetry component constraint", do_warn)
284 n_next = cell_env%manifold%n_lin_rows + 1
286 probe_lin_w = cell_env%manifold%lin_w
287 probe_lin_w(:, n_next) = cand_lin_w(:, i)
289 m_probe, cell_env%manifold%q0, cell_env%manifold%mask, info, &
290 lin_w=probe_lin_w(:, 1:n_next), &
291 eq_pair=cell_env%manifold%eq_pair(:, 1:cell_env%manifold%n_eq_rows))
293 cell_env%manifold = m_probe
295 CALL resolve_degenerate_constraint(cell_env%manifold, info, &
296 "symmetry linear constraint", 0, do_warn, &
297 lin_w=cand_lin_w(:, i:i))
302 n_next = cell_env%manifold%n_eq_rows + 1
303 IF (n_next >
n_geom - 1)
EXIT
304 probe_eq_pair = cell_env%manifold%eq_pair
305 probe_eq_pair(:, n_next) = cand_eq_pair(:, i)
307 m_probe, cell_env%manifold%q0, cell_env%manifold%mask, info, &
308 lin_w=cell_env%manifold%lin_w(:, 1:cell_env%manifold%n_lin_rows), &
309 eq_pair=probe_eq_pair(:, 1:n_next))
311 cell_env%manifold = m_probe
313 CALL resolve_degenerate_constraint(cell_env%manifold, info, &
314 "symmetry equality constraint", 0, do_warn, &
315 eq_pair=cand_eq_pair(:, i:i))
328 SUBROUTINE try_add_mask_bits(m, candidate_bits, source_label, do_warn)
330 INTEGER,
INTENT(IN) :: candidate_bits
331 CHARACTER(LEN=*),
INTENT(IN) :: source_label
332 LOGICAL,
INTENT(IN) :: do_warn
334 INTEGER :: b, flag, info
339 IF (iand(candidate_bits, flag) /= 0 .AND. iand(m%mask, flag) == 0)
THEN
341 lin_w=m%lin_w(:, 1:m%n_lin_rows), &
342 eq_pair=m%eq_pair(:, 1:m%n_eq_rows))
346 CALL resolve_degenerate_constraint(m, info, source_label, flag, do_warn)
351 END SUBROUTINE try_add_mask_bits
363 SUBROUTINE resolve_degenerate_constraint(m, info, source_label, mask, do_warn, lin_w, eq_pair)
365 INTEGER,
INTENT(IN) :: info
366 CHARACTER(LEN=*),
INTENT(IN) :: source_label
367 INTEGER,
INTENT(IN) :: mask
368 LOGICAL,
INTENT(IN) :: do_warn
369 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: lin_w(:, :)
370 INTEGER,
INTENT(IN),
OPTIONAL :: eq_pair(:, :)
372 INTEGER :: old_mask, old_n_lin, pinned_bits
377 old_n_lin = m%n_lin_rows
381 pinned_bits = iand(iand(not(old_mask), m%mask),
mask_all)
382 IF (pinned_bits /= 0 .AND. m%n_lin_rows == old_n_lin)
THEN
383 CALL cp_warn(__location__, &
384 "CELL_OPT: "//trim(source_label)//
" is locally degenerate at "// &
385 "the initial cell. CELL_OPT pins implied cell component(s): "// &
388 CALL cp_warn(__location__, &
389 "CELL_OPT: "//trim(source_label)//
" is locally degenerate at "// &
390 "the initial cell. CELL_OPT pins implied tangent direction(s).")
398 CALL cp_abort(__location__, &
399 "CELL_OPT: "//trim(source_label)//
" is locally degenerate at "// &
400 "the initial cell ("// &
403 END SUBROUTINE resolve_degenerate_constraint
Reduced-coordinate parameterization of cell constraints for CELL_OPT.
integer, parameter, public comp_cx
integer, parameter, public gfix_gamma
subroutine, public cell_manifold_pin_semidefinite(m, mask, is_pinned, lin_w, eq_pair)
Pin implied directions when a candidate constraint is semidefinite at q0.
integer, parameter, public n_constraint_bits
integer, parameter, public gfix_v
integer, parameter, public n_geom
integer, parameter, public n_slot
integer, parameter, public gfix_all
subroutine, public cell_manifold_init(m, q0, mask, info, lin_w, eq_pair)
Record constraint targets at q0, check row independence, and build [Y, Z].
integer, parameter, public info_licq
integer, parameter, public gfix_beta
logical function, public cell_manifold_is_redundant(m, mask, lin_w, eq_pair)
Test whether one candidate constraint stays zero on manifold m near q0.
integer, parameter, public mask_all
pure character(len=default_string_length) function, public cell_manifold_status_label(info)
Return a short description of a cell_manifold_utils status code.
pure real(kind=dp) function, dimension(n_slot), public cell_manifold_pack_hmat(hmat)
Pack the upper-triangular canonical cell matrix into q(1:6).
integer, parameter, public comp_bx
integer, parameter, public comp_cy
integer, parameter, public gfix_alpha
integer, parameter, public info_ok
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_setup_manifold(cell_env, emit_warnings)
Initialize cell constraints from CONSTRAINT, KEEP_SYMMETRY, KEEP_ANGLES, and KEEP_VOLUME.
subroutine, public cell_opt_fold_symmetry_rows(cell_env, symmetry_id, emit_warnings)
Add independent constraint rows for crystal system symmetry_id.
subroutine, public cell_opt_env_release(cell_env)
...
subroutine, public cell_opt_env_create(cell_env, force_env, geo_section)
...
Parse CELL_OPT constraints, build symmetry constraint rows, and compute the cell enthalpy gradient.
subroutine, public parse_cell_constraint(constraint_tokens, cell, explicit, mask)
Parses the tokens of the CONSTRAINT keyword into a cell component mask.
subroutine, public read_external_press_tensor(geo_section, cell, pres_ext, mtrx, input_to_opt)
Reads the external pressure tensor.
subroutine, public symmetry_constraint_rows(symmetry_id, mask, lin_w, n_lin_rows, eq_pair, n_eq_rows)
Translate a crystal system into cell constraint rows.
pure character(len=default_string_length) function, public cell_opt_constraint_label(mask)
Returns the label of the cell constraint mask.
Handles all functions related to the CELL.
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
integer, parameter, public cell_sym_none
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...
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,...
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, file_access)
...
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
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
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
Active constraint set and fixed coordinate bases anchored at q0.
Type containing all informations abour the simulation cell optimization.
Type defining parameters related to the simulation cell.
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