Exemplo n.º 1
0
  def __init__(self, molecule, **kwargs):

    if not found:
      qtk.exit("horton module not found.")
    if 'wf_convergence' not in kwargs:
      kwargs['wf_convergence'] = 1e-06
    GaussianBasisInput.__init__(self, molecule, **kwargs)
    self.setting.update(kwargs)
    self.backup()

    mol = IOData(coordinates=molecule.R, numbers=molecule.Z)
    obasis = get_gobasis(mol.coordinates, mol.numbers,
                         self.setting['basis_set'])
    grid = BeckeMolGrid(mol.coordinates, mol.numbers, 
                        mol.pseudo_numbers)

    # Create a linalg factory
    lf = DenseLinalgFactory(obasis.nbasis)
    
    # Compute Gaussian integrals
    olp = obasis.compute_overlap(lf)
    kin = obasis.compute_kinetic(lf)
    na = obasis.compute_nuclear_attraction(mol.coordinates, 
                                           mol.pseudo_numbers, lf)
    er = obasis.compute_electron_repulsion(lf)

    # Create alpha orbitals
    exp_alpha = lf.create_expansion()
    
    # Initial guess
    guess_core_hamiltonian(olp, kin, na, exp_alpha)

    external = {'nn': compute_nucnuc(mol.coordinates, 
                                     mol.pseudo_numbers)}
    libxc_term = RLibXCHybridGGA('xc_b3lyp')
    terms = [
        #RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RGridGroup(obasis, grid, [libxc_term]),
        RExchangeTerm(er, 'x_hf', libxc_term.get_exx_fraction()),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)

    self.ht_mol = mol
    self.ht_grid = grid
    self.ht_external = external
    self.ht_obasis = obasis
    self.ht_lf = lf
    self.ht_olp = olp
    self.ht_kin = kin
    self.ht_na = na
    self.ht_er = er
    self.ht_exp_alpha = exp_alpha
    self.ht_ham = ham
Exemplo n.º 2
0
 def __init__(self, molecule, **kwargs):
     GaussianBasisInput.__init__(self, molecule, **kwargs)
     self.setting.update(kwargs)
     self.backup()
     if 'gaussian_setting' not in self.setting:
         gaussian_setting = [
             '6d 10f',
             'nosymm',
             'Scf(maxcycle=1000,verytight)',
             'int(grid=ultrafine)',
             'IOp(2/12=3)',  # allow atoms to be too near
             'force',
         ]
         self.setting['gaussian_setting'] = gaussian_setting
Exemplo n.º 3
0
 def __init__(self, molecule, **kwargs):
   GaussianBasisInput.__init__(self, molecule, **kwargs)
   self.setting.update(kwargs)
   self.backup()
   if 'gaussian_setting' not in self.setting:
     gaussian_setting = [
       '6d 10f',
       'nosymm',
       'Scf(maxcycle=1000,verytight)',
       'int(grid=ultrafine)',
       'IOp(2/12=3)', # allow atoms to be too near
       'force',
     ]
     self.setting['gaussian_setting'] = gaussian_setting
