Esempio n. 1
0
def test_scripts():
    # Generate some random system with random esp data
    natom = 5
    numbers = np.random.randint(1, 20, natom)
    coordinates = np.random.uniform(0, 10, (natom, 3))
    origin = np.zeros(3, float)
    grid_rvecs = np.identity(3, float)*1.0
    shape = np.array([10, 10, 10])
    pbc = np.ones(3, int)
    ugrid = UniformGrid(origin, grid_rvecs, shape, pbc)
    esp_cube_data = np.random.uniform(-1, 1, shape)
    rho_cube_data = np.random.uniform(-1, 1, shape)
    mol_esp = IOData(coordinates=coordinates, numbers=numbers, grid=ugrid, cube_data=esp_cube_data)
    mol_rho = mol_esp.copy()
    mol_rho.cube_data = rho_cube_data

    # Write the cube file to the tmpdir and run scripts (run 1)
    with tmpdir('horton.scripts.test.test_espfit.test_scripts') as dn:
        mol_esp.to_file(os.path.join(dn, 'esp.cube'))
        check_script('horton-esp-cost.py esp.cube esp.h5 --wnear=0:1.0:0.5', dn)
        check_script('horton-esp-fit.py esp.h5 other.h5', dn)
        check_script('horton-esp-test.py esp.h5 other.h5:charges foo.h5', dn)
        check_script('horton-esp-gen.py other.h5:charges esp.cube gen.h5', dn)
        check_files(dn, ['esp.h5', 'other.h5', 'foo.h5', 'gen.h5'])

    # Write the cube file to the tmpdir and run scripts (run 2)
    with tmpdir('horton.scripts.test.test_espfit.test_scripts2') as dn:
        mol_esp.to_file(os.path.join(dn, 'esp.cube'))
        mol_rho.to_file(os.path.join(dn, 'rho.cube'))
        check_script('horton-esp-cost.py esp.cube esp.h5 --wnear=0:1.0:0.5 --wdens=rho.cube --wsave=weight.cube', dn)
        check_files(dn, ['esp.h5', 'weight.cube'])
        check_script('horton-esp-fit.py esp.h5 other.h5', dn)
        check_script('horton-esp-test.py esp.h5 other.h5:charges foo.h5', dn)
        check_script('horton-esp-gen.py other.h5:charges esp.cube gen.h5', dn)
        check_files(dn, ['esp.h5', 'other.h5', 'foo.h5', 'gen.h5'])
Esempio n. 2
0
def test_dump_load_fcidimp_consistency_ao():
    # Setup IOData
    mol0 = IOData.from_file(context.get_fn('test/water.xyz'))
    obasis = get_gobasis(mol0.coordinates, mol0.numbers, '3-21G')
    lf = DenseLinalgFactory(obasis.nbasis)

    # Compute stuff for fcidump file. test without transforming to mo basis
    mol0.core_energy = compute_nucnuc(mol0.coordinates, mol0.pseudo_numbers)
    mol0.nelec = 10
    mol0.ms2 = 1
    mol0.one_mo = lf.create_two_index()
    obasis.compute_kinetic(mol0.one_mo)
    obasis.compute_nuclear_attraction(mol0.coordinates, mol0.pseudo_numbers, mol0.one_mo)
    mol0.two_mo = obasis.compute_electron_repulsion(lf)

    # Dump to a file and load it again
    with tmpdir('horton.io.test.test_molpro.test_dump_load_fcidump_consistency_ao') as dn:
        mol0.to_file('%s/FCIDUMP' % dn)
        mol1 = IOData.from_file('%s/FCIDUMP' % dn)

    # Compare results
    assert mol0.core_energy == mol1.core_energy
    assert mol0.nelec == mol1.nelec
    assert mol0.ms2 == mol1.ms2
    assert mol0.one_mo == mol1.one_mo
    assert mol0.two_mo == mol1.two_mo
Esempio n. 3
0
def check_script_lta(fn_sym, suffix):
    with tmpdir('horton.scripts.test.test_cpart.test_script_lta_coarse_h_%s' % suffix) as dn:
        # prepare files
        if fn_sym is not None:
            copy_files(dn, [fn_sym])
        write_atomdb_refatoms(dn)

        # write a random cube file
        fn_cube = 'dens.cube'
        sys = write_random_lta_cube(dn, fn_cube)

        # run the script
        fn_h5 = '%s_cpart.h5' % fn_cube[:-5]
        if fn_sym is None:
            check_script('horton-cpart.py %s %s:cpart/h_r1 h atoms.h5' % (fn_cube, fn_h5), dn)
        else:
            check_script('horton-cpart.py %s %s:cpart/h_r1 h atoms.h5 --symmetry=%s' % (fn_cube, fn_h5, fn_sym), dn)

        # check the output
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'cpart' in f
            assert 'h_r1' in f['cpart']
            if fn_sym is not None:
                assert 'symmetry' in f['cpart/h_r1']
                assert 'charges' in f['cpart/h_r1/symmetry']
                assert 'cartesian_multipoles' in f['cpart/h_r1/symmetry']
                for name, ds in f['cpart/h_r1/symmetry'].iteritems():
                    assert ds.shape[0] == sys.extra['symmetry'].natom
                    assert ds.shape[1] == 2
Esempio n. 4
0
def check_script_water_sto3g(scheme, do_deriv=True):
    with tmpdir('horton.scripts.test.test_wpart.test_script_water_sto3g_%s' % scheme) as dn:
        fn_fchk = 'water_sto3g_hf_g03.fchk'
        copy_files(dn, [fn_fchk])
        if scheme == 'b':
            check_script('horton-wpart.py %s water_sto3g_hf_g03_wpart.h5:wpart %s --debug' % (fn_fchk, scheme), dn)
        else:
            write_atomdb_sto3g(dn, do_deriv)
            check_script('horton-wpart.py %s water_sto3g_hf_g03_wpart.h5:wpart %s atoms.h5 --slow' % (fn_fchk, scheme), dn)
        fn_h5 = 'water_sto3g_hf_g03_wpart.h5'
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'wpart' in f
            assert abs(f['wpart/charges'][:].sum()) < 1e-2
            assert 'wpart/spin_charges' not in f
            assert 'atom_00000' in f['wpart']
            for s in 'density_decomposition', 'hartree_decomposition':
                assert s in f['wpart']['atom_00000']
                assert 'spline_00000' in f['wpart']['atom_00000'][s]
                assert 'rtransform' in f['wpart']['atom_00000'][s]['spline_00000'].attrs
                assert 'extrapolation' in f['wpart']['atom_00000'][s]['spline_00000'].attrs
                assert 'y' in f['wpart']['atom_00000'][s]['spline_00000']
                assert 'd' in f['wpart']['atom_00000'][s]['spline_00000']
            if scheme != 'b':
                assert 'spline_prodensity' in f['wpart']['atom_00000']
                assert 'spline_prohartree' in f['wpart']['atom_00000']
