def rotate_coeffs(coeffs, obasis, rmat): '''Apply a rotation to all cartesian basis functions. **Arguments:** coeffs Expansion coefficients of a set of functions (orbitals) in a local basis. shape=(nbasis,nfn) obasis The local basis set object. rmat The rotation matrix. ''' if obasis.nbasis != coeffs.shape[0]: raise TypeError( 'The shape of the coefficients array does not match the basis set size' ) if obasis.shell_types.min() < 0: raise TypeError('Pure functions are not supported in rotate_coeffs.') result = np.zeros(coeffs.shape) # 1) undo the part normalization of the basis functions due to the cartesian powers lmax = obasis.shell_types.max() powers = get_cartesian_powers(lmax) factors = [] for ishell in xrange(obasis.nshell): shell_type = obasis.shell_types[ishell] icart0 = ((shell_type + 2) * (shell_type + 1) * (shell_type)) / 6 shellsize = ((shell_type + 2) * (shell_type + 1)) / 2 for ifn in xrange(shellsize): ipow = icart0 + ifn factors.append( np.sqrt( fac2(2 * powers[ipow, 0] - 1) * fac2(2 * powers[ipow, 1] - 1) * fac2(2 * powers[ipow, 2] - 1))) factors = np.array(factors) # replace the array coeffs by the one with undone normalization coeffs = coeffs / factors.reshape(-1, 1) # 2) the actual rotation ibasis0 = 0 for ishell in xrange(obasis.nshell): shell_type = obasis.shell_types[ishell] icart0 = ((shell_type + 2) * (shell_type + 1) * (shell_type)) / 6 shellsize = ((shell_type + 2) * (shell_type + 1)) / 2 for iorb in xrange(coeffs.shape[1]): result[ibasis0:ibasis0 + shellsize, iorb] = rotate_cartesian_multipole( rmat, coeffs[ibasis0:ibasis0 + shellsize, iorb], 'coeffs') ibasis0 += shellsize # 3) apply the part of the normalization of the basis functions due to the cartesian powers result *= factors.reshape(-1, 1) return result
def rotate_coeffs(coeffs, obasis, rmat): """Apply a rotation to all cartesian basis functions. **Arguments:** coeffs Expansion coefficients of a set of functions (orbitals) in a local basis. shape=(nbasis,nfn) obasis The local basis set object. rmat The rotation matrix. """ if obasis.nbasis != coeffs.shape[0]: raise TypeError("The shape of the coefficients array does not match the basis set size") if obasis.shell_types.min() < 0: raise TypeError("Pure functions are not supported in rotate_coeffs.") result = np.zeros(coeffs.shape) # 1) undo the part normalization of the basis functions due to the cartesian powers lmax = obasis.shell_types.max() powers = get_cartesian_powers(lmax) factors = [] for ishell in xrange(obasis.nshell): shell_type = obasis.shell_types[ishell] icart0 = ((shell_type + 2) * (shell_type + 1) * (shell_type)) / 6 shellsize = ((shell_type + 2) * (shell_type + 1)) / 2 for ifn in xrange(shellsize): ipow = icart0 + ifn factors.append( np.sqrt(fac2(2 * powers[ipow, 0] - 1) * fac2(2 * powers[ipow, 1] - 1) * fac2(2 * powers[ipow, 2] - 1)) ) factors = np.array(factors) # replace the array coeffs by the one with undone normalization coeffs = coeffs / factors.reshape(-1, 1) # 2) the actual rotation ibasis0 = 0 for ishell in xrange(obasis.nshell): shell_type = obasis.shell_types[ishell] icart0 = ((shell_type + 2) * (shell_type + 1) * (shell_type)) / 6 shellsize = ((shell_type + 2) * (shell_type + 1)) / 2 for iorb in xrange(coeffs.shape[1]): result[ibasis0 : ibasis0 + shellsize, iorb] = rotate_cartesian_multipole( rmat, coeffs[ibasis0 : ibasis0 + shellsize, iorb], "coeffs" ) ibasis0 += shellsize # 3) apply the part of the normalization of the basis functions due to the cartesian powers result *= factors.reshape(-1, 1) return result
def get_point_moments(coordinates, rmat=None, lmax=4): if rmat is None: rmat = np.identity(3, float) cartesian_powers = get_cartesian_powers(lmax) ncart = cartesian_powers.shape[0] result = np.zeros(ncart) for i in xrange(len(coordinates)): vec = np.dot(rmat, coordinates[i]) for j in xrange(ncart): px, py, pz = cartesian_powers[j] result[j] += vec[0]**px * vec[1]**py * vec[2]**pz return result
def get_pentagon_moments(rmat=None, lmax=4): if rmat is None: rmat = np.identity(3, float) cartesian_powers = get_cartesian_powers(lmax) ncart = cartesian_powers.shape[0] result = np.zeros(ncart) for i in xrange(6): alpha = 2.0*np.pi/5.0 vec = np.array([1+np.cos(alpha), np.sin(alpha), 0]) vec = np.dot(rmat, vec) for j in xrange(ncart): px, py, pz = cartesian_powers[j] result[j] += vec[0]**px * vec[1]**py * vec[2]**pz return result