def convert_xml(xmlfile):
    bsdict = read_xml(xmlfile)
    outfile = create_json_filename(xmlfile)
    print("New basis file: ", outfile)

    bsdict['molssi_bse_magic'] = 1
    #print(json.dumps(bsdict, indent=4))
    bse.write_json_basis(outfile, bsdict)
def convert_xml_agg(xmlfile):
    atom_dict, table_dict = read_basis_xml_agg(xmlfile)

    atom_basis_path = create_json_filename(xmlfile, 'element')
    table_basis_path = create_json_filename(xmlfile, 'table')

    print("Atom basis: ", atom_basis_path)
    print("Table basis: ", table_basis_path)

    atom_dict['molssi_bse_magic'] = 1
    table_dict['molssi_bse_magic'] = 1
    table_dict['basisSetRole'] = 'orbital'
    bse.write_json_basis(atom_basis_path, atom_dict)
    bse.write_json_basis(table_basis_path, table_dict)
예제 #3
0
    newjs['basisSetReferences'] = ref
    for el, v in newjs['basisSetElements'].items():
        v.pop('elementReferences')

    if len(ref) == 0:
        refname = "noref"
    else:
        refname = '_'.join(ref)

    new_filename = src_base + "_" + refname + ".json"
    print()
    print("New filename: ", new_filename)
    print("Ref(s): ", ref)
    print("Elements in ref: ", elements_in_ref)

    bse.write_json_basis(new_filename, newjs)

    # Go through all the aggregate files and rename
    for el, v in element_files.items():
        for z in elements_in_ref:
            if z in v['basisSetElements']:
                comps = v['basisSetElements'][z]['elementComponents']
                if src in comps:
                    idx = comps.index(src)
                    comps[idx] = new_filename

# Save all the aggregate files
for k, v in element_files.items():
    bse.write_json_basis(k, v)

os.rename(src, src + ".old")
            if not cname in added_map:
                added_map[cname] = []

            added_map[cname].append(k)

            # remove only the equivalent shells
            celements[k]['elementElectronShells'] = [
                x for x in cel['elementElectronShells']
                if not x in sel['elementElectronShells']
            ]

    # rewrite the candidate file
    if changed:
        os.rename(cfile, cfile + ".old")
        bse.write_json_basis(cfile, cdata)

# print out the replacement map
for k, v in replaced_map.items():
    print("Replaced in {}: {}".format(k, v))
for k, v in added_map.items():
    print("Partially replaced in {}: {}".format(k, v))

# Now go through all the atom basis files, doing replacements
for afile in element_files:
    adata = bse.read_json_by_path(afile)

    changed = False

    for k, v in adata['basisSetElements'].items():
        for i, c in enumerate(v['elementComponents']):
        dest_elements[k] = v
    else:
        dest_el = dest_elements[k]
        dest_el['elementReferences'].extend(v['elementReferences'])
        dest_el['elementElectronShells'].extend(v['elementElectronShells'])

# Handle a rename
for f in element_files:
    changed = False
    data = bse.read_json_by_path(f)
    for k, v in data['basisSetElements'].items():
        if src_base in v['elementComponents']:
            changed = True
            print("Found in {} {}".format(f, k))
            v['elementComponents'] = [
                dest_base if x == src_base else x
                for x in v['elementComponents']
            ]

    if changed:
        os.rename(f, f + ".old")
        bse.write_json_basis(f, data)

# Rename the old file
os.rename(src, src + '.old')

# Rename the old description file
if os.path.isfile(src_base + '.txt'):
    src_desc_file = src_base + '.txt'
    os.rename(src_desc_file, src_desc_file + '.old')
def create_xml_agg(xmlfile):
    # Create from a simple (non-composed) basis
    atom_basis_file = create_json_filename(xmlfile, 'element')
    table_basis_file = create_json_filename(xmlfile, 'table')

    # Needed for the table entry
    atom_basis_file = create_json_filename(xmlfile, 'element')

    json_file = os.path.basename(create_json_filename(xmlfile))

    bs = read_xml(xmlfile)

    # May be none
    ecp_file = get_ecp_file(xmlfile)
    if ecp_file:
        ecp_json = create_json_filename(ecp_file)

    elementlist = list(bs['basisSetElements'].keys())

    atom_elements = {
        k: {
            'elementComponents': [json_file]
        }
        for k in elementlist
    }
    table_elements = {
        k: {
            'elementEntry': atom_basis_file
        }
        for k in elementlist
    }

    # Handle elements with ecp
    if ecp_file:
        ecp_data = bse.read_json_basis(ecp_json)
        ecp_elements = list(ecp_data['basisSetElements'].keys())

        for k in ecp_elements:
            if not k in atom_elements:
                atom_elements[k] = {'elementComponents': [ecp_json]}
            else:
                atom_elements[k]['elementComponents'].append(ecp_json)

    # Create the actual dictionaries

    atom_dict = {
        'basisSetName': bs['basisSetName'],
        'basisSetDescription': bs['basisSetDescription'],
        'basisSetElements': atom_elements
    }

    table_dict = {
        'basisSetName': bs['basisSetName'],
        'basisSetDescription': bs['basisSetDescription'],
        'basisSetElements': table_elements
    }

    atom_dict['molssi_bse_magic'] = 1
    table_dict['molssi_bse_magic'] = 1
    table_dict['basisSetRole'] = 'orbital'
    bse.write_json_basis(atom_basis_file, atom_dict)
    bse.write_json_basis(table_basis_file, table_dict)
예제 #7
0
        reffile = os.path.join(ref_dir, elref + '.json')
        file_ref_json = None
        if os.path.isfile(reffile):
            with open(reffile, 'r') as ftmp:
                file_ref_json = json.loads(ftmp.read())
        else:
            print("Missing file {}".format(reffile))
            continue

        elref_data = find_Z(file_ref_json, el)
        new_references = []

        for d in elref_data:
            if 'article' in d:
                new_references.append(d['article'])
                if not d['article'] in refdata:
                    print("File: ", f)
                    print("reffile: ", reffile)
                    raise RuntimeError(
                        "Reference {} not found in REFERENCES".format(
                            d['article']))
            else:
                print("No article: {}".format(reffile))

        #print("    Articles: ", new_references)
        data['elementReferences'] = new_references

    #os.rename(f, f+'.old')
    bse.write_json_basis(f, file_data)