Example #1
0
def getCube(inp, dv=None, cube_header=None, **kwargs):
  if dv is None:
    dv = inp.dv
  if not cube_header:
    if 'resolution' not in kwargs:
      res = 0.2
    else:
      res = float(kwargs['resolution'])
    if 'margin' not in kwargs:
      margin = 7.0
    else:
      margin = float(kwargs['resolution'])
    cube_header = getCubeGrid(inp, margin, res)

  def getSpace(i):
    coord_min = cube_header[0, 1+i]
    step = cube_header[1+i, 0]
    size = cube_header[1+i, 1+i]
    coord_max = coord_min + (step-1)*size
    return np.linspace(coord_min, coord_max, step)

  coord_axes = [getSpace(i) for i in range(3)]
  X, Y, Z = np.meshgrid(*coord_axes, indexing='ij')
  step = X.shape
  X = X.reshape(X.size)
  Y = Y.reshape(Y.size)
  Z = Z.reshape(Z.size)
  coords = np.array([X,Y,Z]).T
  rho = gp.getRho(inp, coords, new=True, dv=dv)
  rho = rho.reshape(*step)
  cube = qtk.CUBE()
  cube.build(inp.molecule, cube_header, rho)

  return cube
Example #2
0
def coord_rho_sigma(inp, rhoSigma):
    coords = inp.grid.points
    if rhoSigma is None:
        rho = gp.getRho(inp, coords)
        sigma = gp.getSigma(inp, coords)
    else:
        rho, sigma = rhoSigma
    return coords, rho, sigma
Example #3
0
def E_dv(inp, dv):
    dv = inp.normalize(dv)
    coords = inp.grid.points
    dm = outer(dv, dv)
    rho = gp.getRho(inp, coords, dv=dv, new=True)
    sigma = gp.getSigma(inp, coords, dv=dv, new=True)
    dft = inp.setting['dft_setting']
    e_k = np.zeros(len(coords))
    for fraction, kf in dft['K'].iteritems():
        e_k += fraction * xcio.exc(inp, kf, [rho, sigma], False)
    K = inp.grid.integrate(rho * e_k)
    V = trace(dm.dot(inp.ext))
    int_vee_rho = td(dm, inp.vee, axes=([0, 1], [0, 1]))
    U = trace(dm.dot(int_vee_rho)) / 2.
    intc = xcio.exc(inp, dft['C'], [rho, sigma], False)
    intx = xcio.exc(inp, dft['X'], [rho, sigma], False)
    XC = inp.grid.integrate(rho * (intc + intx))
    E = K + V + U + XC
    return E
Example #4
0
def vxc(inp, xcFlag=1, rhoSigma = None, report=True):
  if type(xcFlag) is int:
    if xcFlag not in xc_dict.values():
      qtk.exit("libxc functional id number %d is not valid" % xcFlag)
    else:
      xc_id = xcFlag
  elif type(xcFlag) is str:
    if xcFlag not in xc_dict:
      qtk.exit("libxc functional id %s is not valid" % xcFlag)
    else:
      xc_id = xc_dict[xcFlag]
  if report:
    inp.libxc_report(xc_id, 'vxc')
  coords = inp.grid.points
  if rhoSigma is None:
    rho = gp.getRho(inp, coords)
    sigma = gp.getSigma(inp, coords)
  else:
    rho, sigma = rhoSigma
  return libxc_vxc(rho, sigma, len(coords), xc_id)
