#!/usr/bin/env python
from interfacebuilder.misc import *
from interfacebuilder.main import interface
import argparse


def parseArguments():
    # Create argument parser
    parser = argparse.ArgumentParser()

    # Positional mandatory arguments
    parser.add_argument("bottom", help="Path to geometry for bottom layer.", type=str)
    parser.add_argument("top", help="Path to geometry for top layer.", type=str)

    # Optional arguments
    parser.add_argument(
        "-N", "--N_translations", help="Number of translations", type=int, default=10
    )
    parser.add_argument(
        "-as", "--angle_stepsize", help="Angle step size", type=float, default=10.0
    )
    parser.add_argument(
        "-al",
        "--angle_limits",
        help="Angle limits",
        type=float,
        nargs="+",
        default=(0, 180.0),
    )
    parser.add_argument(
        "-t", "--tolerance", help="Acceptance criterion", type=float, default=0.1
    )
    parser.add_argument(
        "-d", "--distance", help="Interlayer distance", type=float, default=4.0
    )
    parser.add_argument(
        "-w", "--weight", help="Weight to reconstruct stack", type=float, default=0.5
    )
    parser.add_argument(
        "--jitter", help="Jitters points for plotting", type=float, default=0.05
    )
    parser.add_argument(
        "--mingamma",
        help="Exclude structures with gamma angles smaller than this value",
        type=float,
        default=20,
    )
    parser.add_argument(
        "--maxgamma",
        help="Exclude structures with gamma angles larger than this value",
        type=float,
        default=160,
    )

    # Parse arguments
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = parseArguments()
    intf = interface(**vars(args))
    if intf.pairs != None:
        assert (
            len(intf.pairs) != 0
        ), "Couldn't construct any linearly independent pairs."
        intf.analyze_results(args.distance, args.weight)
        intf.plot_results(args.jitter)
