Пример #1
0
    def test_load_kernel(self):
        data_ref_nonin = np.loadtxt(dname +
                                    '/water.tddft_iter.omega.pxx.txt-ref')[:,
                                                                           1]
        data_ref_inter = np.loadtxt(
            dname + '/water.tddft_iter.omega.inter.pxx.txt-ref')[:, 1]
        for form in ["txt", "npy", "hdf5"]:
            td = tddft_iter_c(pb.sv,
                              pb,
                              tddft_iter_broadening=1e-2,
                              xc_code='RPA',
                              load_kernel=True,
                              kernel_fname="kernel." + form,
                              kernel_format=form,
                              kernel_path_hdf5="kernel_pack")

            # check nonin
            omegas = np.linspace(0.0, 2.0, 500) + 1j * td.eps
            pxx = td.comp_nonin(omegas).imag
            self.assertTrue(
                np.allclose(data_ref_nonin, pxx, rtol=1.0, atol=1e-05))

            # check inter
            omegas = np.linspace(0.0, 2.0, 150) + 1j * td.eps
            pxx = -td.comp_polariz_xx(omegas).imag
            self.assertTrue(
                np.allclose(data_ref_inter, pxx, rtol=1.0, atol=1e-05))
Пример #2
0
def run_tddft_iter(calculator, label, freq):
    from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
    if label == "siesta":
        sv = system_vars_c().init_siesta_xml()
    elif label == "gpaw":
        sv = system_vars_c().init_gpaw(calculator)
    else:
        raise ValueError("Only siesta or gpaw calculator for the moment!")

    pb = prod_basis_c().init_prod_basis_pp(sv)
    td = tddft_iter_c(pb.sv, pb, tddft_iter_broadening=1e-2)
    omegas = np.linspace(freq[0], freq[freq.shape[0] - 1],
                         freq.shape[0]) + 1j * td.eps

    pxx_nonin = np.zeros(omegas.shape[0], dtype=float)
    pxx_inter = np.zeros(omegas.shape[0], dtype=float)

    vext = np.transpose(td.moms1)
    for iomega, omega in enumerate(omegas):
        pxx_nonin[iomega] = -np.dot(td.apply_rf0(vext[0, :], omega),
                                    vext[0, :]).imag

    pxx_inter = -td.comp_polariz_xx(omegas).imag

    return pxx_nonin, pxx_inter
Пример #3
0
    def test_tddft_iter_lda(self):
        """ Compute polarization with LDA TDDFT  """
        from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
        from pyscf.nao.m_comp_dm import comp_dm
        from timeit import default_timer as timer

        dname = os.path.dirname(os.path.abspath(__file__))
        sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
        pb = prod_basis_c().init_prod_basis_pp(sv, jcutoff=7)
        td = tddft_iter_c(pb.sv,
                          pb,
                          tddft_iter_broadening=1e-2,
                          xc_code='LDA,PZ',
                          level=0)
        omegas = np.linspace(0.0, 2.0, 150) + 1j * td.eps
        pxx = -td.comp_polariz_xx(omegas).imag
        data = np.array([omegas.real * 27.2114, pxx])
        np.savetxt('water.tddft_iter_lda.omega.inter.pxx.txt',
                   data.T,
                   fmt=['%f', '%f'])
        data_ref = np.loadtxt(dname +
                              '/water.tddft_iter_lda.omega.inter.pxx.txt-ref')
        #print('    td.rf0_ncalls ', td.rf0_ncalls)
        #print(' td.matvec_ncalls ', td.matvec_ncalls)
        self.assertTrue(np.allclose(data_ref, data.T, rtol=1.0, atol=1e-05))
Пример #4
0
    def test_tddft_iter(self):
        """ This is iterative TDDFT with SIESTA starting point """
        td = tddft_iter_c(pb.sv, pb)
        self.assertTrue(hasattr(td, 'x'))
        self.assertTrue(
            td.ksn2f.sum() ==
            8.0)  # water: O -- 6 electrons in the valence + H2 -- 2 electrons
        self.assertEqual(td.xocc.shape[0], 4)
        self.assertEqual(td.xvrt.shape[0], 19)

        dn0 = td.apply_rf0(td.moms1[:, 0])
Пример #5
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
import os, unittest, numpy as np
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
import h5py

dname = os.path.dirname(os.path.abspath(__file__))
sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
pb = prod_basis_c().init_prod_basis_pp(sv, jcutoff=7)
td = tddft_iter_c(pb.sv, pb, tddft_iter_broadening=1e-2, xc_code='RPA')

np.savetxt("kernel.txt", td.kernel)
np.save("kernel.npy", td.kernel)

hdf = h5py.File("kernel.hdf5", "w")
hdf.create_dataset("kernel_pack", data=td.kernel)
hdf.close()


class KnowValues(unittest.TestCase):
    def test_non_inter_polariz(self):
        """ This is non-interacting polarizability TDDFT with SIESTA starting point """
        omegas = np.linspace(0.0, 2.0, 500) + 1j * td.eps
        pxx = td.comp_nonin(omegas).imag
        #pxx = np.zeros_like(omegas)
Пример #6
0
from __future__ import print_function, division
import numpy as np
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c

sv = system_vars_c().init_siesta_xml(label='siesta', cd='.', force_gamma=True)
pb = prod_basis_c().init_prod_basis_pp(sv)
td = tddft_iter_c(pb.sv, pb)
omegas = np.linspace(0.0, 0.25, 150) + 1j * td.eps
pxx = -td.comp_polariz_xx(omegas).imag
data = np.array([omegas.real * 27.2114, pxx])
print('    td.rf0_ncalls ', td.rf0_ncalls)
print(' td.matvec_ncalls ', td.matvec_ncalls)
np.savetxt('tddft_iter.omega.inter.pxx.txt', data.T, fmt=['%f', '%f'])
Пример #7
0
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
import numpy as np
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c

sv = system_vars_c().init_siesta_xml(label='siesta', cd='.', force_gamma=True)
pb = prod_basis_c().init_prod_basis_pp(sv)
td = tddft_iter_c(pb.sv, pb)
omegas = np.linspace(0.0,0.25,150)+1j*td.eps
pxx = -td.comp_polariz_xx(omegas).imag
data = np.array([omegas.real*27.2114, pxx])
print('    td.rf0_ncalls ', td.rf0_ncalls)
print(' td.matvec_ncalls ', td.matvec_ncalls)
np.savetxt('tddft_iter.omega.inter.pxx.txt', data.T, fmt=['%f','%f'])