Does the work of reading the Rosetta SQLite3 .db3 file to retrieve the mapping

def get_mapping_from_db3_file( db_path ):
    '''
    Does the work of reading the Rosetta SQLite3 .db3 file to retrieve the mapping
    '''
    import sqlite3 # should be moved to the top but we do this here for CentOS 5 support

    conn = sqlite3.connect(db_path)
    results = conn.cursor().execute('''
    SELECT chain_id, pdb_residue_number, insertion_code, residues.struct_id, residues.resNum, residues.name3, residues.res_type
    FROM residue_pdb_identification
    INNER JOIN residues ON residue_pdb_identification.struct_id=residues.struct_id AND residue_pdb_identification.residue_number=residues.resNum
    ''')

    # Create the mapping from PDB residues to Rosetta residues
    rosetta_residue_ids = []
    mapping = {}
    for r in results:
        mapping["%s%s%s" % (r[0], str(r[1]).rjust(4), r[2])] = {'pose_residue_id' : r[4], 'name3' : r[5], 'res_type' : r[6]}
        rosetta_residue_ids.append(r[4])

    # Ensure that the the range of the map is exactly the set of Rosetta residues i.e. the map from (a subset of) the PDB residues to the Rosetta residues is surjective
    raw_residue_list = [r for r in conn.cursor().execute('''SELECT resNum, name3 FROM residues ORDER BY resNum''')]
    assert(sorted([r[0] for r in raw_residue_list]) == sorted(rosetta_residue_ids))

    return mapping