Skip to content

Commit 9d11c16

Browse files
authored
Merge pull request #21 from openpathsampling/release-0.0.3
Release 0.0.3
2 parents 6b9cbb9 + 600edbd commit 9d11c16

File tree

15 files changed

+793
-277
lines changed

15 files changed

+793
-277
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ miscellaneous operations on OPS output files.
2828
**Miscellaneous Commands:**
2929

3030
* `contents`: List named objects from an OPS .nc file
31-
* `strip-snapshots`: Remove coordinates/velocities from an OPS storage
3231
* `append`: add objects from INPUT_FILE to another file
3332

3433
Full documentation is at https://openpathsampling-cli.readthedocs.io/; a brief

devtools/miniconda_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ conda_version="latest"
2222
#conda_version="4.4.10" # can pin a miniconda version like this, if needed
2323

2424
MINICONDA=Miniconda${pyV}-${conda_version}-${OS_ARCH}.sh
25-
MINICONDA_MD5=$(curl -s https://repo.continuum.io/miniconda/ | grep -A3 $MINICONDA | sed -n '4p' | sed -n 's/ *<td>\(.*\)<\/td> */\1/p')
25+
MINICONDA_MD5=$(curl -sL https://repo.continuum.io/miniconda/ | grep -A3 $MINICONDA | sed -n '4p' | sed -n 's/ *<td>\(.*\)<\/td> */\1/p')
2626
wget https://repo.continuum.io/miniconda/$MINICONDA
2727
SCRIPT_MD5=`eval "$MD5_CMD $MD5_OPT $MINICONDA" | cut -d ' ' -f 1`
2828

docs/for_core/cli.rst

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ to develop plugins for the CLI, see its documentation. The CLI subcommands
2828
are defined through a plugin system, which makes it very easy for developers
2929
to create new subcommands.
3030

31-
* CLI documentation:
32-
* CLI code repository:
31+
* CLI documentation: https://openpathsampling-cli.readthedocs.io/
32+
* CLI code repository: https://github.com/openpathsampling/openpathsampling-cli/
3333

3434
Workflow with the CLI
3535
---------------------
@@ -41,6 +41,76 @@ files.
4141

4242
To use it, you'll want to first set up
4343

44+
45+
Finding your way around the CLI
46+
-------------------------------
47+
48+
Like many command line tools, the OPS CLI has the options ``-h`` or
49+
``--help`` to get help. If you run ``openpathsampling --help`` you should
50+
see something like this::
51+
52+
Usage: openpathsampling [OPTIONS] COMMAND [ARGS]...
53+
54+
OpenPathSampling is a Python library for path sampling simulations. This
55+
command line tool facilitates common tasks when working with
56+
OpenPathSampling. To use it, use one of the subcommands below. For
57+
example, you can get more information about the pathsampling tool with:
58+
59+
openpathsampling pathsampling --help
60+
61+
Options:
62+
--log PATH logging configuration file
63+
-h, --help Show this message and exit.
64+
65+
Simulation Commands:
66+
visit-all Run MD to generate initial trajectories
67+
equilibrate Run equilibration for path sampling
68+
pathsampling Run any path sampling simulation, including TIS variants
69+
70+
Miscellaneous Commands:
71+
contents list named objects from an OPS .nc file
72+
append add objects from INPUT_FILE to another file
73+
74+
The ``--log`` option takes a logging configuration file (e.g., `logging.conf
75+
<>`_, and sets that logging behavior. If you use it, it must come before the
76+
subcommand name.
77+
78+
You can find out more about each subcommand by putting ``--help`` *after*
79+
the subcommand name, e.g., ``openpathsampling pathsampling --help``, which
80+
returns::
81+
82+
Usage: openpathsampling pathsampling [OPTIONS] INPUT_FILE
83+
84+
General path sampling, using setup in INPUT_FILE
85+
86+
Options:
87+
-o, --output-file PATH output ncfile [required]
88+
-m, --scheme TEXT identifier for the move scheme
89+
-t, --init-conds TEXT identifier for initial conditions (sample set or
90+
trajectory)
91+
-n, --nsteps INTEGER number of Monte Carlo trials to run
92+
-h, --help Show this message and exit.
93+
94+
Here you see the list of the options for the running a path sampling
95+
simulation. In general, path sampling requires an output
96+
file, a move scheme and initial conditions from some input file, and the
97+
number of steps to run. Note that only the output file is technically
98+
required: the CLI will default to running 0 steps (essentially, testing the
99+
validity of your setup), and it can try to guess the move scheme and initial
100+
conditions. In general, the way it guesses follows the following path:
101+
102+
1. If there is only one object of the suitable type in the INPUT_FILE, use
103+
that.
104+
2. If there are multiple objects of the correct type, but only one has a
105+
name, use the named object.
106+
3. In special cases it looks for specific names, such as
107+
``initial_conditions``, and will use those.
108+
109+
Full details on how various CLI parameters search the storage can be seen in
110+
the `Parameter Interpretation
111+
<https://openpathsampling-cli.readthedocs.io/en/latest/interpretation.html>`_
112+
section of the CLI docs.
113+
44114
Simulation Commands
45115
-------------------
46116

@@ -68,9 +138,6 @@ Here are some of the simulation commands implemented in the OPS CLI:
68138
have been visited (works for MSTIS or any 2-state system); must provide
69139
states, engine, and initial snapshot on command line
70140

71-
.. TODO figure showing how these all work -- what is needed for each, what
72-
is implicit
73-
74141
Miscellaneous Commands
75142
----------------------
76143

@@ -79,10 +146,29 @@ foregoing the CLI tools to run simulations, some of the "miscellaneous"
79146
commands are likely to be quite useful. Here are some that are available in
80147
the CLI:
81148

82-
* ``nclist``: list all the named objects in an OPS storage, organized by
149+
* ``contents``: list all the named objects in an OPS storage, organized by
83150
store (type); this is extremely useful to get the name of an object to use
84-
as command-line input to one of the simulation scripts
85-
* ``strip-snapshots``: create a copy of the input storage file with the
151+
152+
153+
.. * ``strip-snapshots``: create a copy of the input storage file with the
86154
details (coordinates/velocities) of all snapshots removed; this allows you
87155
to make a much smaller copy (with results of CVs) to copy back to a local
88156
computer for analysis
157+
158+
* ``append`` : add an object from once OPS storage into another one; this is
159+
useful for getting everything into a single file before running a
160+
simulation
161+
162+
Customizing the CLI
163+
-------------------
164+
165+
The OPS CLI uses a flexible plugin system to enable users to easily add
166+
custom functionality. This way, you can create and distribute custom
167+
plugins, giving more functionality to other users who would benefit from it,
168+
without adding everything to the core package and thus overwhelming new
169+
users.
170+
171+
Installing a plugin is easy: just create the directory
172+
``$HOME/.openpathsampling/cli-plugins/``, and copy the plugin Python script
173+
into there. For details on how to write a CLI plugin, see the `CLI
174+
development docs <https://openpathsampling-cli.readthedocs.io/>`_.

docs/full_cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ currently gives all commands alphabetically, without regard to section. In
99
general, this is not yet well-organized; contributions to improve that would
1010
be appreciated.
1111

12-
.. click:: paths_cli.cli:OPS_CLI
12+
.. click:: paths_cli.cli:main
1313
:prog: openpathsampling
1414
:show-nested:

docs/sphinx-helpers/make_param_table.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import click
1313

1414
from paths_cli import parameters
15+
from paths_cli import param_core
1516

1617
TableEntry = collections.namedtuple("TableEntry",
1718
"param flags get_args help")
@@ -20,7 +21,7 @@ def is_click_decorator(thing):
2021
return getattr(thing, '__module__', None) == 'click.decorators'
2122

2223
def is_parameter(thing):
23-
return (isinstance(thing, parameters.AbstractLoader)
24+
return (isinstance(thing, param_core.AbstractLoader)
2425
or is_click_decorator(thing))
2526

2627
def rst_wrap(code):
@@ -33,18 +34,18 @@ def flags_help(click_decorator):
3334
return flags, help_
3435

3536
def get_args(parameter):
36-
if isinstance(parameter, parameters.StorageLoader):
37+
if isinstance(parameter, param_core.StorageLoader):
3738
return "``name``"
38-
elif isinstance(parameter, (parameters.OPSStorageLoadNames,
39-
parameters.OPSStorageLoadSingle)):
39+
elif isinstance(parameter, (param_core.OPSStorageLoadNames,
40+
param_core.OPSStorageLoadSingle)):
4041
return "``storage``, ``name``"
4142
elif is_click_decorator(parameter):
4243
return "No ``get`` function"
4344
else:
4445
return "Unknown"
4546

4647
def get_click_decorator(thing):
47-
if isinstance(thing, parameters.AbstractLoader):
48+
if isinstance(thing, param_core.AbstractLoader):
4849
return thing.param.clicked()
4950
elif is_click_decorator(thing):
5051
return thing

paths_cli/cli.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"""
55
# builds off the example of MultiCommand in click's docs
66
import collections
7+
import logging
8+
import logging.config
79
import os
810

911
import click
@@ -36,16 +38,30 @@ def __init__(self, *args, **kwargs):
3638
self.plugin_folders.append(folder)
3739

3840
plugin_files = self._list_plugin_files(self.plugin_folders)
39-
self.plugins = self._load_plugin_files(plugin_files)
41+
plugins = self._load_plugin_files(plugin_files)
4042

4143
self._get_command = {}
4244
self._sections = collections.defaultdict(list)
43-
for plugin in self.plugins:
44-
self._get_command[plugin.name] = plugin.func
45-
self._sections[plugin.section].append(plugin.name)
45+
self.plugins = []
46+
for plugin in plugins:
47+
self._register_plugin(plugin)
4648

4749
super(OpenPathSamplingCLI, self).__init__(*args, **kwargs)
4850

51+
def _register_plugin(self, plugin):
52+
self.plugins.append(plugin)
53+
self._get_command[plugin.name] = plugin.func
54+
self._sections[plugin.section].append(plugin.name)
55+
56+
def _deregister_plugin(self, plugin):
57+
# mainly used in testing
58+
self.plugins.remove(plugin)
59+
del self._get_command[plugin.name]
60+
self._sections[plugin.section].remove(plugin.name)
61+
62+
def plugin_for_command(self, command_name):
63+
return {p.name: p for p in self.plugins}[command_name]
64+
4965
@staticmethod
5066
def _list_plugin_files(plugin_folders):
5167
def is_plugin(filename):
@@ -112,22 +128,22 @@ def format_commands(self, ctx, formatter):
112128
OpenPathSampling is a Python library for path sampling simulations. This
113129
command line tool facilitates common tasks when working with
114130
OpenPathSampling. To use it, use one of the subcommands below. For example,
115-
you can get more information about the strip-snapshots (filesize reduction)
116-
tool with:
131+
you can get more information about the pathsampling tool with:
117132
118-
openpathsampling strip-snapshots --help
133+
openpathsampling pathsampling --help
119134
"""
120135

121-
OPS_CLI = OpenPathSamplingCLI(
122-
name="openpathsampling",
123-
help=_MAIN_HELP,
124-
context_settings=CONTEXT_SETTINGS
125-
)
126-
127-
def main(): # no-cov
128-
OPS_CLI()
136+
@click.command(cls=OpenPathSamplingCLI, name="openpathsampling",
137+
help=_MAIN_HELP, context_settings=CONTEXT_SETTINGS)
138+
@click.option('--log', type=click.Path(exists=True, readable=True),
139+
help="logging configuration file")
140+
def main(log):
141+
if log:
142+
logging.config.fileConfig(log, disable_existing_loggers=False)
143+
# TODO: if log not given, check for logging.conf in .openpathsampling/
129144

145+
logger = logging.getLogger(__name__)
146+
logger.debug("About to run command") # TODO: maybe log invocation?
130147

131148
if __name__ == '__main__': # no-cov
132149
main()
133-
# print("list commands:", cli.list_commands())

paths_cli/commands/strip_snapshots.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)