# Buggy code
def _single_frame(self):
    mobile_com = self.mobile_atoms.center(self.weights).astype(np.float64)
    self._mobile_coordinates64[:] = self.mobile_atoms.positions
    self._mobile_coordinates64 -= mobile_com

    self.rmsd[self._frame_index, :2] = self._ts.frame, self._trajectory.time

    if self._groupselections_atoms:
        # superimpose structures: MDAnalysis qcprot needs Nx3 coordinate
        # array with float64 datatype (float32 leads to errors up to 1e-3 in
        # RMSD). Note that R is defined in such a way that it acts **to the
        # left** so that we can easily use broadcasting and save one
        # expensive numpy transposition.

        self.rmsd[self._frame_index, 2] = qcp.CalcRMSDRotationalMatrix(
            self._ref_coordinates64,
            self._mobile_coordinates64,
            self._n_atoms,
            self._rot,
            self.weights,
        )

        self._R[:, :] = self._rot.reshape(3, 3)
        # Transform each atom in the trajectory (use inplace ops to
        # avoid copying arrays) (Marginally (~3%) faster than
        # "ts.positions[:] = (ts.positions - x_com) * R + ref_com".)
        self._ts.positions[:] -= mobile_com

        # R acts to the left & is broadcasted N times.
        self._ts.positions[:] = np.dot(self._ts.positions, self._R)
        self._ts.positions += self._ref_com

        # 2) calculate secondary RMSDs (without any further
        #    superposition)
        for igroup, (refpos, atoms) in enumerate(
            zip(self._groupselections_ref_coords64, self._groupselections_atoms), 3
        ):
            self.rmsd[self._frame_index, igroup] = rmsd(
                refpos,
                atoms["mobile"].positions,
                weights=self.weights,
                center=False,
                superposition=False,
            )
    else:
        # only calculate RMSD by setting the Rmatrix to None (no need
        # to carry out the rotation as we already get the optimum RMSD)
        self.rmsd[self._frame_index, 2] = qcp.CalcRMSDRotationalMatrix(
            self._ref_coordinates64,
            self._mobile_coordinates64,
            self._n_atoms,
            None,
            self.weights,
        )

    self._pm.rmsd = self.rmsd[self._frame_index, 2]


# Traceback (ValueError)
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import PSF, DCD, CRD
import MDAnalysis.analysis.rms as rms
mda.__version__
'0.20.1'
u = mda.Universe(PSF, DCD)  # closed AdK (PDB ID: 1AKE)
R = rms.RMSD(u,  # universe to align
...              u,  # reference universe or atomgroup
...              select='backbone',  # group to superimpose and calculate RMSD
...              groupselections=["all"],  # groups for RMSD
...              weights='mass')  # weights for each atom
R.run()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MDAnalysis/analysis/base.py", line 197, in run
self._single_frame()
File "MDAnalysis/analysis/rms.py", line 638, in _single_frame
center=False, superposition=False)
File "MDAnalysis/analysis/rms.py", line 247, in rmsd
raise ValueError('weights must have same length as a and b')
ValueError: weights must have same length as a and b

# Fixed code
def _single_frame(self):
    mobile_com = self.mobile_atoms.center(self.weights_select).astype(np.float64)
    self._mobile_coordinates64[:] = self.mobile_atoms.positions
    self._mobile_coordinates64 -= mobile_com

    self.rmsd[self._frame_index, :2] = self._ts.frame, self._trajectory.time

    if self._groupselections_atoms:
        # superimpose structures: MDAnalysis qcprot needs Nx3 coordinate
        # array with float64 datatype (float32 leads to errors up to 1e-3 in
        # RMSD). Note that R is defined in such a way that it acts **to the
        # left** so that we can easily use broadcasting and save one
        # expensive numpy transposition.

        self.rmsd[self._frame_index, 2] = qcp.CalcRMSDRotationalMatrix(
            self._ref_coordinates64,
            self._mobile_coordinates64,
            self._n_atoms,
            self._rot,
            self.weights_select,
        )

        self._R[:, :] = self._rot.reshape(3, 3)
        # Transform each atom in the trajectory (use inplace ops to
        # avoid copying arrays) (Marginally (~3%) faster than
        # "ts.positions[:] = (ts.positions - x_com) * R + ref_com".)
        self._ts.positions[:] -= mobile_com

        # R acts to the left & is broadcasted N times.
        self._ts.positions[:] = np.dot(self._ts.positions, self._R)
        self._ts.positions += self._ref_com

        # 2) calculate secondary RMSDs (without any further
        #    superposition)
        for igroup, (refpos, atoms) in enumerate(
            zip(self._groupselections_ref_coords64, self._groupselections_atoms), 3
        ):
            self.rmsd[self._frame_index, igroup] = rmsd(
                refpos,
                atoms["mobile"].positions,
                weights=self.weights_groupselections[igroup - 3],
                center=False,
                superposition=False,
            )
    else:
        # only calculate RMSD by setting the Rmatrix to None (no need
        # to carry out the rotation as we already get the optimum RMSD)
        self.rmsd[self._frame_index, 2] = qcp.CalcRMSDRotationalMatrix(
            self._ref_coordinates64,
            self._mobile_coordinates64,
            self._n_atoms,
            None,
            self.weights_select,
        )

    self._pm.rmsd = self.rmsd[self._frame_index, 2]