Exemplo n.º 4
0
    def __init__(self, molecule, **kwargs):
        if not ht_found:
            qtk.exit("horton module not found.")
        if not ps_found:
            qtk.exit("pyscf module not found.")
        if not xc_found:
            print xcpath
            print xc_found
            qtk.exit("libxc not found.")
        if 'wf_convergence' not in kwargs:
            kwargs['wf_convergence'] = 1e-06

        if 'kinetic_functional' not in kwargs:
            kwargs['kinetic_functional'] = 'LLP'

        if 'aufbau' in kwargs and kwargs['aufbau']:
            self.aufbau = True
            self.orbitals = []
        else:
            self.aufbau = False

        GaussianBasisInput.__init__(self, molecule, **kwargs)
        self.setting.update(kwargs)
        self.backup()

        if 'dft_setting' not in kwargs:
            if not self.aufbau:
                kf = self.setting['kinetic_functional']
                if kf == 'LLP':
                    self.setting['dft_setting'] = {
                        'K': {
                            1.0: 'XC_GGA_K_LLP'
                        },
                    }
            else:
                self.setting['dft_setting'] = {'K': {1.0: 'XC_GGA_K_VW'}}

            ss = self.setting['theory']
            sdft = self.setting['dft_setting']
            if ss == 'pbe':
                sdft['X'] = 'XC_GGA_X_PBE'
                sdft['C'] = 'XC_GGA_C_PBE'
            elif ss == 'blyp':
                sdft['X'] = 'XC_GGA_X_B88'
                sdft['C'] = 'XC_GGA_C_LYP'

        dft = self.setting['dft_setting']
        for k, v in dft.iteritems():
            if type(dft[k]) is str:
                dft[k] = xc_dict[v]
            elif type(dft[k]) is dict:
                for key, value in dft[k].iteritems():
                    if type(value) is str:
                        dft[k][key] = xc_dict[value]

        mol_str = []
        for i in range(molecule.N):
            atm_str = [molecule.type_list[i]]
            for j in range(3):
                atm_str.append(str(molecule.R[i, j]))
            mol_str.append(' '.join(atm_str))
        mol_str = '; '.join(mol_str)

        mol = gto.Mole()
        mol.build(atom=mol_str, basis=self.setting['basis_set'])
        ig = ps.scf.hf.get_init_guess(mol, key='atom')
        ovl = mol.intor_symmetric("cint1e_ovlp_sph")
        kin = mol.intor_symmetric("cint1e_kin_sph")
        ext = mol.intor_symmetric("cint1e_nuc_sph")
        # 4D array, can be contracted by numpy.tensordot (td)
        # nao x nao integrated density Coulomb kernel can be computed via
        # int_vee_rho = td(dm, vee, axes=([0,1], [0,1]))
        # the final electron-electron cam be computed via
        # Vee = 0.5 * trace(dm, int_vee_rho)
        nao = mol.nao_nr()
        vee = mol.intor(
            "cint2e_sph",
            comp=1,
            hermi=1,
        ).reshape(nao, nao, nao, nao)

        coord = np.array(np.atleast_2d(molecule.R * 1.8897261245650618))
        grid = BeckeMolGrid(coord, molecule.Z.astype(int), molecule.Z)

        self.molecule = molecule
        self.mol = mol
        self.ovl = ovl
        self.kin = kin
        self.ext = ext
        self.vee = vee
        self.nao = nao
        self.dv = self.normalize(sqrt(diag(ig)))
        self.initial_guess = copy.deepcopy(self.dv)
        self.ig = ig
        self.grid = grid
        self.update(self.dv)
        self.old_deltadv = None
        self.new_deltadv = None
        self.old_E = None
        self.dv_list = []
        self.psi_list = []
        self.dpsi_list = []

        self.optimizers = {
            'tnc': opt.fmin_tnc,
            'ncg': opt.fmin_ncg,
            'cg': opt.fmin_cg,
            'bfgs': opt.fmin_bfgs,
            'l_bfgs_b': opt.fmin_l_bfgs_b,
            'simplex': opt.fmin,
        }
        self.optimizer_settings = {
            'tnc': {
                'xtol': 0.0,
                'pgtol': 0.0,
                'maxfun': 1000
            },
            'simplex': {
                'xtol': 1E-10,
                'ftol': 1E-10,
                'maxfun': 1000
            },
        }

        self.orbitals = []
