from orbkit.test.tools import equal import os, inspect tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) options.quiet = True ## N2 cc-pVDZ RHF folder = os.path.join(tests_home, '../outputs_for_testing/molpro') qc = read.main_read(os.path.join(folder, 'n2.mold'), all_mo=True) ao = integrals.AOIntegrals(qc) Nelec = int(abs(qc.get_charge(nuclear=False))) # MO overlap S = ao.overlap(asMO=1) equal(S, numpy.eye(ao.Norb)) # calculate Hartree-Fock energy from AOs Hcore = ao.Hcore(asMO=0) Vee = ao.Vee(asMO=0) Vnn = qc.nuclear_repulsion P = 2*numpy.dot(qc.mo_spec.coeffs[:Nelec//2,:].T, qc.mo_spec.coeffs[:Nelec//2,:]) G = P[None,None,:,:]*Vee - numpy.swapaxes(0.5*P.T[None,:,:,None]*Vee, 1, 3) G = numpy.sum(G, axis=(2, 3)) F = Hcore + G E = 0.5*numpy.tensordot(P, Hcore+F, axes=2) equal(E+Vnn, -108.92022806) # calculate Hartree-Fock energy from MOs
filepath = os.path.join(folder, 'NaCl_molden_files.tar.gz') mult.read(filepath, all_mo=True, nosym=False) index_list, mo_overlap = mult.order_using_analytical_overlap(None) ref_index_list = numpy.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 ]) ref_mo_overlap = numpy.array([ 4.13745151e-01, 2.15209531e-03, 2.40850414e-01, -2.07815132e-01, 3.90468693e-04, 4.71516377e-07, -6.04865743e-02, -9.27526663e-02, 1.62857101e-03, -1.00590028e-02, 2.73144332e-04, 1.63299615e-03, -5.18414926e-12, 1.13089955e-02, 1.47904182e-03, 3.64802085e-03, 1.27676532e-02, 4.83763397e-03, 4.16172762e-13, 2.08800853e-02, -2.39703107e-13, -7.54349302e-03, 1.33143892e-02, 1.45756792e-02, 6.67309109e-13, -6.82625732e-03, -3.67718123e-03, 3.15176712e-02, 3.93694019e-13, 2.66813819e-02, 4.84897659e-13, 2.77389964e-02, -2.56704784e-03, 1.08086793e-02, 1.31446440e-13, -7.66053565e-03, 3.45599160e-02, -5.70839661e-14, 2.12447532e-02, 7.70203986e-02, 6.44096989e-03, -3.66681252e-02, 1.53864579e-13, 3.26282367e-02, 1.43079111e-14, 1.94622960e-03, -1.21481229e-01, 6.01625651e-02, -5.28532595e-02, -8.08826853e-02, -9.41869139e-02, -1.09207539e-01 ]) equal(numpy.array(index_list[0][0]), ref_index_list) equal(numpy.array(mo_overlap[0][0][0]), ref_mo_overlap)
slice_length=slice_length, numproc=numproc)) j_01.append( detci.ci_core.jab(zero, sing, molist, molistdrv, slice_length=slice_length, numproc=numproc)) nabla_j_01.append( -numpy.sum(detci.ci_core.jab(zero, sing, molist, molistdrv2, slice_length=slice_length, numproc=numproc), axis=0)) # Sum over the three components mu_01.append(detci.ci_core.mu(ci[a], ci[b], qc, zero, sing, omr, omv)) filepath = os.path.join(tests_home, 'refdata_h3+.npz') #numpy.savez('refdata_h3+.npz', rho_01=rho_01, j_01=j_01, nabla_j_01=nabla_j_01, mu_01=mu_01) refdata = numpy.load(filepath) equal(rho_01, refdata['rho_01']) equal(j_01, refdata['j_01']) equal(nabla_j_01, refdata['nabla_j_01']) equal(mu_01, refdata['mu_01'])
'psi4_molden': [0., 0., -0.386892149961], } for fname in files: skip = False if fname == 'cclib': try: __import__(fname) except ImportError: skip = True if not skip: qcinfo = readers[fname](os.path.join(folder, files[fname]), cclib_parser='Gaussian', all_mo=True) assert qcinfo.ao_spec.get_ao_num() == qcinfo.mo_spec.get_coeffs( ).shape[1] e_list = numpy.zeros(4, dtype=float) coeffs_list = numpy.zeros(4, dtype=float) contrac_list = numpy.zeros(4, dtype=float) geo_list = qcinfo.geo_spec[0] for i in range(4): e_list[i] = qcinfo.mo_spec[i]['energy'] coeffs_list[i] = qcinfo.ao_spec[i]['coeffs'][0, 0] contrac_list[i] = qcinfo.ao_spec[i]['coeffs'][0, 1] for ref in [[e_list, refeigen], [coeffs_list, refexp], [contrac_list, refcontrac], [geo_list, refgeo]]: if fname in ref[1].keys(): equal(ref[0], ref[1][fname])
all_mo=True, spin=None, i_md=0, interactive=False) # Extend the beta input file qc_b = read.main_read(fid, itype=ok_opt[j], all_mo=True, spin=None, i_md=1, interactive=False) qc.mo_spec.extend(qc_b.mo_spec) qc.mo_spec.update() else: qc = read.main_read(fid, itype=ok_opt[j], interactive=False, all_mo=True, cclib_parser='Gaussian') ao_overlap_matrix = ai.get_ao_overlap(qc.geo_spec, qc.geo_spec, qc.ao_spec) # Loop over spin if unrestricted for spin in ['alpha', 'beta']: mos = qc.mo_spec['all_mo ' + spin] if mos != []: moom = ai.get_mo_overlap_matrix(mos, mos, ao_overlap_matrix, numproc=options.numproc) equal(moom, numpy.eye(len(moom)), tol=tol)
from orbkit.detci.ci_read import psi4_detci, molpro_mcscf from orbkit.test.tools import equal from orbkit import options import numpy import os, inspect tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, 'outputs_for_testing') options.quiet = True #I don't know what elese to check here... #Someone elese please add an occupation number check filetypes = ['psi4', 'molpro'] readers = {'psi4': psi4_detci, 'molpro': molpro_mcscf} files = {'psi4': 'h2o.out', 'molpro': 'lih.out'} ref_coeff = { 'psi4': numpy.array([0.976736, -0.093030, -0.076255, 0.067785]), 'molpro': numpy.array([0.9460981, -0.1770487, 0.1770487, -0.0378771]) } for ftype in filetypes: ciclass = readers[ftype](os.path.join(folder, files[ftype])) equal(ciclass[0].coeffs[:4], ref_coeff[ftype])
folder = os.path.join(tests_home, '../outputs_for_testing') qc = read.main_read(os.path.join(folder, 'molpro/nh3.mold'), all_mo=True) Nelec = int(abs(qc.get_charge(nuclear=False))) ao = integrals.AOIntegrals(qc) ## test basic 1- and 2-electron integrals S = ao.overlap(asMO=0) S_mo = ao.overlap(asMO=1) T = ao.kinetic(asMO=0) V = ao.Vne(asMO=0) Vee = ao.Vee(asMO=0) Vee_mo = ao.Vee(asMO=1) ref = numpy.load(os.path.join(tests_home, 'nh3.npz')) equal(S, ref['S']) equal(S_mo, numpy.eye(ao.Norb)) equal(T, ref['T']) equal(V, ref['V']) equal(Vee, ref['Vee']) equal(Vee_mo, ref['Vee_mo']) ## test Hartree-Fock energy P = 2 * numpy.dot(qc.mo_spec.coeffs[:Nelec // 2, :].T, qc.mo_spec.coeffs[:Nelec // 2, :]) G = P[None, None, :, :] * Vee - numpy.swapaxes( 0.5 * P.T[None, :, :, None] * Vee, 1, 3) G = numpy.sum(G, axis=(2, 3)) Hcore = T + V F = Hcore + G EHF = 0.5 * numpy.tensordot(P, Hcore + F, axes=2)
import numpy from orbkit.qcinfo import QCinfo from orbkit.orbitals import MOClass from orbkit import options import os, inspect import warnings warnings.filterwarnings("ignore") options.quiet = True tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../outputs_for_testing/gaussian') filepath = os.path.join(folder, 'h2o_uhf_cart.inp.log') qc = main_read(filepath, all_mo=True) equal(qc.mo_spec.get_homo(), 9) equal(qc.mo_spec.get_lumo(), 10) equal(qc.mo_spec.get_lastbound(), qc.mo_spec.get_homo()) h**o = qc.mo_spec.get_homo() lumo = qc.mo_spec.get_lumo() lastbound = qc.mo_spec.get_lastbound() alpha = numpy.array(qc.mo_spec.alpha_index) beta = numpy.array(qc.mo_spec.beta_index) usecases = { 'h**o-1:lumo+2': range(h**o - 1, lumo + 2), 'h**o,lumo': [h**o, lumo], 'h**o': [h**o],
filepath = os.path.join(folder, 'h2o_rhf_sph.molden') qc = read.main_read(filepath, all_mo=True) grid.adjust_to_geo(qc, extend=2.0, step=1) grid.grid_init(is_vector=False, force=True) drv = [None, 'x', 'y', 'z', 'xx', 'xy', 'xz', 'yy', 'yz', 'zz'] data = [] for i in range(2): if i: grid.grid2vector() data.append([ rho_compute(qc, slice_length=0), rho_compute(qc, numproc=options.numproc), rho_compute(qc, laplacian=True, slice_length=0)[-1], rho_compute(qc, laplacian=True, numproc=options.numproc)[-1], rho_compute(qc, calc_mo=True, drv=drv, slice_length=0), rho_compute(qc, calc_mo=True, drv=drv, numproc=options.numproc) ]) data[1] = [grid.mv2g(d=i) for i in data[1]] for i in range(len(data[0])): equal(data[0][i], data[1][i]) filepath = os.path.join(tests_home, 'refdata_rho_compute.npz') #numpy.savez(filepath, data=data[0]) refdata = numpy.load(filepath) in_dic = {0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four'} for i in range(5): equal(data[0][i], refdata[in_dic[i]])
from orbkit.test.tools import equal from orbkit.qcinfo import QCinfo from orbkit import options import os, inspect, tempfile, numpy options.quiet = True tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../outputs_for_testing') filepath = os.path.join(folder, 'NaCl_molden_files.tar.gz') qc_old = main_read(filepath) tests_home = tempfile.gettempdir() filepath = os.path.join(tests_home, 'tmp.npz') main_output(qc_old, outputname=filepath, otype='native', ftype='numpy') qc_new = main_read(filepath) equal(qc_old, qc_new) os.remove(filepath) # Test restart from standard npz data output set_grid(0, 0, 0, is_vector=False) main_output(numpy.zeros(get_shape()), qc=qc_old, outputname=filepath) qc_new = main_read(filepath) equal(qc_old, qc_new) os.remove(filepath)
dx = 4.970736 grid.x = numpy.arange(3) * dx - 4.970736 grid.y = numpy.arange(3) * dx - 4.970736 grid.z = numpy.arange(3) * dx - 4.732975 grid.is_initialized = True grid.is_regular = True grid.is_vector = False tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../outputs_for_testing/gaussian') filepath = os.path.join(folder, 'h2o_rhf_sph.fchk') qc = read.main_read(filepath, all_mo=False) rho, delta_rho = rho_compute(qc, drv='xyz') rho2, delta_rho2, laplacian = rho_compute(qc, laplacian=True) equal(rho, rho2) #equal(delta_rho,delta_rho2) #BUG refdata = numpy.genfromtxt(os.path.join(folder, 'h2o_rhf_sph_grad.cube'), skip_header=9).reshape((-1, )) refrho = numpy.zeros_like(rho) refdrho = numpy.zeros((3, ) + rho.shape) c = 0 for i in range(len(grid.x)): for j in range(len(grid.y)): for k in range(len(grid.z)): refrho[i, j, k] = refdata[c] c += 1 for l in range(3): refdrho[l, i, j, k] = refdata[c] c += 1
import os, inspect import numpy from orbkit import Multi from orbkit import options from orbkit.test.tools import equal options.quiet = True tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../outputs_for_testing') filepath = os.path.join(folder, 'NaCl_molden_files.tar.gz') multiple_files = Multi() multiple_files.read(filepath, all_mo=True, nosym=False) index_list, mo_overlap = multiple_files.order_using_analytical_overlap(None) #numpy.savez('refdata_read_multiple_files.npz', index_list=index_list[0][0], mo_overlap=mo_overlap[0][0]) filepath = os.path.join(tests_home, 'refdata_read_multiple_files.npz') refdata = numpy.load(filepath) equal(index_list[0][0], refdata['index_list']) equal(mo_overlap[0][0], refdata['mo_overlap'])
import numpy import os, inspect from orbkit import read from orbkit import analytical_integrals as ai from orbkit import options from orbkit.test.tools import equal options.quiet = True tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../read/outputs_for_testing') filepath = os.path.join(folder, 'h2o_rhf_sph.molden') qc = read.main_read(filepath, all_mo=True) ao_overlap_matrix = ai.get_ao_overlap(qc.geo_spec, qc.geo_spec, qc.ao_spec, ao_spherical=qc.ao_spherical) moom = ai.get_mo_overlap_matrix(qc.mo_spec, qc.mo_spec, ao_overlap_matrix, numproc=options.numproc) equal(moom, numpy.eye(len(moom)))
''' Test orbkit units module ''' from orbkit.units import * from orbkit.test.tools import equal #Reference values for conversion ref_ha2ev = 27.211386 ref_a02aa = 0.529177210 ref_debye2ea0 = 0.393456 ref_u2me = 1822.888486192 equal(ha2ev * ev2ha, 1) equal(a02aa * aa2a0, 1) equal(debye2ea0 * ea02debye, 1) equal(u2me * me2u, 1) equal(ha2ev, ref_ha2ev) equal(a02aa, ref_a02aa) equal(u2me, ref_u2me) #Debye vaue is not precise enouth - test less stringently equal(debye2ea0, ref_debye2ea0, 1e-3)
from orbkit.qcinfo import QCinfo import numpy from orbkit import options import os, inspect options.quiet = True tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../outputs_for_testing/gamess') filepath = os.path.join(folder, 'formaldehyde.log') qc = main_read(filepath, all_mo=True) item = qc.mo_spec.get_coeffs() for i in range(item.shape[0]): item[i] = numpy.zeros(item.shape[1]) + i qc.mo_spec.set_coeffs(item) equal(qc.mo_spec.get_coeffs(), item) item = qc.mo_spec.get_occ() qc.mo_spec.set_occ(item) equal(qc.mo_spec.get_occ(), item) item = qc.mo_spec.get_eig() qc.mo_spec.set_eig(item) equal(qc.mo_spec.get_eig(), item) item = qc.mo_spec.get_sym() qc.mo_spec.set_sym(item) equal(qc.mo_spec.get_sym(), item)
all_mo=True, spin=None, i_md=1, interactive=False) qc.mo_spec.extend(qc_b.mo_spec) qc.mo_spec.update() else: qc = read.main_read(fid, itype=ok_opt[j], interactive=False, all_mo=True, cclib_parser='Gaussian') dip = get_dipole_moment(qc, component=['x', 'y', 'z']) equal(dip, ref_dip[folder[j]]) ''' Old tests ''' tests_home = os.path.dirname(inspect.getfile(inspect.currentframe())) folder = os.path.join(tests_home, '../outputs_for_testing/molpro') filepath = os.path.join(folder, 'h2o_rhf_sph.molden') qc = read.main_read(filepath, all_mo=True) dip = get_dipole_moment(qc, component=['x', 'y', 'z']) ref_dip = [0.00000000e+00, -1.01130147e-16, 8.17259184e-01] equal(dip, ref_dip) qc.geo_spec += numpy.array([1, 1, 0]) dip = get_dipole_moment(qc, component=['x', 'y', 'z'])
''' Test orbkit units module ''' from orbkit.units import * from orbkit.test.tools import equal #Reference values for conversion ref_ha_to_ev = 27.211386 ref_a0_to_aa = 0.529177210 ref_debye_to_ea0 = 0.393456 ref_u_to_me = 1822.888486192 equal(ha_to_ev * ev_to_ha, 1) equal(a0_to_aa * aa_to_a0, 1) equal(debye_to_ea0 * ea0_to_debye, 1) equal(u_to_me * me_to_u, 1) equal(ha_to_ev, ref_ha_to_ev) equal(a0_to_aa, ref_a0_to_aa) equal(u_to_me, ref_u_to_me) #Debye vaue is not precise enouth - test less stringently equal(debye_to_ea0, ref_debye_to_ea0 , 1e-3)