-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglSyMM.f90
2229 lines (1955 loc) · 68.6 KB
/
glSyMM.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
! cvs generated header
! $Id: glSyMM.f90,v 1.35 2004/04/01 20:52:53 paulo Exp $
!
Module glSyMM_mod
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Use moving_axis
Implicit None
real(kind=gldouble), parameter :: PI = 3.141592653589793_gldouble
Integer,Dimension (:), Allocatable, Save:: z
Real(kind=glfloat),Parameter :: zero=0.0_glfloat, one=1.0_glfloat
Real(kind=glfloat), Dimension(4) :: &
atom_ambient = (/ 0.8_glfloat, 0.8_glfloat, 0.8_glfloat, one /), &
atom_diffuse = (/ 0.4_glfloat, 0.4_glfloat, 0.4_glfloat, one /), &
atom_specular = (/ 0.9_glfloat, 0.9_glfloat, 0.9_glfloat, one /), &
bond_ambient = (/ 0.8_glfloat, 0.8_glfloat, 0.8_glfloat, one /), &
bond_diffuse = (/ 0.4_glfloat, 0.4_glfloat, 0.4_glfloat, one /), &
bond_specular = (/ 0.3_glfloat, 0.3_glfloat, 0.3_glfloat, one /), &
light_ambient = (/ 0.26_glfloat, 0.26_glfloat, 0.26_glfloat, one /), &
light_diffuse = (/ 0.2_glfloat, 0.2_glfloat, 0.2_glfloat, one /), &
light_specular = (/ 0.13_glfloat, 0.13_glfloat, 0.13_glfloat, one /)
Real(kind=glfloat),Dimension(92,3),Save :: iupac_colors
Real(kind=glfloat),Dimension(92),Save :: v_radius
Real(kind=glfloat),Dimension(92),Save :: vdW_radius
Real(kind=glclampf), Dimension(4),Save :: background
Real(kind=glclampf), Dimension(4),Save :: &
background_default= (/ 20/255.0_glclampf, 0/255.0_glclampf, 29/255.0_glclampf,&
1.0_glclampf /)
Character(len=2), Dimension(103), Save :: symbols
Real, Dimension(103), Save :: atomic_masses
Real(kind=gldouble), Dimension(:), Allocatable, Save::gl_radius
Data v_radius/0.200,0.286,0.340,0.589,0.415,0.400,0.400, &
0.400,0.320,0.423,0.485,0.550,0.675,0.600, &
0.525,0.510,0.495,0.508,0.665,0.495,0.720, &
0.735,0.665,0.675,0.675,0.670,0.615,0.750, &
0.760,0.725,0.610,0.585,0.605,0.610,0.605, &
0.524,0.735,0.560,0.890,0.780,0.740,0.735, &
0.675,0.700,0.725,0.750,0.795,0.845,0.815, &
0.730,0.730,0.735,0.700,0.577,0.835,0.670, &
0.935,0.915,0.910,0.905,0.900,0.900,0.995, &
0.895,0.880,0.875,0.870,0.865,0.860,0.970, &
0.860,0.785,0.715,0.685,0.675,0.685,0.660, &
0.750,0.750,0.850,0.775,0.770,0.770,0.840, &
1.000,1.000,1.000,0.950,0.940,0.895,0.805, &
0.790/
Data vdW_radius/0.430,0.741,0.880,0.550,1.030,0.900,0.880, &
0.880,0.840,0.815,1.170,1.300,1.550,1.400, &
1.250,1.220,1.190,0.995,1.530,1.190,1.640, &
1.670,1.530,1.550,1.550,1.540,1.530,1.700, &
1.720,1.650,1.420,1.370,1.410,1.420,1.410, &
1.069,1.670,1.320,1.980,1.760,1.680,1.670, &
1.550,1.600,1.650,1.700,1.790,1.890,1.830, &
1.660,1.660,1.670,1.600,1.750,1.870,1.540, &
2.070,2.030,2.020,2.010,2.000,2.000,2.190, &
1.990,1.960,1.950,1.940,1.930,1.920,2.140, &
1.920,1.770,1.630,1.570,1.550,1.570,1.520, &
1.700,1.700,1.900,1.750,1.740,1.740,1.880, &
0.200,0.200,0.200,2.100,2.080,1.990,1.810, &
1.780/
! the array atomic_masses contains the molar masses for atoms
Data atomic_masses/1.00794, 4.002602, 6.941, 9.01218, 10.811, 12.011 &
,14.00674, 15.9994, 18.998403, 20.1797, 22.989768, 24.305 &
,26.981539, 28.0855, 30.973762, 32.066, 35.4527, 39.948, 39.0983 &
,40.078, 44.95591, 47.88, 50.9415, 51.9961, 54.93805, 55.847 &
,58.9332, 58.6934, 63.546, 65.39, 69.723, 72.61, 74.92159, 78.96 &
,79.904, 83.8, 85.4678, 87.62, 88.90585, 91.224, 92.90638, 95.94 &
,97.9072, 101.07, 102.9055, 106.42, 107.8682, 112.411, 114.818 &
,118.71, 121.760, 127.6, 126.90447, 131.29, 132.90543, 137.327 &
,138.9055, 140.115, 140.90765, 144.24, 144.9127, 150.36, 151.965 &
,157.25, 158.92534, 162.50, 164.93032, 167.26, 168.93421, 173.04 &
,174.967, 178.49, 180.9479, 183.84, 186.207, 190.23, 192.22 &
,195.08, 196.96654, 200.59, 204.3833, 207.2, 208.98037, 208.9824 &
,209.9871, 222.0176, 223.0197, 226.0254, 227.0278, 232.0381 &
,231.03588, 238.0289, 237.048, 244.0642, 243.0614, 247.0703 &
,247.0703, 251.0796, 252.083, 257.0951, 258.1, 259.1009, 262.11/
! an array containing the symbols of the elements
! strict IUPAC symbols ie first letter uppercase second letter lowercase
Data symbols/"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", &
"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", &
"Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", &
"As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", &
"Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", &
"Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", &
"Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", &
"Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", &
"Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", &
"Es", "Fm", "Md", "No", "Lr"/
! derived types and operations
Type atom
Integer :: z
Character(len=2) :: symbol
Real(kind=glfloat), Dimension (3) :: coords
End Type atom
Interface Operator(==)
Module Procedure compare_atoms
End Interface
Type atom_data
Character(len=2) :: symbol
Real(kind=glfloat) :: vdW
Real(kind=glfloat) :: radius
Real(kind=glfloat), Dimension(3) :: color
Real(kind=glfloat) :: mass
End Type atom_data
Type(atom_data), Dimension(92), Save :: atomic_data
Type(atom), Allocatable, Dimension(:), Save :: molecule, molecule_OP
Type(atom), Allocatable, Dimension(:), Save :: molecule_CM, molecule_IA
Real(kind=glfloat), Dimension(3) :: center_of_mass
Real, Dimension(3,3) :: inertial_tensor
Real, Dimension(3) :: eigenvalues
Real, Dimension (3,3) :: eigenvectors
Real(kind=glfloat) :: maxsize=6.5_glfloat
Logical, Save :: bonds, atoms, ghosts=.False., reflection=.True.
Logical, Save :: light0_on=.true., light1_on=.false., light2_on=.true., light3_on=.false.
Integer, Parameter :: &
mirror_xy=1, &
mirror_yz=2, &
mirror_zx=3, &
no_mirror=4
Integer, Parameter :: &
axis_x=1, &
axis_y=2, &
axis_z=3, &
no_axis=4
Logical,Save :: mxy=.False.,myz=.False.,mzx=.False.
Logical,Save :: a_X=.False.,a_Y=.False.,a_Z=.False.
Logical,Save :: a_mxy, inversion=.False.
Integer,Save :: atoms_list=1, bonds_list=2, axis_list=3, &
mirrorXY_list=4, mirrorYZ_list=5, mirrorZX_list=6, &
axisX_list=7, axisY_list=8, axisZ_list=9, ghosts_list=10,&
ghosts_list_inverted=11, ghosts_list_reflection=12, ghosts_list_stay=20, &
moving_axis_list=13
! Public :: bonds, atoms, make_menu
Contains
Subroutine glSyMM_display()
use opengl_gl
use opengl_glu
use opengl_glut
use moving_axis
end Subroutine glSyMM_display
Subroutine create_mirror_list(plane)
Use opengl_gl
Use opengl_glu
Use opengl_glut
Use moving_axis
Implicit None
Character(1), Intent(in):: plane
! on entry plane contains the basis vector perpendicular to the mirror plane
Select Case (plane)
Case ('x') ! plane YZ
Call glPushMatrix()
Call glColor4fv(mirror_color)
Call glBegin(GL_QUADS)
Call glVertex3f(zero,-mirror_size,mirror_size)
Call glVertex3f(zero,mirror_size,mirror_size)
Call glVertex3f(zero,mirror_size,-mirror_size)
Call glVertex3f(zero,-mirror_size,-mirror_size)
Call glEnd
Call glPopMatrix()
Case ('y') ! plane ZX
Call glPushMatrix()
Call glColor4fv(mirror_color)
Call glBegin(GL_QUADS)
Call glVertex3f(-mirror_size,zero,mirror_size)
Call glVertex3f(mirror_size,zero,mirror_size)
Call glVertex3f(mirror_size,zero,-mirror_size)
Call glVertex3f(-mirror_size,zero,-mirror_size)
Call glEnd
Call glPopMatrix()
Case ('z') ! plane XY
Call glPushMatrix()
Call glColor4fv(mirror_color)
Call glBegin(GL_QUADS)
Call glVertex3f(-mirror_size,mirror_size,zero)
Call glVertex3f(mirror_size,mirror_size,zero)
Call glVertex3f(mirror_size,-mirror_size,zero)
Call glVertex3f(-mirror_size,-mirror_size,zero)
Call glEnd
Call glPopMatrix()
End Select
End Subroutine create_mirror_list
Subroutine draw_axis_list(axis)
Use opengl_gl
Use opengl_glu
Use opengl_glut
Use moving_axis
Implicit None
Character(1), Intent(in):: axis
Select Case (axis)
Case ('x') ! X axis
Call glPushMatrix()
Call glLineWidth(8.0_glfloat)
Call glColor4fv(axis_color)
Call glBegin(GL_LINES)
Call glVertex3f(-mirror_size,zero,zero)
Call glVertex3f(mirror_size,zero,zero)
Call glEnd
Call glPopMatrix()
Case ('y') ! Y axis
Call glPushMatrix()
Call glLineWidth(8.0_glfloat)
Call glColor4fv(axis_color)
Call glBegin(GL_LINES)
Call glVertex3f(zero,-mirror_size,zero)
Call glVertex3f(zero,mirror_size,zero)
Call glEnd
Call glPopMatrix()
Case ('z') ! Z axis
Call glPushMatrix()
Call glLineWidth(8.0_glfloat)
Call glColor4fv(axis_color)
Call glBegin(GL_LINES)
Call glVertex3f(zero,zero,-mirror_size)
Call glVertex3f(zero,zero,mirror_size)
Call glEnd
Call glPopMatrix()
End Select
End Subroutine draw_axis_list
Subroutine init_radius
Implicit None
Integer::i
Do i=1,92
vdW_radius(i)=vdW_radius(i)/2.0
v_radius(i)=v_radius(i)/2.0
atomic_data(i)%vdW=vdW_radius(i)/2.0
atomic_data(i)%radius=v_radius(i)/2.0
Enddo
! vdW_radius(1)=1.17/3 ! hydrogen
! vdW_radius(6)=1.75/3 ! carbon
! vdW_radius(7)=1.55/3 ! nitrogen
! vdW_radius(8)=1.40/3 ! oxygen
! vdW_radius(15)= 1.28/3 ! phosphorus
! vdW_radius(16)= 1.80/3 ! sulfur
End Subroutine init_radius
Subroutine init_colors
Implicit None
Integer::i
Do i=1,92
iupac_colors(i,1)=0.0 ! default (green4, lightgreen)
iupac_colors(i,2)=139/255.0
iupac_colors(i,3)=0.0
Enddo
iupac_colors(1,1)=1.0 ! hydrogen (white,grey70)
iupac_colors(1,2)=1.0
iupac_colors(1,3)=1.0
iupac_colors(6,1)=153/255.0 ! carbon (grey60,white)
iupac_colors(6,2)=153/255.0
iupac_colors(6,3)=153/255.0
iupac_colors(7,1)=176/255.0 ! nitrogen (lightsteelblue3,slateblue1)
iupac_colors(7,2)=196/255.0
iupac_colors(7,3)=222/255.0
iupac_colors(8,1)=255.0/255.0 ! oxygen (red,lightpink)
iupac_colors(8,2)=0.0/255.0
iupac_colors(8,3)=0.0/255.0
iupac_colors(15,1)=147/255.0 ! phosphorus (mediumpurple,palevioletred)
iupac_colors(15,2)=112/255.0
iupac_colors(15,3)=219/255.0
iupac_colors(16,1)=139/255.0 ! sulfur (yellow4,yellow1)
iupac_colors(16,2)=139/255.0
iupac_colors(16,3)=0.0/255.0
Do i=1,92
atomic_data(i)%color(1)=iupac_colors(i,1)
atomic_data(i)%color(2)=iupac_colors(i,2)
atomic_data(i)%color(3)=iupac_colors(i,3)
Enddo
End Subroutine init_colors
Subroutine init_symbols()
Implicit None
Integer :: i
Do i=1,92
atomic_data(i)%symbol=symbols(i)
Enddo
End Subroutine init_symbols
Subroutine init_masses()
Implicit None
Integer :: i
Do i=1,92
atomic_data(i)%mass=atomic_masses(i)
Enddo
End Subroutine init_masses
Function cm(a) !result(molecule_CM)
Real(kind=glfloat),Dimension(3) :: cm
Type(atom), Dimension(:) :: a
! real(kind=glfloat), dimension(3) :: molecule_cm
Real :: mT
Integer :: natoms, i
cm=0.0
mT=0.0
natoms=Ubound(a,1)
Do i=1,natoms
mT=mT+atomic_data(a(i)%z)%mass
cm(1)=cm(1)+a(i)%coords(1)*atomic_data(a(i)%z)%mass
cm(2)=cm(2)+a(i)%coords(2)*atomic_data(a(i)%z)%mass
cm(3)=cm(3)+a(i)%coords(3)*atomic_data(a(i)%z)%mass
Enddo
cm(1)=cm(1)/mT
cm(2)=cm(2)/mT
cm(3)=cm(3)/mT
Write(*,*)'mT=',mT
End Function cm
Logical Function compare_atoms(a,b)
! this function only compares by coordinates and atomic number ... phear !
Implicit None
Type(atom), Intent(in) :: a,b
Real(kind=glfloat) :: tol=0.02
compare_atoms=((a%z==b%z).And. &
(Abs(a%coords(1)-b%coords(1))<tol) .And. &
(Abs(a%coords(2)-b%coords(2))<tol) .And. &
(Abs(a%coords(3)-b%coords(3))<tol))
End Function compare_atoms
Subroutine make_menu(submenuid)
Use opengl_gl
Use opengl_glu
Use opengl_glut
Use view_modifier
Implicit None
Integer(kind=glcint), Intent(in) :: submenuid
Integer(kind=glcint) :: menuid, mirror_menu, axis_menu, top_menu, invertion_menu,&
improper_rotation_menu, top_menuid, background_menu, &
cx_menuid, cy_menuid, cz_menuid, sx_menuid, sy_menuid, sz_menuid, lights_menuid
cx_menuid = glutCreateMenu(general_c_axis)
Call glutAddMenuEntry("2",12)
Call glutAddMenuEntry("3",13)
Call glutAddMenuEntry("4",14)
Call glutAddMenuEntry("5",15)
Call glutAddMenuEntry("6",16)
Call glutAddMenuEntry("7",17)
Call glutAddMenuEntry("8",18)
cy_menuid = glutCreateMenu(general_c_axis)
Call glutAddMenuEntry("2",22)
Call glutAddMenuEntry("3",23)
Call glutAddMenuEntry("4",24)
Call glutAddMenuEntry("5",25)
Call glutAddMenuEntry("6",26)
Call glutAddMenuEntry("7",27)
Call glutAddMenuEntry("8",28)
cz_menuid = glutCreateMenu(general_c_axis)
Call glutAddMenuEntry("2",32)
Call glutAddMenuEntry("3",33)
Call glutAddMenuEntry("4",34)
Call glutAddMenuEntry("5",35)
Call glutAddMenuEntry("6",36)
Call glutAddMenuEntry("7",37)
Call glutAddMenuEntry("8",38)
sx_menuid = glutCreateMenu(general_s_axis)
Call glutAddMenuEntry("1",11)
Call glutAddMenuEntry("2",12)
Call glutAddMenuEntry("3",13)
Call glutAddMenuEntry("4",14)
Call glutAddMenuEntry("5",15)
Call glutAddMenuEntry("6",16)
Call glutAddMenuEntry("7",17)
Call glutAddMenuEntry("8",18)
sy_menuid = glutCreateMenu(general_s_axis)
Call glutAddMenuEntry("1",21)
Call glutAddMenuEntry("2",22)
Call glutAddMenuEntry("3",23)
Call glutAddMenuEntry("4",24)
Call glutAddMenuEntry("5",25)
Call glutAddMenuEntry("6",26)
Call glutAddMenuEntry("7",27)
Call glutAddMenuEntry("8",28)
sz_menuid = glutCreateMenu(general_s_axis)
Call glutAddMenuEntry("1",31)
Call glutAddMenuEntry("2",32)
Call glutAddMenuEntry("3",33)
Call glutAddMenuEntry("4",34)
Call glutAddMenuEntry("5",35)
Call glutAddMenuEntry("6",36)
Call glutAddMenuEntry("7",37)
Call glutAddMenuEntry("8",38)
improper_rotation_menu = glutCreateMenu(draw_improper)
Call glutAddMenuEntry("axis X",axis_x)
Call glutAddMenuEntry("axis Y",axis_y)
Call glutAddMenuEntry("axis Z",axis_z)
Call glutAddMenuEntry("no axis",no_axis)
mirror_menu = glutCreateMenu(draw_mirror)
Call glutAddMenuEntry("mirror XY",mirror_xy)
Call glutAddMenuEntry("mirror YZ",mirror_yz)
Call glutAddMenuEntry("mirror ZX",mirror_zx)
Call glutAddMenuEntry("no mirror",no_mirror)
axis_menu = glutCreateMenu(draw_axis)
Call glutAddMenuEntry("axis X",axis_x)
Call glutAddMenuEntry("axis Y",axis_y)
Call glutAddMenuEntry("axis Z",axis_z)
Call glutAddMenuEntry("no axis",no_axis)
invertion_menu = glutCreateMenu(invert_menu)
Call glutAddMenuEntry("invert",1)
background_menu = glutCreateMenu(background_color_menu)
Call glutAddMenuEntry("Black",0)
Call glutAddMenuEntry("White",1)
Call glutAddMenuEntry("Grey",2)
Call glutAddMenuEntry("LightGrey",3)
Call glutAddMenuEntry("DarkGrey",4)
Call glutAddMenuEntry("Peachy",5)
Call glutAddMenuEntry("DarkBlue",6)
Call glutAddMenuEntry("DarkGreen",7)
Call glutAddMenuEntry("Default",8)
lights_menuid = glutCreateMenu(lights_menu)
Call glutAddMenuEntry("Light0",0)
Call glutAddMenuEntry("Light1",1)
Call glutAddMenuEntry("Light2",2)
Call glutAddMenuEntry("Light3",3)
! is this needed or can one use glutnullfunc ???
! top_menu = glutCreateMenu(does_nothing)
menuid = glutCreateMenu(menu_handler)
Call glutAddSubMenu("View Modifier",submenuid)
Call glutAddSubMenu("Background",background_menu)
Call glutAddSubMenu("Lights",lights_menuid)
Call glutAddSubMenu("Mirror planes",mirror_menu)
! Call glutAddSubMenu("Proper Rotation Axis",axis_menu)
! Call glutAddSubMenu("Imroper Rotation Axis",improper_rotation_menu)
Call glutAddSubMenu("Inversion Center", invertion_menu)
! Call glutAddSubMenu("TEST", cx_menuid)
Call glutAddSubMenu ("Cx axis", cx_menuid)
Call glutAddSubMenu ("Cy axis", cy_menuid)
Call glutAddSubMenu ("Cz axis", cz_menuid)
Call glutAddSubMenu ("Sx axis", sx_menuid)
Call glutAddSubMenu ("Sy axis", sy_menuid)
Call glutAddSubMenu ("Sz axis", sz_menuid)
! Call glutAddMenu ("Dummy",top_menu)
! call glutAddSubMenu("left mouse button",button_left)
! call glutAddSubMenu("middle mouse button",button_middle)
! call glutAddSubMenu("arrow keys",arrow_keys)
! call glutAddMenuEntry("reset to initial view",10) ! RESET
call glutAddMenuEntry("view from above",11) ! ABOVE
call glutAddMenuEntry("quit",12) ! QUIT
call glutAttachMenu(GLUT_RIGHT_BUTTON)
End Subroutine make_menu
! ------------
subroutine menu_handler(value)
! ------------
use view_modifier
integer(kind=glcint), intent(in out) :: value
! This routine handles the first level entries in the menu
select case(value)
! case(10) !RESET)
! call reset_to_init
case(11)! ABOVE)
call view_from_above
case(12) !QUIT)
stop
end select
return
end subroutine menu_handler
Subroutine does_nothing(value)
implicit None
integer, intent(in out) :: value
end Subroutine does_nothing
Subroutine draw_mirror(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
Select Case (selection)
Case (mirror_xy)
mxy=.Not.mxy
Call reflect_on_plane('z')
Case (mirror_yz)
myz=.Not.myz
Call reflect_on_plane('x')
Case (mirror_zx)
mzx=.Not.mzx
Call reflect_on_plane('y')
Case (no_mirror)
mxy=.False.
myz=.False.
mzx=.False.
End Select
End Subroutine draw_mirror
Subroutine general_c_axis(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
! selection=a*10+o
! a= axis (x=1,y=2,z=3)
! o= order of rotation
Implicit None
Integer, Intent(in out) :: selection
Real(kind=glfloat) :: ang
Integer :: kk, a, o
o=mod(selection,10)
a=selection/10
ang=360./o
! write(*,*)"a=",a,"o=",o,selection
Select Case (a)
Case (axis_x)
a_X=.True.
a_Y=.False.
a_Z=.False.
Call rotate_around_axis('x',ang)
Case (axis_y)
a_X=.False.
a_Y=.True.
a_Z=.False.
Call rotate_around_axis('y',ang)
Case (axis_z)
a_X=.False.
a_Y=.False.
a_Z=.True.
Call rotate_around_axis('z',ang)
Case (no_axis)
a_X=.False.
a_Y=.False.
a_Z=.False.
ghosts=.False.
End Select
End Subroutine general_c_axis
Subroutine general_s_axis(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
Real(kind=glfloat) :: ang
Integer :: kk,a,o
! selection=a*10+o
! a= axis (x=1,y=2,z=3)
! o= order of improper rotation
o=mod(selection,10)
a=selection/10
ang=360./o
! write(*,*)"a=",a,"o=",o,selection
Select Case (a)
Case (axis_x)
a_X=.True.
a_Y=.False.
a_Z=.False.
Call improper_rotation('x',ang)
Case (axis_y)
a_X=.False.
a_Y=.True.
a_Z=.False.
Call improper_rotation('y',ang)
Case (axis_z)
a_X=.False.
a_Y=.False.
a_Z=.True.
Call improper_rotation('z',ang)
Case (no_axis)
a_X=.False.
a_Y=.False.
a_Z=.False.
ghosts=.False.
End Select
End Subroutine general_s_axis
Subroutine draw_axis(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
Real(kind=glfloat) :: ang
Integer :: kk
Select Case (selection)
Case (axis_x)
a_X=.Not.a_X
Write(*,'(a)',advance='no')'Rotation angle= '
Read(*,*)ang
Call rotate_around_axis('x',ang)
Case (axis_y)
a_Y=.Not.a_Y
Write(*,'(a)',advance='no')'Rotation angle= '
Read(*,*)ang
Call rotate_around_axis('y',ang)
Case (axis_z)
Write(*,'(a)',advance='no')'Rotation angle= '
Read(*,*)ang
a_Z=.Not.a_Z
Call rotate_around_axis('z',ang)
Case (no_axis)
a_X=.False.
a_Y=.False.
a_Z=.False.
ghosts=.False.
End Select
End Subroutine draw_axis
Subroutine draw_improper(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
Real(kind=glfloat) :: ang
Integer :: kk
Select Case (selection)
Case (axis_x)
a_X=.True.
Write(*,'(a)',advance='no')'Rotation angle= '
Read(*,*)ang
Call improper_rotation('x',ang)
Case (axis_y)
Write(*,'(a)',advance='no')'Rotation angle= '
Read(*,*)ang
a_Y=.True.
Call improper_rotation('y',ang)
Case (axis_z)
Write(*,'(a)',advance='no')'Rotation angle= '
Read(*,*)ang
a_Z=.True.
Call improper_rotation('z',ang)
Case (no_axis)
a_X=.False.
a_Y=.False.
a_Z=.False.
ghosts=.False.
End Select
End Subroutine draw_improper
Subroutine background_color_menu(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
! Real(kind=glclampf), Dimension(4),Save :: background
! Real(kind=glclampf), Dimension(4),Save :: background_default
Select Case (selection)
Case (0) ! Black
background = (/ 0.0_glclampf, 0.0_glclampf, 0.0_glclampf, 1.0_glclampf /)
Case (1) ! White
background= (/ 1.0_glclampf, 1.0_glclampf, 1.0_glclampf, 1.0_glclampf /)
Case (2) ! Grey
background= (/ 127/255.0_glclampf, 127/255.0_glclampf, 127/255.0_glclampf,&
1.0_glclampf /)
Case (3) ! LightGrey
background= (/ 180/255.0_glclampf, 180/255.0_glclampf, 180/255.0_glclampf,&
1.0_glclampf /)
Case (4) ! DarkGrey
background= (/ 50/255.0_glclampf, 50/255.0_glclampf, 50/255.0_glclampf,&
1.0_glclampf /)
Case (5) ! Peachy
background= (/ 205/255.0_glclampf, 179/255.0_glclampf, 139/255.0_glclampf,&
1.0_glclampf /)
Case (6) ! DarkBlue
background= (/ 20/255.0_glclampf, 20/255.0_glclampf, 80/255.0_glclampf,&
1.0_glclampf /)
Case (7) ! DarkGreen
background= (/ 20/255.0_glclampf, 80/255.0_glclampf, 20/255.0_glclampf,&
1.0_glclampf /)
Case (8) ! Default
background= background_default
End Select
Call glClearColor(background(1),background(2),background(3),background(4))
! write(*,*)background,'sub'
End Subroutine background_color_menu
Subroutine invert_menu(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
! inversion=.not.inversion
Call invert_around_center()
End Subroutine invert_menu
Subroutine lights_menu(selection)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Integer, Intent(in out) :: selection
Select Case (selection)
Case (0)
light0_on=.not. light0_on
if (light0_on) then
call glEnable(GL_LIGHT0)
else
call glDisable(GL_LIGHT0)
endif
Case (1)
light1_on=.not. light1_on
if (light1_on) then
call glEnable(GL_LIGHT1)
else
call glDisable(GL_LIGHT1)
endif
Case (2)
light2_on=.not. light2_on
if (light2_on) then
call glEnable(GL_LIGHT2)
else
call glDisable(GL_LIGHT2)
endif
Case (3)
light3_on=.not. light3_on
if (light3_on) then
call glEnable(GL_LIGHT3)
else
call glDisable(GL_LIGHT3)
endif
End Select
! write(*,*)light0_on,light1_on,light2_on,light3_on
End Subroutine lights_menu
! Subroutine does_nothing()
! Use opengl_gl
! Use opengl_glu
! Use opengl_glut
! Implicit None
! Integer, Intent(in out) :: selection
! End Subroutine does_nothing
Subroutine rotate_around_axis(axis,angle)
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Use moving_axis
Implicit None
Character(1), Intent (in) :: axis
Real(kind=glfloat),Parameter :: zero=0.0_glfloat, one=1.0_glfloat
! Character(1) :: axis='x'
Real(kind=glfloat), Dimension (3) :: vec
Real(kind=glfloat) :: spin=zero
Real(kind=glfloat) :: angle,factor, c1,s1,c2,s2
Integer :: kk,steps=12
! write(*,*)'im SO here!'
! write(*,*)moving_a, esfera2D
Select Case (axis)
Case ('x')
if (moving_a) then
! c1=cos(esfera2D(1)*PI/180)
! s1=sin(esfera2D(1)*PI/180)
! c2=cos(esfera2D(2)*PI/180)
! s2=sin(esfera2D(2)*PI/180)
! vec= (/c1, -s1*c2, s1*s2 /)
! vec= (/ 2*c1*s1**2*c2-2*c1*s1**2+c1, (2*s1**3-2*s1)*c2-2*s1**3+s1, 2*c1*s1*s2 /)
vec= ex
else
vec= (/ one, zero, zero /)
endif
Case ('y')
if (moving_a) then
! c1=cos(esfera2D(1)*PI/180)
! s1=sin(esfera2D(1)*PI/180)
! c2=cos(esfera2D(2)*PI/180)
! s2=sin(esfera2D(2)*PI/180)
! vec= (/ s1, c1*c2, -c1*s2/)
! vec= (/ (1-2*c1**2)*s1*c2+2*c1**2*s1, (2*c1**3-c1)*c2-2*c1**3+2*c1, (1-2*c1**2)*s2 /)
vec= ey
else
vec= (/ zero, one, zero /)
endif
Case ('z')
if (moving_a) then
! c1=cos(esfera2D(1)*PI/180)
! s1=sin(esfera2D(1)*PI/180)
! c2=cos(esfera2D(2)*PI/180)
! s2=sin(esfera2D(2)*PI/180)
! vec= (/ zero, s2, c2 /)
! vec= (/ -s1*s2, c1*s2, c2/)
vec= ez
else
vec= (/ zero, zero, one /)
endif
Case default
write(*,*) 'dunno how to rotate around that axis '//axis
Stop
End Select
steps=steps/slow
factor=angle/steps
Do kk=0,steps
spin=kk*factor
Call glClear(Ior(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
Call glPushMatrix()
Call glCallList(axis_list)
If (moving_a) then
! call glPushMatrix()
! call glRotated(esfera2D(1), 0.0_gldouble, 0.0_gldouble, 1.0_gldouble)
! call glRotated(esfera2D(2), cos(PI*esfera2d(1)/180.0_gldouble), &
! -sin(PI*esfera2D(1)/180.0_gldouble), 0.0_gldouble)
Call glCallList(moving_axis_list)
! !
! !
! !
! x2(1-c)+c xy(1-c)-zs xz(1-c)+ys 0 !
! yx(1-c)+zs y2(1-c)+c yz(1-c)-xs 0 !
! xz(1-c)-ys yz(1-c)+xs z2(1-c)+c 0 !
! 0 0 0 1 !
! !
! Where c=cos(angle), s=sin(angle), and ||(x,y,z)||=1 (if not, the GL !
! will normalize this vector). !
! !
! Call glPopMatrix()
endif
If (atoms) Call glCallList(atoms_list)
If (bonds) Call glCallList(bonds_list)
if (moving_a) then
call glPushMatrix()
call glRotated(esfera2D(1), 0.0_gldouble, 0.0_gldouble, 1.0_gldouble)
call glRotated(esfera2D(2), cos(PI*esfera2d(1)/180.0_gldouble), &
-sin(PI*esfera2D(1)/180.0_gldouble), 0.0_gldouble)
If (mxy) call create_mirror_list('z')
If (myz) call create_mirror_list('x')
If (mzx) call create_mirror_list('y')
If (a_x) Call draw_axis_list('x')
If (a_y) Call draw_axis_list('y')
If (a_z) Call draw_axis_list('z')
call glPopMatrix()
else
If (mxy) Call glCallList(mirrorXY_list)
If (myz) Call glCallList(mirrorYZ_list)
If (mzx) Call glCallList(mirrorZX_list)
If (a_x) Call glCallList(axisX_list)
If (a_y) Call glCallList(axisY_list)
If (a_z) Call glCallList(axisZ_list)
endif
Call glPopMatrix()
Call glPushMatrix()
If (real_size>maxsize) Then
scale=maxsize/real_size
Call glScalef(scale,scale,scale)
Endif
Call glRotatef(spin,vec(1),vec(2),vec(3))
Call glCallList(ghosts_list)
Call glFlush()
Call glutSwapBuffers()
If (real_size>maxsize) Then
scale=maxsize/real_size
Call glScalef(1/scale,1/scale,1/scale)
Endif
Call glPopMatrix()
End Do
spin=steps*factor
Call glNewList(ghosts_list_stay,GL_COMPILE)
Call glPushMatrix()
If (real_size>maxsize) Then
scale=maxsize/real_size
Call glScalef(scale,scale,scale)
Endif
Call glRotatef(spin,vec(1),vec(2),vec(3))
Call glCallList(ghosts_list)
If (real_size>maxsize) Then
scale=maxsize/real_size
Call glScalef(1/scale,1/scale,1/scale)
Endif
Call glPopMatrix()
Call glEndList()
ghosts=.True.
End Subroutine rotate_around_axis
Subroutine invert_around_center()
Use opengl_gl
! Use opengl_glu
Use opengl_glut
Implicit None
Real(kind=glfloat),Parameter :: zero=0.0_glfloat, one=1.0_glfloat
Real(kind=glfloat), Dimension (:,:),Allocatable :: vel
Integer :: kk,steps=12,natoms,jj, istat
natoms=Ubound(molecule,1)
Allocate(vel(1:natoms,1:3),stat=istat)
If (istat/=0) Stop 'Failed to allocate vel'
steps=steps/slow
Do kk=1,natoms
Do jj=1,3
vel(kk,jj)=-2*molecule(kk)%coords(jj)/steps
End Do
End Do
Do kk=0,steps
Call glClear(Ior(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
Call glPushMatrix()
Call glCallList(axis_list)
! If (moving_a) Call glCallList(moving_axis_list)
If (moving_a) then
! call glPushMatrix()
! call glRotated(esfera2D(1), 0.0_gldouble, 0.0_gldouble, 1.0_gldouble)
! call glRotated(esfera2D(2), cos(PI*esfera2d(1)/180.0_gldouble), &
! -sin(PI*esfera2D(1)/180.0_gldouble), 0.0_gldouble)
Call glCallList(moving_axis_list)
! call glPopMatrix()
endif
If (atoms) Call glCallList(atoms_list)
If (bonds) Call glCallList(bonds_list)
if (moving_a) then
call glPushMatrix()
call glRotated(esfera2D(1), 0.0_gldouble, 0.0_gldouble, 1.0_gldouble)
call glRotated(esfera2D(2), cos(PI*esfera2d(1)/180.0_gldouble), &
-sin(PI*esfera2D(1)/180.0_gldouble), 0.0_gldouble)
If (mxy) call create_mirror_list('z')
If (myz) call create_mirror_list('x')
If (mzx) call create_mirror_list('y')
If (a_x) Call draw_axis_list('x')
If (a_y) Call draw_axis_list('y')
If (a_z) Call draw_axis_list('z')
call glPopMatrix()
else
If (mxy) Call glCallList(mirrorXY_list)
If (myz) Call glCallList(mirrorYZ_list)
If (mzx) Call glCallList(mirrorZX_list)
If (a_x) Call glCallList(axisX_list)
If (a_y) Call glCallList(axisY_list)
If (a_z) Call glCallList(axisZ_list)
endif
Call glPopMatrix()
Call glPushMatrix()
If (real_size>maxsize) Then
scale=maxsize/real_size
Call glScalef(scale,scale,scale)
Endif
Do jj=1,natoms
molecule_OP(jj)%coords(1)=molecule(jj)%coords(1)+vel(jj,1)*kk
molecule_OP(jj)%coords(2)=molecule(jj)%coords(2)+vel(jj,2)*kk
molecule_OP(jj)%coords(3)=molecule(jj)%coords(3)+vel(jj,3)*kk
Enddo