(git:0446f17)
Loading...
Searching...
No Matches
topology_multiple_unit_cell.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Handles the multiple unit cell option regarding atomic coordinates
10!> \author Teodoro Laino [tlaino] - 05.2009
11! **************************************************************************************************
13 USE cell_types, ONLY: cell_type
20 USE kinds, ONLY: default_string_length,&
21 dp
24#include "./base/base_uses.f90"
25
26 IMPLICIT NONE
27
28 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'topology_multiple_unit_cell'
29
30 PRIVATE
31
32 ! Public parameters
33 PUBLIC :: topology_muc
34
35CONTAINS
36
37! **************************************************************************************************
38!> \brief Handles the multiple_unit_cell for the atomic coordinates.
39!> \param topology ...
40!> \param subsys_section ...
41!> \author Teodoro Laino [tlaino] - 05.2009
42! **************************************************************************************************
43 SUBROUTINE topology_muc(topology, subsys_section)
44 TYPE(topology_parameters_type), INTENT(INOUT) :: topology
45 TYPE(section_vals_type), POINTER :: subsys_section
46
47 CHARACTER(len=*), PARAMETER :: routinen = 'topology_muc'
48
49 CHARACTER(LEN=default_string_length) :: unit_str
50 INTEGER :: handle, i, ind, j, k, m, n, natoms, nrep
51 INTEGER, DIMENSION(:), POINTER :: iwork, multiple_unit_cell
52 LOGICAL :: check, explicit, scale
53 REAL(kind=dp), DIMENSION(3) :: trsl, trsl_i, trsl_j, trsl_k
54 TYPE(cell_type), POINTER :: cell
55 TYPE(section_vals_type), POINTER :: work_section
56
57 CALL timeset(routinen, handle)
58
59 NULLIFY (multiple_unit_cell, iwork, cell)
60
61 ! Store original number of atoms for the molecule generation in any case
62 topology%natom_muc = topology%natoms
63
64 CALL section_vals_val_get(subsys_section, "TOPOLOGY%MULTIPLE_UNIT_CELL", &
65 i_vals=multiple_unit_cell)
66
67 ! Fail is one of the value is set to zero..
68 IF (any(multiple_unit_cell <= 0)) &
69 CALL cp_abort(__location__, "SUBSYS%TOPOLOGY%MULTIPLE_UNIT_CELL accepts "// &
70 "only integer values greater than zero.")
71
72 IF (any(multiple_unit_cell /= 1)) THEN
73
74 ! Check that the setup between CELL and TOPOLOGY is the same
75 CALL section_vals_val_get(subsys_section, "CELL%MULTIPLE_UNIT_CELL", &
76 i_vals=iwork)
77 IF (any(iwork /= multiple_unit_cell)) &
78 CALL cp_abort(__location__, "The input parameters for "// &
79 "SUBSYS%TOPOLOGY%MULTIPLE_UNIT_CELL and "// &
80 "SUBSYS%CELL%MULTIPLE_UNIT_CELL have to agree.")
81
82 cell => topology%cell_muc
83 natoms = topology%natoms*product(multiple_unit_cell)
84
85 ! Check, if velocities are provided, that they are consistent in number with the atoms...
86 work_section => section_vals_get_subs_vals(subsys_section, "VELOCITY")
87 CALL section_vals_get(work_section, explicit=explicit)
88 IF (explicit) THEN
89 CALL section_vals_val_get(work_section, '_DEFAULT_KEYWORD_', n_rep_val=nrep)
90 check = nrep == natoms
91 IF (.NOT. check) &
92 CALL cp_abort(__location__, "The number of available entries in the "// &
93 "VELOCITY section is not compatible with the number of atoms.")
94 END IF
95
96 CALL reallocate(topology%atom_info%id_molname, 1, natoms)
97 CALL reallocate(topology%atom_info%id_resname, 1, natoms)
98 CALL reallocate(topology%atom_info%resid, 1, natoms)
99 CALL reallocate(topology%atom_info%id_atmname, 1, natoms)
100 CALL reallocate(topology%atom_info%r, 1, 3, 1, natoms)
101 CALL reallocate(topology%atom_info%atm_mass, 1, natoms)
102 CALL reallocate(topology%atom_info%atm_charge, 1, natoms)
103 CALL reallocate(topology%atom_info%occup, 1, natoms)
104 CALL reallocate(topology%atom_info%beta, 1, natoms)
105 CALL reallocate(topology%atom_info%id_element, 1, natoms)
106
107 ind = 0
108 DO k = 1, multiple_unit_cell(3)
109 trsl_k = cell%hmat(:, 3)*real(k - 1, kind=dp)
110 DO j = 1, multiple_unit_cell(2)
111 trsl_j = cell%hmat(:, 2)*real(j - 1, kind=dp)
112 DO i = 1, multiple_unit_cell(1)
113 trsl_i = cell%hmat(:, 1)*real(i - 1, kind=dp)
114 trsl = trsl_i + trsl_j + trsl_k
115 ind = ind + 1
116 IF (ind == 1) cycle
117 ! Loop over all atoms
118 n = (ind - 1)*topology%natoms
119 DO m = 1, topology%natoms
120 topology%atom_info%id_atmname(n + m) = topology%atom_info%id_atmname(m)
121 topology%atom_info%r(1, n + m) = topology%atom_info%r(1, m) + trsl(1)
122 topology%atom_info%r(2, n + m) = topology%atom_info%r(2, m) + trsl(2)
123 topology%atom_info%r(3, n + m) = topology%atom_info%r(3, m) + trsl(3)
124 topology%atom_info%id_molname(n + m) = topology%atom_info%id_molname(m)
125 topology%atom_info%id_resname(n + m) = topology%atom_info%id_resname(m)
126 topology%atom_info%resid(n + m) = topology%atom_info%resid(m)
127 topology%atom_info%id_element(n + m) = topology%atom_info%id_element(m)
128 topology%atom_info%atm_mass(n + m) = topology%atom_info%atm_mass(m)
129 topology%atom_info%atm_charge(n + m) = topology%atom_info%atm_charge(m)
130 END DO
131 END DO
132 END DO
133 END DO
134 ! Store the new total number of atoms
135 topology%natoms = natoms
136
137 ! Deallocate the coordinate section (will be rebuilt later with the whole atomic set)
138 work_section => section_vals_get_subs_vals(subsys_section, "COORD")
139 CALL section_vals_get(work_section, explicit=explicit)
140 IF (explicit) THEN
141 CALL section_vals_val_get(work_section, "UNIT", c_val=unit_str)
142 CALL section_vals_val_get(work_section, "SCALED", l_val=scale)
143 END IF
144 CALL section_vals_remove_values(work_section)
145 IF (explicit) THEN
146 CALL section_vals_val_set(work_section, "UNIT", c_val=unit_str)
147 CALL section_vals_val_set(work_section, "SCALED", l_val=scale)
148 END IF
149 END IF
150
151 CALL timestop(handle)
152
153 END SUBROUTINE topology_muc
154
Handles all functions related to the CELL.
Definition cell_types.F:15
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
subroutine, public section_vals_remove_values(section_vals)
removes the values of a repetition of the section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
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
integer, parameter, public default_string_length
Definition kinds.F:57
Utility routines for the memory handling.
Handles the multiple unit cell option regarding atomic coordinates.
subroutine, public topology_muc(topology, subsys_section)
Handles the multiple_unit_cell for the atomic coordinates.
Control for reading in different topologies and coordinates.
Definition topology.F:13
Type defining parameters related to the simulation cell.
Definition cell_types.F:55