Esempio n. 5
0
def test_dump_load_fcidimp_consistency_mo_active():
    # Setup IOData
    mol0 = IOData.from_file(context.get_fn('test/h2o_sto3g.fchk'))
    lf = DenseLinalgFactory(mol0.obasis.nbasis)

    # Compute stuff for fcidump file.
    one = lf.create_two_index()
    mol0.obasis.compute_kinetic(one)
    mol0.obasis.compute_nuclear_attraction(mol0.coordinates, mol0.pseudo_numbers, one)
    two = mol0.obasis.compute_electron_repulsion(lf)

    # transform to mo basis and use only active space
    enn = compute_nucnuc(mol0.coordinates, mol0.pseudo_numbers)
    mol0.one_mo, mol0.two_mo, mol0.core_energy = split_core_active(one, two, enn, mol0.exp_alpha, 2, 4)
    mol0.one_mo.symmetrize()
    mol0.two_mo.symmetrize()
    mol0.nelec = 10
    mol0.ms2 = 0

    # Dump to a file and load it again
    with tmpdir('horton.io.test.test_molpro.test_dump_load_fcidump_consistency_mo_active') as dn:
        mol0.to_file('%s/FCIDUMP' % dn)
        mol1 = IOData.from_file('%s/FCIDUMP' % dn)

    # Compare results
    assert mol0.core_energy == mol1.core_energy
    assert mol0.nelec == mol1.nelec
    assert mol0.ms2 == mol1.ms2
    assert mol0.one_mo == mol1.one_mo
    assert mol0.two_mo == mol1.two_mo
Esempio n. 6
0
def test_dump_load_fcidimp_consistency_mo_active():
    # Setup IOData
    mol0 = IOData.from_file(context.get_fn('test/h2o_sto3g.fchk'))

    # Compute stuff for fcidump file.
    one = mol0.obasis.compute_kinetic()
    mol0.obasis.compute_nuclear_attraction(mol0.coordinates, mol0.pseudo_numbers, one)
    two = mol0.obasis.compute_electron_repulsion()

    # transform to mo basis and use only active space
    enn = compute_nucnuc(mol0.coordinates, mol0.pseudo_numbers)
    mol0.one_mo, mol0.two_mo, mol0.core_energy = split_core_active(one, two, enn, mol0.orb_alpha, 2, 4)
    mol0.nelec = 10
    mol0.ms2 = 0

    # Dump to a file and load it again
    with tmpdir('horton.io.test.test_molpro.test_dump_load_fcidump_consistency_mo_active') as dn:
        mol0.to_file('%s/FCIDUMP' % dn)
        mol1 = IOData.from_file('%s/FCIDUMP' % dn)

    # Compare results
    np.testing.assert_equal(mol0.core_energy, mol1.core_energy)
    np.testing.assert_equal(mol0.nelec, mol1.nelec)
    np.testing.assert_equal(mol0.ms2, mol1.ms2)
    np.testing.assert_almost_equal(mol0.one_mo, mol1.one_mo)
    np.testing.assert_almost_equal(mol0.two_mo, mol1.two_mo)
Esempio n. 7
0
def check_load_dump_consistency(fn):
    sys1 = System.from_file(context.get_fn(os.path.join('test', fn)))
    with tmpdir('horton.io.test.test_molden.check_load_dump_consistency.%s' % fn) as dn:
        fn_tmp = os.path.join(dn, 'foo.molden.input')
        sys1.to_file(fn_tmp)
        sys2 = System.from_file(fn_tmp)
    compare_systems(sys1, sys2)
Esempio n. 8
0
def test_write_script_output():
    class Foo:
        pass

    def test_h5(fn_h5):
        with h5.File(fn_h5, "r") as f:
            assert sorted(f.keys()) == ["a", "c"]
            assert f["a"].keys() == ["b"]
            assert (f["a/b"][:] == np.array([1, 2, 3])).all()
            assert (f["c"][:] == np.array([0.1, 0.2, 0.3])).all()
            assert len(f.attrs) == 5

    with tmpdir("horton.scripts.test.test_common.test_write_script_output") as dn:
        fn_h5 = "%s/foo.h5" % dn
        results = {"a": {"b": np.array([1, 2, 3])}, "c": np.array([0.1, 0.2, 0.3])}
        args = Foo()
        args.bar = "egg"
        args.bork = "kwak"
        write_script_output(fn_h5, "/", results, args)
        test_h5(fn_h5)
        write_script_output(fn_h5, "/", results, args)
        test_h5(fn_h5)
        with h5.File(fn_h5) as f:
            f["d"] = 5
        write_script_output(fn_h5, "/", results, args)
        test_h5(fn_h5)
        with h5.File(fn_h5) as f:
            for key in f.keys():
                del f[key]
        write_script_output(fn_h5, "/", results, args)
        test_h5(fn_h5)
Esempio n. 9
0
def check_dump_load_fcidimp_consistency_mo(fn):
    # Setup IOData
    mol0 = IOData.from_file(fn)
    lf = DenseLinalgFactory(mol0.obasis.nbasis)

    # Compute stuff for fcidump file.
    one = lf.create_two_index()
    mol0.obasis.compute_kinetic(one)
    mol0.obasis.compute_nuclear_attraction(mol0.coordinates, mol0.pseudo_numbers, one)
    two = mol0.obasis.compute_electron_repulsion(lf)

    # transform to mo basis, skip core energy
    (mol0.one_mo,), (mol0.two_mo,) = transform_integrals(one, two, 'tensordot', mol0.exp_alpha)
    mol0.one_mo.symmetrize()
    mol0.two_mo.symmetrize()

    # Dump to a file and load it again
    with tmpdir('horton.io.test.test_molpro.test_dump_load_fcidump_consistency_mo_%s' % os.path.basename(fn)) as dn:
        fn = '%s/FCIDUMP' % dn
        mol0.to_file(fn)
        mol1 = IOData.from_file(fn)

    # Compare results
    assert mol1.core_energy == 0.0
    assert mol1.nelec == 0
    assert mol1.ms2 == 0
    assert mol0.one_mo == mol1.one_mo
    assert mol0.two_mo == mol1.two_mo
Esempio n. 10
0
def test_script_convert_g03():
    with tmpdir("horton.scripts.test.test_atomdb.test_script_convert_g03") as dn:
        copy_atom_output("atom_001_001_hf_sto3g.fchk", 1, 0, 2, dn, "atom.fchk")
        copy_atom_output("atom_001_002_hf_sto3g.fchk", 1, -1, 1, dn, "atom.fchk")
        copy_atom_output("atom_008_007_hf_sto3g.fchk", 8, +1, 4, dn, "atom.fchk")
        copy_atom_output("atom_008_008_hf_sto3g.fchk", 8, 0, 3, dn, "atom.fchk")
        copy_atom_output("atom_008_009_hf_sto3g.fchk", 8, -1, 2, dn, "atom.fchk")
        make_fake_run_script("g03", dn)
        check_script("horton-atomdb.py convert", dn)
        # check presence of files
        fns = [
            "atoms.h5",
            "dens_001__h.png",
            "rdens_001__h.png",
            "fukui_001__h.png",
            "rfukui_001__h.png",
            "dens_008__o.png",
            "rdens_008__o.png",
            "fukui_008__o.png",
            "rfukui_008__o.png",
        ]
        check_files(dn, fns)
        # load proatomdb file and check some contents
        padb = ProAtomDB.from_file(os.path.join(dn, "atoms.h5"))
        assert padb.get_numbers() == [1, 8]
        assert padb.get_charges(1) == [0, -1]
        assert padb.get_charges(8) == [+1, 0, -1]
