Example #1
0
def main():
    args = parse_args()

    fn_h5, grp_name = parse_h5(args.output, 'output')
    # check if the group is already present (and not empty) in the output file
    if check_output(fn_h5, grp_name, args.overwrite):
        return

    # Load the system
    sys = System.from_file(args.wfn)

    # Define a list of optional arguments for the WPartClass:
    WPartClass = wpart_schemes[args.scheme]
    kwargs = dict((key, val) for key, val in vars(args).iteritems() if key in WPartClass.options)

    # Load the proatomdb
    if args.atoms is not None:
        proatomdb = ProAtomDB.from_file(args.atoms)
        proatomdb.normalize()
        kwargs['proatomdb'] = proatomdb
    else:
        proatomdb = None

    # Run the partitioning
    agspec = AtomicGridSpec(args.grid)
    molgrid = BeckeMolGrid(sys, agspec, mode='only')
    sys.update_grid(molgrid) # for the grid to be written to the output
    wpart = wpart_schemes[args.scheme](sys, molgrid, **kwargs)
    names = wpart.do_all()

    write_part_output(fn_h5, grp_name, wpart, names, args)
Example #2
0
    def getBeckeGrid(self, resolution='fine', new=False, **kwargs):
        """
    coarse, medium, fine, veryfine, ultrafine and insane
    """
        if not hasattr(self, 'molecule'):
            qtk.exit("no molecule structure found")
        if new or not hasattr(self, 'grid'):
            molecule = self.molecule
            coord = np.array(np.atleast_2d(molecule.R * 1.8897261245650618))
            self.grid = BeckeMolGrid(coord, molecule.Z.astype(int), molecule.Z,
                                     resolution)

            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)

            if 'gto_kwargs' in kwargs:
                mol = gto.Mole(**kwargs['gto_kwargs'])
            else:
                mol = gto.Mole()

            #mol.build(atom=mol_str, basis=self.setting['basis_set'])
            if hasattr(self, 'basis_name'):
                basis = self.basis_name
            self.basisFormat()
            mol.build(atom=mol_str, basis=self.pybasis)
            self.mol = mol
            del_list = ['_phi', '_psi', '_dphi', '_dpsi', '_rho', '_drho']
            for p in del_list:
                if hasattr(self, p):
                    delattr(self, p)
Example #3
0
 def from_molecule(cls, mol, scheme=None, grid=None, spin="ab", **kwargs):
     if grid is None:
         grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers,
                             agspec="fine", random_rotate=False, mode='keep')
     else:
         check_molecule_grid(mol, grid)
     # compute molecular electron density
     dens = mol.compute_density(grid.points, spin=spin)
     if mol.pesudo_numbers is None:
         pesudo_numbers = mol.numbers
     else:
         pesudo_numbers = mol.pesudo_numbers
     return cls(mol.coordinates, mol.numbers, pesudo_numbers, dens, grid, scheme, **kwargs)
Example #4
0
def main():
    args = parse_args()

    fn_h5, grp_name = parse_h5(args.output, 'output')
    # check if the group is already present (and not empty) in the output file
    if check_output(fn_h5, grp_name, args.overwrite):
        return

    # Load the system
    mol = IOData.from_file(args.wfn)

    # Define a list of optional arguments for the WPartClass:
    WPartClass = wpart_schemes[args.scheme]
    kwargs = dict((key, val) for key, val in vars(args).iteritems()
                  if key in WPartClass.options)

    # Load the proatomdb
    if args.atoms is not None:
        proatomdb = ProAtomDB.from_file(args.atoms)
        proatomdb.normalize()
        kwargs['proatomdb'] = proatomdb
    else:
        proatomdb = None

    # Run the partitioning
    agspec = AtomicGridSpec(args.grid)
    grid = BeckeMolGrid(mol.coordinates,
                        mol.numbers,
                        mol.pseudo_numbers,
                        agspec,
                        mode='only')
    dm_full = mol.get_dm_full()
    moldens = mol.obasis.compute_grid_density_dm(dm_full,
                                                 grid.points,
                                                 epsilon=args.epsilon)
    dm_spin = mol.get_dm_spin()
    if dm_spin is not None:
        kwargs['spindens'] = mol.obasis.compute_grid_density_dm(
            dm_spin, grid.points, epsilon=args.epsilon)
    wpart = wpart_schemes[args.scheme](mol.coordinates, mol.numbers,
                                       mol.pseudo_numbers, grid, moldens,
                                       **kwargs)
    keys = wpart.do_all()

    if args.slow:
        # ugly hack for the slow analysis involving the AIM overlap operators.
        wpart_slow_analysis(wpart, mol)
        keys = list(wpart.cache.iterkeys(tags='o'))

    write_part_output(fn_h5, grp_name, wpart, keys, args)
Example #5
0
    def __init__(self,
                 coordinates,
                 numbers,
                 pseudo_numbers,
                 specs='medium',
                 k=3,
                 rotate=False):
        """Initialize class.

        Parameters
        ----------
        coordinates : np.ndarray, shape=(M, 3)
            Cartesian coordinates of `M` atoms in the molecule.
        numbers : np.ndarray, shape=(M,)
            Atomic number of `M` atoms in the molecule.
        pseudo_numbers : np.ndarray, shape=(M,)
            Pseudo-number of `M` atoms in the molecule.
        specs : str, optional
            Specification of grid. Either choose from ['coarse', 'medium', 'fine', 'veryfine',
            'ultrafine', 'insane'] or provide a string of 'rname:rmin:rmax:nrad:nang' format.
            Here 'rname' denotes the type of radial grid and can be chosen from ['linear', 'exp',
            'power'], 'rmin' and 'rmax' specify the first and last radial grid points in angstrom,
            'nrad' specify the number of radial grid points, and 'nang' specify the number of
            angular Lebedev-Laikov grid. The 'nang' can be chosen from (6, 14, 26, 38, 50, 74, 86,
            110, 146, 170, 194, 230, 266, 302, 350, 434, 590, 770, 974, 1202, 1454, 1730, 2030,
            2354, 2702, 3074, 3470, 3890, 4334, 4802, 5294, 5810).
        k : int, optional
            The order of the switching function in Becke's weighting scheme.
        rotate : bool, optional
            Whether to randomly rotate spherical grids.

        """
        self._coordinates = coordinates
        self._numbers = numbers
        self._pseudo_numbers = pseudo_numbers
        self._k = k
        self._rotate = rotate
        self.specs = specs

        self._grid = BeckeMolGrid(self.coordinates,
                                  self.numbers,
                                  self.pseudo_numbers,
                                  agspec=self.specs,
                                  k=k,
                                  random_rotate=rotate,
                                  mode='keep')
Example #6
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 = []