Esempio 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)
Esempio n. 2
0
def test_reader_equivalent():
    # Test the two dalton formats. These two files are the same basis in the two slightly-different
    # format.
    file1 = os.path.join(reader_test_data_dir, 'dalton', '6-31g.good.1.mol.bz2')
    file2 = os.path.join(reader_test_data_dir, 'dalton', '6-31g.good.2.mol.bz2')
    data1 = readers.read_formatted_basis_file(file1)
    data2 = readers.read_formatted_basis_file(file2)

    assert data1 == data2
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(curate_test_data_dir, filename1)
    file2 = os.path.join(curate_test_data_dir, filename2)

    bs1 = readers.read_formatted_basis_file(file1)
    bs2 = readers.read_formatted_basis_file(file2)

    assert curate.compare_basis(bs1, bs2, rel_tol=1.0e-14)
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)
Esempio n. 5
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)
Esempio n. 6
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)
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)
Esempio n. 8
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)
Esempio n. 9
0
def test_reader(file_rel_path):
    file_path = os.path.join(reader_test_data_dir, file_rel_path)
    is_bad = ".bad." in os.path.basename(file_path)

    if is_bad:
        # Read the first line of the file. This will contain the string
        # that should match the exception
        with bz2.open(file_path, 'rt', encoding='utf-8') as tf:
            match = tf.readline()

        # Get what we want to match as part of the exception
        match = match[8:].strip()

        with pytest.raises(Exception, match=match):
            readers.read_formatted_basis_file(file_path)
    else:
        # Also validate the result (as both component and minimal)
        readers.read_formatted_basis_file(file_path, validate=True, as_component=True)
        readers.read_formatted_basis_file(file_path, validate=True, as_component=False)
def test_duplicate_fail(filename):
    filepath = os.path.join(curate_test_data_dir, filename)
    filedata = readers.read_formatted_basis_file(filepath, 'nwchem')
    _test_duplicates(filedata, True)