예제 #1
0
def _run_test_bundles(tmp_path, fmt, reffmt, ext, data_dir):
    '''Test functionality related to creating archive of basis set'''

    tmp_path = str(tmp_path)  # Needed for python 3.5

    bs_ext = bse.writers.get_format_extension(fmt)
    ref_ext = bse.refconverters.get_format_extension(reffmt)

    filename = "bundletest_" + fmt + "_" + reffmt + ext
    filepath = os.path.join(tmp_path, filename)

    bse.create_bundle(filepath, fmt, reffmt, None, data_dir)
    extract_dir = "extract_" + filename
    extract_path = os.path.join(tmp_path, extract_dir)
    _extract_all(filepath, extract_path)

    # Keep track of all the basis sets we have found
    # Start with all found in the data dir, and remove
    # each time we process one
    all_bs = []
    for k, v in bse.get_metadata(data_dir).items():
        for ver in v['versions'].keys():
            all_bs.append((k, ver))

    all_ref = all_bs.copy()

    for root, dirs, files in os.walk(extract_path):
        for basename in files:
            if basename == 'README.txt':
                continue

            fpath = os.path.join(root, basename)
            name, ver = basename.split('.')[:2]
            tr_name = bse.misc.basis_name_from_filename(name)

            if basename.endswith('.ref' + ref_ext):
                compare_data = bse.get_references(tr_name,
                                                  fmt=reffmt,
                                                  version=ver,
                                                  data_dir=data_dir)
                all_ref.remove((name, ver))
            elif basename.endswith(bs_ext):
                compare_data = bse.get_basis(name,
                                             fmt=fmt,
                                             version=ver,
                                             data_dir=data_dir)
                all_bs.remove((name, ver))
            elif basename.endswith('.family_notes'):
                compare_data = bse.get_family_notes(name, data_dir)
            elif basename.endswith('.notes'):
                compare_data = bse.get_basis_notes(name, data_dir)
            else:
                raise RuntimeError("Unknown file found: " + fpath)

            with open(fpath, 'r', encoding='utf-8') as ftmp:
                assert compare_data == ftmp.read()

    assert len(all_bs) == 0
    assert len(all_ref) == 0
예제 #2
0
파일: basisset.py 프로젝트: kyusque/FMOe
def main():
    d = {}
    for basisset_name, meta in basis_set_exchange.get_metadata().items():
        basisset = {}
        elements = basis_set_exchange.get_basis(
            basisset_name)['basis_set_elements']

        try:
            for Z in meta['versions'][meta['latest_version']]['elements']:
                element = basis_set_exchange.lut.element_data_from_Z(
                    Z)[0].capitalize()
                shells = elements[Z].get('element_electron_shells')
                if shells is None:
                    raise ValueError('no shells: {}/{}'.format(
                        basisset_name, element))
                basisset[element] = number_of_functions(shells)

        except ValueError as e:
            print(e, file=sys.stderr)
        else:
            d[basisset_name] = basisset

    json.dump(d, sys.stdout)
'''
Some data common to all tests
'''

import os
import basis_set_exchange as bse

# The directory containing this file
_my_dir = os.path.dirname(os.path.abspath(__file__))

# Use random for getting sets of elements
rand_seed = 39466  # from random.org

# Load all the metadata once
data_dir = bse.api._default_data_dir
bs_metadata = bse.get_metadata()
bs_names = list(bs_metadata.keys())
bs_read_formats = list(bse.get_reader_formats().keys())
bs_write_formats = list(bse.get_writer_formats()) + [None]
bs_write_formats_ecp = list(bse.get_writer_formats(['scalar_ecp'
                                                    ]).keys()) + [None]
bs_write_formats_noecp = list(
    set(bs_write_formats) - set(bs_write_formats_ecp))
ref_formats = list(bse.get_reference_formats().keys()) + [None]
all_families = bse.get_families()
all_roles = bse.get_roles()
true_false = [True, False]

# All basis names/versions combinations
bs_names_vers = []
for k, v in bs_metadata.items():
예제 #4
0
def list_basis_sets() -> Tuple[str, str]:
    return sorted((v['display_name'], v['display_name']) for k, v in bse.get_metadata().items())
예제 #5
0
#!/usr/bin/env python3

# This script determines what basis sets are missing authoritative sources
# that should be placed in this directory

import os
from basis_set_exchange import get_metadata, misc

my_dir = os.path.dirname(os.path.abspath(__file__))
auth_sources = [x for x in os.listdir(my_dir) if x.endswith('.bz2')]

md = get_metadata()

found_ver = {}

# Start with everything in the metadata, removing what we find
# in this directory
missing = {k: list(v['versions'].keys()) for k, v in md.items()}

for s in auth_sources:
    bsname, ver, _, _ = s.split('.')

    if not bsname in missing:
        raise RuntimeError(
            "Source {} does not correspond to a basis set in the library".
            format(bsname))
    if not ver in missing[bsname]:
        raise RuntimeError(
            "Source {} version {} does not correspond to a basis set version in the library"
            .format(bsname, ver))
예제 #6
0
# to use, set the env. variable NWCHEM_BASIS_LIBRARY=$NWCHEM_TOP/src/basis/libraries.bse/
# Requires the installation of the python env. from
# https://github.com/MolSSI-BSE/basis_set_exchange
# See https://molssi-bse.github.io/basis_set_exchange/
#
# names changed
# def2-universal-jfit was weigend_coulomb_fitting
# dgauss-a1-dftjfit   was dgauss_a1_dft_coulomb_fitting
# dgauss-a2-dftjfit   was dgauss_a2_dft_coulomb_fitting
#
import basis_set_exchange as bse
from datetime import datetime
today = datetime.now().isoformat(timespec='minutes')
print(today)
all_bs = bse.get_all_basis_names()
md = bse.get_metadata()
for bas_name in all_bs:
    #get version and list of elements
    version_bs = md[bas_name]['latest_version']
    elements_list = md[bas_name]['versions'][version_bs]['elements']
    #open file
    # get rid of asterisks
    file_name = bas_name.replace("*", "s")
    #get rid of parenthesis
    file_name = file_name.replace("(", "")
    file_name = file_name.replace(")", "")
    #replace commas with underscore
    file_name = file_name.replace(",", "_")
    #replace whitespace with underscore
    file_name = file_name.replace(" ", "_")
    print(' file name is ' + file_name + "\n")