#!/usr/bin/env python

"""Command line tool for general reconstructions."""

import argparse
from cryoem.program.rec_setup import RecSetup
from cryoem.program.rec import Rec


parser = argparse.ArgumentParser(prog='gmm-rec',
    description='3D reconstructions using Gaussian mixture models')

parser.add_argument('input',
                    help='input class averages as mrc file')
parser.add_argument('-o', '--output',
                    help='output volume as mrc file',
                    default='rec.mrc')
parser.add_argument('-s', '--steps', type=int, nargs='+',
                    help=('Total number of steps.'),
                    default=1000)
parser.add_argument('-d', '--input-size', type=int,
                    help=('resize input images to have this many ' +
                          'pixels along each axis'))
parser.add_argument('-a', '--pixel-size', default=4.0, type=float,
                    help='Input pixel size in Angstrom.')
parser.add_argument('-A', '--voxel-size', default=2.0, type=float,
                    help='Output voxel size in Angstrom.')
parser.add_argument('-M', '--fix-mixture',
                    help='do not update the initial mixture model',
                    action='store_true')
parser.add_argument('-T', '--fix-transformations',
                    help=('do not update the transformations (i.e. ' +
                          'rotations and translations)'),
                    action='store_true')
parser.add_argument('-N', '--counts', default=1000, type=int,
                    help='Number of counts per image.')
parser.add_argument('-K', '--components', default=100, type=int,
                    help='Number of mixture model components.')
parser.add_argument('--prior-mean', type=float,
                    help='Prior standard deviation on component means.')
parser.add_argument('--prior-variance', default=[10, 1000],
                    type=float, nargs=2,
                    help=('Alpha and beta of gamma prior on ' +
                          'component variance.'))
parser.add_argument('--prior-weights', default=10.0, type=float,
                    help=('Prior Dirichlet distribution on ' +
                          'component weights.'))
parser.add_argument('-g', '--global_rotations',
                    help=('Do initial reconstruction with global ' +
                          'rotation sampling.'),
                    action='store_true')
parser.add_argument('-r', '--random-rotations', default=100, type=int,
                    help=('Number of rotations to use in global ' +
                          'rotation sampling.'))
parser.add_argument('--mixture-steps', default=100, type=int,
                    help=('Number of mixture sampling steps.'))
parser.add_argument('--transformation-steps', default=100, type=int,
                    help=('Number of transformation sampling steps.'))
parser.add_argument('--std-range', default=5.0, type=float,
                    help=('Truncate Gaussians beyond this multiple ' +
                          'of the standard deviation.'))
parser.add_argument('-p', '--parallel', default=1, type=int,
                    help='Number of parallel reconstructions.')
parser.add_argument('-m', '--mixture',
                    help='CSV file with initial mixture model.')
parser.add_argument('-t', '--transformations',
                    help='CSV file with initial transformations.')
parser.add_argument('-v', '--verbose',
                    help=('use -vv or -vvv for higher verbosity'),
                    action='count')
parser.add_argument('--version', action='version',
                    version='%(prog)s 1.0')


args = parser.parse_args()

setup = RecSetup.from_args(args)
Rec(setup).run()
