Пример #1
0
 def _spherical_from_cartesian(self):
     '''
     Reduces the dimensionality of the contracted cartesian
     basis to the contracted spherical basis.
     '''
     print('warning: this is not correct')
     lmax = self['L'].cat.as_ordered().max()
     prim_ovl = self.primitive_overlap().square()
     cartprim, ls = self._cartesian_contraction_matrix(l=True)
     contracted = pd.DataFrame(np.dot(np.dot(cartprim.T, prim_ovl), cartprim))
     sh = solid_harmonics(lmax)
     sphtrans = car2sph_transform_matrices(sh, lmax)
     bfns = self.groupby('func')
     lcounts = bfns.apply(lambda y: y['L'].values[0]).value_counts()
     for l, lc in lcounts.items():
         lcounts[l] = lc * spher_lml_count[l] // cart_lml_count[l]
     lc = lcounts.sum()
     spherical = np.zeros((contracted.shape[0], lc), dtype=np.float64)
     ip = 0
     ic = 0
     while ip < lc:
         l = ls[ic]
         if l < 2:
             spherical[:,ic] = contracted[ic]
             ip += 1
             ic += 1
         else:
             cspan = ic + cart_lml_count[l]
             sspan = ip + spher_lml_count[l]
             carts = contracted[list(range(ic, cspan))]
             trans = np.dot(carts, sphtrans[l].T)
             spherical[:,ip:sspan] = trans
             ip += spher_lml_count[l]
             ic += cart_lml_count[l]
     return pd.DataFrame(np.dot(np.dot(spherical.T, contracted), spherical))
Пример #2
0
def gen_string_bfns(universe, kind='spherical'):
    """
    Given an exatomic.container.Universe that contains complete momatrix
    and basis_set attributes, generates and returns the strings corresponding
    to how the basis functions would be written out with paper and pencil.
    This is mainly for debugging and testing generality to deal with different
    computational codes' basis function ordering schemes.

    Args
        universe (exatomic.container.Universe): must contain momatrix and basis_set

    Returns
        bastrs (list): list of strings of basis functions
    """
    lmax = universe.basis_set['L'].cat.as_ordered().max()
    universe.basis_set['N'] = _vec_sloppy_normalize(universe.basis_set['alpha'].values,
                                                    universe.basis_set['L'].values)
    bases = universe.basis_set.groupby('set')
    if hasattr(universe, 'basis_set_order'):
        centers = universe.basis_set_order.groupby('center')
    sh = solid_harmonics(lmax)
    bfns = []
    bastrs = []
    for i, (seht, x, y, z) in enumerate(zip(universe.atom['set'], universe.atom['x'],
                                            universe.atom['y'],   universe.atom['z'])):
        spherical = universe.basis_set_summary.ix[seht].spherical
        xastr = 'x' if np.isclose(x, 0) else 'x - ' + str(x)
        yastr = 'y' if np.isclose(y, 0) else 'y - ' + str(y)
        zastr = 'z' if np.isclose(z, 0) else 'z - ' + str(z)
        nucpos = {'x': xastr, 'y': yastr, 'z': zastr}
        r2str = '(' + xastr + ')**2 + (' + yastr + ')**2 + (' + zastr + ')**2'
        if hasattr(universe, 'basis_set_order'):
            bas = bases.get_group(seht).groupby('L')
            basord = centers.get_group(i + 1)
            for L, ml, shfunc in zip(basord['L'], basord['ml'], basord['shell_function']):
                grp = bas.get_group(L).groupby('shell_function').get_group(shfunc)
                bastr = ''
                prefacs = _gen_prefactor(sh, L, ml, nucpos)
                bastrs.append(_enumerate_primitives_prefacs(prefacs, grp, r2str))
        else:
            bas = bases.get_group(seht).groupby('shell_function')
            for f, grp in bas:
                if len(grp) == 0: continue
                l = grp['L'].values[0]
                if spherical:
                    sym_keys = universe.spherical_gtf_order.symbolic_keys(l)
                    for L, ml in sym_keys:
                        bastr = ''
                        prefacs = _gen_prefactor(sh, L, ml, nucpos)
                        bastrs.append(_enumerate_primitives_prefacs(prefacs, grp, r2str))
                else:
                    subcart = universe.cartesian_gtf_order[universe.cartesian_gtf_order['l'] == l]
                    prefacs = _cartesian_prefactor(l, subcart['x'], subcart['y'], subcart['z'], nucpos)
                    for prefac in prefacs:
                        bastrs.append(_enumerate_primitives_prefacs([prefac], grp, r2str))
    return bastrs