def nbnd(calc, val):
    """If nbnd is negative, assign additional bands of that quantity.

    https://www.quantum-espresso.org/Doc/INPUT_PW.html#nbnd
    """
    assert isinstance(val, int)
    if val < 0 and calc.atoms:
        nvalence, nel = calc.get_nvalence()
        if calc.get_param('noncolin'):
            val = nvalence.sum() - val * 2
        else:
            val = int(nvalence.sum() / 2) - val
    return val
