Exemplo n.º 1
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)
Exemplo n.º 2
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)
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)