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

Added python interface to symmetric vector kernels #83

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 99 additions & 18 deletions qml/kernels/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

from .fkernels import fget_vector_kernels_gaussian
from .fkernels import fget_vector_kernels_laplacian
from .fkernels import fget_vector_kernels_gaussian_symmetric
from .fkernels import fget_vector_kernels_laplacian_symmetric
from .fkernels import fget_local_kernels_gaussian

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

def get_atomic_kernels_laplacian_symmetric(mols, sigmas):

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

n1 = np.array([mol.natoms for mol in mols1], dtype=np.int32)
n2 = np.array([mol.natoms for mol in mols2], dtype=np.int32)
max_atoms = np.max(n)

max1 = np.max(n1)
max2 = np.max(n2)
nm = n.size

nm1 = n1.size
nm2 = n2.size
cmat_size = mols[0].representation.shape[1]

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

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

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

for imol in range(nm2):
x2[imol,:n2[imol],:cmat_size] = mols2[imol].representation
sigmas = np.asarray(sigmas, dtype=np.float64)
nsigmas = sigmas.size

return fget_vector_kernels_laplacian(x1, n, sigmas, nm, nsigmas)


def get_atomic_kernels_gaussian(mols, sigmas):

n = np.array([mol.natoms for mol in mols], dtype=np.int32)

max_atoms = np.max(n)

nm = n.size

cmat_size = mols[0].representation.shape[1]

x1 = np.zeros((nm, max_atoms, cmat_size), dtype=np.float64, order="F")

for imol in range(nm1):
x[imol,:n[imol],:cmat_size] = mols[imol].representation

# Reorder for Fortran speed
x1 = np.swapaxes(x1, 0, 2)
x2 = np.swapaxes(x2, 0, 2)
x = np.swapaxes(x, 0, 2)

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

return fget_vector_kernels_gaussian(x1, x2, n1, n2, sigmas,
nm1, nm2, nsigmas)
return fget_vector_kernels_gaussian(x, n, sigmas, nm, nsigmas)


def arad_local_kernels(mols1, mols2, sigmas,
Expand Down Expand Up @@ -125,3 +141,68 @@ def arad_local_symmetric_kernels(mols1, sigmas,
width=width, cut_distance=cut_distance, r_width=r_width, c_width=c_width)

return K

def get_atomic_kernels_laplacian(mols1, mols2, sigmas):

n1 = np.array([mol.natoms for mol in mols1], dtype=np.int32)
n2 = np.array([mol.natoms for mol in mols2], dtype=np.int32)

max1 = np.max(n1)
max2 = np.max(n2)

nm1 = n1.size
nm2 = n2.size

cmat_size = mols1[0].representation.shape[1]

x1 = np.zeros((nm1, max1, cmat_size), dtype=np.float64, order="F")
x2 = np.zeros((nm2, max2, cmat_size), dtype=np.float64, order="F")

for imol in range(nm1):
x1[imol,:n1[imol],:cmat_size] = mols1[imol].representation

for imol in range(nm2):
x2[imol,:n2[imol],:cmat_size] = mols2[imol].representation

# Reorder for Fortran speed
x1 = np.swapaxes(x1, 0, 2)
x2 = np.swapaxes(x2, 0, 2)

sigmas = np.asarray(sigmas, dtype=np.float64)
nsigmas = sigmas.size

return fget_vector_kernels_laplacian(x1, x2, n1, n2, sigmas,
nm1, nm2, nsigmas)


def get_atomic_kernels_gaussian(mols1, mols2, sigmas):

n1 = np.array([mol.natoms for mol in mols1], dtype=np.int32)
n2 = np.array([mol.natoms for mol in mols2], dtype=np.int32)

max1 = np.max(n1)
max2 = np.max(n2)

nm1 = n1.size
nm2 = n2.size

cmat_size = mols1[0].representation.shape[1]

x1 = np.zeros((nm1, max1, cmat_size), dtype=np.float64, order="F")
x2 = np.zeros((nm2, max2, cmat_size), dtype=np.float64, order="F")

for imol in range(nm1):
x1[imol,:n1[imol],:cmat_size] = mols1[imol].representation

for imol in range(nm2):
x2[imol,:n2[imol],:cmat_size] = mols2[imol].representation

# Reorder for Fortran speed
x1 = np.swapaxes(x1, 0, 2)
x2 = np.swapaxes(x2, 0, 2)

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

return fget_vector_kernels_gaussian(x1, x2, n1, n2, sigmas,
nm1, nm2, nsigmas)