def test_manip_roundtrip_slow(basis):
    bse_dict = api.get_basis(basis)
    bse_dict_gen = manip.make_general(bse_dict)
    bse_dict_unc = manip.uncontract_general(bse_dict_gen)
    bse_dict_unc = manip.prune_basis(bse_dict_unc)
    bse_dict_sort = sort.sort_basis(bse_dict_unc)

    bse_dict = manip.uncontract_general(bse_dict)
    bse_dict = manip.uncontract_spdf(bse_dict)
    assert curate.compare_basis(bse_dict, bse_dict_unc, rel_tol=0.0)
    assert curate.compare_basis(bse_dict, bse_dict_sort, rel_tol=0.0)

    bse_dict_gen = manip.prune_basis(bse_dict_gen)
    bse_dict_gen2 = manip.make_general(bse_dict_unc)
    bse_dict_gen2 = manip.prune_basis(bse_dict_gen2)
    assert curate.compare_basis(bse_dict_gen, bse_dict_gen2, rel_tol=0.0)
Ejemplo n.º 2
0
def test_diff_json_files(tmp_path):
    tmp_path = str(tmp_path)  # Needed for python 3.5

    filename1 = '6-31G_s_s-full.json.bz2'
    filename2 = '6-31G-full.json.bz2'

    file1 = os.path.join(test_data_dir, filename1)
    file2 = os.path.join(test_data_dir, filename2)

    tmpfile1 = os.path.join(tmp_path, filename1)
    tmpfile2 = os.path.join(tmp_path, filename2)

    shutil.copyfile(file1, tmpfile1)
    shutil.copyfile(file2, tmpfile2)

    curate.diff_json_files([tmpfile1], [tmpfile2])
    curate.diff_json_files([tmpfile2], [tmpfile1])

    diff1 = fileio.read_json_basis(tmpfile1 + '.diff')
    diff2 = fileio.read_json_basis(tmpfile2 + '.diff')

    assert len(diff1['elements']) == 36
    assert len(diff2['elements']) == 0

    reffilename = '6-31G_s_s-polarization.json.bz2'
    reffile = os.path.join(test_data_dir, reffilename)
    refdata = fileio.read_json_basis(reffile)

    assert curate.compare_basis(diff1, refdata, rel_tol=0.0)
Ejemplo n.º 3
0
def test_manip_steep_augmentation(testdir):
    full_testdir = os.path.join(steep_augmentation_test_data_dir, testdir)
    basefile = testdir + '.nw.bz2'
    base_data = readers.read_formatted_basis_file(
        os.path.join(full_testdir, basefile))

    for slevel, sprefix in [(0, ''), (1, 's'), (2, 'd')]:
        # diffuse level 0 is augmented, 1 is doubly augmented
        for dlevel, dprefix in [(0, ''), (1, 'd'), (2, 't')]:
            if slevel == 0 and dlevel == 0:
                continue
            ref = testdir.replace('un-', 'un{}-'.format(sprefix)).replace(
                'aug-', '{}aug-'.format(dprefix)) + '.nw.ref.bz2'
            full_ref_path = os.path.join(full_testdir, ref)
            ref_data = readers.read_formatted_basis_file(
                full_ref_path, 'nwchem')
            ref_data = manip.make_general(ref_data)

            new_data = copy.deepcopy(base_data)
            if slevel > 0:
                new_data = manip.geometric_augmentation(new_data,
                                                        slevel,
                                                        steep=True)
            if dlevel > 0:
                new_data = manip.geometric_augmentation(new_data,
                                                        dlevel,
                                                        steep=False)
            # The basis has to be sorted, since this also happens in the writers
            new_data = sort.sort_basis(new_data)
            new_data = manip.make_general(new_data)
            assert curate.compare_basis(new_data, ref_data)