Example #5
0
def dE_ddv(inp, coords=None):
    if coords is None:
        coords = inp.grid.points

    # derivative is buggy...

    rho = gp.getRho(inp, coords)
    sigma = gp.getSigma(inp, coords)
    dft = inp.setting['dft_setting']

    dEk_drho = np.zeros(len(coords))
    dEk_dsigma = np.zeros(len(coords))
    Ek = np.zeros(len(coords))
    for fraction, kf in dft['K'].iteritems():
        dEk_drho_f, dEk_dsigma_f = xcio.vxc(inp, kf, [rho, sigma], False)
        dEk_drho += fraction * dEk_drho_f
        dEk_dsigma += fraction * dEk_dsigma_f
        Ek += xcio.exc(inp, kf, [rho, sigma], False)

    dEc_drho, dEc_dsigma = xcio.vxc(inp, dft['C'], [rho, sigma], False)
    dEx_drho, dEx_dsigma = xcio.vxc(inp, dft['X'], [rho, sigma], False)
    #Ec = xcio.exc(inp, dft['C'], [rho, sigma], False)
    #Ex = xcio.exc(inp, dft['X'], [rho, sigma], False)
    dE_drho = dEk_drho + dEc_drho + dEx_drho
    dE_dsigma = dEk_dsigma + dEc_dsigma + dEx_dsigma
    #epsilon = Ek + Ec + Ex

    dE_kxc = np.zeros(len(inp.dv))
    for i in range(len(inp.dv)):
        drho_dci, dsigma_dci = drhoSigma_dc(inp, i)
        rho_dE_dc = dE_drho * drho_dci + dE_dsigma * dsigma_dci
        #E_drho_dc = drho_dci * epsilon
        integrand = rho_dE_dc
        dE_kxc[i] = inp.grid.integrate(integrand)

    vee_rho = td(inp.dm, inp.vee, axes=([0, 1], [0, 1]))
    dE_ee = 2 * vee_rho.dot(inp.dv)
    dE_ext = 2 * inp.ext.dot(inp.dv)
    out = dE_kxc + dE_ee + dE_ext

    return out
Example #6
0
def E(inp, coords=None, **kwargs):
    if coords is None:
        coords = inp.grid.points
    rho = gp.getRho(inp, coords)
    sigma = gp.getSigma(inp, coords)
    dft = inp.setting['dft_setting']
    if 'term' not in kwargs:
        e_k = np.zeros(len(coords))
        for fraction, kf in dft['K'].iteritems():
            e_k += fraction * xcio.exc(inp, kf, [rho, sigma], False)
        K = inp.grid.integrate(rho * e_k)
        V = trace(inp.dm.dot(inp.ext))
        int_vee_rho = td(inp.dm, inp.vee, axes=([0, 1], [0, 1]))
        U = trace(inp.dm.dot(int_vee_rho)) / 2.
        intc = xcio.exc(inp, dft['C'], [rho, sigma], False)
        intx = xcio.exc(inp, dft['X'], [rho, sigma], False)
        XC = inp.grid.integrate(rho * (intc + intx))
        E = K + V + U + XC
    elif kwargs['term'] == 'K':
        e_k = np.zeros(len(coords))
        for fraction, kf in dft['K'].iteritems():
            e_k += fraction * xcio.exc(inp, kf, [rho, sigma], False)
        E = inp.grid.integrate(rho * e_k)
    elif kwargs['term'] == 'vw':
        E = trace(inp.dm.dot(inp.kin))
    elif kwargs['term'] == 'U':
        int_vee_rho = td(inp.dm, inp.vee, axes=([0, 1], [0, 1]))
        E = trace(inp.dm.dot(int_vee_rho)) / 2.
    elif kwargs['term'] == 'V':
        E = trace(inp.dm.dot(inp.ext))
    elif kwargs['term'] == 'X':
        intx = xcio.exc(inp, dft['X'], [rho, sigma], False)
        E = inp.grid.integrate(rho * intx)
    elif kwargs['term'] == 'C':
        intc = xcio.exc(inp, dft['C'], [rho, sigma], False)
        E = inp.grid.integrate(rho * intc)
    elif kwargs['term'] in xc_dict.values() \
    or kwargs['term'] in xc_dict:
        epsilon = xcio.exc(inp, kwargs['term'], [rho, sigma])
        E = inp.grid.integrate(rho * epsilon)
    return E