20
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
# SOFTWARE.
22
22
23
+ from __future__ import print_function
24
+
23
25
import numpy as np
24
26
25
27
from .farad_kernels import fget_kernels_arad
26
28
from .farad_kernels import fget_symmetric_kernels_arad
27
29
28
- PTP = {\
29
- 1 :[1 ,1 ] ,2 : [1 ,8 ]#Row1
30
-
31
- ,3 :[2 ,1 ] ,4 : [2 ,2 ]#Row2\
32
- ,5 :[2 ,3 ] ,6 : [2 ,4 ] ,7 :[2 ,5 ] ,8 :[2 ,6 ] ,9 :[2 ,7 ] ,10 :[2 ,8 ]\
33
-
34
- ,11 :[3 ,1 ] ,12 : [3 ,2 ]#Row3\
35
- ,13 :[3 ,3 ] ,14 : [3 ,4 ] ,15 :[3 ,5 ] ,16 :[3 ,6 ] ,17 :[3 ,7 ] ,18 :[3 ,8 ]\
36
-
37
- ,19 :[4 ,1 ] ,20 : [4 ,2 ]#Row4\
38
- ,31 :[4 ,3 ] ,32 : [4 ,4 ] ,33 :[4 ,5 ] ,34 :[4 ,6 ] ,35 :[4 ,7 ] ,36 :[4 ,8 ]\
39
- ,21 :[4 ,9 ] ,22 : [4 ,10 ],23 :[4 ,11 ],24 :[4 ,12 ],25 :[4 ,13 ],26 :[4 ,14 ],27 :[4 ,15 ],28 :[4 ,16 ],29 :[4 ,17 ],30 :[4 ,18 ]\
40
-
41
- ,37 :[5 ,1 ] ,38 : [5 ,2 ]#Row5\
42
- ,49 :[5 ,3 ] ,50 : [5 ,4 ] ,51 :[5 ,5 ] ,52 :[5 ,6 ] ,53 :[5 ,7 ] ,54 :[5 ,8 ]\
43
- ,39 :[5 ,9 ] ,40 : [5 ,10 ],41 :[5 ,11 ],42 :[5 ,12 ],43 :[5 ,13 ],44 :[5 ,14 ],45 :[5 ,15 ],46 :[5 ,16 ],47 :[5 ,17 ],48 :[5 ,18 ]\
44
-
45
- ,55 :[6 ,1 ] ,56 : [6 ,2 ]#Row6\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,89 :[7 ,19 ],90 : [7 ,20 ],91 :[7 ,21 ],92 :[7 ,22 ],93 :[7 ,23 ],94 :[7 ,24 ],95 :[7 ,25 ],96 :[7 ,26 ],97 :[7 ,27 ],98 :[7 ,28 ],99 :[7 ,29 ],100 :[7 ,30 ],101 :[7 ,31 ],101 :[7 ,32 ],102 :[7 ,14 ],103 :[7 ,33 ]}
54
56
55
57
56
- def get_atomic_kernels_arad (X1 , X2 , Z1 , Z2 , sigmas , \
58
+ def get_atomic_kernels_arad (X1 , X2 , Z1 , Z2 , sigmas ,
57
59
width = 0.2 , cut_distance = 5.0 , r_width = 1.0 , c_width = 0.5 ):
58
60
""" Calculates the Gaussian kernel matrix K for atomic ARAD
59
61
descriptors for a list of different sigmas.
60
62
61
63
K is calculated using an OpenMP parallel Fortran routine.
62
64
63
- Arguments:
64
- ==============
65
- X1 -- np.array of ARAD descriptors for molecules in set 1.
66
- X2 -- np.array of ARAD descriptors for molecules in set 2.
67
- Z1 -- List of lists of nuclear charges for molecules in set 1.
68
- Z2 -- List of lists of nuclear charges for molecules in set 2.
69
- sigmas -- List of sigma for which to calculate the Kernel matrices.
70
-
71
- Returns:
72
- ==============
73
- K -- The kernel matrices for each sigma (3D-array, Ns x N1 x N2)
65
+ :param X1: ARAD descriptors for molecules in set 1.
66
+ :type X1: numpy array
67
+ :param X2: Array of ARAD descriptors for molecules in set 2.
68
+ :type X2: numpy array
69
+ :param Z1: List of lists of nuclear charges for molecules in set 1.
70
+ :type Z1: list
71
+ :param Z2: List of lists of nuclear charges for molecules in set 2.
72
+ :type Z2: list
73
+ :param sigmas: List of sigmas for which to calculate the Kernel matrices.
74
+ :type sigmas: list
75
+
76
+ :return: The kernel matrices for each sigma - shape (Ns, N1, N2)
77
+ :rtype: numpy array
74
78
"""
75
79
76
80
amax = X1 .shape [1 ]
@@ -85,61 +89,42 @@ def get_atomic_kernels_arad(X1, X2, Z1, Z2, sigmas, \
85
89
assert X1 .shape [0 ] == nm1 , "ERROR: Check ARAD decriptor sizes! code = 4"
86
90
assert X2 .shape [0 ] == nm2 , "ERROR: Check ARAD decriptor sizes! code = 5"
87
91
88
- N1 = []
89
- for Z in Z1 :
90
- N1 .append (len (Z ))
91
-
92
- N2 = []
93
- for Z in Z2 :
94
- N2 .append (len (Z ))
95
-
96
- N1 = np .array (N1 ,dtype = np .int32 )
97
- N2 = np .array (N2 ,dtype = np .int32 )
98
-
99
- nsigmas = len (sigmas )
100
-
101
- c1 = []
102
- for charges in Z1 :
103
- c1 .append (np .array ([PTP [int (q )] for q in charges ], dtype = np .int32 ))
104
-
105
- Z1_arad = np .zeros ((nm1 ,amax ,2 ))
106
-
92
+ N1 = np .empty (nm1 , dtype = np .int32 )
93
+ Z1_arad = np .zeros ((nm1 , amax , 2 ))
107
94
for i in range (nm1 ):
108
- for j , z in enumerate (c1 [i ]):
109
- Z1_arad [i ,j ] = z
110
-
111
- c2 = []
112
- for charges in Z2 :
113
- c2 .append (np .array ([PTP [int (q )] for q in charges ], dtype = np .int32 ))
114
-
115
- Z2_arad = np .zeros ((nm2 ,amax ,2 ))
95
+ N1 [i ] = len (Z1 [i ])
96
+ Z1_arad [i ,:N1 [i ]] = np .asarray ([PTP [q ] for q in Z1 [i ]], dtype = np .int32 )
116
97
98
+ N2 = np .empty (nm2 , dtype = np .int32 )
99
+ Z2_arad = np .zeros ((nm2 , amax , 2 ))
117
100
for i in range (nm2 ):
118
- for j , z in enumerate (c2 [i ]):
119
- Z2_arad [i ,j ] = z
101
+ N2 [i ] = len (Z2 [i ])
102
+ Z2_arad [i ,:N2 [i ]] = np .asarray ([PTP [q ] for q in Z2 [i ]], dtype = np .int32 )
103
+
120
104
121
105
sigmas = np .array (sigmas )
106
+ nsigmas = sigmas .size
122
107
123
- return fget_kernels_arad (X1 , X2 , Z1_arad , Z2_arad , N1 , N2 , sigmas , \
108
+ return fget_kernels_arad (X1 , X2 , Z1_arad , Z2_arad , N1 , N2 , sigmas ,
124
109
nm1 , nm2 , nsigmas , width , cut_distance , r_width , c_width )
125
110
126
111
127
- def get_atomic_symmetric_kernels_arad (X1 , Z1 , sigmas , \
112
+ def get_atomic_symmetric_kernels_arad (X1 , Z1 , sigmas ,
128
113
width = 0.2 , cut_distance = 5.0 , r_width = 1.0 , c_width = 0.5 ):
129
114
""" Calculates the Gaussian kernel matrix K for atomic ARAD
130
115
descriptors for a list of different sigmas.
131
116
132
117
K is calculated using an OpenMP parallel Fortran routine.
133
118
134
- Arguments:
135
- ==============
136
- X1 -- np.array of ARAD descriptors for molecules in set 1.
137
- Z1 -- List of lists of nuclear charges for molecules in set 1.
138
- sigmas -- List of sigma for which to calculate the Kernel matrices.
119
+ :param X1: ARAD descriptors for molecules in set 1.
120
+ :type X1: numpy array
121
+ :param Z1: List of lists of nuclear charges for molecules in set 1.
122
+ :type Z1: list
123
+ :param sigmas: List of sigmas for which to calculate the Kernel matrices.
124
+ :type sigmas: list
139
125
140
- Returns:
141
- ==============
142
- K -- The kernel matrices for each sigma (3D-array, Ns x N1 x N2)
126
+ :return: The kernel matrices for each sigma - shape (Ns, N1, N1)
127
+ :rtype: numpy array
143
128
"""
144
129
145
130
amax = X1 .shape [1 ]
@@ -150,25 +135,14 @@ def get_atomic_symmetric_kernels_arad(X1, Z1, sigmas, \
150
135
151
136
assert X1 .shape [0 ] == nm1 , "ERROR: Check ARAD decriptor sizes! code = 4"
152
137
153
- N1 = []
154
- for Z in Z1 :
155
- N1 .append (len (Z ))
156
-
157
- N1 = np .array (N1 ,dtype = np .int32 )
158
-
159
- nsigmas = len (sigmas )
160
-
161
- c1 = []
162
- for charges in Z1 :
163
- c1 .append (np .array ([PTP [int (q )] for q in charges ], dtype = np .int32 ))
164
-
165
- Z1_arad = np .zeros ((nm1 ,amax ,2 ))
166
-
138
+ N1 = np .empty (nm1 , dtype = np .int32 )
139
+ Z1_arad = np .zeros ((nm1 , amax , 2 ))
167
140
for i in range (nm1 ):
168
- for j , z in enumerate ( c1 [i ]):
169
- Z1_arad [ i , j ] = z
141
+ N1 [ i ] = len ( Z1 [i ])
142
+ Z1_arad [ i ,: N1 [ i ]] = np . asarray ([ PTP [ q ] for q in Z1 [ i ]], dtype = np . int32 )
170
143
171
144
sigmas = np .array (sigmas )
145
+ nsigmas = sigmas .size
172
146
173
- return fget_symmetric_kernels_arad (X1 , Z1_arad , N1 , sigmas , \
147
+ return fget_symmetric_kernels_arad (X1 , Z1_arad , N1 , sigmas ,
174
148
nm1 , nsigmas , width , cut_distance , r_width , c_width )
0 commit comments