Exemplo n.º 5
0
    def __init__(self, molecule, **kwargs):

        inp.ht = ht

        if 'theory' not in kwargs:
            kwargs['theory'] = 'hf'

        if 'save_c_type' not in kwargs:
            kwargs['save_c_type'] = True

        if not found:
            qtk.exit("horton module not found.")
        if 'wf_convergence' not in kwargs:
            kwargs['wf_convergence'] = 1e-06

        if 'cholesky' not in kwargs:
            kwargs['cholesky'] = True

        GaussianBasisInput.__init__(self, molecule, **kwargs)
        self.setting.update(kwargs)
        self.backup()

        coord = molecule.R * qtk.setting.a2b

        mol = IOData(coordinates=coord, numbers=molecule.Z)
        obasis = get_gobasis(mol.coordinates, mol.numbers,
                             self.setting['basis_set'])
        grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers)

        olp = obasis.compute_overlap()
        kin = obasis.compute_kinetic()
        na = obasis.compute_nuclear_attraction(mol.coordinates,
                                               mol.pseudo_numbers)
        if self.setting['cholesky']:
            er = obasis.compute_electron_repulsion_cholesky()
        else:
            er = obasis.compute_electron_repulsion()

        exp_alpha = orb_alpha = Orbitals(obasis.nbasis)

        # Initial guess
        guess_core_hamiltonian(olp, kin + na, exp_alpha)

        external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
        theory = self.setting['theory']
        if theory in xc_info.xc_map:
            self.xc = xc_info.xc_map[theory]
        else:
            self.xc = None

        terms = [
            RTwoIndexTerm(kin, 'kin'),
            RTwoIndexTerm(na, 'ne'),
            RDirectTerm(er, 'hartree'),
        ]
        if self.setting['theory'] == 'hf':
            terms.append(RExchangeTerm(er, 'x_hf'))
        elif self.setting['theory'] == 'pbe':
            libxc_terms = [
                RLibXCGGA('x_pbe'),
                RLibXCGGA('c_pbe'),
            ]
            terms.append(RGridGroup(obasis, grid, libxc_terms))
        elif self.setting['theory'] == 'blyp':
            libxc_terms = [
                RLibXCGGA('x_b88'),
                RLibXCGGA('c_lyp'),
            ]
            terms.append(RGridGroup(obasis, grid, libxc_terms))
        elif self.setting['theory'] == 'pbe0':
            hyb_term = RLibXCHybridGGA('xc_pbeh')
            terms.append(RGridGroup(obasis, grid, [hyb_term]))
            terms.append(RExchangeTerm(er, 'x_hf',
                                       hyb_term.get_exx_fraction()))
        elif self.setting['theory'] == 'b3lyp':
            hyb_term = RLibXCHybridGGA('xc_b3lyp')
            terms.append(RGridGroup(obasis, grid, [hyb_term]))
            terms.append(RExchangeTerm(er, 'x_hf',
                                       hyb_term.get_exx_fraction()))
        elif self.setting['theory'] == 'hse06':
            hyb_term = RLibXCHybridGGA('xc_hse06')
            terms.append(RGridGroup(obasis, grid, [hyb_term]))
            terms.append(RExchangeTerm(er, 'x_hf',
                                       hyb_term.get_exx_fraction()))
        elif self.setting['theory'] == 'tpss':
            libxc_terms = [
                RLibXCMGGA('x_tpss'),
                RLibXCMGGA('c_tpss'),
            ]
            terms.append(RGridGroup(obasis, grid, libxc_terms))
        elif self.setting['theory'] == 'm05':
            hyb_term = RLibXCHybridMGGA('xc_m05')
            terms.append(RGridGroup(obasis, grid, [hyb_term]))
            terms.append(RExchangeTerm(er, 'x_hf',
                                       hyb_term.get_exx_fraction()))
        ham = REffHam(terms, external)

        occ_model = AufbauOccModel(
            int((sum(self.molecule.Z) - self.molecule.charge) / 2.))
        occ_model.assign(orb_alpha)

        occ = np.zeros(olp.shape[0])
        N = int(sum(self.molecule.Z) - self.molecule.charge)
        occ[:N / 2] = 1
        C = copy.deepcopy(exp_alpha.coeffs.__array__())
        dm = (C * occ).dot(C.T)

        if self.setting['save_c_type']:
            self.ht_mol = mol
            self.ht_grid = grid
            self.grid = grid
            self.ht_external = external
            self.ht_obasis = obasis
            self.ht_occ_model = occ_model
            self.ht_olp = olp
            self.ht_kin = kin
            self.ht_na = na
            self.ht_er = er
            self.ht_exp_alpha = exp_alpha
            self.ht_dm_alpha = exp_alpha.to_dm()
            self.ht_terms = terms
            self.ht_ham = ham
        else:
            self.grid_points = grid.points
            self.grid_weights = grid.weights

        self.olp = olp.__array__()
        self.S = self.olp
        self.kin = kin.__array__()
        self.T = self.kin
        self.nn = external['nn']
        try:
            d, U = np.linalg.eigh(self.olp)
            self.X = U.dot(np.diag(np.sqrt(1 / d)).dot(U.T))
        except Exception as err:
            qtk.warning(err)
        self.na = na.__array__()
        self.er = er.__array__()
        self.U = self.er
        self.mov = exp_alpha.coeffs.__array__()
        self.initial_mov = C
        self.initial_dm = dm
        self.occ = occ
        self.occupation = 2 * occ
        self.v_ext = self.na
Exemplo n.º 6
0
 def __init__(self, molecule, **kwargs):
   if 'wf_convergence' not in kwargs:
     kwargs['wf_convergence'] = 1e-06
   GaussianBasisInput.__init__(self, molecule, **kwargs)
   self.setting.update(kwargs)
   self.backup()
Exemplo n.º 7
0
 def __init__(self, molecule, **kwargs):
     if 'wf_convergence' not in kwargs:
         kwargs['wf_convergence'] = 1e-06
     GaussianBasisInput.__init__(self, molecule, **kwargs)
     self.setting.update(kwargs)
     self.backup()
