Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Commit 2f47e85

Browse files
larsbratholmandersx
authored andcommitted
Added python interface to symmetric vector kernels (#83)
1 parent 54a2f19 commit 2f47e85

File tree

1 file changed

+99
-18
lines changed

1 file changed

+99
-18
lines changed

qml/kernels/wrappers.py

+99-18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
from .fkernels import fget_vector_kernels_gaussian
2626
from .fkernels import fget_vector_kernels_laplacian
27+
from .fkernels import fget_vector_kernels_gaussian_symmetric
28+
from .fkernels import fget_vector_kernels_laplacian_symmetric
2729
from .fkernels import fget_local_kernels_gaussian
2830

2931
from ..arad import get_local_kernels_arad
@@ -62,38 +64,52 @@ def get_atomic_kernels_laplacian(mols1, mols2, sigmas):
6264
return fget_vector_kernels_laplacian(x1, x2, n1, n2, sigmas,
6365
nm1, nm2, nsigmas)
6466

67+
def get_atomic_kernels_laplacian_symmetric(mols, sigmas):
6568

66-
def get_atomic_kernels_gaussian(mols1, mols2, sigmas):
69+
n = np.array([mol.natoms for mol in mols], dtype=np.int32)
6770

68-
n1 = np.array([mol.natoms for mol in mols1], dtype=np.int32)
69-
n2 = np.array([mol.natoms for mol in mols2], dtype=np.int32)
71+
max_atoms = np.max(n)
7072

71-
max1 = np.max(n1)
72-
max2 = np.max(n2)
73+
nm = n.size
7374

74-
nm1 = n1.size
75-
nm2 = n2.size
75+
cmat_size = mols[0].representation.shape[1]
7676

77-
cmat_size = mols1[0].representation.shape[1]
77+
x = np.zeros((nm, max_atoms, cmat_size), dtype=np.float64, order="F")
7878

79-
x1 = np.zeros((nm1, max1, cmat_size), dtype=np.float64, order="F")
80-
x2 = np.zeros((nm2, max2, cmat_size), dtype=np.float64, order="F")
79+
for imol in range(nm):
80+
x[imol,:n[imol],:cmat_size] = mols[imol].representation
8181

82-
for imol in range(nm1):
83-
x1[imol,:n1[imol],:cmat_size] = mols1[imol].representation
82+
# Reorder for Fortran speed
83+
x = np.swapaxes(x, 0, 2)
8484

85-
for imol in range(nm2):
86-
x2[imol,:n2[imol],:cmat_size] = mols2[imol].representation
85+
sigmas = np.asarray(sigmas, dtype=np.float64)
86+
nsigmas = sigmas.size
87+
88+
return fget_vector_kernels_laplacian(x1, n, sigmas, nm, nsigmas)
89+
90+
91+
def get_atomic_kernels_gaussian(mols, sigmas):
92+
93+
n = np.array([mol.natoms for mol in mols], dtype=np.int32)
94+
95+
max_atoms = np.max(n)
96+
97+
nm = n.size
98+
99+
cmat_size = mols[0].representation.shape[1]
100+
101+
x1 = np.zeros((nm, max_atoms, cmat_size), dtype=np.float64, order="F")
102+
103+
for imol in range(nm1):
104+
x[imol,:n[imol],:cmat_size] = mols[imol].representation
87105

88106
# Reorder for Fortran speed
89-
x1 = np.swapaxes(x1, 0, 2)
90-
x2 = np.swapaxes(x2, 0, 2)
107+
x = np.swapaxes(x, 0, 2)
91108

92109
sigmas = np.array(sigmas, dtype=np.float64)
93110
nsigmas = sigmas.size
94111

95-
return fget_vector_kernels_gaussian(x1, x2, n1, n2, sigmas,
96-
nm1, nm2, nsigmas)
112+
return fget_vector_kernels_gaussian(x, n, sigmas, nm, nsigmas)
97113

98114

99115
def arad_local_kernels(mols1, mols2, sigmas,
@@ -125,3 +141,68 @@ def arad_local_symmetric_kernels(mols1, sigmas,
125141
width=width, cut_distance=cut_distance, r_width=r_width, c_width=c_width)
126142

127143
return K
144+
145+
def get_atomic_kernels_laplacian(mols1, mols2, sigmas):
146+
147+
n1 = np.array([mol.natoms for mol in mols1], dtype=np.int32)
148+
n2 = np.array([mol.natoms for mol in mols2], dtype=np.int32)
149+
150+
max1 = np.max(n1)
151+
max2 = np.max(n2)
152+
153+
nm1 = n1.size
154+
nm2 = n2.size
155+
156+
cmat_size = mols1[0].representation.shape[1]
157+
158+
x1 = np.zeros((nm1, max1, cmat_size), dtype=np.float64, order="F")
159+
x2 = np.zeros((nm2, max2, cmat_size), dtype=np.float64, order="F")
160+
161+
for imol in range(nm1):
162+
x1[imol,:n1[imol],:cmat_size] = mols1[imol].representation
163+
164+
for imol in range(nm2):
165+
x2[imol,:n2[imol],:cmat_size] = mols2[imol].representation
166+
167+
# Reorder for Fortran speed
168+
x1 = np.swapaxes(x1, 0, 2)
169+
x2 = np.swapaxes(x2, 0, 2)
170+
171+
sigmas = np.asarray(sigmas, dtype=np.float64)
172+
nsigmas = sigmas.size
173+
174+
return fget_vector_kernels_laplacian(x1, x2, n1, n2, sigmas,
175+
nm1, nm2, nsigmas)
176+
177+
178+
def get_atomic_kernels_gaussian(mols1, mols2, sigmas):
179+
180+
n1 = np.array([mol.natoms for mol in mols1], dtype=np.int32)
181+
n2 = np.array([mol.natoms for mol in mols2], dtype=np.int32)
182+
183+
max1 = np.max(n1)
184+
max2 = np.max(n2)
185+
186+
nm1 = n1.size
187+
nm2 = n2.size
188+
189+
cmat_size = mols1[0].representation.shape[1]
190+
191+
x1 = np.zeros((nm1, max1, cmat_size), dtype=np.float64, order="F")
192+
x2 = np.zeros((nm2, max2, cmat_size), dtype=np.float64, order="F")
193+
194+
for imol in range(nm1):
195+
x1[imol,:n1[imol],:cmat_size] = mols1[imol].representation
196+
197+
for imol in range(nm2):
198+
x2[imol,:n2[imol],:cmat_size] = mols2[imol].representation
199+
200+
# Reorder for Fortran speed
201+
x1 = np.swapaxes(x1, 0, 2)
202+
x2 = np.swapaxes(x2, 0, 2)
203+
204+
sigmas = np.array(sigmas, dtype=np.float64)
205+
nsigmas = sigmas.size
206+
207+
return fget_vector_kernels_gaussian(x1, x2, n1, n2, sigmas,
208+
nm1, nm2, nsigmas)

0 commit comments

Comments
 (0)