libcli¶
Shared operations for client interfaces.
This module contains functions and classes that are shared amongst the client interfaces. It contains also others used to enhance the user experience.
- class taurenmd.libs.libcli.CustomParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]¶
Custom Parser class.
- class taurenmd.libs.libcli.ParamsToDict(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Convert command-line parameters in an argument to a dictionary.
Example
Where
-x
is an optional argument of the command-line client interface.>>> par1=1 par2='my name' par3=[1,2,3] >>> {'par1': 1, 'par2': 'my name', 'par3': [1, 2, 3]}
- class taurenmd.libs.libcli.ProgressBar(total, prefix='', suffix='', decimals=1, bar_length=None)[source]¶
Contextualizes a Progress Bar.
- Parameters
total (int convertable) – The total number o iteractions expected.
prefix (str) – Some prefix to enhance readability.
suffix (str) – Some suffix to enhance readability.
decimals (int-convertable) – The demicals to show in percentage. Defaults to 1.
bar_length (int, float, -convertable) – The length of the bar. If not provided (
None
), uses half of the terminal window.Thanks to for the initial template function
https (//dev.to/natamacm/progressbar-in-python-a3n)
Examples
>>> with ProgressBar(5000, suffix='frames') as PB: >>> for i in trajectory: >>> # do something >>> PB.increment()
- taurenmd.libs.libcli.add_angle_unit_arg(parser)[source]¶
Add angle unit selectiona argument to parser.
Is defined by
-a
and--aunit
.Wether angles are to be calculated in degrees or radians.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the topology positionl argument.
- taurenmd.libs.libcli.add_atom_selection_arg(parser)[source]¶
Add selection optional argument.
Selection argument is a string that defines the atom selection, this is defined by
-l
and--selection
, and defaults toall
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the selection argument.
- taurenmd.libs.libcli.add_atom_selections_arg(parser)[source]¶
Add selections optional argument.
Selections argument is a string that defines a list of atom selections, this is defined by
-g
and--selections
, and defaults toall
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the selections argument.
- taurenmd.libs.libcli.add_data_export_arg(parser)[source]¶
Add export argument.
Export argument configures data export to a text file in table format.
Is defined by
-x
and--export
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the export argument.
- taurenmd.libs.libcli.add_frame_list_arg(parser)[source]¶
Add frame list argument.
Registers a list of frame numbers, is defined by
-t
and--flist
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the flist argument.
- taurenmd.libs.libcli.add_insort_arg(parser)[source]¶
Sort input by trail int.
Applies
taurenmd.libs.libio.sort_numbered_input()
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the insort argument.
- taurenmd.libs.libcli.add_inverted_array(parser)[source]¶
Add inverted selections optional argument.
Saves an array of 0s and 1s to invert the order of selections.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the selections argument.
- taurenmd.libs.libcli.add_output_dir_arg(parser)[source]¶
Add output dir to client.
Client gains –odir option.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the export argument.
- taurenmd.libs.libcli.add_plane_selection_arg(parser)[source]¶
Add plane selection argument.
Plane selection is a selection of three regions separated by ‘or’ operator.
Is defined by
-z
and--plane-selection
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the plane-selection argument.
- taurenmd.libs.libcli.add_plot_arg(parser)[source]¶
Add plot parameters.
Plot kwargs that will be passed to the plotting function.
Defined by
--plot
.If given, plot results. Additional arguments can be given to specify the plot parameters.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the plot argument.
- taurenmd.libs.libcli.add_reference_frame_arg(parser)[source]¶
Add a reference frame argument.
Reference frame is the frame to compute the parameter against.
Depending on the client logic the reference frame might have different meanings.
Is defined by
-r
and--ref-frame
.Defaults to
0
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the refence-frame argument.
- taurenmd.libs.libcli.add_slice_arg(parser)[source]¶
Add start, stop and step slicing arguments.
Slicing arguments are according to Python Slice object
- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the trajectory positionl argument.
- taurenmd.libs.libcli.add_subparser(parser, module)[source]¶
Add a subcommand to a parser.
- Parameters
parser (argparse.add_suparsers object) – The parser to add the subcommand to.
module – A python module containing the characteristics of a taurenmd client interface. Client interface modules require the following attributes:
__doc__
which feeds the description argument of add_parser,_help
which feeds help,ap
which is an ArgumentParser, and amain
function, which executes the main logic of the interface.
- taurenmd.libs.libcli.add_top_output_arg(parser)[source]¶
Add argument to export first frame as topology PDB file.
Defined by
-o
and--top-output
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the topology output argument.
- taurenmd.libs.libcli.add_topology_arg(parser)[source]¶
Add topology positional argument to parser.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the topology positionl argument.
- taurenmd.libs.libcli.add_traj_output_arg(parser)[source]¶
Add argument to export trajectory after client modifications.
Defined by
-d
and--traj-output
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to which add the trajectory output argument.
- taurenmd.libs.libcli.add_trajectories_arg(parser)[source]¶
Add trajectory positional argument to parser.
Accepts multiple trajectory files.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the trajectory positionl argument.
- taurenmd.libs.libcli.add_trajectory_arg(parser)[source]¶
Add trajectory positional argument to parser.
Accepts a single trajectory file.
- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the trajectory positionl argument.
- taurenmd.libs.libcli.add_version_arg(parser)[source]¶
Add version
-v
option to parser.Displays a message informing the current version. Also accessible via
--version
.- Parameters
parser (argparse.ArgumentParser) – The argument parser to add the version argument.
- taurenmd.libs.libcli.maincli(ap, main)[source]¶
Client main function.
Operates when client is called directly outside the
taurenmd
client interface.Reads input parameters
saves inpu command to log file
runs client
main
functionsaves references to log file
- Returns
The result value from client
main
function.
- taurenmd.libs.libcli.represent_argument(arg)[source]¶
Represent argument in a string.
If argument has spaces represents string with quotation marks “.