def superpose(ras, rbs, weights=None):
if weights is None:<EOL><INDENT>ma = ras.mean(axis=<NUM_LIT:0>)<EOL>mb = rbs.mean(axis=<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>total_weight = weights.sum()<EOL>ma = np.dot(weights, ras)/total_weight<EOL>mb = np.dot(weights, rbs)/total_weight<EOL><DEDENT>if weights is None:<EOL><INDENT>A = np.dot((rbs-mb).transpose(), ras-ma)<EOL><DEDENT>else:<EOL><INDENT>weights = weights.reshape((-<NUM_LIT:1>, <NUM_LIT:1>))<EOL>A = np.dot(((rbs-mb)*weights).transpose(), (ras-ma)*weights)<EOL><DEDENT>v, s, wt = np.linalg.svd(A)<EOL>s[:] = <NUM_LIT:1><EOL>if np.linalg.det(np.dot(v, wt)) < <NUM_LIT:0>:<EOL><INDENT>s[<NUM_LIT:2>] = -<NUM_LIT:1><EOL><DEDENT>r = np.dot(wt.T*s, v.T)<EOL>return Complete(r, np.dot(r, -mb) + ma)<EOL>
Compute the transformation that minimizes the RMSD between the points ras and rbs

       Arguments:
        | ``ras``  --  a ``np.array`` with 3D coordinates of geometry A,
                       shape=(N,3)
        | ``rbs``  --  a ``np.array`` with 3D coordinates of geometry B,
                       shape=(N,3)

       Optional arguments:
        | ``weights``  --  a numpy array with fitting weights for each
                           coordinate, shape=(N,)

       Return value:
        | ``transformation``  --  the transformation that brings geometry A into
                                  overlap with geometry B

       Each row in ras and rbs represents a 3D coordinate. Corresponding rows
       contain the points that are brought into overlap by the fitting
       procedure. The implementation is based on the Kabsch Algorithm:

       http://dx.doi.org/10.1107%2FS0567739476001873