Esempio n. 11
0
def test_write_script_output():
    class Foo:
        pass
    def test_h5(fn_h5):
        with h5.File(fn_h5, 'r') as f:
            assert sorted(f.keys()) == ['a', 'c']
            assert f['a'].keys() == ['b']
            assert (f['a/b'][:] == np.array([1, 2, 3])).all()
            assert (f['c'][:] == np.array([0.1, 0.2, 0.3])).all()
            assert len(f.attrs) == 5
    with tmpdir('horton.scripts.test.test_common.test_write_script_output') as dn:
        fn_h5 = '%s/foo.h5' % dn
        results = {'a': {'b': np.array([1, 2, 3])}, 'c': np.array([0.1, 0.2, 0.3])}
        args = Foo()
        args.bar = 'egg'
        args.bork = 'kwak'
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
        with h5.File(fn_h5) as f:
            f['d'] = 5
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
        with h5.File(fn_h5) as f:
            for key in f.keys():
                del f[key]
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
Esempio n. 12
0
def check_load_dump_consistency(fn):
    mol1 = IOData.from_file(context.get_fn(os.path.join('test', fn)))
    with tmpdir('horton.io.test.test_molden.check_load_dump_consistency.%s' % fn) as dn:
        fn_tmp = os.path.join(dn, 'foo.molden')
        mol1.to_file(fn_tmp)
        mol2 = IOData.from_file(fn_tmp)
    compare_mols(mol1, mol2)
Esempio n. 13
0
def test_script_input_orca():
    with tmpdir("horton.scripts.test.test_atomdb.test_script_input_orca") as dn:
        fn_template = "template_atomdb_orca.in"
        copy_files(dn, [fn_template])
        check_script("horton-atomdb.py input orca H,13 %s --no-hund" % fn_template, dn)
        fns = [
            "001__h_003_q-02/mult02/atom.in",
            "001__h_003_q-02/mult04/atom.in",
            "001__h_002_q-01/mult01/atom.in",
            "001__h_002_q-01/mult03/atom.in",
            "001__h_001_q+00/mult02/atom.in",
            "013_al_015_q-02/mult04/atom.in",
            "013_al_015_q-02/mult02/atom.in",
            "013_al_014_q-01/mult03/atom.in",
            "013_al_014_q-01/mult05/atom.in",
            "013_al_014_q-01/mult01/atom.in",
            "013_al_013_q+00/mult02/atom.in",
            "013_al_013_q+00/mult04/atom.in",
            "013_al_012_q+01/mult01/atom.in",
            "013_al_012_q+01/mult03/atom.in",
            "013_al_011_q+02/mult02/atom.in",
            "013_al_010_q+03/mult01/atom.in",
            "run_orca.sh",
        ]
        check_files(dn, fns)
Esempio n. 14
0
def test_dump_load_fcidimp_consistency_ao():
    # Setup IOData
    mol0 = IOData.from_file(context.get_fn('test/water.xyz'))
    obasis = get_gobasis(mol0.coordinates, mol0.numbers, '3-21G')

    # Compute stuff for fcidump file. test without transforming to mo basis
    mol0.core_energy = compute_nucnuc(mol0.coordinates, mol0.pseudo_numbers)
    mol0.nelec = 10
    mol0.ms2 = 1
    mol0.one_mo = (
        obasis.compute_kinetic() +
        obasis.compute_nuclear_attraction(mol0.coordinates, mol0.pseudo_numbers))
    mol0.two_mo = obasis.compute_electron_repulsion()

    # Dump to a file and load it again
    with tmpdir('horton.io.test.test_molpro.test_dump_load_fcidump_consistency_ao') as dn:
        mol0.to_file('%s/FCIDUMP' % dn)
        mol1 = IOData.from_file('%s/FCIDUMP' % dn)

    # Compare results
    np.testing.assert_equal(mol0.core_energy, mol1.core_energy)
    np.testing.assert_equal(mol0.nelec, mol1.nelec)
    np.testing.assert_equal(mol0.ms2, mol1.ms2)
    np.testing.assert_almost_equal(mol0.one_mo, mol1.one_mo)
    np.testing.assert_almost_equal(mol0.two_mo, mol1.two_mo)
Esempio n. 15
0
def test_ap1rog_cs_scf_restart():
    lf, occ_model, one, er, external, exp_alpha, olp = prepare_hf('6-31G')

    # Do AP1roG optimization:
    geminal_solver = RAp1rog(lf, occ_model)
    guess = np.array([-0.1, -0.05, -0.02])

    with tmpdir('horton.correlatedwfn.test.test_geminals.test_ap1rog_cs_scf_restart') as dn:
        checkpoint_fn = '%s/checkpoint.h5' % dn
        energy, g, l = geminal_solver(one, er, external['nn'], exp_alpha, olp,
                                      True, guess={'geminal': guess},
                                      checkpoint_fn=checkpoint_fn)
        assert (abs(energy - -1.151686291339) < 1e-6)

        old = IOData.from_file(checkpoint_fn)

    assert hasattr(old, 'olp')
    assert hasattr(old, 'exp_alpha')

    # Update to slightly stretch geometry of H2
    mol1, lf, olp1, one1, er1 = prepare_mol('6-31G', 1.05)

    # re-orthogonalize orbitals
    project_orbitals_ortho(old.olp, olp1, old.exp_alpha, exp_alpha)

    # recompute
    energy, c, l = geminal_solver(one1, er1, external['nn'], exp_alpha, olp1,
                                  True, guess={'geminal': guess},
                                  checkpoint=-1)

    assert (abs(energy - -1.11221603918) < 1e-6)
Esempio n. 16
0
def test_agspec_local_file():
    with tmpdir('horton.scripts.test.test_espfit.test_scripts_symmetry') as dn:
        fn_dest = os.path.join(dn, 'mygrid.txt')
        shutil.copy(context.get_fn('grids/tv-13.7-4.txt'), fn_dest)
        agspec = AtomicGridSpec(fn_dest)
        rgrid, nlls = agspec.get(1, 1)
        assert rgrid.rtransform.to_string() == 'PowerRTransform 3.69705074304963e-06 19.279558946793685 24'
        assert (nlls == np.array([6, 6, 6, 6, 6, 6, 6, 6, 14, 14, 26, 38, 50, 86, 110, 110, 110, 110, 86, 50, 50, 14, 6, 6])).all()
