Exemple #1
0
    def add_random(self):
        """
        Creates a new set of variables to reconstruct the dmatpawu

        matrix_i (integers) is a matrix natpawu x ndim with entries are 0 or 1
        matrix_d (deltas) is a matrix natpawu x ndim with entries are [0, 0.5)
        P (matrices) is a set of matrices natpawu x ndim x ndim
        Those three matrices allow to reconstruct the variable 'dmatpawu' used by ABINIT

        :return:
        """
        matrices_defined = []

        matrix_i = self.num_indep_matrices*[None]
        matrix_d = self.num_indep_matrices*[None]
        euler = self.num_indep_matrices*[None]

        for i in range(self.num_indep_matrices):

            nelect = self.num_electrons_dftu[i]
            val = [x for x in list(itertools.product(range(2), repeat=self.ndim)) if sum(x) == nelect]
            ii = val[np.random.randint(len(val))]
            dd = np.zeros(self.ndim)
            matrix_i[i] = list(ii)
            matrix_d[i] = list(dd)
            matrices_defined.append(self.connections[i])
            p = gram_smith_qr(self.ndim)
            euler[i] = gea_all_angles(p)

        data = {'E': euler, 'O': matrix_i, 'D': matrix_d}

        return self.new_entry(data), None
Exemple #2
0
def dmatpawu2params(dmatpawu, ndim):
    """
    Takes the contents of the variable 'dmatpawu' and return their components as a set of 'occupations', 'deltas'
    and 'euler_angles'
    The Euler angles is a ordered list of angles that can rebuild a rotation matrix 'R'
    The rotation matrix 'R' is ensured to be an element of SO(ndim), ie det(R)=1.
    When the eigenvectors return a matrix with determinant -1 a mirror on the first dimension is applied.
    Such condition has no effect on the physical result of the correlation matrix

    :param dmatpawu: The contents of the variable 'dmatpawu'. A list of number representing N matrices ndim x ndim
    :param ndim: ndim is 5 for 'd' orbitals and 7 for 'f' orbitals
    :return:
    """
    dm = np.array(dmatpawu).reshape((-1, ndim, ndim))
    num_matrices = dm.shape[0]
    eigval = np.array([np.linalg.eigh(x)[0] for x in dm])
    occupations = np.array(np.round(eigval), dtype=int)
    deltas = np.abs(eigval - occupations)
    rotations = np.array([np.linalg.eigh(x)[1] for x in dm])

    mirror = np.eye(ndim)
    mirror[0, 0] = -1

    for i in range(len(rotations)):
        if np.linalg.det(rotations[i]) < 0:
            rotations[i] = np.dot(rotations[i], mirror)

    euler_angles = np.array([list(gea_all_angles(p)) for p in rotations])

    return {'occupations': occupations, 'deltas': deltas, 'euler_angles': euler_angles, 'num_matrices': num_matrices}
Exemple #3
0
    def add_random(self):
        """
        Creates a new set of variables to reconstruct the dmatpawu

        matrix_i (integers) is a matrix natpawu x ndim with entries are 0 or 1
        matrix_d (deltas) is a matrix natpawu x ndim with entries are [0, 0.5)
        P (matrices) is a set of matrices natpawu x ndim x ndim
        Those three matrices allow to reconstruct the variable 'dmatpawu' used by ABINIT

        :return:
        """
        matrices_defined = []

        matrix_i = self.num_indep_matrices * [None]
        matrix_d = self.num_indep_matrices * [None]
        euler = self.num_indep_matrices * [None]

        for i in range(self.num_indep_matrices):
            nelect = self.num_electrons_dftu[i]
            val = [
                x for x in list(
                    itertools.product(list(range(2)), repeat=self.ndim))
                if sum(x) == nelect
            ]
            ii = val[np.random.randint(len(val))]
            dd = np.zeros(self.ndim)
            matrix_i[i] = list(ii)
            matrix_d[i] = list(dd)
            matrices_defined.append(self.connections[i])
            p = gram_smith_qr(self.ndim)
            euler[i] = gea_all_angles(p)

        data = {
            'euler_angles': euler,
            'occupations': matrix_i,
            'deltas': matrix_d,
            'num_matrices': self.num_indep_matrices,
            'ndim': self.ndim
        }

        return self.new_entry(data), None
Exemple #4
0
def dmatpawu2params(dmatpawu, ndim):
    """
    Takes the contents of the variable 'dmatpawu' and return their components as a set of 'occupations', 'deltas'
    and 'euler_angles'
    The Euler angles is a ordered list of angles that can rebuild a rotation matrix 'R'
    The rotation matrix 'R' is ensured to be an element of SO(ndim), ie det(R)=1.
    When the eigenvectors return a matrix with determinant -1 a mirror on the first dimension is applied.
    Such condition has no effect on the physical result of the correlation matrix

    :param dmatpawu: The contents of the variable 'dmatpawu'. A list of number representing N matrices ndim x ndim
    :param ndim: ndim is 5 for 'd' orbitals and 7 for 'f' orbitals
    :return:
    """
    dm = np.array(dmatpawu).reshape((-1, ndim, ndim))
    num_matrices = dm.shape[0]
    eigval = np.array([np.linalg.eigh(x)[0] for x in dm])
    occupations = np.array(np.round(eigval), dtype=int)
    deltas = np.abs(eigval - occupations)
    rotations = np.array([np.linalg.eigh(x)[1] for x in dm])

    mirror = np.eye(ndim)
    mirror[0, 0] = -1

    for i in range(len(rotations)):
        if np.linalg.det(rotations[i]) < 0:
            rotations[i] = np.dot(rotations[i], mirror)

    euler_angles = np.array([list(gea_all_angles(p)) for p in rotations])

    return {
        'occupations': occupations,
        'deltas': deltas,
        'euler_angles': euler_angles,
        'num_matrices': num_matrices,
        'ndim': ndim
    }