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']
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
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)
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']
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)
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"]
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']
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 sys = 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) sys_sym = System.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 == (sys_sym.extra['symmetry'].natom, 2)
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']
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)
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
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)
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)
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)
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
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']
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
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)
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
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)
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'])
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)