def get_CA_or(res: Residue) -> Atom: """Returns the alpha carbon for the resiude if there is one, else the first atom in the list""" atoms: List[Atom] = list(res.get_atoms()) alphacarbons = list( filter(lambda atom: True if atom.get_name() == 'CA' else False, atoms)) return atoms[0] if len(alphacarbons) == 0 else alphacarbons[0]
def get_alpha_carbon(res:Residue)->Atom: """Get the first(only) alpha carbon in the residue or an exception""" alpha_carbons: List[Atom] = list( filter(lambda internal_atom: internal_atom.get_id() =='CA', res.get_atoms()) ) if len(alpha_carbons) != 1: raise Exception(f"Alpha carbon not found or duplicated in residue {res.get_full_id()}") return alpha_carbons[0]