text_plain_output_1.png
import numpy as np

def compute_all_yukawa(x):
    return x.apply(compute_yukawa_matrix, axis=1, x2=x)
def compute_yukawa_matrix(x, x2):
    notatom = x2[x2.atom_index != x['atom_index']].reset_index(drop=True)
    atom = x[['x', 'y', 'z']]
    charge = x[['nuclear_charge']]
    notatom['dist'] = ((notatom[['x', 'y', 'z']].values - atom.values) ** 2).sum(axis=1)
    notatom['dist'] = np.sqrt(notatom['dist'].astype(np.float32))
    notatom['dist'] = charge.values * notatom[['nuclear_charge']].values.reshape(-1) * np.exp(-2 * notatom['dist'] / notatom['dist'].max()) / notatom['dist']
    s = notatom.groupby('atom')['dist'].transform(lambda x: x.sort_values(ascending=False))
    index0, index1 = ([], [])
    for i in notatom.atom.unique():
        for j in range(notatom[notatom.atom == i].shape[0]):
            if j < 5:
                index1.append('dist_' + i + '_' + str(j))
            index0.append(j)
    s.index = index0
    s = s[s.index < 5]
    s.index = index1
    return s

np.allclose(smallstruct2.fillna(0), smallstruct1.fillna(0))