Calculate root mean square deviation (RMSD) with numpy of Python

5.8k Views Asked by At

I transformed the coordinates of two atoms into an array: coord

And I must calculate the root mean squared deviation (RMSD) between the two sets of these coordinates.

For this I have:

def cal_rmsd_numpy(coord_1, coord_2):
    rmsd = np.sqrt(((coord_1 - coord_2) ** 2).mean())    ## this would be the formula
    return rmsd

rmsd = cal_rmsd_numpy(coord_1, coord_2)

print(rmsd)

But the result does not give me the correct number. I think the error is in the formula. Could someone please help me correct what I have wrong?

The formule for RMSD is:

enter image description here

3

There are 3 best solutions below

0
Angellys Correa On BEST ANSWER

Solution found:

rmsd = np.sqrt(((((coordenadas_1 - coordenadas_2)** 2))*3).mean())
0
Chema_arguez On

You have to add up the subtraction of the coordinates firs:

rmsd = np.sqrt((((coordenadas_1 - coordenadas_2)**2).sum()).mean())

Or even more intuitive looking to the formula:

rmsd = np.sqrt((((coordenadas_1 - coordenadas_2)**2).sum())/len(coordenadas_1))

1
Fairy Dance On
np.sqrt(((a - b)**2).sum(-1).mean())