Esempio n. 17
0
def test_consistency_file():
    with tmpdir('horton.io.test.test_chk.test_consistency_file') as dn:
        fn_h5 = '%s/foo.h5' % dn
        fn_fchk = context.get_fn('test/water_sto3g_hf_g03.fchk')
        fn_log = context.get_fn('test/water_sto3g_hf_g03.log')
        mol1 = IOData.from_file(fn_fchk, fn_log)
        mol1.to_file(fn_h5)
        mol2 = IOData.from_file(fn_h5)
        compare_mols(mol1, mol2)
Esempio n. 18
0
def test_consistency_file():
    with tmpdir('horton.io.test.test_chk.test_consistency_file') as dn:
        fn_chk = '%s/chk.h5' % dn
        fn_fchk = context.get_fn('test/water_sto3g_hf_g03.fchk')
        fn_log = context.get_fn('test/water_sto3g_hf_g03.log')
        sys1 = System.from_file(fn_fchk, fn_log, chk=None)
        sys1.to_file(fn_chk)
        sys2 = System.from_file(fn_chk, chk=None)
        compare_systems(sys1, sys2)
Esempio n. 19
0
def test_load_dump_consistency():
    mol0 = IOData.from_file(context.get_fn('test/ch3_hf_sto3g.fchk'))

    with tmpdir('horton.io.test.test_xyz.test_load_dump_consistency') as dn:
        mol0.to_file('%s/test.xyz' % dn)
        mol1 = IOData.from_file('%s/test.xyz' % dn)

    assert mol0.title == mol1.title
    assert (mol0.numbers == mol1.numbers).all()
    assert abs(mol0.coordinates - mol1.coordinates).max() < 1e-5
Esempio n. 20
0
def test_io_filename():
    padb1 = ProAtomDB.from_refatoms(numbers=[1, 6], max_kation=1, max_anion=0)
    keys = sorted(padb1._map.keys())
    assert keys == [(1, 0), (6, 0), (6, 1)]

    with tmpdir('horton.dpart.test.test_proatomdb.test_io_filename') as dn:
        filename = '%s/test.h5' % dn
        padb1.to_file(filename)
        padb2 = ProAtomDB.from_file(filename)
        compare_padbs(padb1, padb2)
Esempio n. 21
0
def check_script_jbw_coarse(scheme):
    with tmpdir("horton.scripts.test.test_cpart.test_script_jbw_coarse_%s" % scheme) as dn:
        fn_cube = "jbw_coarse_aedens.cube"
        copy_files(dn, [fn_cube])
        write_atomdb_refatoms(dn)
        fn_h5 = "foobar.h5"
        check_script("horton-cpart.py %s foobar.h5:cpart/%s_r1 %s atoms.h5" % (fn_cube, scheme, scheme), dn)
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert "cpart" in f
            assert scheme + "_r1" in f["cpart"]
Esempio n. 22
0
def check_script_jbw_coarse(scheme):
    with tmpdir('horton.scripts.test.test_cpart.test_script_jbw_coarse_%s' % scheme) as dn:
        fn_cube = 'jbw_coarse_aedens.cube'
        copy_files(dn, [fn_cube])
        write_atomdb_refatoms(dn)
        fn_h5 = 'foobar.h5'
        check_script('horton-cpart.py %s foobar.h5:cpart/%s_r1 %s atoms.h5' % (fn_cube, scheme, scheme), dn)
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'cpart' in f
            assert scheme + '_r1' in f['cpart']
Esempio n. 23
0
def test_script_convert_g09():
    with tmpdir("horton.scripts.test.test_atomdb.test_script_convert_g09") as dn:
        copy_atom_output("atom_014_013_hf_lan.fchk", 14, +1, 2, dn, "atom.fchk")
        make_fake_run_script("g09", dn)
        check_script("horton-atomdb.py convert --grid medium", dn)
        # check presence of files
        fns = ["atoms.h5", "dens_014_si.png", "rdens_014_si.png", "fukui_014_si.png", "rfukui_014_si.png"]
        check_files(dn, fns)
        # load proatomdb file and check some contents
        padb = ProAtomDB.from_file(os.path.join(dn, "atoms.h5"))
        assert padb.get_numbers() == [14]
        assert padb.get_charges(14) == [+1]
        assert padb.get_rgrid(14).size == 49
Esempio n. 24
0
def test_load_dump_consistency():
    sys0 = System.from_file(context.get_fn('test/water_element.xyz'))
    sys0._cell = get_random_cell(5.0, 3)

    with tmpdir('horton.io.test.test_vasp.test_load_dump_consistency') as dn:
        sys0.to_file('%s/POSCAR' % dn)
        sys1 = System.from_file('%s/POSCAR' % dn)

    assert (sys1.numbers == [8, 1, 1]).all()
    assert abs(sys0.coordinates[1] - sys1.coordinates[0]).max() < 1e-10
    assert abs(sys0.coordinates[0] - sys1.coordinates[1]).max() < 1e-10
    assert abs(sys0.coordinates[2] - sys1.coordinates[2]).max() < 1e-10
    assert abs(sys0.cell.rvecs - sys1.cell.rvecs).max() < 1e-10
Esempio n. 25
0
def test_script_convert_g09():
    with tmpdir('horton.scripts.test.test_atomdb.test_script_convert_g09') as dn:
        copy_atom_output('atom_014_013_hf_lan.fchk', 14, +1, 2, dn, 'atom.fchk')
        make_fake_run_script('g09', dn)
        check_script('horton-atomdb.py convert --grid medium', dn)
        # check presence of files
        fns = ['atoms.h5', 'dens_014_si.png', 'rdens_014_si.png', 'fukui_014_si.png', 'rfukui_014_si.png']
        check_files(dn, fns)
        # load proatomdb file and check some contents
        padb = ProAtomDB.from_file(os.path.join(dn, 'atoms.h5'))
        assert padb.get_numbers() == [14]
        assert padb.get_charges(14) == [+1]
        assert padb.get_rgrid(14).size == 49
