class OneParticleGF(object): def __init__(self, cc, eta=0.01): self.cc = cc self.eomip = EOMIP(cc) self.eomea = EOMEA(cc) self.eta = eta def solve_ip(self, ps, qs, omegas): if not isinstance(ps, collections.Iterable): ps = [ps] if not isinstance(qs, collections.Iterable): qs = [qs] cc = self.cc print("solving ip portion") Sw = initial_ip_guess(cc) Sw += np.random.rand(Sw.shape[0]) diag = self.eomip.get_diag() imds = self.eomip.make_imds() e_vector = list() for q in qs: e_vector.append(greens_e_vector_ip_rhf(cc, q)) gfvals = np.zeros((len(ps), len(qs), len(omegas)), dtype=complex) for ip, p in enumerate(ps): print 'gf idx', ip b_vector = greens_b_vector_ip_rhf(cc, p) for iw, omega in enumerate(omegas): invprecond_multiply = lambda x: x / (omega + diag + 1j * self. eta) def matr_multiply(vector, args=None): return greens_func_multiply(self.eomip.matvec, vector, omega + 1j * self.eta, imds) size = len(b_vector) Ax = spla.LinearOperator((size, size), matr_multiply) mx = spla.LinearOperator((size, size), invprecond_multiply) Sw, info = spla.gmres(Ax, b_vector, x0=Sw, tol=1e-14, M=mx) if info != 0: raise RuntimeError for iq, q in enumerate(qs): gfvals[ip, iq, iw] = -np.dot(e_vector[iq], Sw) if len(ps) == 1 and len(qs) == 1: return gfvals[0, 0, :] else: return gfvals def solve_ea(self, ps, qs, omegas): if not isinstance(ps, collections.Iterable): ps = [ps] if not isinstance(qs, collections.Iterable): qs = [qs] cc = self.cc print("solving ea portion") Sw = initial_ea_guess(cc) diag = self.eomea.get_diag() e_vector = list() for p in ps: e_vector.append(greens_e_vector_ea_rhf(cc, p)) gfvals = np.zeros((len(ps), len(qs), len(omegas)), dtype=complex) for iq, q in enumerate(qs): b_vector = greens_b_vector_ea_rhf(cc, q) for iw, omega in enumerate(omegas): invprecond_multiply = lambda x: x / (-omega + diag + 1j * self. eta) def matr_multiply(vector, args=None): return greens_func_multiply(self.eomea.matvec, vector, -omega + 1j * self.eta) size = len(b_vector) Ax = spla.LinearOperator((size, size), matr_multiply) mx = spla.LinearOperator((size, size), invprecond_multiply) Sw, info = spla.gmres(Ax, b_vector, x0=Sw, tol=1e-14, M=mx) for ip, p in enumerate(ps): gfvals[ip, iq, iw] = np.dot(e_vector[ip], Sw) if len(ps) == 1 and len(qs) == 1: return gfvals[0, 0, :] else: return gfvals def kernel(self, p, q, omegas): return self.solve_ip(p, q, omegas) #, self.solve_ea(p, q, omegas)
def __init__(self, cc, eta=0.01): self.cc = cc self.eomip = EOMIP(cc) self.eomea = EOMEA(cc) self.eta = eta
def __init__(self, cc, nvir_act=0): EOMIP.__init__(self, cc) self.nvir_act = nvir_act