Angellys Correa
Angellys Correa

Reputation: 61

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

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

Upvotes: 0

Views: 7688

Answers (4)

CYU
CYU

Reputation: 21

I believe that there's a mistake in the first formula. You probably wanted to say:

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

Upvotes: 0

Fairy Dance
Fairy Dance

Reputation: 21

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

Upvotes: 2

Chema_arguez
Chema_arguez

Reputation: 77

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))

Upvotes: 0

Angellys Correa
Angellys Correa

Reputation: 61

Solution found:

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

Upvotes: 1

Related Questions