-
Notifications
You must be signed in to change notification settings - Fork 1
/
qs_linres_nmr_utils.F
338 lines (303 loc) · 15.3 KB
/
qs_linres_nmr_utils.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
332
333
334
335
336
337
338
!--------------------------------------------------------------------------------------------------!
! 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 Chemical shift calculation by dfpt
!> Initialization of the nmr_env, creation of the special neighbor lists
!> Perturbation Hamiltonians by application of the p and rxp oprtators to psi0
!> Write output
!> Deallocate everything
!> \note
!> The psi0 should be localized
!> the Sebastiani method works within the assumption that the orbitals are
!> completely contained in the simulation box
!> \par History
!> created 07-2005 [MI]
!> \author MI
! **************************************************************************************************
MODULE qs_linres_nmr_utils
USE atomic_kind_types, ONLY: atomic_kind_type
USE cell_types, ONLY: cell_type
USE cp_control_types, ONLY: dft_control_type
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type
USE cp_output_handling, ONLY: cp_p_file,&
cp_print_key_finished_output,&
cp_print_key_should_output,&
cp_print_key_unit_nr
USE cp_parser_methods, ONLY: parser_get_next_line,&
parser_get_object
USE cp_parser_types, ONLY: cp_parser_type,&
parser_create,&
parser_release
USE cp_units, ONLY: cp_unit_from_cp2k,&
cp_unit_to_cp2k
USE input_section_types, ONLY: section_vals_get_subs_vals,&
section_vals_type,&
section_vals_val_get
USE kinds, ONLY: default_path_length,&
dp
USE memory_utilities, ONLY: reallocate
USE particle_types, ONLY: particle_type
USE pw_env_types, ONLY: pw_env_type
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_linres_types, ONLY: linres_control_type,&
nmr_env_type
USE qs_matrix_pools, ONLY: qs_matrix_pools_type
USE scf_control_types, ONLY: scf_control_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
PUBLIC :: nmr_env_cleanup, nmr_env_init
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_linres_nmr_utils'
CONTAINS
! **************************************************************************************************
!> \brief Initialize the nmr environment
!> \param nmr_env ...
!> \param qs_env ...
!> \par History
!> 07.2006 created [MI]
!> \author MI
! **************************************************************************************************
SUBROUTINE nmr_env_init(nmr_env, qs_env)
!
TYPE(nmr_env_type) :: nmr_env
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'nmr_env_init'
CHARACTER(LEN=default_path_length) :: nics_file_name
INTEGER :: handle, ini, ir, j, n_mo(2), n_rep, nao, &
nat_print, natom, nmoloc, nspins, &
output_unit
INTEGER, DIMENSION(:), POINTER :: bounds, list
LOGICAL :: gapw
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(cp_logger_type), POINTER :: logger
TYPE(dft_control_type), POINTER :: dft_control
TYPE(linres_control_type), POINTER :: linres_control
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(pw_env_type), POINTER :: pw_env
TYPE(qs_matrix_pools_type), POINTER :: mpools
TYPE(scf_control_type), POINTER :: scf_control
TYPE(section_vals_type), POINTER :: lr_section, nmr_section
!
CALL timeset(routineN, handle)
NULLIFY (atomic_kind_set, cell, dft_control, linres_control, scf_control)
NULLIFY (logger, mpools, nmr_section, particle_set)
NULLIFY (pw_env)
n_mo(1:2) = 0
nao = 0
nmoloc = 0
logger => cp_get_default_logger()
lr_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%LINRES")
output_unit = cp_print_key_unit_nr(logger, lr_section, "PRINT%PROGRAM_RUN_INFO", &
extension=".linresLog")
CALL nmr_env_cleanup(nmr_env)
IF (output_unit > 0) THEN
WRITE (output_unit, "(/,T20,A,/)") "*** Start NMR Chemical Shift Calculation ***"
WRITE (output_unit, "(T10,A,/)") "Inizialization of the NMR environment"
END IF
! If current_density or full_nmr different allocations are required
nmr_section => section_vals_get_subs_vals(qs_env%input, &
& "PROPERTIES%LINRES%NMR")
CALL section_vals_val_get(nmr_section, "INTERPOLATE_SHIFT", l_val=nmr_env%interpolate_shift)
CALL section_vals_val_get(nmr_section, "SHIFT_GAPW_RADIUS", r_val=nmr_env%shift_gapw_radius)
CALL section_vals_val_get(nmr_section, "NICS", l_val=nmr_env%do_nics)
IF (nmr_env%do_nics) THEN
CALL section_vals_val_get(nmr_section, "NICS_FILE_NAME", &
c_val=nics_file_name)
BLOCK
CHARACTER(LEN=2) :: label
LOGICAL :: my_end
TYPE(cp_parser_type) :: parser
CALL parser_create(parser, nics_file_name)
CALL parser_get_next_line(parser, 1)
CALL parser_get_object(parser, nmr_env%n_nics)
ALLOCATE (nmr_env%r_nics(3, nmr_env%n_nics))
CALL parser_get_next_line(parser, 2)
DO j = 1, nmr_env%n_nics
CALL parser_get_object(parser, label)
CALL parser_get_object(parser, nmr_env%r_nics(1, j))
CALL parser_get_object(parser, nmr_env%r_nics(2, j))
CALL parser_get_object(parser, nmr_env%r_nics(3, j))
nmr_env%r_nics(1, j) = cp_unit_to_cp2k(nmr_env%r_nics(1, j), "angstrom")
nmr_env%r_nics(2, j) = cp_unit_to_cp2k(nmr_env%r_nics(2, j), "angstrom")
nmr_env%r_nics(3, j) = cp_unit_to_cp2k(nmr_env%r_nics(3, j), "angstrom")
CALL parser_get_next_line(parser, 1, at_end=my_end)
IF (my_end) EXIT
END DO
CALL parser_release(parser)
END BLOCK
END IF
CALL get_qs_env(qs_env=qs_env, &
atomic_kind_set=atomic_kind_set, &
cell=cell, &
dft_control=dft_control, &
linres_control=linres_control, &
mpools=mpools, &
particle_set=particle_set, &
pw_env=pw_env, &
scf_control=scf_control)
!
! Check if restat also psi0 should be restarted
!IF(nmr_env%restart_nmr .AND. scf_control%density_guess/=restart_guess)THEN
! CPABORT("restart_nmr requires density_guess=restart")
!ENDIF
!
! check that the psi0 are localized and you have all the centers
IF (.NOT. linres_control%localized_psi0) THEN
CPWARN("To get NMR parameters within PBC you need localized zero order orbitals")
END IF
gapw = dft_control%qs_control%gapw
nspins = dft_control%nspins
natom = SIZE(particle_set, 1)
!
! Conversion factors
! factor for the CHEMICAL SHIFTS: alpha^2 * ppm.
nmr_env%shift_factor = (1.0_dp/137.03602_dp)**2*1.0E+6_dp/cell%deth
! factor for the CHEMICAL SHIFTS: alpha^2 * ppm.
nmr_env%shift_factor_gapw = (1.0_dp/137.03602_dp)**2*1.0E+6_dp
! chi_factor = 1/4 * e^2/m * a_0 ^2
nmr_env%chi_factor = 1.9727566E-29_dp/1.0E-30_dp ! -> displayed in 10^-30 J/T^2
! Factor to convert 10^-30 J/T^2 into ppm cgs = ppm cm^3/mol
! = 10^-30 * mu_0/4pi * N_A * 10^6 * 10^6 [one 10^6 for ppm, one for m^3 -> cm^3]
nmr_env%chi_SI2ppmcgs = 6.022045_dp/1.0E+2_dp
! Chi to Shift: 10^-30 * 2/3 mu_0 / Omega * 1/ppm
nmr_env%chi_SI2shiftppm = 1.0E-30_dp*8.37758041E-7_dp/ &
(cp_unit_from_cp2k(cell%deth, "angstrom^3")*1.0E-30_dp)*1.0E+6_dp
IF (output_unit > 0) THEN
WRITE (output_unit, "(T2,A,T65,ES15.6)") "NMR| Shift gapw radius (a.u.) ", nmr_env%shift_gapw_radius
IF (nmr_env%do_nics) THEN
WRITE (output_unit, "(T2,A,T50,I5,A)") "NMR| NICS computed in ", nmr_env%n_nics, " additional points"
WRITE (output_unit, "(T2,A,T60,A)") "NMR| NICS coordinates read on file ", TRIM(nics_file_name)
END IF
WRITE (output_unit, "(T2,A,T65,ES15.6)") "NMR| Shift factor (ppm)", nmr_env%shift_factor
IF (gapw) THEN
WRITE (output_unit, "(T2,A,T65,ES15.6)") "NMR| Shift factor gapw (ppm)", nmr_env%shift_factor_gapw
END IF
WRITE (output_unit, "(T2,A,T65,ES15.6)") "NMR| Chi factor (SI)", nmr_env%chi_factor
WRITE (output_unit, "(T2,A,T65,ES15.6)") "NMR| Conversion Chi (ppm/cgs)", nmr_env%chi_SI2ppmcgs
WRITE (output_unit, "(T2,A,T65,ES15.6)") "NMR| Conversion Chi to Shift", nmr_env%chi_SI2shiftppm
END IF
ALLOCATE (nmr_env%do_calc_cs_atom(natom))
nmr_env%do_calc_cs_atom = 0
IF (BTEST(cp_print_key_should_output(logger%iter_info, nmr_section,&
& "PRINT%SHIELDING_TENSOR"), cp_p_file)) THEN
NULLIFY (bounds, list)
nat_print = 0
CALL section_vals_val_get(nmr_section,&
& "PRINT%SHIELDING_TENSOR%ATOMS_LU_BOUNDS", &
i_vals=bounds)
nat_print = bounds(2) - bounds(1) + 1
IF (nat_print > 0) THEN
ALLOCATE (nmr_env%cs_atom_list(nat_print))
DO ir = 1, nat_print
nmr_env%cs_atom_list(ir) = bounds(1) + (ir - 1)
nmr_env%do_calc_cs_atom(bounds(1) + (ir - 1)) = 1
END DO
END IF
IF (.NOT. ASSOCIATED(nmr_env%cs_atom_list)) THEN
CALL section_vals_val_get(nmr_section, "PRINT%SHIELDING_TENSOR%ATOMS_LIST", &
n_rep_val=n_rep)
nat_print = 0
DO ir = 1, n_rep
NULLIFY (list)
CALL section_vals_val_get(nmr_section, "PRINT%SHIELDING_TENSOR%ATOMS_LIST", &
i_rep_val=ir, i_vals=list)
IF (ASSOCIATED(list)) THEN
CALL reallocate(nmr_env%cs_atom_list, 1, nat_print + SIZE(list))
DO ini = 1, SIZE(list)
nmr_env%cs_atom_list(ini + nat_print) = list(ini)
nmr_env%do_calc_cs_atom(list(ini)) = 1
END DO
nat_print = nat_print + SIZE(list)
END IF
END DO ! ir
END IF
IF (.NOT. ASSOCIATED(nmr_env%cs_atom_list)) THEN
ALLOCATE (nmr_env%cs_atom_list(natom))
DO ir = 1, natom
nmr_env%cs_atom_list(ir) = ir
END DO
nmr_env%do_calc_cs_atom = 1
END IF
!
! check the list
CPASSERT(ASSOCIATED(nmr_env%cs_atom_list))
DO ir = 1, SIZE(nmr_env%cs_atom_list, 1)
IF (nmr_env%cs_atom_list(ir) .LT. 1 .OR. nmr_env%cs_atom_list(ir) .GT. natom) THEN
CPABORT("Unknown atom(s)")
END IF
DO j = 1, SIZE(nmr_env%cs_atom_list, 1)
IF (j .EQ. ir) CYCLE
IF (nmr_env%cs_atom_list(ir) .EQ. nmr_env%cs_atom_list(j)) THEN
CPABORT("Duplicate atoms")
END IF
END DO
END DO
ELSE
NULLIFY (nmr_env%cs_atom_list)
END IF
IF (output_unit > 0) THEN
IF (ASSOCIATED(nmr_env%cs_atom_list)) THEN
WRITE (output_unit, "(T2,A,T69,I5,A)") "NMR| Shielding tensor computed for ", &
SIZE(nmr_env%cs_atom_list, 1), " atoms"
ELSE
WRITE (output_unit, "(T2,A,T50)")&
& "NMR| Shielding tensor not computed at the atomic positions"
END IF
END IF
!
! Initialize the chemical shift tensor
ALLOCATE (nmr_env%chemical_shift(3, 3, natom), &
nmr_env%chemical_shift_loc(3, 3, natom))
nmr_env%chemical_shift = 0.0_dp
nmr_env%chemical_shift_loc = 0.0_dp
IF (nmr_env%do_nics) THEN
ALLOCATE (nmr_env%chemical_shift_nics_loc(3, 3, nmr_env%n_nics), &
nmr_env%chemical_shift_nics(3, 3, nmr_env%n_nics))
nmr_env%chemical_shift_nics_loc = 0.0_dp
nmr_env%chemical_shift_nics = 0.0_dp
END IF
CALL cp_print_key_finished_output(output_unit, logger, lr_section,&
& "PRINT%PROGRAM_RUN_INFO")
CALL timestop(handle)
END SUBROUTINE nmr_env_init
! **************************************************************************************************
!> \brief Deallocate the nmr environment
!> \param nmr_env ...
!> \par History
!> 07.2005 created [MI]
!> \author MI
! **************************************************************************************************
SUBROUTINE nmr_env_cleanup(nmr_env)
TYPE(nmr_env_type) :: nmr_env
IF (ASSOCIATED(nmr_env%cs_atom_list)) THEN
DEALLOCATE (nmr_env%cs_atom_list)
END IF
IF (ASSOCIATED(nmr_env%do_calc_cs_atom)) THEN
DEALLOCATE (nmr_env%do_calc_cs_atom)
END IF
!chemical_shift
IF (ASSOCIATED(nmr_env%chemical_shift)) THEN
DEALLOCATE (nmr_env%chemical_shift)
END IF
IF (ASSOCIATED(nmr_env%chemical_shift_loc)) THEN
DEALLOCATE (nmr_env%chemical_shift_loc)
END IF
! nics
IF (ASSOCIATED(nmr_env%r_nics)) THEN
DEALLOCATE (nmr_env%r_nics)
END IF
IF (ASSOCIATED(nmr_env%chemical_shift_nics)) THEN
DEALLOCATE (nmr_env%chemical_shift_nics)
END IF
IF (ASSOCIATED(nmr_env%chemical_shift_nics_loc)) THEN
DEALLOCATE (nmr_env%chemical_shift_nics_loc)
END IF
END SUBROUTINE nmr_env_cleanup
END MODULE qs_linres_nmr_utils