-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommod.f90
More file actions
1063 lines (930 loc) · 29.2 KB
/
Copy pathcommod.f90
File metadata and controls
1063 lines (930 loc) · 29.2 KB
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) 2021 Chee Kwan Gan (ihpcganck@gmail.com)
! Copyright (C) 2020 Chee Kwan Gan (ihpcganck@gmail.com)
!
! This program 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.
!
! This program 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.
!
!
module commod
use sgsym
use derived_constants
implicit none
interface fargv
module procedure getarg_str,getarg_int,getarg_double
end interface
contains
subroutine getarg_str(n,str)
integer :: n
character(len=*) :: str
call get_command_argument(n,str)
end subroutine getarg_str
subroutine getarg_int(n,k)
integer :: n, k
character(len=100) :: tmpstr
call get_command_argument(n,tmpstr)
read(unit=tmpstr,FMT='(I10)') k
end subroutine getarg_int
subroutine getarg_double(n,k)
integer :: n
real(double) :: k
character(len=100) :: tmpstr
call get_command_argument(n,tmpstr)
read(unit=tmpstr,FMT='(D22.15)') k
end subroutine getarg_double
function num2str(v,nspaces) result (str)
integer :: tmpv,i,v,nspaces,digit,ind
character(len=nspaces) :: str
tmpv = v
if(v < 0) then
write(*,'(A)') 'err: v is negative.'
stop 1
endif
do i = 1, nspaces
digit = modulo(tmpv,10)
tmpv = tmpv/10
ind = nspaces-i+1
str(ind:ind) = DIGITARR(digit)
enddo
end function num2str
function str2N(str) result(n)
character(len=*) :: str
integer :: n
read(str,'(I10)') n
end function str2N
function N2str(i) result (str)
integer :: i,j,tmpv,intarr(20),nd,digit
character(len=20) :: str
if(i < 0) then
tmpv = -i
else
tmpv = I
endif
nd = 0
do
digit = modulo(tmpv,10)
nd = nd + 1
intarr(nd) = digit
tmpv = tmpv/10
if(tmpv == 0) exit
enddo
str = ' '
do j = 1, nd
str(j:j) = digitarr(intarr(nd-j+1))
enddo
if(i < 0) then
nd = nd + 1
do j = nd,2,-1
str(j:j) = str(j-1:j-1)
enddo
str(1:1) = '-'
endif
end function N2str
subroutine fargn(n)
integer :: n
integer :: m
m = command_argument_count()
if(n /= m) then
write(*,'(A,I4,A)') 'we need ',n,' arguments'
write(*,'(A)') 'err: check number of arguments'
stop 1
endif
end subroutine fargn
function num_of_strings(tmp)
character(len=*) :: tmp
integer :: num_of_strings
character(len=DSL) :: line
integer,parameter :: max_num_cols = 100
character(len=100) :: test_array(max_num_cols)
integer :: i,io
line = trim(tmp)
write(*,'(A)') 'line is '//trim(line)
do i = 1, max_num_cols
read(line,*,iostat=io) test_array(1:i)
if(io /= 0) then
exit
endif
enddo
num_of_strings = i-1
if(num_of_strings == max_num_cols) then
endif
end function num_of_strings
function num_of_integers(tmp)
character(len=*) :: tmp
integer :: num_of_integers
character(len=DSL) :: line
integer,parameter :: max_num_cols = 100
integer :: test_array(max_num_cols)
integer :: i,io
line = trim(tmp)
write(*,'(A)') 'line is '//trim(line)
do i = 1, max_num_cols
read(line,*,iostat=io) test_array(1:i)
if(io /= 0) then
exit
endif
enddo
num_of_integers = i-1
if(num_of_integers == max_num_cols) then
write(*,*) 'count_int_number= ',num_of_integers
write(*,*) 'err: we may need to increase max_num_cols.'
stop 1
endif
end function num_of_integers
subroutine read_gendata(dstype,fileu,filename,nametag,v,dopt,vdefault,vec)
integer,optional :: vec
integer :: dopt
integer :: dstype,fileu
type(dtype) :: v,vdefault
character(len=*) :: nametag,filename
logical :: done
integer :: ios,s
character(len=DSL) :: str1,str2
logical :: found
integer :: i,j
character(len=DSL) :: tmpstr
if(present(vec)) then
if(vec > DTYPEMAXLEN) then
write(*,*) 'vec= ',vec
write(*,*) 'DTYPEMAXLEN= ',DTYPEMAXLEN
write(*,'(A)') 'err: vec > DTYPEMAXLEN.'
stop 1
endif
endif
found = .false.
v%li = .false.
v%lr = .false.
v%ls = .false.
if(dstype == itype) then
v%li = .true.
else if(dstype == rtype) then
v%lr = .true.
else if(dstype == stype) then
v%ls = .true.
endif
write(*,'(A)') 'Search keyword=|'//trim(nametag)//'| in '//trim(filename)
open(fileu,file=trim(filename),status='old',action='read')
done = .false.
do
if(done) exit
read(fileu,DSF,iostat=ios) str1
if(ios /= 0) then
done = .true.
else
call onespace(DSL,str1,str2)
s = scan(str2,' ')
if(s > 0) then
if(str2(1:s-1) == '#keyword') then
str2 = str2(s+1:DSL)
s = scan(str2,' ')
if(str2(1:s-1) == trim(nametag)) then
done = .true.
found = .true.
str2 = str2(s+1:DSL)
if(v%li) then
write(*,'(A)') 'str2 is |'//trim(str2)//'|'
if(present(vec)) then
read(str2,*) v%ivec(1:vec)
tmpstr = N2str(v%ivec(1))
do j = 2, vec
tmpstr = trim(tmpstr)//','//trim(N2str(v%ivec(j)))
enddo
write(*,'(A)') 'Integer variable '//trim(nametag)//' is |'//trim(tmpstr)//'|'
else
read(str2,*) v%i
write(*,'(A)') 'Integer variable '//trim(nametag)//' is '//trim(N2str(v%i))
endif
else if(v%lr) then
write(*,'(A)') 'str2 is |'//trim(str2)//'|'
if(present(vec)) then
read(str2,*) v%rvec(1:vec)
write(*,*) 'Real variable '//trim(nametag)//' is ',v%rvec(1:vec)
else
read(str2,*) v%r
write(*,*) 'Real variable '//trim(nametag)//' is ',v%r
endif
else if(v%ls) then
write(*,'(A)') 'str2 is |'//trim(str2)//'|'
if(present(vec)) then
read(str2,*) v%svec(1:vec)
write(*,*) 'String variable '//trim(nametag)//' is:'
do i = 1, vec
write(*,'(A)') trim(v%svec(i))
enddo
else
read(str2,*) v%s
write(*,'(A)') 'String variable '//trim(nametag)//' is '//trim(v%s)
endif
endif
endif
else
endif
else
done = .true.
endif
endif
enddo
close(fileu)
if(.not. found .and. dopt == NONDEFAULTOPT) then
write(*,*) 'cannot find the keyword='//trim(nametag)
write(*,'(A)') 'err: cannot find the the keyword.'
stop 1
else if(.not. found .and. dopt == DEFAULTOPT) then
write(*,'(/A)') 'Could not find '//trim(nametag)
if(v%li) then
if(present(vec)) then
v%ivec(1:vec) = vdefault%ivec(1:vec)
write(*,*) 'Warning: assume default value of ',v%ivec(1:vec)
else
v%i = vdefault%i
write(*,*) 'Warning: assume default value of ',v%i
endif
else if(v%lr) then
if(present(vec)) then
v%rvec(1:vec) = vdefault%rvec(1:vec)
write(*,*) 'Warning: assume default value of ',v%rvec(1:vec)
else
v%r = vdefault%r
write(*,*) 'Warning: assume default value of ', v%r
endif
else if(v%ls) then
if(present(vec)) then
v%svec(1:vec) = vdefault%svec(1:vec)
write(*,*) 'Warning: assume default value of ',v%svec(1:vec)
else
v%s = vdefault%s
write(*,'(A)') 'Warning: assume default value of '//trim(v%s)
endif
endif
endif
end subroutine read_gendata
subroutine getlenang(a,L)
real(double) :: a(3,3),L(6)
real(double) :: sintheta,costheta
L(1) = vecmag3(a(1:3,1))
L(2) = vecmag3(a(1:3,2))
L(3) = vecmag3(a(1:3,3))
costheta = dotprod3(a(1:3,2),a(1:3,3))/(L(2)*L(3))
sintheta = sqrt((1d0-costheta)*(1+costheta))
L(4) = atan2(sintheta,costheta)*rad2deg
costheta = dotprod3(a(1:3,3),a(1:3,1))/(L(3)*L(1))
sintheta = sqrt((1d0-costheta)*(1+costheta))
L(5) = atan2(sintheta,costheta)*rad2deg
costheta = dotprod3(a(1:3,1),a(1:3,2))/(L(1)*L(2))
sintheta = sqrt((1d0-costheta)*(1+costheta))
L(6) = atan2(sintheta,costheta)*rad2deg
end subroutine getlenang
subroutine real2recip(reallatt,reciplatt)
real(double) :: reallatt(3,3),reciplatt(3,3)
real(double) :: vol,tmp2(3,3)
vol = det3(reallatt(1,1))
if(vol < 0) then
write(*,*) 'vol = ',vol
write(*,'(A)') 'err: vol is negative. Check reallatt.'
stop 1
endif
tmp2 = inv3x3(reallatt(1,1))
reciplatt(1:3,1) = tmp2(1,1:3)
reciplatt(1:3,2) = tmp2(2,1:3)
reciplatt(1:3,3) = tmp2(3,1:3)
end subroutine real2recip
function dotprod3(A,B)
real(double) :: A(1:3),B(1:3),dotprod3
dotprod3 = dotprodn(3,a(1),b(1))
end function dotprod3
function dotprodn(n,A,B)
integer :: n,i
real(double) :: A(n),B(n),dotprodn
dotprodn = zero
do i = 1, n
dotprodn = dotprodn + A(i)*B(i)
enddo
end function dotprodn
function tripprod(A)
real(double) :: A(3,3),tripprod
tripprod = A(1,1)*(A(2,2)*A(3,3)-A(2,3)*A(3,2)) - &
A(1,2)*(A(2,1)*A(3,3)-A(2,3)*A(3,1)) + &
A(1,3)*(A(2,1)*A(3,2)-A(2,2)*A(3,1))
end function tripprod
function det3(a)
real(double) :: det3,a(3,3)
det3 = tripprod(a)
end function det3
subroutine frac2abs(reallatt,FracC,AbsC)
real(double) :: FracC(1:3),AbsC(1:3),reallatt(3,3)
integer :: i,j
do i = 1, 3
AbsC(i) = 0
do j = 1, 3
AbsC(i) = AbsC(i) + reallatt(i,j)*FracC(j)
enddo
enddo
end subroutine frac2abs
subroutine abs2frac(reciplatt,AbsC,FracC)
real(double) :: AbsC(3),FracC(3),reciplatt(3,3)
integer :: i
do i = 1, 3
FracC(i) = dotprod3(AbsC(1:3),reciplatt(1:3,i))
enddo
end subroutine abs2frac
function vecmag3(x)
real(double) :: vecmag3,x(3)
vecmag3 = sqrt(dotprod3(x,x))
end function vecmag3
function inv3x3(a) result(inv)
real(double) :: a(3,3),inv(3,3)
real(double) :: det,absdet
inv(1,1) = a(2,2)*a(3,3)-a(2,3)*a(3,2)
inv(2,1) = -(a(2,1)*a(3,3) - a(2,3)*a(3,1))
inv(3,1) = a(2,1)*a(3,2) - a(2,2)*a(3,1)
inv(1,2) = -(a(1,2)*a(3,3) - a(1,3)*a(3,2))
inv(2,2) = a(1,1)*a(3,3) - a(1,3)*a(3,1)
inv(3,2) = -(a(1,1)*a(3,2) - a(1,2)*a(3,1))
inv(1,3) = a(1,2)*a(2,3) - a(1,3)*a(2,2)
inv(2,3) = -(a(1,1)*a(2,3) - a(1,3)*a(2,1))
inv(3,3) = a(1,1)*a(2,2) - a(1,2)*a(2,1)
det = a(1,1)*inv(1,1)+a(1,2)*inv(2,1)+a(1,3)*inv(3,1)
absdet = abs(det)
if(absdet < 1.0d-13) then
write(*,*) 'absdet = ',absdet
write(*,'(A)') 'err: det is too small in inv3x3.'
stop 1
endif
inv = inv/det
end function inv3x3
subroutine onespace(ns,comment1,comment)
integer :: ns
character(len=ns) :: comment1,comment
integer :: i,j
comment = 's'
i = 1
j = 1
loop2: do
loop1: do
if(comment1(i:i) /= ' ') exit loop1
i = i + 1
if(i == ns) exit loop2
enddo loop1
loop3: do
if(comment1(i:i) == ' ') exit loop3
comment(j:j) = comment1(i:i)
j = j + 1
i = i + 1
enddo loop3
comment(j:j) = ' '
j = j + 1
enddo loop2
end subroutine onespace
subroutine assign_str_fr_struct_out(inu,s)
integer :: inu
type(supercell) :: s
integer :: i
do i = 1, 3
read(inu,*) s%a(1:3,i)
enddo
read(inu,*) s%n
do i = 1, s%n
read(inu,*) s%at(i)%gr, s%at(i)%z,s%at(i)%f(1:3)
enddo
call real2recip(s%a,s%b)
close(inu)
end subroutine assign_str_fr_struct_out
subroutine assign_str_fr_xsf(controlu,sc)
integer :: i,controlu
type(supercell) :: sc
character(LEN=DSL) :: tmp
read(controlu,*) tmp
if(trim(tmp) /= 'CRYSTAL') then
write(*,'(A)') 'err: Keyword CRYSTAL not found.'
stop 1
endif
read(controlu,*) tmp
if(trim(tmp) /= 'PRIMVEC') then
write(*,'(A)') 'err: Keyword PRIMVEC not found.'
stop 1
endif
read(controlu,*) sc%a(1:3,1)
read(controlu,*) sc%a(1:3,2)
read(controlu,*) sc%a(1:3,3)
read(controlu,*) tmp
if(trim(tmp) /= 'CONVVEC') then
write(*,'(A)') 'err: Keyword CONVVEC not found.'
stop 1
endif
read(controlu,*) sc%a(1:3,1)
read(controlu,*) sc%a(1:3,2)
read(controlu,*) sc%a(1:3,3)
call real2recip(sc%a,sc%b)
read(controlu,*) tmp
if(trim(tmp) /= 'PRIMCOORD') then
write(*,'(A)') 'err: Keyword PRIMCOORD not found.'
stop 1
endif
read(controlu,*) sc%n
do i = 1, sc%n
read(controlu,*) sc%at(i)%z, sc%at(i)%ac
call abs2frac(sc%b,sc%at(i)%ac,sc%at(i)%f)
enddo
sc%sg_label = '1-P1'
end subroutine assign_str_fr_xsf
subroutine assign_str_fr_poscar(controlu,sc)
integer :: controlu
type(supercell) :: sc
real(double) :: totalscaling,vol
integer :: i,j,s,nsp,v,z,ind
character(LEN=DSL) :: comment1,comment2,tmp1,tmp2,valuestr,targetlabel
real(double) :: pos(3)
integer,allocatable :: numarr(:)
integer :: totn,k,labellen,SGnumber,loc
logical :: done,found,puredigits
integer :: nvalid
real(double) :: density
read(controlu,DSF) comment1
call onespace(DSL,comment1,comment2)
sc%commentline = trim(comment2)
write(*,'(A,A,A)') 'POSCAR comment is [',trim(comment2),'].'
s = scan(comment2,' ')
if(comment2(1:s-1) == 'ATMS:') then
tmp1= comment2(s+1:DSL)
read(tmp1,*) v
sc%n = v
if(sc%n < 1) then
write(*,*) 'sc%n = ',sc%n
write(*,'(A)') 'err: check sc%n in assign_str_fr_poscar'
stop 1
endif
s = scan(tmp1,' ')
tmp1 = tmp1(s+1:DSL)
read(tmp1,*) v
sc%nsp = v
if(sc%nsp < 1) then
write(*,*) 'sc%nsp = ',sc%nsp
write(*,'(A)') 'err: check sc%nsp in assign_str_fr_poscar.'
stop 1
elseif(sc%nsp > zordmax) then
write(*,*) 'sc%nsp,zordmax=',sc%nsp,zordmax
write(*,'(A)') 'err: check sc%nsp, i.e., the number of species/elements'
stop 1
endif
s = scan(tmp1,' ')
tmp1 = tmp1(s+1:DSL)
nsp = v
if(sc%nsp > zordmax) then
write(*,*) 'sc%nsp = ',sc%nsp
write(*,*) 'zordmax = ',zordmax
write(*,'(A)') 'err: out of bound.'
stop 1
endif
do i = 1, nsp
read(tmp1,*) v
sc%n_per_species(i) = v
s = scan(tmp1,' ')
tmp1 = tmp1(s+1:DSL)
s = scan(tmp1,' ')
valuestr = tmp1(1:s-1)
found = .false.
do j = 1, zordmax
if(found) exit
if(trim(valuestr) == trim(Ats(j)) .or. trim(valuestr) == trim(CAts(j)) ) then
z = j
found = .true.
endif
enddo
if(.not. found) then
write(*,*) 'valuestr = ',trim(valuestr)
write(*,'(A)') 'err: this valuestr is not found in the periodic table.'
stop 1
endif
sc%zarr(i) = z
tmp1 = tmp1(s+1:DSL)
enddo
ind = 0
do j = 1, sc%nsp
ind = ind + sc%n_per_species(j)
enddo
if(ind /= sc%n) then
write(*,*) 'ind,sc%n=',ind,sc%n
write(*,'(A)') 'err: missing atoms in the assign_str_fr_poscar.'
stop 1
endif
sc%sg_label = ''
if(trim(tmp1) /= '') then
s = scan(tmp1,' ')
valuestr = tmp1(1:s-1)
if(trim(valuestr) /= 'SG') then
write(*,*) 'valuestr is '//trim(valuestr)
write(*,*) 'The first optional parameter must be SG.'
write(*,'(A)') 'err: Check poscar.'
stop 1
endif
tmp1 = tmp1(s+1:DSL)
s = scan(tmp1,' ')
valuestr = tmp1(1:s-1)
sc%sg_label = trim(valuestr)
else
write(*,*) 'No SG label'
endif
read(controlu,*) totalscaling
read(controlu,*) sc%a(1:3,1)
read(controlu,*) sc%a(1:3,2)
read(controlu,*) sc%a(1:3,3)
allocate(numarr(sc%nsp))
read(controlu,DSF) tmp1
write(*,*) 'tmp1 is .'//trim(tmp1)//'.'
call onespace(DSL,tmp1,tmp2)
s = scan(tmp2,'0123456789')
if(s == 0) then
write(*,'(A)') 'We are going to process the species line |'//trim(tmp2)//'|'
nsp = num_of_strings(tmp2)
if(nsp /= sc%nsp) then
write(*,*) 'err: nsp,sc%nsp = ',nsp,sc%nsp
stop 1
endif
do i = 1, sc%nsp
s = scan(tmp2,' ')
valuestr = tmp2(1:s-1)
write(*,*) 'valuestr is '//trim(valuestr)
found = .false.
do j = 1, zordmax
if(found) exit
if(trim(valuestr) == trim(CATS(j))) then
z = j
if(z /= sc%zarr(i)) then
write(*,*) 'z, sc%zarr(i) = ',z,sc%zarr(i)
write(*,'(A)') 'err: Inconsistency.'
stop 1
endif
found = .true.
endif
enddo
if( .not. found) then
write(*,'(A)') 'err: not found.'
stop 1
endif
tmp2 = tmp2(s+1:DSL)
enddo
read(controlu,DSF) tmp2
nsp = num_of_integers(tmp2)
if(nsp /= sc%nsp) then
write(*,*) 'err: nsp,sc%nsp = ',nsp,sc%nsp
stop 1
endif
read(tmp2,*) numarr(1:sc%nsp)
else
nsp = num_of_integers(tmp1)
if(nsp /= sc%nsp) then
write(*,*) 'err: nsp,sc%nsp = ',nsp,sc%nsp
stop 1
endif
read(tmp1,*) numarr(1:sc%nsp)
endif
do i = 1, sc%nsp
if(numarr(i) /= sc%n_per_species(i)) then
write(*,*) 'species: i=',i
write(*,*) 'numarr(i) = '//trim(N2str(numarr(i)))//', sc%n_per_species(i) = '//trim(N2str(sc%n_per_species(i)))
write(*,'(A)') 'err: numarr(i) and sc%n_per_species(i) are not consistent'
stop 1
endif
enddo
deallocate(numarr)
else
if(comment2(1:s-1) == 'SG') then
tmp2 = comment2(s+1:DSL)
targetlabel = trim(tmp2)
write(*,*) 'targetlabel = '//trim(targetlabel)
puredigits = .true.
labellen = len(trim(targetlabel))
do i = 1, labellen
if(.not. puredigits) then
exit
endif
loc = scan(targetlabel(i:i),'0123456789')
if(loc /= 1) then
puredigits = .false.
endif
enddo
if(puredigits) then
SGnumber = str2N(trim(targetlabel))
write(*,*) 'SGnumber is ',SGnumber
if(SGnumber >= 1 .and. SGnumber <= 230) then
targetlabel = trim(SGbase(1,SGnumber)%sglabel)
write(*,*) 'Fully expand the default SG label to the full SG label:'
write(*,*) 'SGnumber= ',SGnumber
write(*,*) 'Full targetlabel= ',trim(targetlabel)
else
write(*,*) 'err: must be between 1 and 230 inclusive. impossible. '
stop 1
endif
endif
sc%sg_label = trim(targetlabel)
write(*,'(A)') 'Possibly adjusted sg_label is '//trim(sc%sg_label)
else
write(*,'(A)') 'WARNING WARNING: No ATMS:, no SG, hence we assume SG 1'
sc%sg_label = '1-P1'
endif
read(controlu,*) totalscaling
read(controlu,*) sc%a(1:3,1)
read(controlu,*) sc%a(1:3,2)
read(controlu,*) sc%a(1:3,3)
read(controlu,DSF) tmp1
call onespace(DSL,tmp1,tmp2)
s = scan(tmp2,'0123456789')
if(s == 0) then
nsp = 0
done = .false.
do
if(done) exit
s = scan(tmp2,' ')
valuestr = tmp2(1:s-1)
found = .false.
do j = 1, zordmax
if(found) exit
if(trim(valuestr) == trim(CATS(j))) then
nsp = nsp + 1
sc%zarr(nsp) = j
found = .true.
endif
enddo
if( .not. found) then
write(*,'(A)') 'err: not found.'
stop 1
endif
tmp2 = tmp2(s+1:DSL)
if(len(trim(tmp2)) == 0) then
write(*,'(A)') 'nsp = '//trim(N2str(nsp))
sc%nsp = nsp
done = .true.
endif
enddo
read(controlu,DSF) tmp1
nvalid = num_of_integers(tmp1)
if(nsp /= nvalid) then
write(*,*) 'nsp,nvalid=',nsp,nvalid
write(*,*) 'err: inconsistency in species line and species line.'
stop 1
endif
read(tmp1,*) sc%n_per_species(1:nsp)
else
write(*,'(A)') 'err: Since this is without ATMs, we must have species line.'
stop 1
endif
endif
totn = 0
do j = 1, sc%nsp
v = sc%n_per_species(j)
do k = 1, v
totn = totn + 1
sc%at(totn)%z = sc%zarr(j)
sc%at(totn)%mass = massofa(sc%zarr(j))
enddo
enddo
write(*,'(A)') 'totn = '//trim(N2str(totn))
sc%n = totn
sc%a = sc%a*totalscaling
call real2recip(sc%a,sc%b)
write(*,'(A,/,3F15.10,A,F15.10,/,3F15.10,A,F15.10,/,3F15.10,A,F15.10)') &
'Real latt:', sc%a(1:3,1),' | ',vecmag3(sc%a(1:3,1)),sc%a(1:3,2),' | ',vecmag3(sc%a(1:3,2)),sc%a(1:3,3),' | ',vecmag3(sc%a(1:3,3))
vol = det3(sc%a(1,1))
if(vol .le. 0) then
write(*,'(A)') 'err: vol is not positive.'
stop 1
endif
sc%vol = vol
write(*,'(A,/,3F15.10,A,F15.10,/,3F15.10,A,F15.10,/,3F15.10,A,F15.10)') &
'Reciprocal latt:', sc%b(1:3,1),' | ',vecmag3(sc%b(1:3,1)),sc%b(1:3,2),' | ',vecmag3(sc%b(1:3,2)),sc%b(1:3,3),' | ',vecmag3(sc%b(1:3,3))
read(controlu,*) tmp1
if(trim(tmp1) == 'Selective') then
read(controlu,*) tmp1
endif
if(trim(tmp1) /= 'Direct' .and. trim(tmp1) /= 'direct' .and. trim(tmp1) /= 'Cartesian' ) then
write(*,'(A)') 'err: dummy should be Direct, direct, or Cartesian'
stop 1
endif
do i = 1, sc%n
sc%at(i)%force(1:3) = (/zero,zero,zero/)
enddo
do i = 1, sc%n
if(trim(tmp1) == 'Direct' .or. trim(tmp1) == 'direct') then
read(controlu,DSF) comment1
call onespace(DSL,comment1,comment2)
read(comment2,*) sc%at(i)%f(1:3)
call frac2abs(sc%a(1,1),sc%at(i)%f(1),sc%at(i)%ac(1))
s = scan(comment2,'|')
if(s > 0) then
tmp2= comment2(s+1:DSL)
read(tmp2,*) sc%at(i)%force(1:3)
write(*,'(A,3F20.10)') 'sc%at(i)%force(1:3) = ',sc%at(i)%force(1:3)
endif
else if(trim(tmp1) == 'Cartesian') then
read(controlu,DSF) comment1
call onespace(DSL,comment1,comment2)
read(comment2,*) pos(1:3)
call abs2frac(sc%b(1,1),pos(1),sc%at(i)%f(1))
call frac2abs(sc%a(1,1),sc%at(i)%f(1),sc%at(i)%ac(1))
s = scan(comment2,'|')
if(s > 0) then
tmp2= comment2(s+1:DSL)
read(tmp2,*) sc%at(i)%force(1:3)
write(*,'(A,3F20.10)') 'sc%at(i)%force(1:3) = ',sc%at(i)%force(1:3)
endif
endif
enddo
call getlenang(sc%a,sc%la(1))
write(*,'(A)') 'la(1:6)='
do i = 1, 6
write(*,'(3F15.10)') sc%la(i)
enddo
write(*,*) 'Volume of the supercell= ',vol
density = crys_density(sc)
sc%density = density
write(*,*) 'Density is ',density,' g/cm^3'
end subroutine assign_str_fr_poscar
subroutine assign_str_fr_fdf(inu,s)
integer :: inu,natom,nspecies,sp,i,j
type(supercell) :: s
character(len=DSL) :: str1,str2,str3
real(double) :: x(3)
character(len=DSL) :: icf
read(inu,*) str1,str2
if(trim(str1) /= 'NumberOfAtoms') then
write(*,*) 'str1 = ',trim(str1)
write(*,*) 'but str1 must be NumberofAtoms'
write(*,'(A)') 'err: check fdf file.'
stop 1
else
read(str2,'(I8)') natom
write(*,*) 'natom = ',natom
s%n = natom
endif
read(inu,*) str1,str2
if(trim(str1) /= 'NumberOfSpecies') then
write(*,*) 'str1 = ',trim(str1)
write(*,*) 'but str1 must be NumberofSpecies'
write(*,'(A)') 'err: check fdf file.'
stop 1
else
read(str2,'(I8)') nspecies
write(*,*) 'nspecies = ',nspecies
s%nsp = nspecies
endif
read(inu,*) str1,str2
if(trim(str2) /= 'ChemicalSpeciesLabel') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be ChemicalSpeciesLabel'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
do i = 1, nspecies
read(inu,*) j,sp
if(j/=i) then
write(*,*) 'j,i=',j,i
write(*,*) 'sp = ',sp
write(*,'(A)') 'err: something wrong with the species numbering ?'
stop 1
else
s%zarr(i) = sp
write(*,*) 's%zarr(',i,')=',sp
endif
enddo
read(inu,*) str1,str2
if(trim(str2) /= 'ChemicalSpeciesLabel') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be ChemicalSpeciesLabel'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
read(inu,*) str1,str2,str3
if(trim(str1) /= 'LatticeConstant') then
write(*,*) 'str1 = ',trim(str1)
write(*,*) 'but str1 must be LatticeConstant'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
if(trim(str2) /= '1.0') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be 1.0'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
if(trim(str3) /= 'Ang') then
write(*,*) 'str3 = ',trim(str3)
write(*,*) 'but str3 must be Ang'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
read(inu,*) str1,str2
if(trim(str2) /= 'LatticeVectors') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be LatticeVectors'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
read(inu,*) s%a(1:3,1)
read(inu,*) s%a(1:3,2)
read(inu,*) s%a(1:3,3)
write(*,*) 's%a is '
write(*,*) s%a(1:3,1)
write(*,*) s%a(1:3,2)
write(*,*) s%a(1:3,3)
call real2recip(s%a,s%b)
read(inu,*) str1,str2
if(trim(str2) /= 'LatticeVectors') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be LatticeVectors'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
read(inu,*) str1,str2
if(trim(str2) == 'Fractional') then
icf = 'frac'
else if(trim(str2) == 'NotScaledCartesianAng') then
icf = 'abs'
else
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be either Fractional or NotScaledCartesianAng'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
read(inu,*) str1,str2
if(trim(str2) /= 'AtomicCoordinatesAndAtomicSpecies') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be AtomicCoordinatesAndAtomicSpecies'
write(*,'(A)') 'err: check fdf file.'
stop 1
endif
do i = 1, natom
read(inu,*) x(1:3),sp
if(trim(icf) == 'frac') then
s%at(i)%f(1:3) = x(1:3)
else if(trim(icf) == 'abs') then
call abs2frac(s%b,x,s%at(i)%f)
else
write(*,'(A)') 'err: frac and abs problem.'
stop 1
endif
s%at(i)%z = s%zarr(sp)
enddo
read(inu,*) str1,str2
if(trim(str2) /= 'AtomicCoordinatesAndAtomicSpecies') then
write(*,*) 'str2 = ',trim(str2)
write(*,*) 'but str2 must be AtomicCoordinatesAndAtomicSpecies'