<commit_before>"""
Common basis set manipulations (such as uncontracting)
"""

import json
import os
import copy
from . import lut


def contraction_string(element):
    """
    Forms a string specifying the contractions for an element

    ie, (16s,10p) -> [4s,3p]
    """

    if 'elementElectronShells' not in element:
        return ""

    cont_map = dict()
    for sh in element['elementElectronShells']:
        nprim = len(sh['shellExponents'])

        for am in sh['shellAngularMomentum']:
            if am not in cont_map:
                cont_map[am] = (nprim, 1)
            else:
                cont_map[am] = (cont_map[am][0] + nprim, cont_map[am][1] + 1)

    primstr = ""
    contstr = ""
    for am in sorted(cont_map.keys()):
        nprim, ncont = cont_map[am]

        if am != 0:
            primstr += ','
            contstr += ','
        primstr += str(nprim) + lut.amint_to_char([am])
        contstr += str(ncont) + lut.amint_to_char([am])

    return "({}) -> [{}]".format(primstr, contstr)


def check_compatible_merge(dest, source):
    """
    TODO - check for any incompatibilities between the two elements
    """
    pass
<commit_msg>Fix contraction strings with generally-contracted shells<commit_after>"""
Common basis set manipulations (such as uncontracting)
"""

import json
import os
import copy
from . import lut


def contraction_string(element):
    """
    Forms a string specifying the contractions for an element

    ie, (16s,10p) -> [4s,3p]
    """

    if 'elementElectronShells' not in element:
        return ""

    cont_map = dict()
    for sh in element['elementElectronShells']:
        nprim = len(sh['shellExponents'])
        ngeneral = len(sh['shellCoefficients'])

        # is a combined general contraction (sp, spd, etc)
        is_spdf = len(sh['shellAngularMomentum']) > 1

        for am in sh['shellAngularMomentum']:
            # If this a general contraction (and not combined am), then use that
            ncont = ngeneral if not is_spdf else 1

            if am not in cont_map:
                cont_map[am] = (nprim, ncont)
            else:
                cont_map[am] = (cont_map[am][0] + nprim, cont_map[am][1] + ncont)

    primstr = ""
    contstr = ""
    for am in sorted(cont_map.keys()):
        nprim, ncont = cont_map[am]

        if am != 0:
            primstr += ','
            contstr += ','
        primstr += str(nprim) + lut.amint_to_char([am])
        contstr += str(ncont) + lut.amint_to_char([am])

    return "({}) -> [{}]".format(primstr, contstr)


def check_compatible_merge(dest, source):
    """
    TODO - check for any incompatibilities between the two elements
    """
    pass

{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.00818452380952381, 'mean_word_length': 2.416772554002541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1913356', 'n_tokens_mistral': 894, 'n_tokens_neox': 847, 'n_words': 235}