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)
Exemple #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)
Exemple #3
0
def test_read_write_basis(file_path):
    # needed to be tested to make sure something isn't left
    # out of the sort lists, etc
    full_path = os.path.join(_data_dir, file_path)
    full_path_new = full_path + '.new'
    data = fileio.read_json_basis(full_path)
    fileio.write_json_basis(full_path_new, data)
    os.remove(full_path_new)
Exemple #4
0
def test_diff_json_files_same(tmp_path):
    tmp_path = str(tmp_path)  # Needed for python 3.5

    filename = 'def2-SV-base.1.json'
    file1 = os.path.join(data_dir, 'ahlrichs', 'SV', filename)
    tmpfile = os.path.join(tmp_path, filename)
    shutil.copyfile(file1, tmpfile)

    curate.diff_json_files([tmpfile], [tmpfile])

    diff_file = tmpfile + '.diff'
    assert os.path.isfile(diff_file)

    diff_data = fileio.read_json_basis(diff_file)
    assert len(diff_data['elements']) == 0
Exemple #5
0
def test_add_basis(tmp_path):
    tmp_path = str(tmp_path)  # Needed for python 3.5
    for sf, refs in _source_data.items():
        sf_path = os.path.join(auth_data_dir, sf)

        name = sf.split('.')[0]
        curate.add_basis(sf_path, tmp_path, 'test_subdir', 'test_' + name,
                         'test_basis_' + name, 'test_family', 'orbital',
                         'Test Basis Description: ' + name, '1',
                         'Test Basis Revision Description', 'Test Source',
                         refs)

    md = api.get_metadata(tmp_path)
    assert len(md) == len(_source_data)

    # Re-read
    for sf in _source_data.keys():
        name = name = sf.split('.')[0]
        name = 'test_basis_' + name
        bse_dict = api.get_basis(name, data_dir=tmp_path)

        assert bse_dict['family'] == 'test_family'

        # Compare against the file we created from
        sf_path = os.path.join(auth_data_dir, sf)
        assert curate.compare_basis_against_file(name,
                                                 sf_path,
                                                 data_dir=tmp_path)

        # Check that all the files exist and contain the right elements
        for fpath, elements in _expected_files.items():
            fpath = os.path.join(tmp_path, fpath)
            assert os.path.isfile(fpath)

            fdata = fileio.read_json_basis(fpath)
            expect_elements = set(misc.expand_elements(elements, True))
            assert set(fdata['elements'].keys()) == expect_elements

    # Validate the new data dir
    validator.validate_data_dir(tmp_path)
Exemple #6
0
#!/usr/bin/env python3

import re
import sys
import copy
from basis_set_exchange import fileio, lut, manip

base_data = fileio.read_json_basis('ANO-RCC.1.json')

with open('splitmap-ano-rcc.txt', 'r') as f:
    split_lines = f.readlines()

all_names = [
    'ANO-RCC-MB', 'ANO-RCC-VDZ', 'ANO-RCC-VDZP', 'ANO-RCC-VTZP',
    'ANO-RCC-VQZP', 'ANO-RCC-VTZ'
]
split_data = {n: {} for n in all_names}
for l in split_lines:
    name, cont = l.split()
    el1, name1 = name.split('.')
    el2, name2, _, _, cont, _ = cont.split('.')
    assert el1 == el2
    assert name2 == 'ANO-RCC'
    assert name1 in all_names

    el = lut.element_Z_from_sym(el1, as_str=True)
    assert el not in split_data[name1]

    cont = re.findall(r'\d+[a-z]+', cont)
    split_data[name1][el] = cont
def test_print_table_basis(file_path):
    full_path = os.path.join(data_dir, file_path)
    tab = fileio.read_json_basis(full_path)
    curate.print_table_basis(tab)
def test_print_elemental_basis(file_path):
    full_path = os.path.join(data_dir, file_path)
    el = fileio.read_json_basis(full_path)
    curate.print_element_basis(el)
def test_print_component_basis(file_path):
    full_path = os.path.join(data_dir, file_path)
    comp = fileio.read_json_basis(full_path)
    curate.print_component_basis(comp)
Exemple #10
0
def test_print_component_basis(file_path):
    full_path = os.path.join(data_dir, file_path)
    comp = fileio.read_json_basis(full_path)
    printing.component_basis_str(comp)