import configparser


def opts_to_cfg(opts):
    """ creates the configuration file corresponding to input options

    Args:
      opts (dict): option dictionary for which to create a configuration object

    Returns:
      config (ConfigParser): configuration object containing formatted options
    """

    config = configparser.ConfigParser()

    config.add_section("General")
    if opts.get("prot_file") is not None:
        config.set("General", "prot_file", str(opts.get("prot_file")))
    if opts.get("lig_file") is not None:
        config.set("General", "lig_file", str(opts.get("lig_file")))
    if opts.get("min_rad") is not None:
        config.set("General", "min_rad", str(opts.get("min_rad")))
    if opts.get("max_rad") is not None:
        config.set("General", "max_rad", str(opts.get("max_rad")))
    if opts.get("constrain_radii") is not None:
        config.set("General", "constrain_radii", str(opts.get("constrain_radii")))

    config.add_section("Specification")
    if opts.get("mode") is not None:
        config.set("Specification", "mode", str(opts.get("mode")))
    if opts.get("resid") is not None:
        config.set("Specification", "resid", str(opts.get("resid")))
    if opts.get("coordinates") is not None:
        config.set("Specification", "coordinates", str(opts.get("coordinates")))
    if opts.get("lig_excl_rad") is not None:
        config.set("Specification", "lig_excl_rad", str(opts.get("lig_excl_rad")))
    if opts.get("lig_incl_rad") is not None:
        config.set("Specification", "lig_incl_rad", str(opts.get("lig_incl_rad")))
    if opts.get("min_volume") is not None:
        config.set("Specification", "min_volume", str(opts.get("min_volume")))

    config.add_section("Partitioning")
    if opts.get("subdivide") is not None:
        config.set("Partitioning", "subdivide", str(opts.get("subdivide")))
    if opts.get("max_clusters") is not None:
        config.set("Partitioning", "max_clusters", str(opts.get("max_clusters")))
    if opts.get("min_subpocket_rad") is not None:
        config.set("Partitioning", "min_subpocket_rad", str(opts.get("min_subpocket_rad")))
    if opts.get("max_subpocket_rad") is not None:
        config.set("Partitioning", "max_subpocket_rad", str(opts.get("max_subpocket_rad")))
    if opts.get("min_subpocket_surf_rad") is not None:
        config.set("Partitioning", "min_subpocket_surf_rad", str(opts.get("min_subpocket_surf_rad")))
    if opts.get("radial_sampling") is not None:
        config.set("Partitioning", "radial_sampling", str(opts.get("radial_sampling")))
    if opts.get("inclusion_radius_buffer") is not None:
        config.set("Partitioning", "inclusion_radius_buffer", str(opts.get("inclusion_radius_buffer")))
    if opts.get("min_cluster_size") is not None:
        config.set("Partitioning", "min_cluster_size", str(opts.get("min_cluster_size")))

    config.add_section("Output")
    if opts.get("project_dir") is not None:
        config.set("Output", "project_dir", str(opts.get("project_dir")))
    if opts.get("output_dir") is not None:
        config.set("Output", "output_dir", str(opts.get("output_dir")))
    if opts.get("prefix") is not None:
        config.set("Output", "prefix", str(opts.get("prefix")))
    if opts.get("logger_stream_level") is not None:
        config.set("Output", "logger_stream_level", str(opts.get("logger_stream_level")))
    if opts.get("logger_file_level") is not None:
        config.set("Output", "logger_file_level", str(opts.get("logger_file_level")))


    config.add_section("PyMOL")
    if opts.get("protein") is not None:
        config.set("PyMOL", "protein", str(opts.get("protein")))
    if opts.get("ligand") is not None:
        config.set("PyMOL", "ligand", str(opts.get("ligand")))
    if opts.get("protein_only") is not None:
        config.set("PyMOL", "protein_only", str(opts.get("protein_only")))
    if opts.get("display_mode") is not None:
        config.set("PyMOL", "display_mode", str(opts.get("display_mode")))
    if opts.get("palette") is not None:
        config.set("PyMOL", "palette", str(opts.get("palette")))
    if opts.get("alpha") is not None:
        config.set("PyMOL", "alpha", str(opts.get("alpha")))

    return config