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

Commit 2634aef

Browse files
larsbratholmandersx
authored andcommitted
bobfix (#46)
larsbratholm fixed bob bug, updated FORTRAN implementations
1 parent 618035d commit 2634aef

File tree

3 files changed

+14
-45
lines changed

3 files changed

+14
-45
lines changed

qml/frepresentations.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,9 @@ subroutine fgenerate_bob(atomic_charges, coordinates, nuclear_charges, id, &
816816
enddo
817817
enddo
818818

819-
start_indices(i) = start_indices(i) + natoms1
819+
start_indices(i) = start_indices(i) + nmax(i)
820820

821-
nbag = (natoms1 * natoms1 - natoms1) / 2
821+
nbag = (nmax(i) * nmax(i) - nmax(i)) / 2
822822
! sort
823823
do j = 1, nbag
824824
k = minloc(bag(:nbag), dim=1)
@@ -845,7 +845,7 @@ subroutine fgenerate_bob(atomic_charges, coordinates, nuclear_charges, id, &
845845
enddo
846846

847847
! sort
848-
nbag = natoms1 * natoms2
848+
nbag = nmax(i) * nmax(j)
849849
do k = 1, nbag
850850
l = minloc(bag(:nbag), dim=1)
851851
cm(start_indices(i) + nbag - k + 1) = bag(l)

qml/representations.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .frepresentations import fgenerate_local_coulomb_matrix
3131
from .frepresentations import fgenerate_atomic_coulomb_matrix
3232
from .frepresentations import fgenerate_eigenvalue_coulomb_matrix
33+
from .frepresentations import fgenerate_bob
3334

3435
from .data import NUCLEAR_CHARGE
3536

@@ -294,37 +295,6 @@ def generate_bob(nuclear_charges, coordinates, atomtypes, size=23, asize = {"O":
294295
:return: 1D representation
295296
:rtype: numpy array
296297
"""
297-
natoms = len(nuclear_charges)
298-
299-
coulomb_matrix = fgenerate_unsorted_coulomb_matrix(nuclear_charges, coordinates, size)
300-
301-
coulomb_matrix = vector_to_matrix(coulomb_matrix)
302-
descriptor = []
303-
atomtypes = np.asarray(atomtypes)
304-
for atom1, size1 in sorted(asize.items()):
305-
pos1 = np.where(atomtypes == atom1)[0]
306-
feature_vector = np.zeros(size1)
307-
feature_vector[:pos1.size] = np.diag(coulomb_matrix)[pos1]
308-
feature_vector.sort()
309-
descriptor.append(feature_vector[:])
310-
for atom2, size2 in sorted(asize.items()):
311-
if atom1 > atom2:
312-
continue
313-
if atom1 == atom2:
314-
size = size1*(size1-1)//2
315-
feature_vector = np.zeros(size)
316-
sub_matrix = coulomb_matrix[np.ix_(pos1,pos1)]
317-
feature_vector[:pos1.size*(pos1.size-1)//2] = sub_matrix[np.triu_indices(pos1.size, 1)]
318-
feature_vector.sort()
319-
descriptor.append(feature_vector[:])
320-
else:
321-
pos2 = np.where(atomtypes == atom2)[0]
322-
feature_vector = np.zeros(size1*size2)
323-
feature_vector[:pos1.size*pos2.size] = coulomb_matrix[np.ix_(pos1,pos2)].ravel()
324-
feature_vector.sort()
325-
descriptor.append(feature_vector[:])
326-
327-
return np.concatenate(descriptor)
328298

329299
n = 0
330300
atoms = sorted(asize, key=asize.get)
@@ -340,7 +310,6 @@ def generate_bob(nuclear_charges, coordinates, atomtypes, size=23, asize = {"O":
340310

341311
return fgenerate_bob(nuclear_charges, coordinates, nuclear_charges, ids, nmax, n)
342312

343-
344313
def get_slatm_mbtypes(nuclear_charges, pbc='000'):
345314
"""
346315
Get the list of minimal types of many-body terms in a dataset. This resulting list

0 commit comments

Comments
 (0)