<commit_before>"""
Notes on functionals in pyquante2.

  1. I would like for all operations here to be array-scale operations.
     - This means e.g. np.power rather than pow
  2. I would like as few memory copies as possible.
  3. Need to decide how to handle redundant information, i.e.
     - rhoa and rhob when non-spin-polarized
       This might make tracking total density and the zeta (spin polarization)
       worthwhile; the latter could just be zero (or False or None or whatever) 
     - return values from non-spin-polarized calculations.

"""
import numpy as np
def zero_low_density(rho,cut=1e-10):
    rho[rho<cut]=0
    return rho

def xs(rho,alpha=2/3.):
    "Xalpha X functional. alpha is the X-alpha scaling factor"
    fac=-2.25*alpha*np.power(0.75/np.pi,1./3.)
    rho3 = np.power(rho,1./3.)
    fx = fac*rho*rho3
    dfxdna = (4./3.)*fac*rho3
    return fx,dfxdna

def xb88(rho,gam):
    rho13 = pow(rho,1./3.)
    x = np.sqrt(gam)/rho13/rho 
    g = b88_g(x)
    dg = b88_dg(x)
    dfxdrho = (4./3.)*rho13*(g-x*dg)
    dfxdgam = 0.5*dg/np.sqrt(gam)
    fx = rho*rho13*g
    return fx,dfxdrho,dfxdgam

def xpbe(rho,gam):
    kap = 0.804
    mu = 0.449276922095889E-2
    ex0,vx0 = xs(rho)
    rho13 = rho**(1.0/3.0)
    rho43 = rho13*rho
    den = 1.E0+mu*gam/rho43/rho43
    F = 1+kap-kap/den
    ex = ex0*F
    dFdr = -(8./3.)*kap*mu*gam/den/den*rho**(-11./3.)
    vxrho = vx0*F+ex0*dFdr
    dFdg = -kap*mu/rho43/rho43/den/den
    vxgam = ex0*dFdg
    return ex,vxrho,vxgam

def cvwn_vector(rhoa,rhob):
    rho = rhoa+rhob
    zeta=(rhoa-rhob)/rho<commit_msg>b88 functional changed to pointwise<commit_after>"""
Notes on functionals in pyquante2.

  1. I would like for all operations here to be array-scale operations.
     - This means e.g. np.power rather than pow
  2. I would like as few memory copies as possible.
  3. Need to decide how to handle redundant information, i.e.
     - rhoa and rhob when non-spin-polarized
       This might make tracking total density and the zeta (spin polarization)
       worthwhile; the latter could just be zero (or False or None or whatever) 
     - return values from non-spin-polarized calculations.

"""
import numpy as np
def zero_low_density(rho,cut=1e-10):
    rho[rho<cut]=0
    return rho

def xs(rho,alpha=2/3.):
    "Xalpha X functional. alpha is the X-alpha scaling factor"
    fac=-2.25*alpha*np.power(0.75/np.pi,1./3.)
    rho3 = np.power(rho,1./3.)
    fx = fac*rho*rho3
    dfxdna = (4./3.)*fac*rho3
    return fx,dfxdna

def xb88(rho,gam,tol=1e-10):
    rho = zero_low_density(rho)
    fxs = []
    dfxdrhos = []
    dfxdgams = []

    for na,gama in zip(rho,gam):
        fx = dfxdrho = dfxdgam = 0
        if na > tol:
            rho13 = np.power(na,1./3.)
            x = np.sqrt(gama)/rho13/na
            g = b88_g(x)
            dg = b88_dg(x)
            dfxdrho = (4./3.)*rho13*(g-x*dg)
            dfxdgam = 0.5*dg/np.sqrt(gama)
            fx = na*rho13*g
        fxs.append(fx)
        dfxdrhos.append(dfxdrho)
        dfxdgams.append(dfxdgam)
    return np.array(fxs),np.array(dfxdrhos),np.array(dfxdgams)

def xpbe(rho,gam):
    kap = 0.804
    mu = 0.449276922095889E-2
    ex0,vx0 = xs(rho)
    rho13 = rho**(1.0/3.0)
    rho43 = rho13*rho
    den = 1.E0+mu*gam/rho43/rho43
    F = 1+kap-kap/den
    ex = ex0*F
    dFdr = -(8./3.)*kap*mu*gam/den/den*rho**(-11./3.)
    vxrho = vx0*F+ex0*dFdr
    dFdg = -kap*mu/rho43/rho43/den/den
    vxgam = ex0*dFdg
    return ex,vxrho,vxgam

def cvwn_vector(rhoa,rhob):
    rho = rhoa+rhob
    zeta=(rhoa-rhob)/rho
{'fraction_non_alphanumeric': 0.13626126126126126, 'fraction_numerical': 0.05686936936936937, 'mean_word_length': 2.459591041869523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '2107084', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1445, 'n_words': 340}