Esempio n. 26
0
def test_script():
    with tmpdir('horton.scripts.test.test_hdf2csv.test_script') as dn:
        with h5.File('%s/test.h5' % dn) as f:
            fill_hdf5(f)
        check_script('horton-hdf2csv.py test.h5:/ test.csv', dn)
        check_files(dn, ['test.h5', 'test.csv'])
        with open('%s/test.csv' % dn) as f:
            r = csv.reader(f)
            rows = [row for row in r]
        with h5.File('%s/test.h5' % dn) as f:
            assert rows[0][0] == 'Converted data from test.h5:/'
            assert len(rows[1]) == 0
            assert len(rows[2]) == 2
            assert rows[2][0] == 'Dataset'
            assert rows[2][1] == 'bar/foo'
            assert len(rows[3]) == 3
            assert rows[3][0] == 'Shape'
            assert rows[3][1] == '5'
            assert rows[3][2] == '2'
            assert float(rows[4][0]) == f['bar/foo'][0,0]
            assert float(rows[8][1]) == f['bar/foo'][4,1]
            assert len(rows[9]) == 0
            assert len(rows[22]) == 2
            assert rows[22][0] == 'Dataset'
            assert rows[22][1] == 'test2'
            assert len(rows[23]) == 3
            assert rows[23][0] == 'Shape'
            assert rows[23][1] == '5'
            assert rows[23][2] == '2'
            assert float(rows[24][0]) == f['test2'][0,0]
            assert float(rows[28][1]) == f['test2'][4,1]
            assert rows[29] == []
            assert len(rows[30]) == 2
            assert rows[30][0] == 'Dataset'
            assert rows[30][1] == 'zzz'
            assert len(rows[31]) == 4
            assert rows[31][0] == 'Shape'
            assert rows[31][1] == '5'
            assert rows[31][2] == '2'
            assert rows[31][3] == '5'
            assert float(rows[32][0]) == f['zzz'][0,0,0]
            assert float(rows[32][1]) == f['zzz'][0,1,0]
            assert rows[32][2] == ''
            assert float(rows[32][3]) == f['zzz'][0,0,1]
            assert float(rows[32][4]) == f['zzz'][0,1,1]
            assert rows[32][5] == ''
            assert len(rows[32]) == 3*5-1
            assert float(rows[36][1]) == f['zzz'][4,1,0]
            assert float(rows[36][3*5-2]) == f['zzz'][4,1,4]
            assert rows[-1] == []
Esempio n. 27
0
def test_load_dump_consistency():
    mol0 = IOData.from_file(context.get_fn('test/water_element.xyz'))
    mol0.cell = get_random_cell(5.0, 3)

    with tmpdir('horton.io.test.test_vasp.test_load_dump_consistency') as dn:
        mol0.to_file('%s/POSCAR' % dn)
        mol1 = IOData.from_file('%s/POSCAR' % dn)

    assert mol0.title == mol1.title
    assert (mol1.numbers == [8, 1, 1]).all()
    assert abs(mol0.coordinates[1] - mol1.coordinates[0]).max() < 1e-10
    assert abs(mol0.coordinates[0] - mol1.coordinates[1]).max() < 1e-10
    assert abs(mol0.coordinates[2] - mol1.coordinates[2]).max() < 1e-10
    assert abs(mol0.cell.rvecs - mol1.cell.rvecs).max() < 1e-10
Esempio n. 28
0
def check_script_water_sto3g(scheme, do_deriv=True):
    with tmpdir('horton.scripts.test.test_wpart.test_script_water_sto3g_%s' % scheme) as dn:
        fn_fchk = 'water_sto3g_hf_g03.fchk'
        copy_files(dn, [fn_fchk])
        if scheme == 'b':
            check_script('horton-wpart.py %s water_sto3g_hf_g03_wpart.h5:wpart/%s %s --debug' % (fn_fchk, scheme, scheme), dn)
        else:
            write_atomdb_sto3g(dn, do_deriv)
            check_script('horton-wpart.py %s water_sto3g_hf_g03_wpart.h5:wpart/%s %s atoms.h5' % (fn_fchk, scheme, scheme), dn)
        fn_h5 = 'water_sto3g_hf_g03_wpart.h5'
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'wpart' in f
            assert scheme in f['wpart']
Esempio n. 29
0
def test_scripts_symmetry():
    # Write the cube file to the tmpdir and run scripts
    with tmpdir('horton.scripts.test.test_espfit.test_scripts_symmetry') as dn:
        # prepare files
        write_random_lta_cube(dn, 'esp.cube')
        copy_files(dn, ['lta_gulp.cif'])
        # run scripts
        check_script('horton-esp-cost.py esp.cube esp.h5 --wnear=0:1.0:0.5 --rcut=4 --alpha-scale=0.1', dn)
        check_files(dn, ['esp.h5'])
        check_script('horton-esp-fit.py esp.h5 other.h5 --symmetry esp.cube lta_gulp.cif', dn)
        mol_sym = IOData.from_file('%s/lta_gulp.cif' % dn)
        with h5.File(os.path.join(dn, 'other.h5')) as f:
            assert 'symmetry' in f
            assert f['symmetry/charges'].shape == (mol_sym.symmetry.natom, 2)
Esempio n. 30
0
def test_script():
    with tmpdir("horton.scripts.test.test_hdf2csv.test_script") as dn:
        with h5.File("%s/test.h5" % dn) as f:
            fill_hdf5(f)
        check_script("horton-hdf2csv.py test.h5:/ test.csv", dn)
        check_files(dn, ["test.h5", "test.csv"])
        with open("%s/test.csv" % dn) as f:
            r = csv.reader(f)
            rows = [row for row in r]
        with h5.File("%s/test.h5" % dn) as f:
            assert rows[0][0] == "Converted data from test.h5:/"
            assert len(rows[1]) == 0
            assert len(rows[2]) == 2
            assert rows[2][0] == "Dataset"
            assert rows[2][1] == "bar/foo"
            assert len(rows[3]) == 3
            assert rows[3][0] == "Shape"
            assert rows[3][1] == "5"
            assert rows[3][2] == "2"
            assert float(rows[4][0]) == f["bar/foo"][0, 0]
            assert float(rows[8][1]) == f["bar/foo"][4, 1]
            assert len(rows[9]) == 0
            assert len(rows[22]) == 2
            assert rows[22][0] == "Dataset"
            assert rows[22][1] == "test2"
            assert len(rows[23]) == 3
            assert rows[23][0] == "Shape"
            assert rows[23][1] == "5"
            assert rows[23][2] == "2"
            assert float(rows[24][0]) == f["test2"][0, 0]
            assert float(rows[28][1]) == f["test2"][4, 1]
            assert rows[29] == []
            assert len(rows[30]) == 2
            assert rows[30][0] == "Dataset"
            assert rows[30][1] == "zzz"
            assert len(rows[31]) == 4
            assert rows[31][0] == "Shape"
            assert rows[31][1] == "5"
            assert rows[31][2] == "2"
            assert rows[31][3] == "5"
            assert float(rows[32][0]) == f["zzz"][0, 0, 0]
            assert float(rows[32][1]) == f["zzz"][0, 1, 0]
            assert rows[32][2] == ""
            assert float(rows[32][3]) == f["zzz"][0, 0, 1]
            assert float(rows[32][4]) == f["zzz"][0, 1, 1]
            assert rows[32][5] == ""
            assert len(rows[32]) == 3 * 5 - 1
            assert float(rows[36][1]) == f["zzz"][4, 1, 0]
            assert float(rows[36][3 * 5 - 2]) == f["zzz"][4, 1, 4]
            assert rows[-1] == []
