-
Notifications
You must be signed in to change notification settings - Fork 8
/
prop_xy2.f90
3236 lines (2883 loc) · 192 KB
/
prop_xy2.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
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
!
! This unit defines all specific routines for a triatomic molecule of XY2 type
!
module prop_xy2
use accuracy
use moltype
use timer
use pot_xy2, only : MLloc2pqr_xy2
implicit none
public prop_xy2_qmom_sym, MLdipole_h2o_lpt2011, prop_xy2_sr, prop_xy2_spin_rotation_bisector
private
integer(ik), parameter :: verbose = 4 ! Verbosity level
contains
recursive subroutine prop_xy2_sr(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iatom, icentre
real(ark) :: xyz0(3), xyz_(natoms,3), r1, r2, alpha1, e1(3), e2(3), e3(3), n1(3), n2(3), n3(3), tmat(3,3), &!
coords(3), c_mb(3,3), c_xyz(3,3), c_xyz_(3,3), tmat_inv(3,3), x(natoms,3)
character(len=cl) :: txt
icentre = nint(extf%coef(1,1)) ! icentre=1 means centre on Y1 and icentre=2 - on Y2
if (rank/=9) then
write(out, '(/a,1x,i3,1x,a)') 'prop_xy2_sr error: rank of the dipole moment vector =', rank, ', expected 9'
stop
endif
!
txt = 'prop_xy2_sr'
!
! xyz are undefined for the local case
if (all(abs(xyz)<small_)) then
!
select case(trim(molec%coords_transform))
case default
write (out,"('prop_xy2_sr: coord. type ',a,' unknown')") trim(molec%coords_transform)
stop 'prop_xy2_sr - bad coord. type'
case('R-RHO-Z')
!
x = MLloc2pqr_xy2(local)
!
xyz0 = x(1,:)
do iatom=1, natoms
xyz_(iatom,:) = x(iatom,:) - xyz0(:)
enddo
!
end select
!
else
!
xyz0 = xyz(1,:)
do iatom=1, natoms
xyz_(iatom,:) = xyz(iatom,:) - xyz0(:)
enddo
!
endif
!
r1 = sqrt(sum(xyz_(2,:)**2))
r2 = sqrt(sum(xyz_(3,:)**2))
e1 = xyz_(2,:)/r1
e2 = xyz_(3,:)/r2
alpha1 = aacos(sum(e1*e2))
!if (abs(alpha1-pi)<0.0001) stop 'prop_xy2_sr error: valence bond angle is 180 degrees (does not work for linear molecule)'
coords = (/r1,r2,alpha1/)
e3 = vector_product(e1,e2)
tmat(1,:) = e1
tmat(2,:) = e2
tmat(3,:) = e3
! compute spin-rotation tensor in molecular-bond frame
c_mb = 0
c_mb(1,1) = fit_xy2_nosym(extF%nterms(1)-1, extF%coef(2:extF%nterms(1),1), coords) ! first parameter defines centre on Y1 or Y2, see above
c_mb(2,2) = fit_xy2_nosym(extF%nterms(2), extF%coef(1:extF%nterms(2),2), coords)
c_mb(3,3) = fit_xy2_nosym(extF%nterms(3), extF%coef(1:extF%nterms(3),3), coords)
c_mb(1,2) = fit_xy2_nosym(extF%nterms(4), extF%coef(1:extF%nterms(4),4), coords)
c_mb(2,1) = fit_xy2_nosym(extF%nterms(5), extF%coef(1:extF%nterms(5),5), coords)
! transform tensor into coordinate frame defined by the input xyz coordinates
call matrix_pseudoinverse_ark( 3, 3, tmat(1:3,1:3), tmat_inv(1:3,1:3) )
c_xyz_(1:3,1:3) = matmul(tmat_inv(1:3,1:3), c_mb(1:3,1:3))
c_xyz(1:3,1:3) = matmul(c_xyz_(1:3,1:3), transpose(tmat_inv(1:3,1:3)))
f(1:9) = (/ c_xyz(1,1), c_xyz(1,2), c_xyz(1,3), c_xyz(2,1), c_xyz(2,2), c_xyz(2,3), c_xyz(3,1), c_xyz(3,2), c_xyz(3,3) /)
contains
function vector_product(v1,v2) result (v)
real(ark), intent(in) :: v1(3), v2(3)
real(ark) :: v(3)
v(1) = v1(2)*v2(3)-v1(3)*v2(2)
v(2) = v1(3)*v2(1)-v1(1)*v2(3)
v(3) = v1(1)*v2(2)-v1(2)*v2(1)
end function vector_product
end subroutine prop_xy2_sr
function fit_xy2_nosym(nparams, params, coords) result(f)
integer(ik), intent(in) :: nparams
real(ark), intent(in) :: params(nparams), coords(:)
real(ark) :: f
real(ark) :: r1, r2, alpha1, rad, f0, f1, f2, f3, req, alphaeq, beta
rad = real(pi,ark)/180.0_ark
req = params(1)
alphaeq = params(2)*rad
beta = params(3)
r1 = (coords(1)-req) * exp(-beta*(coords(1)-req)**2)
r2 = (coords(2)-req) * exp(-beta*(coords(2)-req)**2)
alpha1 = coords(3)-alphaeq
f0 = params(4)
f1 = xy2_func_n1_d6( (/r1,r2,alpha1/), params(5:22) ) ! nparams = 18
f2 = xy2_func_n2_d6( (/r1,r2,alpha1/), params(23:67) ) ! nparams = 45
f3 = xy2_func_n3_d6( (/r1,r2,alpha1/), params(68:87) ) ! nparams = 20
f = f0 + f1 + f2 + f3
end function fit_xy2_nosym
function xy2_func_n1_d6(coords, params) result(v)
real(ark), intent(in) :: coords(3)
real(ark), intent(in) :: params(18)
real(ark) :: v
real(ark) :: r1,r2,a1
real(ark) :: f(18)
r1 = coords(1)
r2 = coords(2)
a1 = coords(3)
f(1) = r1
f(2) = r1**2
f(3) = r1**3
f(4) = r1**4
f(5) = r1**5
f(6) = r1**6
f(7) = r2
f(8) = r2**2
f(9) = r2**3
f(10) = r2**4
f(11) = r2**5
f(12) = r2**6
f(13) = a1
f(14) = a1**2
f(15) = a1**3
f(16) = a1**4
f(17) = a1**5
f(18) = a1**6
v = sum(f*params)
end function xy2_func_n1_d6
function xy2_func_n2_d6(coords, params) result(v)
real(ark), intent(in) :: coords(3)
real(ark), intent(in) :: params(45)
real(ark) :: v
real(ark) :: r1,r2,a1
real(ark) :: f(45)
r1 = coords(1)
r2 = coords(2)
a1 = coords(3)
f(1) = r1*r2
f(2) = r1*r2**2
f(3) = r1*r2**3
f(4) = r1*r2**4
f(5) = r1*r2**5
f(6) = r1**2*r2
f(7) = r1**2*r2**2
f(8) = r1**2*r2**3
f(9) = r1**2*r2**4
f(10) = r1**3*r2
f(11) = r1**3*r2**2
f(12) = r1**3*r2**3
f(13) = r1**4*r2
f(14) = r1**4*r2**2
f(15) = r1**5*r2
f(16) = a1*r1
f(17) = a1**2*r1
f(18) = a1**3*r1
f(19) = a1**4*r1
f(20) = a1**5*r1
f(21) = a1*r1**2
f(22) = a1**2*r1**2
f(23) = a1**3*r1**2
f(24) = a1**4*r1**2
f(25) = a1*r1**3
f(26) = a1**2*r1**3
f(27) = a1**3*r1**3
f(28) = a1*r1**4
f(29) = a1**2*r1**4
f(30) = a1*r1**5
f(31) = a1*r2
f(32) = a1**2*r2
f(33) = a1**3*r2
f(34) = a1**4*r2
f(35) = a1**5*r2
f(36) = a1*r2**2
f(37) = a1**2*r2**2
f(38) = a1**3*r2**2
f(39) = a1**4*r2**2
f(40) = a1*r2**3
f(41) = a1**2*r2**3
f(42) = a1**3*r2**3
f(43) = a1*r2**4
f(44) = a1**2*r2**4
f(45) = a1*r2**5
v = sum(f*params)
end function xy2_func_n2_d6
function xy2_func_n3_d6(coords, params) result(v)
real(ark), intent(in) :: coords(3)
real(ark), intent(in) :: params(20)
real(ark) :: v
real(ark) :: r1,r2,a1
real(ark) :: f(20)
r1 = coords(1)
r2 = coords(2)
a1 = coords(3)
f(1) = a1*r1*r2
f(2) = a1**2*r1*r2
f(3) = a1**3*r1*r2
f(4) = a1**4*r1*r2
f(5) = a1*r1*r2**2
f(6) = a1**2*r1*r2**2
f(7) = a1**3*r1*r2**2
f(8) = a1*r1*r2**3
f(9) = a1**2*r1*r2**3
f(10) = a1*r1*r2**4
f(11) = a1*r1**2*r2
f(12) = a1**2*r1**2*r2
f(13) = a1**3*r1**2*r2
f(14) = a1*r1**2*r2**2
f(15) = a1**2*r1**2*r2**2
f(16) = a1*r1**2*r2**3
f(17) = a1*r1**3*r2
f(18) = a1**2*r1**3*r2
f(19) = a1*r1**3*r2**2
f(20) = a1*r1**4*r2
v = sum(f*params)
end function xy2_func_n3_d6
!###################################################################################################################################
recursive subroutine xy2_dipole_sym(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iatom,ierr
real(ark) :: xyz0(3), xyz_(natoms,3), r1, r2, alpha1, e1(3), e2(3), n1(3), n2(3), n3(3), tmat(3,3), coords(3), mu_mb(3), tmat_inv(3,3)
if (rank/=3) then
write(out, '(/a,1x,i3,1x,a)') 'xy2_dipole_sym error: rank of the dipole moment vector =', rank, ', expected 3'
stop
endif
xyz0 = xyz(1,:)
do iatom=1, natoms
xyz_(iatom,:) = xyz(iatom,:) - xyz0(:)
enddo
r1 = sqrt(sum(xyz_(2,:)**2))
r2 = sqrt(sum(xyz_(3,:)**2))
e1 = xyz_(2,:)/r1
e2 = xyz_(3,:)/r2
alpha1 = acos(sum(e1*e2))
n1 = e1 + e2
n2 = e1 - e2
n1 = n1/sqrt(sum(n1(:)**2))
n2 = n2/sqrt(sum(n2(:)**2))
n3 = vector_product(e1,e2)
n3 = n3/sqrt(sum(n3(:)**2))
tmat(1,:) = n1
tmat(2,:) = n2
tmat(3,:) = n3
coords = (/r1,r2,alpha1/)
mu_mb(1) = fit_xy2_dipole_A1(extF%nterms(1), extF%coef(1:extF%nterms(1),1), coords)
mu_mb(2) = fit_xy2_dipole_B2(extF%nterms(2), extF%coef(1:extF%nterms(2),2), coords)
mu_mb(3) = 0.0
call matrix_pseudoinverse_ark( 3, 3, tmat(1:3,1:3), tmat_inv(1:3,1:3) )
!
f(1:3) = matmul(tmat_inv(1:3,1:3), mu_mb(1:3))
!
contains
function vector_product(v1,v2) result (v)
real(ark), intent(in) :: v1(3), v2(3)
real(ark) :: v(3)
v(1) = v1(2)*v2(3)-v1(3)*v2(2)
v(2) = v1(3)*v2(1)-v1(1)*v2(3)
v(3) = v1(1)*v2(2)-v1(2)*v2(1)
end function vector_product
end subroutine xy2_dipole_sym
subroutine MLinvmatark(al,ai,dimen,ierr)
integer,intent(in) :: dimen
real(ark),intent(in) :: al(:,:)
real(ark),intent(out) :: ai(:,:)
integer(ik),intent(out) :: ierr
real(ark) :: h(dimen),p,q
integer(ik) :: i1,i2,k,i,j,k8,k9
ierr = 0
ai=al
do i1=1,dimen
k=dimen-i1+1
p=ai(1,1)
do i=2,dimen
q=ai(i,1)
!
if (abs(p)<small_a) then
!
ierr = i
!
return
!
endif
!
h(i)=q/p
if(i.le.k) h(i)=-q/p
do j=2,i
k8=i-1
k9=j-1
ai(k8,k9)=ai(i,j)+q*h(j)
enddo
enddo
ai(dimen,dimen)=1.0_ark/p
do i=2,dimen
k8=i-1
ai(dimen,k8)=h(i)
enddo
end do
do i=1,dimen
k8=i-1
do j=1,k8
ai(j,i)=ai(i,j)
enddo
enddo
return
end subroutine MLinvmatark
! Subroutine to test xy2_dipole_sym if it is able to reproduce the original ab initio Cartesian components
subroutine TEST_xy2_dipole_sym(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iounit, iatom, npoints, ipoint, info, ithread
real(ark) :: xyz_(natoms,3), mu_xyz(3), mu_xyz0(3), rms(3), angs
character(cl) :: fname
integer(ik), external :: omp_get_thread_num
f = 0
ithread = omp_get_thread_num()
print*, ithread
if (ithread==0) then
write(out, '(/a)') 'TEST_xy2_dipole_sym/start: test dipole moment transformation'
angs = 0.529177209_ark
fname = 'MU.dat'
call IOstart(fname, iounit)
open(iounit,form='formatted',file=fname,iostat=info)
if (info/=0) then
write(out, '(/a,a,a)') 'TEST_xy2_dipole_sym error: file "', trim(fname), '" not found'
stop
endif
ipoint = 0
rms = 0
do
ipoint = ipoint + 1
read(iounit,*,iostat=info) (xyz_(iatom,1:3), iatom=1, natoms), mu_xyz0(1:3)
if (info/=0) exit
xyz_ = xyz_ * angs
call xy2_dipole_sym(rank, ncoords, natoms, local, xyz_, mu_xyz(1:3))
write(out, '(1x,i6,9(1x,f12.4))') ipoint, mu_xyz0(1:3), mu_xyz(1:3), mu_xyz0(1:3)-mu_xyz(1:3)
rms(1:3) = rms(1:3) + (mu_xyz0(1:3)-mu_xyz(1:3))**2
enddo
npoints = ipoint-1
close(iounit)
rms = sqrt(rms/real(npoints,ark))
write(out, '(/1x,a,3(1x,f12.4))') 'rms =', rms
write(out, '(/a)') 'TEST_xy2_dipole_sym/done'
endif
!$omp barrier
stop
end subroutine TEST_xy2_dipole_sym
!###################################################################################################################################
! Electric field gradient tensor for XY2-type molecule, centered on Y atom
recursive subroutine xy2_efg_y(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iatom, icentre
real(ark) :: xyz0(3), xyz_(natoms,3), r1, r2, alpha1, e1(3), e2(3), e3(3), n1(3), n2(3), tmat(3,3), &!
coords(3), efg_mb1(3,3), efg_mb2(3,3), efg_A1, efg_B2, efg_xyz(3,3,2), efg_xyz_(3,3), tmat_inv(3,3)
icentre = nint(extf%coef(1,1)) ! icentre=1 means centre on Y1 and icentre=2 - on Y2
if (rank/=6) then
write(out, '(/a,1x,i3,1x,a)') 'xy2_efg_y error: rank of the dipole moment vector =', rank, ', expected 6'
stop
endif
xyz0 = xyz(1,:)
do iatom=1, natoms
xyz_(iatom,:) = xyz(iatom,:) - xyz0(:)
enddo
r1 = sqrt(sum(xyz_(2,:)**2))
r2 = sqrt(sum(xyz_(3,:)**2))
e1 = xyz_(2,:)/r1
e2 = xyz_(3,:)/r2
alpha1 = acos(sum(e1*e2))
if (abs(alpha1-pi)<0.0001) stop 'xy2_efg_y error: valence bond angle is 180 degrees (does not work for linear molecule)'
coords = (/r1,r2,alpha1/)
! construct projection vectors
if (icentre==1) then
xyz0 = xyz(2,:)
do iatom=1, natoms
xyz_(iatom,:) = xyz(iatom,:) - xyz0(:)
enddo
n1 = xyz_(1,:)/sqrt(sum(xyz_(1,:)**2))
n2 = xyz_(3,:)/sqrt(sum(xyz_(3,:)**2))
elseif (icentre==2) then
xyz0 = xyz(3,:)
do iatom=1, natoms
xyz_(iatom,:) = xyz(iatom,:) - xyz0(:)
enddo
n1 = xyz_(1,:)/sqrt(sum(xyz_(1,:)**2))
n2 = xyz_(2,:)/sqrt(sum(xyz_(2,:)**2))
endif
e1 = n1 + n2
e2 = n1 - n2
e1 = e1/sqrt(sum(e1(:)**2))
e2 = e2/sqrt(sum(e2(:)**2))
e3 = vector_product(e1,e2)
e3 = e3/sqrt(sum(e3(:)**2))
tmat(1,:) = e1
tmat(2,:) = e2
tmat(3,:) = e3
! compute EFG tensor
efg_mb1 = 0
efg_mb2 = 0
efg_A1 = fit_xy2_dipole_A1(extF%nterms(1)-1, extF%coef(2:extF%nterms(1),1), coords) ! first parameter defines centre on Y1 or Y2, see above
efg_B2 = fit_xy2_dipole_B2(extF%nterms(2), extF%coef(1:extF%nterms(2),2), coords)
efg_mb1(1,1) = (efg_A1 + efg_B2)*0.5_ark
efg_mb2(1,1) = (efg_A1 - efg_B2)*0.5_ark
efg_A1 = fit_xy2_dipole_A1(extF%nterms(3), extF%coef(1:extF%nterms(3),3), coords)
efg_B2 = fit_xy2_dipole_B2(extF%nterms(4), extF%coef(1:extF%nterms(4),4), coords)
efg_mb1(2,2) = (efg_A1 + efg_B2)*0.5_ark
efg_mb2(2,2) = (efg_A1 - efg_B2)*0.5_ark
efg_A1 = fit_xy2_dipole_A1(extF%nterms(5), extF%coef(1:extF%nterms(5),5), coords)
efg_B2 = fit_xy2_dipole_B2(extF%nterms(6), extF%coef(1:extF%nterms(6),6), coords)
efg_mb1(1,2) = (efg_A1 + efg_B2)*0.5_ark
efg_mb2(1,2) = (efg_A1 - efg_B2)*0.5_ark
efg_mb1(3,3) = -( efg_mb1(1,1) + efg_mb1(2,2) )
efg_mb1(2,1) = efg_mb1(1,2)
efg_mb2(3,3) = -( efg_mb2(1,1) + efg_mb2(2,2) )
efg_mb2(2,1) = efg_mb2(1,2)
! transform EFG tensor into coordinate frame defined by the input xyz coordinates
call matrix_pseudoinverse_ark( 3, 3, tmat(1:3,1:3), tmat_inv(1:3,1:3) )
efg_xyz_(1:3,1:3) = matmul(tmat_inv(1:3,1:3), efg_mb1(1:3,1:3))
efg_xyz(1:3,1:3,1) = matmul(efg_xyz_(1:3,1:3), transpose(tmat_inv(1:3,1:3)))
efg_xyz_(1:3,1:3) = matmul(tmat_inv(1:3,1:3), efg_mb2(1:3,1:3))
efg_xyz(1:3,1:3,2) = matmul(efg_xyz_(1:3,1:3), transpose(tmat_inv(1:3,1:3)))
f(1:6) = (/ efg_xyz(1,1,icentre), efg_xyz(1,2,icentre), efg_xyz(1,3,icentre), &!
efg_xyz(2,2,icentre), efg_xyz(2,3,icentre), efg_xyz(3,3,icentre) /)
contains
function vector_product(v1,v2) result (v)
real(ark), intent(in) :: v1(3), v2(3)
real(ark) :: v(3)
v(1) = v1(2)*v2(3)-v1(3)*v2(2)
v(2) = v1(3)*v2(1)-v1(1)*v2(3)
v(3) = v1(1)*v2(2)-v1(2)*v2(1)
end function vector_product
end subroutine xy2_efg_y
! Subroutine to test xy2_efg_y1 or xy2_efg_y2 if it is able to reproduce the original ab initio Cartesian components
subroutine TEST_xy2_efg_y(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iounit, iatom, npoints, ipoint, info, i, j, k, l, ii, ithread
real(ark) :: xyz_(natoms,3), mu_xyz(6), mu_xyz0(3,3), rms(6), angs, dmu(6)
character(cl) :: fname
integer(ik), external :: omp_get_thread_num
f = 0
ithread = omp_get_thread_num()
if (ithread==0) then
write(out, '(/a)') 'TEST_xy2_efg_y/start: test polarizability tensor transformation'
angs = 0.529177209_ark
fname = 'EFG.dat'
call IOstart(fname, iounit)
open(iounit,form='formatted',file=fname,iostat=info)
if (info/=0) then
write(out, '(/a,a,a)') 'xy2_efg_y error: file "', trim(fname), '" not found'
stop
endif
ipoint = 0
rms = 0
do
ipoint = ipoint + 1
read(iounit,*,iostat=info) (xyz_(iatom,1:3), iatom=1, natoms), (mu_xyz0(i,1:3), i=1, 3)
if (info/=0) exit
xyz_ = xyz_ * angs
call xy2_efg_y(rank, ncoords, natoms, local, xyz_, mu_xyz(1:6))
ii = 0
dmu = 0
do i=1, 3
do j=i, 3
ii = ii + 1
dmu(ii) = mu_xyz0(i,j) - mu_xyz(ii)
enddo
enddo
write(out, '(1x,i6,3x,6(4x,f12.4,1x,f12.4))') ipoint, (dmu(i)+mu_xyz(i), dmu(i), i=1, 6)
rms = rms + dmu**2
enddo
npoints = ipoint-1
close(iounit)
rms = sqrt(rms/real(npoints,ark))
write(out, '(/1x,a,6(1x,f12.4))') 'rms =', rms
write(out, '(/a)') 'TEST_xy2_efg_y/done'
endif
!$omp barrier
stop
end subroutine TEST_xy2_efg_y
!###################################################################################################################################
recursive subroutine prop_xy2_qmom_sym(rank, ncoords, natoms, local, xyz, f)
implicit none
!
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iatom,ierr
real(ark) :: xyz0(3), xyz_(natoms,3), r1, r2, alpha1, e1(3), e2(3), n1(3), n2(3), n3(3), tmat(3,3), &
coords(3), qmom_mb(3,3), qmom_xyz(3,3), qmom_xyz_(3,3), tmat_inv(3,3), x(3,3)
if (rank/=6) then
write(out, '(/a,1x,i3,1x,a)') 'xy2_qmom_sym error: rank of the dipole moment vector =', rank, ', expected 6'
stop
endif
! xyz are undefined for the local case
if (all(abs(xyz)<small_)) then
!
select case(trim(molec%coords_transform))
case default
write (out,"('prop_xy2_qmom_sym: coord. type ',a,' unknown')") trim(molec%coords_transform)
stop 'prop_xy2_qmom_sym - bad coord. type'
case('R-RHO-Z')
!
x = MLloc2pqr_xy2(local)
!
end select
!
else
!
x = xyz
!
endif
xyz0 = x(1,:)
do iatom=1, natoms
xyz_(iatom,:) = x(iatom,:) - xyz0(:)
enddo
r1 = sqrt(sum(xyz_(2,:)**2))
r2 = sqrt(sum(xyz_(3,:)**2))
e1 = xyz_(2,:)/r1
e2 = xyz_(3,:)/r2
alpha1 = acos(sum(e1*e2))
n1 = e1 + e2
n2 = e1 - e2
n1 = n1/sqrt(sum(n1(:)**2))
n2 = n2/sqrt(sum(n2(:)**2))
n3 = vector_product(e1,e2)
n3 = n3/sqrt(sum(n3(:)**2))
tmat(1,:) = n1
tmat(2,:) = n2
tmat(3,:) = n3
coords = (/r1,r2,alpha1/)
qmom_mb = 0
qmom_mb(1,1) = fit_xy2_dipole_A1(extF%nterms(1), extF%coef(1:extF%nterms(1),1), coords)
qmom_mb(2,2) = fit_xy2_dipole_A1(extF%nterms(2), extF%coef(1:extF%nterms(2),2), coords)
qmom_mb(1,2) = fit_xy2_dipole_B2(extF%nterms(3), extF%coef(1:extF%nterms(3),3), coords)
qmom_mb(3,3) = -( qmom_mb(1,1) + qmom_mb(2,2) )
qmom_mb(2,1) = qmom_mb(1,2)
call matrix_pseudoinverse_ark( 3, 3, tmat(1:3,1:3), tmat_inv(1:3,1:3) )
!
!call MLinvmatark(tmat,tmat_inv,3,ierr)
!
!if (ierr/=0) then
! write(out,"('xy2_dipole_sym error: failed inverse',i0)") ierr
! stop 'xy2_dipole_sym error: failed inverse'
!endif
!
qmom_xyz_(1:3,1:3) = matmul(tmat_inv(1:3,1:3), qmom_mb(1:3,1:3))
qmom_xyz(1:3,1:3) = matmul(qmom_xyz_(1:3,1:3), transpose(tmat_inv(1:3,1:3)))
f(1:6) = (/ qmom_xyz(1,1), qmom_xyz(1,2), qmom_xyz(1,3), qmom_xyz(2,2), qmom_xyz(2,3), qmom_xyz(3,3) /)
contains
function vector_product(v1,v2) result (v)
real(ark), intent(in) :: v1(3), v2(3)
real(ark) :: v(3)
v(1) = v1(2)*v2(3)-v1(3)*v2(2)
v(2) = v1(3)*v2(1)-v1(1)*v2(3)
v(3) = v1(1)*v2(2)-v1(2)*v2(1)
end function vector_product
end subroutine prop_xy2_qmom_sym
! Subroutine to test xy2_qmom_sym if it is able to reproduce the original ab initio Cartesian components
subroutine TEST_xy2_qmom_sym(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iounit, iatom, npoints, ipoint, info, i, j, k, l, ii, ithread
real(ark) :: xyz_(natoms,3), mu_xyz(6), mu_xyz0(3,3), rms(6), angs, dmu(6)
character(cl) :: fname
integer(ik), external :: omp_get_thread_num
f = 0
ithread = omp_get_thread_num()
if (ithread==0) then
write(out, '(/a)') 'TEST_xy2_qmom_sym/start: test polarizability tensor transformation'
angs = 0.529177209_ark
fname = 'QMOM.dat'
call IOstart(fname, iounit)
open(iounit,form='formatted',file=fname,iostat=info)
if (info/=0) then
write(out, '(/a,a,a)') 'TEST_xy2_qmom_sym error: file "', trim(fname), '" not found'
stop
endif
ipoint = 0
rms = 0
do
ipoint = ipoint + 1
read(iounit,*,iostat=info) (xyz_(iatom,1:3), iatom=1, natoms), (mu_xyz0(i,1:3), i=1, 3)
if (info/=0) exit
xyz_ = xyz_ * angs
call prop_xy2_qmom_sym(rank, ncoords, natoms, local, xyz_, mu_xyz(1:6))
ii = 0
dmu = 0
do i=1, 3
do j=i, 3
ii = ii + 1
dmu(ii) = mu_xyz0(i,j) - mu_xyz(ii)
enddo
enddo
write(out, '(1x,i6,3x,6(4x,f12.4,1x,f12.4))') ipoint, (dmu(i)+mu_xyz(i), dmu(i), i=1, 6)
rms = rms + dmu**2
enddo
npoints = ipoint-1
close(iounit)
rms = sqrt(rms/real(npoints,ark))
write(out, '(/1x,a,6(1x,f12.4))') 'rms =', rms
write(out, '(/a)') 'TEST_xy2_qmom_sym/done'
endif
!$omp barrier
stop
end subroutine TEST_xy2_qmom_sym
!###################################################################################################################################
recursive subroutine xy2_alpha_sym(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iatom
real(ark) :: xyz0(3), xyz_(natoms,3), r1, r2, alpha1, e1(3), e2(3), n1(3), n2(3), n3(3), tmat(3,3), &!
coords(3), alpha_mb(3,3), alpha_xyz(3,3), alpha_xyz_(3,3), tmat_inv(3,3)
if (rank/=6) then
write(out, '(/a,1x,i3,1x,a)') 'xy2_alpha_sym error: rank of the dipole moment vector =', rank, ', expected 6'
stop
endif
xyz0 = xyz(1,:)
do iatom=1, natoms
xyz_(iatom,:) = xyz(iatom,:) - xyz0(:)
enddo
r1 = sqrt(sum(xyz_(2,:)**2))
r2 = sqrt(sum(xyz_(3,:)**2))
e1 = xyz_(2,:)/r1
e2 = xyz_(3,:)/r2
alpha1 = acos(sum(e1*e2))
n1 = e1 + e2
n2 = e1 - e2
n1 = n1/sqrt(sum(n1(:)**2))
n2 = n2/sqrt(sum(n2(:)**2))
n3 = vector_product(e1,e2)
n3 = n3/sqrt(sum(n3(:)**2))
tmat(1,:) = n1
tmat(2,:) = n2
tmat(3,:) = n3
coords = (/r1,r2,alpha1/)
alpha_mb = 0
alpha_mb(1,1) = fit_xy2_dipole_A1(extF%nterms(1), extF%coef(1:extF%nterms(1),1), coords)
alpha_mb(2,2) = fit_xy2_dipole_A1(extF%nterms(2), extF%coef(1:extF%nterms(2),2), coords)
alpha_mb(3,3) = fit_xy2_dipole_A1(extF%nterms(3), extF%coef(1:extF%nterms(3),3), coords)
alpha_mb(1,2) = fit_xy2_dipole_B2(extF%nterms(4), extF%coef(1:extF%nterms(4),4), coords)
alpha_mb(2,1) = alpha_mb(1,2)
call matrix_pseudoinverse_ark( 3, 3, tmat(1:3,1:3), tmat_inv(1:3,1:3) )
alpha_xyz_(1:3,1:3) = matmul(tmat_inv(1:3,1:3), alpha_mb(1:3,1:3))
alpha_xyz(1:3,1:3) = matmul(alpha_xyz_(1:3,1:3), transpose(tmat_inv(1:3,1:3)))
f(1:6) = (/ alpha_xyz(1,1), alpha_xyz(1,2), alpha_xyz(1,3), alpha_xyz(2,2), alpha_xyz(2,3), alpha_xyz(3,3) /)
contains
function vector_product(v1,v2) result (v)
real(ark), intent(in) :: v1(3), v2(3)
real(ark) :: v(3)
v(1) = v1(2)*v2(3)-v1(3)*v2(2)
v(2) = v1(3)*v2(1)-v1(1)*v2(3)
v(3) = v1(1)*v2(2)-v1(2)*v2(1)
end function vector_product
end subroutine xy2_alpha_sym
! Subroutine to test xy2_alpha_sym if it is able to reproduce the original ab initio Cartesian components
subroutine TEST_xy2_alpha_sym(rank, ncoords, natoms, local, xyz, f)
integer(ik),intent(in) :: rank, ncoords, natoms
real(ark),intent(in) :: local(ncoords), xyz(natoms,3)
real(ark),intent(out) :: f(rank)
integer(ik) :: iounit, iatom, npoints, ipoint, info, i, j, k, l, ii, ithread
real(ark) :: xyz_(natoms,3), mu_xyz(6), mu_xyz0(3,3), rms(6), angs, dmu(6)
character(cl) :: fname
integer(ik), external :: omp_get_thread_num
f = 0
ithread = omp_get_thread_num()
if (ithread==0) then
write(out, '(/a)') 'TEST_xy2_alpha_sym/start: test polarizability tensor transformation'
angs = 0.529177209_ark
fname = 'ALPHA.dat'
call IOstart(fname, iounit)
open(iounit,form='formatted',file=fname,iostat=info)
if (info/=0) then
write(out, '(/a,a,a)') 'TEST_xy2_alpha_sym error: file "', trim(fname), '" not found'
stop
endif
ipoint = 0
rms = 0
do
ipoint = ipoint + 1
read(iounit,*,iostat=info) (xyz_(iatom,1:3), iatom=1, natoms), (mu_xyz0(i,1:3), i=1, 3)
if (info/=0) exit
xyz_ = xyz_ * angs
call xy2_alpha_sym(rank, ncoords, natoms, local, xyz_, mu_xyz(1:6))
ii = 0
dmu = 0
do i=1, 3
do j=i, 3
ii = ii + 1
dmu(ii) = mu_xyz0(i,j) - mu_xyz(ii)
enddo
enddo
write(out, '(1x,i6,3x,6(4x,f12.4,1x,f12.4))') ipoint, (dmu(i)+mu_xyz(i), dmu(i), i=1, 6)
rms = rms + dmu**2
enddo
npoints = ipoint-1
close(iounit)
rms = sqrt(rms/real(npoints,ark))
write(out, '(/1x,a,6(1x,f12.4))') 'rms =', rms
write(out, '(/a)') 'TEST_xy2_alpha_sym/done'
endif
!$omp barrier
stop
end subroutine TEST_xy2_alpha_sym
!###################################################################################################################################
function fit_xy2_dipole_A1(nparams, params, coords) result(f)
integer(ik), intent(in) :: nparams
real(ark), intent(in) :: params(nparams), coords(:)
real(ark) :: f
real(ark) :: r1, r2, alpha1, rad, f0, f1, f2, f3, req, alphaeq, beta
rad = real(pi,ark)/180.0_ark
req = params(1)
alphaeq = params(2)*rad
beta = params(3)
r1 = (coords(1)-req) *exp(-beta*(coords(1)-req)**2)
r2 = (coords(2)-req) *exp(-beta*(coords(2)-req)**2)
alpha1 = coords(3)-alphaeq
f0 = params(4)
f1 = xy2_func_a1_n1_d6( (/r1,r2,alpha1/), params(5:16) ) ! nparams = 12
f2 = xy2_func_a1_n2_d6( (/r1,r2,alpha1/), params(17:40) ) ! nparams = 24
f3 = xy2_func_a1_n3_d6( (/r1,r2,alpha1/), params(41:53) ) ! nparams = 13
f = f0 + f1 + f2 + f3
end function fit_xy2_dipole_A1
!###################################################################################################################################
function fit_xy2_dipole_B2(nparams, params, coords) result(f)
integer(ik), intent(in) :: nparams
real(ark), intent(in) :: params(nparams), coords(:)
real(ark) :: f
real(ark) :: r1, r2, alpha1, rad, f0, f1, f2, f3, req, alphaeq, beta
rad = real(pi,ark)/180.0_ark
req = params(1)