-
Notifications
You must be signed in to change notification settings - Fork 19
/
descriptors_noncommercial.inc
5292 lines (4254 loc) · 234 KB
/
descriptors_noncommercial.inc
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
! HND XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
! HND X
! HND X GAP (Gaussian Approximation Potental)
! HND X
! HND X
! HND X Portions of GAP were written by Albert Bartok-Partay, Gabor Csanyi,
! HND X Copyright 2006-2021.
! HND X
! HND X Portions of GAP were written by Noam Bernstein as part of
! HND X his employment for the U.S. Government, and are not subject
! HND X to copyright in the USA.
! HND X
! HND X GAP is published and distributed under the
! HND X Academic Software License v1.0 (ASL)
! HND X
! HND X GAP is distributed in the hope that it will be useful for non-commercial
! HND X academic research, but WITHOUT ANY WARRANTY; without even the implied
! HND X warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! HND X ASL for more details.
! HND X
! HND X You should have received a copy of the ASL along with this program
! HND X (e.g. in a LICENSE.md file); if not, you can write to the original licensors,
! HND X Gabor Csanyi or Albert Bartok-Partay. The ASL is also published at
! HND X http://github.com/gabor1/ASL
! HND X
! HND X When using this software, please cite the following reference:
! HND X
! HND X A. P. Bartok et al Physical Review Letters vol 104 p136403 (2010)
! HND X
! HND X When using the SOAP kernel or its variants, please additionally cite:
! HND X
! HND X A. P. Bartok et al Physical Review B vol 87 p184115 (2013)
! HND X
! HND XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
! HND X
! HND X
! HND X This file contains descriptors written by others, not A. P. Bartok and Gabor Csanyi
! HND X and the code here is owned by their respective authors, as indicated below.
! HND X
!!!!!!!!
!!! Work of Wojciech Szlachta BEGINS here
!!!!!!!!
subroutine bond_real_space_initialise(this,args_str,error)
type(bond_real_space), intent(inout) :: this
character(len=*), intent(in) :: args_str
integer, optional, intent(out) :: error
type(Dictionary) :: params
INIT_ERROR(error)
call finalise(this)
call initialise(params)
call param_register(params, 'bond_cutoff', '0.00', this%bond_cutoff, help_string="Bond cutoff for bond_real_space-type descriptors")
call param_register(params, 'bond_transition_width', '0.00', this%bond_transition_width, help_string="Bond transition width for bond_real_space-type descriptors")
call param_register(params, 'cutoff', '0.00', this%cutoff, help_string="Space cutoff for bond_real_space-type descriptors")
call param_register(params, 'transition_width', '0.00', this%transition_width, help_string="Space transition width for bond_real_space-type descriptors")
call param_register(params, 'atom_gaussian_width', '0.00', this%atom_sigma, help_string="Atom sigma for bond_real_space-type descriptors", altkey='atom_sigma')
call param_register(params, 'max_neighbours', '0', this%max_neighbours, help_string="Maximum number of neighbours")
if (.not. param_read_line(params, args_str, ignore_unknown=.true.,task='bond_real_space_initialise args_str')) then
RAISE_ERROR("bond_real_space_initialise failed to parse args_str='"//trim(args_str)//"'", error)
endif
call finalise(params)
this%initialised = .true.
endsubroutine bond_real_space_initialise
subroutine bond_real_space_finalise(this,error)
type(bond_real_space), intent(inout) :: this
integer, optional, intent(out) :: error
INIT_ERROR(error)
if(.not. this%initialised) return
this%bond_cutoff = 0.0_dp
this%bond_transition_width = 0.0_dp
this%cutoff = 0.0_dp
this%transition_width = 0.0_dp
this%atom_sigma = 0.0_dp
this%max_neighbours = 0
this%initialised = .false.
endsubroutine bond_real_space_finalise
subroutine bond_real_space_calc(this,at,descriptor_out,do_descriptor,do_grad_descriptor,args_str,error)
type(bond_real_space), intent(in) :: this
type(atoms), intent(in) :: at
type(descriptor_data), intent(out) :: descriptor_out
logical, intent(in), optional :: do_descriptor, do_grad_descriptor
character(len=*), intent(in), optional :: args_str
integer, optional, intent(out) :: error
type(Dictionary) :: params
character(STRING_LENGTH) :: atom_mask_name
logical :: has_atom_mask_name
logical, dimension(:), pointer :: atom_mask_pointer
type(atoms) :: at_copy
logical :: my_do_descriptor, my_do_grad_descriptor
integer :: n_descriptors, n_cross, i_desc, i, j, n, k, m, m_index, l, &
ij_neighbours, n_index
integer, dimension(3) :: shift_j, shift_k
real(dp) :: r_ij, r_ijk
real(dp) :: atom_i(3), atom_j(3), atom_k(3), bond(3), bond_len
real(dp) :: atom_i_cross_atom_j(3), atom_i_normsq_min_atom_j_normsq
real(dp), allocatable :: r(:,:), z(:), c(:)
real(dp) :: self_overlap
real(dp), allocatable :: dr(:,:,:,:), dz(:,:,:), dc(:,:,:)
real(dp), allocatable :: dself_overlap(:,:)
integer, allocatable :: ii(:)
real(dp), allocatable :: pos(:,:)
real(dp) :: r_m_cross_r_l(3)
INIT_ERROR(error)
call system_timer('bond_real_space_calc')
if(.not. this%initialised) then
RAISE_ERROR("bond_real_space_calc: descriptor object not initialised", error)
endif
my_do_descriptor = optional_default(.false., do_descriptor)
my_do_grad_descriptor = optional_default(.false., do_grad_descriptor)
if( .not. my_do_descriptor .and. .not. my_do_grad_descriptor ) return
call finalise(descriptor_out)
atom_mask_pointer => null()
if(present(args_str)) then
call initialise(params)
call param_register(params, 'atom_mask_name', 'NONE', atom_mask_name, has_value_target=has_atom_mask_name, &
help_string="Name of a logical property in the atoms object. For atoms where this property is true descriptors are " // &
"calculated.")
if (.not. param_read_line(params,args_str,ignore_unknown=.true.,task='bond_real_space_calc args_str')) then
RAISE_ERROR("bond_real_space_calc failed to parse args_str='"//trim(args_str)//"'", error)
endif
call finalise(params)
if( has_atom_mask_name ) then
if (.not. assign_pointer(at, trim(atom_mask_name), atom_mask_pointer)) then
RAISE_ERROR("bond_real_space_calc did not find "//trim(atom_mask_name)//" property in the atoms object.", error)
endif
RAISE_ERROR("bond_real_space_calc cannot use atom masks yet.",error)
else
atom_mask_pointer => null()
endif
endif
call descriptor_sizes(this,at,n_descriptors,n_cross,n_index=n_index,error=error)
allocate(descriptor_out%x(n_descriptors))
i_desc = 0
do i = 1, at%N
do n = 1, n_neighbours(at, i)
j = neighbour(at, i, n, shift=shift_j, distance=r_ij, max_dist=this%bond_cutoff)
if(j == 0) cycle
i_desc = i_desc + 1
atom_i = at%pos(:,i)
atom_j = at%pos(:,j) + matmul(at%lattice, shift_j)
at_copy = at
call add_atoms(at_copy, 0.5_dp * (atom_i + atom_j), 1)
call calc_connect(at_copy)
ij_neighbours = 0
do m = 1, n_neighbours(at_copy, at%N + 1)
k = neighbour(at_copy, at%N + 1, m, max_dist=this%cutoff)
if(k == 0) cycle
if(at_copy%pos(:,k) .feq. at_copy%pos(:,at%N + 1)) cycle
ij_neighbours = ij_neighbours + 1
enddo
if(ij_neighbours > this%max_neighbours) then
RAISE_ERROR("bond_real_space_calc: number of neighbours exceeds max_neighbours", error)
endif
if(my_do_descriptor .or. my_do_grad_descriptor) then
allocate(r(3,ij_neighbours), z(ij_neighbours), c(ij_neighbours))
allocate(ii(ij_neighbours), pos(3,ij_neighbours))
r = 0.0_dp
z = 0.0_dp
c = 0.0_dp
self_overlap = 0.0_dp
bond = atom_i - atom_j
bond_len = norm(bond)
atom_i_cross_atom_j = atom_i .cross. atom_j
atom_i_normsq_min_atom_j_normsq = normsq(atom_i) - normsq(atom_j)
ii = 0
pos = 0.0_dp
if(my_do_grad_descriptor) then
allocate(dr(3,ij_neighbours,3,ij_neighbours), dz(ij_neighbours,3,ij_neighbours), dc(ij_neighbours,3,ij_neighbours), dself_overlap(3,ij_neighbours))
dr = 0.0_dp
dz = 0.0_dp
dc = 0.0_dp
dself_overlap = 0.0_dp
endif
m_index = 2
do m = 1, n_neighbours(at_copy, at%N + 1)
k = neighbour(at_copy, at%N + 1, m, shift=shift_k, distance=r_ijk, max_dist=this%cutoff)
if(k == 0) cycle
if(at_copy%pos(:,k) .feq. at_copy%pos(:,at%N + 1)) cycle
atom_k = at_copy%pos(:,k) + matmul(at_copy%lattice, shift_k)
if(atom_k .feq. atom_i) then
! r remains zero
z(1) = 0.5_dp * bond_len
c(1) = coordination_function(r_ijk, this%cutoff, this%transition_width)
ii(1) = k
pos(:,1) = atom_k
if(my_do_grad_descriptor) then
! dr remains zero
dz(1,:,1) = 0.5_dp * bond / bond_len
dz(1,:,2) = - dz(1,:,1)
dc(1,:,1) = 0.25_dp * dcoordination_function(r_ijk, this%cutoff, this%transition_width) * bond / r_ijk
dc(1,:,2) = - dc(1,:,1)
endif
elseif(atom_k .feq. atom_j) then
! r remain zero
z(2) = -0.5_dp * bond_len
c(2) = coordination_function(r_ijk, this%cutoff, this%transition_width)
ii(2) = k
pos(:,2) = atom_k
if(my_do_grad_descriptor) then
! dr remains zero
dz(2,:,1) = -0.5_dp * bond / bond_len
dz(2,:,2) = - dz(2,:,1)
dc(2,:,1) = -0.25_dp * dcoordination_function(r_ijk, this%cutoff, this%transition_width) * bond / r_ijk
dc(2,:,2) = - dc(2,:,1)
endif
else
m_index = m_index + 1
r(:,m_index) = ((atom_k .cross. bond) + atom_i_cross_atom_j) / bond_len
z(m_index) = ((atom_k .dot. bond) - 0.5_dp * atom_i_normsq_min_atom_j_normsq) / bond_len
c(m_index) = coordination_function(r_ijk, this%cutoff, this%transition_width)
ii(m_index) = k
pos(:,m_index) = atom_k
if(my_do_grad_descriptor) then
dr(:,m_index,1,1) = ((/ 0.0_dp, atom_k(3) - atom_j(3), atom_j(2) - atom_k(2) /) / bond_len) - (r(:,m_index) * bond(1) / bond_len**2)
dr(:,m_index,2,1) = ((/ atom_j(3) - atom_k(3), 0.0_dp, atom_k(1) - atom_j(1) /) / bond_len) - (r(:,m_index) * bond(2) / bond_len**2)
dr(:,m_index,3,1) = ((/ atom_k(2) - atom_j(2), atom_j(1) - atom_k(1), 0.0_dp /) / bond_len) - (r(:,m_index) * bond(3) / bond_len**2)
dz(m_index,:,1) = ((atom_k - atom_i) / bond_len) - (z(m_index) * bond / bond_len**2)
dc(m_index,:,1) = -0.5_dp * dcoordination_function(r_ijk, this%cutoff, this%transition_width) * (atom_k - at_copy%pos(:,at%N + 1)) / r_ijk
dr(:,m_index,1,2) = - dr(:,m_index,1,1) + ((/ 0.0_dp, bond(3), - bond(2) /) / bond_len)
dr(:,m_index,2,2) = - dr(:,m_index,2,1) + ((/ - bond(3), 0.0_dp, bond(1) /) / bond_len)
dr(:,m_index,3,2) = - dr(:,m_index,3,1) + ((/ bond(2), - bond(1), 0.0_dp /) / bond_len)
dz(m_index,:,2) = - dz(m_index,:,1) - (bond / bond_len)
dc(m_index,:,2) = dc(m_index,:,1)
dr(:,m_index,1,m_index) = (/ 0.0_dp, - bond(3), bond(2) /) / bond_len
dr(:,m_index,2,m_index) = (/ bond(3), 0.0_dp, - bond(1) /) / bond_len
dr(:,m_index,3,m_index) = (/ - bond(2), bond(1), 0.0_dp /) / bond_len
dz(m_index,:,m_index) = bond / bond_len
dc(m_index,:,m_index) = -2.0_dp * dc(m_index,:,1)
endif
endif
enddo
endif
if(my_do_descriptor) then
allocate(descriptor_out%x(i_desc)%data(2 + (1 + 2 * this%max_neighbours) * this%max_neighbours))
allocate(descriptor_out%x(i_desc)%ci(n_index))
descriptor_out%x(i_desc)%data = 0.0_dp
do m = 1, ij_neighbours
self_overlap = self_overlap + c(m)**2
if(m == 1) then
descriptor_out%x(i_desc)%data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * m)) = z(m)
elseif(m == 2) then
descriptor_out%x(i_desc)%data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * m)) = z(m)
self_overlap = self_overlap + 2.0_dp * c(m) * c(m - 1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 )
else
do l = 3, ij_neighbours
if(l == m) then
descriptor_out%x(i_desc)%data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1) = normsq(r(:,m))
descriptor_out%x(i_desc)%data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l)) = z(m)
else
descriptor_out%x(i_desc)%data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1) = r(:,m) .dot. r(:,l)
descriptor_out%x(i_desc)%data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l)) = ((r(:,m) .cross. r(:,l)) .dot. bond) / bond_len
endif
if(l < m) then
self_overlap = self_overlap + 2.0_dp * c(m) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 )
endif
enddo
endif
enddo
descriptor_out%x(i_desc)%data(1) = real(ij_neighbours, dp)
descriptor_out%x(i_desc)%data(2) = self_overlap
descriptor_out%x(i_desc)%data(3:ij_neighbours + 2) = c
descriptor_out%x(i_desc)%covariance_cutoff = coordination_function(r_ij, this%bond_cutoff, this%bond_transition_width)
descriptor_out%x(i_desc)%ci(:) = (/ i, j /)
descriptor_out%x(i_desc)%has_data = .true.
endif
if(my_do_grad_descriptor) then
allocate(descriptor_out%x(i_desc)%grad_data(2 + (1 + 2 * ij_neighbours) * ij_neighbours,3,ij_neighbours))
allocate(descriptor_out%x(i_desc)%ii(ij_neighbours))
allocate(descriptor_out%x(i_desc)%pos(3,ij_neighbours))
allocate(descriptor_out%x(i_desc)%grad_covariance_cutoff(3,ij_neighbours))
allocate(descriptor_out%x(i_desc)%has_grad_data(ij_neighbours))
descriptor_out%x(i_desc)%grad_data = 0.0_dp
do m = 1, ij_neighbours
dself_overlap(:,1) = dself_overlap(:,1) + 2.0_dp * c(m) * dc(m,:,1)
dself_overlap(:,2) = dself_overlap(:,2) + 2.0_dp * c(m) * dc(m,:,2)
if(m == 1) then
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * m),:,1) = dz(m,:,1)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * m),:,2) = dz(m,:,2)
elseif(m == 2) then
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * m),:,1) = dz(m,:,1)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * m),:,2) = dz(m,:,2)
dself_overlap(:,1) = dself_overlap(:,1) + 2.0_dp * dc(m,:,1) * c(m - 1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(m - 1,:,1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 ) \
+ c(m) * c(m - 1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 ) \
* (pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2
dself_overlap(:,2) = dself_overlap(:,2) + 2.0_dp * dc(m,:,2) * c(m - 1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(m - 1,:,2) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 ) \
+ c(m) * c(m - 1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,m - 1)) / this%atom_sigma**2 ) \
* (pos(:,m - 1) - pos(:,m)) / this%atom_sigma**2
else
dself_overlap(:,m) = dself_overlap(:,m) + 2.0_dp * c(m) * dc(m,:,m)
do l = 3, ij_neighbours
if(l == m) then
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,1) = 2.0_dp * (r(:,m) .dot. dr(:,m,1,1))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,1) = 2.0_dp * (r(:,m) .dot. dr(:,m,2,1))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,1) = 2.0_dp * (r(:,m) .dot. dr(:,m,3,1))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),:,1) = dz(m,:,1)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,2) = 2.0_dp * (r(:,m) .dot. dr(:,m,1,2))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,2) = 2.0_dp * (r(:,m) .dot. dr(:,m,2,2))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,2) = 2.0_dp * (r(:,m) .dot. dr(:,m,3,2))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),:,2) = dz(m,:,2)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,m) = 2.0_dp * (r(:,m) .dot. dr(:,m,1,m))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,m) = 2.0_dp * (r(:,m) .dot. dr(:,m,2,m))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,m) = 2.0_dp * (r(:,m) .dot. dr(:,m,3,m))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),:,m) = dz(m,:,m)
else
r_m_cross_r_l = r(:,m) .cross. r(:,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,1) = (dr(:,m,1,1) .dot. r(:,l)) + (r(:,m) .dot. dr(:,l,1,1))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,1) = (dr(:,m,2,1) .dot. r(:,l)) + (r(:,m) .dot. dr(:,l,2,1))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,1) = (dr(:,m,3,1) .dot. r(:,l)) + (r(:,m) .dot. dr(:,l,3,1))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),1,1) = ((((dr(:,m,1,1) .cross. r(:,l)) + (r(:,m) .cross. dr(:,l,1,1))) .dot. bond) + (r_m_cross_r_l .dot. ((/ 1.0_dp, 0.0_dp, 0.0_dp /) - (bond * bond(1) / bond_len**2)))) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),2,1) = ((((dr(:,m,2,1) .cross. r(:,l)) + (r(:,m) .cross. dr(:,l,2,1))) .dot. bond) + (r_m_cross_r_l .dot. ((/ 0.0_dp, 1.0_dp, 0.0_dp /) - (bond * bond(2) / bond_len**2)))) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),3,1) = ((((dr(:,m,3,1) .cross. r(:,l)) + (r(:,m) .cross. dr(:,l,3,1))) .dot. bond) + (r_m_cross_r_l .dot. ((/ 0.0_dp, 0.0_dp, 1.0_dp /) - (bond * bond(3) / bond_len**2)))) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,2) = (dr(:,m,1,2) .dot. r(:,l)) + (r(:,m) .dot. dr(:,l,1,2))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,2) = (dr(:,m,2,2) .dot. r(:,l)) + (r(:,m) .dot. dr(:,l,2,2))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,2) = (dr(:,m,3,2) .dot. r(:,l)) + (r(:,m) .dot. dr(:,l,3,2))
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),1,2) = ((((dr(:,m,1,2) .cross. r(:,l)) + (r(:,m) .cross. dr(:,l,1,2))) .dot. bond) + (r_m_cross_r_l .dot. ((/ -1.0_dp, 0.0_dp, 0.0_dp /) + (bond * bond(1) / bond_len**2)))) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),2,2) = ((((dr(:,m,2,2) .cross. r(:,l)) + (r(:,m) .cross. dr(:,l,2,2))) .dot. bond) + (r_m_cross_r_l .dot. ((/ 0.0_dp, -1.0_dp, 0.0_dp /) + (bond * bond(2) / bond_len**2)))) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),3,2) = ((((dr(:,m,3,2) .cross. r(:,l)) + (r(:,m) .cross. dr(:,l,3,2))) .dot. bond) + (r_m_cross_r_l .dot. ((/ 0.0_dp, 0.0_dp, -1.0_dp /) + (bond * bond(3) / bond_len**2)))) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,m) = dr(:,m,1,m) .dot. r(:,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,m) = dr(:,m,2,m) .dot. r(:,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,m) = dr(:,m,3,m) .dot. r(:,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),1,m) = ((dr(:,m,1,m) .cross. r(:,l)) .dot. bond) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),2,m) = ((dr(:,m,2,m) .cross. r(:,l)) .dot. bond) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),3,m) = ((dr(:,m,3,m) .cross. r(:,l)) .dot. bond) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,1,l) = r(:,m) .dot. dr(:,l,1,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,2,l) = r(:,m) .dot. dr(:,l,2,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l) - 1,3,l) = r(:,m) .dot. dr(:,l,3,l)
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),1,l) = ((r(:,m) .cross. dr(:,l,1,l)) .dot. bond) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),2,l) = ((r(:,m) .cross. dr(:,l,2,l)) .dot. bond) / bond_len
descriptor_out%x(i_desc)%grad_data(2 + ij_neighbours + (2 * (m - 1) * ij_neighbours) + (2 * l),3,l) = ((r(:,m) .cross. dr(:,l,3,l)) .dot. bond) / bond_len
endif
if(l < m) then
dself_overlap(:,m) = dself_overlap(:,m) + 2.0_dp * dc(m,:,m) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ c(m) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
* (pos(:,l) - pos(:,m)) / this%atom_sigma**2
if(l == 1) then
dself_overlap(:,1) = dself_overlap(:,1) + 2.0_dp * dc(m,:,1) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(l,:,1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ c(m) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
* (pos(:,m) - pos(:,l)) / this%atom_sigma**2
dself_overlap(:,2) = dself_overlap(:,2) + 2.0_dp * dc(m,:,2) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(l,:,2) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 )
elseif(l == 2) then
dself_overlap(:,1) = dself_overlap(:,1) + 2.0_dp * dc(m,:,1) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(l,:,1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 )
dself_overlap(:,2) = dself_overlap(:,2) + 2.0_dp * dc(m,:,2) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(l,:,2) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ c(m) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
* (pos(:,m) - pos(:,l)) / this%atom_sigma**2
else
dself_overlap(:,1) = dself_overlap(:,1) + 2.0_dp * dc(m,:,1) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(l,:,1) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 )
dself_overlap(:,2) = dself_overlap(:,2) + 2.0_dp * dc(m,:,2) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ 2.0_dp * c(m) * dc(l,:,2) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 )
dself_overlap(:,l) = dself_overlap(:,l) + 2.0_dp * c(m) * dc(l,:,l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
+ c(m) * c(l) * exp( -0.25_dp * normsq(pos(:,m) - pos(:,l)) / this%atom_sigma**2 ) \
* (pos(:,m) - pos(:,l)) / this%atom_sigma**2
endif
endif
enddo
endif
enddo
!descriptor_out%x(i_desc)%grad_data(1,:,:) = 0.0_dp
descriptor_out%x(i_desc)%grad_data(2,:,:) = dself_overlap
descriptor_out%x(i_desc)%grad_data(3:ij_neighbours + 2,:,:) = dc
descriptor_out%x(i_desc)%ii = ii
descriptor_out%x(i_desc)%pos = pos
descriptor_out%x(i_desc)%grad_covariance_cutoff = 0.0_dp
descriptor_out%x(i_desc)%grad_covariance_cutoff(:,1) = dcoordination_function(r_ij, this%bond_cutoff, this%bond_transition_width) * bond / r_ij
descriptor_out%x(i_desc)%grad_covariance_cutoff(:,2) = - descriptor_out%x(i_desc)%grad_covariance_cutoff(:,1)
descriptor_out%x(i_desc)%has_grad_data = .true.
endif
if(my_do_descriptor .or. my_do_grad_descriptor) then
deallocate(r, z, c)
deallocate(ii, pos)
if(my_do_grad_descriptor) then
deallocate(dr, dz, dc, dself_overlap)
endif
endif
call finalise(at_copy)
enddo
enddo
call system_timer('bond_real_space_calc')
endsubroutine bond_real_space_calc
function bond_real_space_dimensions(this,error) result(i)
type(bond_real_space), intent(in) :: this
integer, optional, intent(out) :: error
integer :: i
INIT_ERROR(error)
if(.not. this%initialised) then
RAISE_ERROR("bond_real_space_dimensions: descriptor object not initialised", error)
endif
i = 2 + (1 + 2 * this%max_neighbours) * this%max_neighbours
endfunction bond_real_space_dimensions
function bond_real_space_cutoff(this,error)
type(bond_real_space), intent(in) :: this
integer, optional, intent(out) :: error
real(dp) :: bond_real_space_cutoff
INIT_ERROR(error)
if(.not. this%initialised) then
RAISE_ERROR("bond_real_space_cutoff: descriptor object not initialised", error)
endif
bond_real_space_cutoff = max(this%cutoff, this%bond_cutoff)
endfunction bond_real_space_cutoff
subroutine bond_real_space_sizes(this,at,n_descriptors,n_cross,mask,n_index,error)
type(bond_real_space), intent(in) :: this
type(atoms), intent(in) :: at
integer, intent(out) :: n_descriptors, n_cross
logical, dimension(:), intent(in), optional :: mask
integer, intent(out), optional :: n_index
integer, optional, intent(out) :: error
type(atoms) :: at_copy
integer :: i, j, k, n, m, shift_j(3)
INIT_ERROR(error)
if(.not. this%initialised) then
RAISE_ERROR("bond_real_space_sizes: descriptor object not initialised", error)
endif
n_descriptors = 0
n_cross = 0
do i = 1, at%N
n_descriptors = n_descriptors + n_neighbours(at, i, max_dist=this%bond_cutoff)
do n = 1, n_neighbours(at, i)
j = neighbour(at, i, n, shift=shift_j, max_dist=this%bond_cutoff)
if(j == 0) cycle
at_copy = at
call add_atoms(at_copy, 0.5_dp * (at%pos(:,i) + at%pos(:,j) + matmul(at%lattice,shift_j)), 1)
call calc_connect(at_copy)
do m = 1, n_neighbours(at_copy, at%N + 1)
k = neighbour(at_copy, at%N + 1, m, max_dist=this%cutoff)
if(k == 0) cycle
if(at_copy%pos(:,k) .feq. at_copy%pos(:,at%N + 1)) cycle
n_cross = n_cross + 1
enddo
call finalise(at_copy)
enddo
enddo
if( present(n_index) ) n_index = 2
endsubroutine bond_real_space_sizes
!!!!!!!!
!!! Work of Wojciech Szlachta ENDS here
!!!!!!!!
!!!!!!!!
!!! Work of Alan Nichol and S. T. John BEGINS here
!!!!!!!!
subroutine descriptor_general_monomer_nmer_MPI_setup(this,at,mpi,mpi_mask,error)
type(descriptor), intent(in) :: this
type(atoms), intent(in) :: at
type(MPI_Context), intent(in) :: mpi
logical, dimension(:), intent(out) :: mpi_mask
integer, optional, intent(out) :: error
integer, dimension(:,:), allocatable :: monomer_index
logical, dimension(at%N) :: associated_to_monomer
integer :: n_monomer
integer :: i
INIT_ERROR(error)
associated_to_monomer = .false.
select case(this%descriptor_type)
case(DT_GENERAL_MONOMER)
call find_general_monomer(at, monomer_index, &
this%descriptor_general_monomer%signature, associated_to_monomer, &
this%descriptor_general_monomer%cutoff, &
this%descriptor_general_monomer%atom_ordercheck, error)
case(DT_GENERAL_DIMER)
call find_general_monomer(at, monomer_index, &
this%descriptor_general_dimer%signature_one, associated_to_monomer, &
this%descriptor_general_dimer%monomer_one_cutoff, &
this%descriptor_general_dimer%atom_ordercheck, error)
case(DT_GENERAL_TRIMER)
call find_general_monomer(at, monomer_index, &
this%descriptor_general_trimer%signature_one, associated_to_monomer, &
this%descriptor_general_trimer%monomer_one_cutoff,&
this%descriptor_general_trimer%atom_ordercheck,error)
case(DT_COM_DIMER)
call find_general_monomer(at, monomer_index, &
this%descriptor_com_dimer%signature_one, associated_to_monomer,&
this%descriptor_com_dimer%monomer_one_cutoff,&
this%descriptor_com_dimer%atom_ordercheck,error)
case default
RAISE_ERROR("descriptor_general_monomer_nmer_MPI_setup: descriptor type "//this%descriptor_type//" not recognised.",error)
endselect
n_monomer = size(monomer_index,2)
mpi_mask = .false.
do i = 1, n_monomer ! for dimer, trimer this is the first monomer (signature_one)
if( mod(i-1, mpi%n_procs) == mpi%my_proc ) then
mpi_mask(monomer_index(:,i)) = .true.
endif
enddo
deallocate(monomer_index)
endsubroutine descriptor_general_monomer_nmer_MPI_setup
subroutine AN_monomer_initialise(this,args_str,error)
type(AN_monomer), intent(inout) :: this
character(len=*), intent(in) :: args_str
integer, optional, intent(out) :: error
type(Dictionary) :: params
INIT_ERROR(error)
call finalise(this)
call initialise(params)
call param_register(params, 'cutoff', '0.00', this%cutoff, help_string="Cutoff for AN_monomer-type descriptors")
call param_register(params, 'atomic_number', '1', this%atomic_number, help_string="Atomic number in AN_monomer-type descriptors")
call param_register(params, 'N', '4', this%N, help_string="Number of atoms in cluster")
call param_register(params, 'do_atomic', 'T', this%do_atomic, help_string="Descriptors are cluster based or atom-based")
if (.not. param_read_line(params, args_str, ignore_unknown=.true.,task='AN_monomer_initialise args_str')) then
RAISE_ERROR("AN_monomer_initialise failed to parse args_str='"//trim(args_str)//"'", error)
endif
call finalise(params)
this%initialised = .true.
endsubroutine AN_monomer_initialise
subroutine AN_monomer_finalise(this,error)
type(AN_monomer), intent(inout) :: this
integer, optional, intent(out) :: error
INIT_ERROR(error)
if(.not. this%initialised) return
this%cutoff = 0.0_dp
this%atomic_number = 0
this%N = 0
this%do_atomic = .false.
this%initialised = .false.
endsubroutine AN_monomer_finalise
subroutine general_monomer_initialise(this,args_str,error)
type(general_monomer), intent(inout) :: this
character(len=*), intent(in) :: args_str
character(len=STRING_LENGTH) :: signature_string
character(len=STRING_LENGTH_SHORT), dimension(99) :: signature_fields
integer, optional, intent(out) :: error
integer :: i,n_atoms,j
type(Dictionary) :: params
INIT_ERROR(error)
call finalise(this)
call initialise(params)
call param_register(params, 'cutoff', '0.00', this%cutoff, help_string="Cutoff for general_monomer-type descriptors")
call param_register(params, 'signature', PARAM_MANDATORY, signature_string, help_string="Atomic numbers of monomer one, format {Z1 Z2 Z3 ...}")
call param_register(params, 'atom_ordercheck', 'true', this%atom_ordercheck, help_string="T: find molecules. F: go by order of atoms")
call param_register(params, 'strict', 'true', this%strict, help_string="Raise error if not all atoms assigned to monomer")
call param_register(params, 'power', '1.0', this%power, help_string="Power of distances to be used in the kernel")
if (.not. param_read_line(params, args_str, ignore_unknown=.true.,task='general_monomer_initialise args_str')) then
RAISE_ERROR("general_monomer_initialise failed to parse args_str='"//trim(args_str)//"'", error)
endif
call finalise(params)
call split_string(signature_string,' ','{}',signature_fields(:),n_atoms,matching=.true.)
allocate(this%signature(n_atoms))
do i=1,n_atoms
this%signature(i) = string_to_int(signature_fields(i))
end do
call permutation_data_initialise(this%permutation_data,signature_one=this%signature,error=error)
this%initialised = .true.
endsubroutine general_monomer_initialise
subroutine general_monomer_finalise(this,error)
type(general_monomer), intent(inout) :: this
integer, optional, intent(out) :: error
INIT_ERROR(error)
if(.not. this%initialised) return
this%cutoff = 0.0_dp
this%power = 1.0_dp
if(allocated(this%signature)) deallocate(this%signature)
this%initialised = .false.
endsubroutine general_monomer_finalise
subroutine com_dimer_initialise(this,args_str,error)
type(com_dimer), intent(inout) :: this
character(len=*), intent(in) :: args_str
character(len=STRING_LENGTH) :: signature_one_string, signature_two_string
character(len=STRING_LENGTH_SHORT), dimension(99) :: signature_one_fields, signature_two_fields
integer, optional, intent(out) :: error
integer :: i, n_atoms_one, n_atoms_two
type(Dictionary) :: params
INIT_ERROR(error)
call finalise(this)
call initialise(params)
call param_register(params, 'cutoff', '0.00', this%cutoff, help_string="Cutoff(intermolecular) for com_dimer-type descriptors")
call param_register(params, 'monomer_one_cutoff', '0.00', this%monomer_one_cutoff, help_string="Cutoff(mono1) for com_dimer-type descriptors")
call param_register(params, 'monomer_two_cutoff', '0.00', this%monomer_two_cutoff, help_string="Cutoff(mono2) for com_dimer-type descriptors")
call param_register(params, 'cutoff_transition_width', '0.50', this%cutoff_transition_width, help_string="Width of smooth cutoff region for com_dimer-type descriptors")
call param_register(params, 'atom_ordercheck', 'true', this%atom_ordercheck, help_string="T: find molecules. F: go by order of atoms")
call param_register(params, 'strict', 'true', this%strict, help_string="Raise error if not all atoms assigned to monomer or if no monomer pairs found")
call param_register(params, 'mpifind', 'false', this%mpifind, help_string="Use find_monomer_pairs_MPI")
call param_register(params, 'signature_one', PARAM_MANDATORY, signature_one_string, help_string="Atomic numbers of monomer one, format {Z1 Z2 Z3 ...}")
call param_register(params, 'signature_two', PARAM_MANDATORY, signature_two_string, help_string="Atomic numbers of monomer two, format {Z1 Z2 Z3 ...}")
if (.not. param_read_line(params, args_str, ignore_unknown=.true.,task='com_dimer_initialise args_str')) then
RAISE_ERROR("com_dimer_initialise failed to parse args_str='"//trim(args_str)//"'", error)
endif
call finalise(params)
call initialise(this%transfer_parameters, args_str, error)
call split_string(signature_one_string,' ','{}',signature_one_fields(:),n_atoms_one,matching=.true.)
call split_string(signature_two_string,' ','{}',signature_two_fields(:),n_atoms_two,matching=.true.)
allocate(this%signature_one(n_atoms_one))
allocate(this%signature_two(n_atoms_two))
do i=1,n_atoms_one
this%signature_one(i) = string_to_int(signature_one_fields(i))
end do
do i=1,n_atoms_two
this%signature_two(i) = string_to_int(signature_two_fields(i))
end do
this%monomers_identical=.False.
if (size(this%signature_one) == size(this%signature_two)) then
if (all(this%signature_one == this%signature_two)) then
this%monomers_identical = .True.
end if
end if
this%initialised = .true.
endsubroutine com_dimer_initialise
subroutine com_dimer_finalise(this,error)
type(com_dimer), intent(inout) :: this
integer, optional, intent(out) :: error
INIT_ERROR(error)
if(.not. this%initialised) return
this%cutoff = 0.0_dp
this%cutoff_transition_width = 0.0_dp
this%monomer_one_cutoff = 0.0_dp
this%monomer_two_cutoff = 0.0_dp
this%atom_ordercheck = .true.
this%use_smooth_cutoff = .false.
if(allocated(this%signature_one)) deallocate(this%signature_one)
if(allocated(this%signature_two)) deallocate(this%signature_two)
this%initialised = .false.
endsubroutine com_dimer_finalise
subroutine general_dimer_initialise(this,args_str,error)
type(general_dimer), intent(inout) :: this
character(len=*), intent(in) :: args_str
character(len=STRING_LENGTH) :: signature_one_string, signature_two_string
character(len=STRING_LENGTH_SHORT), dimension(99) :: signature_one_fields, signature_two_fields
integer, optional, intent(out) :: error
integer :: i,j, n_atoms_one, n_atoms_two, dimer_size, start, finish, d
logical, dimension(:,:), allocatable :: intermolecular
integer, dimension(:), allocatable :: signature
type(Dictionary) :: params
INIT_ERROR(error)
call finalise(this)
call initialise(params)
call param_register(params, 'cutoff', '0.00', this%cutoff, &
help_string="Cutoff(intermolecular) for general_dimer-type descriptors")
call param_register(params, 'monomer_one_cutoff', '0.00', this%monomer_one_cutoff, &
help_string="Cutoff(mono1) for general_dimer-type descriptors")
call param_register(params, 'monomer_two_cutoff', '0.00', this%monomer_two_cutoff, &
help_string="Cutoff(mono2) for general_dimer-type descriptors")
call param_register(params, 'cutoff_transition_width', '0.50', this%cutoff_transition_width, &
help_string="Width of smooth cutoff region for general_dimer-type descriptors")
call param_register(params, 'internal_swaps_only', 'true', this%internal_swaps_only, &
help_string="F: energies will be symmetrised over swaps of nuclei between monomers")
call param_register(params, 'atom_ordercheck', 'true', this%atom_ordercheck, &
help_string="T: find molecules. F: go by order of atoms")
call param_register(params, 'double_count', 'false', this%double_count, &
help_string="T: double count when constructing the dimers, for compatibility with water dimer descriptor, default False")
call param_register(params, 'strict', 'true', this%strict, &
help_string="Raise error if not all atoms assigned to monomer or if no monomer pairs found")
call param_register(params, 'strict_mask', 'true', this%strict_mask, &
help_string="Raise error if atom mask includes only part of a monomer")
call param_register(params, 'use_com', 'false', this%use_com, &
help_string="Use COM instead of COG")
call param_register(params, 'mpifind', 'false', this%mpifind, &
help_string="Use find_monomer_pairs_MPI")
call param_register(params, 'signature_one', PARAM_MANDATORY, signature_one_string, &
help_string="Atomic numbers of monomer one, format {Z1 Z2 Z3 ...}")
call param_register(params, 'signature_two', PARAM_MANDATORY, signature_two_string, &
help_string="Atomic numbers of monomer two, format {Z1 Z2 Z3 ...}")
call param_register(params, 'power', '1.00', this%power, &
help_string="Power of interatomic distances to be used in the kernel.")
call param_register(params, 'dist_shift', '0.0', this%dist_shift, &
help_string="Distance shift for inverse distance descriptors.")
if (.not. param_read_line(params, args_str, ignore_unknown=.true.,task='general_dimer_initialise args_str')) then
RAISE_ERROR("general_dimer_initialise failed to parse args_str='"//trim(args_str)//"'", error)
endif
call finalise(params)
call initialise(this%transfer_parameters, args_str, error)
call split_string(signature_one_string,' ','{}',signature_one_fields(:),n_atoms_one,matching=.true.)
call split_string(signature_two_string,' ','{}',signature_two_fields(:),n_atoms_two,matching=.true.)
allocate(this%signature_one(n_atoms_one))
allocate(this%signature_two(n_atoms_two))
do i=1,n_atoms_one
this%signature_one(i) = string_to_int(signature_one_fields(i))
end do
do i=1,n_atoms_two
this%signature_two(i) = string_to_int(signature_two_fields(i))
end do
this%monomers_identical=.False.
if (size(this%signature_one) == size(this%signature_two)) then
if (all(this%signature_one == this%signature_two)) then
this%monomers_identical = .True.
end if
end if
call permutation_data_initialise(this%permutation_data,signature_one=this%signature_one,signature_two=this%signature_two,internal_swaps_only=this%internal_swaps_only,error=error)
dimer_size=n_atoms_one + n_atoms_two
d=dimer_size*(dimer_size-1)/2
allocate(signature(dimer_size))
allocate(intermolecular(dimer_size,dimer_size))
allocate(this%is_intermolecular(d))
allocate(this%cutoff_contributor(d))
allocate(this%component_atoms(d,2))
signature(1:n_atoms_one) = this%signature_one
signature(1+n_atoms_one:dimer_size) = this%signature_two
intermolecular = .false.
this%cutoff_contributor=.false.
do i=1,n_atoms_one
do j=1+n_atoms_one,dimer_size
intermolecular(i,j)=.true.
end do
end do
start = 0
finish=dimer_size-1
do i=1,dimer_size
do j=1,finish-start
this%is_intermolecular(start+j) = intermolecular(i,i+j)
this%component_atoms(start+j,:) = (/ i, i+j /)
end do
start = finish
finish=finish + dimer_size-i-1
end do
do i=1,d
if (this%is_intermolecular(i)) then
if (.not. signature(this%component_atoms(i,1))==1 ) then
if (.not. signature(this%component_atoms(i,2))==1 ) then
this%cutoff_contributor(i)=.true.
end if
end if
end if
end do
this%initialised = .true.
deallocate(signature)
deallocate(intermolecular)
endsubroutine general_dimer_initialise
subroutine general_dimer_finalise(this,error)
type(general_dimer), intent(inout) :: this
integer, optional, intent(out) :: error
INIT_ERROR(error)
if(.not. this%initialised) return
this%cutoff = 0.0_dp
this%cutoff_transition_width = 0.0_dp
this%monomer_one_cutoff = 0.0_dp
this%monomer_two_cutoff = 0.0_dp
this%atom_ordercheck = .true.
this%internal_swaps_only = .true.
this%use_smooth_cutoff = .false.
this%power = 1.0_dp
this%dist_shift = 0.0_dp
if(allocated(this%signature_one)) deallocate(this%signature_one)
if(allocated(this%signature_two)) deallocate(this%signature_two)
if(allocated(this%is_intermolecular)) deallocate(this%is_intermolecular)
if(allocated(this%component_atoms)) deallocate(this%component_atoms)
if(allocated(this%cutoff_contributor)) deallocate(this%cutoff_contributor)
this%initialised = .false.
endsubroutine general_dimer_finalise
subroutine general_trimer_initialise(this,args_str,error)
type(general_trimer), intent(inout) :: this
character(len=*), intent(in) :: args_str
character(len=STRING_LENGTH) :: signature_one_string, signature_two_string, signature_three_string
character(len=STRING_LENGTH_SHORT), dimension(99) :: signature_one_fields, signature_two_fields, signature_three_fields
integer, optional, intent(out) :: error
integer :: i,j, n_atoms_one, n_atoms_two, n_atoms_three, trimer_size, start, finish,d
logical, dimension(:,:), allocatable :: intermolecular
integer, dimension(:), allocatable :: signature
type(Dictionary) :: params
INIT_ERROR(error)
call finalise(this)
call initialise(params)
call param_register(params, 'cutoff', '0.00', this%cutoff, &
help_string="Cutoff(intermolecular) for general_trimer-type descriptors")
call param_register(params, 'monomer_one_cutoff', '0.00', this%monomer_one_cutoff, &
help_string="Cutoff(mono1) for general_trimer-type descriptors")
call param_register(params, 'monomer_two_cutoff', '0.00', this%monomer_two_cutoff, &
help_string="Cutoff(mono2) for general_trimer-type descriptors")
call param_register(params, 'monomer_three_cutoff', '0.00', this%monomer_three_cutoff, &
help_string="Cutoff(mono3) for general_trimer-type descriptors")
call param_register(params, 'cutoff_transition_width', '0.50', this%cutoff_transition_width, &
help_string="Width of smooth cutoff region for general_trimer-type descriptors")
call param_register(params, 'internal_swaps_only', 'true', this%internal_swaps_only, &
help_string="F: energies will be symmetrised over swaps of nuclei between monomers")
call param_register(params, 'atom_ordercheck', 'true', this%atom_ordercheck, &
help_string="T: find molecules. F: go by order of atoms")
call param_register(params, 'strict', 'true', this%strict, &
help_string="Raise error if not all atoms assigned to monomer or if no monomer pairs found")
call param_register(params, 'use_com', 'false', this%use_com, &
help_string="Use COM instead of COG")
call param_register(params, 'mpifind', 'false', this%mpifind, &
help_string="Use find_monomer_triplets_MPI")
call param_register(params, 'signature_one', PARAM_MANDATORY, signature_one_string, &
help_string="Atomic numbers of monomer one, format {Z1 Z2 Z3 ...}")
call param_register(params, 'signature_two', PARAM_MANDATORY, signature_two_string, &
help_string="Atomic numbers of monomer two, format {Z1 Z2 Z3 ...}")
call param_register(params, 'signature_three', PARAM_MANDATORY, signature_three_string, &
help_string="Atomic numbers of monomer three, format {Z1 Z2 Z3 ...}")
call param_register(params, 'power', '1.0', this%power, &
help_string="Power of distances to be used in the kernel")
call param_register(params, 'dist_shift', '0.0', this%dist_shift, &
help_string="Distance shift for inverse distance descriptors.")
if (.not. param_read_line(params, args_str, ignore_unknown=.true.,task='general_trimer_initialise args_str')) then