Exemple #1
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)
Exemple #2
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
Exemple #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
Exemple #4
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
Exemple #5
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)
Exemple #6
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