def rdm_spinsum(self, sum_rdm1: bool=True, sum_rdm2: bool=True) -> tuple:
    '\n        Given the spin-ful 1- and 2-particle reduced density matrices, compute the spin-free RDMs by spin summation.\n\n        Parameters\n        ----------\n            sum_rdm1, sum_rdm2 :\n               If set to true, perform spin summation on rdm1, rdm2\n\n        Returns\n        -------\n            rdm1_spinsum, rdm2_spinsum :\n                The desired spin-free matrices\n        '
    n_MOs = self.n_orbitals
    rdm1_spinsum = None
    rdm2_spinsum = None
    if sum_rdm1:
        if (self._rdm1 is None):
            raise TequilaException('The spin-RDM for the 1-RDM does not exist!')
        if (self._rdm1.shape[0] != (2 * n_MOs)):
            raise TequilaException('The existing RDM needs to be in spin-orbital basis, it is already spin-free!')
        rdm1_spinsum = numpy.zeros([n_MOs, n_MOs])
        for p in range(n_MOs):
            for q in range((p + 1)):
                rdm1_spinsum[(p, q)] += self._rdm1[((2 * p), (2 * q))]
                rdm1_spinsum[(p, q)] += self._rdm1[(((2 * p) + 1), ((2 * q) + 1))]
        for p in range(n_MOs):
            for q in range(p):
                rdm1_spinsum[(q, p)] = rdm1_spinsum[(p, q)]
    if sum_rdm2:
        if (self._rdm2 is None):
            raise TequilaException('The spin-RDM for the 2-RDM does not exist!')
        if (self._rdm2.shape[0] != (2 * n_MOs)):
            raise TequilaException('The existing RDM needs to be in spin-orbital basis, it is already spin-free!')
        rdm2_spinsum = numpy.zeros([n_MOs, n_MOs, n_MOs, n_MOs])
        for (p, q, r, s) in product(range(n_MOs), repeat=4):
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[((2 * p), (2 * q), (2 * r), (2 * s))]
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[(((2 * p) + 1), (2 * q), ((2 * r) + 1), (2 * s))]
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[((2 * p), ((2 * q) + 1), (2 * r), ((2 * s) + 1))]
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[(((2 * p) + 1), ((2 * q) + 1), ((2 * r) + 1), ((2 * s) + 1))]
    return (rdm1_spinsum, rdm2_spinsum)
Given the spin-ful 1- and 2-particle reduced density matrices, compute the spin-free RDMs by spin summation.

Parameters
----------
    sum_rdm1, sum_rdm2 :
       If set to true, perform spin summation on rdm1, rdm2

Returns
-------
    rdm1_spinsum, rdm2_spinsum :
        The desired spin-free matrices
def rdm_spinsum(self, sum_rdm1: bool=True, sum_rdm2: bool=True) -> tuple:
    '\n        Given the spin-ful 1- and 2-particle reduced density matrices, compute the spin-free RDMs by spin summation.\n\n        Parameters\n        ----------\n            sum_rdm1, sum_rdm2 :\n               If set to true, perform spin summation on rdm1, rdm2\n\n        Returns\n        -------\n            rdm1_spinsum, rdm2_spinsum :\n                The desired spin-free matrices\n        '
    n_MOs = self.n_orbitals
    rdm1_spinsum = None
    rdm2_spinsum = None
    if sum_rdm1:
        if (self._rdm1 is None):
            raise TequilaException('The spin-RDM for the 1-RDM does not exist!')
        if (self._rdm1.shape[0] != (2 * n_MOs)):
            raise TequilaException('The existing RDM needs to be in spin-orbital basis, it is already spin-free!')
        rdm1_spinsum = numpy.zeros([n_MOs, n_MOs])
        for p in range(n_MOs):
            for q in range((p + 1)):
                rdm1_spinsum[(p, q)] += self._rdm1[((2 * p), (2 * q))]
                rdm1_spinsum[(p, q)] += self._rdm1[(((2 * p) + 1), ((2 * q) + 1))]
        for p in range(n_MOs):
            for q in range(p):
                rdm1_spinsum[(q, p)] = rdm1_spinsum[(p, q)]
    if sum_rdm2:
        if (self._rdm2 is None):
            raise TequilaException('The spin-RDM for the 2-RDM does not exist!')
        if (self._rdm2.shape[0] != (2 * n_MOs)):
            raise TequilaException('The existing RDM needs to be in spin-orbital basis, it is already spin-free!')
        rdm2_spinsum = numpy.zeros([n_MOs, n_MOs, n_MOs, n_MOs])
        for (p, q, r, s) in product(range(n_MOs), repeat=4):
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[((2 * p), (2 * q), (2 * r), (2 * s))]
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[(((2 * p) + 1), (2 * q), ((2 * r) + 1), (2 * s))]
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[((2 * p), ((2 * q) + 1), (2 * r), ((2 * s) + 1))]
            rdm2_spinsum[(p, q, r, s)] += self._rdm2[(((2 * p) + 1), ((2 * q) + 1), ((2 * r) + 1), ((2 * s) + 1))]
    return (rdm1_spinsum, rdm2_spinsum)