Esempio n. 31
0
def test_load_dump_load_aelta():
    fn_cube1 = context.get_fn('test/aelta.cube')
    mol1 = IOData.from_file(fn_cube1)

    with tmpdir('horton.io.test.test_cube.test_load_dump_load_aelta') as dn:
        fn_cube2 = '%s/%s' % (dn, 'aelta.cube')
        mol1.to_file(fn_cube2)
        mol2 = IOData.from_file(fn_cube2)

        assert mol1.title == mol2.title
        assert abs(mol1.coordinates - mol2.coordinates).max() < 1e-4
        assert (mol1.numbers == mol2.numbers).all()
        ugrid1 = mol1.grid
        ugrid2 = mol2.grid
        assert abs(ugrid1.grid_rvecs - ugrid2.grid_rvecs).max() < 1e-4
        assert (ugrid1.shape == ugrid2.shape).all()
        assert abs(mol1.cube_data - mol2.cube_data).max() < 1e-4
        assert abs(mol1.pseudo_numbers - mol2.pseudo_numbers).max() < 1e-4
Esempio n. 32
0
def test_script_convert_cp2k():
    with tmpdir('horton.scripts.test.test_atomdb.test_script_convert_cp2k') as dn:
        copy_atom_output('atom_op2.cp2k.out', 8, +2, 3, dn, 'atom.cp2k.out')
        copy_atom_output('atom_op1.cp2k.out', 8, +1, 4, dn, 'atom.cp2k.out')
        copy_atom_output('atom_o.cp2k.out',   8,  0, 2, dn, 'atom.cp2k.out')
        copy_atom_output('atom_om1.cp2k.out', 8, -1, 1, dn, 'atom.cp2k.out')
        copy_atom_output('atom_om2.cp2k.out', 8, -2, 0, dn, 'atom.cp2k.out')
        make_fake_run_script('cp2k', dn)
        check_script('horton-atomdb.py convert', dn)
        # check presence of files
        fns = ['atoms.h5', 'dens_008__o.png', 'rdens_008__o.png', 'fukui_008__o.png', 'rfukui_008__o.png']
        check_files(dn, fns)
        # load proatomdb file and check some contents
        padb = ProAtomDB.from_file(os.path.join(dn, 'atoms.h5'))
        assert padb.get_numbers() == [8]
        assert padb.get_charges(8) == [+2, +1, 0, -1, -2]
        assert not padb.get_record(8, -2).safe
        assert padb.get_rgrid(8).size == 71
Esempio n. 33
0
def test_script_convert_g09():
    with tmpdir(
            'horton.scripts.test.test_atomdb.test_script_convert_g09') as dn:
        copy_atom_output('atom_014_013_hf_lan.fchk', 14, +1, 2, dn,
                         'atom.fchk')
        make_fake_run_script('g09', dn)
        check_script('horton-atomdb.py convert --grid medium', dn)
        # check presence of files
        fns = [
            'atoms.h5', 'dens_014_si.png', 'rdens_014_si.png',
            'fukui_014_si.png', 'rfukui_014_si.png'
        ]
        check_files(dn, fns)
        # load proatomdb file and check some contents
        padb = ProAtomDB.from_file(os.path.join(dn, 'atoms.h5'))
        assert padb.get_numbers() == [14]
        assert padb.get_charges(14) == [+1]
        assert padb.get_rgrid(14).size == 49
Esempio n. 34
0
def test_scripts_symmetry():
    # Write the cube file to the tmpdir and run scripts
    with tmpdir('horton.scripts.test.test_espfit.test_scripts_symmetry') as dn:
        # prepare files
        write_random_lta_cube(dn, 'esp.cube')
        copy_files(dn, ['lta_gulp.cif'])
        # run scripts
        check_script(
            'horton-esp-cost.py esp.cube esp.h5 --wnear=0:1.0:0.5 --rcut=4 --alpha-scale=0.1',
            dn)
        check_files(dn, ['esp.h5'])
        check_script(
            'horton-esp-fit.py esp.h5 other.h5 --symmetry esp.cube lta_gulp.cif',
            dn)
        mol_sym = IOData.from_file('%s/lta_gulp.cif' % dn)
        with h5.File(os.path.join(dn, 'other.h5')) as f:
            assert 'symmetry' in f
            assert f['symmetry/charges'].shape == (mol_sym.symmetry.natom, 2)
Esempio n. 35
0
def test_ap1rog_cs_scf_restart():
    lf, occ_model, one, er, external, exp_alpha, olp = prepare_hf('6-31G')

    # Do AP1roG optimization:
    geminal_solver = RAp1rog(lf, occ_model)
    guess = np.array([-0.1, -0.05, -0.02])

    with tmpdir(
            'horton.correlatedwfn.test.test_geminals.test_ap1rog_cs_scf_restart'
    ) as dn:
        checkpoint_fn = '%s/checkpoint.h5' % dn
        energy, g, l = geminal_solver(one,
                                      er,
                                      external['nn'],
                                      exp_alpha,
                                      olp,
                                      True,
                                      guess={'geminal': guess},
                                      checkpoint_fn=checkpoint_fn)
        assert (abs(energy - -1.151686291339) < 1e-6)

        old = IOData.from_file(checkpoint_fn)

    assert hasattr(old, 'olp')
    assert hasattr(old, 'exp_alpha')

    # Update to slightly stretch geometry of H2
    mol1, lf, olp1, one1, er1 = prepare_mol('6-31G', 1.05)

    # re-orthogonalize orbitals
    project_orbitals_ortho(old.olp, olp1, old.exp_alpha, exp_alpha)

    # recompute
    energy, c, l = geminal_solver(one1,
                                  er1,
                                  external['nn'],
                                  exp_alpha,
                                  olp1,
                                  True,
                                  guess={'geminal': guess},
                                  checkpoint=-1)

    assert (abs(energy - -1.11221603918) < 1e-6)
Esempio n. 36
0
def test_chk_initialization_override():
    with tmpdir('horton.test.test_checkpoint.test_chk_override') as dn:
        fn_chk1 = '%s/chk1.h5' % dn
        fn_chk2 = '%s/chk2.h5' % dn
        sys1 = System.from_file(context.get_fn('test/hf_sto3g.fchk'), chk=fn_chk1)
        del sys1
        sys1 = System.from_file(context.get_fn('test/hf_sto3g.fchk'))
        sys2 = System.from_file(fn_chk1, chk=fn_chk2)

        compare_systems(sys1, sys2)
        assert os.path.isfile(fn_chk2)

        sys3 = System.from_file(fn_chk2, chk=None)
        compare_systems(sys1, sys3)
        sys3.numbers[:] = 0
        sys3.update_chk('numbers')

        sys4 = System.from_file(fn_chk2, chk=None)
        compare_systems(sys1, sys4)