Exemplo n.º 8
0
  def __init__(self, molecule, **kwargs):
    if not ht_found:
      qtk.exit("horton module not found.")
    if not ps_found:
      qtk.exit("pyscf module not found.")
    if not xc_found:
      print xcpath
      print xc_found
      qtk.exit("libxc not found.")
    if 'wf_convergence' not in kwargs:
      kwargs['wf_convergence'] = 1e-06

    if 'kinetic_functional' not in kwargs:
      kwargs['kinetic_functional'] = 'LLP'

    if 'aufbau' in kwargs and kwargs['aufbau']:
      self.aufbau = True
      self.orbitals = []
    else:
      self.aufbau = False

    GaussianBasisInput.__init__(self, molecule, **kwargs)
    self.setting.update(kwargs)
    self.backup()

    if 'dft_setting' not in kwargs:
      if not self.aufbau:
        kf = self.setting['kinetic_functional']
        if kf == 'LLP':
          self.setting['dft_setting'] = {
            'K': {1.0: 'XC_GGA_K_LLP'},
          }
      else:
        self.setting['dft_setting'] = {
          'K': {1.0: 'XC_GGA_K_VW'}
        }
        
      ss = self.setting['theory']
      sdft = self.setting['dft_setting']
      if ss == 'pbe':
        sdft['X'] = 'XC_GGA_X_PBE'
        sdft['C'] = 'XC_GGA_C_PBE'
      elif ss == 'blyp':
        sdft['X'] = 'XC_GGA_X_B88'
        sdft['C'] = 'XC_GGA_C_LYP'

    dft = self.setting['dft_setting']
    for k, v in dft.iteritems():
      if type(dft[k]) is str:
        dft[k] = xc_dict[v]
      elif type(dft[k]) is dict:
        for key, value in dft[k].iteritems():
          if type(value) is str:
            dft[k][key] = xc_dict[value]

    mol_str = []
    for i in range(molecule.N):
      atm_str = [molecule.type_list[i]]
      for j in range(3):
         atm_str.append(str(molecule.R[i,j]))
      mol_str.append(' '.join(atm_str))
    mol_str = '; '.join(mol_str)

    mol = gto.Mole()
    mol.build(atom=mol_str, basis=self.setting['basis_set'])
    ig = ps.scf.hf.get_init_guess(mol, key = 'atom')
    ovl = mol.intor_symmetric("cint1e_ovlp_sph")
    kin = mol.intor_symmetric("cint1e_kin_sph")
    ext = mol.intor_symmetric("cint1e_nuc_sph")
    # 4D array, can be contracted by numpy.tensordot (td)
    # nao x nao integrated density Coulomb kernel can be computed via
    # int_vee_rho = td(dm, vee, axes=([0,1], [0,1]))
    # the final electron-electron cam be computed via
    # Vee = 0.5 * trace(dm, int_vee_rho)
    nao = mol.nao_nr()
    vee = mol.intor(
            "cint2e_sph", comp=1, hermi=1,
          ).reshape(nao, nao, nao, nao)

    coord = np.array(np.atleast_2d(molecule.R*1.8897261245650618))
    grid = BeckeMolGrid(coord, molecule.Z.astype(int), molecule.Z)

    self.molecule = molecule
    self.mol = mol
    self.ovl = ovl
    self.kin = kin
    self.ext = ext
    self.vee = vee
    self.nao = nao
    self.dv = self.normalize(sqrt(diag(ig)))
    self.initial_guess = copy.deepcopy(self.dv)
    self.ig = ig
    self.grid = grid
    self.update(self.dv)
    self.old_deltadv = None
    self.new_deltadv = None
    self.old_E = None
    self.dv_list = []
    self.psi_list = []
    self.dpsi_list = []

    self.optimizers = {
      'tnc': opt.fmin_tnc,
      'ncg': opt.fmin_ncg,
      'cg': opt.fmin_cg,
      'bfgs': opt.fmin_bfgs,
      'l_bfgs_b': opt.fmin_l_bfgs_b,
      'simplex': opt.fmin,
    }
    self.optimizer_settings = {
      'tnc': {'xtol': 0.0, 'pgtol': 0.0, 'maxfun': 1000},
      'simplex': {'xtol': 1E-10, 'ftol': 1E-10, 'maxfun': 1000},
    }

    self.orbitals = []