s should be a string taken from columns 12-15 (zero-indexed) inclusive of a PDB coordinate line.

def pdb_atom_name_to_element(s):
    '''s should be a string taken from columns 12-15 (zero-indexed) inclusive of a PDB coordinate line.'''
    assert(len(s) == 4)
    if len(s.strip()) == 4:
        assert(s[0] == 'H' or s[0] == 'C' or s[0] == 'O') # "If the name of a hydrogen has four characters, it is left-justified starting in column 13; if it has fewer than four characters, it is left-justified starting in column 14. If the name of a hydrogen has four characters, it is left-justified starting in column 13; if it has fewer than four characters, it is left-justified starting in column 14."
        return s[0] # I think this works for hydrogen - I do not know if it is generally correct for carbon and oxygen but something like this is necessary - see CE11 in 1DAN. The correct approach is described somewhere in the  IUPAC recommendations (Pure Appl Chem 70:117 (1998), http://www.iupac.org/publications/pac/1998/pdf/7001x0117.pdf.
    else:
        return s[:2].strip()