-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from calpolyccg/cli
Create CLI
- Loading branch information
Showing
16 changed files
with
250 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
Installation | ||
============ | ||
|
||
MD-SAPT can be installed by cloning the GitHub repository. | ||
MD-SAPT can be installed from the psi4 Conda repo like so: | ||
|
||
.. code-block:: bash | ||
conda install -c psi4/label/dev -c conda-forge mdsapt | ||
Alternatively, it can be installed by cloning the GitHub repository. | ||
|
||
.. code-block:: bash | ||
git clone https://github.com/calpolyccg/MDSAPT.git | ||
pip install ./MDSAPT | ||
MD-SAPT can also be installed from conda. | ||
To ensure it's been installed correctly, run `mdsapt` or `python3 -m mdsapt`. | ||
|
||
.. code-block:: bash | ||
.. code-block:: | ||
Warning: importing 'simtk.openmm' is deprecated. Import 'openmm' instead. | ||
2022-03-30 09:32:50,071 mdsapt INFO MDSAPT 1.2.0 starting | ||
2022-03-30 09:32:50,071 mdsapt INFO Copyright (c) 2021 Alia Lescoulie, Astrid Yu, and Ashley Ringer McDonald | ||
2022-03-30 09:32:50,071 mdsapt INFO Released under GPLv3 License | ||
Usage: python -m mdsapt [OPTIONS] COMMAND [ARGS]... | ||
MDSAPT - Molecular Dynamics Symmetry-Adapted Perturbation Theory | ||
This command-line interface lets you easily do common MDSAPT-related tasks. | ||
conda install -c psi4 MDSAPT | ||
Options: | ||
--help Show this message and exit. | ||
Commands: | ||
generate Generate a template input file at filename. | ||
run Run a SAPT calculation using the configuration in in_file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ dependencies: | |
- psi4>=1.6.1,<1.7 | ||
|
||
- mdanalysis>=2.2.0,<2.3 | ||
- click | ||
- numpy | ||
- openmm | ||
- pandas | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Main entrypoint for the CLI. | ||
""" | ||
|
||
# Note that we import directly from the CLI instead of the full package. This is an optimization | ||
# since some CLI tasks do not need the entire package. | ||
from .cli import cli | ||
|
||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
import click | ||
from mdsapt.config import RangeFrameSelection | ||
|
||
# Note that we do not import MDSAPT. This is a speed optimization; it is imported later. | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
"""Location of the mdsapt package to be used in resolving templates.""" | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
""" | ||
MDSAPT - Molecular Dynamics Symmetry-Adapted Perturbation Theory, by Alia Lescoulie, Astrid Yu, and Ashley Ringer McDonald. | ||
This command-line interface lets you easily do common MDSAPT-related tasks. | ||
""" | ||
|
||
|
||
@cli.command() | ||
@click.argument( | ||
'filename', | ||
default='input.yaml', | ||
) | ||
@click.option( | ||
'-t', '--template', 'template', | ||
help="Template to generate from. By default, trajectory.", | ||
type=click.Choice(['trajectory', 'docking'], case_sensitive=False), | ||
default='trajectory', | ||
) | ||
@click.option( | ||
'-f', '--force', | ||
help="If provided, overwrites existing files.", | ||
is_flag=True, | ||
) | ||
def generate(filename: str, template: str, force: bool): | ||
""" | ||
Generate a template input file at filename. | ||
""" | ||
ensure_safe_to_overwrite(filename, force) | ||
|
||
# TODO: make a wizard for these templates | ||
template_path = os.path.join(_dir_path, 'data', f'{template}_template.yaml') | ||
|
||
with open(template_path, 'r') as template: | ||
template_data = template.read() | ||
with open(filename, 'w') as new_file: | ||
new_file.write(template_data) | ||
|
||
logger.info(f'Generated template input file {filename}') | ||
|
||
|
||
@cli.command() | ||
@click.argument( | ||
'in_file', | ||
default='input.yaml', | ||
) | ||
@click.argument( | ||
'out_file', | ||
default='out.csv', | ||
) | ||
@click.option( | ||
'-f', '--force', | ||
help="If provided, overwrites existing files.", | ||
is_flag=True, | ||
) | ||
def run(in_file: str, out_file: str, force: bool): | ||
""" | ||
Run a SAPT calculation using the configuration in in_file. Outputs will be written to | ||
out_file. | ||
""" | ||
import mdsapt | ||
|
||
ensure_safe_to_overwrite(out_file, force) | ||
|
||
config = mdsapt.load_from_yaml_file(in_file) | ||
if isinstance(config.analysis, mdsapt.config.TrajectoryAnalysisConfig): | ||
sapt = mdsapt.TrajectorySAPT(config) | ||
frames = config.analysis.frames | ||
sapt.run(frames.start, frames.stop, frames.step) | ||
elif isinstance(config.analysis, mdsapt.config.DockingAnalysisConfig): | ||
sapt = mdsapt.DockingSAPT(config) | ||
sapt.run() | ||
|
||
logger.info('saving results to CSV') | ||
sapt.results.to_csv(out_file) | ||
|
||
|
||
def ensure_safe_to_overwrite(path: str, force: bool): | ||
""" | ||
Helper function to ensure that it's safe to overwrite the given file, and | ||
halts the program if not. | ||
""" | ||
if not os.path.exists(path): | ||
return | ||
|
||
if force: | ||
logger.warning("will overwrite existing CSV %s", path) | ||
return | ||
|
||
logger.error("Halting, file already exists: %s", path) | ||
logger.error("If you want to overwrite that file, add the -f flag") | ||
sys.exit(-1) |
Oops, something went wrong.