charnley / rmsd

Calculate Root-mean-square deviation (RMSD) of two molecules, using rotation, in xyz or pdb format
BSD 2-Clause "Simplified" License
500 stars 115 forks source link

Align N molecules to M other molecules #35

Closed larsbratholm closed 2 years ago

larsbratholm commented 6 years ago

Code if this will be implemented in the future.

Where P is (N, natoms, 3) and Q is (M, natoms, 3).

C = np.dot(np.transpose(P, [0,2,1]), Q.T)
V, S, W = np.linalg.svd(np.transpose(C, [0,3,1,2]))
d = (np.linalg.det(V) * np.linalg.det(W)) < 0.0
S[d,-1] *= -1
V[d, :, -1] *= -1

U = np.dot(V[0,1], W[0,1])
U = np.matmul(V, W)

P = np.einsum('ijk,iabk->ijba', P, U)

delta = P - np.transpose(Q, [1,2,0])

rmsd = np.sqrt(np.sum(delta**2, axis=(1,2)))
benjfitz commented 6 years ago

Making sure I understand, you would like to have two lists of molecules and compare each molecule in list N to each molecule in list M? If so, why not run RMSD in a bash script using for loops?

larsbratholm commented 6 years ago

Mostly for speed if M and N is large.

nbehrnd commented 5 years ago

@larsbratholm Assuming you were interested in the comparison of multiple cluster data per run, I wrote a moderator script distributing the workload on multiple CPU. At present, aiming to harvest the RMSD as distribution rather than attributed to a specific test of modelA to modelB, it seems to be good enough (deposit.)