-
Notifications
You must be signed in to change notification settings - Fork 0
/
postproc.f
9139 lines (8948 loc) · 342 KB
/
postproc.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
module postproc
implicit none
contains
c---------------------------------------------------------------------
subroutine locpotav(fincoords,finformat,direction,avlength)
! averages VASP LOCPOT file in a chosen direction (1,2,3)
use defs
use misc
use readcoords
implicit none
character(len=*), intent(in) :: fincoords,finformat
integer, intent(in) :: direction
double precision, intent(in) :: avlength
! local variables:
type(atom), allocatable :: atoms(:)
type(element), allocatable :: species(:)
integer natoms, nspecies,ngrid(1:3)
integer i,j,jstart,jend,navmacro,navmacro_half,jtrue
double precision vecs(1:3,1:3)!,vol
double precision, allocatable :: potarr(:,:,:),potav(:)
double precision, allocatable :: potavmacro(:)
character(len=256) :: line
!
if(talk) print fsubstart,"locpotav"
if (talk) print '(8x,"averageing file: ",A40)',fincoords
if (direction.ne.1.and.direction.ne.2.and.direction.ne.3) then
goto 100
end if
!
! read coordinate and cell information
call read_coords(fincoords,finformat,atoms,natoms,species,
& nspecies,vecs)
open(51,file=fincoords,status='old',err=101)
! skip "header"
do i=1,natoms+9
read(51,'(A256)',err=101,end=101) line
end do
! read grid dimensions
read(51,*) ngrid(1:3)
print*, "grid dimensions:",ngrid(1:3)
allocate(potarr(ngrid(1),ngrid(2),ngrid(3)))
read(51,*) potarr(1:ngrid(1),1:ngrid(2),1:ngrid(3))
close(51)
!
! begin average
allocate(potav(ngrid(direction)))
do i=1,ngrid(direction)
potav(i)=0.0d0
if(direction==1) then
do j=1,ngrid(2)
potav(i)=potav(i)+sum(potarr(i,j,:))
end do
end if
if(direction==2) then
do j=1,ngrid(1)
potav(i)=potav(i)+sum(potarr(j,i,:))
end do
end if
if(direction==3) then
do j=1,ngrid(1)
potav(i)=potav(i)+sum(potarr(j,:,i))
end do
end if
end do
! end average
! begin write average
!call vecs2vol(vecs,vol)
potav=potav*dble(ngrid(direction)) &
& /(dble(ngrid(1)*ngrid(2)*ngrid(3)))
open(51,file="LOCPOTAV",status='replace')
do i=1,ngrid(direction)
write(51,*) dble(i)/dble(ngrid(direction)),potav(i)
end do
close(51)
! end write average
deallocate(potarr)
!
! begin calculate and write macroscopic (sliding window) average
allocate(potavmacro(ngrid(direction)))
navmacro=ceiling(ngrid(direction)*avlength)
navmacro_half=int(navmacro/2)
do i=1,ngrid(direction)
!print*, "i=",i
potavmacro(i)=0.0d0
jstart=i-navmacro_half
jend=jstart+navmacro-1
!print*, "jstart,jend=",jstart,jend
do j=jstart,jend
jtrue=j
do while (jtrue.gt.ngrid(direction))
jtrue=jtrue-ngrid(direction)
end do
do while (jtrue.lt.1)
jtrue=jtrue+ngrid(direction)
end do
potavmacro(i)=potavmacro(i)+potav(jtrue)
end do
end do
potavmacro=potavmacro/dble(navmacro)
open(51,file="LOCPOTAVMACRO",status='replace')
do i=1,ngrid(direction)
write(51,*) dble(i)/dble(ngrid(direction)),potavmacro(i)
end do
close(51)
! end calculate and write macroscopic average
deallocate(potav)
deallocate(potavmacro)
!
! end normally:
if(talk) print fsubendext, "locpotav"
return
!
! Errors:
100 nerr=nerr+1
print ferrmssg," direction has to be 1,2, or 3 (cofima --help)"
close(51)
return
101 nerr=nerr+1
print ferrmssg," when opening/reading LOCPOT file"
close(51)
return
end subroutine locpotav
c---------------------------------------------------------------------
subroutine get_com(file1,format1)
use defs
use misc
use readcoords
implicit none
! calculates the Center Of Molecule
!
! variables
character(len=*), intent(in) :: file1,format1
! internal variables
type(atom),allocatable :: atoms(:)
type(element),allocatable :: species(:)
double precision vecs(1:3,1:3),com(1:3)
integer natoms,nspecies
integer iatom
!
if(talk) print fsubstart,"get_com"
if (talk) print '(8x,"file: ",A40)',file1
if (talk) print '(8x,"format: ",A40)',format1
!
! begin read coordinates from file
call read_coords(file1,format1,atoms,natoms,species,
& nspecies,vecs)
!print*,vecs
! end read coordinates from file
!
! begin calculate com
com=0.0d0
do iatom=1,natoms
!print*,atoms(iatom)%abswhere
!call frac2abs(atoms(iatom)%where,vecs,atoms(iatom)%abswhere)
com=com+atoms(iatom)%abswhere
end do
com=com/dble(natoms)
print '(8x,"COM in Angs (probably):",3(F10.6))',com(1:3)
! end calculate com
!
! end normally:
deallocate(atoms,species)
if(talk) print fsubendext, "get_com"
return
end subroutine get_com
c---------------------------------------------------------------------
subroutine get_comass(file1,format1)
use defs
use misc
use readcoords
implicit none
! calculates the Center Of Molecule
!
! variables
character(len=*), intent(in) :: file1,format1
! internal variables
type(atom),allocatable :: atoms(:)
type(element),allocatable :: species(:)
double precision vecs(1:3,1:3),comass(1:3)
integer natoms,nspecies
integer iatom
!
if(talk) print fsubstart,"get_comass"
if (talk) print '(8x,"file: ",A40)',file1
if (talk) print '(8x,"format: ",A40)',format1
!
! begin read coordinates from file
call read_coords(file1,format1,atoms,natoms,species,
& nspecies,vecs)
!print*,vecs
! end read coordinates from file
!
! begin calculate comass
comass=0.0d0
do iatom=1,natoms
!print*,atoms(iatom)%abswhere
!call frac2abs(atoms(iatom)%where,vecs,atoms(iatom)%abswhere)
comass=comass+atoms(iatom)%abswhere*atoms(iatom)%mass
end do
comass=comass/sum(atoms(:)%mass)
print '(8x,"Center of mass in Angs:",3(F10.6))',comass(1:3)
! end calculate comass
!
! end normally:
deallocate(atoms,species)
if(talk) print fsubendext, "get_comass"
return
end subroutine get_comass
c---------------------------------------------------------------------
subroutine relax_atoms(atoms,vecs,step)
use defs
use misc, only : abs2frac
implicit none
double precision, intent(in) :: step,vecs(1:3,1:3)
type(atom), intent(inout) :: atoms(:)
integer i,natoms
if(talk) print fsubstart,"relax_atoms"
if(talk) print '(8x,"forces are multiplied by ",F10.6)',step
natoms=size(atoms)
if(talk) print '(8x,I6," atoms")',natoms
do i=1,natoms
!print*,atoms(i)%force(1:3)
atoms(i)%abswhere=atoms(i)%abswhere+atoms(i)%force*step
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
if(talk) print fsubendext, "relax_atoms"
return
end subroutine relax_atoms
c---------------------------------------------------------------------
subroutine relax_rigid_molecule(atoms,vecs,step)
use defs
use misc, only : abs2frac,cross_product
use transform, only : rotatecoords
implicit none
double precision, intent(in) :: step,vecs(1:3,1:3)
double precision av_radial_force, delta_r(1:3), radial_force
double precision sum_of_forces(1:3),sum_of_torques(1:3)
double precision angle,vector(1:3),com(1:3)
type(atom), intent(inout) :: atoms(:)
integer i,natoms
if(talk) print fsubstart,"relax_rigid_molecule"
natoms=size(atoms)
sum_of_forces=0.0d0
do i=1,natoms
sum_of_forces=sum_of_forces+atoms(i)%force
end do ! i
! rigid tranlation
print '(8x,"translating molecule by ",3(F12.6,x)," Angs ")', &
& sum_of_forces*step/dble(natoms)
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere+sum_of_forces*step &
& /dble(natoms)
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
!
! move center of molecule (com) to 0
com=0.0d0
do i=1,natoms
com=com+atoms(i)%abswhere
end do
com=com/dble(natoms)
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere-com
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
!
! calculate total torque
sum_of_torques=0.0d0
do i=1,natoms
sum_of_torques=sum_of_torques+cross_product(atoms(i)%abswhere, &
& atoms(i)%force)
end do
!
! rigid rotation
!angle=norm2(sum_of_torques)*step/dble(natoms)
angle=norm2(sum_of_torques)*step
if (angle.gt.0.0d0) then
vector=sum_of_torques/norm2(sum_of_torques) ! not really needed, just for neat output
else
vector=0.0d0
vector(1)=1.0d0
end if
print '(8x,"rotating molecule by ",F9.3," degrees around ", &
& 3(F9.3,x))', angle, vector
call rotatecoords(atoms,vecs,0,angle,vector)
!
! move com back
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere+com
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
! expand or shrink molecule
av_radial_force=0.0d0
! calculate average radial force
do i=1,natoms
if (norm2(atoms(i)%abswhere-com).gt.0.0d0) then
radial_force=dot_product(atoms(i)%force,atoms(i)%abswhere-com) &
& /(norm2(atoms(i)%abswhere-com))**2
else
radial_force=0.0d0
end if
av_radial_force=av_radial_force + radial_force
end do ! i
av_radial_force=av_radial_force/dble(natoms)
! rigid breathing
print '(8x," expanding molecule by ",3(F12.6,x)," Angs ")', &
& av_radial_force*step
do i=1,natoms
delta_r=(atoms(i)%abswhere-com)*av_radial_force*step
atoms(i)%abswhere=atoms(i)%abswhere+delta_r
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
if(talk) print fsubendext, "relax_rigid_molecule"
return
end subroutine relax_rigid_molecule
c---------------------------------------------------------------------
subroutine relax_rigid_molecule_rot(atoms,vecs,step)
use defs
use misc, only : abs2frac,cross_product
use transform, only : rotatecoords
implicit none
double precision, intent(in) :: step,vecs(1:3,1:3)
double precision sum_of_torques(1:3)
double precision angle,vector(1:3),com(1:3)
type(atom), intent(inout) :: atoms(:)
integer i,natoms
if(talk) print fsubstart,"relax_rigid_molecule_rot"
natoms=size(atoms)
!
! move center of molecule (com) to 0
com=0.0d0
do i=1,natoms
com=com+atoms(i)%abswhere
end do
com=com/dble(natoms)
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere-com
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
!
! calculate total torque
sum_of_torques=0.0d0
do i=1,natoms
sum_of_torques=sum_of_torques+cross_product(atoms(i)%abswhere, &
& atoms(i)%force)
end do
!
! rigid rotation
!angle=norm2(sum_of_torques)*step/dble(natoms)
angle=norm2(sum_of_torques)*step
if (angle.gt.0.0d0) then
vector=sum_of_torques/norm2(sum_of_torques) ! not really needed, just for neat output
else
vector=0.0d0
vector(1)=1.0d0
end if
print '(8x,"rotating molecule by ",F9.3," degrees around ", &
& 3(F9.3,x))', angle, vector
call rotatecoords(atoms,vecs,0,angle,vector)
!
! move com back
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere+com
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
if(talk) print fsubendext, "relax_rigid_molecule_rot"
return
end subroutine relax_rigid_molecule_rot
c---------------------------------------------------------------------
subroutine relax_rigid_molecule_rot2(atoms,vecs,step)
! same as relax_rigid_molecule_rot, but with a different way to
! calculate the total rotation angle and axis
use defs
use misc, only : abs2frac,cross_product
use transform, only : rotatecoords
implicit none
double precision, intent(in) :: step,vecs(1:3,1:3)
double precision sum_of_torques(1:3)
double precision angle,vector(1:3),com(1:3)
type(atom), intent(inout) :: atoms(:)
integer i,natoms
if(talk) print fsubstart,"relax_rigid_molecule_rot2"
natoms=size(atoms)
!
! move center of molecule (com) to 0
com=0.0d0
do i=1,natoms
com=com+atoms(i)%abswhere
end do
com=com/dble(natoms)
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere-com
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
!
! calculate average rotation angle and axis
sum_of_torques=0.0d0
do i=1,natoms
sum_of_torques=sum_of_torques+cross_product(atoms(i)%abswhere, &
& atoms(i)%force)/norm2(atoms(i)%abswhere)**2
end do
sum_of_torques=sum_of_torques/dble(natoms)
!
! rigid rotation
angle=norm2(sum_of_torques)*step*360.0d0/(2.0d0*Pi)
if (angle.gt.0.0d0) then
vector=sum_of_torques/norm2(sum_of_torques) ! not really needed, just for neat output
else
vector=0.0d0
vector(1)=1.0d0
end if
print '(8x,"rotating molecule by ",F9.3," degrees around ", &
& 3(F9.3,x))', angle, vector
call rotatecoords(atoms,vecs,0,angle,vector)
!
! move com back
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere+com
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
if(talk) print fsubendext, "relax_rigid_molecule_rot2"
return
end subroutine relax_rigid_molecule_rot2
c---------------------------------------------------------------------
subroutine relax_rigid_molecule_trala(atoms,vecs,step)
use defs
use misc, only : abs2frac
implicit none
double precision, intent(in) :: step,vecs(1:3,1:3)
double precision sum_of_forces(1:3)
double precision angle,vector(1:3)
type(atom), intent(inout) :: atoms(:)
integer i,natoms
if(talk) print fsubstart,"relax_rigid_molecule_trala"
natoms=size(atoms)
sum_of_forces=0.0d0
do i=1,natoms
sum_of_forces=sum_of_forces+atoms(i)%force
end do ! i
! rigid tranlation
print '(8x,"translating molecule by ",3(F12.6,x)," Angs ")', &
& sum_of_forces*step/dble(natoms)
do i=1,natoms
atoms(i)%abswhere=atoms(i)%abswhere+sum_of_forces*step &
& /dble(natoms)
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
!
if(talk) print fsubendext, "relax_rigid_molecule_trala"
return
end subroutine relax_rigid_molecule_trala
c---------------------------------------------------------------------
subroutine relax_rigid_molecule_breath(atoms,vecs,step)
use defs
use misc, only : abs2frac
implicit none
double precision, intent(in) :: step,vecs(1:3,1:3)
double precision av_radial_force,radial_force,com(1:3)
double precision delta_r(1:3),tol
type(atom), intent(inout) :: atoms(:)
integer i,natoms
if(talk) print fsubstart,"relax_rigid_molecule_breath"
natoms=size(atoms)
av_radial_force=0.0d0
tol=1.0E-3 ! in Angs. Only atoms with a minimum distance from the center of molecule are relaxed (numerical reasons)
! get center of molecule (com)
com=0.0d0
do i=1,natoms
com=com+atoms(i)%abswhere
end do
com=com/dble(natoms)
print '(8x,"center of molecule at ",3(F12.6))',com
! calculate average radial force
do i=1,natoms
if (norm2(atoms(i)%abswhere-com).gt.tol) then
radial_force=dot_product(atoms(i)%force,atoms(i)%abswhere-com) &
& /(norm2(atoms(i)%abswhere-com))**2
print '(8x,"radial force acts on atom ",I0,x,A2)', &
& i, atoms(i)%name
else
radial_force=0.0d0
end if
av_radial_force=av_radial_force + radial_force
end do ! i
av_radial_force=av_radial_force/dble(natoms)
! rigid breathing
print '(8x," expanding molecule by ",3(F12.6,x)," Angs ")', &
& av_radial_force*step
do i=1,natoms
delta_r=(atoms(i)%abswhere-com)*av_radial_force*step
atoms(i)%abswhere=atoms(i)%abswhere+delta_r
call abs2frac(atoms(i)%abswhere,vecs,atoms(i)%where)
end do
!
if(talk) print fsubendext, "relax_rigid_molecule_breath"
return
end subroutine relax_rigid_molecule_breath
c---------------------------------------------------------------------
subroutine get_xcoulomb(file1,file2,format1,step,finestep,rmin)
use defs
use misc
use readcoords
implicit none
! calculates the classical Coulomb energy of an exciton
!
! variables
character(len=*), intent(in) :: file1,file2,format1
! internal variables
type(atom),allocatable :: atoms(:)
!type(element),allocatable :: species(:)
!double precision vecs(1:3,1:3),
double precision xcoul,enorm,hnorm,rvec1(1:3),rvec2(1:3)
double precision overlap,emom1,emom2,hmom1,hmom2
double precision ecom(1:3),hcom(1:3),e_delta_r(1:3),h_delta_r(1:3)
double precision dx,dy,dz,d3r,origin(1:3),rmin,reh
double precision d3rfine,r0
double precision, allocatable :: grid(:,:,:,:),wf1(:,:,:)
double precision, allocatable :: wf2(:,:,:)
integer i1,i2,i3,j1,j2,j3,nx,ny,nz,step
integer k1,k2,k3,l1,l2,l3,finestep
!integer natoms,nspecies
!integer iatom
!
if(talk) print fsubstart,"get_xcoulomb"
if (talk) print '(8x,"files: ",2(A40))',file1,file2
if (talk) print '(8x,"format: ",A40)',format1
!
! begin definitions
print '(8x,"step: ",I0)', step
print '(8x,"fine step: ",I0)', finestep
print '(8x,"rmin: ",F10.6," * coarse grid spacing")', rmin
! end definitions
!
! begin read cube file
call read_cube(file1,atoms,grid,wf1)
call read_cube(file2,atoms,grid,wf2)
deallocate(atoms)
! end read cube file
!
! begin initialize
xcoul=0.0d0
enorm=0.0d0
ecom=0.0d0 ! center of mass for e density
emom1=0.0d0 ! first radial moment for e density
emom2=0.0d0 ! 2nd radial moment for e density
hnorm=0.0d0
hcom=0.0d0 ! center of mass for h density
hmom1=0.0d0 ! first radial moment for h density
hmom2=0.0d0 ! 2nd radial moment for h density
overlap=0.0d0
nx=size(grid,1)
ny=size(grid,2)
nz=size(grid,3)
dx=(grid(2,1,1,1)-grid(1,1,1,1))*dble(step)
dy=(grid(1,2,1,2)-grid(1,1,1,2))*dble(step)
dz=(grid(1,1,2,3)-grid(1,1,1,3))*dble(step)
origin(1:3)=grid(1,1,1,1:3)
rmin=rmin*max(max(dx,dy),dz)
d3r=dx*dy*dz
d3rfine=d3r/dble((2*finestep)**3)
print '(8x,"grid dimension: ",3(I0,1x))',nx,ny,nz
! end initialize
!
! begin calculate density norms and center of mass
do i1=1,nx,step
! print '(8x,"current progress: ",1(F6.1)," %")', &
! & dble(i1-1)/dble(nx)*100.0d0
do i2=1,ny,step
do i3=1,nz,step
rvec1(1:3) = grid(i1,i2,i3,1:3)
enorm=enorm+wf1(i1,i2,i3)*d3r
ecom=ecom+wf1(i1,i2,i3)*rvec1(1:3)*d3r
hnorm=hnorm+wf2(i1,i2,i3)*d3r
hcom=hcom+wf2(i1,i2,i3)*rvec1(1:3)*d3r
end do ! i3
end do ! i2
end do ! i1
! end calculate density norms and center of mass
!
! begin calculate density moments
do i1=1,nx,step
! print '(8x,"current progress: ",1(F6.1)," %")', &
! & dble(i1-1)/dble(nx)*100.0d0
do i2=1,ny,step
do i3=1,nz,step
rvec1(1:3) = grid(i1,i2,i3,1:3)
e_delta_r(1:3)=rvec1(1:3)-ecom(1:3)
h_delta_r(1:3)=rvec1(1:3)-hcom(1:3)
emom1=emom1+wf1(i1,i2,i3)*absvec(e_delta_r)*d3r
emom2=emom2+wf1(i1,i2,i3)*dot_product(e_delta_r,e_delta_r)*d3r
hmom1=hmom1+wf2(i1,i2,i3)*absvec(h_delta_r)*d3r
hmom2=hmom2+wf2(i1,i2,i3)*dot_product(h_delta_r,h_delta_r)*d3r
end do ! i3
end do ! i2
end do ! i1
!
print '(8x,"e WF norm:",1(F10.6))',enorm
print '(8x,"e WF com:",3(F10.6))',ecom
print '(8x,"e WF mom1:",1(F10.6))',emom1
print '(8x,"e WF mom2:",3(F10.6))',emom2
print '(8x,"h WF norm:",1(F10.6))',hnorm
print '(8x,"h WF com:",3(F10.6))',hcom
print '(8x,"h WF mom1:",1(F10.6))',hmom1
print '(8x,"h WF mom2:",3(F10.6))',hmom2
! end calculate density moments
!
!
if (finestep<0) then
if(allocated(atoms)) deallocate(atoms)
if(allocated(grid)) deallocate(grid)
if(allocated(wf1)) deallocate(wf1)
if(allocated(wf2)) deallocate(wf2)
if(talk) print fsubendext, "get_xcoulomb"
return
end if
!
! begin calculate Coulomb energy and overlaps
! enorm=0.0d0
! hnorm=0.0d0
do i1=1,nx,step
print '(8x,"current progress: ",1(F6.1)," %")', &
& dble(i1-1)/dble(nx)*100.0d0
do i2=1,ny,step
!print '(8x,"current y grid index: ",1(I0))',i2
do i3=1,nz,step
rvec1(1:3) = grid(i1,i2,i3,1:3)
! enorm=enorm+wf1(i1,i2,i3)*d3r
! hnorm=hnorm+wf2(i1,i2,i3)*d3r
overlap=overlap+sqrt(abs(wf1(i1,i2,i3)*wf2(i1,i2,i3)))*d3r
do j1=1,nx,step
do j2=1,ny,step
do j3=1,nz,step
! if (.not.(i1==j1.and.i2==j2.and.i3==j3)) then
rvec2(1:3) = grid(j1,j2,j3,1:3)
reh=dot_product(rvec1-rvec2,rvec1-rvec2)**0.5d0
if (reh.gt.rmin) then
xcoul=xcoul-wf1(i1,i2,i3)*wf2(j1,j2,j3)*d3r**2/reh
else
if (.not.(i1==j1.and.i2==j2.and.i3==j3)) then
! treat region with r_eh<=rmin with fine grid
!print '(8x,"Entering fine grid")'
do k1=-finestep,finestep-1
do k2=-finestep,finestep-1
do k3=-finestep,finestep-1
do l1=-finestep,finestep-1
do l2=-finestep,finestep-1
do l3=-finestep,finestep-1
rvec1(1:3)=grid(i1,i2,i3,1:3) &
& +(/dble(k1)*dx,dble(k2)*dy,dble(k3)*dz/) &
& /dble(2*finestep)
rvec2(1:3)=grid(j1,j2,j3,1:3) &
& +(/dble(l1)*dx,dble(l2)*dy,dble(l3)*dz/) &
& /dble(2*finestep)
reh=dot_product(rvec1-rvec2,rvec1-rvec2)**0.5d0
if(reh.gt.0.0d0) then
xcoul=xcoul-wf1(i1,i2,i3)*wf2(j1,j2,j3) &
& *d3rfine**2/reh
end if
end do
end do
end do
end do
end do
end do
else
! use spherical average near r=0:
r0=(3.0d0*d3r/(4.0d0*Pi))**(1.0d0/3.0d0)
xcoul=xcoul-wf1(i1,i2,i3)*wf2(j1,j2,j3)*2.0d0*Pi*r0**2
end if ! (.not.(i1==j1.and.i2==j2.and.i3==j3))
! end if
end if
end do
end do
end do
end do
end do
end do
print '(8x,"E_Coulomb(X) in Hartree:",1(F10.6))',xcoul
print '(8x,"E_Coulomb(X) in eV:",1(F10.6))',xcoul*hartree
print '(8x,"e WF norm:",1(F10.6))',enorm
print '(8x,"h WF norm:",1(F10.6))',hnorm
print '(8x,"e-h density overlap:",1(F10.6))',overlap
! begin calculate Coulomb energy and overlaps
!
! end normally:
deallocate(grid,wf1,wf2)
if(talk) print fsubendext, "get_xcoulomb"
return
end subroutine get_xcoulomb
c---------------------------------------------------------------------
subroutine get_ekin(file1,format1,step)
use defs
use misc
use readcoords
implicit none
! calculates the kinetic energy of a WF
!
! variables
character(len=*), intent(in) :: file1,format1
! internal variables
type(atom),allocatable :: atoms(:)
!type(element),allocatable :: species(:)
!double precision vecs(1:3,1:3),
double precision ekin,enorm
double precision dx,dy,dz,d3r,origin(1:3)
double precision r0
double precision nabla_psi(1:3)
double precision, allocatable :: grid(:,:,:,:)
double precision, allocatable :: wf1(:,:,:)
integer i1,i2,i3,nx,ny,nz,step
!
if(talk) print fsubstart,"get_ekin"
if (talk) print '(8x,"file: ",1(A40))',file1
if (talk) print '(8x,"format: ",A40)',format1
!
! begin definitions
print '(8x,"step: ",I0)', step
! end definitions
!
! begin read cube file
call read_cube(file1,atoms,grid,wf1)
deallocate(atoms)
! end read cube file
!
! begin calculate ekin
ekin=0.0d0
enorm=0.0d0
nx=size(grid,1)
ny=size(grid,2)
nz=size(grid,3)
dx=(grid(2,1,1,1)-grid(1,1,1,1))*dble(step)
dy=(grid(1,2,1,2)-grid(1,1,1,2))*dble(step)
dz=(grid(1,1,2,3)-grid(1,1,1,3))*dble(step)
origin(1:3)=grid(1,1,1,1:3)
d3r=dx*dy*dz
print '(8x,"grid dimension: ",3(I0,1x))',nx,ny,nz
do i1=2,nx-1,step
print '(8x,"current progress: ",1(F6.1)," %")', &
& dble(i1-1)/dble(nx)*100.0d0
do i2=2,ny-1,step
do i3=2,nz-1,step
enorm=enorm+wf1(i1,i2,i3)*d3r
nabla_psi(1:3)=(/(sqrt(abs(wf1(i1+1,i2,i3))) &
& -sqrt(abs(wf1(i1-1,i2,i3))))/dx, &
& (sqrt(abs(wf1(i1,i2+1,i3))) &
& -sqrt(abs(wf1(i1,i2-1,i3))))/dy, &
& (sqrt(abs(wf1(i1,i2,i3+1))) &
& -sqrt(abs(wf1(i1,i2,i3-1))))/dz/)/2.0d0
ekin=ekin+0.50d0*dot_product(nabla_psi,nabla_psi)*d3r
end do
end do
end do
print '(8x,"E_kin in Hartree:",1(F10.6))',ekin
print '(8x,"E_kin in eV:",1(F10.6))',ekin*hartree
print '(8x,"e WF norm:",1(F10.6))',enorm
! end calculate xcoul
!
! end normally:
deallocate(grid,wf1)
if(talk) print fsubendext, "get_ekin"
return
end subroutine get_ekin
c---------------------------------------------------------------------
subroutine read_cube(file1,atoms,grid,wf)
use defs
implicit none
! reads WF or density from cube file
! variables
character(len=*), intent(in) :: file1
double precision, allocatable :: wf(:,:,:),grid(:,:,:,:)
type(atom),allocatable :: atoms(:)
!type(element),allocatable :: species(:)
! internal variables
character line*1024
integer natoms,nx(1:3)
integer iatom,atnum,i1,i2,i3
double precision xmin(1:3),amin,rdum
!double precision xgrid(1:3)
! ************************************************
! read cube file header
!
open(51,file=file1,err=100)
read(51,'(A256)',err=100,end=100) line
read(51,'(A256)',err=100,end=100) line
!write (10+it,'(A)') "OUTER LOOP: X, MIDDLE LOOP: Y, INNER LOOP: Z"
read(51,'(I6,F10.5,F10.5,F10.5)') natoms,xmin(1),xmin(2),xmin(3)
read(51,'(I6,F10.5,F10.5,F10.5)') nx(1),amin,rdum,rdum
read(51,'(I6,F10.5,F10.5,F10.5)') nx(2),rdum,amin,rdum
read(51,'(I6,F10.5,F10.5,F10.5)') nx(3),rdum,rdum,amin
! read atoms positions
if(allocated(atoms)) deallocate(atoms)
allocate(atoms(natoms))
do iatom=1,natoms
read(51,'(I6,F10.5,F10.5,F10.5,F10.5)') atnum,rdum, &
& atoms(iatom)%abswhere(1:3)
atoms(iatom)%abswhere=atoms(iatom)%abswhere*bohr
atoms(iatom)%name=elements(atnum)
end do
!
print '(8x,"natoms: ",I0)', natoms
!
! End read cube file header
! ************************************************
! ************************************************
! loop on the grid
if(allocated(grid)) deallocate(grid)
allocate(grid(nx(1),nx(2),nx(3),1:3))
allocate(wf(nx(1),nx(2),nx(3)))
!
do i1=1,nx(1)
do i2=1,nx(2)
do i3=1,nx(3)
! get grid point position
grid(i1,i2,i3,1) = xmin(1) + dble(i1-1)*amin
grid(i1,i2,i3,2) = xmin(2) + dble(i2-1)*amin
grid(i1,i2,i3,3) = xmin(3) + dble(i3-1)*amin
! get wf or density
read(51,'(E14.6)') wf(i1,i2,i3)
end do
end do
end do
close(51)
return
100 nerr=nerr+1
close(51)
print ferrmssg,'Coul not open/read cube file.'
return
end subroutine read_cube
c---------------------------------------------------------------------
subroutine get_vasp_bandstructure(lattice,nskip)
use defs
use misc, only: frac2abs
implicit none
character*1024 :: eigenval,outcar,line,xtics
character*1024 :: formatstring
integer nskip ! number of kpoints to skip in plot at the beginning of the kpoint list
character lattice ! lattice type, e.g. hex,cubic..
integer nbands,iband,nkpoints,ikpoint,nele,iline,idum
integer iwrite,iread,i1
logical spinpol,has_G,has_X,has_R,has_M
double precision, allocatable :: eigenvalues_up(:,:)
double precision, allocatable :: eigenvalues_down(:,:)
double precision, allocatable :: k(:,:),kabs(:,:),svec(:)
double precision s,tol,efermi,gvecs(3,3),fdum
!
print fsubstart,'get_vasp_bandstructure'
!
! begin initialize
!
eigenval="EIGENVAL"
outcar="OUTCAR"
s=0.0d0
spinpol=.false.
has_G=.false.
has_X=.false.
has_R=.false.
has_M=.false.
tol=1D-4
!
! end initialize
!
!
! begin read Fermi energy and reciprocal lattice vectors
!
open(51,file=outcar,status='old')
10 read(51,'(A256)',err=100,end=20) line
if(index(line,'E-fermi').gt.0) then
iread=index(line,'E-fermi')+9
read(line(iread:),*) efermi
end if
if (index(line,'reciprocal lattice vectors').gt.0) then
do i1=1,3
read (51,*,end=20,err=100) fdum,fdum,fdum,gvecs(i1,1:3)
end do
gvecs=gvecs*2.0d0*pi
end if
goto 10
!
20 continue
close(51)
print '(8x,"reciprocal lattice vecs:",3(/,8x,3(F12.6)))', &
& (gvecs(i1,1:3),i1=1,3)
!
! end read Fermi energy and reciprocal lattice vectors
!
open(51,file=eigenval, status='old')
!
! begin read nbands, nkpoints
!
read(51,*,end=100,err=100) idum,idum,idum, idum
if (idum==2) spinpol=.true.
do iline=1,4
read(51,'(A1024)',end=100,err=100) line
end do
read(51,*,end=100,err=100) nele,nkpoints,nbands
!print '(8x,3(1x,I0))',nele,nkpoints,nbands
allocate(k(1:nkpoints,1:3),eigenvalues_up(nkpoints,nbands))
allocate(kabs(1:nkpoints,1:3))
allocate(svec(1:nkpoints))
svec=0.0d0
if(spinpol) allocate(eigenvalues_down(nkpoints,nbands))
!
! end read nbands, nkpoints
!
!
! begin read kpoints and eigenvalues
!
do ikpoint=1,nkpoints
read(51,'(A1024)',end=100,err=100) line
read(51,*,end=100,err=100) k(ikpoint,1:3)
call frac2abs(k(ikpoint,:),gvecs,kabs(ikpoint,:))
do iband=1,nbands
if (.not.spinpol) then
read(51,*,err=100,end=100) idum, &
& eigenvalues_up(ikpoint,iband)
else
read(51,*,err=100,end=100) idum, &
& eigenvalues_up(ikpoint,iband), &
& eigenvalues_down(ikpoint,iband)
end if
end do
end do
close(51)
!
! end read kpoints and eigenvalues
!
!
! begin print eigenvalues