-
Notifications
You must be signed in to change notification settings - Fork 1
/
qs_vcd_ao.F
2875 lines (2416 loc) · 136 KB
/
qs_vcd_ao.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
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------------------------------------------!
! 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 !
!--------------------------------------------------------------------------------------------------!
MODULE qs_vcd_ao
USE ai_contraction, ONLY: block_add,&
contraction
USE ai_kinetic, ONLY: kinetic
USE ai_overlap_ppl, ONLY: ppl_integral
USE ao_util, ONLY: exp_radius_very_extended
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind_set
USE basis_set_types, ONLY: get_gto_basis_set,&
gto_basis_set_p_type,&
gto_basis_set_type
USE block_p_types, ONLY: block_p_type
USE cell_types, ONLY: cell_type,&
pbc
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_copy, dbcsr_desymmetrize, dbcsr_distribution_get, &
dbcsr_distribution_type, dbcsr_finalize, dbcsr_get_block_p, dbcsr_get_info, dbcsr_init_p, &
dbcsr_p_type, dbcsr_scale, dbcsr_set, dbcsr_type, dbcsr_work_create
USE cp_dbcsr_operations, ONLY: dbcsr_allocate_matrix_set,&
dbcsr_deallocate_matrix_set
USE external_potential_types, ONLY: get_potential,&
gth_potential_type,&
sgp_potential_type
USE gaussian_gridlevels, ONLY: gridlevel_info_type
USE input_section_types, ONLY: section_vals_get_subs_vals,&
section_vals_type
USE kinds, ONLY: default_string_length,&
dp,&
int_8
USE memory_utilities, ONLY: reallocate
USE message_passing, ONLY: mp_comm_type
USE orbital_pointers, ONLY: coset,&
init_orbital_pointers,&
ncoset
USE particle_types, ONLY: particle_type
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_methods, ONLY: pw_axpy,&
pw_zero
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: pw_r3d_rs_type
USE qs_energy_types, ONLY: qs_energy_type
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_integral_utils, ONLY: basis_set_list_setup,&
get_memory_usage
USE qs_integrate_potential, ONLY: integrate_pgf_product
USE qs_kind_types, ONLY: get_qs_kind,&
get_qs_kind_set,&
qs_kind_type
USE qs_ks_types, ONLY: qs_ks_env_type
USE qs_linres_types, ONLY: vcd_env_type
USE qs_moments, ONLY: build_dsdv_moments
USE qs_neighbor_list_types, ONLY: &
get_iterator_info, get_neighbor_list_set_p, neighbor_list_iterate, &
neighbor_list_iterator_create, neighbor_list_iterator_p_type, &
neighbor_list_iterator_release, neighbor_list_set_p_type, nl_set_sub_iterator, &
nl_sub_iterate
USE qs_rho_types, ONLY: qs_rho_type
USE qs_vxc, ONLY: qs_vxc_create
USE realspace_grid_types, ONLY: realspace_grid_type
USE rs_pw_interface, ONLY: potential_pw2rs
USE sap_kind_types, ONLY: alist_type,&
build_sap_ints,&
get_alist,&
release_sap_int,&
sap_int_type,&
sap_sort
USE task_list_types, ONLY: atom_pair_type,&
task_list_type,&
task_type
USE virial_types, ONLY: virial_type
!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
!$ USE OMP_LIB, ONLY: omp_lock_kind, &
!$ omp_init_lock, omp_set_lock, &
!$ omp_unset_lock, omp_destroy_lock
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! *** Global parameters ***
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_vcd_ao'
INTEGER, PARAMETER :: bi_1 = 1, bi_x = 2, bi_y = 3, bi_z = 4, bi_xx = 5, &
bi_xy = 6, bi_xz = 7, bi_yy = 8, bi_yz = 9, bi_zz = 10
! *** Public subroutines ***
PUBLIC :: build_dSdV_matrix, build_com_rpnl_r, &
hr_mult_by_delta_3d, hr_mult_by_delta_1d, build_dcom_rpnl, build_drpnl_matrix, &
build_tr_matrix, &
build_rcore_matrix, &
build_rpnl_matrix, &
build_matrix_r_vhxc, &
build_matrix_hr_rh
CONTAINS
! **************************************************************************************************
!> \brief Build the matrix Hr*delta_nu^\lambda - rH*delta_mu^\lambda
!> \param vcd_env ...
!> \param qs_env ...
!> \param rc ...
!> \author Edward Ditler
! **************************************************************************************************
SUBROUTINE build_matrix_hr_rh(vcd_env, qs_env, rc)
TYPE(vcd_env_type) :: vcd_env
TYPE(qs_environment_type), POINTER :: qs_env
REAL(dp), DIMENSION(3) :: rc
CHARACTER(LEN=*), PARAMETER :: routineN = 'build_matrix_hr_rh'
INTEGER, PARAMETER :: ispin = 1
INTEGER :: handle, i
REAL(KIND=dp) :: eps_ppnl
TYPE(cell_type), POINTER :: cell
TYPE(dft_control_type), POINTER :: dft_control
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_all, sap_ppnl
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env=qs_env, &
dft_control=dft_control, &
particle_set=particle_set, &
sab_all=sab_all, &
sap_ppnl=sap_ppnl, &
qs_kind_set=qs_kind_set, &
cell=cell)
eps_ppnl = dft_control%qs_control%eps_ppnl
DO i = 1, 3
CALL dbcsr_set(vcd_env%matrix_hr(ispin, i)%matrix, 0._dp)
CALL dbcsr_set(vcd_env%matrix_rh(ispin, i)%matrix, 0._dp)
END DO
ASSOCIATE (my_matrix_hr_1d => vcd_env%matrix_hr(ispin, 1:3))
CALL build_rpnl_matrix(my_matrix_hr_1d, qs_kind_set, particle_set, sab_all, sap_ppnl, &
dft_control%qs_control%eps_ppnl, cell, rc, &
direction_Or=.TRUE.)
CALL build_tr_matrix(my_matrix_hr_1d, qs_env, qs_kind_set, "ORB", sab_all, &
direction_Or=.TRUE., rc=rc)
CALL build_rcore_matrix(my_matrix_hr_1d, qs_env, qs_kind_set, "ORB", sab_all, rc)
CALL build_matrix_r_vhxc(vcd_env%matrix_hr, qs_env, rc)
END ASSOCIATE
ASSOCIATE (my_matrix_hr_1d => vcd_env%matrix_rh(ispin, 1:3))
CALL build_rpnl_matrix(my_matrix_hr_1d, qs_kind_set, particle_set, sab_all, sap_ppnl, &
dft_control%qs_control%eps_ppnl, cell, rc, &
direction_Or=.FALSE.)
CALL build_tr_matrix(my_matrix_hr_1d, qs_env, qs_kind_set, "ORB", sab_all, &
direction_Or=.FALSE., rc=rc)
CALL build_rcore_matrix(my_matrix_hr_1d, qs_env, qs_kind_set, "ORB", sab_all, rc)
CALL build_matrix_r_vhxc(vcd_env%matrix_rh, qs_env, rc)
END ASSOCIATE
CALL timestop(handle)
END SUBROUTINE build_matrix_hr_rh
! **************************************************************************************************
!> \brief Product of r with V_nl. Adapted from build_com_rpnl.
!> \param matrix_rv ...
!> \param qs_kind_set ...
!> \param particle_set ...
!> \param sab_all ...
!> \param sap_ppnl ...
!> \param eps_ppnl ...
!> \param cell ...
!> \param ref_point ...
!> \param direction_Or ...
!> \author Edward Ditler, Tomas Zimmermann
! **************************************************************************************************
SUBROUTINE build_rpnl_matrix(matrix_rv, qs_kind_set, particle_set, sab_all, sap_ppnl, eps_ppnl, &
cell, ref_point, direction_Or)
TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_rv
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_all, sap_ppnl
REAL(KIND=dp), INTENT(IN) :: eps_ppnl
TYPE(cell_type), INTENT(IN), OPTIONAL, POINTER :: cell
REAL(KIND=dp), DIMENSION(3) :: ref_point
LOGICAL :: direction_Or
CHARACTER(LEN=*), PARAMETER :: routineN = 'build_rpnl_matrix'
INTEGER :: handle, i, iab, iac, iatom, ibc, icol, &
ikind, irow, jatom, jkind, kac, kbc, &
kkind, na, natom, nb, nkind, np, slot
INTEGER, DIMENSION(3) :: cell_b
LOGICAL :: found, ppnl_present
REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: achint, acint, bchint, bcint
TYPE(alist_type), POINTER :: alist_ac, alist_bc
TYPE(block_p_type), DIMENSION(3) :: blocks_rv
TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set
TYPE(gto_basis_set_type), POINTER :: orb_basis_set
TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
!$ INTEGER(kind=omp_lock_kind), &
!$ ALLOCATABLE, DIMENSION(:) :: locks
!$ INTEGER :: lock_num, hash
!$ INTEGER, PARAMETER :: nlock = 501
ppnl_present = ASSOCIATED(sap_ppnl)
IF (.NOT. ppnl_present) RETURN
CALL timeset(routineN, handle)
nkind = SIZE(qs_kind_set)
natom = SIZE(particle_set)
! sap_int needs to be shared as multiple threads need to access this
NULLIFY (sap_int)
ALLOCATE (sap_int(nkind*nkind))
DO i = 1, nkind*nkind
NULLIFY (sap_int(i)%alist, sap_int(i)%asort, sap_int(i)%aindex)
sap_int(i)%nalist = 0
END DO
MARK_USED(ref_point)
! "nder" in moment_mode is "order"
CALL build_sap_ints(sap_int, sap_ppnl, qs_kind_set, nder=1, moment_mode=.TRUE., &
particle_set=particle_set, cell=cell, refpoint=ref_point)
! *** Set up a sorting index
CALL sap_sort(sap_int)
ALLOCATE (basis_set(nkind))
DO ikind = 1, nkind
CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set)
IF (ASSOCIATED(orb_basis_set)) THEN
basis_set(ikind)%gto_basis_set => orb_basis_set
ELSE
NULLIFY (basis_set(ikind)%gto_basis_set)
END IF
END DO
! *** All integrals needed have been calculated and stored in sap_int
! *** We now calculate the commutator matrix elements
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP SHARED (basis_set, matrix_rv, &
!$OMP sap_int, nkind, eps_ppnl, locks, sab_all, direction_Or) &
!$OMP PRIVATE (ikind, jkind, iatom, jatom, cell_b, &
!$OMP iab, irow, icol, blocks_rv, &
!$OMP found, iac, ibc, alist_ac, alist_bc, &
!$OMP na, np, nb, kkind, kac, kbc, i, &
!$OMP hash, natom, acint, bcint, achint, bchint)
!$OMP SINGLE
!$ ALLOCATE (locks(nlock))
!$OMP END SINGLE
!$OMP DO
!$ DO lock_num = 1, nlock
!$ call omp_init_lock(locks(lock_num))
!$ END DO
!$OMP END DO
!$OMP DO SCHEDULE(GUIDED)
DO slot = 1, sab_all(1)%nl_size
ikind = sab_all(1)%nlist_task(slot)%ikind
jkind = sab_all(1)%nlist_task(slot)%jkind
iatom = sab_all(1)%nlist_task(slot)%iatom
jatom = sab_all(1)%nlist_task(slot)%jatom
cell_b(:) = sab_all(1)%nlist_task(slot)%cell(:)
IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) CYCLE
IF (.NOT. ASSOCIATED(basis_set(jkind)%gto_basis_set)) CYCLE
iab = ikind + nkind*(jkind - 1)
! *** Create matrix blocks for a new matrix block column ***
irow = iatom
icol = jatom
DO i = 1, 3
CALL dbcsr_get_block_p(matrix_rv(i)%matrix, irow, icol, blocks_rv(i)%block, found)
CPASSERT(found)
END DO
! loop over all kinds for projector atom
DO kkind = 1, nkind
iac = ikind + nkind*(kkind - 1)
ibc = jkind + nkind*(kkind - 1)
IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) CYCLE
IF (.NOT. ASSOCIATED(sap_int(ibc)%alist)) CYCLE
CALL get_alist(sap_int(iac), alist_ac, iatom)
CALL get_alist(sap_int(ibc), alist_bc, jatom)
IF (.NOT. ASSOCIATED(alist_ac)) CYCLE
IF (.NOT. ASSOCIATED(alist_bc)) CYCLE
DO kac = 1, alist_ac%nclist
DO kbc = 1, alist_bc%nclist
IF (alist_ac%clist(kac)%catom /= alist_bc%clist(kbc)%catom) CYCLE
IF (ALL(cell_b + alist_bc%clist(kbc)%cell - alist_ac%clist(kac)%cell == 0)) THEN
IF (alist_ac%clist(kac)%maxac*alist_bc%clist(kbc)%maxach < eps_ppnl) CYCLE
acint => alist_ac%clist(kac)%acint
bcint => alist_bc%clist(kbc)%acint
achint => alist_ac%clist(kac)%achint
bchint => alist_bc%clist(kbc)%achint
na = SIZE(acint, 1)
np = SIZE(acint, 2)
nb = SIZE(bcint, 1)
!$ hash = MOD((iatom - 1)*natom + jatom, nlock) + 1
!$ CALL omp_set_lock(locks(hash))
IF (direction_Or) THEN
! Vnl*r
blocks_rv(1)%block(1:na, 1:nb) = blocks_rv(1)%block(1:na, 1:nb) + &
MATMUL(achint(1:na, 1:np, 1), TRANSPOSE(bcint(1:nb, 1:np, 2)))
blocks_rv(2)%block(1:na, 1:nb) = blocks_rv(2)%block(1:na, 1:nb) + &
MATMUL(achint(1:na, 1:np, 1), TRANSPOSE(bcint(1:nb, 1:np, 3)))
blocks_rv(3)%block(1:na, 1:nb) = blocks_rv(3)%block(1:na, 1:nb) + &
MATMUL(achint(1:na, 1:np, 1), TRANSPOSE(bcint(1:nb, 1:np, 4)))
ELSE
! r*Vnl
blocks_rv(1)%block(1:na, 1:nb) = blocks_rv(1)%block(1:na, 1:nb) + &
MATMUL(achint(1:na, 1:np, 2), TRANSPOSE(bcint(1:nb, 1:np, 1)))
blocks_rv(2)%block(1:na, 1:nb) = blocks_rv(2)%block(1:na, 1:nb) + &
MATMUL(achint(1:na, 1:np, 3), TRANSPOSE(bcint(1:nb, 1:np, 1)))
blocks_rv(3)%block(1:na, 1:nb) = blocks_rv(3)%block(1:na, 1:nb) + &
MATMUL(achint(1:na, 1:np, 4), TRANSPOSE(bcint(1:nb, 1:np, 1)))
END IF
!$ CALL omp_unset_lock(locks(hash))
EXIT ! We have found a match and there can be only one single match
END IF
END DO
END DO
END DO
DO i = 1, 3
NULLIFY (blocks_rv(i)%block)
END DO
END DO
!$OMP DO
!$ DO lock_num = 1, nlock
!$ call omp_destroy_lock(locks(lock_num))
!$ END DO
!$OMP END DO
!$OMP SINGLE
!$ DEALLOCATE (locks)
!$OMP END SINGLE NOWAIT
!$OMP END PARALLEL
CALL release_sap_int(sap_int)
DEALLOCATE (basis_set)
CALL timestop(handle)
END SUBROUTINE build_rpnl_matrix
! **************************************************************************************************
!> \brief Calculation of the product Tr or rT over Cartesian Gaussian functions.
!> \param matrix_tr ...
!> \param qs_env ...
!> \param qs_kind_set ...
!> \param basis_type basis set to be used
!> \param sab_nl pair list (must be consistent with basis sets!)
!> \param direction_Or ...
!> \param rc ...
!> \date 11.10.2010
!> \par History
!> Ported from qs_overlap, replaces code in build_core_hamiltonian
!> Refactoring [07.2014] JGH
!> Simplify options and use new kinetic energy integral routine
!> Adapted from qs_kinetic [07.2016]
!> Adapted from build_com_tr_matrix [2021] by ED
!> \author JGH
!> \version 1.0
! **************************************************************************************************
SUBROUTINE build_tr_matrix(matrix_tr, qs_env, qs_kind_set, basis_type, sab_nl, direction_Or, rc)
TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_tr
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
CHARACTER(LEN=*), INTENT(IN) :: basis_type
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_nl
LOGICAL :: direction_Or
REAL(KIND=dp), DIMENSION(3), OPTIONAL :: rc
CHARACTER(len=*), PARAMETER :: routineN = 'build_tr_matrix'
INTEGER :: handle, iatom, icol, ikind, ir, irow, &
iset, jatom, jkind, jset, ldsab, ltab, &
natom, ncoa, ncob, nkind, nseta, &
nsetb, sgfa, sgfb, slot
INTEGER, DIMENSION(3) :: cell
INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
npgfb, nsgfa, nsgfb
INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
LOGICAL :: do_symmetric, found, trans
REAL(KIND=dp) :: tab
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: qab, tkab
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: kab
REAL(KIND=dp), DIMENSION(3) :: ra, rab, rac, rb, rbc
REAL(KIND=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
REAL(KIND=dp), DIMENSION(:, :), POINTER :: kx_block, ky_block, kz_block, rpgfa, &
rpgfb, scon_a, scon_b, zeta, zetb
TYPE(cell_type), POINTER :: qs_cell
TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
!$ INTEGER(kind=omp_lock_kind), &
!$ ALLOCATABLE, DIMENSION(:) :: locks
!$ INTEGER :: lock_num, hash, hash1, hash2
!$ INTEGER(KIND=int_8) :: iatom8
!$ INTEGER, PARAMETER :: nlock = 501
MARK_USED(int_8)
CALL timeset(routineN, handle)
nkind = SIZE(qs_kind_set)
! check for symmetry
CPASSERT(SIZE(sab_nl) > 0)
CALL get_neighbor_list_set_p(neighbor_list_sets=sab_nl, symmetric=do_symmetric)
! prepare basis set
ALLOCATE (basis_set_list(nkind))
CALL basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
! *** Allocate work storage ***
ldsab = get_memory_usage(qs_kind_set, basis_type)
CALL get_qs_env(qs_env=qs_env, &
particle_set=particle_set, &
cell=qs_cell, &
natom=natom)
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED (ldsab,do_symmetric, sab_nl, rc,&
!$OMP ncoset,matrix_tr,basis_set_list,qs_cell,natom,locks) &
!$OMP PRIVATE (kx_block,ky_block,kz_block,kab,qab,tab,ikind,jkind,iatom,jatom,rab,rac,rbc,cell, &
!$OMP basis_set_a, basis_set_b, nseta, ncoa, ncob, ltab, nsetb, tkab, &
!$OMP irow, icol, found, trans, sgfa, sgfb, iset, jset, &
!$OMP hash, hash1, hash2, iatom8, slot) &
!$OMP PRIVATE (first_sgfa, la_max, la_min, npgfa, nsgfa, rpgfa, set_radius_a, zeta, scon_a) &
!$OMP PRIVATE (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, set_radius_b, zetb, scon_b) &
!$OMP SHARED(particle_set, direction_or) &
!$OMP PRIVATE(ra, rb)
!$OMP SINGLE
!$ ALLOCATE (locks(nlock))
!$OMP END SINGLE
!$OMP DO
!$ DO lock_num = 1, nlock
!$ call omp_init_lock(locks(lock_num))
!$ END DO
!$OMP END DO
ALLOCATE (kab(ldsab, ldsab, 3), qab(ldsab, ldsab))
!$OMP DO SCHEDULE(GUIDED)
DO slot = 1, sab_nl(1)%nl_size
ikind = sab_nl(1)%nlist_task(slot)%ikind
jkind = sab_nl(1)%nlist_task(slot)%jkind
iatom = sab_nl(1)%nlist_task(slot)%iatom
jatom = sab_nl(1)%nlist_task(slot)%jatom
cell(:) = sab_nl(1)%nlist_task(slot)%cell(:)
rab(1:3) = sab_nl(1)%nlist_task(slot)%r(1:3)
basis_set_a => basis_set_list(ikind)%gto_basis_set
IF (.NOT. ASSOCIATED(basis_set_a)) CYCLE
basis_set_b => basis_set_list(jkind)%gto_basis_set
IF (.NOT. ASSOCIATED(basis_set_b)) CYCLE
!$ iatom8 = INT(iatom - 1, int_8)*INT(natom, int_8) + INT(jatom, int_8)
!$ hash1 = INT(MOD(iatom8, INT(nlock, int_8)) + 1)
! basis ikind
first_sgfa => basis_set_a%first_sgf
la_max => basis_set_a%lmax
la_min => basis_set_a%lmin
npgfa => basis_set_a%npgf
nsgfa => basis_set_a%nsgf_set
rpgfa => basis_set_a%pgf_radius
set_radius_a => basis_set_a%set_radius
scon_a => basis_set_a%scon
zeta => basis_set_a%zet
! basis jkind
first_sgfb => basis_set_b%first_sgf
lb_max => basis_set_b%lmax
lb_min => basis_set_b%lmin
npgfb => basis_set_b%npgf
nsgfb => basis_set_b%nsgf_set
rpgfb => basis_set_b%pgf_radius
set_radius_b => basis_set_b%set_radius
scon_b => basis_set_b%scon
zetb => basis_set_b%zet
nseta = basis_set_a%nset
nsetb = basis_set_b%nset
IF (do_symmetric) THEN
IF (iatom <= jatom) THEN
irow = iatom
icol = jatom
ELSE
irow = jatom
icol = iatom
END IF
ELSE
irow = iatom
icol = jatom
END IF
NULLIFY (kx_block)
CALL dbcsr_get_block_p(matrix=matrix_tr(1)%matrix, &
row=irow, col=icol, BLOCK=kx_block, found=found)
CPASSERT(found)
NULLIFY (ky_block)
CALL dbcsr_get_block_p(matrix=matrix_tr(2)%matrix, &
row=irow, col=icol, BLOCK=ky_block, found=found)
CPASSERT(found)
NULLIFY (kz_block)
CALL dbcsr_get_block_p(matrix=matrix_tr(3)%matrix, &
row=irow, col=icol, BLOCK=kz_block, found=found)
CPASSERT(found)
! The kinetic integrals depend only on rab (also for the screening)
tab = NORM2(rab)
! With and without MIC, rab(:) is the vector giving us the coordinates of rb.
ra = pbc(particle_set(iatom)%r(:), qs_cell)
rb(:) = ra(:) + rab(:)
rac = pbc(rc, ra, qs_cell)
rbc = rac + rab
trans = do_symmetric .AND. (iatom > jatom)
DO iset = 1, nseta
ncoa = npgfa(iset)*(ncoset(la_max(iset)) - ncoset(la_min(iset) - 1))
sgfa = first_sgfa(1, iset)
DO jset = 1, nsetb
IF (set_radius_a(iset) + set_radius_b(jset) < tab) CYCLE
!$ hash2 = MOD((iset - 1)*nsetb + jset, nlock) + 1
!$ hash = MOD(hash1 + hash2, nlock) + 1
ncob = npgfb(jset)*(ncoset(lb_max(jset)) - ncoset(lb_min(jset) - 1))
sgfb = first_sgfb(1, jset)
! calculate integrals
ltab = MAX(npgfa(iset)*ncoset(la_max(iset) + 1), npgfb(jset)*ncoset(lb_max(jset) + 1))
ALLOCATE (tkab(ltab, ltab))
CALL kinetic(la_max(iset) + 1, la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
lb_max(jset) + 1, lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
rab, tkab)
! commutator
CALL ab_opr(la_max(iset), npgfa(iset), rpgfa(:, iset), la_min(iset), &
lb_max(jset), npgfb(jset), rpgfb(:, jset), lb_min(jset), &
tab, tkab, kab, rac, rbc, direction_Or)
DEALLOCATE (tkab)
! Contraction step
DO ir = 1, 3
CALL contraction(kab(:, :, ir), qab, ca=scon_a(:, sgfa:), na=ncoa, ma=nsgfa(iset), &
cb=scon_b(:, sgfb:), nb=ncob, mb=nsgfb(jset), trans=trans)
!$ CALL omp_set_lock(locks(hash))
SELECT CASE (ir)
CASE (1)
CALL block_add("IN", qab, nsgfa(iset), nsgfb(jset), kx_block, sgfa, sgfb, trans=trans)
CASE (2)
CALL block_add("IN", qab, nsgfa(iset), nsgfb(jset), ky_block, sgfa, sgfb, trans=trans)
CASE (3)
CALL block_add("IN", qab, nsgfa(iset), nsgfb(jset), kz_block, sgfa, sgfb, trans=trans)
END SELECT
!$ CALL omp_unset_lock(locks(hash))
END DO
END DO
END DO
END DO !iterator
DEALLOCATE (kab, qab)
!$OMP DO
!$ DO lock_num = 1, nlock
!$ call omp_destroy_lock(locks(lock_num))
!$ END DO
!$OMP END DO
!$OMP SINGLE
!$ DEALLOCATE (locks)
!$OMP END SINGLE NOWAIT
!$OMP END PARALLEL
! Release work storage
DEALLOCATE (basis_set_list)
CALL timestop(handle)
END SUBROUTINE build_tr_matrix
! **************************************************************************************************
!> \brief Commutator of the of the local part of the pseudopotential with r
!> \param matrix_rcore ...
!> \param qs_env ...
!> \param qs_kind_set ...
!> \param basis_type ...
!> \param sab_nl ...
!> \param rf ...
!> \author Edward Ditler, Tomas Zimmermann
! **************************************************************************************************
SUBROUTINE build_rcore_matrix(matrix_rcore, qs_env, qs_kind_set, basis_type, sab_nl, rf)
TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_rcore
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
CHARACTER(LEN=*) :: basis_type
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_nl
REAL(KIND=dp), DIMENSION(3), OPTIONAL :: rf
CHARACTER(len=*), PARAMETER :: routineN = 'build_rcore_matrix'
INTEGER, PARAMETER :: nexp_max = 30
INTEGER :: atom_a, atom_b, handle, i, iatom, icol, idir, ikind, inode, irow, iset, jatom, &
jkind, jset, katom, kkind, ldai, ldsab, maxco, maxder, maxl, maxlgto, maxlppl, maxnset, &
maxsgf, mepos, n_local, ncoa, ncob, nder, nexp_lpot, nexp_ppl, nimages, nkind, nloc, &
nseta, nsetb, nthread, sgfa, sgfb
INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind
INTEGER, DIMENSION(1:10) :: nrloc
INTEGER, DIMENSION(3) :: cellind
INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, &
nct_lpot, npgfa, npgfb, nsgfa, nsgfb
INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
INTEGER, DIMENSION(nexp_max) :: nct_ppl
LOGICAL :: do_symmetric, dokp, ecp_local, &
ecp_semi_local, found, lpotextended
REAL(KIND=dp) :: alpha, dab, dac, dbc, ppl_radius
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: hab, qab
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: ppl_work, rhab, work
REAL(KIND=dp), DIMENSION(1:10) :: aloc, bloc
REAL(KIND=dp), DIMENSION(3) :: ra, rab, rac, raf, rb, rbc, rbf
REAL(KIND=dp), DIMENSION(4, nexp_max) :: cval_ppl
REAL(KIND=dp), DIMENSION(:), POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
set_radius_a, set_radius_b
REAL(KIND=dp), DIMENSION(:, :), POINTER :: cval_lpot, hx_block, hy_block, hz_block, &
rpgfa, rpgfb, scon_a, scon_b, sphi_a, &
sphi_b, zeta, zetb
REAL(KIND=dp), DIMENSION(nexp_max) :: alpha_ppl
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(gth_potential_type), POINTER :: gth_potential
TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
TYPE(neighbor_list_iterator_p_type), &
DIMENSION(:), POINTER :: ap_iterator, nl_iterator
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sac_ppl
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(sgp_potential_type), POINTER :: sgp_potential
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env=qs_env, &
atomic_kind_set=atomic_kind_set, &
qs_kind_set=qs_kind_set, &
particle_set=particle_set, &
sac_ppl=sac_ppl, &
cell=cell)
! check for symmetry
CPASSERT(SIZE(sab_nl) > 0)
CALL get_neighbor_list_set_p(neighbor_list_sets=sab_nl, symmetric=do_symmetric)
nkind = SIZE(qs_kind_set)
! prepare basis set
ALLOCATE (basis_set_list(nkind))
CALL basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
nder = 0
nimages = 1
alpha_ppl = 0
nct_ppl = 0
cval_ppl = 0
nkind = SIZE(atomic_kind_set)
dokp = (nimages > 1)
CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, atom_of_kind=atom_of_kind)
maxder = ncoset(nder)
CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxlgto=maxlgto, &
maxsgf=maxsgf, maxnset=maxnset, maxlppl=maxlppl, &
basis_type=basis_type)
maxl = MAX(maxlgto, maxlppl)
CALL init_orbital_pointers(2*maxl + 2*nder + 2)
!tz: maxco in maxco*ncoset(maxlgto+1) is an overkill,
! properly there should be maxpgf*ncoset(maxlgto+1), but maxpgf is difficult to get
ldsab = MAX(maxco, ncoset(maxlppl), maxsgf, maxlppl, maxco*ncoset(maxlgto + 1))
ldai = ncoset(2*maxlgto + 2)
DO ikind = 1, nkind
CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a, basis_type=basis_type)
IF (ASSOCIATED(basis_set_a)) THEN
basis_set_list(ikind)%gto_basis_set => basis_set_a
ELSE
NULLIFY (basis_set_list(ikind)%gto_basis_set)
END IF
END DO
nthread = 1
!$ nthread = omp_get_max_threads()
CALL neighbor_list_iterator_create(nl_iterator, sab_nl, nthread=nthread)
! iterator for basis/potential list
CALL neighbor_list_iterator_create(ap_iterator, sac_ppl, search=.TRUE., nthread=nthread)
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP SHARED (nl_iterator, ap_iterator, basis_set_list, &
!$OMP atomic_kind_set, qs_kind_set, particle_set, &
!$OMP sab_nl, sac_ppl, nthread, ncoset, nkind, &
!$OMP atom_of_kind, ldsab, maxnset, maxder, &
!$OMP maxlgto, nder, maxco, dokp, cell) &
!$OMP SHARED (matrix_rcore, rf) &
!$OMP PRIVATE (ikind, jkind, inode, iatom, jatom, rab, basis_set_a, basis_set_b, atom_a) &
!$OMP PRIVATE (atom_b) &
!$OMP PRIVATE (nsetb) &
!$OMP PRIVATE (dab, irow, icol, hx_block, hy_block, hz_block, found, iset, ncoa) &
!$OMP PRIVATE (sgfa, jset, ncob, sgfb, work, hab, rhab, kkind, nseta) &
!$OMP PRIVATE (gth_potential, sgp_potential, alpha, cexp_ppl, lpotextended) &
!$OMP PRIVATE (ppl_radius, nexp_lpot, nexp_ppl, alpha_ppl, alpha_lpot, nct_ppl) &
!$OMP PRIVATE (ecp_semi_local, nct_lpot, cval_ppl, cval_lpot, rac, dac, rbc, dbc) &
!$OMP PRIVATE (mepos) &
!$OMP PRIVATE (katom, ppl_work, cellind, ecp_local) &
!$OMP PRIVATE (first_sgfa, la_max, la_min, npgfa, nsgfa, rpgfa, set_radius_a, sphi_a, zeta, scon_a) &
!$OMP PRIVATE (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, set_radius_b, sphi_b, zetb, scon_b) &
!$OMP PRIVATE (nloc, nrloc, aloc, bloc, n_local, a_local, c_local, ldai) &
!$OMP PRIVATE (ra, rb, qab, raf, rbf)
mepos = 0
!$ mepos = omp_get_thread_num()
ALLOCATE (hab(ldsab, ldsab), rhab(ldsab, ldsab, 3), work(ldsab, ldsab*(nder + 1), 3))
ALLOCATE (qab(ldsab, ldsab))
ldai = ncoset(2*maxlgto + 2)
ALLOCATE (ppl_work(ldai, ldai, MAX(maxder, 2*maxlgto + 2 + 1)))
DO WHILE (neighbor_list_iterate(nl_iterator, mepos=mepos) == 0)
CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, inode=inode, &
iatom=iatom, jatom=jatom, r=rab, cell=cellind)
basis_set_a => basis_set_list(ikind)%gto_basis_set
IF (.NOT. ASSOCIATED(basis_set_a)) CYCLE
basis_set_b => basis_set_list(jkind)%gto_basis_set
IF (.NOT. ASSOCIATED(basis_set_b)) CYCLE
atom_a = atom_of_kind(iatom)
atom_b = atom_of_kind(jatom)
! basis ikind
first_sgfa => basis_set_a%first_sgf
la_max => basis_set_a%lmax
la_min => basis_set_a%lmin
npgfa => basis_set_a%npgf
nsgfa => basis_set_a%nsgf_set
rpgfa => basis_set_a%pgf_radius
set_radius_a => basis_set_a%set_radius
sphi_a => basis_set_a%sphi
zeta => basis_set_a%zet
scon_a => basis_set_a%scon
! basis jkind
first_sgfb => basis_set_b%first_sgf
lb_max => basis_set_b%lmax
lb_min => basis_set_b%lmin
npgfb => basis_set_b%npgf
nsgfb => basis_set_b%nsgf_set
rpgfb => basis_set_b%pgf_radius
set_radius_b => basis_set_b%set_radius
sphi_b => basis_set_b%sphi
zetb => basis_set_b%zet
scon_b => basis_set_b%scon
nseta = basis_set_a%nset
nsetb = basis_set_b%nset
! *** Create matrix blocks for a new matrix block column ***
irow = iatom
icol = jatom
NULLIFY (hx_block)
NULLIFY (hy_block)
NULLIFY (hz_block)
CALL dbcsr_get_block_p(matrix=matrix_rcore(1)%matrix, &
row=irow, col=icol, BLOCK=hx_block, found=found)
CPASSERT(found)
CALL dbcsr_get_block_p(matrix=matrix_rcore(2)%matrix, &
row=irow, col=icol, BLOCK=hy_block, found=found)
CPASSERT(found)
CALL dbcsr_get_block_p(matrix=matrix_rcore(3)%matrix, &
row=irow, col=icol, BLOCK=hz_block, found=found)
CPASSERT(found)
dab = NORM2(rab)
ra = pbc(particle_set(iatom)%r(:), cell)
rb(:) = ra(:) + rab(:)
raf = pbc(rf, ra, cell)
rbf = raf + rab
! loop over all kinds for pseudopotential atoms
DO kkind = 1, nkind
CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
sgp_potential=sgp_potential)
IF (ASSOCIATED(gth_potential)) THEN
CALL get_potential(potential=gth_potential, &
alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
lpot_present=lpotextended, ppl_radius=ppl_radius)
nexp_ppl = 1
alpha_ppl(1) = alpha
nct_ppl(1) = SIZE(cexp_ppl)
cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
IF (lpotextended) THEN
CALL get_potential(potential=gth_potential, &
nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, cval_lpot=cval_lpot)
CPASSERT(nexp_lpot < nexp_max)
nexp_ppl = nexp_lpot + 1
alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
DO i = 1, nexp_lpot
cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
END DO
END IF
ELSE IF (ASSOCIATED(sgp_potential)) THEN
CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
ppl_radius=ppl_radius)
IF (ecp_local) THEN
CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
IF (SUM(ABS(aloc(1:nloc))) < 1.0e-12_dp) CYCLE
nexp_ppl = nloc
CPASSERT(nexp_ppl <= nexp_max)
nct_ppl(1:nloc) = nrloc(1:nloc) - 1
alpha_ppl(1:nloc) = bloc(1:nloc)
cval_ppl(1, 1:nloc) = aloc(1:nloc)
ELSE
CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
nexp_ppl = n_local
CPASSERT(nexp_ppl <= nexp_max)
nct_ppl(1:n_local) = 1
alpha_ppl(1:n_local) = a_local(1:n_local)
cval_ppl(1, 1:n_local) = c_local(1:n_local)
END IF
IF (ecp_semi_local) THEN
CPABORT("VCD with semi-local ECPs not implemented")
END IF
ELSE
CYCLE
END IF
CALL nl_set_sub_iterator(ap_iterator, ikind, kkind, iatom, mepos=mepos)
DO WHILE (nl_sub_iterate(ap_iterator, mepos=mepos) == 0)
CALL get_iterator_info(ap_iterator, mepos=mepos, jatom=katom, r=rac)
dac = SQRT(SUM(rac*rac))
rbc(:) = rac(:) - rab(:)
dbc = SQRT(SUM(rbc*rbc))
IF ((MAXVAL(set_radius_a(:)) + ppl_radius < dac) .OR. &
(MAXVAL(set_radius_b(:)) + ppl_radius < dbc)) THEN
CYCLE
END IF
DO iset = 1, nseta
IF (set_radius_a(iset) + ppl_radius < dac) CYCLE
ncoa = npgfa(iset)*ncoset(la_max(iset))
! ncoa = npgfa(iset)*(ncoset(la_max(iset))-ncoset(la_min(iset)-1))
sgfa = first_sgfa(1, iset)
DO jset = 1, nsetb
IF (set_radius_b(jset) + ppl_radius < dbc) CYCLE
ncob = npgfb(jset)*ncoset(lb_max(jset))
! ncob = npgfb(jset)*(ncoset(lb_max(jset))-ncoset(lb_min(jset)-1))
sgfb = first_sgfb(1, jset)
IF (set_radius_a(iset) + set_radius_b(jset) < dab) CYCLE
! *** Calculate the GTH pseudo potential forces ***
hab = 0
rhab = 0
ppl_work = 0
work = 0
CALL ppl_integral( &
la_max(iset) + 1, la_min(iset), npgfa(iset), &
rpgfa(:, iset), zeta(:, iset), &
lb_max(jset) + 1, lb_min(jset), npgfb(jset), &
rpgfb(:, jset), zetb(:, jset), &
nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
rab, dab, rac, dac, rbc, dbc, hab(:, :), ppl_work)
! product with r
CALL ab_opr(la_max(iset), npgfa(iset), rpgfa(:, iset), 0, &
lb_max(jset), npgfb(jset), rpgfb(:, jset), 0, &
dab, hab(:, :), rhab(:, :, :), raf, rbf, &
direction_Or=.FALSE.)
DO idir = 1, 3
CALL dgemm("N", "N", ncoa, nsgfb(jset), ncob, &
1.0_dp, rhab(1, 1, idir), SIZE(rhab, 1), &
sphi_b(1, sgfb), SIZE(sphi_b, 1), &
0.0_dp, work(1, 1, idir), SIZE(work, 1))
!$OMP CRITICAL(h_block_critical)
SELECT CASE (idir)
CASE (1)
CALL dgemm("T", "N", nsgfa(iset), nsgfb(jset), ncoa, &
1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
work(1, 1, idir), SIZE(work, 1), &
1.0_dp, hx_block(sgfa, sgfb), SIZE(hx_block, 1))
CASE (2)
CALL dgemm("T", "N", nsgfa(iset), nsgfb(jset), ncoa, &
1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
work(1, 1, idir), SIZE(work, 1), &
1.0_dp, hy_block(sgfa, sgfb), SIZE(hy_block, 1))
CASE (3)
CALL dgemm("T", "N", nsgfa(iset), nsgfb(jset), ncoa, &
1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
work(1, 1, idir), SIZE(work, 1), &
1.0_dp, hz_block(sgfa, sgfb), SIZE(hz_block, 1))
END SELECT
!$OMP END CRITICAL(h_block_critical)
END DO
END DO
END DO
END DO
END DO
END DO ! iterator
DEALLOCATE (hab, rhab, work, ppl_work)
!$OMP END PARALLEL
CALL neighbor_list_iterator_release(ap_iterator)
CALL neighbor_list_iterator_release(nl_iterator)
DEALLOCATE (atom_of_kind, basis_set_list)
CALL timestop(handle)
END SUBROUTINE build_rcore_matrix
! **************************************************************************************************
!> \brief Commutator of the Hartree+XC potentials with r
!> \param matrix_rv ...
!> \param qs_env ...
!> \param rc ...
!> \author Edward Ditler, Tomas Zimmermann
! **************************************************************************************************
SUBROUTINE build_matrix_r_vhxc(matrix_rv, qs_env, rc)
TYPE(dbcsr_p_type), DIMENSION(:, :), &
INTENT(INOUT), POINTER :: matrix_rv
TYPE(qs_environment_type), POINTER :: qs_env
REAL(KIND=dp), DIMENSION(3) :: rc
CHARACTER(LEN=*), PARAMETER :: routineN = 'build_matrix_r_vhxc'
INTEGER, PARAMETER :: nspins = 1
INTEGER :: handle, idir, ispin
REAL(kind=dp) :: edisp
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_rvxc, matrix_rvxc_desymm
TYPE(pw_env_type), POINTER :: pw_env
TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace, v_tau_rspace
TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace
TYPE(qs_energy_type), POINTER :: energy
TYPE(qs_ks_env_type), POINTER :: ks_env
TYPE(qs_rho_type), POINTER :: rho_struct
TYPE(section_vals_type), POINTER :: input, xc_section
CALL timeset(routineN, handle)