Esempio n. 37
0
def check_script_water_sto3g(scheme, do_deriv=True):
    with tmpdir('horton.scripts.test.test_wpart.test_script_water_sto3g_%s' %
                scheme) as dn:
        fn_fchk = 'water_sto3g_hf_g03.fchk'
        copy_files(dn, [fn_fchk])
        if scheme == 'b':
            check_script(
                'horton-wpart.py %s water_sto3g_hf_g03_wpart.h5:wpart/%s %s --debug'
                % (fn_fchk, scheme, scheme), dn)
        else:
            write_atomdb_sto3g(dn, do_deriv)
            check_script(
                'horton-wpart.py %s water_sto3g_hf_g03_wpart.h5:wpart/%s %s atoms.h5'
                % (fn_fchk, scheme, scheme), dn)
        fn_h5 = 'water_sto3g_hf_g03_wpart.h5'
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'wpart' in f
            assert scheme in f['wpart']
Esempio n. 38
0
def test_load_dump_load_aelta():
    fn_cube1 = context.get_fn('test/aelta.cube')
    sys1 = System.from_file(fn_cube1)

    with tmpdir('horton.io.test.test_cube.test_load_dump_load_aelta') as dn:
        fn_cube2 = '%s/%s' % (dn, 'aelta.cube')
        sys1.to_file(fn_cube2)
        sys2 = System.from_file(fn_cube2)

        assert sys1.natom == sys2.natom
        assert abs(sys1.coordinates - sys2.coordinates).max() < 1e-4
        assert (sys1.numbers == sys2.numbers).all()
        ugrid1 = sys1.grid
        ugrid2 = sys2.grid
        assert abs(ugrid1.grid_rvecs - ugrid2.grid_rvecs).max() < 1e-4
        assert (ugrid1.shape == ugrid2.shape).all()
        assert abs(sys1.extra['cube_data'] -
                   sys2.extra['cube_data']).max() < 1e-4
        assert abs(sys1.pseudo_numbers - sys2.pseudo_numbers).max() < 1e-4
Esempio n. 39
0
def check_script_lta(fn_sym, suffix, do_spin=False):
    with tmpdir('horton.scripts.test.test_cpart.test_script_lta_coarse_h_%s' % suffix) as dn:
        # prepare files
        if fn_sym is not None:
            copy_files(dn, [fn_sym])
        write_atomdb_refatoms(dn)

        # write a random cube file
        fn_cube = 'dens.cube'
        mol = write_random_lta_cube(dn, fn_cube)

        # if needed, write a random spin cube file
        if do_spin:
            fn_spin = 'spin.cube'
            molspin = write_random_lta_cube(dn, fn_spin)

        # run the script
        fn_h5 = '%s_cpart.h5' % fn_cube[:-5]
        opts = ''
        if not (fn_sym is None):
            opts += ' --symmetry=%s' % fn_sym
        if do_spin:
            opts += ' --spindens=%s' % fn_spin
        check_script('horton-cpart.py %s %s:cpart/h_r1 h atoms.h5 %s' % (fn_cube, fn_h5, opts), dn)

        # check the output
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'cpart' in f
            assert 'h_r1' in f['cpart']
            assert 'charges' in f['cpart/h_r1']
            if do_spin:
                assert 'spin_charges' in f['cpart/h_r1']
            if fn_sym is not None:
                assert 'symmetry' in f['cpart/h_r1']
                assert 'charges' in f['cpart/h_r1/symmetry']
                if do_spin:
                    assert 'spin_charges' in f['cpart/h_r1/symmetry']
                assert 'cartesian_multipoles' in f['cpart/h_r1/symmetry']
                for name, ds in f['cpart/h_r1/symmetry'].iteritems():
                    assert ds.shape[0] == mol.symmetry.natom
                    assert ds.shape[1] == 2
Esempio n. 40
0
def test_script_convert_g03():
    with tmpdir('horton.scripts.test.test_atomdb.test_script_convert_g03') as dn:
        copy_atom_output('atom_001_001_hf_sto3g.fchk', 1,  0, 2, dn, 'atom.fchk')
        copy_atom_output('atom_001_002_hf_sto3g.fchk', 1, -1, 1, dn, 'atom.fchk')
        copy_atom_output('atom_008_007_hf_sto3g.fchk', 8, +1, 4, dn, 'atom.fchk')
        copy_atom_output('atom_008_008_hf_sto3g.fchk', 8,  0, 3, dn, 'atom.fchk')
        copy_atom_output('atom_008_009_hf_sto3g.fchk', 8, -1, 2, dn, 'atom.fchk')
        make_fake_run_script('g03', dn)
        check_script('horton-atomdb.py convert', dn)
        # check presence of files
        fns = [
            'atoms.h5',
            'dens_001__h.png', 'rdens_001__h.png', 'fukui_001__h.png', 'rfukui_001__h.png',
            'dens_008__o.png', 'rdens_008__o.png', 'fukui_008__o.png', 'rfukui_008__o.png',
        ]
        check_files(dn, fns)
        # load proatomdb file and check some contents
        padb = ProAtomDB.from_file(os.path.join(dn, 'atoms.h5'))
        assert padb.get_numbers() == [1, 8]
        assert padb.get_charges(1) == [0, -1]
        assert padb.get_charges(8) == [+1, 0, -1]
Esempio n. 41
0
def test_dump_basis_atom_map_gbs():
    sto3g = GOBasisFamily('original STO-3G',
                          filename=context.get_fn('basis/sto-3g.gbs'))
    sto3g.load()
    with tmpdir('horton.gbasis.test.test_iobas.test_dump_basis_atom_map_gbs'
                ) as tmp:
        tmp_gbs = '{0}/test.gbs'.format(tmp)
        dump_basis_atom_map_gbs(tmp_gbs, sto3g.name, sto3g.basis_atom_map)
        new_sto3g = GOBasisFamily('new STO-3G', filename=tmp_gbs)
        new_sto3g.load()
        for atom, bca in new_sto3g.basis_atom_map.iteritems():
            old_bca = sto3g.basis_atom_map[atom]
            for i, contraction in enumerate(bca.bcs):
                old_contraction = old_bca.bcs[i]
                assert contraction.shell_type == old_contraction.shell_type
                np.testing.assert_equal(contraction.alphas,
                                        old_contraction.alphas)
                # Limited precision due to normalization of contractions after loading
                # them from file.
                np.testing.assert_almost_equal(contraction.con_coeffs,
                                               old_contraction.con_coeffs)
Esempio n. 42
0
def test_script_input_cp2k():
    with tmpdir(
            'horton.scripts.test.test_atomdb.test_script_input_cp2k') as dn:
        fn_template = 'template_atomdb_cp2k.in'
        fn_valence = 'include_atomdb_cp2k_valence.inc'
        fn_ppot = 'include_atomdb_cp2k_ppot.inc'
        copy_files(dn, [fn_template, fn_valence, fn_ppot])
        check_script('horton-atomdb.py input cp2k Ca,F %s' % fn_template, dn)
        fns = [
            '020_ca_021_q-01/mult02/atom.in',
            '020_ca_020_q+00/mult01/atom.in',
            '020_ca_019_q+01/mult02/atom.in',
            '020_ca_018_q+02/mult01/atom.in',
            '020_ca_017_q+03/mult02/atom.in',
            '009__f_010_q-01/mult01/atom.in',
            '009__f_009_q+00/mult02/atom.in',
            '009__f_008_q+01/mult03/atom.in',
            '009__f_007_q+02/mult04/atom.in',
            'run_cp2k.sh',
        ]
        check_files(dn, fns)
