Did you try residue.natoms() and/or residue_type.natoms()? I haven’t looked at the python but that’s the name of the call in C++.
There is no pose-based all atoms accessor for atoms, you’ll need to use the residue level.
Separately, as a general rule, you should probably not be looping through atoms and resetting their 3d coordinates. You should instead determine the single DOF in the atom tree you need to change to get the alteration you want and change that instead. For example, you’d alter the jump connecting the peptide to (whatever), rather than altering the positions of each atom in the peptide.