<commit_before>#!/usr/bin/env python
# File: gen_grid.py
# Author: <NAME> <<EMAIL>>
#

'''
Generate DFT grids and weights, based on the code provided by <NAME> <>
'''


import os
import ctypes
from functools import reduce
import numpy
import pyscf.lib
from pyscf import gto
from pyscf.dft import radi

libdft = pyscf.lib.load_library('libdft')

# Stratmann, Scuseria, Frisch. CPL, 257, 213 (1996), eq.11
def stratmann(g):
    '''Stratmann, Scuseria, Frisch. CPL, 257, 213 (1996)'''
    a = .64 # comment after eq. 14, 
    if isinstance(g, numpy.ndarray):
        ma = g/a
        ma2 = ma * ma
        g1 = (1/16.)*(ma*(35 + ma2*(-35 + ma2*(21 - 5 *ma2))))
        g1[g<=-a] = -1
        g1[g>= a] =  1
        return g1
    else:
        if g <= -a:
            g = -1
        elif g >= a:
            g = 1
        else:
            ma = g/a
            ma2 = ma*ma
            g = (1/16.)*(ma*(35 + ma2*(-35 + ma2*(21 - 5 *ma2))))
        return g

def original_becke(g):
    '''Treutler & Ahlrichs, JCP, 102, 346 (1995)'''
    g = (3 - g*g) * g * .5
    g = (3 - g*g) * g * .5
    g = (3 - g*g) * g * .5
    return g

def gen_atomic_grids(mol, radi_method=radi.gauss_chebeshev, level=3):
    atom_grids_tab = {}
    for atm in mol.basis.keys():
        if atm in mol.grids:
            n_rad, n_ang = mol.grids[atm]
        else:
            chg = gto.mole._charge(atm)
            n_rad = _num_radpt(chg, level)
            n_ang = _num_angpt(chg, level)
        rad, rad_weight = radi_method(n_rad)
        # from FDftGridGenerator::GetAtomGridParams
        # atomic_scale = 1
        # rad *= atomic_scale
        # rad_weight *= atomic_scale

        #TODO: reduce grid size for inner shells, i.e. for inner most
        # radial points, use smaller n_ang
        grid = numpy.empty((n_ang,4))
        libdft.MakeAngularGrid(grid.ctypes.data_as(ctypes.c_void_p),
                               ctypes.c_int(n_ang))
        ang, ang_weight = grid[:,:3], grid[:,3]
        atom_grids_tab[atm] = (rad, rad_weight, ang, ang_weight)
    return atom_grids_tab

def count_girds(mol, atom_grids_tab):
    ngrid = 0
    for ia in range(mol.natm):<commit_msg>fix bug in dft.gen_grid due to the change of Mole.basis<commit_after>#!/usr/bin/env python
# File: gen_grid.py
# Author: <NAME> <<EMAIL>>
#

'''
Generate DFT grids and weights, based on the code provided by <NAME> <>
'''


import os
import ctypes
from functools import reduce
import numpy
import pyscf.lib
from pyscf import gto
from pyscf.dft import radi

libdft = pyscf.lib.load_library('libdft')

# Stratmann, Scuseria, Frisch. CPL, 257, 213 (1996), eq.11
def stratmann(g):
    '''Stratmann, Scuseria, Frisch. CPL, 257, 213 (1996)'''
    a = .64 # comment after eq. 14, 
    if isinstance(g, numpy.ndarray):
        ma = g/a
        ma2 = ma * ma
        g1 = (1/16.)*(ma*(35 + ma2*(-35 + ma2*(21 - 5 *ma2))))
        g1[g<=-a] = -1
        g1[g>= a] =  1
        return g1
    else:
        if g <= -a:
            g = -1
        elif g >= a:
            g = 1
        else:
            ma = g/a
            ma2 = ma*ma
            g = (1/16.)*(ma*(35 + ma2*(-35 + ma2*(21 - 5 *ma2))))
        return g

def original_becke(g):
    '''Treutler & Ahlrichs, JCP, 102, 346 (1995)'''
    g = (3 - g*g) * g * .5
    g = (3 - g*g) * g * .5
    g = (3 - g*g) * g * .5
    return g

def gen_atomic_grids(mol, radi_method=radi.gauss_chebeshev, level=3):
    atom_grids_tab = {}
    for atm in mol._basis.keys():
        if atm in mol.grids:
            n_rad, n_ang = mol.grids[atm]
        else:
            chg = gto.mole._charge(atm)
            n_rad = _num_radpt(chg, level)
            n_ang = _num_angpt(chg, level)
        rad, rad_weight = radi_method(n_rad)
        # from FDftGridGenerator::GetAtomGridParams
        # atomic_scale = 1
        # rad *= atomic_scale
        # rad_weight *= atomic_scale

        #TODO: reduce grid size for inner shells, i.e. for inner most
        # radial points, use smaller n_ang
        grid = numpy.empty((n_ang,4))
        libdft.MakeAngularGrid(grid.ctypes.data_as(ctypes.c_void_p),
                               ctypes.c_int(n_ang))
        ang, ang_weight = grid[:,:3], grid[:,3]
        atom_grids_tab[atm] = (rad, rad_weight, ang, ang_weight)
    return atom_grids_tab

def count_girds(mol, atom_grids_tab):
    ngrid = 0
    for ia in range(mol.natm):
{'fraction_non_alphanumeric': 0.13712451272643889, 'fraction_numerical': 0.038523274478330656, 'mean_word_length': 2.0460893854748603, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4786051', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1651, 'n_words': 428}