Esempio n. 43
0
def check_script_ch3_rohf_sto3g(scheme, do_deriv=True):
    with tmpdir(
            'horton.scripts.test.test_wpart.test_script_ch3_rohf_sto3g_%s' %
            scheme) as dn:
        fn_fchk = 'ch3_rohf_sto3g_g03.fchk'
        copy_files(dn, [fn_fchk])
        if scheme == 'b':
            check_script(
                'horton-wpart.py %s foo.h5:wpart %s --debug' %
                (fn_fchk, scheme), dn)
        else:
            write_atomdb_sto3g(dn, do_deriv)
            check_script(
                'horton-wpart.py %s foo.h5:wpart %s atoms.h5' %
                (fn_fchk, scheme), dn)
        fn_h5 = 'foo.h5'
        check_files(dn, [fn_h5])
        with h5.File(os.path.join(dn, fn_h5)) as f:
            assert 'wpart' in f
            assert abs(f['wpart/charges'][:].sum()) < 1e-2
            assert abs(f['wpart/spin_charges'][:].sum() - 1) < 1e-2
Esempio n. 44
0
def check_script_input_gaussian(binary):
    with tmpdir('horton.scripts.test.test_atomdb.test_script_input_%s' %
                binary) as dn:
        fn_template = 'template_atomdb_gaussian.in'
        fn_basis1 = 'include_atomdb_gaussian_basis.001_000_00'
        fn_basis8 = 'include_atomdb_gaussian_basis.008_000_00'
        copy_files(dn, [fn_template, fn_basis1, fn_basis8])
        check_script(
            'horton-atomdb.py input %s 1,O %s' % (binary, fn_template), dn)
        fns = [
            '001__h_003_q-02/mult02/atom.in',
            '001__h_002_q-01/mult01/atom.in',
            '001__h_001_q+00/mult02/atom.in',
            '008__o_010_q-02/mult01/atom.in',
            '008__o_009_q-01/mult02/atom.in',
            '008__o_008_q+00/mult03/atom.in',
            '008__o_007_q+01/mult04/atom.in',
            '008__o_006_q+02/mult03/atom.in',
            '008__o_005_q+03/mult02/atom.in',
            'run_%s.sh' % binary,
        ]
        check_files(dn, fns)
Esempio n. 45
0
def test_check_output():
    with tmpdir('horton.scripts.test.test_common.test_check_output') as dn:
        assert not check_output('%s/foo.h5' % dn, '/', True)
        assert not check_output('%s/foo.h5' % dn, '/bar', True)
        assert not check_output('%s/foo.h5' % dn, '/', False)
        assert not check_output('%s/foo.h5' % dn, '/bar', False)
        with h5.File('%s/foo.h5' % dn) as f:
            f.create_group('bork')
        assert not check_output('%s/foo.h5' % dn, '/', True)
        assert not check_output('%s/foo.h5' % dn, '/bork', True)
        assert not check_output('%s/foo.h5' % dn, '/bar', True)
        assert check_output('%s/foo.h5' % dn, '/', False)
        assert not check_output('%s/foo.h5' % dn, '/bork', False)
        assert not check_output('%s/foo.h5' % dn, '/bar', False)
        with h5.File('%s/foo.h5' % dn) as f:
            f['bork']['a'] = np.array([1, 2, 3])
        assert not check_output('%s/foo.h5' % dn, '/', True)
        assert not check_output('%s/foo.h5' % dn, '/bork', True)
        assert not check_output('%s/foo.h5' % dn, '/bar', True)
        assert check_output('%s/foo.h5' % dn, '/', False)
        assert check_output('%s/foo.h5' % dn, '/bork', False)
        assert not check_output('%s/foo.h5' % dn, '/bar', False)
Esempio n. 46
0
def test_write_script_output():
    class Foo:
        pass

    def test_h5(fn_h5):
        with h5.File(fn_h5, 'r') as f:
            assert sorted(f.keys()) == ['a', 'c']
            assert f['a'].keys() == ['b']
            assert (f['a/b'][:] == np.array([1, 2, 3])).all()
            assert (f['c'][:] == np.array([0.1, 0.2, 0.3])).all()
            assert len(f.attrs) == 5

    with tmpdir(
            'horton.scripts.test.test_common.test_write_script_output') as dn:
        fn_h5 = '%s/foo.h5' % dn
        results = {
            'a': {
                'b': np.array([1, 2, 3])
            },
            'c': np.array([0.1, 0.2, 0.3])
        }
        args = Foo()
        args.bar = 'egg'
        args.bork = 'kwak'
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
        with h5.File(fn_h5) as f:
            f['d'] = 5
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
        with h5.File(fn_h5) as f:
            for key in f.keys():
                del f[key]
        write_script_output(fn_h5, '/', results, args)
        test_h5(fn_h5)
Esempio n. 47
0
def test_scripts():
    with tmpdir('horton.scripts.test.test_convert.test_scripts') as dn:
        fn_fchk = 'water_sto3g_hf_g03.fchk'
        copy_files(dn, [fn_fchk])
        check_script('horton-convert.py %s test.xyz' % fn_fchk, dn)
Esempio n. 48
0
def test_locked1():
    # just a silly test
    with tmpdir('horton.scripts.test.test_common.test_locked1') as dn:
        with LockedH5File('%s/foo.h5' % dn) as f:
            pass
Esempio n. 49
0
def test_script():
    with tmpdir('horton.scripts.test.test_cubehead.test_script') as dn:
        fn_fchk = 'water_sto3g_hf_g03.fchk'
        copy_files(dn, [fn_fchk])
        check_script('horton-cubehead.py %s cubehead.txt' % fn_fchk, dn)
        check_files(dn, ['cubehead.txt'])
Esempio n. 50
0
def test_locked2():
    # test error handling in h5.File constructor
    with assert_raises(IOError):
        with tmpdir('horton.scripts.test.test_common.test_locked2') as dn:
            with LockedH5File('%s/foo.h5' % dn, mode='r', wait=0.1, count=3) as f:
                pass
Esempio n. 51
0
def test_locked4():
    # test error handling of wrong driver
    with assert_raises(ValueError):
        with tmpdir('horton.scripts.test.test_common.test_locked4') as dn:
            with LockedH5File('%s/foo.h5' % dn, driver='core') as f:
                pass
Esempio n. 52
0
def test_locked5():
    # test error handling in with clause
    with assert_raises(RuntimeError):
        with tmpdir('horton.scripts.test.test_common.test_locked5') as dn:
            with LockedH5File('%s/foo.h5' % dn) as f:
                raise RuntimeError