-
Notifications
You must be signed in to change notification settings - Fork 8
/
moltype.f90
2719 lines (2529 loc) · 73.2 KB
/
moltype.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
module moltype
use accuracy
use lapack
implicit none
private
public MoleculeT,molec,MLinitialize_molec,MLequilibrium_chi,MLorienting_a0,&
MLZmatrixT,MLfromlocal2cartesian,MLdiag_ulen,ML_check_steps,three_j,&
intensity,MLIntensityT,MLthresholdsT,extF,MLext_locexp,MLvector_product,ML_sym_rotat,ML_euler_rotait,MLdiag_ulen_ark,&
aacos,MLlinurark,MLlinur,faclog,aasin
public MLtemplate_poten,MLtemplate_potential,MLtemplate_coord_transform,MLtemplate_b0,MLtemplate_extF,MLtemplate_kinetic
public MLtemplate_symmetry_transformation,MLtemplate_rotsymmetry,ML_rjacobi_fit_ark,ML_splint,ML_splint_quint,ML_spline
public MLorienting_a0_across_dadrho,manifold
!
integer(ik), parameter :: verbose = 4 ! Verbosity level
type MLZmatrixT
character(len=cl) :: name ! Identifying name of atom (no effect on anything)
integer(ik) :: connect(4) ! z-matrix connections
end type MLZmatrixT
!
character(len=cl),parameter :: axis_system = 'Eckart'
abstract interface
real(ark) function MLtemplate_poten (local,xyz)
use accuracy
real(ark),intent(in) :: local(:)
real(ark),intent(in) :: xyz(:,:)
end function MLtemplate_poten
!
real(ark) function MLtemplate_potential (ncoords,natoms,local,xyz,force)
use accuracy
integer(ik),intent(in) :: ncoords,natoms
real(ark),intent(in) :: local(ncoords)
real(ark),intent(in) :: xyz(natoms,3)
real(ark),intent(in) :: force(:)
end function MLtemplate_potential
!
subroutine MLtemplate_extF(rank,ncoords,natoms,local,xyz,mu_xyz)
use accuracy
!
integer(ik),intent(in) :: rank,ncoords,natoms
real(ark),intent(in) :: local(ncoords),xyz(natoms,3)
real(ark),intent(out) :: mu_xyz(rank)
!
end subroutine MLtemplate_extF
!
subroutine MLtemplate_kinetic(nmodes,nterms,rho,g_vib,g_rot,g_cor,pseudo)
use accuracy
!
integer(ik),intent(in) :: nmodes,nterms
real(ark),intent(in) :: rho
real(ark),intent(out) :: g_vib(nmodes,nmodes,nterms),g_rot(3,3,nterms),g_cor(nmodes,3,nterms),pseudo(Nterms)
!
end subroutine MLtemplate_kinetic
!
subroutine MLtemplate_symmetry_transformation(ioper,natoms,src,dst)
use accuracy
!
integer(ik),intent(in) :: ioper ! group operation
integer(ik),intent(in) :: natoms
real(ark),intent(in) :: src(natoms)
real(ark),intent(out) :: dst(natoms)
!
end subroutine MLtemplate_symmetry_transformation
!
subroutine MLtemplate_rotsymmetry(J,K,tau,gamma,ideg)
use accuracy
!
integer(ik),intent(in) :: J,K,tau ! rot. quanta
integer(ik),intent(out) :: gamma,ideg
!
end subroutine MLtemplate_rotsymmetry
!
end interface
abstract interface
subroutine MLtemplate_b0 (Npoints,Natoms,b0,rho_i,rho_ref,rho_borders)
use accuracy
!
integer(ik), intent(in) :: Npoints
integer(ik), intent(in) :: Natoms
real(ark), intent(out) :: b0(Natoms,3,0:Npoints)
real(ark), intent(in) ,optional :: rho_i(0:Npoints)
real(ark), intent(out),optional :: rho_ref
real(ark), intent(in) ,optional :: rho_borders(2) ! rhomim, rhomax - borders
!
end subroutine MLtemplate_b0
!
function MLtemplate_coord_transform (src,ndst,direct) result (dst)
use accuracy
integer(ik),intent(in) :: ndst
real(ark),intent(in) :: src(:)
logical,intent(in) :: direct
!
real(ark),dimension(ndst) :: dst
!
end function MLtemplate_coord_transform
end interface
!procedure(interface1), pointer, nopass :: p
!Edit: In response to your comment, if you want to use the pass keyword, the interface would have to be changed as such:
!ABSTRACT INTERFACE
! integer function interface1(passed_object, a)
! import :: type1
! class(type1), intent(...) :: passed_object
! real, intent(in) :: a
! END function interface1
!END INTERFACE
!
type MoleculeT
!
character(len=cl) :: moltype ! Identifying the Molecule type (e.g. XY3)
real(ark),pointer :: AtomMasses(:)
real(ark),pointer :: req(:)
real(ark),pointer :: alphaeq(:)
real(ark),pointer :: taueq(:)
real(ark),pointer :: local_eq(:)
real(ark),pointer :: chi_eq(:)
real(ark),pointer :: specparam(:)
real(ark) :: rho_ref
real(ark) :: rho_border(2)
type(MLZmatrixT),pointer :: zmatrix(:) !
!
character(len=cl) :: coords_transform ! type of the coordinate transformation
integer(ik),pointer :: dihedtype(:) ! dihedral type
character(len=cl),pointer :: coordinates(:,:) ! Identifying the coordinate system, e.g. 'Cartesian', 'Bond-Angle'
integer(ik) :: Nmodes,Ndihedrals,Natoms,Nbonds,Nangles,Ncoords
integer(ik) :: parmax ! number of pot. parameters
integer(ik) :: N_meppars ! number of MEP. parameters
character(len=cl) :: potentype ! type of potential function
character(len=cl) :: kinetic_type ! type of the kinetic function
character(len=cl) :: meptype ! type of MEP function
real(ark),pointer :: force(:) ! force field
real(ark),pointer :: mep_params(:) ! MEP parameters
integer(ik),pointer :: mep_ind(:,:) ! MEP powers-index
character(len=16),pointer :: forcename(:) ! characters to store the force constant labels
integer(ik),pointer :: pot_ind(:,:) ! indexes with the powers for every expansion term
integer(ik),pointer :: ifit(:) ! varying indexes to control fitting
character(len=cl) :: symmetry ! molecular symmetry
!
!procedure(MLtemplate_poten),pointer :: potenfunc => null ()
!
end type MoleculeT
!
type xyT
real(ark) :: val
end type xyT
!
type(MoleculeT),save :: molec
!
!external field (function)expansion in terms of local coordinates
type MLext_locexp
integer(ik) :: rank ! rank of the external field (number of components),
! e.g. 3 for dipole, 9 for polarizability
integer(ik), pointer :: maxord(:) ! maximal order of the xi-expansions for each component.
integer(ik), pointer :: nterms(:)
integer(ik), pointer :: term(:, :, :)
integer(ik), pointer :: ifit(:, :)
real(ark), pointer :: coef(:, :)
character(cl), pointer :: name(:, :)
real(ark), pointer :: fdstep(:)
character(cl), pointer :: intcoords(:)
real(ark), pointer :: geom_ref(:)
integer(ik) :: irho_ref
character(cl) :: ftype = 'GENERAL' ! field type
real(rk) :: matelem_threshold = -1e0 ! threshold to set the primitive matrix elements to zero, required to reduce numerical noice in overtone intensities
end type MLext_locexp
!
! external field, e.g. dipole moment, palarizability etc.
!
type(MLext_locexp) :: extF
!type MLextf_xiexp
! integer(ik) :: maxord(3)
! real(ark), pointer :: fdstep(:)
! real(ark) :: coef_thr
!
! integer(ik) :: nterms(3)
! integer(ik), pointer :: term(:, :, :)
! real(ark), pointer :: coef(:, :, :)
! logical :: man_terms = .false.
! logical :: man_coefs = .false.
!
! integer(ik), pointer :: npoints(:)
! real(ark), pointer :: b(:, :)
!end type MLextf_xiexp
!type(MLextf_xiexp) :: extF_xi
!vars for transition intensities calculations
type MLthresholdsT
real(rk) :: intensity = -1e0 ! threshold defining the output intensities
real(rk) :: linestrength = -1e0 ! threshold defining the output linestrength
real(rk) :: coeff = -1e0 ! threshold defining the eigenfunction coefficients
! taken into account in the matrix elements evaluation.
real(rk) :: leading_coeff = 0.1
end type MLthresholdsT
type MLIntensityT
logical :: do = .false. ! process (.true.) or not (.false.) the intensity (or TM) calculations
character(cl) :: action ! type of the intensity calculations:
! absorption, emission, tm (transition moments),
! raman, and so on.
real(rk) :: temperature ! temperature in K
real(rk) :: part_func ! partition function
real(rk) :: ZPE ! zero point energy
type(MLthresholdsT) :: threshold ! different thresholds
real(rk),pointer :: gns(:) ! nuclear stat. weights
integer(ik),pointer :: isym_pairs(:) ! numbers defining symmetry pairs with allowed transitions, analogous to gns
real(rk) :: freq_window(1:2) ! frequency window (1/cm)
real(rk) :: erange_low(1:2) ! energy range for the lower state
real(rk) :: erange_upp(1:2) ! energy range for the upper state
integer(ik) :: J(1:2) ! range of J-values, from..to; in order to avoid double counting of transitions
! in the calculations it is always assumed that
! J1<=J_lower<=J2 and J1<=J_upper<J2;
!
integer(ik),pointer :: v_low(:,:) ! lower state range of the quantun numbers employed
integer(ik),pointer :: v_upp(:,:) ! upper state range of the quantun numbers employed
! in intensity calculations; (imode,1:2),
! where 1 stands for the beginning and 2 for the end.
!
integer(ik) :: swap_size = 0 ! the number of vectors to keep in memory
character(cl) :: swap = "NONE" ! whether save the compacted vectors or read
character(cl) :: swap_file ="compress" ! where swap the compacted eigenvectors to
integer(ik) :: int_increm = 1e9 ! used to print out the lower energies needed to select int_increm intensities
real(rk) :: factor = 1.0d0 ! factor <1 to be applied the maxsize of the vector adn thus to be shrunk
real(rk) :: wallclock ! wallclock limit, needed to estmate how many transitions can be processed within one job
logical :: reduced ! process intensity in a reduced symmetry adapted approach, only the (1,2) degenerate component
logical :: pruning = .false. ! for the TM-based basis set pruning compute and store the max vib. intensity for each state
logical :: output_short = .false. ! Long output is with all quantum numbers and energies; short is with indeces, energies and A-coef-s only
logical :: tdm_replace = .false. ! Replace vibrational trandipole moments with experimental values
!
! variables used in extfield module
integer(ik) :: tens_rank = 1
integer(ik) :: tens_ialpha = 3
integer(ik) :: tens_ibeta = 3
character(cl) :: tens_oper = 'NA'
integer(ik) :: tens_oper_ielem = 1
character(cl) :: tens_frame = 'NA'
integer(ik) :: tens_ibatch = 1
real(rk) :: tens_omega
!
integer(ik) :: nvib_quanta_upp = 0
integer(ik) :: nvib_quanta_low = 0
integer(ik) :: vib_quanta_upp(20,1000)
integer(ik) :: vib_quanta_low(20,1000)
!
end type MLIntensityT
type(MLIntensityT),save :: intensity
!
integer(ik) :: manifold
contains
!
! The procedure defines for a given molecule
! the equilibrium geometry, potential function, masses, and something else.
! In fact it redirects the execution to the case related subroutine
!
subroutine MLinitialize_molec(Moltype,Coordinates,coords_transform,&
Nbonds,Nangles,Ndihedrals,dihedtype_,&
AtomMasses,local_eq, &
force_,forcename_,ifit_,pot_ind_,specparam,potentype,kinetic_type,&
symmetry_,rho_border,zmatrix_)
character(len=cl),intent(in) :: Moltype
character(len=cl),intent(in) :: Coordinates(:,:)
character(len=cl),intent(in) :: coords_transform ! coordinate transformation type
integer(ik), intent(in) :: Nbonds,Nangles,Ndihedrals
integer(ik), intent(in) :: dihedtype_(0:Ndihedrals)
real(ark), intent(in) :: AtomMasses(:)
real(ark), intent(in) :: local_eq(:)
!
real(ark),intent(in) :: force_(:)
integer(ik),intent(in) :: ifit_(:) ! indexes contrilloing fit
integer(ik),intent(in) :: pot_ind_(:,:) ! indexes with the powers for every expansion term
character(len=16),intent(in) :: forcename_(:)
real(ark), intent(in) :: specparam(:)
!
character(len=cl),intent(in) :: potentype,kinetic_type
character(len=cl),intent(in) :: symmetry_
real(ark) :: rho_border(2) ! rhomim, rhomax - borders
type(MLZmatrixT),intent(in) :: zmatrix_(:) !
!
integer(ik) :: alloc,Ncoords
!
if (verbose>=4) write(out,"(/'MLinitialize_molec/start: molecular and potential parameters')")
!
molec%moltype = Moltype
molec%coords_transform = coords_transform
!
molec%Natoms = size(AtomMasses)
molec%Ndihedrals = Ndihedrals
molec%Nmodes = size(Coordinates,dim=2)
molec%Nbonds = Nbonds
molec%Nangles = Nangles
!
Ncoords = Nbonds+Nangles+Ndihedrals
molec%Ncoords = Ncoords
!
molec%parmax = size(force_)
!
allocate (molec%force(molec%parmax),molec%forcename(molec%parmax),&
molec%ifit(molec%parmax),molec%pot_ind(1:Ncoords,molec%parmax),stat=alloc)
if (alloc/=0) then
write (out,"(' Error ',i8,' allocating matix force ')") alloc
stop 'MLforce_and_geometry - cannot allocate force'
end if
!
allocate (molec%coordinates(3,molec%Nmodes),molec%specparam(Ncoords),molec%AtomMasses(molec%Natoms),molec%req(Nbonds),&
molec%alphaeq(Nangles),molec%taueq(Ndihedrals),molec%local_eq(Ncoords),&
molec%dihedtype(0:Ndihedrals),stat=alloc)
if (alloc/=0) then
write (out,"(' Error ',i8,' allocating matixes for masses, reqs, or alphaeq-s ')") alloc
stop 'MLforce_and_geometry - cannot allocate masses, reqs, or alphaeq-s'
end if
!
allocate (molec%zmatrix(molec%Natoms),stat=alloc)
if (alloc/=0) then
write (out,"(' Error ',i8,' allocating matix zmatrix ')") alloc
stop 'MLforce_and_geometry - cannot allocate zmatrix'
end if
!
molec%zmatrix(1:molec%Natoms) = zmatrix_(1:molec%Natoms)
!
molec%force = force_
molec%forcename = forcename_
molec%pot_ind = pot_ind_
molec%ifit = ifit_
!
! store equilibrium parameters
!
molec%req(1:Nbonds) = local_eq(1:Nbonds)
molec%alphaeq(1:Nangles) = local_eq(Nbonds+1:Nbonds+Nangles)
molec%taueq(1:Ndihedrals) = local_eq(Nbonds+Nangles+1:Ncoords)
!
molec%local_eq = local_eq
molec%potentype = potentype
molec%kinetic_type = kinetic_type
molec%atomMasses = AtomMasses
molec%specparam = specparam
molec%dihedtype = dihedtype_
molec%symmetry = symmetry_
!
!molec%potenfunc => MLpoten_xy2_morbid
!
! Store the molecular structure parameters
!
molec%coordinates(1,:) = Coordinates(1,:)
molec%coordinates(2,:) = Coordinates(2,:)
molec%coordinates(3,:) = Coordinates(3,:)
!
! define the integration borders for each mode
!
molec%rho_border(:) = rho_border(:)
!
!call xy2_initialize(xy2)
!
if (verbose>=4) write(out,"('MLinitialize_molec/end')")
end subroutine MLinitialize_molec
!
! Here we define chi_eq -
! equilibrium values of the internal coordinates chi
!
subroutine MLequilibrium_chi(chi_eq)
real(ark),intent(in) :: chi_eq(:) ! Equilibrium values for the internal coordinates chi
integer(ik) :: alloc
if (verbose>=5) write(out,"(/'MLequilibrium_chi/start: chi_eq')")
allocate (molec%chi_eq(size(chi_eq)),stat=alloc)
!
molec%chi_eq = chi_eq
!
if (verbose>=5) write(out,"('MLequilibrium_chi/end')")
end subroutine MLequilibrium_chi
subroutine MLorienting_a0(Natoms,AtomMasses,a0,transform,method)
integer(ik),intent(in) :: Natoms
real(ark), intent(in) :: AtomMasses(Natoms)
real(ark), intent(inout) :: a0(Natoms,3)
real(ark), intent(out),optional :: transform(3,3)
character(cl),optional :: method
!
real(ark) :: a0_t(Natoms,3)
real(ark) :: CM_shift
integer(ik) :: ix,jx,imx
!
real(ark) :: b(3,1),a(3,3),c(3,3),a_t,c_t(3),Inert(3)
real(rk) :: a_rk(Natoms,3),b_rk(3,1)
if (verbose>=5) write(out,"(/'MLorienting_a0/start')")
!
! Find center of mass
!
do ix = 1,3
CM_shift = sum(a0(:,ix)*AtomMasses(:))/sum(AtomMasses(:))
a0(:,ix) = a0(:,ix) - CM_shift
enddo
!
Inert(1) = sum(AtomMasses(:)*( a0(:,2)**2+ a0(:,3)**2) )
Inert(2) = sum(AtomMasses(:)*( a0(:,1)**2+ a0(:,3)**2) )
Inert(3) = sum(AtomMasses(:)*( a0(:,1)**2+ a0(:,2)**2) )
!
! First Eckart equation
!
do ix = 1,3
!
a_t = sum(AtomMasses(:)*a0(:,ix))
if (abs(a_t)>10.0_rk**(-rk)) then
write(out,"('MLorienting_a0: a0 is not a solution of Eckart 1 for ix =',i4,d18.8)") ix,a_t
stop 'MLorienting_a0: a0 is not solution of Eckart1'
endif
!
enddo
!
! Second Eckart equation
!
a = 0
do ix = 1,3
!
a(ix,ix) = Inert(ix)
!
do jx = 1,3
if (ix/=jx) a(ix,jx) =-sum(AtomMasses(:)*a0(:,ix)*a0(:,jx) )
enddo
!
enddo
!
!a = real(a,kind=rk)
!
if (present(method)) then
!
select case (trim(method))
!
case('LAPACK')
!
a_rk = a
!
call lapack_syev(a_rk,b_rk(:,1))
!
c = a_rk
!
case('ULEN')
!
call MLdiag_ulen_ark(3,a,b(:,1),c)
!
case default
write (out,"('MLorienting_a0: method ',a,' unknown')") trim(method)
stop 'MLorienting_a0: method unknown'
!
end select
!
else
!
call MLdiag_ulen_ark(3,a,b(:,1),c)
!
endif
!
!
!
!c = a
!
!do ix=1,2
! do jx=ix,3
! !
! if (abs(a(ix,ix))<abs(a(jx,ix))) then
! !
! a(:,ix) = c(:,jx)
! a(:,jx) = c(:,ix)
! !
! endif
! !
! enddo
!enddo
!
!c_t(:) = a(:,1)
!a(:,1) = a(:,3)
!a(:,3) = c_t(:)
!!
!do ix=1,3
! !
! if (a(ix,ix)<0.0_rk) a(:,ix) = -a(:,ix)
! !
!enddo
!
! Found coordinate transformation "c"
!
!c = real(a,kind=rk)
!
! Transformation of a0
!
do ix = 1,Natoms
a0_t(ix,:) = matmul(transpose(c),a0(ix,:))
enddo
!
Inert(1) = sum(AtomMasses(:)*( a0_t(:,2)**2+ a0_t(:,3)**2) )
Inert(2) = sum(AtomMasses(:)*( a0_t(:,1)**2+ a0_t(:,3)**2) )
Inert(3) = sum(AtomMasses(:)*( a0_t(:,1)**2+ a0_t(:,2)**2) )
!
imx = minloc(Inert(:),dim=1)
!
!c_t(:) = c(imx,:) ; c(imx,:) = c(3,:) ; c(3,:) = c_t(:)
!c_t(:) = c(imn,:) ; c(imn,:) = c(1,:) ; c(1,:) = c_t(:)
!
!c_t(:) = c(:,imx) ; c(:,imx) = c(:,3) ; c(:,3) = c_t(:)
!
!do ix = 1,Natoms
! a0_t(ix,:) = matmul(transpose(c),a0(ix,:))
!enddo
!
!Inert(1) = sum(AtomMasses(:)*( a0_t(:,2)**2+ a0_t(:,3)**2) )
!Inert(2) = sum(AtomMasses(:)*( a0_t(:,1)**2+ a0_t(:,3)**2) )
!Inert(3) = sum(AtomMasses(:)*( a0_t(:,1)**2+ a0_t(:,2)**2) )
!
!imn = minloc(Inert(:),dim=1)
!c_t(:) = c(:,imn) ; c(:,imn) = c(:,1) ; c(:,1) = c_t(:)
!
do ix = 1,Natoms
a0(ix,:) = matmul(transpose(c),a0(ix,:))
enddo
!
Inert(1) = sum(AtomMasses(:)*( a0(:,2)**2+ a0(:,3)**2) )
Inert(2) = sum(AtomMasses(:)*( a0(:,1)**2+ a0(:,3)**2) )
Inert(3) = sum(AtomMasses(:)*( a0(:,1)**2+ a0(:,2)**2) )
!
if (verbose>=6) then
write(out,"('i0',3f12.8)") Inert(1:3)
endif
!
! Second Eckart equation
!
do ix = 1,3
do jx = 1,3
if (ix/=jx) then
a_t = sum(AtomMasses(:)*a0(:,ix)*a0(:,jx) )
if (abs(a_t)>1000.0_rk*small_) then
write(out,"('MLorienting_a0: a0 is not a solution of Eckart 2 for ix,jx =',2i4,d18.8)") ix,jx,a_t
stop 'MLorienting_a0: a0 is not solution of Eckart2'
endif
endif
enddo
!
enddo
!
! we might need the transformation matrix out there
!
if (present(transform)) then
transform = c
endif
!
if (verbose>=5) write(out,"('MLorienting_a0/stop')")
end subroutine MLorienting_a0
!
subroutine MLorienting_a0_across_dadrho(Natoms,npoints,AtomMasses,arho_borders,a0,da0,periodic,lincoord,method,transform)
integer(ik),intent(in) :: Natoms,npoints
real(ark), intent(in) :: AtomMasses(Natoms)
real(ark), intent(in) :: arho_borders(2) ! rhomim, rhomax - borders
real(ark), intent(inout) :: a0(Natoms,3,0:npoints),da0(Natoms,3,0:npoints)
logical ,intent(in) :: periodic
real(ark), intent(out),optional :: transform(3,3)
character(cl),optional :: method
integer(ik),optional :: lincoord
!
real(ark) :: CM_shift,Eq(3),A(3,3),A1(3,3),A2(3,3),C1(3,3),C2(3,3),b1(3),b2(3),S(3,3),T(3,3)
real(ark) :: b0(Natoms,3,0:npoints),db0(Natoms,3,0:npoints)
real(rk) :: a_rk(3,3),b_rk(3,1)
integer(ik) :: ix,jx,jy,imx,ipoint,i,ieq,jatom,ilincoord=0
!
if (verbose>=5) write(out,"(/'MLorienting_a0_across_dadrho/start')")
!
if (present(lincoord)) ilincoord = lincoord
!
! Find center of mass
!
do ipoint = 0,npoints
!
do ix = 1,3
CM_shift = sum(a0(:,ix,ipoint)*AtomMasses(:))/sum(AtomMasses(:))
a0(:,ix,ipoint) = a0(:,ix,ipoint) - CM_shift
enddo
!
enddo
!
do ipoint = 0,npoints
!
ieq = 0
do ix = 1,3
!
if (ix/=ilincoord) then
!
ieq = ieq+1
!
Eq(ieq) = 0
do jatom = 1,Natoms
do jx = 1,3
do jy = 1,3
!
Eq(ieq) = Eq(ieq) + AtomMasses(jatom)*epsil(ix,jx,jy)*a0(jatom,jx,ipoint)*da0(jatom,jy,ipoint)
!
enddo
enddo
enddo
!
endif
!
enddo
!
do jx = 1,3
do jy = 1,3
!
A(jx,jy) = sum(AtomMasses(:)*a0(:,jx,ipoint)*da0(:,jy,ipoint))
!
enddo
enddo
!
A1 = matmul(A,transpose(A))
A2 = matmul(transpose(A),A)
!
call MLdiag_ulen_ark(3,A1,b1,C1)
call MLdiag_ulen_ark(3,A2,b2,C2)
!
a_rk = A1
call lapack_syev(a_rk,b_rk(:,1))
C1 = a_rk
!
a_rk = A2
call lapack_syev(a_rk,b_rk(:,1))
C2 = a_rk
!
T = matmul(C2,transpose(C1))
!
A1 = matmul(S,transpose(S))
A2 = matmul(transpose(S),S)
!
do jatom = 1,Natoms
!
b0 (jatom,:,ipoint) = matmul(T, a0(jatom,:,ipoint))
db0(jatom,:,ipoint) = matmul(T,da0(jatom,:,ipoint))
!
enddo
!
ieq = 0
Eq = 0
do ix = 1,3
!
if (ix/=ilincoord) then
!
ieq = ieq+1
!
Eq(ieq) = 0
do jatom = 1,Natoms
do jx = 1,3
do jy = 1,3
!
Eq(ieq) = Eq(ieq) + AtomMasses(jatom)*epsil(ix,jx,jy)*b0(jatom,jx,ipoint)*db0(jatom,jy,ipoint)
!
enddo
enddo
enddo
!
endif
!
enddo
!
do jatom = 1,Natoms
!
b0 (jatom,:,ipoint) = matmul(a0 (jatom,:,ipoint),T)
db0(jatom,:,ipoint) = matmul(da0(jatom,:,ipoint),T)
!
enddo
!
ieq = 0
Eq = 0
do ix = 1,3
!
if (ix/=ilincoord) then
!
ieq = ieq+1
!
Eq(ieq) = 0
do jatom = 1,Natoms
do jx = 1,3
do jy = 1,3
!
Eq(ieq) = Eq(ieq) + AtomMasses(jatom)*epsil(ix,jx,jy)*b0(jatom,jx,ipoint)*db0(jatom,jy,ipoint)
!
enddo
enddo
enddo
!
endif
!
enddo
!
S = matmul(T,A)
!
T = matmul(C1,transpose(C2))
!
S = matmul(A,T)
!
continue
!
enddo
!
if (present(transform)) then
!transform = c
transform = 0
endif
!
if (verbose>=5) write(out,"('MLorienting_a0_across_dadrho/stop')")
end subroutine MLorienting_a0_across_dadrho
!
! 6-dim rotations: (123),(312),(12)*,(23)*,(13)*
!
function ML_sym_rotat(ioper,a) result (f)
integer(ik) :: ioper
real(ark),intent(in) :: a(3,3)
real(ark),dimension(3,3) :: f
select case(ioper)
!
case (1)
!
f = a
!
case (2)
!
f = cshift(a,1,1)
!
case (3)
!
f = cshift(a,2,1)
!
case (4)
!
f(1,:) = a(1,:) ; f(2,:) = a(3,:) ; f(3,:) = a(2,:) ; f = transpose(f)
!
case (5)
!
f(1,:) = a(3,:) ; f(2,:) = a(2,:) ; f(3,:) = a(1,:) ; f = transpose(f)
!
case (6)
!
f(1,:) = a(2,:) ; f(2,:) = a(1,:) ; f(3,:) = a(3,:) ; f = transpose(f)
!
end select
end function ML_sym_rotat
subroutine ML_check_steps(xi,itype,imode,fstep)
real(ark),intent(in) :: xi(1:molec%Nmodes)
integer(ik),intent(in) :: itype,imode
real(ark),intent(out) :: fstep(2)
real(ark) :: rhoe
if (verbose>=6) write(out,"(/'ML_check_steps/start')")
!
fstep(1:2) = 1.0_ark
!
select case(trim(molec%coordinates(itype,imode)))
case default
write (out,"('ML_check_steps: coordinate type ',a,' unknown')") trim(molec%coordinates(itype,imode))
stop 'ML_check_steps - bad coordinate-type'
case('MORSE')
!
fstep(1:2) = 1.0_ark
!
case('HARMONIC','NORMAL','LINEAR','SAME','X-XE')
!
fstep(1:2) = 1.0_ark
!
case('COSRHO')
!
rhoe = molec%chi_eq(imode)
!
if (abs( cos(rhoe)-xi(imode)-1.0_ark )<small_) then
!
fstep(2) = 0.0_ark
!
endif
if (abs( cos(rhoe)-xi(imode)+1.0_ark )<small_) then
!
fstep(1) = 0.0_ark
!
endif
!
case('COSTAU')
!
if (abs( xi(imode)-1.0_ark )>small_) then
!
fstep(2) = 0.0_ark
!
endif
if (abs( xi(imode)+1.0_ark )<small_) then
!
fstep(1) = 0.0_ark
!
endif
!
case('COSTAU2')
!
if (abs( xi(imode) )<small_) then
!
fstep(1) = 0.0_ark
!
endif
if (abs( xi(imode)**2-1.0_ark )<small_) then
!
fstep(2) = 0.0_ark
!
endif
!
case('SINRHO')
!
rhoe = molec%chi_eq(imode)
!
if (abs( sin(rhoe)-xi(imode)-1.0_ark )>small_) then
!
fstep(2) = 0.0_ark
!
endif
if (abs( sin(rhoe)-xi(imode)+1.0_ark )<small_) then
!
fstep(1) = 0.0_ark
!
endif
!
case('LINCOSRHO')
!
rhoe = molec%chi_eq(imode)
!
if (abs( cos(rhoe)-xi(imode)-1.0_ark )>small_) then
!
fstep(2) = 0.0_ark
!
endif
if (abs( cos(rhoe)-xi(imode)+1.0_ark )<small_) then
!
fstep(1) = 0.0_ark
!
endif
!
case('LINSINRHO')
!
rhoe = molec%chi_eq(imode)
!
if (abs( sin(rhoe)-xi(imode)-1.0_ark )>small_) then
!
fstep(2) = 0.0_ark
!
endif
if (abs( sin(rhoe)-xi(imode)+1.0_ark )<small_) then
!
fstep(1) = 0.0_ark
!
endif
!
!
case('COSX','SINX')
!
if (xi(imode)-1.0_ark < small_) then
!
fstep(2) = 0.0_ark
!
endif
if (xi(imode)+1.0_ark < small_) then
!
fstep(1) = 0.0_ark
!
endif
!
case('1-COSX')
!
if (abs( xi(imode) )<small_) then
!
fstep(1) = 0.0_ark
!
endif
if (abs( xi(imode) )>small_) then
!
fstep(2) = 0.0_ark
!
endif
!
end select
!
if (fstep(1)+fstep(2)==0.0_ark) then
write (out,"('ML_check_steps: no numerical derivatives allowed around point ',f18.8)") xi(imode)
write (out,"('imode - ',i8)") imode
stop 'ML_check_steps - bad point for derivatives'
endif
if (verbose>=6) write(out,"('ML_check_steps/end')")
end subroutine ML_check_steps
subroutine MLfromlocal2cartesian(pm,r,cartesian)
integer(ik),intent(in) :: pm
real(ark),intent(in) :: r(molec%Ncoords)
real(ark),intent(out) :: cartesian(molec%Natoms,3)
real(ark) :: x(molec%Natoms,3)
real(ark) :: n1(3),n2(3),n3(3)
!
real(ark) :: rot(3,3),CM_shift
real(ark) :: alpha,phi,v12(3),v23(3),f_t,beta,alpha3,cosa3,cosphi
!
real(ark) :: rbond
!
integer(ik) :: iangle,idihedral,iatom,j
integer(ik) :: p0,p1,p2,p3,p4,ix,kappa(3),idelta,ikappa,zeta
character(len=cl) :: txt = 'MLfromlocal2cartesian'
!
if (verbose>=6) write(out,"(/'MLfromlocal2cartesian/start')")
!
if (abs(pm)/=1) then
!
write(out,"(/'MLfromlocal2cartesian: illegal pm, not 1,-1: ',i8)") pm
stop 'illegal pm'
!
endif
!
! cartesian coordinates
!
x = 0
!
! #1 - at the reference coordinate of atom #1
!
x(1,:) = 0
!
! #2 - on the vector between refernce atoms 1 and 2
!
n1(:) = (/0.0_ark,0.0_ark,1.0_ark/)
!
x(2,:) = x(1,:)+n1(:)*r(1)
!
iangle = 1
idihedral = 0
!
if (molec%NAtoms>2) then
!
iatom = 3
!
J = molec%zmatrix(iatom)%connect(4)
!
select case (J)