Skip to content

Commit

Permalink
Fixed representation test
Browse files Browse the repository at this point in the history
  • Loading branch information
charnley committed Feb 23, 2024
1 parent 5be2374 commit 5228012
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 147 deletions.
3 changes: 2 additions & 1 deletion src/qmllib/representations/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def generate_atomic_coulomb_matrix(
if indices is None:
nindices = len(nuclear_charges)
indices = np.arange(1, 1 + nindices, 1, dtype=int)
# elif type("") == type(indices):
elif isinstance(indices, str):
if indices in NUCLEAR_CHARGE:
indices = np.where(nuclear_charges == NUCLEAR_CHARGE[indices])[0] + 1
Expand Down Expand Up @@ -311,6 +310,8 @@ def generate_bob(
:rtype: numpy array
"""

# TODO Moving between str and int is _, should translate everything to use int

n = 0
atoms = sorted(asize, key=asize.get)
nmax = [asize[key] for key in atoms]
Expand Down
174 changes: 86 additions & 88 deletions src/qmllib/representations/slatm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import itertools

import numpy as np
import scipy.spatial.distance as spatial_distance

from .fslatm import fget_sbop, fget_sbop_local, fget_sbot, fget_sbot_local

Expand All @@ -12,91 +9,92 @@ def update_m(obj, ia, rcut=9.0, pbc=None):
for periodic systems (or very large system)
"""

zs, coords, c = obj
v1, v2, v3 = c
vs = spatial_distance.norm(c, axis=0)

nns = []
for i, vi in enumerate(vs):
raise NotImplementedError()
# n1_doulbe = rcut / li # TODO Anders, what is li
# n1 = int(n1_doulbe)
# if n1 - n1_doulbe == 0:
# n1s = (
# range(-n1, n1 + 1)
# if pbc[i]
# else [
# 0,
# ]
# )
# elif n1 == 0:
# n1s = (
# [-1, 0, 1]
# if pbc[i]
# else [
# 0,
# ]
# )
# else:
# n1s = (
# range(-n1 - 1, n1 + 2)
# if pbc[i]
# else [
# 0,
# ]
# )

# nns.append(n1s)

n1s, n2s, n3s = nns

n123s_ = np.array(list(itertools.product(n1s, n2s, n3s)))
n123s = []
for n123 in n123s_:
n123u = list(n123)
if n123u != [0, 0, 0]:
n123s.append(n123u)

nau = len(n123s)
n123s = np.array(n123s, np.float64)

na = len(zs)
cia = coords[ia]

if na == 1:
ds = np.array([[0.0]])
else:
ds = spatial_distance.squareform(spatial_distance.pdist(coords))

zs_u = []
coords_u = []
zs_u.append(zs[ia])
coords_u.append(coords[ia])
for i in range(na):
di = ds[i, ia]
if (di > 0) and (di <= rcut):
zs_u.append(zs[i])
coords_u.append(coords[ia])

# add new coords by translation
ts = np.zeros((nau, 3))
for iau in range(nau):
ts[iau] = np.dot(n123s[iau], c)

coords_iu = coords[i] + ts # np.dot(n123s, c)
dsi = spatial_distance.norm(coords_iu - cia, axis=1)
filt = np.logical_and(dsi > 0, dsi <= rcut)
nx = filt.sum()
zs_u += [
zs[i],
] * nx
coords_u += [
list(coords_iu[filt, :]),
]

obj_u = [zs_u, coords_u]

return obj_u
raise NotImplementedError("Function is in-complete")

# zs, coords, c = obj
# v1, v2, v3 = c
# vs = spatial_distance.norm(c, axis=0)

# nns = []
# for i, vi in enumerate(vs):
# # n1_doulbe = rcut / li # what is li
# # n1 = int(n1_doulbe)
# # if n1 - n1_doulbe == 0:
# # n1s = (
# # range(-n1, n1 + 1)
# # if pbc[i]
# # else [
# # 0,
# # ]
# # )
# # elif n1 == 0:
# # n1s = (
# # [-1, 0, 1]
# # if pbc[i]
# # else [
# # 0,
# # ]
# # )
# # else:
# # n1s = (
# # range(-n1 - 1, n1 + 2)
# # if pbc[i]
# # else [
# # 0,
# # ]
# # )

# # nns.append(n1s)

# n1s, n2s, n3s = nns

# n123s_ = np.array(list(itertools.product(n1s, n2s, n3s)))
# n123s = []
# for n123 in n123s_:
# n123u = list(n123)
# if n123u != [0, 0, 0]:
# n123s.append(n123u)

# nau = len(n123s)
# n123s = np.array(n123s, np.float64)

# na = len(zs)
# cia = coords[ia]

# if na == 1:
# ds = np.array([[0.0]])
# else:
# ds = spatial_distance.squareform(spatial_distance.pdist(coords))

# zs_u = []
# coords_u = []
# zs_u.append(zs[ia])
# coords_u.append(coords[ia])
# for i in range(na):
# di = ds[i, ia]
# if (di > 0) and (di <= rcut):
# zs_u.append(zs[i])
# coords_u.append(coords[ia])

# # add new coords by translation
# ts = np.zeros((nau, 3))
# for iau in range(nau):
# ts[iau] = np.dot(n123s[iau], c)

# coords_iu = coords[i] + ts # np.dot(n123s, c)
# dsi = spatial_distance.norm(coords_iu - cia, axis=1)
# filt = np.logical_and(dsi > 0, dsi <= rcut)
# nx = filt.sum()
# zs_u += [
# zs[i],
# ] * nx
# coords_u += [
# list(coords_iu[filt, :]),
# ]

# obj_u = [zs_u, coords_u]

# return obj_u


def get_boa(z1, zs_):
Expand Down
Loading

0 comments on commit 5228012

Please sign in to comment.