Exemple #1
0
def test_get_references_1(basis_name, fmt):
    """ Tests getting references for all basis sets

    Also test getting references for a random selection of elements
    """
    this_metadata = bs_metadata[basis_name]
    for ver in this_metadata['versions'].keys():
        bse.get_references(basis_name, fmt=fmt, version=ver)

        avail_elements = this_metadata['versions'][ver]['elements']
        nelements = random.randint(1, len(avail_elements))
        selected_elements = random.sample(avail_elements, nelements)
        bse.get_references(basis_name, elements=selected_elements, fmt=fmt, version=ver)
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
Exemple #3
0
def writebs(md, bas_name, summary_file, get_aux=0):
    md_bas_name = bas_name.lower()
    md_bas_name = md_bas_name.replace("*", "_st_")
    md_bas_name = md_bas_name.replace("/", "_sl_")
    print(' md_bas_name ' + md_bas_name + "\n")
    print(' bas_name ' + bas_name + "\n")
    version_bs = md[md_bas_name]['latest_version']
    elements_list = md[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(" ", "_")
    #replace forward slash with underscore
    file_name = file_name.replace("/", "_")
    #lowercase
    file_name = file_name.lower()
    if get_aux == 1:
        file_name = file_name + "-autoaux"
    print(' file name is ' + file_name + "\n")
    output_file = open(file_name, 'w')
    output_file.write('# BSE Version ' + bse.version() + '\n')
    output_file.write('# Data downloaded on ' + today + '\n')

    if get_aux == 0:
        output_file.write('# ' + bas_name + ' version number ' + version_bs +
                          '\n')
        output_file.write('# Description: ' + md[md_bas_name]['description'] +
                          '\n')
        output_file.write('# Role: ' + md[md_bas_name]['role'] + '\n')
        output_file.write(
            '# ' +
            bse.get_references(bas_name, fmt='txt').replace('\n', '\n# '))
        output_file.write('# \n')
    elif get_aux == 1:
        output_file.write('# ' + bas_name + ' version number ' + version_bs +
                          ' AutoAux \n')
        output_file.write('# Role: JK Fitting \n')
        output_file.write(
            '# Stoychev GL, Auer AA, Neese F. \n# Automatic Generation of Auxiliary Basis Sets.\n# J Chem Theory Comput. 2017 Feb 14;13(2):554-562.\n# doi: 10.1021/acs.jctc.6b01041.\n'
        )
        output_file.write('# \n')

    n_elements = 0
    for element in elements_list:
        n_elements = n_elements + 1
    if get_aux == 1:
        summary_file.write('Basis set \"' + bas_name +
                           '-autoaux\" (number of atoms ' + str(n_elements) +
                           ')\n')
    else:
        summary_file.write('Basis set \"' + bas_name + '\" (number of atoms ' +
                           str(n_elements) + ')\n')
    for element in elements_list:
        #element='h'
        try:
            bs_str = bse.get_basis(bas_name,
                                   header=False,
                                   elements=element,
                                   fmt='nwchem',
                                   optimize_general=True,
                                   uncontract_general=True,
                                   get_aux=get_aux)
        except:
            #            print("failed for"+element)
            pass
        else:
            bs_str = bs_str.replace("BASIS", "basis")
            bs_str = bs_str.replace("END", "end")
            bs_str = bs_str.replace("PRINT", "")
            element_str = bse.misc.compact_elements([element])
            if get_aux == 1:
                bs_str = bs_str.replace(
                    "ao basis", element_str + "_" + bas_name + "-autoaux")
            else:
                bs_str = bs_str.replace("ao basis",
                                        element_str + "_" + bas_name)
            #ECP
            bs_str = bs_str.replace(
                "ECP", "ecp \"" + element_str + "_" + bas_name + "\"")
            output_file.write(bs_str)
            #
            print(bas_name + " " + element_str)
    return
Exemple #4
0
 #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")
 output_file = open(file_name, 'w')
 output_file.write('# BSE Version ' + bse.version() + '\n')
 output_file.write('# Data downloaded at ' + today + '\n')
 output_file.write('# ' + bas_name + ' version number ' + version_bs + '\n')
 output_file.write('# Description: ' + md[bas_name]['description'] + '\n')
 output_file.write('# Role: ' + md[bas_name]['role'] + '\n')
 output_file.write(
     '# ' + bse.get_references(bas_name, fmt='txt').replace('\n', '\n# '))
 output_file.write('# \n')
 for element in elements_list:
     #element='h'
     try:
         bs_str = bse.get_basis(bas_name,
                                header=False,
                                elements=element,
                                fmt='nwchem',
                                optimize_general=True)
     except:
         #            print("failed for"+element)
         pass
     else:
         bs_str = bs_str.replace("BASIS", "basis")
         bs_str = bs_str.replace("END", "end")
Exemple #5
0
    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(" ","_")
    #replace forward slash with underscore
    file_name = file_name.replace("/","_")
    print(' file name is '+file_name+"\n")
    output_file = open(file_name,'w')
    output_file.write('# BSE Version '+bse.version()+'\n')
    output_file.write('# Data downloaded at '+today+'\n')
    output_file.write('# '+bas_name+' version number '+version_bs+'\n')
    output_file.write('# Description: '+md[bas_name]['description']+'\n')
    output_file.write('# Role: '+md[bas_name]['role']+'\n')
    output_file.write('# '+bse.get_references(bas_name,fmt='txt').replace('\n','\n# '))
    output_file.write('# \n')
    for element in elements_list:
        #element='h'
        try:
            bs_str=bse.get_basis(bas_name, header=False, elements=element, fmt='nwchem', optimize_general=True, uncontract_general=True)
        except:
#            print("failed for"+element)
            pass
        else:
            bs_str=bs_str.replace("BASIS","basis")
            bs_str=bs_str.replace("END","end")
            bs_str=bs_str.replace("PRINT","")
            element_str=bse.misc.compact_elements([element])
            bs_str=bs_str.replace("ao basis",element_str+"_"+bas_name)
            #ECP