-
Notifications
You must be signed in to change notification settings - Fork 1
/
topology_xtl.F
331 lines (308 loc) · 16.2 KB
/
topology_xtl.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Handles XTL (Molecular Simulations, Inc (MSI)) files
!> \author Teodoro Laino [tlaino]
!> \date 05.2009
! **************************************************************************************************
MODULE topology_xtl
USE cell_methods, ONLY: cell_create,&
set_cell_param,&
write_cell
USE cell_types, ONLY: cell_release,&
cell_type,&
pbc,&
scaled_to_real
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type,&
cp_to_string
USE cp_output_handling, ONLY: cp_print_key_finished_output,&
cp_print_key_unit_nr
USE cp_parser_methods, ONLY: parser_get_next_line,&
parser_get_object,&
parser_search_string
USE cp_parser_types, ONLY: cp_parser_type,&
parser_create,&
parser_release
USE cp_units, ONLY: cp_unit_to_cp2k
USE input_section_types, ONLY: section_get_rval,&
section_vals_type
USE kinds, ONLY: default_string_length,&
dp
USE memory_utilities, ONLY: reallocate
USE message_passing, ONLY: mp_para_env_type
USE string_table, ONLY: id2str,&
s2s,&
str2id
USE topology_types, ONLY: atom_info_type,&
topology_parameters_type
#include "./base/base_uses.f90"
IMPLICIT NONE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'topology_xtl'
PRIVATE
PUBLIC :: read_coordinate_xtl
CONTAINS
! **************************************************************************************************
!> \brief Performs the real task of reading the proper information from the XTL
!> file
!> \param topology ...
!> \param para_env ...
!> \param subsys_section ...
!> \date 05.2009
!> \par Format Information implemented:
!> TITLE
!> DIMENSION
!> CELL
!> SYMMETRY
!> SYM MAT
!> ATOMS
!> EOF
!>
!> \author Teodoro Laino [tlaino]
! **************************************************************************************************
SUBROUTINE read_coordinate_xtl(topology, para_env, subsys_section)
TYPE(topology_parameters_type) :: topology
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(section_vals_type), POINTER :: subsys_section
CHARACTER(len=*), PARAMETER :: routineN = 'read_coordinate_xtl'
INTEGER, PARAMETER :: nblock = 1000
REAL(KIND=dp), PARAMETER :: threshold = 1.0E-6_dp
CHARACTER(LEN=default_string_length) :: strtmp
INTEGER :: dimensions, handle, icol, ii, isym, iw, &
jj, natom, natom_orig, newsize
INTEGER, DIMENSION(3) :: periodic
LOGICAL :: check, found, my_end
REAL(KIND=dp) :: pfactor, threshold2
REAL(KIND=dp), DIMENSION(3) :: cell_angles, cell_lengths, r, r1, r2, s, &
transl_vec
REAL(KIND=dp), DIMENSION(3, 3) :: rot_mat
TYPE(atom_info_type), POINTER :: atom_info
TYPE(cell_type), POINTER :: cell
TYPE(cp_logger_type), POINTER :: logger
TYPE(cp_parser_type) :: parser
NULLIFY (logger)
logger => cp_get_default_logger()
iw = cp_print_key_unit_nr(logger, subsys_section, "PRINT%TOPOLOGY_INFO/XTL_INFO", &
extension=".subsysLog")
CALL timeset(routineN, handle)
pfactor = section_get_rval(subsys_section, "TOPOLOGY%MEMORY_PROGRESSION_FACTOR")
! Element is assigned on the basis of the atm_name
topology%aa_element = .TRUE.
atom_info => topology%atom_info
CALL reallocate(atom_info%id_molname, 1, nblock)
CALL reallocate(atom_info%id_resname, 1, nblock)
CALL reallocate(atom_info%resid, 1, nblock)
CALL reallocate(atom_info%id_atmname, 1, nblock)
CALL reallocate(atom_info%r, 1, 3, 1, nblock)
CALL reallocate(atom_info%atm_mass, 1, nblock)
CALL reallocate(atom_info%atm_charge, 1, nblock)
CALL reallocate(atom_info%occup, 1, nblock)
CALL reallocate(atom_info%beta, 1, nblock)
CALL reallocate(atom_info%id_element, 1, nblock)
IF (iw > 0) WRITE (iw, *) " Reading in XTL file ", TRIM(topology%coord_file_name)
CALL parser_create(parser, topology%coord_file_name, para_env=para_env)
! Check for TITLE
CALL parser_search_string(parser, "TITLE", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
IF (found) THEN
IF (iw > 0) WRITE (iw, '(/,A)') " XTL_INFO| TITLE :: "//TRIM(parser%input_line(parser%icol:))
END IF
! Check for _chemical_formula_sum
CALL parser_search_string(parser, "DIMENSION", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
IF (found) THEN
IF (iw > 0) WRITE (iw, '(A)') " XTL_INFO| DIMENSION :: "//TRIM(parser%input_line(parser%icol:))
CALL parser_get_object(parser, dimensions)
IF (dimensions /= 3) THEN
CPABORT("XTL file with working DIMENSION different from 3 cannot be parsed!")
END IF
ELSE
! Assuming by default we work in 3D-periodic systems
dimensions = 3
END IF
! Parsing cell infos
periodic = 1
! Check for _cell_length_a
CALL parser_search_string(parser, "CELL", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
IF (.NOT. found) &
CPABORT("The field CELL was not found in XTL file! ")
CALL parser_get_next_line(parser, 1)
! CELL LENGTH A
CALL parser_get_object(parser, cell_lengths(1))
cell_lengths(1) = cp_unit_to_cp2k(cell_lengths(1), "angstrom")
! CELL LENGTH B
CALL parser_get_object(parser, cell_lengths(2))
cell_lengths(2) = cp_unit_to_cp2k(cell_lengths(2), "angstrom")
! CELL LENGTH C
CALL parser_get_object(parser, cell_lengths(3))
cell_lengths(3) = cp_unit_to_cp2k(cell_lengths(3), "angstrom")
! CELL ANGLE ALPHA
CALL parser_get_object(parser, cell_angles(1))
cell_angles(1) = cp_unit_to_cp2k(cell_angles(1), "deg")
! CELL ANGLE BETA
CALL parser_get_object(parser, cell_angles(2))
cell_angles(2) = cp_unit_to_cp2k(cell_angles(2), "deg")
! CELL ANGLE GAMMA
CALL parser_get_object(parser, cell_angles(3))
cell_angles(3) = cp_unit_to_cp2k(cell_angles(3), "deg")
! Create cell
NULLIFY (cell)
CALL cell_create(cell, tag="CELL_XTL")
CALL set_cell_param(cell, cell_lengths, cell_angles, periodic=periodic, &
do_init_cell=.TRUE.)
CALL write_cell(cell, subsys_section)
! Parse atoms info and fractional coordinates
! Check for _atom_site_label
CALL parser_search_string(parser, "ATOMS", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
IF (.NOT. found) &
CPABORT("The field ATOMS was not found in XTL file! ")
CALL parser_get_next_line(parser, 1)
! Paranoic syntax check.. if this fails one should improve the description of XTL files
found = (INDEX(parser%input_line, "NAME X Y Z") /= 0)
IF (.NOT. found) &
CPABORT("The field ATOMS in XTL file, is not followed by name and coordinates tags! ")
CALL parser_get_next_line(parser, 1)
! Parse real info
natom = 0
DO WHILE (INDEX(parser%input_line, "EOF") == 0)
natom = natom + 1
! Resize in case needed
IF (natom > SIZE(atom_info%id_molname)) THEN
newsize = INT(pfactor*natom)
CALL reallocate(atom_info%id_molname, 1, newsize)
CALL reallocate(atom_info%id_resname, 1, newsize)
CALL reallocate(atom_info%resid, 1, newsize)
CALL reallocate(atom_info%id_atmname, 1, newsize)
CALL reallocate(atom_info%r, 1, 3, 1, newsize)
CALL reallocate(atom_info%atm_mass, 1, newsize)
CALL reallocate(atom_info%atm_charge, 1, newsize)
CALL reallocate(atom_info%occup, 1, newsize)
CALL reallocate(atom_info%beta, 1, newsize)
CALL reallocate(atom_info%id_element, 1, newsize)
END IF
! NAME
CALL parser_get_object(parser, strtmp)
atom_info%id_atmname(natom) = str2id(strtmp)
atom_info%id_molname(natom) = str2id(s2s("MOL"//TRIM(ADJUSTL(cp_to_string(natom)))))
atom_info%id_resname(natom) = atom_info%id_molname(natom)
atom_info%resid(natom) = 1
atom_info%id_element(natom) = atom_info%id_atmname(natom)
! X
CALL parser_get_object(parser, atom_info%r(1, natom))
! Y
CALL parser_get_object(parser, atom_info%r(2, natom))
! Z
CALL parser_get_object(parser, atom_info%r(3, natom))
s = atom_info%r(1:3, natom)
CALL scaled_to_real(atom_info%r(1:3, natom), s, cell)
CALL parser_get_next_line(parser, 1, at_end=my_end)
IF (my_end) EXIT
END DO
!
threshold2 = threshold*threshold
! Preliminary check: check if atoms provided are really unique.. this is a paranoic
! check since they should be REALLY unique.. anyway..
DO ii = 1, natom
r1 = atom_info%r(1:3, ii)
DO jj = ii + 1, natom
r2 = atom_info%r(1:3, jj)
r = pbc(r1 - r2, cell)
! SQRT(DOT_PRODUCT(r, r)) >= threshold
check = (DOT_PRODUCT(r, r) >= threshold2)
CPASSERT(check)
END DO
END DO
! Parse Symmetry Group and generation elements..
! Check for SYMMETRY
CALL parser_search_string(parser, "SYMMETRY", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
IF (found) THEN
IF (iw > 0) WRITE (iw, '(A)') " XTL_INFO| Symmetry Infos :: "//TRIM(parser%input_line(parser%icol:))
END IF
! Check for SYM MAT
CALL parser_search_string(parser, "SYM MAT", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
CPWARN_IF(.NOT. found, "The field SYM MAT was not found in XTL file! ")
IF (iw > 0) WRITE (iw, '(A,I0)') " XTL_INFO| Number of atoms before applying symmetry operations :: ", natom
IF (iw > 0) WRITE (iw, '(A10,1X,3F12.6)') (TRIM(id2str(atom_info%id_atmname(ii))), atom_info%r(1:3, ii), ii=1, natom)
IF (found) THEN
! Apply symmetry elements and generate the whole set of atoms in the unit cell
isym = 0
natom_orig = natom
DO WHILE (found)
isym = isym + 1
icol = INDEX(parser%input_line, "SYM MAT") + 8
READ (parser%input_line(icol:), *) ((rot_mat(ii, jj), jj=1, 3), ii=1, 3), transl_vec(1:3)
Loop_over_unique_atoms: DO ii = 1, natom_orig
! Rotate and apply translation
r1 = MATMUL(rot_mat, atom_info%r(1:3, ii)) + transl_vec
! Verify if this atom is really unique..
check = .TRUE.
DO jj = 1, natom
r2 = atom_info%r(1:3, jj)
r = pbc(r1 - r2, cell)
! SQRT(DOT_PRODUCT(r, r)) <= threshold
IF (DOT_PRODUCT(r, r) <= threshold2) THEN
check = .FALSE.
EXIT
END IF
END DO
! If the atom generated is unique let's add to the atom set..
IF (check) THEN
natom = natom + 1
! Resize in case needed
IF (natom > SIZE(atom_info%id_molname)) THEN
newsize = INT(pfactor*natom)
CALL reallocate(atom_info%id_molname, 1, newsize)
CALL reallocate(atom_info%id_resname, 1, newsize)
CALL reallocate(atom_info%resid, 1, newsize)
CALL reallocate(atom_info%id_atmname, 1, newsize)
CALL reallocate(atom_info%r, 1, 3, 1, newsize)
CALL reallocate(atom_info%atm_mass, 1, newsize)
CALL reallocate(atom_info%atm_charge, 1, newsize)
CALL reallocate(atom_info%occup, 1, newsize)
CALL reallocate(atom_info%beta, 1, newsize)
CALL reallocate(atom_info%id_element, 1, newsize)
END IF
atom_info%id_atmname(natom) = atom_info%id_atmname(ii)
atom_info%id_molname(natom) = atom_info%id_molname(ii)
atom_info%id_resname(natom) = atom_info%id_resname(ii)
atom_info%resid(natom) = atom_info%resid(ii)
atom_info%id_element(natom) = atom_info%id_element(ii)
atom_info%r(1:3, natom) = r1
END IF
END DO Loop_over_unique_atoms
CALL parser_search_string(parser, "SYM MAT", ignore_case=.FALSE., found=found, &
begin_line=.FALSE., search_from_begin_of_file=.FALSE.)
END DO
END IF
IF (iw > 0) WRITE (iw, '(A,I0)') " XTL_INFO| Number of symmetry operations :: ", isym
IF (iw > 0) WRITE (iw, '(A,I0)') " XTL_INFO| Number of total atoms :: ", natom
IF (iw > 0) WRITE (iw, '(A10,1X,3F12.6)') (TRIM(id2str(atom_info%id_atmname(ii))), atom_info%r(1:3, ii), ii=1, natom)
! Releasse local cell type and parser
CALL cell_release(cell)
CALL parser_release(parser)
! Reallocate all structures with the exact NATOM size
CALL reallocate(atom_info%id_molname, 1, natom)
CALL reallocate(atom_info%id_resname, 1, natom)
CALL reallocate(atom_info%resid, 1, natom)
CALL reallocate(atom_info%id_atmname, 1, natom)
CALL reallocate(atom_info%r, 1, 3, 1, natom)
CALL reallocate(atom_info%atm_mass, 1, natom)
CALL reallocate(atom_info%atm_charge, 1, natom)
CALL reallocate(atom_info%occup, 1, natom)
CALL reallocate(atom_info%beta, 1, natom)
CALL reallocate(atom_info%id_element, 1, natom)
topology%natoms = natom
topology%molname_generated = .TRUE.
CALL cp_print_key_finished_output(iw, logger, subsys_section, &
"PRINT%TOPOLOGY_INFO/XTL_INFO")
CALL timestop(handle)
END SUBROUTINE read_coordinate_xtl
END MODULE topology_xtl