/
autocorrelation.py
1936 lines (1745 loc) · 85.3 KB
/
autocorrelation.py
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
import numpy as np
from molSimplify.Classes.mol3D import mol3D
from molSimplify.Classes.ligand import ligand_breakdown, ligand_assign
from molSimplify.Scripts.geometry import distance
from molSimplify.Classes.globalvars import globalvars
# ########## UNIT CONVERSION
HF_to_Kcal_mol = 627.503
def autocorrelation(mol, prop_vec, orig, d, oct=True, catoms=None, use_dist=False):
"""Calculate and return the products autocorrelation for a single atom
Parameters
----------
mol : mol3D
mol3D object to calculate autocorrelation over
prop_vec : list
property of atoms in mol in order of index
orig : int
zero-indexed starting atom
d : int
number of hops to travel
oct : bool, optional
Flag is octahedral complex, by default True
catoms: list, optional
List of connecting atoms, by default None (uses mol3D.getBondedAtomsSmart)
use_dist : bool, optional
Weigh autocorrelation by physical distance of atom from original, by default False
Returns
-------
result_vector : list
assembled products autocorrelations
"""
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
if not use_dist:
result_vector[hopped] = prop_vec[orig] * prop_vec[orig]
else:
result_vector[hopped] = 0.5 * abs(prop_vec[orig]) ** 2.4 / mol.natoms
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in AC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
if not use_dist:
result_vector[hopped] += prop_vec[orig] * prop_vec[inds]
else:
this_dist = distance(mol.getAtom(orig).coords(), mol.getAtom(inds).coords())
result_vector[hopped] += prop_vec[orig] * prop_vec[inds] / (this_dist * mol.natoms)
historical_set.update(active_set)
active_set = new_active_set
return (result_vector)
def autocorrelation_derivative(mol, prop_vec, orig, d, oct=True, catoms=None):
"""Returns derivative vector of products autocorrelations
Parameters
----------
mol : mol3D
mol3D object to calculate derivatives over
prop_vec : list
property of atoms in mol in order of index
orig : int
zero-indexed starting atom
d : int
number of hops to travel
oct : bool, optional
Flag is octahedral complex, by default True
catoms : list, optional
List of connecting atom, by default None (use mol3D.getBondedAtomsSmart)
Returns
-------
derivative_mat : list
RAC derivatives matrix
"""
derivative_mat = np.zeros((d + 1, len(prop_vec)))
# loop for each atom
hopped = 0
active_set = set([orig])
historical_set = set()
for derivate_ind in range(0, len(prop_vec)):
if derivate_ind == orig:
derivative_mat[hopped, derivate_ind] = 2 * prop_vec[orig]
else:
derivative_mat[hopped, derivate_ind] = 0
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in AC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
for derivate_ind in range(0, len(prop_vec)):
if derivate_ind == orig:
derivative_mat[hopped, derivate_ind] += prop_vec[inds]
elif derivate_ind == inds:
derivative_mat[hopped, derivate_ind] += prop_vec[orig]
historical_set.update(active_set)
active_set = new_active_set
return (derivative_mat)
def ratiometric(mol, prop_vec_num, prop_vec_den, orig, d, oct=True, catoms=None):
"""This function returns the ratiometrics for one atom
Parameters
----------
mol : mol3D class
prop_vec : vector, property of atoms in mol in order of index
orig : int, zero-indexed starting atom
d : int, number of hops to travel
oct : bool, if complex is octahedral, will use better bond checks
Returns
-------
result_vector : vector of prop_vec_num / prop_vec_den
"""
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
result_vector[hopped] = prop_vec_num[orig] / prop_vec_den[orig]
"""
if oct:
print('using OCT autocorrelation')
else:
print('NOT using OCT autocorrelation')
"""
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in AC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
result_vector[hopped] += prop_vec_num[orig] / prop_vec_den[inds]
historical_set.update(active_set)
active_set = new_active_set
return (result_vector)
def summetric(mol, prop_vec, orig, d, oct=True, catoms=None):
"""This function returns the summetrics for one atom
Parameters
----------
mol : mol3D class
prop_vec : vector, property of atoms in mol in order of index
orig : int, zero-indexed starting atom
d : int, number of hops to travel
oct : bool, if complex is octahedral, will use better bond checks
Returns
-------
result_vector : vector of prop_vec_num / prop_vec_den
"""
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
result_vector[hopped] = prop_vec[orig] + prop_vec[orig]
"""
if oct:
print('using OCT autocorrelation')
else:
print('NOT using OCT autocorrelation')
"""
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in AC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
result_vector[hopped] += prop_vec[orig] + prop_vec[inds]
historical_set.update(active_set)
active_set = new_active_set
return (result_vector)
def deltametric(mol: mol3D, prop_vec, orig, d: int, oct=True, catoms=None):
# # this function returns the deltametric
# # over the whole molecule
# Inputs:
# mol - mol3D class
# prop_vec - vector, property of atoms in mol in order of index
# orig - int, zero-indexed starting atom
# d - int, number of hops to travel
# oct - bool, if complex is octahedral, will use better bond checks
# if oct:
# print('using OCT delta autocorrelation')
# else:
# print('NOT using OCT delta autocorrelation')
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
result_vector[hopped] = 0.00
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in DAC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
result_vector[hopped] += prop_vec[orig] - prop_vec[inds]
historical_set.update(active_set)
active_set = new_active_set
return (result_vector)
def autocorrelation_catoms(mol, prop_vec, orig, d, oct=True, catoms=None):
# Calculate the autocorrelation for the orig to certain connecting atoms.
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
result_vector[hopped] = prop_vec[orig] * prop_vec[orig]
# if oct:
# print('using OCT autocorrelation')
# else:
# print('NOT using OCT autocorrelation')
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in AC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
# print('--1--:', this_atoms_neighbors)
if this_atom == orig and (catoms is not None):
this_atoms_neighbors = catoms
# print('--2--:', this_atoms_neighbors)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
result_vector[hopped] += prop_vec[orig] * prop_vec[inds]
historical_set.update(active_set)
active_set = new_active_set
return (result_vector)
def deltametric_derivative(mol, prop_vec, orig, d, oct=True, catoms=None):
# # this function returns the derivative vector
# # of the scalar autocorrelation
# # starting at orig with depth d,
# # with respect to the atomic properties
# # in prop_vec, for all atoms.
# # The return type is np.array for
# # Be sure to read this carefully!
# Inputs:
# mol - mol3D class
# prop_vec - vector, property of atoms in mol in order of index
# orig - int, zero-indexed starting atom
# d - int, number of hops to travel
# oct - bool, if complex is octahedral, will use better bond checks
# if oct:
# print('using OCT delta autocorrelation')
# else:
# print('NOT using OCT delta autocorrelation')
derivative_mat = np.zeros((d + 1, len(prop_vec)))
hopped = 0
active_set = set([orig])
historical_set = set()
# the zero-depth element is always zero
for derivate_ind in range(0, len(prop_vec)):
derivative_mat[hopped, derivate_ind] = 0.0
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in DAC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
for derivate_ind in range(0, len(prop_vec)):
if derivate_ind == orig:
derivative_mat[hopped, derivate_ind] += 1
elif derivate_ind == inds:
derivative_mat[hopped, derivate_ind] += -1
historical_set.update(active_set)
active_set = new_active_set
return (derivative_mat)
def deltametric_catoms(mol, prop_vec, orig, d, oct=True, catoms=None):
# Calculate the deltametrics for the orig to certain connecting atoms.
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
result_vector[hopped] = 0.00
# metal_idx = get_metal_index(mol)
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in DAC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
# print('--1--:', this_atoms_neighbors)
if this_atom == orig and (catoms is not None):
this_atoms_neighbors = catoms
# print('--2--:', this_atoms_neighbors)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
result_vector[hopped] += prop_vec[orig] - prop_vec[inds]
historical_set.update(active_set)
active_set = new_active_set
return (result_vector)
def full_autocorrelation(mol, prop, d, oct=oct, modifier=False, use_dist=False, transition_metals_only=True):
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier, transition_metals_only=transition_metals_only)
index_set = list(range(0, mol.natoms))
autocorrelation_vector = np.zeros(d + 1)
for centers in index_set:
autocorrelation_vector += autocorrelation(mol, w, centers, d, oct=oct, use_dist=use_dist)
return (autocorrelation_vector)
def full_autocorrelation_derivative(mol, prop, d, oct=oct, modifier=False):
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
index_set = list(range(0, mol.natoms))
autocorrelation_derivative_mat = np.zeros((d + 1, mol.natoms))
for centers in index_set:
autocorrelation_derivative_mat += autocorrelation_derivative(mol, w, centers, d, oct=oct)
return (autocorrelation_derivative_mat)
def atom_only_autocorrelation(mol, prop, d, atomIdx, oct=True):
# atomIdx must be either a list of indicies
# or a single index
w = construct_property_vector(mol, prop, oct)
autocorrelation_vector = np.zeros(d + 1)
if hasattr(atomIdx, "__len__"): # Indicative of a list of indices
for elements in atomIdx:
autocorrelation_vector += autocorrelation(mol, w, elements, d, oct=oct)
autocorrelation_vector = np.divide(autocorrelation_vector, len(atomIdx)) # averaging
else: # Single index
autocorrelation_vector += autocorrelation(mol, w, atomIdx, d, oct=oct)
return (autocorrelation_vector)
def atom_only_autocorrelation_derivative(mol, prop, d, atomIdx, oct=True):
# atomIdx must b either a list of indicies
# or a single index
w = construct_property_vector(mol, prop, oct)
autocorrelation_derivative_mat = np.zeros((d + 1, mol.natoms))
if hasattr(atomIdx, "__len__"):
for elements in atomIdx:
autocorrelation_derivative_mat += autocorrelation_derivative(mol, w, elements, d, oct=oct)
autocorrelation_derivative_mat = np.divide(autocorrelation_derivative_mat, len(atomIdx))
else:
autocorrelation_derivative_mat += autocorrelation_derivative(mol, w, atomIdx, d, oct=oct)
return (autocorrelation_derivative_mat)
def metal_only_autocorrelation(mol, prop, d, oct=True, catoms=None,
func=autocorrelation, modifier=False):
try:
metal_ind = get_metal_index(mol)
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
autocorrelation_vector = func(mol, w, metal_ind, d, oct=oct,
catoms=catoms)
except IndexError:
print('Error, no metal found in mol object!')
return False
return (autocorrelation_vector)
def metal_only_autocorrelation_derivative(mol, prop, d, oct=True, catoms=None,
func=autocorrelation_derivative, modifier=False):
try:
metal_ind = get_metal_index(mol)
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
autocorrelation_vector_derivative = func(mol, w, metal_ind, d, oct=oct,
catoms=catoms)
except IndexError:
print('Error, no metal found in mol object!')
return False
return (autocorrelation_vector_derivative)
def multimetal_only_autocorrelation(mol, prop, d, oct=True, catoms=None,
func=autocorrelation, modifier=False):
autocorrelation_vector = np.zeros(d + 1)
n_met = len(mol.findMetal())
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
for metal_ind in mol.findMetal():
autocorrelation_vector += func(mol, w, metal_ind, d, oct=oct, catoms=catoms)
autocorrelation_vector = np.divide(autocorrelation_vector, n_met)
return (autocorrelation_vector)
def multiatom_only_autocorrelation(mol, prop, d, oct=True, catoms=None,
func=autocorrelation, modifier=False,
additional_elements=False):
autocorrelation_vector = np.zeros(d + 1)
metal_list = mol.findMetal()
if additional_elements:
for element in additional_elements:
metal_list += mol.findAtomsbySymbol(element)
n_met = len(metal_list)
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
for metal_ind in metal_list:
autocorrelation_vector += func(mol, w, metal_ind, d, oct=oct, catoms=catoms)
autocorrelation_vector = np.divide(autocorrelation_vector, n_met)
return (autocorrelation_vector)
def atom_only_ratiometric(mol, prop_num, prop_den, d, atomIdx, oct=True):
# atomIdx must b either a list of indicies
# or a single index
w_num = construct_property_vector(mol, prop_num, oct)
w_den = construct_property_vector(mol, prop_den, oct)
autocorrelation_vector = np.zeros(d + 1)
if hasattr(atomIdx, "__len__"):
for elements in atomIdx:
autocorrelation_vector += ratiometric(mol, w_num, w_den, elements, d, oct=oct)
autocorrelation_vector = np.divide(autocorrelation_vector, len(atomIdx))
else:
autocorrelation_vector += ratiometric(mol, w_num, w_den, atomIdx, d, oct=oct)
return (autocorrelation_vector)
def atom_only_summetric(mol, prop, d, atomIdx, oct=True):
# atomIdx must b either a list of indicies
# or a single index
w = construct_property_vector(mol, prop, oct)
autocorrelation_vector = np.zeros(d + 1)
if hasattr(atomIdx, "__len__"):
for elements in atomIdx:
autocorrelation_vector += summetric(mol, w, elements, d, oct=oct)
autocorrelation_vector = np.divide(autocorrelation_vector, len(atomIdx))
else:
autocorrelation_vector += summetric(mol, w, atomIdx, d, oct=oct)
return (autocorrelation_vector)
def atom_only_deltametric(mol, prop, d, atomIdx, oct=True, modifier=False):
# atomIdx must b either a list of indicies
# or a single index
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
deltametric_vector = np.zeros(d + 1)
if hasattr(atomIdx, "__len__"):
for elements in atomIdx:
deltametric_vector += deltametric(mol, w, elements, d, oct=oct)
deltametric_vector = np.divide(deltametric_vector, len(atomIdx))
else:
deltametric_vector += deltametric(mol, w, atomIdx, d, oct=oct)
return (deltametric_vector)
def atom_only_deltametric_derivative(mol, prop, d, atomIdx, oct=True, modifier=False):
# atomIdx must b either a list of indicies
# or a single index
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
deltametric_derivative_mat = np.zeros((d + 1, mol.natoms))
if hasattr(atomIdx, "__len__"):
for elements in atomIdx:
deltametric_derivative_mat += deltametric_derivative(mol, w, elements, d, oct=oct)
deltametric_derivative_mat = np.divide(deltametric_derivative_mat, len(atomIdx))
else:
deltametric_derivative_mat += deltametric_derivative(mol, w, atomIdx, d, oct=oct)
return (deltametric_derivative_mat)
def metal_only_deltametric_derivative(mol, prop, d, oct=True, catoms=None,
func=deltametric_derivative, modifier=False):
try:
metal_ind = get_metal_index(mol)
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
deltametric_vector_derivative = func(mol, w, metal_ind, d, oct=oct,
catoms=catoms)
except IndexError:
print('Error, no metal found in mol object!')
return False
return (deltametric_vector_derivative)
def metal_only_deltametric(mol, prop, d, oct=True, catoms=None,
func=deltametric, modifier=False):
try:
metal_ind = get_metal_index(mol)
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
deltametric_vector = func(mol, w, metal_ind, d, oct=oct,
catoms=catoms)
except IndexError:
print('Error, no metal found in mol object!')
return False
return (deltametric_vector)
def multimetal_only_deltametric(mol, prop, d, oct=True, catoms=None,
func=deltametric, modifier=False):
deltametric_vector = np.zeros(d + 1)
n_met = len(mol.findMetal())
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
for metal_ind in mol.findMetal():
deltametric_vector += func(mol, w, metal_ind, d, oct=oct,
catoms=catoms)
deltametric_vector = np.divide(deltametric_vector, n_met)
return (deltametric_vector)
def multiatom_only_deltametric(mol, prop, d, oct=True, catoms=None,
func=deltametric, modifier=False,
additional_elements=False):
deltametric_vector = np.zeros(d + 1)
metal_list = mol.findMetal()
if additional_elements:
for element in additional_elements:
metal_list += mol.findAtomsbySymbol(element)
n_met = len(metal_list)
w = construct_property_vector(mol, prop, oct=oct, modifier=modifier)
for metal_ind in mol.findMetal():
deltametric_vector += func(mol, w, metal_ind, d, oct=oct,
catoms=catoms)
deltametric_vector = np.divide(deltametric_vector, n_met)
return (deltametric_vector)
def metal_only_layer_density(mol, prop, d, oct=True):
try:
metal_ind = get_metal_index(mol)
print(('metal_index is: %d' % metal_ind))
w = construct_property_vector(mol, prop, oct=oct)
density_vector = layer_density_in_3D(mol, w, metal_ind, d, oct=oct)
except IndexError:
print('Error, no metal found in mol object!')
return False
return density_vector
def layer_density_in_3D(mol, prop_vec, orig, d, oct=True):
# # this function returns the density (prop^3/(d+1)^3)
# # for one atom
# Inputs:
# mol - mol3D class
# prop_vec - vector, property of atoms in mol in order of index
# orig - int, zero-indexed starting atom
# d - int, number of hops to travel
# oct - bool, if complex is octahedral, will use better bond checks
result_vector = np.zeros(d + 1)
hopped = 0
active_set = set([orig])
historical_set = set()
result_vector[hopped] = prop_vec[orig] ** 3 / (hopped + 1) ** 3
# if oct:
# print('using OCT autocorrelation')
# else:
# print('NOT using OCT autocorrelation')
while hopped < (d):
hopped += 1
new_active_set = set()
for this_atom in active_set:
# prepare all atoms attached to this connection
# print('called in AC')
this_atoms_neighbors = mol.getBondedAtomsSmart(this_atom, oct=oct)
for bound_atoms in this_atoms_neighbors:
if (bound_atoms not in historical_set) and (bound_atoms not in active_set):
new_active_set.add(bound_atoms)
# print('new active set at hop = ' +str(hopped) + ' is ' +str(new_active_set))
for inds in new_active_set:
result_vector[hopped] += prop_vec[inds] ** 3 / (hopped + 1) ** 3
historical_set.update(active_set)
active_set = new_active_set
return result_vector
def construct_property_vector(mol: mol3D, prop: str, oct=True, modifier=False, transition_metals_only=True):
# # assigns the value of property
# # for atom i (zero index) in mol
# # to position i in returned vector
# # can be used to create weighted
# # graph representations
# # oct - bool, if complex is octahedral, will use better bond checks
# # modifier - dict, used to modify prop vector (e.g. for adding
# # ONLY used with ox_nuclear_charge ox or charge)
# # {"Fe":2, "Co": 3} etc
allowed_strings = ['electronegativity', 'nuclear_charge', 'ident', 'topology',
'ox_nuclear_charge', 'size', 'vdwrad', 'group_number', 'polarizability',
'bondvalence', 'num_bonds', 'bondvalence_devi', 'bodavrg', 'bodstd', 'charge']
# # note that ident just codes every atom as one, this gives
# # a purely toplogical index. coord gives the number of
# # connecting atom to attom i (similar to Randic index)
# if not oct:
# print('NOT using octahedral bonding pattern')
globs = globalvars()
prop_dict = dict()
w = np.zeros(mol.natoms)
done = False
if prop not in allowed_strings:
print(('error, property ' + str(prop) + ' is not a vaild choice'))
print((' options are ' + str(allowed_strings)))
return False
if prop == 'electronegativity':
prop_dict = globs.endict()
elif prop == 'size':
at_keys = list(globs.amass().keys())
for keys in at_keys:
values = globs.amass()[keys][2]
prop_dict.update({keys: values})
elif prop == 'nuclear_charge':
at_keys = list(globs.amass().keys())
for keys in at_keys:
values = globs.amass()[keys][1]
prop_dict.update({keys: values})
elif prop == 'group_number': # Uses number of valence electrons
# if not modifier:
at_keys = list(globs.amass().keys())
for keys in at_keys:
values = globs.amass()[keys][-1]
prop_dict.update({keys: values})
# ###### 11/06/2019 -- Adjusted Gval RACs to not adjust on oxidation state. Confounded with O RACs. #####
# # else:
# at_keys = globs.amass().keys()
# for keys in at_keys:
# values = globs.amass()[keys][3]
# if keys in modifier.keys():
# values -= float(modifier[keys]) # assumes oxidation state provided (i.e. Fe(IV))
# prop_dict.update({keys: values})
elif prop == 'ox_nuclear_charge':
if not modifier:
print('Error, must give modifier with ox_nuclear_charge')
return False
else:
at_keys = list(globs.amass().keys())
for keys in at_keys:
values = globs.amass()[keys][1]
if keys in list(modifier.keys()):
values -= float(modifier[keys]) # assumes oxidation state provided (i.e. Fe(IV))
prop_dict.update({keys: values})
elif prop == 'polarizability':
prop_dict = globs.polarizability()
for i, atoms in enumerate(mol.getAtoms()):
atom_type = atoms.symbol()
w[i] = prop_dict[atom_type]
elif prop == 'ident':
at_keys = list(globs.amass().keys())
for keys in at_keys:
prop_dict.update({keys: 1})
elif prop == 'topology':
for i, atoms in enumerate(mol.getAtoms()):
# print('atom # ' + str(i) + " symbol = " + str(atoms.symbol()))
w[i] = len(mol.getBondedAtomsSmart(i, oct=oct))
done = True
elif prop == 'vdwrad':
prop_dict = globs.vdwrad()
for i, atoms in enumerate(mol.getAtoms()):
atom_type = atoms.symbol()
if atom_type in globs.metalslist():
w[i] = globs.amass()[atoms.symbol()][2]
else:
w[i] = prop_dict[atoms.symbol()]
done = True
# for keys in at_keys:
# prop_dict.update({keys: 1})
elif prop == 'bondvalence':
assert len(mol.getAtoms()) == len(mol.bv_dict)
for i, atoms in enumerate(mol.getAtoms()):
w[i] = mol.bv_dict[i]
done = True
elif prop == 'num_bonds':
for i, atom in enumerate(mol.getAtoms()):
if not atom.ismetal(transition_metals_only):
w[i] = globs.bondsdict()[atom.symbol()]
else:
w[i] = len(mol.getBondedAtomsSmart(i, oct=oct))
done = True
elif prop == 'bondvalence_devi':
assert len(mol.getAtoms()) == len(mol.bvd_dict)
for i, atoms in enumerate(mol.getAtoms()):
w[i] = mol.bvd_dict[i]
done = True
elif prop == 'bodavrg':
assert len(mol.getAtoms()) == len(mol.bodavrg_dict)
for i, atoms in enumerate(mol.getAtoms()):
w[i] = mol.bodavrg_dict[i]
done = True
elif prop == 'bodstd':
assert len(mol.getAtoms()) == len(mol.bodstd_dict)
for i, atoms in enumerate(mol.getAtoms()):
w[i] = mol.bodstd_dict[i]
done = True
elif prop == 'charge':
assert len(mol.getAtoms()) == len(mol.charge_dict)
for i, atoms in enumerate(mol.getAtoms()):
w[i] = mol.charge_dict[i]
done = True
if not done:
for i, atoms in enumerate(mol.getAtoms()):
# print('atom # ' + str(i) + " symbol = " + str(atoms.symbol()))
w[i] = prop_dict[atoms.symbol()]
return (w)
def find_ligand_autocorrelations_oct(mol, prop, loud, depth, name=False,
oct=True, custom_ligand_dict=False):
# # this function takes a
# # symmetric (axial == axial,
# # equatorial == equatorial)
# # octahedral complex
# # and returns autocorrelations for
# # the axial an equatorial ligands
# # custom_ligand_dict allows the user to skip the breakdown
# # in cases where 3D geo is not correct/formed
# # custom_ligand_dict.keys() must be eq_ligands_list, ax_ligand_list
# # ax_con_int_list ,eq_con_int_list
# # with types: eq/ax_ligand_list list of mol3D
# # eq/ax_con_int_list list of list/tuple of int e.g, [[1,2] [1,2]]
if not custom_ligand_dict:
liglist, ligdents, ligcons = ligand_breakdown(mol, BondedOct=oct)
(ax_ligand_list, eq_ligand_list, ax_natoms_list,
eq_natoms_list, ax_con_int_list, eq_con_int_list,
ax_con_list, eq_con_list, built_ligand_list) = ligand_assign(
mol, liglist, ligdents, ligcons, loud, name=False)
else:
ax_ligand_list = custom_ligand_dict["ax_ligand_list"]
eq_ligand_list = custom_ligand_dict["eq_ligand_list"]
ax_con_int_list = custom_ligand_dict["ax_con_int_list"]
eq_con_int_list = custom_ligand_dict["eq_con_int_list"]
# count ligands
n_ax = len(ax_ligand_list)
n_eq = len(eq_ligand_list)
# get full ligand AC
ax_ligand_ac_full = []
eq_ligand_ac_full = []
for i in range(0, n_ax):
if not list(ax_ligand_ac_full):
ax_ligand_ac_full = full_autocorrelation(ax_ligand_list[i].mol, prop, depth)
else:
ax_ligand_ac_full += full_autocorrelation(ax_ligand_list[i].mol, prop, depth)
ax_ligand_ac_full = np.divide(ax_ligand_ac_full, n_ax)
for i in range(0, n_eq):
if not list(eq_ligand_ac_full):
eq_ligand_ac_full = full_autocorrelation(eq_ligand_list[i].mol, prop, depth)
else:
eq_ligand_ac_full += full_autocorrelation(eq_ligand_list[i].mol, prop, depth)
eq_ligand_ac_full = np.divide(eq_ligand_ac_full, n_eq)
# get partial ligand AC
ax_ligand_ac_con = []
eq_ligand_ac_con = []
for i in range(0, n_ax):
if not list(ax_ligand_ac_con):
ax_ligand_ac_con = atom_only_autocorrelation(ax_ligand_list[i].mol, prop, depth, ax_con_int_list[i])
else:
ax_ligand_ac_con += atom_only_autocorrelation(ax_ligand_list[i].mol, prop, depth, ax_con_int_list[i])
ax_ligand_ac_con = np.divide(ax_ligand_ac_con, n_ax)
for i in range(0, n_eq):
if not list(eq_ligand_ac_con):
eq_ligand_ac_con = atom_only_autocorrelation(eq_ligand_list[i].mol, prop, depth, eq_con_int_list[i])
else:
eq_ligand_ac_con += atom_only_autocorrelation(eq_ligand_list[i].mol, prop, depth, eq_con_int_list[i])
eq_ligand_ac_con = np.divide(eq_ligand_ac_con, n_eq)
# ax_ligand_ac_con = atom_only_autocorrelation(ax_ligand.mol,prop,depth,ax_con_int)
# eq_ligand_ac_con = atom_only_autocorrelation(eq_ligand.mol,prop,depth,eq_con_int)
return ax_ligand_ac_full, eq_ligand_ac_full, ax_ligand_ac_con, eq_ligand_ac_con
def find_ligand_autocorrelation_derivatives_oct(mol, prop, loud, depth, name=False,
oct=True, custom_ligand_dict=False):
# # this function takes a
# # symmetric (axial == axial,
# # equatorial == equatorial)
# # octahedral complex
# # and returns autocorrelations for
# # the axial an equatorial ligands
# # custom_ligand_dict allows the user to skip the breakdown
# # in cases where 3D geo is not correct/formed
# # custom_ligand_dict.keys() must be eq_ligands_list, ax_ligand_list
# # ax_con_int_list ,eq_con_int_list
# # with types: eq/ax_ligand_list list of mol3D
# # eq/ax_con_int_list list of list/tuple of int e.g, [[1,2] [1,2]]
if not custom_ligand_dict:
liglist, ligdents, ligcons = ligand_breakdown(mol, BondedOct=oct)
(ax_ligand_list, eq_ligand_list, ax_natoms_list, eq_natoms_list, ax_con_int_list,
eq_con_int_list, ax_con_list, eq_con_list, built_ligand_list) = ligand_assign(
mol, liglist, ligdents, ligcons, loud, name=False)
else:
ax_ligand_list = custom_ligand_dict["ax_ligand_list"]
eq_ligand_list = custom_ligand_dict["eq_ligand_list"]
ax_con_int_list = custom_ligand_dict["ax_con_int_list"]
eq_con_int_list = custom_ligand_dict["eq_con_int_list"]
# count ligands
n_ax = len(ax_ligand_list)
n_eq = len(eq_ligand_list)
# get full ligand AC
ax_ligand_ac_full_derivative = None
eq_ligand_eq_full_derivative = None
# allocate the full jacobian matrix
ax_full_j = np.zeros([depth + 1, mol.natoms])
eq_full_j = np.zeros([depth + 1, mol.natoms])
ax_con_j = np.zeros([depth + 1, mol.natoms])
eq_con_j = np.zeros([depth + 1, mol.natoms])
# full ligand ACs
for i in range(0, n_ax): # for each ax ligand
ax_ligand_ac_full_derivative = full_autocorrelation_derivative(ax_ligand_list[i].mol, prop, depth)
# now we need to map back to full positions
for ii, row in enumerate(ax_ligand_ac_full_derivative):
for original_ids in list(ax_ligand_list[i].ext_int_dict.keys()):
ax_full_j[ii, original_ids] += np.divide(row[ax_ligand_list[i].ext_int_dict[original_ids]], n_ax)
for i in range(0, n_eq): # for each eq ligand
# now we need to map back to full positions
eq_ligand_eq_full_derivative = full_autocorrelation_derivative(eq_ligand_list[i].mol, prop, depth)
for ii, row in enumerate(eq_ligand_eq_full_derivative):
for original_ids in list(eq_ligand_list[i].ext_int_dict.keys()):
eq_full_j[ii, original_ids] += np.divide(row[eq_ligand_list[i].ext_int_dict[original_ids]], n_eq)
# ligand connection ACs
for i in range(0, n_ax):
ax_ligand_ac_con_derivative = atom_only_autocorrelation_derivative(ax_ligand_list[i].mol, prop, depth,
ax_con_int_list[i])
# now we need to map back to full positions
for ii, row in enumerate(ax_ligand_ac_con_derivative):
for original_ids in list(ax_ligand_list[i].ext_int_dict.keys()):
ax_con_j[ii, original_ids] += np.divide(row[ax_ligand_list[i].ext_int_dict[original_ids]], n_ax)
for i in range(0, n_eq):
eq_ligand_ac_con_derivative = atom_only_autocorrelation_derivative(eq_ligand_list[i].mol, prop, depth,
eq_con_int_list[i])
# now we need to map back to full positions
for ii, row in enumerate(eq_ligand_ac_con_derivative):
for original_ids in list(eq_ligand_list[i].ext_int_dict.keys()):
eq_con_j[ii, original_ids] += np.divide(row[eq_ligand_list[i].ext_int_dict[original_ids]], n_eq)
return ax_full_j, eq_full_j, ax_con_j, eq_con_j
def find_ligand_autocorrs_and_deltametrics_oct_dimers(mol, prop, loud, depth, name=False,
oct=True, custom_ligand_dict=False):
# # this function takes a
# # symmetric (axial == axial,
# # equatorial == equatorial)
# # octahedral complex
# # and returns autocorrelations for
# # the axial an equatorial ligands
# # custom_ligand_dict allows the user to skip the breakdown
# # in cases where 3D geo is not correct/formed
# # custom_ligand_dict.keys() must be eq_ligands_list, ax_ligand_list
# # ax_con_int_list ,eq_con_int_list
# # with types: eq/ax_ligand_list list of mol3D
# # eq/ax_con_int_list list of list/tuple of int e.g, [[1,2] [1,2]]
if not custom_ligand_dict:
raise ValueError('No custom ligand dict provided!')
# liglist, ligdents, ligcons = ligand_breakdown(mol)
# ax_ligand_list, eq_ligand_list, ax_natoms_list, eq_natoms_list, ax_con_int_list, eq_con_int_list,
# ax_con_list, eq_con_list, built_ligand_list = ligand_assign(
# mol, liglist, ligdents, ligcons, loud, name=False)
else:
ax1_ligand_list = custom_ligand_dict["ax1_ligand_list"]
ax2_ligand_list = custom_ligand_dict["ax2_ligand_list"]
ax3_ligand_list = custom_ligand_dict["ax3_ligand_list"]
ax1_con_int_list = custom_ligand_dict["ax1_con_int_list"]
ax2_con_int_list = custom_ligand_dict["ax2_con_int_list"]
ax3_con_int_list = custom_ligand_dict["ax3_con_int_list"]
axligs = [ax1_ligand_list, ax2_ligand_list, ax3_ligand_list]
axcons = [ax1_con_int_list, ax2_con_int_list, ax3_con_int_list]
n_axs = [len(i) for i in axligs]
# get full ligand AC
ax_ligand_ac_fulls = [False, False, False]
for axnum in range(3):
ax_ligand_ac_full = list()
for i in range(0, n_axs[axnum]):
if not list(ax_ligand_ac_full):
ax_ligand_ac_full = full_autocorrelation(axligs[axnum][i].mol, prop, depth)
else:
ax_ligand_ac_full += full_autocorrelation(axligs[axnum][i].mol, prop, depth)
ax_ligand_ac_full = np.divide(ax_ligand_ac_full, n_axs[axnum])
ax_ligand_ac_fulls[axnum] = ax_ligand_ac_full
# get partial ligand AC
ax_ligand_ac_cons = [False, False, False]
for axnum in range(3):
ax_ligand_ac_con = list()
for i in range(0, n_axs[axnum]):
if not list(ax_ligand_ac_con):
ax_ligand_ac_con = atom_only_autocorrelation(axligs[axnum][i].mol, prop, depth, axcons[axnum][i])
else:
ax_ligand_ac_con += atom_only_autocorrelation(axligs[axnum][i].mol, prop, depth, axcons[axnum][i])
ax_ligand_ac_con = np.divide(ax_ligand_ac_con, n_axs[axnum])
ax_ligand_ac_cons[axnum] = ax_ligand_ac_con
# get deltametrics
ax_delta_cons = [False, False, False]
for axnum in range(3):
ax_delta_con = list()
for i in range(0, n_axs[axnum]):
if not list(ax_delta_con):
ax_delta_con = atom_only_deltametric(axligs[axnum][i].mol, prop, depth, axcons[axnum][i])
else:
ax_delta_con += atom_only_deltametric(axligs[axnum][i].mol, prop, depth, axcons[axnum][i])
ax_delta_con = np.divide(ax_delta_con, n_axs[axnum])
ax_delta_cons[axnum] = ax_delta_con
return ax_ligand_ac_fulls + ax_ligand_ac_cons + ax_delta_cons
def find_ligand_deltametrics_oct(mol, prop, loud, depth, name=False, oct=True, custom_ligand_dict=False):
# # custom_ligand_dict.keys() must be eq_ligands_list, ax_ligand_list
# # ax_con_int_list ,eq_con_int_list
# # with types: eq/ax_ligand_list list of mol3D
# # eq/ax_con_int_list list of list/tuple of int e.g, [[1,2] [1,2]]
# # this function takes a
# # octahedral complex
# # and returns deltametrics for
# # the axial an equatorial ligands
if not custom_ligand_dict:
liglist, ligdents, ligcons = ligand_breakdown(mol, BondedOct=oct)
(ax_ligand_list, eq_ligand_list, ax_natoms_list, eq_natoms_list, ax_con_int_list,
eq_con_int_list, ax_con_list, eq_con_list, built_ligand_list) = ligand_assign(
mol, liglist, ligdents, ligcons, loud, name=False)
else:
ax_ligand_list = custom_ligand_dict["ax_ligand_list"]
eq_ligand_list = custom_ligand_dict["eq_ligand_list"]
ax_con_int_list = custom_ligand_dict["ax_con_int_list"]
eq_con_int_list = custom_ligand_dict["eq_con_int_list"]
# count ligands
n_ax = len(ax_ligand_list)
n_eq = len(eq_ligand_list)
# get partial ligand AC
ax_ligand_ac_con = []
eq_ligand_ac_con = []
for i in range(0, n_ax):