import re


def parse_calpha_pdb (pdbfile):
    """
    Parse the coordinates of the c-alpha atoms from the given pdb file
   
    Parameters:
        pdb_file: The PDB file with path
    Returns:
        PDB_struct: A dictionary containing the parsed information
    """ 
    PDB_struct = {}
    fh = open(pdbfile, 'r')
    for line in fh:
        if re.match('^ATOM', line):
            atomname = line[13:15]
            atomname = atomname.replace(' ', '')
            # Only consider the information for the c-alpha atoms
            if atomname != 'CA':
                continue
            chain = line[21]
            X_coord = line[30:38]
            Y_coord = line[38:46]
            Z_coord = line[46:54]
            
            # Strip white space
            X_coord = re.sub('\s+','',X_coord)
            Y_coord = re.sub('\s+','',Y_coord)
            Z_coord = re.sub('\s+','',Z_coord)
            
            # convert from string to numeric
            X_coord = float(X_coord)
            Y_coord = float(Y_coord) 
            Z_coord = float(Z_coord)	
            
            res_name = line[17:20]
            res_id = line[22:26]
            
            res_name = re.sub('\s+','',res_name)
            res_id = re.sub('\s+','',res_id)
            res_id = int(res_id)
            if chain not in PDB_struct.keys():
                PDB_struct[chain] = dict()
                PDB_struct[chain]['COORD'] = []
                PDB_struct[chain]['RESNAME'] = []
                PDB_struct[chain]['RESID'] = []
                PDB_struct[chain]['ATOM_NAME'] = []
            PDB_struct[chain]['COORD'].append([X_coord, Y_coord, Z_coord])
            PDB_struct[chain]['RESNAME'].append(res_name)
            PDB_struct[chain]['RESID'].append(res_id)
            PDB_struct[chain]['ATOM_NAME'].append(atomname)
    fh.close()
    return PDB_struct