-
Notifications
You must be signed in to change notification settings - Fork 4
/
symm_ewpc_gen.f90
1107 lines (993 loc) · 41.6 KB
/
symm_ewpc_gen.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
!
! ParaGauss, a program package for high-performance computations of
! molecular systems
!
! Copyright (C) 2014 T. Belling, T. Grauschopf, S. Krüger,
! F. Nörtemann, M. Staufer, M. Mayer, V. A. Nasluzov, U. Birkenheuer,
! A. Hu, A. V. Matveev, A. V. Shor, M. S. K. Fuchs-Rohr, K. M. Neyman,
! D. I. Ganyushin, T. Kerdcharoen, A. Woiterski, A. B. Gordienko,
! S. Majumder, M. H. i Rotllant, R. Ramakrishnan, G. Dixit,
! A. Nikodem, T. Soini, M. Roderus, N. Rösch
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License version 2 as
! published by the Free Software Foundation [1].
!
! 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.
!
! [1] http://www.gnu.org/licenses/gpl-2.0.html
!
! Please see the accompanying LICENSE file for further information.
!
subroutine symm_ewpc_gen ()
!
! Purpose: ewpc_array containing all information about external
! field is filled in
!
# include "def.h"
use datatype
use calc3c_switches
use filename_module
use symm_positions
use pointcharge_module
use operations_module
use iounitadmin_module
use group_module, only: group_num_el, symm_transformation_int, &
sub_group, group_coset, ylm_trafos, group_coset_decomp
use unique_atom_module
use ewaldpc_module, ex_pcew_dumm=>ex_pcew
use type_module, only: IK => i4_kind, RK => r8_kind
use comm, only: comm_rank
implicit none
! *** end of interface ***
type(symm_transformation_int) :: point_trafos_pc
! transformations of the symmetry equivalent point charges
type(sub_group) :: local_groups_pc
! local symmetry group of the unique point charges
type(group_coset) :: cosets_pc
! coset of the local symmetry group of the unique point charges
real (RK) :: position(3), position2(3)
type(pointcharge_type), pointer :: pc
! treats PC of ewald program generated file
type(unique_atom_type), pointer :: ua
logical:: ex_pcew
real (RK):: e_nuc_ewpc,dist
integer(IK):: na, nb, eq_a, kl_ew, kl1, kl_pcr, n_gxat, kl_ew_eq
integer(IK):: it_ewpc,it_pcr,ii,i_ua,i_eq,eq_pcc,eq_pcs
integer(IK),dimension(:),allocatable:: pcew_no
integer (IK):: n_ewpc_arr, i, j, n_equal, n, j_epe_r, epe_r(300)
real(RK), allocatable, dimension(:,:) ::pcew_temp
real(RK),parameter:: small_ew=1.d-2
real(RK)::ewpc_array_charge,e_nuc_pcr,min_pccdist,min_pcsdist,min_pcrdist
real (RK) :: min_ewpcdist, gv_nuc_ewpc(3)
real(RK)::max_ewpc_pcr_dev=0.0_rk
character(len=256) :: trace_message
integer (IK) :: k
#if 0
real(RK) :: r_screep, rc_screep(3), distance_to_screep
#endif
if(comm_rank() == 0) print*, 'symm_ewpc_gen ______________________________________________'
kl_pcr=0
if(ewaldpc) then
ex_pcew=.true.
ewpc_unit=openget_iounit(trim(inpfile('ewald.pcr')) &
,form='FORMATTED',status='old')
#if 0 /* control that cluster is inside screep */
read(ewpc_unit,*) EWPC_N,r_screep,rc_screep
ii=0
distance_to_screep=100.0_rk
do i=1,N_unique_atoms+n_timps
do eq_a=1,unique_atoms(i)%N_equal_atoms
ii=ii+1
dist=sqrt(sum((unique_atoms(i)%position(:,eq_a) &
-rc_screep)**2))
distance_to_screep=min(r_screep-dist,distance_to_screep)
enddo
enddo
print*, 'minimum distance_to_screep' ,distance_to_screep
ASSERT(distance_to_screep.gt.2.0_rk)
#else
read(ewpc_unit,*) EWPC_N
#endif
nullify(pc) !called after symm_epe and thus ponter was on pcc_array pcs_array
allocate(pc,pcew_temp(4,EWPC_N),pcew_no(EWPC_N),stat=ewa_allocstat(21))
ASSERT(ewa_allocstat(21).eq.0)
ewa_allocstat(21)=1 ! pcew_temp
ewa_allocstat(27)=1 ! pcew_no
ewa_allocstat(16)=1 ! PC as a temp
!** loop over all centers in file and sort out PC which positions coincide
! with the positions of regular atoms of QM cluster
if(output_unit > 0) then
write(output_unit,*) &
' Number of centers generated with program ewald, EWPC_N ' ,EWPC_N
if(ex_gxepe) then
write(output_unit,*) 'as file epe.r with regular atomic positions is located'
write(output_unit,*) ' EWPC centers coinciding with atoms will be sorted out'
!!$ write(output_unit,*) gxepe_array(1)%position(:,1)
end if
endif
epe_r=0
ii=1
it_ewpc=EWPC_N ! it_ewpc here is help variable to define number of PC
mc: do i=1,EWPC_N
read(ewpc_unit,*) pcew_temp(:,ii)
!!$ if(ii.eq.1) write(output_unit,*) pcew_temp(:,ii)
j_epe_r=0
do i_ua=1,N_unique_atoms+n_timps
if(gxepe_impu(i_ua)==0) cycle !!!!!!!!!!!!!!AS important
if(ex_gxepe) then
if(i_ua.gt.N_unique_atoms) then
do i_eq=1,unique_timps(i_ua-N_unique_atoms)%N_equal_atoms
j_epe_r=j_epe_r+1
if (dot_product(gxepe_array(i_ua)%position(:,i_eq) &
-pcew_temp(1:3,ii), &
gxepe_array(i_ua)%position(:,i_eq)-pcew_temp(1:3,ii)) &
.lt.small_ew) then
epe_r(j_epe_r)=1
it_ewpc=it_ewpc-1
cycle mc
endif ! dot_product
end do
else
do i_eq=1,unique_atoms(i_ua)%N_equal_atoms
j_epe_r=j_epe_r+1
if (dot_product(gxepe_array(i_ua)%position(:,i_eq)- &
pcew_temp(1:3,ii), &
gxepe_array(i_ua)%position(:,i_eq)-pcew_temp(1:3,ii)) &
.lt.small_ew) then
epe_r(j_epe_r)=1
it_ewpc=it_ewpc-1
cycle mc
endif ! dot_product
enddo ! i_eq=1,unique_atoms(i_ua)%N_equal_atoms
end if
else ! .not.ex_gxepe
do i_eq=1,unique_atoms(i_ua)%N_equal_atoms
if (dot_product(unique_atoms(i_ua)%position(:,i_eq)- &
pcew_temp(1:3,ii), &
unique_atoms(i_ua)%position(:,i_eq)-pcew_temp(1:3,ii)) &
.lt.small_ew) then
it_ewpc=it_ewpc-1
cycle mc
endif !
enddo
endif ! ex_gxepe/else
enddo
ii=ii+1
enddo mc
call returnclose_iounit(ewpc_unit)
!** now pcew_temp contains only PC which do not related to centers of QM cluster
EWPC_N=it_ewpc
if(output_unit > 0) then
write(output_unit,*) 'EWPC_N after sorting out PC in atomic positions' ,EWPC_N
do j=1,n_epe_r
if(epe_r(j)==0) print*,'WARNING : ',j,' EPE.R center has no EWALD center coincided !!!!!!!!!!!!'
end do
endif
gx_epe_ex: if(ex_gxepe) then
do i_ua=1,N_unique_atoms
deallocate(gxepe_array(i_ua)%position,stat=ewa_allocstat(23))
ASSERT(ewa_allocstat(23).eq.0)
end do
deallocate(gxepe_array,gxepe_impu,stat=ewa_allocstat(22))
ASSERT(ewa_allocstat(23).eq.0)
endif gx_epe_ex
!** done
#if 1
e_nuc_ewpc=0.0_rk
do na=1,N_unique_atoms
do eq_a=1,unique_atoms(na)%N_equal_atoms
gv_nuc_ewpc=0.0_rk
do nb=1,EWPC_N
dist=sqrt(sum((unique_atoms(na)%position(:,eq_a) &
-pcew_temp(1:3,nb))**2))
e_nuc_ewpc=e_nuc_ewpc+pcew_temp(4,nb)*(unique_atoms(na)%Z-unique_atoms(na)%ZC)/dist
gv_nuc_ewpc=gv_nuc_ewpc+ pcew_temp(4,nb)*&
(unique_atoms(na)%position(:,eq_a)-pcew_temp(1:3,nb))/dist**3
enddo
if(comm_rank() == 0) print*,'gv_nuc_ewpc: ',gv_nuc_ewpc,sum(gv_nuc_ewpc**2)
enddo
enddo
if(comm_rank() == 0) print*,'e_nuc_ewpc with initial pcew_temp',e_nuc_ewpc
#endif
!** reorder atoms in pcr_temp and pcew_temp
!** first go coinsiding atoms with the same charges
#if 0
call read_pcr_temp(pcr_n)
#endif
kl_ew=0
kl_ew_eq=0
ex_pcr_n: if(pcr_n.ne.0) then ! if epe charges exist
if(n_timps.gt.0) then
n_gxat=sum(unique_atoms(1:N_unique_atoms)%N_equal_atoms)+&
sum(unique_timps(1:n_timps)%N_equal_atoms)
else
n_gxat=sum(unique_atoms(1:N_unique_atoms)%N_equal_atoms)
end if
if(comm_rank() == 0) then
if(print_epe) print*,'n_gxat pcr_n n_gxat_pcr ',n_gxat, pcr_n, n_gxat_pcr
endif
kl_pcr=n_gxat_pcr
if(output_unit > 0) then
write(output_unit,*) 'initial values of kl_pcr and kl_ew',kl_pcr,kl_ew
print*, 'initial values of kl_pcr and kl_ew',kl_pcr,kl_ew
endif
do i=1,EWPC_N
kl1=kl_pcr+1
do k=kl1,pcr_n
if(dot_product(pcr_temp(1:3,k)-pcew_temp(1:3,i) &
,pcr_temp(1:3,k)-pcew_temp(1:3,i)).lt.small_ew &
.and. ((abs(pcr_temp(4,k)-pcew_temp(4,i)).lt.0.01_rk) ) ) then
!**** centers coincide and charges are equal
! such centers generated with ewald can be neglected
max_ewpc_pcr_dev=max(sqrt(dot_product(pcr_temp(1:3,k)-pcew_temp(1:3,i) &
,pcr_temp(1:3,k)-pcew_temp(1:3,i))),max_ewpc_pcr_dev)
kl_pcr=kl_pcr+1
kl_ew=kl_ew+1
pc%position_first_ec=pcr_temp(1:3,kl_pcr)
pcr_temp(1:3,kl_pcr)=pcr_temp(1:3,k)
pcr_temp(1:3,k)=pc%position_first_ec
pc%z=pcr_temp(4,kl_pcr)
pcr_temp(4,kl_pcr)=pcr_temp(4,k)
pcr_temp(4,k)=pc%z
#if 0
index=psb_ind(kl_pcr)
psb_ind(kl_pcr)=psb_ind(k)
psb_ind(k)=index
#endif
pc%position_first_ec=pcew_temp(1:3,kl_ew)
pcew_temp(1:3,kl_ew)=pcew_temp(1:3,i)
pcew_temp(1:3,i)=pc%position_first_ec
pc%z=pcew_temp(4,kl_ew)
pcew_temp(4,kl_ew)=pcew_temp(4,i)
pcew_temp(4,i)=pc%z
pc%c=0.0_rk
exit
endif ! dot_product
enddo ! kl1,pcr_n
enddo ! i=1,EWPC_N
if(comm_rank() == 0) print*,'max_ewpc_pcr_dev for equivalent centers', max_ewpc_pcr_dev
if(output_unit > 0) then
if(print_epe) &
print*, 'found coinciding in charge centers in pcr and ewpc (kl_pcr,kl_ew)', kl_pcr,kl_ew
write(output_unit,*) 'number of found coinciding in charge centers in pcr and ewpc',kl_pcr,kl_ew
write(output_unit,*) 'indexes for last coinciding elements ' ,kl_ew,kl_pcr
endif
!!** done equivalent atoms go first
kl_ew_eq=kl_ew ! centers starting from this index will not be neglected
! but treated with modified charge now this centers are sorted
! and the charges are modified
if(comm_rank() == 0) print*, 'locate centers which coinside but have different charges'
do i=kl_ew+1,EWPC_N
kl1=kl_pcr+1
do k=kl1,pcr_n
if(dot_product(pcr_temp(1:3,k)-pcew_temp(1:3,i) &
,pcr_temp(1:3,k)-pcew_temp(1:3,i)).lt.small_ew ) then
max_ewpc_pcr_dev=max(sqrt(dot_product(pcr_temp(1:3,k)-pcew_temp(1:3,i) &
,pcr_temp(1:3,k)-pcew_temp(1:3,i))),max_ewpc_pcr_dev)
kl_pcr=kl_pcr+1
kl_ew=kl_ew+1
pc%position_first_ec=pcr_temp(1:3,kl_pcr)
pcr_temp(1:3,kl_pcr)=pcr_temp(1:3,k)
pcr_temp(1:3,k)=pc%position_first_ec
pc%z=pcr_temp(4,kl_pcr)
pcr_temp(4,kl_pcr)=pcr_temp(4,k)
pcr_temp(4,k)=pc%z
pc%position_first_ec=pcew_temp(1:3,kl_ew)
pcew_temp(1:3,kl_ew)=pcew_temp(1:3,i)
pcew_temp(1:3,i)=pc%position_first_ec
pc%z=pcew_temp(4,kl_ew)
pcew_temp(4,kl_ew)=pcew_temp(4,i)
pcew_temp(4,i)=pc%z
pcew_temp(4,kl_ew)=pcew_temp(4,kl_ew)-pcr_temp(4,kl_pcr)
pcr_temp(4,kl_pcr)=0.0_rk
pc%c=0.0_rk
exit
endif! dot_product
enddo! kl1,pcr_n
enddo! i=1,EWPC_N
if(comm_rank() == 0) then
if(print_epe) then
print*,'max_ewpc_pcr_dev for other coinciding centers', max_ewpc_pcr_dev
print*, 'coinciding centers in ewpc and pcr arrays kl_ew kl_pcr',kl_ew,kl_pcr
print*, 'charge of collected PCs, pcew_temp vs pcr_temp', &
sum(pcew_temp(4,1:kl_ew)),sum(pcr_temp(4,1+n_gxat_pcr:kl_pcr))
DPRINT 'if not changed from previous value then no such centers'
endif
endif
if(output_unit > 0) write(output_unit,*) &
'number of coinciding centers in ewpc and pcr arrays & charges ',kl_ew &
,sum(pcew_temp(4,1:kl_ew)),sum(pcr_temp(4,1+n_gxat_pcr:kl_pcr))
!!** done second go centers with modified charges
endif ex_pcr_n
! ** now first kl centers in pcew_temp and pcr_temp coincide
! calculate its interact with cluster to be compared with cluster_epe interact
e_nuc_pcr=0.0_rk
min_pcrdist=100.0
do nb=1,kl_ew
do na=1,N_unique_atoms
do eq_a=1,unique_atoms(na)%N_equal_atoms
dist=sqrt(sum((unique_atoms(na)%position(:,eq_a) &
-pcew_temp(1:3,nb))**2))
min_pcrdist=min(min_pcrdist,dist)
e_nuc_pcr=e_nuc_pcr+ &
pcew_temp(4,nb)*(unique_atoms(na)%Z-unique_atoms(na)%ZC)/dist
enddo
enddo
if(comm_rank() == 0) then
DPRINT pcew_temp(1:3,nb),pcew_temp(4,nb),nb
endif
enddo
if(comm_rank() == 0) then
print*,'min_pcrdist', min_pcrdist
if(print_epe) &
print*,'e_nuc_pcr to be compared with e_nuc_epe',e_nuc_pcr
endif
! ** check potential of PC
e_nuc_ewpc = 0.0_rk
min_ewpcdist=100.0_rk
do nb=1+kl_ew,EWPC_N
j=0
do na=1,N_unique_atoms
do eq_a=1,unique_atoms(na)%N_equal_atoms
j=j+1
dist=sqrt(sum((unique_atoms(na)%position(:,eq_a) &
-pcew_temp(1:3,nb))**2))
if(dist < min_ewpcdist) then
min_ewpcdist=dist
ii=j
end if
e_nuc_ewpc = e_nuc_ewpc+pcew_temp(4,nb)*unique_atoms(na)%Z/dist
enddo! eq_a=1,unique_atoms(na)%N_equal_atoms
enddo! na=1,N_unique_atoms
enddo! 1,EWPC_N
min_ewpcdist= min_ewpcdist*0.529177_rk
if(min_ewpcdist < 1.0_rk) then
write(trace_message,*) "WARNING: minimal distance between EWALD.PCR and QM cluster is ",min_ewpcdist, &
"Angstrom for QM center ",ii
call write_to_trace_unit(trim(trace_message))
end if
#if 0
print*,'min_ewpcdist',min_ewpcdist
ASSERT(min_ewpcdist.gt.1.0_rk)
#endif
if(output_unit > 0) then
DPRINT 'now first kl centers in pcew_temp and pcr_temp coincide'
write(output_unit,*) 'e_nuc_ewpc with use of pcew_temp and Z', e_nuc_ewpc, &
sum(pcew_temp(4,1+kl_ew:EWPC_N))
if(print_epe) print*,'e_nuc_ewpc with use of pcew_temp and Z', e_nuc_ewpc, &
sum(pcew_temp(4,1+kl_ew:EWPC_N))
!** done
if(pcr_n.ne.0) then
if(print_epe) write(output_unit,*) '** take additional centers in pcew_temp',1+kl_ew
else
if(print_epe) write(output_unit,*) '** take PC from pcew_temp starting from ',1+kl_ew
end if
endif
!!** now reorder all atoms in ewpc_temp starting from first non equivalent one
i=1+kl_ew_eq
it_ewpc=0 !types of EWPC
ewpc_wh: do while(i.le.EWPC_N)
pc%position_first_ec(1:3)=pcew_temp(1:3,i)
pc%name='ewald PC '
it_ewpc=it_ewpc+1
position(1) = pc%position_first_ec(1)
position(2) = pc%position_first_ec(3)
position(3) = pc%position_first_ec(2)
! now apply all symmetry operations to the position of the
! unique atom
n = 0
do j=1,group_num_el
position2 = MATMUL(ylm_trafos(1)%matrix(:,:,j),position)
if (dot_product(position2-position,position2-position) < small_ew) then
n = n+1
end if
enddo
! allocate group elements
local_groups_pc%num_el = n
allocate(local_groups_pc%elements(n),stat=ewa_allocstat(12))
ASSERT(ewa_allocstat(12).eq.0)
ewa_allocstat(12)=1
! fill up group elements
n = 0
do j=1,group_num_el
position2 = MATMUL(ylm_trafos(1)%matrix(:,:,j),position)
if (dot_product(position2-position,position2-position) < small_ew) then
n = n+1
local_groups_pc%elements(n) = j
end if
end do
!
! determine symmetry equivalent atoms
!
call group_coset_decomp(n_equal,local_groups_pc,cosets_pc,point_trafos_pc%matrix)
pc%N_equal_charges=n_equal
ewa_allocstat(13)=1 ! point_trafos_pc%matrix
ewa_allocstat(14)=1 ! cosets_pc%elements
allocate(pc%position(3,pc%N_equal_charges),stat=ewa_allocstat(15))
ASSERT(ewa_allocstat(15).eq.0)
ewa_allocstat(15)=1 ! pc%position in temp
! determine positions of equal atoms
! write(output_unit,*) " Equal charges of Type ",i
do j=1,n_equal
position2 = MATMUL(ylm_trafos(1)%matrix(:,:,cosets_pc%elements(1,j)),position)
pc%position(1,j) = position2(1)
pc%position(2,j) = position2(3)
pc%position(3,j) = position2(2)
do ii=i,EWPC_N
if(dot_product(pcew_temp(1:3,ii)-pc%position(:,j) &
,pcew_temp(1:3,ii)-pc%position(:,j)) < small_ew) then
pcew_temp(1:3,ii)=pcew_temp(1:3,i)
pcew_temp(1:3,i)=pc%position(1:3,j)
pc%z=pcew_temp(4,ii)
pc%c=0.0_rk
pcew_temp(4,ii)=pcew_temp(4,i)
pcew_temp(4,i)=pc%z
pcew_no(i)=it_ewpc
exit
endif !
enddo ! ii=i+1,EWPC_N
if(i>EWPC_N) stop ' i>EWPC_N, check EWPC array'
i=i+1
enddo ! j=1,n_equal
deallocate(local_groups_pc%elements, point_trafos_pc%matrix, &
cosets_pc%elements, pc%position, stat=ewa_allocstat(12))
ASSERT(ewa_allocstat(12).eq.0) ! local_groups_pc%elements
ewa_allocstat(13)=0 ! point_trafos_pc%matrix
ewa_allocstat(14)=0 ! coset%elements
ewa_allocstat(15)=0 ! pc%position in temp
ASSERT(n_equal.eq.pc%N_equal_charges)
enddo ewpc_wh ! while
!** done
!** check potential of PC
e_nuc_ewpc = 0.0_rk
do nb=1+kl_ew,EWPC_N
do na=1,N_unique_atoms
do eq_a=1,unique_atoms(na)%N_equal_atoms
e_nuc_ewpc = e_nuc_ewpc+pcew_temp(4,nb)*(unique_atoms(na)%Z-unique_atoms(na)%ZC)/ &
sqrt(sum((unique_atoms(na)%position(:,eq_a)-pcew_temp(1:3,nb))**2))
enddo ! eq_a=1,unique_atoms(na)%N_equal_atoms
enddo ! na=1,N_unique_atoms
enddo ! 1,EWPC_N
if(output_unit > 0) then
write(output_unit,*) 'e_nuc_ewpc with use of pcew_temp & Z', e_nuc_ewpc, &
sum(pcew_temp(4,1+kl_ew:EWPC_N))
if(print_epe) then
print*,'e_nuc_ewpc and z', e_nuc_ewpc,sum(pcew_temp(4,1+kl_ew:EWPC_N))
print*,'epe coinciding centers are not taken into account'
endif
endif
!** done
!!** now reorder still left atoms in pcr_temp
it_pcr=0 !types of pcr
epe_ex:if(pcr_n.gt.kl_pcr) then
if(output_unit > 0) then
if(print_epe) print*, pcr_n-kl_pcr, &
' not coinciding with ewpc environment epe centers are found of total charge', &
sum(pcr_temp(4,1+kl_pcr:pcr_n))
write(output_unit,*) &
' not coinciding with ewpc environment epe centers exist in No=', &
pcr_n-kl_pcr
write(output_unit,*) 'charge of these PC ', sum(pcr_temp(4,1+kl_pcr:pcr_n))
endif
!** take additional centers in pcr_temp
i=1+kl_pcr
pcr_wh: do while(i.le.pcr_n)
pc%position_first_ec(1:3)=pcr_temp(1:3,i)
pc%name='pcr '
it_pcr=it_pcr+1
position(1) = pc%position_first_ec(1)
position(2) = pc%position_first_ec(3)
position(3) = pc%position_first_ec(2)
! now apply all symmetry operations to the position of the
! unique atom
n = 0
do j=1,group_num_el
position2 = MATMUL(ylm_trafos(1)%matrix(:,:,j),position)
if (dot_product(position2-position,position2-position) < small_ew) then
n = n+1
end if
enddo
local_groups_pc%num_el = n
allocate(local_groups_pc%elements(n),stat=ewa_allocstat(12))
ASSERT(ewa_allocstat(12).eq.0)
ewa_allocstat(12)=1
! fill up group elements
n = 0
do j=1,group_num_el
position2 = MATMUL(ylm_trafos(1)%matrix(:,:,j),position)
if (dot_product(position2-position,position2-position) < small_ew) then
n = n+1
local_groups_pc%elements(n) = j
end if
end do
!
! determine symmetry equivalent atoms
!
call group_coset_decomp(n_equal,local_groups_pc,cosets_pc,point_trafos_pc%matrix)
ewa_allocstat(13)=1 ! point_trafos_pc%matrix
ewa_allocstat(14)=1 ! cosets_pc
pc%N_equal_charges=n_equal
allocate(pc%position(3,pc%N_equal_charges),stat=ewa_allocstat(15))
ASSERT(ewa_allocstat(15).eq.0)
ewa_allocstat(15)=1
do j=1,n_equal
position2 = MATMUL(ylm_trafos(1)%matrix(:,:,cosets_pc%elements(1,j)),position)
pc%position(1,j) = position2(1)
pc%position(2,j) = position2(3)
pc%position(3,j) = position2(2)
do ii=i,pcr_n
if(dot_product(pcr_temp(1:3,ii)-pc%position(:,j) &
,pcr_temp(1:3,ii)-pc%position(:,j)) < small_ew) then
pcr_temp(1:3,ii)=pcr_temp(1:3,i)
pcr_temp(1:3,i)=pc%position(1:3,j)
pc%z=pcr_temp(4,ii)
pc%c=0.0_rk
pcr_temp(4,ii)=pcr_temp(4,i)
pcr_temp(4,i)=pc%z
pcr_no(i)=it_pcr
exit
endif !
enddo ! ii=i+1,pcr_n
if(i>pcr_n) stop ' i>EWPC_N, check EWPC array'
i=i+1
enddo ! j=1,n_equal
deallocate(local_groups_pc%elements, point_trafos_pc%matrix, &
cosets_pc%elements,&
pc%position, stat=ewa_allocstat(13))
ASSERT(ewa_allocstat(13).eq.0) ! point_trafos_pc%matrix
ewa_allocstat(12)=0 ! local_groups_pc%elements
ewa_allocstat(14)=0 ! cosets_pc%elements
ewa_allocstat(15)=0 ! pc%position
enddo pcr_wh! while
!** done
else epe_ex
if(comm_rank() == 0) then
DPRINT 'no not coinciding with ewpc environment epe centers exist'
endif
endif epe_ex
deallocate(pc,stat=ewa_allocstat(16))
ASSERT(ewa_allocstat(16).eq.0)
nullify(pc)
#if 0
print*,'read_pc_array'
call read_pc_array(pcc_array,'pcc_array',pcc_n)
call read_pc_array(pcs_array,'pcs_array',pcs_n)
print*,'read_pc_array done'
#endif
n_unique_pcr=pcs_n+pcc_n
if(pcr_n.gt.kl_pcr) n_unique_pcr=n_unique_pcr+it_pcr
allocate(ewpc_array(it_ewpc+n_unique_pcr), stat=ewa_allocstat(3))
ASSERT(ewa_allocstat(3).eq.0)
ewa_allocstat(3)=1
!!$ write(output_unit, *) '** store not coinciding pcew centers'
n_ewpc_arr=0
i=1+kl_ew_eq
if(comm_rank() == 0) then
if(print_epe) print*,' ewpc_array (ewald.pcr part) :'
endif
! first go ewald_pcr unique centers
! second pcs and pcc centers
ewpcarr_wh: do while(i.le.EWPC_N)
ASSERT(pcew_no(i).le.size(ewpc_array))
pc=>ewpc_array(pcew_no(i))
n_equal=0
pc%z=0.0_rk
pc%c=0.0_rk
do ii=i,ewpc_N
n_equal=n_equal+1
pc%z=pc%z+pcew_temp(4,ii)
if(ii.eq.ewpc_N) exit
if(pcew_no(ii+1).ne.pcew_no(ii)) exit
enddo !ii=i,ewpc_N
pc%z=pc%z/n_equal
allocate(pc%position(3,n_equal),stat=ewa_allocstat(4))
ASSERT(ewa_allocstat(4).eq.0)
ewa_allocstat(4)=1
pc%name='ewpc '
pc%N_equal_charges= n_equal
pc%position_first_ec=pcew_temp(1:3,i)
do ii=1,n_equal
pc%position(:,ii)=pcew_temp(1:3,i+ii-1)
n_ewpc_arr=n_ewpc_arr+1
!!! print all generated charges
#if 0 /* print all ewpc */
if(print_epe) &
print '(4f15.8,i4,4i4)',pc%position(:,ii),pc%z,n_equal,ii,pcew_no(i),n_ewpc_arr
write(output_unit, '(4f15.8,i4,4i4)') pc%position(:,ii), &
pc%z,n_equal,0,0,1,0
#endif
enddo ! ii=1,equal
! print only first atoms in the group
!!$ write(output_unit, '(4f15.8,i3,4i2,f15.8)') &
! print '(4f15.8,i3,4i2,f15.8)' &
! pc%position(:,1),pc%z,n_equal,0,0,1,0, &
! sqrt(sum((unique_atoms(1)%position(:,1) &
! -pc%position(:,1))**2))
!!$ write(output_unit, '(4f15.8,i3,4i2,f15.8,i4)') &
! if(print_epe) print '(4f15.8,i4,4i4,f15.8,i4)', &
! pc%position(:,1),pc%z,n_equal,0,0,1,0, &
! sqrt(sum((unique_atoms(1)%position(:,1) &
! -pc%position(:,1))**2)),(pcew_no(i))
i=i+n_equal
enddo ewpcarr_wh
if(output_unit > 0) write(output_unit,*) &
'number of groups of symmetry equavalent ewpc PC',it_ewpc
ewpc_n=it_ewpc
if(comm_rank() == 0) then
DPRINT 'it_ewpc',it_ewpc
endif
!** done
pcr_n_ex: if(pcr_n.ne.0) then
if(output_unit > 0) then
write(output_unit,*) &
'** store not coinciding pcr centers'
if(print_epe) print*,'** store not coinciding pcr centers_____________', &
size(pcc_array),size(pcs_array)
endif
i=1+kl_pcr
ewpcarr_pcr: do while(i.le.pcr_n) ! total number of atoms in epe.pcr
ASSERT(pcr_no(i)+ewpc_n.le.size(ewpc_array))
pc=>ewpc_array(pcr_no(i)+ewpc_n)
n_equal=0
pc%z=0.0_rk
do ii=i,pcr_n
n_equal=n_equal+1
pc%z=pc%z-pcr_temp(4,ii) ! negative charge for virtual PC
if(ii.eq.pcr_n) exit
if(pcr_no(ii+1).ne.pcr_no(ii)) exit
enddo
pc%z=pc%z/n_equal
pc%c=0.0_rk
allocate(pc%position(3,n_equal),stat=ewa_allocstat(4))
ASSERT(ewa_allocstat(4).eq.0)
ewa_allocstat(4)=1
pc%name='pcr '
pc%N_equal_charges= n_equal
pc%position_first_ec=pcr_temp(1:3,i)
do ii=1,n_equal
pc%position(:,ii)=pcr_temp(1:3,i+ii-1)
n_ewpc_arr=n_ewpc_arr+1
!!! print all generated charges
#if 0 /* print all pcr */
if(print_epe) print '(4f15.8,i4,4i4)',pc%position(:,ii),pc%z,n_equal,ii,pcr_no(i)+ewpc_n,n_ewpc_arr
#endif
!!! write(output_unit, '(4f15.8,i3,4i2)'),pc%position(:,ii),&
!!! pc%z,n_equal,0,0,1,0
enddo ! ii=1,equal
! print only first atoms in the group
!!$ write(output_unit, '(4f15.8,i3,4i2,f15.8)') &
!!$ pc%position(:,1),pc%z,n_equal,0,0,1,0, &
!!$ sqrt(sum((unique_atoms(1)%position(:,1) &
!!$ -pc%position(:,1))**2))
!!$ print '(4f15.8,i3,4i2,f15.8)',pc%position(:,1),pc%z,n_equal,0,0,1,0, &
!!$ sqrt(sum((unique_atoms(1)%position(:,1) &
!!$ -pc%position(:,1))**2))
i=i+n_equal
enddo ewpcarr_pcr
if(output_unit > 0) write(output_unit,*) 'number of groups of symmetry equavalent pcr PC',it_pcr
ewpc_n=ewpc_n+it_pcr
if(comm_rank() == 0) then
DPRINT 'it_ewpc + it_pcr', ewpc_n
endif
!** done
endif pcr_n_ex
start_regI_epevar=ewpc_n+1
cluster_nuc_epe_en=0.0_rk
store_pcs: if(pcs_n.ne.0) then !** store pcs centers and calculate
! cluster_nuc_epe_en for epe shells
if(comm_rank() == 0) then
if(print_epe) print*,' ewpc_array (epe.pcs part) :'
endif
min_pcsdist=100.0
do na=1,size(pcs_array)
pc=>ewpc_array(na+ewpc_n)
allocate(pc%position(3,pcs_array(na)%n_equal_charges))
! pc=pcs_array(na)
pc%z=pcs_array(na)%z
pc%c=0.0_rk
pc%name=pcs_array(na)%name
pc%n_equal_charges=pcs_array(na)%n_equal_charges
pc%position=pcs_array(na)%position
pc%position_first_ec=pcs_array(na)%position_first_ec
#if 0 /* delete deference with ewpc_temp */
pc%position=pcr_array(na)%position
#endif
#if 1 /* control cluster_nuc_epe_en */
do eq_pcs=1,pc%n_equal_charges
do i=1,N_unique_atoms+n_timps
if(i.gt.N_unique_atoms) then
ua=>unique_timps(i-N_unique_atoms)
do eq_a=1,ua%N_equal_atoms
dist=sqrt(sum((ua%position(:,eq_a) &
-pc%position(:,eq_pcs))**2))
cluster_nuc_epe_en=cluster_nuc_epe_en+ &
pc%z*(ua%Z-ua%zc)/dist
enddo
else ! reg atom
do eq_a=1,unique_atoms(i)%N_equal_atoms
dist=sqrt(sum((unique_atoms(i)%position(:,eq_a) &
-pc%position(:,eq_pcs))**2))
min_pcsdist=min(min_pcsdist,dist)
cluster_nuc_epe_en=cluster_nuc_epe_en+ &
pc%z*(unique_atoms(i)%Z-unique_atoms(i)%zc)/dist
enddo
end if
enddo
n_ewpc_arr=n_ewpc_arr+1
#if 0 /* print all pcc */
if(print_epe) print '(4f15.8,i4,4i4,i5)', &
pc%position(:,eq_pcs),pc%z,pc%n_equal_charges,eq_pcs,na+ewpc_n,n_ewpc_arr
#endif
enddo
! print '(4f15.8,i3,4i2,i5)',pc%position(:,1),pc%z,pc%n_equal_charges,0,0,1,0,na+ewpc_n
if(comm_rank() == 0) then
DPRINT na, cluster_nuc_epe_en,pc%N_equal_charges,pc%z,sum(pc%position(:,pc%N_equal_charges))
endif
#endif
enddo ! N_unique_pcr
if(comm_rank() == 0) then
DPRINT 'min_pcsdist', min_pcsdist
DPRINT 'cluster_nuc_epe_en pcs', cluster_nuc_epe_en
endif
ewpc_n=ewpc_n+size(pcs_array)
endif store_pcs
#if 0
call read_pc_array(ewpc_array,'ewpc_arra',ewpc_n)
if(associated(pcc_array)) then
do na=1,size(pcc_array)
deallocate(pcc_array(na)%position,stat=ewa_allocstat(26))
ASSERT(ewa_allocstat(26).eq.0)
enddo
deallocate(pcc_array,stat=ewa_allocstat(19))
ASSERT(ewa_allocstat(19).eq.0)
endif
! if(pcs_n.ne.0) then
if(associated(pcs_array)) then
do na=1,size(pcs_array)
deallocate(pcs_array(na)%position,stat=ewa_allocstat(25))
ASSERT(ewa_allocstat(25).eq.0)
enddo
deallocate(pcs_array,stat=ewa_allocstat(18))
ASSERT(ewa_allocstat(18).eq.0)
endif
call print_e_nuc_ewpc()
return
#endif
store_pcc: if(pcc_n.ne.0) then !** store pcc centers and calculate
! cluster_nuc_epe_en for epe cores
if(comm_rank() == 0) then
if(print_epe) print*,' ewpc_array (epe.pcc part) :'
endif
nullify(pc)
min_pccdist=100.0
do na=1,size(pcc_array)
ASSERT(na+ewpc_n.le.size(ewpc_array))
pc=>ewpc_array(na+ewpc_n)
! pc=pcc_array(na)
allocate(pc%position(3,pcc_array(na)%n_equal_charges))
! pc=pcs_array(na)
pc%z=pcc_array(na)%z
pc%c=0.0_rk
pc%name=pcc_array(na)%name
pc%n_equal_charges=pcc_array(na)%n_equal_charges
pc%position=pcc_array(na)%position
pc%position_first_ec=pcc_array(na)%position_first_ec
#if 0 /* delete deference with ewpc_temp */
pc%position=pcr_array(na)%position
#endif
#if 1 /* control cluster_nuc_epe_en */
do eq_pcc=1,pc%n_equal_charges
do i=1,N_unique_atoms+n_timps
if(i.gt.N_unique_atoms) then
ua=>unique_timps(i-N_unique_atoms)
do eq_a=1,ua%N_equal_atoms
dist=sqrt(sum((ua%position(:,eq_a) &
-pc%position(:,eq_pcc))**2))
cluster_nuc_epe_en=cluster_nuc_epe_en &
+pc%z*(ua%Z-ua%ZC)/dist
enddo
else
do eq_a=1,unique_atoms(i)%N_equal_atoms
dist=sqrt(sum((unique_atoms(i)%position(:,eq_a) &
-pc%position(:,eq_pcc))**2))
min_pccdist=min(dist,min_pccdist)
cluster_nuc_epe_en=cluster_nuc_epe_en &
+pc%z*(unique_atoms(i)%Z-unique_atoms(i)%ZC)/dist
enddo
end if
enddo
n_ewpc_arr=n_ewpc_arr+1
#if 0 /* print all pcc */
if(print_epe) print '(4f15.8,i4,4i4,i5)', &
pc%position(:,eq_pcc),pc%z,pc%n_equal_charges,eq_pcc,na+ewpc_n,n_ewpc_arr
#endif
enddo
! print '(4f15.8,i3,4i2,i5)',pc%position(:,1),pc%z,pc%n_equal_charges,0,0,1,0,na+ewpc_n
#endif
enddo ! N_unique_pcr
if(comm_rank() == 0) then
DPRINT 'min_pccdist',min_pccdist
endif
ewpc_n=ewpc_n+size(pcc_array)
endif store_pcc
deallocate(pcew_temp,stat=ewa_allocstat(21))
ASSERT(ewa_allocstat(21).eq.0)
ewpc_array_charge=0.0_rk
do na=1,ewpc_n
ewpc_array_charge = ewpc_array_charge+ewpc_array(na)%z*ewpc_array(na)%n_equal_charges
enddo
if(output_unit > 0) then
if(print_epe) print*, 'ewpc_array_charge ', ewpc_array_charge
write(output_unit,*) 'final number of ewald and epe centers '
write(output_unit,*) 'to model external field actin on claster '
write(output_unit,*) ewpc_n
write(output_unit,*)
write(output_unit,*) 'energy of interaction of the claster nuclei'
write(output_unit,*) 'with epe only centers, cluster_nuc_epe_en'
write(output_unit,*) cluster_nuc_epe_en
if(comm_rank() == 0) then
if(print_epe) &
print*, 'cluster_nuc_epe_en calculated with ewpc_array coinciding and the same charges ', cluster_nuc_epe_en
if(print_epe) print*, 'PCR_N----', pcr_n
endif
endif
if(pcr_n.ne.0) then
! deallocate(pcr_temp,pcr_no,psb_ind, stat=ewa_allocstat(9))
deallocate(pcr_temp,pcr_no, stat=ewa_allocstat(9))
ASSERT(ewa_allocstat(9).eq.0)
end if
! if(pcr_n.ne.0) then
if(associated(pcr_array)) then
do na=1,size(pcr_array)
deallocate(pcr_array(na)%position,stat=ewa_allocstat(24))
ASSERT(ewa_allocstat(24).eq.0)
enddo
deallocate(pcr_array,stat=ewa_allocstat(17))
ASSERT(ewa_allocstat(17).eq.0)
if(comm_rank() == 0) print*,'pcr_array deallocated'
endif
! if(pcc_n.ne.0) then
if(associated(pcc_array)) then
do na=1,size(pcc_array)
deallocate(pcc_array(na)%position,stat=ewa_allocstat(26))
ASSERT(ewa_allocstat(26).eq.0)
enddo
deallocate(pcc_array,stat=ewa_allocstat(19))
ASSERT(ewa_allocstat(19).eq.0)
endif
! if(pcs_n.ne.0) then
if(associated(pcs_array)) then
do na=1,size(pcs_array)
deallocate(pcs_array(na)%position,stat=ewa_allocstat(25))
ASSERT(ewa_allocstat(25).eq.0)
enddo
deallocate(pcs_array,stat=ewa_allocstat(18))
ASSERT(ewa_allocstat(18).eq.0)
endif
if(allocated(pcew_no)) then
deallocate(pcew_no,stat=ewa_allocstat(27))
ASSERT(ewa_allocstat(27).eq.0)
endif
nullify(pc)
e_nuc_ewpc=0.0_rk
! print*, n_ewpc_arr, 'n_ewpc_arr xx'
! print*
min_ewpcdist=100.0_rk
do na=1,ewpc_n
pc=>ewpc_array(na)
do eq_pcc=1,pc%n_equal_charges
! print*,' F',pc%position(:,eq_pcc)*0.529,pc%z,na
j=0
do i=1,N_unique_atoms+n_timps
if(i.gt.N_unique_atoms) then
ua=>unique_timps(i-N_unique_atoms)
do eq_a=1,ua%N_equal_atoms
dist=sqrt(sum((ua%position(:,eq_a) &
-pc%position(:,eq_pcc))**2))
e_nuc_ewpc=e_nuc_ewpc+pc%z*(ua%Z-ua%ZC)/dist
enddo
else
do eq_a=1,unique_atoms(i)%N_equal_atoms
j=j+1
dist=sqrt(sum((unique_atoms(i)%position(:,eq_a) &
-pc%position(:,eq_pcc))**2))
e_nuc_ewpc=e_nuc_ewpc &