“cmd.count_states” returns the number of states in the selection.
cmd.count_states(string selection)
def count_states(selection="(all)", quiet=1):
count_states | cmd.frame | api