def get_pdb_to_pose_residue_map(pdb_path, rosetta_scripts_path, rosetta_database_path = None, pdb_id = None, extra_flags = ''):
    '''Takes a path to a PDB file, the RosettaScripts executable, and the Rosetta database and then uses the features database to map PDB residue IDs to pose residue IDs.
       On success, (True, the residue mapping) is returned. On failure, (False, a list of errors) is returned.

       The mapping maps residue IDs to a dict with the three letter residue code and the Rosetta pose id e.g.

           mapping = {
              u'B 435 ': {'name3': u'GLN', 'pose_residue_id': 370, 'res_type': u'GLN'},
              ...
           }

       Note: extra_flags should typically include '-ignore_zero_occupancy false' and '-ignore_unrecognized_res'.'''

    errors = []
    exit_code = 0
    F, script_path = tempfile.mkstemp(dir=".")
    script_handle = os.fdopen(F, "w")

    try:
        db_path = script_path + ".db3"
        script_handle.write(script % db_path)
        script_handle.close()
        if rosetta_database_path:
            command_line = '%s -database %s -constant_seed -in:file:s %s -parser:protocol %s -overwrite -out:nooutput %s' % (rosetta_scripts_path, rosetta_database_path, pdb_path, script_path, extra_flags)
        else:
            command_line = '%s -constant_seed -in:file:s %s -parser:protocol %s -overwrite -out:nooutput %s' % (rosetta_scripts_path, pdb_path, script_path, extra_flags)

        exit_code, stdout = commands.getstatusoutput(command_line)
        if exit_code != 0:
            errors.append("An error occured during execution. The exit code was %d. The output was:\n\n%s" % (exit_code, stdout))
        else:
            try:
                mapping = get_mapping_from_db3_file( db_path )
            except Exception, e:
                errors.append(str(e))
                errors.append(traceback.format_exc())
                errors.append("The features database does not seem to have been correctly created. Check to see if the command '%s' is correct." % command_line)
    except Exception, e:
        errors.append(str(e))
        errors.append(traceback.format_exc())
        exit_code = 1

    if errors and ((extra_flags.find('-ignore_zero_occupancy false') == -1) or (extra_flags.find('-ignore_unrecognized_res') == -1)):
        errors.append("Note: extra_flags should typically include both '-ignore_zero_occupancy false' and '-ignore_unrecognized_res'.")

    if os.path.exists(script_path):
        os.remove(script_path)
    if os.path.exists(db_path):
        os.remove(db_path)
    if exit_code or errors:
        return False, errors

    return True, mapping
Takes a path to a PDB file, the RosettaScripts executable, and the Rosetta database and then uses the features database to map PDB residue IDs to pose residue IDs.
       On success, (True, the residue mapping) is returned. On failure, (False, a list of errors) is returned.

       The mapping maps residue IDs to a dict with the three letter residue code and the Rosetta pose id e.g.

           mapping = {
              u'B 435 ': {'name3': u'GLN', 'pose_residue_id': 370, 'res_type': u'GLN'},
              ...
           }

       Note: extra_flags should typically include '-ignore_zero_occupancy false' and '-ignore_unrecognized_res'.