@value.setter
def value(self, value):
    PATTERNS = ('^(\\d)(\\w)(\\d+),(\\d)(\\w)(\\d+)$', '^(\\d)(\\w)(\\d+)$')
    tokens = (token for pattern in PATTERNS for token in re.findall(pattern, value))
    if (not tokens):
        raise ValueError('Invalid configuration string.')
    [tokens] = tokens
    if (len(tokens) == 3):
        core = None
        valence = tokens
    elif (len(tokens) == 6):
        core = tokens[:3]
        valence = tokens[(- 3):]
    else:
        raise ValueError('Unexpected length of the configuration string.')
    (valenceLevel, valenceShell, valenceOccupancy) = valence
    valenceLevel = int(valenceLevel)
    valenceOccupancy = int(valenceOccupancy)
    if (valenceOccupancy > OCCUPANCIES[valenceShell]):
        raise ValueError('Wrong number of electrons in the valence shell.')
    if core:
        (coreLevel, coreShell, coreOccupancy) = core
        coreLevel = int(coreLevel)
        coreOccupancy = int(coreOccupancy)
        if (coreOccupancy > OCCUPANCIES[coreShell]):
            raise ValueError('Wrong number of electrons in the core shell.')
        self.levels = (coreLevel, valenceLevel)
        self.shells = (coreShell, valenceShell)
        self.occupancies = [coreOccupancy, valenceOccupancy]
    else:
        self.levels = (valenceLevel,)
        self.shells = (valenceShell,)
        self.occupancies = [valenceOccupancy]
    self.subshells = tuple([f'{level}{shell}' for (level, shell) in zip(self.levels, self.shells)])
    self._value = value
@value.setter
def value(self, value):
    PATTERNS = ('^(\\d)(\\w)(\\d+),(\\d)(\\w)(\\d+)$', '^(\\d)(\\w)(\\d+)$')
    tokens = (token for pattern in PATTERNS for token in re.findall(pattern, value))
    if (not tokens):
        raise ValueError('Invalid configuration string.')
    [tokens] = tokens
    if (len(tokens) == 3):
        core = None
        valence = tokens
    elif (len(tokens) == 6):
        core = tokens[:3]
        valence = tokens[(- 3):]
    else:
        raise ValueError('Unexpected length of the configuration string.')
    (valenceLevel, valenceShell, valenceOccupancy) = valence
    valenceLevel = int(valenceLevel)
    valenceOccupancy = int(valenceOccupancy)
    if (valenceOccupancy > OCCUPANCIES[valenceShell]):
        raise ValueError('Wrong number of electrons in the valence shell.')
    if core:
        (coreLevel, coreShell, coreOccupancy) = core
        coreLevel = int(coreLevel)
        coreOccupancy = int(coreOccupancy)
        if (coreOccupancy > OCCUPANCIES[coreShell]):
            raise ValueError('Wrong number of electrons in the core shell.')
        self.levels = (coreLevel, valenceLevel)
        self.shells = (coreShell, valenceShell)
        self.occupancies = [coreOccupancy, valenceOccupancy]
    else:
        self.levels = (valenceLevel,)
        self.shells = (valenceShell,)
        self.occupancies = [valenceOccupancy]
    self.subshells = tuple([f'{level}{shell}' for (level, shell) in zip(self.levels, self.shells)])
    self._value = value