Exemplo n.º 1
0
 def diagonalise_mean_field(self, system, ueff, niup, nidown):
     # mean field Hamiltonians.
     HMFU = system.T[0] + numpy.diag(ueff * nidown)
     HMFD = system.T[1] + numpy.diag(ueff * niup)
     (e_up, ev_up) = diagonalise_sorted(HMFU)
     (e_down, ev_down) = diagonalise_sorted(HMFD)
     # Construct new wavefunction given new density.
     self.trial[:, :system.nup] = ev_up[:, :system.nup]
     self.trial[:, system.nup:] = ev_down[:, :system.ndown]
     # Construct corresponding site densities.
     niup = self.density(self.trial[:, :system.nup])
     nidown = self.density(self.trial[:, system.nup:])
     return (niup, nidown, e_up, e_down)
Exemplo n.º 2
0
 def __init__(self, system, cplx, trial, parallel=False, verbose=False):
     if verbose:
         print ("# Parsing free electron input options.")
     init_time = time.time()
     self.name = "free_electron"
     self.type = "free_electron"
     self.initial_wavefunction = trial.get('initial_wavefunction',
                                           'free_electron')
     if verbose:
         print ("# Diagonalising one-body Hamiltonian.")
     (self.eigs_up, self.eigv_up) = diagonalise_sorted(system.T[0])
     (self.eigs_dn, self.eigv_dn) = diagonalise_sorted(system.T[1])
     self.reference = trial.get('reference', None)
     if cplx:
         self.trial_type = complex
     else:
         self.trial_type = float
     self.read_in = trial.get('read_in', None)
     self.psi = numpy.zeros(shape=(system.nbasis, system.nup+system.ndown),
                            dtype=self.trial_type)
     if self.read_in is not None:
         if verbose:
             print ("# Reading trial wavefunction from %s"%(self.read_in))
         try:
             self.psi = numpy.load(self.read_in)
             self.psi = self.psi.astype(self.trial_type)
         except OSError:
             if verbose:
                 print("# Trial wavefunction is not in native numpy form.")
                 print("# Assuming Fortran GHF format.")
             orbitals = read_fortran_complex_numbers(self.read_in)
             tmp = orbitals.reshape((2*system.nbasis, system.ne),
                                    order='F')
             ups = []
             downs = []
             # deal with potential inconsistency in ghf format...
             for (i, c) in enumerate(tmp.T):
                 if all(abs(c[:system.nbasis]) > 1e-10):
                     ups.append(i)
                 else:
                     downs.append(i)
             self.psi[:, :system.nup] = tmp[:system.nbasis, ups]
             self.psi[:, system.nup:] = tmp[system.nbasis:, downs]
     else:
         # I think this is slightly cleaner than using two separate
         # matrices.
         if self.reference is not None:
             self.psi[:, :system.nup] = self.eigv_up[:, self.reference]
             self.psi[:, system.nup:] = self.eigv_dn[:, self.reference]
         else:
             self.psi[:, :system.nup] = self.eigv_up[:, :system.nup]
             self.psi[:, system.nup:] = self.eigv_dn[:, :system.ndown]
     gup = gab(self.psi[:, :system.nup],
                                      self.psi[:, :system.nup]).T
     gdown = gab(self.psi[:, system.nup:],
                                        self.psi[:, system.nup:]).T
     self.G = numpy.array([gup, gdown])
     self.etrial = local_energy(system, self.G)[0].real
     # For interface compatability
     self.coeffs = 1.0
     self.ndets = 1
     self.bp_wfn = trial.get('bp_wfn', None)
     self.error = False
     self.eigs = numpy.append(self.eigs_up, self.eigs_dn)
     self.eigs.sort()
     self.initialisation_time = time.time() - init_time
     if verbose:
         print ("# Finished initialising free electron trial wavefunction.")
Exemplo n.º 3
0
 def random_starting_point(self, nbasis):
     random = numpy.random.random((nbasis, nbasis))
     random = 0.5 * (random + random.T)
     (energies, eigv) = diagonalise_sorted(random)
     return (energies, eigv)
Exemplo n.º 4
0
 def __init__(self, system, cplx, trial, parallel=False, verbose=False):
     if verbose:
         print ("# Parsing multi-determinant trial wavefunction input"
                "options.")
     init_time = time.time()
     self.name = "multi_determinant"
     self.expansion = "multi_determinant"
     self.type = trial.get('type')
     self.ndets = trial.get('ndets', None)
     self.eigs = numpy.array([0.0])
     self.initial_wavefunction = trial.get('initial_wavefunction',
                                           'free_electron')
     self.bp_wfn = trial.get('bp_wfn', 'init')
     if cplx or self.type == 'GHF':
         self.trial_type = complex
     else:
         self.trial_type = float
     if self.type == 'UHF':
         nbasis = system.nbasis
     else:
         nbasis = 2 * system.nbasis
     self.GAB = numpy.zeros(shape=(self.ndets, self.ndets, nbasis, nbasis),
                            dtype=self.trial_type)
     self.weights = numpy.zeros(shape=(self.ndets, self.ndets),
                                dtype=self.trial_type)
     # For debugging purposes.
     if self.type == 'free_electron':
         (self.eigs, self.eigv) = diagonalise_sorted(system.T[0])
         psi = numpy.zeros(shape=(self.ndets, system.nbasis, system.ne))
         psi[:,:system.nup] = self.eigv[:,:system.nup]
         psi[:,system.nup:] = self.eigv[:,:system.ndown]
         self.psi = numpy.array([copy.deepcopy(psi) for i in range(0,self.ndets)])
         self.G = numpy.zeros(2, nbasis, nbasis)
         self.emin = sum(self.eigs[:system.nup]) + sum(self.eigs[:system.ndown])
         self.coeffs = numpy.ones(self.ndets)
     else:
         self.orbital_file = trial.get('orbitals')
         self.coeffs_file = trial.get('coefficients')
         # Store the complex conjugate of the multi-determinant trial
         # wavefunction expansion coefficients for ease later.
         if verbose:
             print ("# Reading wavefunction from %s." % self.coeffs_file)
         self.coeffs = read_fortran_complex_numbers(self.coeffs_file)
         self.psi = numpy.zeros(shape=(self.ndets, nbasis, system.ne),
                                dtype=self.coeffs.dtype)
         orbitals = read_fortran_complex_numbers(self.orbital_file)
         start = 0
         skip = nbasis * system.ne
         end = skip
         for i in range(self.ndets):
             self.psi[i] = orbitals[start:end].reshape((nbasis, system.ne),
                                                       order='F')
             start = end
             end += skip
         self.G = gab_multi_det_full(self.psi, self.psi,
                                     self.coeffs, self.coeffs,
                                     self.GAB, self.weights)
         self.trial = (local_energy_ghf_full(system, self.GAB,
                                             self.weights)[0].real)
     self.error = False
     self.initialisation_time = time.time() - init_time
     if verbose:
         print ("# Finished setting up trial wavefunction.")