-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvoronai.f
1142 lines (752 loc) · 33.5 KB
/
voronai.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
********************************************************************************
** FICHE F.35. THE VORONOI CONSTRUCTION IN 2D AND 3D. **
** This FORTRAN code is intended to illustrate points made in the text. **
** To our knowledge it works correctly. However it is the responsibility of **
** the user to test it, if it is to be used in a research application. **
********************************************************************************
C *******************************************************************
C ** TWO SEPARATE PARTS: TWO AND THREE DIMENSIONAL VERSIONS. **
C *******************************************************************
C *******************************************************************
C ** FICHE F.35 - PART A **
C ** THE VORONOI CONSTRUCTION IN 2D. **
C *******************************************************************
PROGRAM VORON2
COMMON / BLOCK1 / RX, RY
C *******************************************************************
C ** CONSTRUCTION OF THE VORONOI POLYGON IN 2D. **
C ** **
C ** THIS PROGRAM TAKES IN A CONFIGURATION IN A SQUARE BOX WITH **
C ** CONVENTIONAL PERIODIC BOUNDARY CONDITIONS AND FOR EACH ATOM **
C ** OBTAINS THE SURROUNDING VORONOI POLYGON, DEFINED AS THAT **
C ** REGION OF SPACE CLOSER TO THE CHOSEN ATOM THAN TO ANY OTHER. **
C ** NEIGHBOURING POLYGONS DEFINE NEIGHBOURING ATOMS. **
C ** THE PROGRAM IS SLOW BUT ESSENTIALLY FOOLPROOF. **
C ** WE USE THE MINIMUM IMAGE CONVENTION AND SET A CUTOFF BEYOND **
C ** WHICH ATOMS ARE ASSUMED NOT TO BE NEIGHBOURS: BOTH OF THESE **
C ** MEASURES ARE DANGEROUS FOR SMALL AND/OR RANDOM SYSTEMS. **
C ** WE DELIBERATELY DO NOT USE PREVIOUSLY-FOUND NEIGHBOURS IN **
C ** CONSTRUCTING NEIGHBOUR LISTS, SO THAT AN INDEPENDENT CHECK **
C ** MAY BE MADE AT THE END. **
C ** HERE WE SIMPLY PRINT OUT THE GEOMETRICAL INFORMATION AT THE **
C ** END. THE OUTPUT IS QUITE LENGTHY. IN PRACTICE, IT WOULD **
C ** PROBABLY BE ANALYZED DIRECTLY WITHOUT PRINTING OUT. **
C ** NB: BEWARE DEGENERATE CONFIGURATIONS, I.E. ONES IN WHICH MORE **
C ** THAN THREE VORONOI DOMAINS SHARE A VERTEX. THE SQUARE LATTICE **
C ** IS AN EXAMPLE. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** INTEGER N NUMBER OF ATOMS **
C ** REAL RX(N),RY(N) POSITIONS **
C ** REAL PX(MAXCAN),PY(MAXCAN) CANDIDATE RELATIVE POSITIONS **
C ** REAL PS(MAXCAN) SQUARED RELATIVE DISTANCES **
C ** INTEGER NVER NUMBER OF VERTICES FOUND **
C ** INTEGER NEDGE NUMBER OF EDGES FOUND **
C ** INTEGER VERTS(MAXCAN) VERTICES FOR EACH CANDIDATE **
C ** = 0 IF NOT A NEIGHBOUR **
C ** = 2 ( 1 EDGE ) IF NEIGHBOUR **
C ** REAL RXVER(MAXVER) VERTEX RELATIVE X-COORD **
C ** REAL RYVER(MAXVER) VERTEX RELATIVE Y-COORD **
C ** INTEGER IVER(MAXVER) ATOMIC INDICES TAGGING **
C ** INTEGER JVER(MAXVER) .. EACH VERTEX OF POLYGON **
C ** **
C ** ROUTINES REFERENCED: **
C ** **
C ** SUBROUTINE READCN ( CNFILE, N, BOX ) **
C ** READS IN CONFIGURATION, NUMBER OF ATOMS, BOX SIZE **
C ** SUBROUTINE SORT ( MAXCAN, PX, PY, PS, TAG, NCAN ) **
C ** SORTS NEIGHBOUR DETAILS INTO ASCENDING DISTANCE ORDER **
C ** SUBROUTINE WORK ( MAXCAN, MAXVER, NCAN, NVER, NEDGE, **
C ** PX, PY, PS, VERTS, RXVER, RYVER, IVER, JVER ) **
C ** CARRIES OUT THE VORONOI CONSTRUCTION **
C *******************************************************************
INTEGER MAXN, MAXCAN, MAXVER
PARAMETER ( MAXN = 108, MAXCAN = 50, MAXVER = 50 )
REAL RX(MAXN), RY(MAXN)
REAL PX(MAXCAN), PY(MAXCAN), PS(MAXCAN)
INTEGER TAG(MAXCAN), VERTS(MAXCAN)
REAL RXVER(MAXVER), RYVER(MAXVER)
INTEGER IVER(MAXVER), JVER(MAXVER)
INTEGER NABLST(MAXVER,MAXN), NNAB(MAXN), INAB, JNAB
INTEGER NCAN, NVER, NCOORD, NEDGE
INTEGER I, J, CAN, VER, N
REAL BOX, BOXINV, RCUT, RCUTSQ, COORD
REAL RXJ, RYJ, RZJ, RXIJ, RYIJ, RZIJ, RIJSQ
CHARACTER CNFILE*30
LOGICAL OK
C *******************************************************************
WRITE(*,'(1H1,'' **** PROGRAM VORON2 **** '')')
WRITE(*,'(//1X,''VORONOI CONSTRUCTION IN 2D '')')
C ** BASIC PARAMETERS **
WRITE(*,'('' ENTER CONFIGURATION FILENAME '')')
READ (*,'(A)') CNFILE
WRITE(*,'('' CONFIGURATION FILENAME '',A)') CNFILE
C ** READCN MUST READ IN INITIAL CONFIGURATION **
CALL READCN ( CNFILE, N, BOX )
WRITE(*,'(1X,I5,''-ATOM CONFIGURATION'')') N
WRITE(*,'('' BOX LENGTH = '',F10.5)') BOX
WRITE(*,'('' ENTER NEIGHBOUR CUTOFF IN SAME UNITS '')')
READ (*,*) RCUT
WRITE(*,'('' NEIGHBOUR CUTOFF = '',F10.5)') RCUT
RCUTSQ = RCUT ** 2
BOXINV = 1.0 / BOX
C ** ZERO ACCUMULATORS **
DO 100 J = 1, N
NNAB(J) = 0
DO 90 INAB = 1, NVER
NABLST(INAB,J) = 0
90 CONTINUE
100 CONTINUE
C *******************************************************************
C ** MAIN LOOP STARTS **
C *******************************************************************
DO 1000 J = 1, N
IF ( MOD ( J, 2 ) .EQ. 0 ) THEN
WRITE(*,'(///1X,''RESULTS FOR ATOM '',I5)') J
ELSE
WRITE(*,'(1H1,''RESULTS FOR ATOM '',I5)') J
ENDIF
RXJ = RX(J)
RYJ = RY(J)
CAN = 0
C ** SELECT CANDIDATES **
DO 500 I = 1, N
IF ( I .NE. J ) THEN
RXIJ = RX(I) - RXJ
RYIJ = RY(I) - RYJ
RXIJ = RXIJ - ANINT ( RXIJ * BOXINV ) * BOX
RYIJ = RYIJ - ANINT ( RYIJ * BOXINV ) * BOX
RIJSQ = RXIJ ** 2 + RYIJ ** 2
IF ( RIJSQ .LT. RCUTSQ ) THEN
CAN = CAN + 1
IF ( CAN .GT. MAXCAN ) THEN
WRITE(*,'('' TOO MANY CANDIDATES '')')
STOP
ENDIF
PX(CAN) = RXIJ
PY(CAN) = RYIJ
PS(CAN) = RIJSQ
TAG(CAN) = I
ENDIF
ENDIF
500 CONTINUE
C ** CANDIDATES HAVE BEEN SELECTED **
NCAN = CAN
C ** SORT INTO INCREASING DISTANCE ORDER **
C ** THIS SHOULD IMPROVE EFFICIENCY **
CALL SORT ( MAXCAN, PX, PY, PS, TAG, NCAN )
C ** PERFORM VORONOI CONSTRUCTION **
CALL WORK ( MAXCAN, MAXVER, NCAN, NVER, NEDGE,
: PX, PY, PS, VERTS,
: RXVER, RYVER, IVER, JVER )
C ** WRITE OUT RESULTS **
WRITE(*,'(/1X,''NUMBER OF NEIGHBOURS '',I5)') NEDGE
WRITE(*,'(/1X,''NEIGHBOUR LIST '')')
WRITE(*,10001)
DO 800 CAN = 1, NCAN
IF ( VERTS(CAN) .NE. 0 ) THEN
PS(CAN) = SQRT ( PS(CAN) )
WRITE(*,'(1X,I5,3X,I5,3X,2F12.5,3X,F12.5)')
: TAG(CAN), VERTS(CAN), PX(CAN), PY(CAN), PS(CAN)
NNAB(J) = NNAB(J) + 1
NABLST(NNAB(J),J) = TAG(CAN)
ENDIF
800 CONTINUE
WRITE(*,'(/1X,''NUMBER OF VERTICES '',I5)') NVER
WRITE(*,'(/1X,''VERTEX LIST '')')
WRITE(*,10002)
DO 900 VER = 1, NVER
WRITE(*,'(1X,2I5,3X,2F12.5)')
: TAG(IVER(VER)), TAG(JVER(VER)),
: RXVER(VER), RYVER(VER)
900 CONTINUE
1000 CONTINUE
C *******************************************************************
C ** MAIN LOOP ENDS **
C *******************************************************************
WRITE(*,'(1H1,''FINAL SUMMARY'')')
WRITE(*,10003)
NCOORD = 0
DO 2000 J = 1, N
NCOORD = NCOORD + NNAB(J)
WRITE(*,'(1X,I5,3X,I5,3X,30I3)') J, NNAB(J),
: ( NABLST(INAB,J), INAB = 1, NNAB(J) )
C ** CHECK THAT IF I IS A NEIGHBOUR OF J **
C ** THEN J IS ALSO A NEIGHBOUR OF I **
DO 1500 INAB = 1, NNAB(J)
I = NABLST(INAB,J)
OK = .FALSE.
JNAB = 0
1200 IF ( ( .NOT. OK ) .AND. ( JNAB .LE. NNAB(I) ) ) THEN
OK = ( J .EQ. NABLST(JNAB,I) )
JNAB = JNAB + 1
GOTO 1200
ENDIF
IF ( .NOT. OK ) THEN
WRITE(*,'(1X,I3,'' IS NOT A NEIGHBOUR OF '',I3)') J, I
ENDIF
1500 CONTINUE
2000 CONTINUE
COORD = REAL ( NCOORD ) / REAL ( N )
WRITE(*,'(/1X,'' AVERAGE COORDINATION NUMBER = '',F10.5)') COORD
STOP
10001 FORMAT(/1X,'ATOM ',3X,'EDGE ',
: /1X,'INDEX',3X,'VERTS',3X,
: ' RELATIVE POSITION ',3X,' DISTANCE ')
10002 FORMAT(/1X,' INDICES RELATIVE POSITION ')
10003 FORMAT(/1X,'INDEX NABS ... NEIGHBOUR INDICES ... ')
END
SUBROUTINE READCN ( CNFILE, N, BOX )
COMMON / BLOCK1 / RX, RY
C *******************************************************************
C ** SUBROUTINE TO READ IN INITIAL CONFIGURATION **
C *******************************************************************
INTEGER MAXN
PARAMETER ( MAXN = 108 )
REAL RX(MAXN), RY(MAXN), BOX
INTEGER N
CHARACTER CNFILE*(*)
INTEGER CNUNIT, I
PARAMETER ( CNUNIT = 10 )
C *******************************************************************
OPEN ( UNIT = CNUNIT, FILE = CNFILE,
: STATUS = 'OLD', FORM = 'UNFORMATTED' )
READ ( CNUNIT ) N, BOX
IF ( N .GT. MAXN ) STOP ' N TOO LARGE '
READ ( CNUNIT ) ( RX(I), I = 1, N ), ( RY(I), I = 1, N )
CLOSE ( UNIT = CNUNIT )
RETURN
END
SUBROUTINE WORK ( MAXCAN, MAXV, NN, NV, NE, RX, RY, RS, VERTS,
: VX, VY, IV, JV )
C *******************************************************************
C ** ROUTINE TO PERFORM VORONOI ANALYSIS **
C ** **
C ** WE WORK INITIALLY ON DOUBLE THE CORRECT SCALE, **
C ** I.E. THE EDGES OF THE POLYGON GO THROUGH THE POINTS. **
C *******************************************************************
INTEGER MAXCAN, NN, MAXV, NV, NE
INTEGER VERTS(MAXCAN)
REAL RX(MAXCAN), RY(MAXCAN), RS(MAXCAN)
REAL VX(MAXV), VY(MAXV)
INTEGER IV(MAXV), JV(MAXV)
LOGICAL OK
INTEGER I, J, L, NN1, N, V
REAL AI, BI, CI, AJ, BJ, CJ, DET, DETINV
REAL VXIJ, VYIJ
REAL TOL
PARAMETER ( TOL = 1.E-6 )
C *******************************************************************
C ** IF THERE ARE LESS THAN 3 POINTS GIVEN **
C ** WE CANNOT CONSTRUCT A POLYGON **
IF ( NN .LT. 3 ) THEN
WRITE(*,'('' LESS THAN 3 POINTS GIVEN TO WORK '',I5)') NN
STOP
ENDIF
NN1 = NN - 1
V = 0
C ** WE AIM TO EXAMINE EACH POSSIBLE VERTEX **
C ** DEFINED BY THE INTERSECTION OF 2 EDGES **
C ** EACH EDGE IS DEFINED BY RX,RY,RS. **
DO 400 I = 1, NN1
AI = RX(I)
BI = RY(I)
CI = -RS(I)
DO 300 J = I + 1, NN
AJ = RX(J)
BJ = RY(J)
CJ = -RS(J)
DET = AI * BJ - AJ * BI
IF ( ABS ( DET ) .GT. TOL ) THEN
C ** THE EDGES INTERSECT **
DETINV = 1.0 / DET
VXIJ = ( BI * CJ - BJ * CI ) * DETINV
VYIJ = ( AJ * CI - AI * CJ ) * DETINV
C ** NOW WE TAKE SHOTS AT THE VERTEX **
C ** USING THE REMAINING EDGES ..... **
OK = .TRUE.
L = 1
100 IF ( OK .AND. ( L .LE. NN ) ) THEN
IF ( ( L .NE. I ) .AND. ( L .NE. J ) ) THEN
OK = ( RX(L) * VXIJ + RY(L) * VYIJ ) .LE. RS(L)
ENDIF
L = L + 1
GOTO 100
ENDIF
C ** IF THE VERTEX MADE IT **
C ** ADD IT TO THE HALL OF FAME **
C ** CONVERT TO CORRECT SCALE **
IF ( OK ) THEN
V = V + 1
IF ( V .GT. MAXV ) STOP 'TOO MANY VERTICES'
IV(V) = I
JV(V) = J
VX(V) = 0.5 * VXIJ
VY(V) = 0.5 * VYIJ
ENDIF
ENDIF
300 CONTINUE
400 CONTINUE
C ** THE SURVIVING VERTICES DEFINE THE VORONOI POLYGON **
NV = V
IF ( NV .LT. 3 ) THEN
WRITE(*,'('' LESS THAN 3 VERTICES FOUND IN WORK '',I5)') NV
STOP
ENDIF
C ** IDENTIFY NEIGHBOURING POINTS **
DO 500 N = 1, NN
VERTS(N) = 0
500 CONTINUE
DO 600 V = 1, NV
VERTS(IV(V)) = VERTS(IV(V)) + 1
VERTS(JV(V)) = VERTS(JV(V)) + 1
600 CONTINUE
C ** POINTS WITH NONZERO VERTS ARE NEIGHBOURS **
C ** IF NONZERO, VERTS SHOULD BE EQUAL TO 2 **
C ** CHECK RESULT AND COUNT EDGES **
OK = .TRUE.
NE = 0
DO 700 N = 1, NN
IF ( VERTS(N) .GT. 0 ) THEN
NE = NE + 1
IF ( VERTS(N) .NE. 2 ) THEN
OK = .FALSE.
ENDIF
ENDIF
700 CONTINUE
IF ( .NOT. OK ) THEN
WRITE (*,'('' **** VERTEX ERROR: DEGENERACY ? **** '')')
ENDIF
IF ( NE .NE. NV ) THEN
WRITE(*,'('' **** EDGE ERROR: DEGENERACY ? **** '')')
ENDIF
RETURN
END
SUBROUTINE SORT ( MAXCAN, RX, RY, RS, TAG, NN )
C *******************************************************************
C ** ROUTINE TO SORT NEIGHBOURS INTO INCREASING ORDER OF DISTANCE **
C ** **
C ** FOR SIMPLICITY WE USE A BUBBLE SORT - OK FOR MAXCAN SMALL. **
C *******************************************************************
INTEGER MAXCAN, NN
REAL RX(MAXCAN), RY(MAXCAN), RS(MAXCAN)
INTEGER TAG(MAXCAN)
LOGICAL CHANGE
INTEGER I, ITOP, I1, TAGI
REAL RXI, RYI, RSI
C *******************************************************************
CHANGE = .TRUE.
ITOP = NN - 1
1000 IF ( CHANGE .AND. ( ITOP .GE. 1 ) ) THEN
CHANGE = .FALSE.
DO 100 I = 1, ITOP
I1 = I + 1
IF ( RS(I) .GT. RS(I1) ) THEN
RXI = RX(I)
RYI = RY(I)
RSI = RS(I)
TAGI = TAG(I)
RX(I) = RX(I1)
RY(I) = RY(I1)
RS(I) = RS(I1)
TAG(I) = TAG(I1)
RX(I1) = RXI
RY(I1) = RYI
RS(I1) = RSI
TAG(I1) = TAGI
CHANGE = .TRUE.
ENDIF
100 CONTINUE
ITOP = ITOP - 1
GOTO 1000
ENDIF
RETURN
END
C *******************************************************************
C ** FICHE F.35 - PART B **
C ** THE VORONOI CONSTRUCTION IN 3D. **
C *******************************************************************
PROGRAM VORON3
COMMON / BLOCK1 / RX, RY, RZ
C *******************************************************************
C ** CONSTRUCTION OF VORONOI POLYHEDRON IN 3D. **
C ** **
C ** THIS PROGRAM TAKES IN A CONFIGURATION IN A CUBIC BOX WITH **
C ** CONVENTIONAL PERIODIC BOUNDARY CONDITIONS AND FOR EACH ATOM **
C ** OBTAINS THE SURROUNDING VORONOI POLYHEDRON, DEFINED AS THAT **
C ** REGION OF SPACE CLOSER TO THE CHOSEN ATOM THAN TO ANY OTHER. **
C ** NEIGHBOURING POLYHEDRA DEFINE NEIGHBOURING ATOMS. **
C ** THIS PROGRAM IS SLOW BUT ESSENTIALLY FOOLPROOF. **
C ** WE USE THE MINIMUM IMAGE CONVENTION AND SET A CUTOFF BEYOND **
C ** WHICH ATOMS ARE ASSUMED NOT TO BE NEIGHBOURS: BOTH OF THESE **
C ** MEASURES ARE DANGEROUS FOR SMALL AND/OR RANDOM SYSTEMS. **
C ** WE DELIBERATELY DO NOT USE PREVIOUSLY-FOUND NEIGHBOURS IN **
C ** CONSTRUCTING NEIGHBOUR LISTS, SO THAT AN INDEPENDENT CHECK **
C ** MAY BE MADE AT THE END. **
C ** HERE WE SIMPLY PRINT OUT THE GEOMETRICAL INFORMATION AT THE **
C ** END. THE OUTPUT IS QUITE LENGTHY. IN PRACTICE, IT WOULD **
C ** PROBABLY BE ANALYZED DIRECTLY WITHOUT PRINTING IT OUT. **
C ** NB: BEWARE DEGENERATE CONFIGURATIONS, I.E. ONES IN WHICH MORE **
C ** THAN FOUR VORONOI DOMAINS SHARE A VERTEX. THE SIMPLE CUBIC **
C ** AND FACE-CENTRED CUBIC LATTICES ARE EXAMPLES. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** INTEGER N NUMBER OF MOLECULES **
C ** REAL RX(N),RY(N),RZ(N) POSITIONS **
C ** REAL PX(MAXCAN), ETC. CANDIDATE RELATIVE POSITIONS **
C ** REAL PS(MAXCAN) SQUARED RELATIVE DISTANCES **
C ** INTEGER NVER NUMBER OF VERTICES FOUND **
C ** INTEGER NEDGE NUMBER OF EDGES FOUND **
C ** INTEGER NFACE NUMBER OF FACES FOUND **
C ** INTEGER EDGES(MAXCAN) EDGES PER FACE FOR CANDIDATES **
C ** = 0 FOR NON-NEIGHBOURS **
C ** REAL RXVER(MAXVER) VERTEX RELATIVE X-COORD **
C ** REAL RYVER(MAXVER) VERTEX RELATIVE Y-COORD **
C ** REAL RZVER(MAXVER) VERTEX RELATIVE Z-COORD **
C ** INTEGER IVER(MAXVER) ATOM INDICES DEFINING **
C ** INTEGER JVER(MAXVER) .. VERTICES IN VORONOI **
C ** INTEGER KVER(MAXVER) .. POLYHEDRON. **
C ** **
C ** ROUTINES REFERENCED: **
C ** **
C ** SUBROUTINE READCN ( CNFILE, N, BOX ) **
C ** READS CONFIGURATION, NUMBER OF ATOMS, BOX SIZE. **
C ** SUBROUTINE SORT ( MAXCAN, PX, PY, PZ, PS, TAG, NCAN ) **
C ** SORTS NEIGHBOUR DETAILS INTO ASCENDING DISTANCE ORDER **
C ** SUBROUTINE WORK ( MAXCAN, MAXVER, NCAN, NVER, NEDGE, NFACE, **
C ** PX, PY, PZ, PS, EDGES, **
C ** RXVER, RYVER, RZVER, IVER, JVER, KVER ) **
C ** CARRIES OUT VORONOI CONSTRUCTION **
C *******************************************************************
INTEGER MAXN, MAXCAN, MAXVER
PARAMETER ( MAXN = 108, MAXCAN = 50, MAXVER = 100 )
REAL RX(MAXN), RY(MAXN), RZ(MAXN)
REAL PX(MAXCAN), PY(MAXCAN), PZ(MAXCAN), PS(MAXCAN)
INTEGER TAG(MAXCAN), EDGES(MAXCAN)
REAL RXVER(MAXVER), RYVER(MAXVER), RZVER(MAXVER)
INTEGER IVER(MAXVER), JVER(MAXVER), KVER(MAXVER)
INTEGER NABLST(MAXVER,MAXN), NNAB(MAXN), INAB, JNAB
INTEGER NCAN, NVER, NEDGE, NFACE, NCOORD
INTEGER I, CAN, VER, J, N
REAL BOX, BOXINV, RCUT, RCUTSQ, COORD
REAL RXJ, RYJ, RZJ, RXIJ, RYIJ, RZIJ, RIJSQ
CHARACTER CNFILE*30
LOGICAL OK
C *******************************************************************
WRITE(*,'(1H1,'' **** PROGRAM VORON3 **** '')')
WRITE(*,'(//1X,''VORONOI CONSTRUCTION IN 3D '')')
C ** BASIC PARAMETERS **
WRITE(*,'('' ENTER CONFIGURATION FILENAME '')')
READ (*,'(A)') CNFILE
WRITE(*,'('' CONFIGURATION FILENAME '',A)') CNFILE
C ** READCN MUST READ IN INITIAL CONFIGURATION **
CALL READCN ( CNFILE, N, BOX )
WRITE(*,'(1X,I5,''-ATOM CONFIGURATION'')') N
WRITE(*,'('' BOX LENGTH = '',F10.5)') BOX
WRITE(*,'('' ENTER NEIGHBOUR CUTOFF IN SAME UNITS '')')
READ (*,*) RCUT
WRITE(*,'('' NEIGHBOUR CUTOFF = '',F10.5)') RCUT
RCUTSQ = RCUT**2
BOXINV = 1.0 / BOX
C ** ZERO ACCUMULATORS **
DO 100 J = 1, N
NNAB(J) = 0
DO 90 INAB = 1, NVER
NABLST(INAB,J) = 0
90 CONTINUE
100 CONTINUE
C *******************************************************************
C ** MAIN LOOP STARTS **
C *******************************************************************
DO 1000 J = 1, N
WRITE(*,'(1H1,'' RESULTS FOR ATOM '',I5)') J
RXJ = RX(J)
RYJ = RY(J)
RZJ = RZ(J)
CAN = 0
C ** SELECT CANDIDATES **
DO 500 I = 1, N
IF ( I .NE. J ) THEN
RXIJ = RX(I) - RXJ
RYIJ = RY(I) - RYJ
RZIJ = RZ(I) - RZJ
RXIJ = RXIJ - ANINT ( RXIJ * BOXINV ) * BOX
RYIJ = RYIJ - ANINT ( RYIJ * BOXINV ) * BOX
RZIJ = RZIJ - ANINT ( RZIJ * BOXINV ) * BOX
RIJSQ = RXIJ**2 + RYIJ**2 + RZIJ**2
IF ( RIJSQ .LT. RCUTSQ ) THEN
CAN = CAN + 1
IF ( CAN .GT. MAXCAN ) THEN
WRITE(*,'('' TOO MANY CANDIDATES '')')
STOP
ENDIF
PX(CAN) = RXIJ
PY(CAN) = RYIJ
PZ(CAN) = RZIJ
PS(CAN) = RIJSQ
TAG(CAN) = I
ENDIF
ENDIF
500 CONTINUE
C ** CANDIDATES HAVE BEEN SELECTED **
NCAN = CAN
C ** SORT INTO ASCENDING ORDER OF DISTANCE **
C ** THIS SHOULD IMPROVE EFFICIENCY **
CALL SORT ( MAXCAN, PX, PY, PZ, PS, TAG, NCAN )
C ** PERFORM VORONOI ANALYSIS **
CALL WORK ( MAXCAN, MAXVER, NCAN, NVER, NEDGE, NFACE,
: PX, PY, PZ, PS, EDGES,
: RXVER, RYVER, RZVER, IVER, JVER, KVER )
C ** WRITE OUT RESULTS **
WRITE(*,'(/1X,''NUMBER OF NEIGHBOURS '',I5)') NFACE
WRITE(*,'(/1X,''NEIGHBOUR LIST '')')
WRITE(*,10001)
DO 800 CAN = 1, NCAN
IF (EDGES(CAN) .NE. 0) THEN
PS(CAN) = SQRT ( PS(CAN) )
WRITE(*,'(1X,I5,3X,I5,3X,3F12.5,3X,F12.5)')
: TAG(CAN), EDGES(CAN),
: PX(CAN), PY(CAN), PZ(CAN), PS(CAN)
NNAB(J) = NNAB(J) + 1
NABLST(NNAB(J),J) = TAG(CAN)
ENDIF
800 CONTINUE
WRITE(*,'(/1X,''NUMBER OF EDGES '',I5)') NEDGE
WRITE(*,'(/1X,''NUMBER OF VERTICES '',I5)') NVER
WRITE(*,'(/1X,''VERTEX LIST '')')
WRITE(*,10002)
DO 900 VER = 1, NVER
WRITE(*,'(1X,3I5,3X,3F12.5)')
: TAG(IVER(VER)), TAG(JVER(VER)), TAG(KVER(VER)),
: RXVER(VER), RYVER(VER), RZVER(VER)
900 CONTINUE
1000 CONTINUE
C *******************************************************************
C ** MAIN LOOP ENDS **
C *******************************************************************
WRITE(*,'(1H1,''FINAL SUMMARY'')')
WRITE(*,10003)
NCOORD = 0
DO 2000 J = 1, N
NCOORD = NCOORD + NNAB(J)
WRITE(*,'(1X,I5,3X,I5,3X,30I3)') J, NNAB(J),
: ( NABLST(INAB,J), INAB = 1, NNAB(J) )
C ** CHECK THAT IF I IS A NEIGHBOUR OF J **
C ** THEN J IS ALSO A NEIGHBOUR OF I **
DO 1500 INAB = 1, NNAB(J)
I = NABLST(INAB,J)
OK = .FALSE.
JNAB = 0
1200 IF ( ( .NOT. OK ) .AND. ( JNAB .LE. NNAB(I) ) ) THEN
OK = ( J .EQ. NABLST(JNAB,I) )
JNAB = JNAB + 1
GOTO 1200
ENDIF
IF ( .NOT. OK ) THEN
WRITE(*,'(1X,I3,'' IS NOT A NEIGHBOUR OF '',I3)') J, I
ENDIF
1500 CONTINUE
2000 CONTINUE
COORD = REAL ( NCOORD ) / REAL ( N )
WRITE(*,'(/1X,'' AVERAGE COORDINATION NUMBER = '',F10.5)') COORD
STOP
10001 FORMAT(/1X,'ATOM ',3X,'FACE ',
: /1X,'INDEX',3X,'EDGES',3X,
: ' RELATIVE POSITION ',3X,
: ' DISTANCE')
10002 FORMAT(/1X,' INDICES RELATIVE POSITION')
10003 FORMAT(/1X,'INDEX NABS ... NEIGHBOUR INDICES ... ')
END
SUBROUTINE READCN ( CNFILE, N, BOX )
COMMON / BLOCK1 / RX, RY, RZ
C *******************************************************************
C ** SUBROUTINE TO READ IN INITIAL CONFIGURATION FROM UNIT 10 **
C *******************************************************************
INTEGER MAXN
PARAMETER ( MAXN = 108 )
REAL RX(MAXN), RY(MAXN), RZ(MAXN), BOX
INTEGER CNUNIT, N, I
PARAMETER ( CNUNIT = 10 )
CHARACTER CNFILE*(*)
C *******************************************************************
OPEN ( UNIT = CNUNIT, FILE = CNFILE,
: STATUS = 'OLD', FORM = 'UNFORMATTED' )
READ ( CNUNIT ) N, BOX
IF ( N .GT. MAXN ) STOP ' N TOO LARGE '
READ ( CNUNIT ) ( RX(I), I = 1, N ),
: ( RY(I), I = 1, N ),
: ( RZ(I), I = 1, N )
CLOSE ( UNIT = CNUNIT )
RETURN
END
SUBROUTINE WORK ( MAXCAN, MAXV, NN, NV, NE, NF,
: RX, RY, RZ, RS, EDGES,
: VX, VY, VZ, IV, JV, KV )
C *******************************************************************
C ** ROUTINE TO PERFORM VORONOI ANALYSIS **
C ** **
C ** WE WORK INITIALLY ON DOUBLE THE CORRECT SCALE, **
C ** I.E. THE FACES OF THE POLYHEDRON GO THROUGH THE POINTS. **
C *******************************************************************
INTEGER MAXCAN, NN, MAXV, NV, NE, NF
INTEGER EDGES(MAXCAN)
REAL RX(MAXCAN), RY(MAXCAN), RZ(MAXCAN), RS(MAXCAN)
REAL VX(MAXV), VY(MAXV), VZ(MAXV)
INTEGER IV(MAXV), JV(MAXV), KV(MAXV)
LOGICAL OK
INTEGER I, J, K, L, NN1, NN2, N, V
REAL AI, BI, CI, DI, AJ, BJ, CJ, DJ, AK, BK, CK, DK
REAL AB, BC, CA, DA, DB, DC, DET, DETINV
REAL VXIJK, VYIJK, VZIJK
REAL TOL
PARAMETER ( TOL = 1.E-6 )
C *******************************************************************
C ** IF THERE ARE LESS THAN 4 POINTS GIVEN **
C ** WE CANNOT CONSTRUCT A POLYHEDRON **
IF ( NN .LT. 4 ) THEN
WRITE(*,'('' LESS THAN 4 POINTS GIVEN TO WORK '',I5)') NN
STOP
ENDIF
NN1 = NN - 1
NN2 = NN - 2
V = 0
C ** WE AIM TO EXAMINE EACH POSSIBLE VERTEX **
C ** DEFINED BY THE INTERSECTION OF 3 PLANES **
C ** EACH PLANE IS SPECIFIED BY RX,RY,RZ,RS **
DO 400 I = 1, NN2
AI = RX(I)
BI = RY(I)
CI = RZ(I)
DI = -RS(I)
DO 300 J = I + 1, NN1
AJ = RX(J)
BJ = RY(J)
CJ = RZ(J)
DJ = -RS(J)
AB = AI * BJ - AJ * BI
BC = BI * CJ - BJ * CI
CA = CI * AJ - CJ * AI
DA = DI * AJ - DJ * AI
DB = DI * BJ - DJ * BI
DC = DI * CJ - DJ * CI
DO 200 K = J + 1, NN
AK = RX(K)
BK = RY(K)
CK = RZ(K)
DK = -RS(K)
DET = AK * BC + BK * CA + CK * AB
IF ( ABS ( DET ) .GT. TOL ) THEN
C ** THE PLANES INTERSECT **
DETINV = 1.0 / DET
VXIJK = ( - DK * BC + BK * DC - CK * DB ) * DETINV
VYIJK = ( - AK * DC - DK * CA + CK * DA ) * DETINV
VZIJK = ( AK * DB - BK * DA - DK * AB ) * DETINV
C ** NOW WE TAKE SHOTS AT THE VERTEX **
C ** USING THE REMAINING PLANES .... **
OK = .TRUE.
L = 1
100 IF ( OK .AND. ( L .LE. NN ) ) THEN
IF ( ( L .NE. I ) .AND.
: ( L .NE. J ) .AND.
: ( L .NE. K ) ) THEN
OK = ( ( RX(L) * VXIJK +
: RY(L) * VYIJK +
: RZ(L) * VZIJK ) .LE. RS(L) )
ENDIF
L = L + 1
GOTO 100
ENDIF
C ** IF THE VERTEX MADE IT **
C ** ADD IT TO THE HALL OF FAME **
C ** CONVERT TO CORRECT SCALE **
IF ( OK ) THEN
V = V + 1
IF ( V .GT. MAXV ) STOP 'TOO MANY VERTICES'