forked from jautschbach/mcd-molcas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread-data-files.f90
536 lines (392 loc) · 16.6 KB
/
read-data-files.f90
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
subroutine read_data_files
! this routine is part of J. Autschbach's set of programs to process
! Molcas data for the generation of various types of spectral
! intensities
! (c) 2019-2023 Jochen Autschbach, SUNY Buffalo
use definitions
use namelist_module
use constants_parameters
use shared_variables
implicit none
complex(KREAL), dimension(:,:,:), allocatable :: quadtmp
integer(KINT) :: idir, i, j, idum, jdum
! ============================================================================
! ------------------------------------------------------
! read the electron spin matrices in a loop over x, y, z
! and add to magdip, if applicable
! ------------------------------------------------------
if (havespin .or. haveang) then
allocate (angmom(nstates,nstates,3))
if (.not. allocated(magdip)) &
stop 'read_data_files: magdip not allocated, though it should be'
end if
if (havespin) then
angmom = 0
do idir = 1, 3
write (cs,'(a,i1,a)') 'spin-',idir,'.txt'
open(unit=iu_d, file=trim(cs), status='old', iostat=ios)
if (ios /= 0) then
write (err,*) 'error: file '//trim(cs)//' does not exist'
stop 'error termination'
end if
read(iu_d,*) cstemp
! by trial & error, we originally leared that the spin-y matrix must be
! processed the same way as angmon, and spin x,z are processed like
! electric dipoles and similar properties.
! however, this changed in 2019 in OpenMolcas (commit ..62f096), so now
! we have option 'oldspiny', and the default is to treat S(y) the same way
! as the other spin components.
! n.b. inner loop must be the row index
do j = 1, nstates
do i = 1, nstates
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
if (dbg>2) write (out,*) i, j, ctemp(1), ctemp(2)
if (idir.eq.2 .and. oldspiny) then
angmom(i,j,idir) = cmplx (-ctemp(2), ctemp(1), kind(KREAL))
else
angmom(i,j,idir) = cmplx (ctemp(1), ctemp(2), kind(KREAL))
end if
if (ios /= 0) then
write (err,*) 'idir, i, j = ', idir, i, j
write (err,*) 'error reading spin value from '//trim(cs)
stop 'error termination'
end if
end do ! i
end do ! j
! attempt to read one more element. This must fail, otherwise
! this would indicate that nstates in the input is not correct
call read_one_more
close (iu_d)
end do ! idir = spin components
write (out,'(1x,a/)') 'successfully read spin matrices from files'
magdip = ge * angmom ! spin contribution to magnetic moment
end if ! havespin
! -----------------------------------------------------
! read the angular momentum data in a loop over x, y, z
! and add to magdip, if applicable
! -----------------------------------------------------
if (haveang) then
angmom = 0
do idir = 1, 3
write (cs,'(a,i1,a)') 'angmom-',idir,'.txt'
open(unit=iu_d, file=trim(cs), status='old', iostat=ios)
if (ios /= 0) then
write (err,*) 'error: file '//trim(cs)//' does not exist'
stop 'error termination'
end if
read(iu_d,*) cstemp
! n.b. inner loop must be the row index
do j = 1, nstates
do i = 1, nstates
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
if (dbg>2) write (out,*) i, j, ctemp(1), ctemp(2)
! angmom is -r x del in Molcas, missing a factor of i
! relative to r x p.
angmom(i,j,idir) = cmplx (-ctemp(2), ctemp(1), kind(KREAL))
if (ios /= 0) then
write (err,*) 'idir, i, j = ', idir, i, j
write (err,*) 'error reading angmom value from '//trim(cs)
stop 'error termination'
end if
end do ! i
end do ! j
! attempt to read one more element. This must fail, otherwise
! this would indicate that nstates in the input is not correct
call read_one_more
close (iu_d)
end do ! idir = angular momentum components
write (out,'(1x,a/)') 'successfully read angular momentum data files'
magdip = magdip + angmom ! add orbital angular momentum to magnetic moment
end if ! haveang
if (havespin .or. haveang) deallocate (angmom)
! -----------------------------------------------------
! read velocity data in a loop over x, y, z
! (replacing electric dipoles for velocity gauge calcs)
! -----------------------------------------------------
if (havevel) then
if (.not. allocated(velocity)) &
stop 'read_data_files: velocity array not allocated, though it should be'
velocity = 0
do idir = 1, 3
write (cs,'(a,i1,a)') 'velocity_dipole-',idir,'.txt'
open(unit=iu_d, file=trim(cs), status='old', iostat=ios)
if (ios /= 0) then
write (err,*) 'error: file '//trim(cs)//' does not exist'
stop 'error termination'
end if
read(iu_d,*) cstemp
! n.b. inner loop must be the row index
do j = 1, nstates
do i = 1, nstates
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
!read (iu_d,'(I4,I4,1x,E25.16,1x,E25.16)', iostat=ios) &
! idum, jdum, ctemp(1), ctemp(2)
if (dbg>2) write (out,*) i, j, ctemp(1), ctemp(2)
velocity(i,j,idir) = cmplx (-ctemp(2), ctemp(1), kind(KREAL))
if (ios /= 0) then
write (err,*) 'idir, i, j = ', idir, i, j
write (err,*) 'error reading velocity value from '//trim(cs)
stop 'error termination'
end if
end do ! i
end do ! j
! attempt to read one more element. This must fail, otherwise
! this would indicate that nstates in the input is not correct
call read_one_more
close (iu_d)
end do ! idir = velocity (del) components
write (out,'(1x,a/)') 'successfully read velocity data files'
end if ! havevel
! --------------------------------------
! now process electric multipole moments
! --------------------------------------
! ---------------------------------------------------------
! read the electric dipole data in a loop over x, y, z. The
! electric dipole elements include a factor -e = -1 au
! ---------------------------------------------------------
if (havedip .and. .not.havevel) then
if (.not. allocated(eldip)) &
stop 'read_data_files: eldip not allocated, though it should be'
eldip = 0
do idir = 1, 3
write (cs,'(a,i1,a)') 'dipole-',idir,'.txt'
open(unit=iu_d, file=trim(cs), status='old', iostat=ios)
if (ios /= 0) then
write (err,*) 'error: file '//trim(cs)//' does not exist'
stop 'error termination'
end if
read(iu_d,*) cstemp
! n.b. inner loop must be the row index
do j = 1, nstates
do i = 1, nstates
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
!read (iu_d,'(I4,I4,1x,E25.16,1x,E25.16)', iostat=ios) &
! idum, jdum, ctemp(1), ctemp(2)
if (dbg>2) write (out,*) i, j, ctemp(1), ctemp(2)
eldip(i,j,idir) = cmplx (ctemp(1), ctemp(2), kind(KREAL))
if (ios /= 0) then
write (err,*) 'idir, i, j = ', idir, i, j
write (err,*) 'error reading dipole value from '//trim(cs)
stop 'error termination'
end if
end do ! i
end do ! j
! attempt to read one more element. This must fail, otherwise
! this would indicate that nstates in the input is not correct
call read_one_more
close (iu_d)
end do ! idir = electric dipole components
write (out,'(1x,a/)') 'successfully read electric dipole data files'
end if ! havedip
! -------------------------------------------------------------
! read the electric quadrupole data in a loop over x, y, z. The
! length-gause matrix elements should include a factor -e = -1 au
! -------------------------------------------------------------
! Maxime's additions
if (havequad .and. havevel) then
if (.not. allocated(veloquad)) &
stop 'read_data_files: veloquad not allocated, though it should be'
veloquad = 0
do idir = 1, 6
write (cs,'(a,i1,a)') 'velocity_quadrupole-',idir,'.txt'
open(unit=iu_d, file=trim(cs), status='old', iostat=ios)
if (ios /= 0) then
write (err,*) 'error: file '//trim(cs)//' does not exist'
stop 'error termination'
end if
read(iu_d,*) cstemp
! n.b. inner loop must be the row index
do j = 1, nstates
do i = 1, nstates
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
!read (iu_d,'(I4,I4,1x,E25.16,1x,E25.16)', iostat=ios) &
! idum, jdum, ctemp(1), ctemp(2)
if (dbg>2) write (out,*) i, j, ctemp(1), ctemp(2)
!veloquad(i,j,idir) = cmplx (ctemp(1), ctemp(2), kind(KREAL))
! veloquad(i,j,idir) = cmplx (ctemp(2), -ctemp(1), kind(KREAL)) ! other possibility to
veloquad(i,j,idir) = cmplx (-ctemp(2), ctemp(1), kind(KREAL))
if (ios /= 0) then
write (err,*) 'idir, i, j = ', idir, i, j
write (err,*) 'error reading quad. value from '//trim(cs)
stop 'error termination'
end if
end do ! i
end do ! j
! attempt to read one more element. This must fail, otherwise
! this would indicate that nstates in the input is not correct
call read_one_more
close (iu_d)
end do ! idir = velocity quadrupole tensor components
write (out,'(1x,a/)') 'successfully read electric velocity quadrupole data files'
! ------------------------------------------------------
! form traceless version of the quadrupole operator, use
! quadtmp for temp. storage. The matrix does NOT
! include the commonly used factor of 3/2, so this may
! need to be taken care of in the calling routine.
! ------------------------------------------------------
allocate (quadtmp(nstates,nstates,6))
quadtmp = 0
quadtmp(:,:,:) = veloquad(:,:,:)
! if veloquad doesn't include -e
veloquad(:,:,:) = -quadtmp(:,:,:)
! if veloquad is only r_i * p_j
! to obtain r_i * p_j + p_i * r_j
! do i = 1,3
! do j = 1,3
! if (i.eq.j) then
! quadtmp(:,:,qindex(i,i)) = &
! two * veloquad(:,:,qindex(i,i)) -sqm1 * one
! write (out,'(1x,a/)') 'I did it'
! else
! quadtmp(:,:,qindex(i,j)) = &
! veloquad(:,:,qindex(i,j)) + veloquad(:,:,qindex(j,i))
! end if
! end do
! end do
!
! ! ------------------------------------------------------
! ! form traceless version of the quadrupole operator, use
! ! quadtmp for temp. storage. The matrix does NOT
! ! include the commonly used factor of 3/2, so this may
! ! need to be taken care of in the calling routine.
! ! ------------------------------------------------------
! allocate (quadtmp(nstates,nstates,6))
! quadtmp = 0
! quadtmp(:,:,:) = veloquad(:,:,:)
! ! accumulate (1/3)trace in the veloquad ZZ components:
! do idir = 1,2
! veloquad(:,:,qindex(3,3)) = veloquad(:,:,qindex(3,3)) &
! + veloquad(:,:,qindex(idir,idir))
! end do
! veloquad(:,:,qindex(3,3)) = veloquad(:,:,qindex(3,3)) * third
! !subtract trace to get [u v - (1/3) delta(u,v) r^2] with u,v, = x,y,z
! do idir = 1,3
! quadtmp(:,:,qindex(idir,idir)) = &
! quadtmp(:,:,qindex(idir,idir)) - veloquad(:,:,qindex(3,3))
! end do
! veloquad(:,:,:) = quadtmp(:,:,:)
!
! ! test for violations of traceless condition
! quadtmp = 0
! do idir = 1,3
! quadtmp(:,:,1) = quadtmp(:,:,1) + &
! veloquad(:,:,qindex(idir,idir))
! end do
! if (maxval(abs(quadtmp(:,:,1))).gt.tiny) then
! write (cstemp,'(1x,a,1x,f15.13)') &
! 'WARNING: quadrupole array not traceless within ',tiny
! write (out,*) trim(cstemp)
! write (out,*) maxval(abs(quadtmp(:,:,1)))
! write (err,*) trim(cstemp)
! write (err,*) maxval(abs(quadtmp(:,:,1)))
! end if
! deallocate(quadtmp)
! write (out,'(1x,a/)') 'quadrupoles transformed to traceless form'
end if ! have velo + quad
! End Maxime's additions
if (havequad .and. .not.havevel) then
if (.not. allocated(elquad)) &
stop 'read_data_files: elquad not allocated, though it should be'
elquad = 0
do idir = 1, 6
write (cs,'(a,i1,a)') 'quadrupole-',idir,'.txt'
open(unit=iu_d, file=trim(cs), status='old', iostat=ios)
if (ios /= 0) then
write (err,*) 'error: file '//trim(cs)//' does not exist'
stop 'error termination'
end if
read(iu_d,*) cstemp
! n.b. inner loop must be the row index
do j = 1, nstates
do i = 1, nstates
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
!read (iu_d,'(I4,I4,1x,E25.16,1x,E25.16)', iostat=ios) &
! idum, jdum, ctemp(1), ctemp(2)
if (dbg>2) write (out,*) i, j, ctemp(1), ctemp(2)
elquad(i,j,idir) = cmplx (ctemp(1), ctemp(2), kind(KREAL))
if (ios /= 0) then
write (err,*) 'idir, i, j = ', idir, i, j
write (err,*) 'error reading quad. value from '//trim(cs)
stop 'error termination'
end if
end do ! i
end do ! j
! attempt to read one more element. This must fail, otherwise
! this would indicate that nstates in the input is not correct
call read_one_more
close (iu_d)
end do ! idir = quadrupole tensor components
write (out,'(1x,a/)') 'successfully read electric quadrupole data files'
! ------------------------------------------------------
! form traceless version of the quadrupole operator, use
! quadtmp for temp. storage. The matrix does NOT
! include the commonly used factor of 3/2, so this may
! need to be taken care of in the calling routine.
! ------------------------------------------------------
allocate (quadtmp(nstates,nstates,6))
quadtmp = 0
quadtmp(:,:,:) = elquad(:,:,:)
! accumulate (1/3)trace in the elquad ZZ components:
do idir = 1,2
elquad(:,:,qindex(3,3)) = elquad(:,:,qindex(3,3)) &
+ elquad(:,:,qindex(idir,idir))
end do
elquad(:,:,qindex(3,3)) = elquad(:,:,qindex(3,3)) * third
!subtract trace to get [u v - (1/3) delta(u,v) r^2] with u,v, = x,y,z
do idir = 1,3
quadtmp(:,:,qindex(idir,idir)) = &
quadtmp(:,:,qindex(idir,idir)) - elquad(:,:,qindex(3,3))
end do
elquad(:,:,:) = quadtmp(:,:,:)
! test for violations of traceless condition
quadtmp = 0
do idir = 1,3
quadtmp(:,:,1) = quadtmp(:,:,1) + &
elquad(:,:,qindex(idir,idir))
end do
if (maxval(abs(quadtmp(:,:,1))).gt.tiny) then
write (cstemp,'(1x,a,1x,f15.13)') &
'WARNING: quadrupole array not traceless within ',tiny
write (out,*) trim(cstemp)
write (out,*) maxval(abs(quadtmp(:,:,1)))
write (err,*) trim(cstemp)
write (err,*) maxval(abs(quadtmp(:,:,1)))
end if
deallocate(quadtmp)
write (out,'(1x,a/)') 'quadrupoles transformed to traceless form'
end if ! havequad
! --------------------------------------
! print some of the assembled data, if requested
if (print_m) then
write (out,'(/1x,a/)') 'magnetic dipole moment matrix elements in au (x,y,z)'
do i = 1,nstates
do j = 1,nstates
write (out,'(i5,1x,i5,1x,3("("F15.10,SP,F15.10,"i)"))') i,j, &
-half*magdip(i,j,1:3)
end do
end do
end if ! print_m
if (print_d) then
write (out,'(/1x,a/)') 'electric dipole moment matrix elements in au (x,y,z)'
do i = 1,nstates
do j = 1,nstates
write (out,'(i5,1x,i5,1x,3("("F15.10,SP,F15.10,"i)"))') i,j, &
eldip(i,j,1:3)
end do
end do
end if ! print_d
return
! ============================================================================
contains
subroutine read_one_more
read (iu_d,*, iostat=ios) idum, jdum, ctemp(1:2)
if (ios == 0) then
write (err,*) 'it appears that the data file '//trim(cs)
write (err,*) 'contains more data than corresponding to nstates'
write (cs,*) nstates
write (err,*) 'as set in options.dat (nstates='// &
trim(adjustl(cs))//'). aborting'
stop 'error termination'
end if
end subroutine read_one_more
end subroutine read_data_files