-
Notifications
You must be signed in to change notification settings - Fork 1
/
symmol.f90
2956 lines (2564 loc) · 78.7 KB
/
symmol.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
! /*******************************************************************************
!
! Copyright (C) 2011 Andrew Gilbert
!
! This file is part of IQmol, a free molecular visualization program. See
! <http://iqmol.org> for more details.
!
! IQmol is free software: you can redistribute it and/or modify it under the
! terms of the GNU General Public License as published by the Free Software
! Foundation, either version 3 of the License, or (at your option) any later
! version.
!
! IQmol is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
! details.
!
! You should have received a copy of the GNU General Public License along
! with IQmol. If not, see <http://www.gnu.org/licenses/>.
!
! ********************************************************************************/
! SYMMOL
! A PROGRAM FOR THE SYMMETRIZATION OF GROUPS OF ATOMS
! By Tullio Pilati and Alessandra Forni
! Version November 4th 2002
!
! This version modified and converted to f90 by Andrew Gilbert 2011
! -----------------------------------------------------------------
! PROGRAM Main
! -----------------------------------------------------------------
! IMPLICIT DOUBLE PRECISION (a-h,o-z)
! PARAMETER (NMA = 300)
! DIMENSION coordinates(3,NMA)
! INTEGER atomicNumbers(NMA)
! CHARACTER*3 pointGroup
!
! READ(*,*) nAtoms
! IF (nAtoms .gt. NMA) STOP 'Too many atoms in Symmol'
! READ(*,*) tolerance
! DO i = 1,nAtoms
! READ (*,*) atomicNumbers(i), (coordinates(k,i), k=1,3)
! IF (atomicNumbers(i) .gt. 103) STOP 'Z too high in SymMol'
! ENDDO
! CALL SymMol(nAtoms, Tolerance, Coordinates, atomicNumbers, pointgroup)
! END
! -----------------------------------------------------------------
MODULE GlobalArrays
! -----------------------------------------------------------------
INTEGER :: natoms
INTEGER :: nmg, nma, nmv
PARAMETER (nmg = 120)
PARAMETER (nma = 1000)
PARAMETER (nmv = nma*nmg)
REAL*8, DIMENSION (:,:), ALLOCATABLE :: X
REAL*8, DIMENSION (:), ALLOCATABLE :: AMAS
REAL*8, DIMENSION (:), ALLOCATABLE :: MSP
REAL*8, DIMENSION (:,:), ALLOCATABLE :: SX
REAL*8, DIMENSION (:), ALLOCATABLE :: SIG
REAL*8, DIMENSION (:), ALLOCATABLE :: DXM
REAL*8, DIMENSION (:), ALLOCATABLE :: MLG
REAL*8 :: PC(7), PCR(7), O(3,3), OI(3,3), G(3,3), GI(3,3), CS(12)
REAL*8 :: OR(3,3), OT(3,3), OTI(3,3), BARC(3), BARO(3), RIN(3)
! SIMME
REAL*8, DIMENSION (:,:,:), ALLOCATABLE :: SIM
REAL*8, DIMENSION (:), ALLOCATABLE :: DEV
REAL*8, DIMENSION (:), ALLOCATABLE :: CSM
REAL*8, DIMENSION (:,:), ALLOCATABLE :: MTG
REAL*8 :: CSMT
INTEGER :: NMS
! SIMME1
REAL*8, DIMENSION (:,:), ALLOCATABLE :: RMS
REAL*8 :: RMST
! RMSMIN
REAL*8, DIMENSION (:,:), ALLOCATABLE :: ppu
REAL*8, DIMENSION (:,:), ALLOCATABLE :: ppo
REAL*8 :: RV(3,3)
INTEGER :: npu
! AT2
REAL*8 :: DCM, DCME
INTEGER :: indwgh, indtol
END MODULE
! -----------------------------------------------------------------
SUBROUTINE SymMol(nat, Tolerance, coordinates, atomicNumbers, pointGroup)
! -----------------------------------------------------------------
USE GlobalArrays
integer, intent(in) :: nat
real(8), intent(inout) :: Tolerance
real(8), dimension(3,nat), intent(inout) :: coordinates
integer, dimension(nat), intent(in) :: atomicNumbers
character(len=3), intent(out) :: pointGroup
natoms = nat
ALLOCATE (X(3, natoms))
ALLOCATE (AMAS(natoms))
ALLOCATE (MSP(natoms))
ALLOCATE (SX(3,natoms))
ALLOCATE (SIG(natoms))
ALLOCATE (DXM(natoms))
ALLOCATE (MLG(natoms))
ALLOCATE (SIM(3, 4, nmg))
ALLOCATE (DEV(nmg))
ALLOCATE (CSM(nmg))
ALLOCATE (MTG(nmg, nmg))
ALLOCATE (RMS(3,nma))
ALLOCATE (PPU(3,nmv))
ALLOCATE (PPO(3,nmv))
WRITE(*,*)' SYMMOL'
WRITE(*,*)' A PROGRAM FOR THE SYMMETRIZATION OF GROUPS OF ATOMS'
WRITE(*,*)' By Tullio Pilati and Alessandra Forni'
WRITE(*,*)' Version November 4th 2002'
! Hard-wired cell parameters
PC(1) = 1.0d0
PC(2) = 1.0d0
PC(3) = 1.0d0
PC(4) = 90.0d0
PC(5) = 90.0d0
PC(6) = 90.0d0
pointGroup = 'C1 '
! Only use weights based on atomic masses
indwgh = 1
! Use a constant tolerance (2 => distance based)
indtol = 1
DCM = Tolerance
DCME = DCM
! Subsequent lines are all atomic coordinates
DO i = 1,nAtoms
X(1,i) = coordinates(1,i)
X(2,i) = coordinates(2,i)
X(3,i) = coordinates(3,i)
ENDDO
NA = NAtoms
CALL massdata(atomicNumbers)
CALL cella
CALl work(Coordinates, pointGroup)
WRITE(*,10) Tolerance
10 FORMAT ('Symmetrized Orthogonal Coordinates Tol = ', F6.3)
! DO i = 1,nAtoms
! WRITE(20,'(i2, 3(f16.10))') atomicNumbers(i), (Coordinates(k,I),k=1,3)
! ENDDO
WRITE(*,*) 'pointGroup ', pointGroup
DEALLOCATE (X, AMAS, MSP, SX, SIG, DXM, MLG)
DEALLOCATE (SIM, DEV, CSM, MTG, RMS, PPU, PPO)
END
! ------------------------------------------------------------------
SUBROUTINE asymunit(MK,IASU,N)
! ------------------------------------------------------------------
USE GlobalArrays
DIMENSION MK(NMA,NMG), IASU(NMA)
DO i = 1,N
IASU(I) = 2
ENDDO
DO 2800 i = 1,N
if (IASU(i) .ne. 2) GOTO 2800
DO J = 1,NMS
K = IABS(MK(I,J))
IF (K.ne.I) THEN
IF (K.eq.0) THEN
IASU(I) = 0
GOTO 2800
ENDIF
IASU(K)=1
ENDIF
ENDDO
2800 CONTINUE
RETURN
END
SUBROUTINE ax_order(A,i,m,msign,invers)
!
! m = group order for the matrix SIM(i)
! msign = 1 asse di rotazione propria
! msign =-1 asse di rotazione impropria
!
PARAMETER (maxorder=8)
IMPLICIT DOUBLE PRECISION (a-h,o-z)
DIMENSION A(3,3,*), B(3,3), C(3,3,2)
CALL vrload(C,0.d0,18)
C(1,1,1) = 1.d0
C(2,2,1) = 1.d0
C(3,3,1) = 1.d0
C(1,1,2) = -1.d0
C(2,2,2) = -1.d0
C(3,3,2) = -1.d0
invers = 2
msign = NINT(det(A,i))
CALL prodmm(A,C,B,i,1,1)
DO m = 1,2*maxorder
IF (ium(C,B,1.d-2,2,1).eq.1) invers = 1
IF (ium(C,B,1.d-2,1,1).eq.1) GOTO 1000
CALL prodmm(A,B,B,i,1,1)
ENDDO
write(*,*)'INPUT PARAMETER DCM probably too HIGH. Reduce it!'
stop
1000 IF (m.lt.6.or.msign.eq.1) RETURN
m1 = (m/4)*4
if (m1.ne.m) m = m/invers
RETURN
END
! -----------------------------------------------------------------
SUBROUTINE vrload(A, const, N)
! -----------------------------------------------------------------
IMPLICIT DOUBLE PRECISION (a-h,o-z)
DIMENSION A(N)
DO I = 1,N
A(I) = const
ENDDO
RETURN
END
SUBROUTINE cella
USE GlobalArrays
IMPLICIT DOUBLE PRECISION (a-h,o-z)
RAD = 57.29577951308232D0
ARAD = 1.D0/RAD
PC(7) = 1.D0
PCR(7) = 1.D0
COM = 1.D0
DO 1030 I = 1,3
K=I+3
CS(I) = COS(PC(K)*ARAD)
CS(K) = SIN(PC(K)*ARAD)
IF(PC(K).GT.0.D0) GOTO 1030
PC(K) = 90.D0
CS(I) = 0.D0
CS(K) = 1.D0
1030 COM = COM-CS(I)*CS(I)
COM = SQRT(COM+2.D0*CS(1)*CS(2)*CS(3))
O(1,1) = PC(1)*CS(6)
O(1,2) = 0.D0
O(1,3) = PC(3)*(CS(2)-CS(1)*CS(3))/CS(6)
O(2,1) = PC(1)*CS(3)
O(2,2) = PC(2)
O(2,3) = PC(3)*CS(1)
O(3,1) = 0.D0
O(3,2) = 0.D0
O(3,3) = PC(3)*COM/CS(6)
IF (ABS(O(2,1)).LT.1.D-10) O(2,1) = 0.D0
IF (ABS(O(2,3)).LT.1.D-10) O(2,3) = 0.D0
IF (ABS(O(1,3)).LT.1.D-10) O(1,3) = 0.D0
PC(7) = det(O,1)
CALL TransposeMatrix(O,G,1,1)
CALL prodmm(G,O,G,1,1,1)
CALL Invert3x3(O,OI,1,1)
PCR(7) = det(OI,1)
CALL Invert3x3(G,GI,1,1)
PCR(1)=SQRT(GI(1,1))
PCR(2)=SQRT(GI(2,2))
PCR(3)=SQRT(GI(3,3))
CS(7)=GI(2,3)/(PCR(2)*PCR(3))
CS(8)=GI(1,3)/(PCR(1)*PCR(3))
CS(9)=GI(1,2)/(PCR(1)*PCR(2))
PCR(4)=RAD*DACOS(CS(7))
PCR(5)=RAD*DACOS(CS(8))
PCR(6)=RAD*DACOS(CS(9))
CS(10)=SIN(ARAD*PCR(4))
CS(11)=SIN(ARAD*PCR(5))
CS(12)=SIN(ARAD*PCR(6))
RETURN
END
! ------------------------------------------------------------------
SUBROUTINE LinearCombination(A,B,C,D,E,I,J,K)
! ------------------------------------------------------------------
IMPLICIT DOUBLE PRECISION (a-h,o-z)
DIMENSION A(3,*), B(3,*), C(3,*)
C(1,K) = A(1,I)*D + B(1,J)*E
C(2,K) = A(2,I)*D + B(2,J)*E
C(3,K) = A(3,I)*D + B(3,J)*E
RETURN
END
SUBROUTINE compatta(WORD,L,K)
IMPLICIT DOUBLE PRECISION (a-h,o-z)
CHARACTER*(*) WORD
K = 0
DO 1 I = 1,L
IF (WORD(I:I) .LE. ' ' .OR. WORD(I:I) .GT. '~') GOTO 1
K = K+1
WORD(K:K) = WORD(I:I)
1 CONTINUE
N = K+1
DO I = N,L
WORD(I:I) = ' '
ENDDO
RETURN
END
! ------------------------------------------------------------------
SUBROUTINE CompleteGroup(MK,N,*)
! ------------------------------------------------------------------
USE GlobalArrays
IMPLICIT DOUBLE PRECISION (a-h,o-z)
DIMENSION CO(3,3), MK(NMA,NMG)
2520 NN = NMS
DO I = 1,NN
DO J = 1,NN
CALL prodmm(SIM,SIM,CO,I,J,1)
DO JJ = 1,NN
L = ium(CO,SIM,1.d-2,1,JJ)
IF(L.EQ.1) GOTO 2590
ENDDO
GOTO 2610
2590 MTG(I,J) = JJ
ENDDO
ENDDO
RETURN
! We have found a new matrix
2610 NMS = NMS+1
IF (NMS.LE.NMG) GOTO 2630
WRITE(6,2)
2 FORMAT(' ERROR: TOO MANY MATRICES FOUND')
WRITE(6,'(3(3F10.5,/),/)') (((SIM(I,J,K),J=1,3),I=1,3),K=1,NMS)
! ritorno per errore
RETURN 1
2630 CALL MatrixCopy(CO,SIM,1,NMS)
DO k = 1,N
k1 = MK(k,J)
MK(k,NMS) = MK(k1,I)
ENDDO
GOTO 2520
END
! ------------------------------------------------------------------
DOUBLE PRECISION FUNCTION crms(t)
! ------------------------------------------------------------------
USE GlobalArrays
IMPLICIT DOUBLE PRECISION (a-h,o-z)
!
! PPU is the vector XO repeated NMS times
! ppo=vettore XS trasformato da MK(NMA,NMS)
! t(3) = vettore variazione angolare in radianti
!
DIMENSION t(3), po(3), pu(3)
DIMENSION RX(3,3), RY(3,3), RZ(3,3), RR(3,3)
call vrload(RX,0.d0,9)
call vrload(RY,0.d0,9)
call vrload(RZ,0.d0,9)
call vrload(RR,0.d0,9)
RX(1,1) = 1.d0
RX(2,2) = dcos(t(1))
RX(2,3) = -dsin(t(1))
RX(3,2) = -RX(2,3)
RX(3,3) = dcos(t(1))
RY(2,2) = 1.d0
RY(1,1) = dcos(t(2))
RY(1,3) = -dsin(t(2))
RY(3,1) = -RY(1,3)
RY(3,3) = dcos(t(2))
RZ(1,1) = dcos(t(3))
RZ(1,2) = -dsin(t(3))
RZ(2,1) = -RZ(1,2)
RZ(2,2) = dcos(t(3))
RZ(3,3) = 1.d0
CALL prodmm(RY,RX,RR,1,1,1)
CALL prodmm(RZ,RR,RV,1,1,1)
! ortonormalizzazione di precisione
call prodv(RV,RV,RV,1,2,3)
call prodv(RV,RV,RV,3,1,2)
call prodv(RV,RV,RV,2,3,1)
call norm(RV,1)
call norm(RV,2)
call norm(RV,3)
! fine ortonormalizzazione di precisione
func=0.d0
DO i=1,npu
po(1) = ppo(1,i)
po(2) = ppo(2,i)
po(3) = ppo(3,i)
pu(1) = ppu(1,i)
pu(2) = ppu(2,i)
pu(3) = ppu(3,i)
CALL prodmv(RV,pu,pu,1,1,1)
func = func+(po(1)-pu(1))**2+(po(2)-pu(2))**2+(po(3)-pu(3))**2
ENDDO
crms = func
return
end
DOUBLE PRECISION FUNCTION Det(X,N)
IMPLICIT NONE
INTEGER N
DOUBLE PRECISION X(3,3,*)
Det = + X(1,1,N)*X(2,2,N)*X(3,3,N) - X(1,1,N)*X(2,3,N)*X(3,2,N)
Det = Det+ X(1,2,N)*X(2,3,N)*X(3,1,N) - X(1,2,N)*X(2,1,N)*X(3,3,N)
Det = Det+ X(1,3,N)*X(2,1,N)*X(3,2,N) - X(1,3,N)*X(2,2,N)*X(3,1,N)
RETURN
END
SUBROUTINE eigen(A,VEC,EIG,W,GAM,BET,BSQ,P,Q,IPO,IORD,IVP,NN)
IMPLICIT DOUBLE PRECISION (a-h,o-z)
!
! --------------
! QCPE VERSION
! DECEMBER 1971
! --------------
!
! MATRIX DIAGNOLIZATION ROUTINE FOR REAL SYMMETRIC CASE
! HOUSEHOLDER METHOD
! RHO=UPPER LIMIT FOR OFF-DIAGONAL ELEMENT
! NN SIZE OF MATRIX
! A=MATRIX (ONLY LOWER TRIANGLE IS USED+THIS IS DESTROYED
! EIG=RETURNED eigenVALUES IN ALGEBRAIC DESCENDING ORDER
! VEC=RETURNED eigenVECTORS IN COLUMNS
!
!
DIMENSION A(NN,NN), VEC(NN,NN), EIG(NN), W(NN), GAM(NN), BET(NN)
DIMENSION BSQ(NN), P(NN), Q(NN), IPO(NN), IORD(NN), IVP(NN)
DATA RHOSQ /1.0D-12/
ADUE=.50D0
ZERO=0.D0
UNO=1.0D0
DUE=2.0D0
N=NN
IF(N)10,550,10
10 N1=N-1
N2=N-2
GAM(1)=A(1,1)
IF(N2) 180,170,20
20 DO 160 NR=1,N2
B=A(NR+1,NR)
S=ZERO
DO 30 I=NR,N2
30 S=S+A(I+2,NR)**2
! PREPARE FOR POSSIBLE BYPASS OF TRANSFORMATION
A(NR+1,NR)=ZERO
IF (S) 150,150,40
40 S=S+B*B
SGN=UNO
IF (B) 50,60,60
50 SGN=-UNO
60 SQRTS=SQRT(S)
D=SGN/(SQRTS+SQRTS)
TEMP=SQRT(ADUE+B*D)
W(NR)=TEMP
A(NR+1,NR)=TEMP
D=D/TEMP
B=-SGN*SQRTS
! D IS FACTOR OF PROPORTIONALITY. NOW COMPUTE AND SAVE W VECTOR.
! EXTRA SINGLY SUBSCRIPTED W VECTOR USED FOR SPEED.
DO 70 I=NR,N2
TEMP=D*A(I+2,NR)
W(I+1)=TEMP
70 A(I+2,NR)=TEMP
! PREMULTIPLY VECTOR W BY MATRIX A TO OBTAIN P VECTOR.
! SIMULTANEOUSLY ACCUMULATE DOT PRODUCT WP,(THE SCALAR K)
WTAW=ZERO
DO 120 I=NR,N1
I1=I+1
SUM=ZERO
DO 80 J=NR,I
80 SUM=SUM+A(I1 ,J+1)*W(J)
IF(N1-I1) 110,90,90
90 DO 100 J=I1,N1
100 SUM=SUM+A(J+1,I1 )*W(J)
110 P(I)=SUM
WWWI=W(I)
120 WTAW=WTAW+SUM*WWWI
! P VECTOR AND SCALAR K NOW STORED. NEXT COMPUTE Q VECTOR
DO 130 I=NR,N1
130 Q(I)=P(I)-WTAW*W(I)
! NOW FORM PAP MATRIX, REQUIRED PART
DO 140 J=NR,N1
QJ=Q(J)
WJ=W(J)
DO 140 I=J,N1
140 A(I+1,J+1)=A(I+1,J+1)-DUE*(W(I)*QJ+WJ*Q(I))
150 BET(NR)=B
BSQ(NR)=B*B
160 GAM(NR+1)=A(NR+1,NR+1)
170 B=A(N,N1)
BET(N1)=B
BSQ(N1)=B*B
GAM(N)=A(N,N)
180 BSQ(N)=ZERO
! ADJOIN AN IDENTIFY MATRIX TO BE POSTMULTIPLIED BY ROTATIONS.
DO 200 I=1,N
DO 190 J=1,N
190 VEC(I,J)=ZERO
200 VEC(I,I)=UNO
M=N
SUM=ZERO
NPAS=1
GO TO 330
210 SUM=SUM+SHIFT
COSA=UNO
G=GAM(1)-SHIFT
PP=G
PPBS=PP*PP+BSQ(1)
PPBR=SQRT(PPBS)
DO 300 J=1,M
COSAP=COSA
IF(PPBS)230,220,230
220 SINA=ZERO
SINA2=ZERO
COSA=UNO
GO TO 270
230 SINA=BET(J)/PPBR
SINA2=BSQ(J)/PPBS
COSA=PP/PPBR
! POSTMULTIPLY IDENTITY BY P-TRANSPOSE MATRIX
NT=J+NPAS
IF(NT-N)250,240,240
240 NT=N
250 DO 260 I=1,NT
TEMP=COSA*VEC(I,J)+SINA*VEC(I,J+1)
VEC(I,J+1)=-SINA*VEC(I,J)+COSA*VEC(I,J+1)
260 VEC(I,J)=TEMP
270 DIA=GAM(J+1)-SHIFT
U=SINA2*(G+DIA)
GAM(J)=G+U
G=DIA-U
PP=DIA*COSA-SINA*COSAP*BET(J)
IF(J-M)290,280,290
280 BET(J)=SINA*PP
BSQ(J)=SINA2*PP*PP
GO TO 310
290 PPBS=PP*PP+BSQ(J+1)
PPBR=SQRT(PPBS)
BET(J)=SINA*PPBR
300 BSQ(J)=SINA2*PPBS
310 GAM(M+1)=G
! TEST FOR CONVERGENCE OF LAST DIAGONAL ELEMENT
NPAS=NPAS+1
IF(BSQ(M)-RHOSQ)320,320,350
320 EIG(M+1)=GAM(M+1)+SUM
330 BET(M)=ZERO
BSQ(M)=ZERO
M=M-1
IF(M)340,380,340
340 IF(BSQ(M)-RHOSQ)320,320,350
! TAKE ROOT OF CORNER 2 BY 2 NEAREST TO LOWER DIAGONAL IN VALUE
! AS ESTIMATE OF eigenVALUE TO USE FOR SHIFT
350 A2=GAM(M+1)
R2=ADUE*A2
R1=ADUE*GAM(M)
R12=R1+R2
DIF=R1-R2
TEMP=SQRT(DIF*DIF+BSQ(M))
R1=R12+TEMP
R2=R12-TEMP
DIF=ABS(A2-R1)-ABS(A2-R2)
IF(DIF)370,360,360
360 SHIFT=R2
GO TO 210
370 SHIFT=R1
GO TO 210
380 EIG(1)=GAM(1)+SUM
! INITIALIZE AUXILIARY TABLES REQUIRED FOR REARRANGING THE VECTORS
DO 390 J=1,N
IPO(J)=J
IVP(J)=J
390 IORD(J)=J
! USE A TRANSPOSITION SORT TO ORDER THE eigenVALUES
M=N
GO TO 430
400 DO 420 J=1,M
IF(EIG(J)-EIG(J+1))410,420,420
410 TEMP=EIG(J)
EIG(J)=EIG(J+1)
EIG(J+1)=TEMP
ITEMP=IORD(J)
IORD(J)=IORD(J+1)
IORD(J+1)=ITEMP
420 CONTINUE
430 M=M-1
IF(M)400,440,400
440 IF(N1)450,490,450
450 DO 480 L=1,N1
NV=IORD(L)
NP=IPO(NV)
IF(NP-L)460,480,460
460 LV=IVP(L)
IVP(NP)=LV
IPO(LV)=NP
DO 470 I=1,N
TEMP=VEC(I,L)
VEC(I,L)=VEC(I,NP)
470 VEC(I,NP)=TEMP
480 CONTINUE
! BACK TRANSFORM THE VECTORS OF THE TRIPLE DIAGONAL MATRIX
490 DO 540 NRR=1,N
K=N1
500 K=K-1
IF(K)540,540,510
510 SUM=ZERO
DO 520 I=K,N1
520 SUM=SUM+VEC(I+1,NRR)*A(I+1,K)
SUM=SUM+SUM
DO 530 I=K,N1
530 VEC(I+1,NRR)=VEC(I+1,NRR)-SUM*A(I+1,K)
GO TO 500
540 CONTINUE
550 RETURN
END
! ------------------------------------------------------------------
SUBROUTINE eq_plane(t,u,v,a)
! ------------------------------------------------------------------
IMPLICIT DOUBLE PRECISION (a-h,o-z)
DIMENSION t(3), u(3), v(3), AA(3,3), DD(3,3), a(4)
! Equazione del piano passante per i punti t,u,v nella forma canonica
! a(1).x+a(2).y+a(3).z+a(4)=0
! con a(1),a(2),a(3)=coseni direttori a(4)=-distanza piano-origine
! vedi International Tables for Crystallography II, p. 43, equaz. 2,3,4, 6
DD(1,1) = t(1)
DD(1,2) = t(2)
DD(1,3) = t(3)
DD(2,1) = u(1)
DD(2,2) = u(2)
DD(2,3) = u(3)
DD(3,1) = v(1)
DD(3,2) = v(2)
DD(3,3) = v(3)
DO i = 1,3
CALL MatrixCopy(DD,AA,1,1)
CALL vrload(AA(1,i),1.d0,3)
a(i)=det(AA,1)
ENDDO
CALL prods(a,a,dist,1,1,2)
a(1) = a(1)/dist
a(2) = a(2)/dist
a(3) = a(3)/dist
a(4) = -det(DD,1)/dist
RETURN
END
! ------------------------------------------------------------------
SUBROUTINE icosahed(XO,PESO,N,MN,MK,MD,II,MDEG,*)
! ------------------------------------------------------------------
USE GlobalArrays
IMPLICIT DOUBLE PRECISION (a-h,o-z)
DIMENSION XO(3,NMA), PESO(NMA), MN(NMA), MK(NMA,NMG), MD(NMA,2)
DIMENSION eqp(4), dp(5), vd(3,5), A(3,3), B(3,3), V(3)
DIMENSION io(5), mp(5)
! LOGICAL ico
REAL*8, DIMENSION (:), ALLOCATABLE :: DA
INTEGER, DIMENSION (:), ALLOCATABLE :: meq
ALLOCATE (da(nma))
ALLOCATE (meq(nma))
RAD = 57.29577951308232D0
DO 2000 I1 = 1,N-4
IF (MD(I1,1).ne.II) GOTO 2000
mp(1) = I1
io(1) = I1
in1 = I1+1
DO 1900 I2=in1,N-3
IF (MD(I1,1).ne.II) GOTO 1900
mp(2) = I2
in2 = I2+1
DO 1800 I3 = in2,N-2
IF (MD(I3,1).ne.II) GOTO 1800
mp(3)=I3
call eq_plane(XO(1,I1),XO(1,I2),XO(1,I3),eqp)
! se il piano e' troppo vicino all'origine viene scartato
if (eqp(4).lt.0.5) GOTO 1800
in3=I3+1
do 1700 I4=in3,N-1
if(MD(I4,1).ne.II) GOTO 1700
mp(4)=I4
d2=eqp(1)*XO(1,I4)+eqp(2)*XO(2,I4)+eqp(3)*XO(3,I4)+eqp(4)
if (DABS(d2).gt.DXM(I4)) GOTO 1700
1300 in4=I4+1
do 1600 I5 = in4,N
if (MD(I5,1).ne.II) GOTO 1600
mp(5)=I5
d2=eqp(1)*XO(1,I5)+eqp(2)*XO(2,I5)+eqp(3)*XO(3,I5)+eqp(4)
if(DABS(d2).gt.DXM(I5))go to 1600
! in mp ci sono i possibili 5 atomi equivalenti rispetto all'asse 5
dmin=100.
dp(1)=dmin
do i=2,5
io(i)=0
dp(i)=0.d0
call LinearCombination(XO,XO,vd,1.d0,-1.d0,I1,mp(i),1)
call prods(vd,vd,dp(i),1,1,2)
if(dp(i).lt.dmin)then
dmin=dp(i)
jj=i
endif
enddo
io(2)=mp(jj)
dp(jj)=100.
dmin=100.
do i=2,5
if(dp(i).lt.dmin.and.io(2).ne.mp(i))then
dmin=dp(i)
kk=i
endif
enddo
io(5)=mp(kk)
do i=2,5
if(mp(i).ne.io(2).and.mp(i).ne.io(5).and.io(3).eq.0)io(3)=mp(i)
if(mp(i).ne.io(2).and.mp(i).ne.io(5).and.mp(i).ne.io(3))jj=mp(i)
enddo
call LinearCombination(XO,XO,vd,1.d0,-1.d0,io(2),io(3),1)
call prods(vd,vd,d1,1,1,1)
call LinearCombination(XO,XO,vd,1.d0,-1.d0,io(2),jj,1)
call prods(vd,vd,d2,1,1,1)
io(4)=jj
if(d2.lt.d1)then
io(4)=io(3)
io(3)=jj
endif
! ora i cinque atomi sono ordinati
! per controllo preliminare prima di passare alla verify, controllo
!he siano uguali ( a meno della tolleranza) le distanze 1-2
dmed=0.
do i=1,5
k=i+1
if(k.gt.5)k=k-5
call LinearCombination(XO,XO,vd,1.d0,-1.d0,io(i),io(k),i)
call prods(vd,vd,dp(i),i,i,2)
dmed=dmed+dp(i)
enddo
dmed=dmed*0.2d0
! write(out,'(a5,5i5)')'io',io
! write(out,'(a5,5f10.5)')'dp',dp
! write(out,'(a5,5f10.5)')'dmed',dmed
call vrload(A,0.d0,9)
do i=1,5
if(DABS(dmed-dp(i)).gt.DXM(i)*.5)go to 1600
! asse C5 come somma dei vertici del pentagono
A(1,3)=A(1,3)+XO(1,io(i))
A(2,3)=A(2,3)+XO(2,io(i))
A(3,3)=A(3,3)+XO(3,io(i))
enddo
! write(out,'(a5,3f10.6)')'A(3)',(A(i,3),i=1,3)
! mette il riferimento in modo che il primo asse 5 coincida con z e che
! il secondo sia nel piano xz
A(1,1) =XO(1,io(1))+XO(1,io(2))-XO(1,io(3))-XO(1,io(4))+XO(1,io(5))
A(2,1) =XO(2,io(1))+XO(2,io(2))-XO(2,io(3))-XO(2,io(4))+XO(2,io(5))
A(3,1) =XO(3,io(1))+XO(3,io(2))-XO(3,io(3))-XO(3,io(4))+XO(3,io(5))
! se la somma dei cinque atomi da' un vettore nullo, cioe' il pentagono
! e' sul cerchio massimo (caso possibile per un gruppo di 30 atomi sugli
! assi C2) passo ad altro pentagono
1400 call norm(A,3)
call norm(A,1)
call prodv(A,A,A,3,1,2)
call norm(A,2)
call prodv(A,A,A,2,3,1)
call TransposeMatrix(A,A,1,1)
! write(out,'(a5,3(/,3f10.6))')'A',((A(i,k),i=1,3),k=1,3)
call RotateFrame(A,XO,N)
!ostruzione dell'asse C5
call vrload(B,0.d0,9)
ROT=72.d0/RAD
CA=COS(ROT)
CB=SIN(ROT)
B(1,1)=CA
B(2,2)=CA
B(1,2)=-CB
B(2,1)=CB
B(3,3)=1.d0
! write(out,'(a5,3(/,3f10.6))')'B',((B(i,k),i=1,3),k=1,3)
! verifica e ottimizza il primo asse 5
call verify(XO,B,MK,MN,MV,N)
! write(out,*)'primo asse C5 MV,NMS',MV,NMS
! write(out,'(30i3)')(MK(ll,NMS),ll=1,N)
if(MV.eq.0)go to 1600
call opt_axis(XO,PESO,V,MK,N,2)
! ottimizza l'sse x con la stessa tecnica precedente
call vrload(A,0.d0,9)
if(V(3).lt.0)then
V(1)=-V(1)
V(2)=-V(2)
V(3)=-V(3)
endif
call VectorCopy(V,A,1,3)
A(1,1)=XO(1,io(1))+XO(1,io(2))-XO(1,io(3))-XO(1,io(4))+XO(1,io(5))
A(2,1)=XO(2,io(1))+XO(2,io(2))-XO(2,io(3))-XO(2,io(4))+XO(2,io(5))
A(3,1)=XO(3,io(1))+XO(3,io(2))-XO(3,io(3))-XO(3,io(4))+XO(3,io(5))
1500 call norm(A,3)
call norm(A,1)
call prodv(A,A,A,3,1,2)
call norm(A,2)
call prodv(A,A,A,2,3,1)
call TransposeMatrix(A,A,1,1)
! write(out,'(a5,3(/,3f10.6))')'A',((A(i,k),i=1,3),k=1,3)
call RotateFrame(A,XO,N)
go to 2010
1600 continue
1700 continue
1800 continue
1900 continue
2000 continue
! uscita normale (non ha trovato nessun asse C5)
IF (NMS.eq.1) THEN
DEALLOCATE (da, meq)
RETURN
ENDIF
!ompleta il gruppo C5. Indispensabile qui!!!
2010 call CompleteGroup(MK,N,*2015)
! scelgo i due pentagoni piu' distanti dall'asse C5 per trovare
! un asse C2. nel caso che gli atomi del sottoset non siano
! tutti indipendenti, postrebbero esserci piu' di cinque atomi
! sul piano parallelo al primo pentagono e quindi devo
! testare tutti i possibili pentagoni
2015 DM=0.d0
do 2020 i=1,N
if(MD(I1,1).ne.II)go to 2020
DA(i)=XO(1,I)**2+XO(2,I)**2
if(DM.gt.DA(i))go to 2020
kk=i
DM=DA(i)
2020 continue
io(1)=kk
dp1=XO(3,kk)
! write(out,*)'io(1),dp1',io(1),dp1
do k=1,4
k1=k+1
io(k1)=MK(io(k),2)
dp1=dp1+XO(3,io(k1))
enddo
dp1=-0.2d0*dp1
! in io(i) ci sono i cinque atomi del primo pentagono
! in meq(i) vanno gli atomi del piano parallelo
me=0
do 2030 i=1,N
com=DABS(dp1-XO(3,i))
if(com.gt.DXM(i))go to 2030
! eliminazione (eventuale) degli atomi del primo piano
do k=1,5
if(i.eq.io(k))go to 2030
enddo
me=me+1
meq(me)=i
2030 continue
! write(out,*)'me,meq',me
! write(out,'(30i4)')(meq(i),i=1,me)
! scelta degli atomi del secondo pentagono
2040 do i=1,me
if(meq(i).ne.0)go to 2050
enddo
! non ci sono assi C2!!!
MDEG=1
DEALLOCATE (da, meq)
RETURN
! i e' il primo atomo del nuovo pentagono
2050 mp(1) = meq(i)
meq(i) = 0
k = 1
! cerca gli altri atomi del secondo penatgono e annulla i relativi meq
DO k = 1,4
k1=k+1
mp(k1) = MK(mp(k),2)
DO l = 1,me
IF (mp(k1).eq.meq(l)) meq(l) = 0
ENDDO
ENDDO
! somma vettori del primo pentagono opportunamente ruotati
! costruzione dell'asse C2 perpendicolare a C5 e parallelo a x
2210 call vrload(A,0.d0,9)
call vrload(vd,0.d0,15)
! write(out,*)'io,mp'
! write(out,'(5i4)')io,mp
do 2250 i=1,5
k=io(i)
do 2220 l=1,NMS
if(MK(k,l).ne.io(1))go to 2220
call prodmv(SIM,XO,vd,l,k,3)
call LinearCombination(vd,vd,vd,1.d0,1.d0,3,1,1)
! write(out,'(a20,i5,3f10.5)')'io(i),vd(1)',io(i),(vd(kk,1),kk=1,3)
go to 2230
2220 continue
2230 k=mp(i)
do 2240 l=1,NMS
if(MK(k,l).ne.mp(1))go to 2240