#!/usr/bin/env python

import IMP.em
import IMP.atom


def main():
    desc = """
Approximate the density threshold to use given the molecular mass of
the complex."""
    p = IMP.ArgumentParser(description=desc)
    p.add_argument("-p", "--apix", dest="apix", type=float, help="voxel size")
    p.add_argument("density", help="EM density map file")
    p.add_argument("numres", type=int, help="number of residues")
    args = p.parse_args()
    in_map_fn = args.density
    num_res = args.numres
    # read the map
    dmap = IMP.em.read_map(in_map_fn)
    if args.apix:
        dmap.update_voxel_size(args.apix)

    mass = IMP.atom.get_mass_from_number_of_residues(num_res)

    t = IMP.em.get_threshold_for_approximate_mass(dmap, mass)
    print("Mass", mass)
    print("approximated threshold:", t)

if __name__ == "__main__":
    main()