Ejemplo n.º 4
0
def test_curatecli_makediff(tmp_path):
    tmp_path = str(tmp_path)  # Needed for python 3.5

    filename1 = '6-31G_s_s-full.json.bz2'
    filename2 = '6-31G-full.json.bz2'

    file1 = os.path.join(curate_test_data_dir, filename1)
    file2 = os.path.join(curate_test_data_dir, filename2)

    tmpfile1 = os.path.join(tmp_path, filename1)
    tmpfile2 = os.path.join(tmp_path, filename2)

    shutil.copyfile(file1, tmpfile1)
    shutil.copyfile(file2, tmpfile2)

    _test_curatecli_cmd('make-diff -l {} -r {}'.format(tmpfile1, tmpfile2))
    _test_curatecli_cmd('make-diff -l {} -r {}'.format(tmpfile2, tmpfile1))

    diff1 = fileio.read_json_basis(tmpfile1 + '.diff')
    diff2 = fileio.read_json_basis(tmpfile2 + '.diff')

    assert len(diff1['elements']) == 36
    assert len(diff2['elements']) == 0

    reffilename = '6-31G_s_s-polarization.json.bz2'
    reffile = os.path.join(curate_test_data_dir, reffilename)
    refdata = fileio.read_json_basis(reffile)

    assert curate.compare_basis(diff1, refdata, rel_tol=0.0)
def test_curate_roundtrip(basis, fmt):

    # Many formats have limitations on general contractions
    if fmt == 'gaussian94':
        uncontract_general = True
        uncontract_spdf = 1
    if fmt == 'turbomole':
        uncontract_general = True
        uncontract_spdf = 0
    if fmt == 'nwchem':
        uncontract_general = False
        uncontract_spdf = 1

    bse_formatted = api.get_basis(basis, fmt=fmt)
    bse_dict = api.get_basis(basis, uncontract_general=uncontract_general)
    bse_dict = manip.uncontract_spdf(bse_dict, uncontract_spdf)

    outfile = tempfile.NamedTemporaryFile(mode='w', delete=False)
    outfile_path = outfile.name
    outfile.write(bse_formatted)
    outfile.close()

    test_dict = curate.read_formatted_basis(outfile_path, fmt)
    os.remove(outfile_path)

    test_dict = manip.sort_basis(test_dict)
    bse_dict = manip.sort_basis(bse_dict)

    # Compare, ignoring metadata (not stored in most formats)
    assert curate.compare_basis(bse_dict, test_dict, rel_tol=0.0)
Ejemplo n.º 6
0
def test_manip_roundtrip(basis):
    bse_dict = api.get_basis(basis,
                             uncontract_general=True,
                             uncontract_spdf=True)
    bse_dict_gen = manip.make_general(bse_dict)
    bse_dict_unc = manip.uncontract_general(bse_dict_gen)

    assert curate.compare_basis(bse_dict, bse_dict_unc, rel_tol=0.0)
Ejemplo n.º 7
0
def test_g94_scaling(tmp_path):
    tmp_path = str(tmp_path)  # Needed for python 3.5

    filename1 = 'sbo4-dz-scaled.gbs.bz2'
    filename2 = 'sbo4-dz-unscaled.gbs.bz2'

    file1 = os.path.join(test_data_dir, filename1)
    file2 = os.path.join(test_data_dir, filename2)

    bs1 = curate.read_formatted_basis(file1)
    bs2 = curate.read_formatted_basis(file2)

    assert curate.compare_basis(bs1, bs2, rel_tol=1.0e-14)
Ejemplo n.º 8
0
def test_manip_dunningext(testdir):
    full_testdir = os.path.join(dunningext_test_data_dir, testdir)
    basefile = testdir + '.nw.bz2'
    base_data = readers.read_formatted_basis_file(os.path.join(full_testdir, basefile))

    for level, prefix in [(2, 'd-'), (3, 't-'), (4, 'q-')]:
        ref = prefix + testdir + '.nw.ref.bz2'
        full_ref_path = os.path.join(full_testdir, ref)
        ref_data = readers.read_formatted_basis_file(full_ref_path, 'nwchem')
        ref_data = manip.make_general(ref_data)

        new_data = manip.extend_dunning_aug(base_data, level)
        new_data = manip.make_general(new_data)
        assert curate.compare_basis(new_data, ref_data)
