#!/usr/bin/env python -W ignore
'''
                 *** The command line interface for pyPcazip ***                                                                                                                                  
'''

# General python libraries import.
from argh import *
import argparse
from CoRe import pypcazip

########################################################
#                      ENTRY POINT                     #
########################################################
@dispatch_command

#PCAZIP usage hints:
#"python ./pcazip.py -i|--input <input-file> -t|--topology <topology-file> 
#        [optional arguments]'\"hi:t:m:s:x:o:p:d:q:\",[\"help\",\"input=\",
#        \"topology=\",\"mask=\",\"selection=\",\"max_num_snapshots=\",
#        \"output=\",\"pdb_out=\",\"temp=\",\"quality=\"])"

# Mandatory command line arguments:
@arg('-i','--input', nargs='*', type=str, help='''Currently xtc, dcd,
multiple-model PDB and amber netcdf are accepted.
An additional syntax might be appended to the file name:
<inputfile>(start:stop:step)
In this latter case a range of frames from the trajectory file will be 
selected in this way:
\"start\" and \"stop\" are integers that stand for the start and end frames 
id to be considered;
\"step\" is an integer that specifies each how-many-frames in the range 
[start:stop] to take one frame for consideration.''')

@arg('-a','--album', nargs='*', type=str, help='''An album indicates the name 
of a file that holds inside it information on a trajectory file
together with indications on the range of frames to be considered from 
the trajectory file.
<trajfile>(start:stop:step) 
\"start\", \"stop\" and \"step\" have the same role as those reported for the 
input file. 
Logically, either input or album arguments should be mandatory.
Controls are set to assure the presence of only one of the two (either input or album) options.''')

# There might be more than one topology file.
# Another check could be to require in input the number of the names of 
# as many topology files as specified in this argument. But to avoid
# having an additional argument we could use the length of the topology 
# input list instead of this argument.
#@arg('-n','--num_top', nargs='?', help="Number of topology files.")
@arg('-t','--topology', nargs='*', type=str, help="The topology file/s.")

# Atoms-filter-like optional command line arguments:
@arg('-m','--mask', nargs='*', type=str, default=None, help='''A PDB-type mask 
file containing only atoms of interest.''')
@arg('-s','--selection',  nargs='*', type = str, default=None, help='''
Atom selection according to Charmm syntax selection keywords.
For more info on selection keywords go to 
http://mdanalysis.googlecode.com/git/package/doc/html/documentation_pages/selections.html
If the user does not provide a selection all particles in the system will be 
selected.''')
@arg('-f','--file_version', type=str, default='UNKN', help="The PCZ version to write [PCZ4 | PCZ6 | PCZ7]")
# Snapshots-filter-like optional command line arguments:
# @charlie
# This version does not support the max. number of snapshots option yet:
#@arg('-x','--max_num_snapshots', type=int, default=0, help='''The integer number indicates the maximum number of snapshots to consider 
#(if 0 means \"all the snapshots in the trajectory\" which is also the default value.)''') 

# Output optional parameters:
@arg('-o', '--output', type=str, default=None, help='''The output file
containing the compressed trajectory.''')
@arg('-p', '--pdb_out', type=str, default=None, help='''The output pdb file
containing the atoms selected from any atoms-filter-like optional command 
line arguments.''')
# @charlie
# the trajectory output option is not supported yet.
# @arg('--trj_output', action='store_true', help='''If this flag is specified, a trajectory file containing the
# coordinates of only the selected atoms and frames will be generated.''')
@arg('--nopca', action='store_true', help='''If this flag is specified, the pca analysis will not be performed and no pcz/compressed
files will be generated.''')

# Other optional parameters:
@arg('-q', '--quality', type=float, default=90.0, help='''Specify the accuracy to be considered for the compression, in terms of percentage in the range [0.0 .. 100.0]. This will also determine the number of PCA components to use for the projections. The default value equals 90.0.''')
@arg('-e', '--evecs', type=int, default=None, help='''Specify the number of total largest eigenvectors to be considered during the pca process.''')
@arg('-x', '--preload', default=False, help="Should the whole trajectory be preloaded in memory False by default.")
@arg('-v', '--verbosity', default=False, help="Increase output verbosity.")




def main(**kwargs):
    class Struct(object):
        def __init__(self, entries):
            self.__dict__.update(entries)
    args = Struct(kwargs)

    pypcazip.pcazip(args)