Ejemplo n.º 9
0
def test_manip_remove_free(testdir):
    full_testdir = os.path.join(rmfree_test_data_dir, testdir)
    basefile = testdir + '.nw.bz2'
    base_data = readers.read_formatted_basis_file(
        os.path.join(full_testdir, basefile))

    ref = 'min_' + testdir + '.nw.ref.bz2'
    full_ref_path = os.path.join(full_testdir, ref)
    ref_data = readers.read_formatted_basis_file(full_ref_path, 'nwchem')
    ref_data = manip.make_general(ref_data)

    new_data = manip.remove_free_primitives(base_data)
    new_data = manip.make_general(new_data)
    assert curate.compare_basis(new_data, ref_data)
Ejemplo n.º 10
0
def test_manip_diffuse_augmentation(testdir):
    full_testdir = os.path.join(diffuse_augmentation_test_data_dir, testdir)
    basefile = testdir + '.nw.bz2'
    base_data = readers.read_formatted_basis_file(
        os.path.join(full_testdir, basefile))

    for level, prefix in [(1, 'd'), (2, 't'), (3, 'q')]:
        ref = prefix + testdir + '.nw.ref.bz2'
        full_ref_path = os.path.join(full_testdir, ref)
        ref_data = readers.read_formatted_basis_file(full_ref_path, 'nwchem')
        ref_data = manip.make_general(ref_data)

        new_data = manip.geometric_augmentation(base_data, level, steep=False)
        new_data = manip.make_general(new_data)
        assert curate.compare_basis(new_data, ref_data)
Ejemplo n.º 11
0
def test_manip_truhlar(testdir):
    full_testdir = os.path.join(truhlar_test_data_dir, testdir)
    basefile = 'aug-' + testdir + '.nw.bz2'
    base_data = readers.read_formatted_basis_file(os.path.join(full_testdir, basefile))

    ref_files = os.listdir(full_testdir)
    ref_files = [x for x in ref_files if x.endswith('.ref.bz2')]

    # Made a mistake here once where reference files weren't being read
    assert ref_files

    for ref in ref_files:
        month = ref.split('-')[0]
        full_ref_path = os.path.join(full_testdir, ref)
        ref_data = readers.read_formatted_basis_file(full_ref_path, 'nwchem')
        ref_data = manip.make_general(ref_data)

        new_data = manip.truhlar_calendarize(base_data, month, use_copy=True)
        assert curate.compare_basis(new_data, ref_data)
Ejemplo n.º 12
0
def test_curate_roundtrip(tmp_path, basis, fmt):
    tmp_path = str(tmp_path)  # Needed for python 3.5

    # Many formats have limitations on general contractions
    if fmt == 'gaussian94':
        uncontract_general = True
        make_general = False
        uncontract_spdf = 1
    if fmt == 'turbomole':
        uncontract_general = True
        make_general = False
        uncontract_spdf = 0
    if fmt == 'nwchem':
        uncontract_general = False
        make_general = False
        uncontract_spdf = 1
    if fmt == 'cfour':
        uncontract_general = False
        make_general = True
        uncontract_spdf = 0

    bse_formatted = api.get_basis(basis, fmt=fmt)
    bse_dict = api.get_basis(basis,
                             uncontract_general=uncontract_general,
                             make_general=make_general)
    bse_dict = manip.uncontract_spdf(bse_dict, uncontract_spdf)

    outfile_path = os.path.join(tmp_path, 'roundtrip.txt')
    with open(outfile_path, 'w', encoding='utf-8') as outfile:
        outfile.write(bse_formatted)

    test_dict = readers.read_formatted_basis_file(outfile_path, fmt)

    test_dict = sort.sort_basis(test_dict)
    bse_dict = sort.sort_basis(bse_dict)

    # Compare, ignoring metadata (not stored in most formats)
    assert curate.compare_basis(bse_dict, test_dict, rel_tol=0.0)