Skip to content

Commit

Permalink
feat: start westpa init script
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexmmaldonado committed May 19, 2024
1 parent 9181225 commit 63522ee
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pydantic-settings = "^2.2.1"
sp_restart = "subpex.scripts.sp_restart:main"
sp_renderer = "subpex.setup.render:cli_renderer"
sp_westpa_config = "subpex.configs.westpa.cli:cli_westpa_config"
sp_westpa_init = "subpex.setup.westpa.main:cli_run_westpa_setup"

[tool.poetry.group.dev.dependencies]
ruff = "^0.4.4"
Expand Down
Empty file added subpex/setup/westpa/__init__.py
Empty file.
82 changes: 82 additions & 0 deletions subpex/setup/westpa/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import argparse
import os
import shutil
import sys

Check warning on line 4 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L1-L4

Added lines #L1 - L4 were not covered by tests

from loguru import logger

Check warning on line 6 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L6

Added line #L6 was not covered by tests

from ...configs import SubpexConfig, WestpaConfig

Check warning on line 8 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L8

Added line #L8 was not covered by tests


def run_westpa_setup(

Check warning on line 11 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L11

Added line #L11 was not covered by tests
subpex_config: SubpexConfig,
westpa_config: WestpaConfig,
write_dir: str = "",
overwrite: bool = False,
) -> None:
"""Setup WESTPA simulation.
Args:
write_dir: Path to directory to initialize simulations.
"""
if os.path.exists(write_dir):
logger.info(f"Directory at {write_dir} exists")
if overwrite:
logger.info("Overwrite is `True`")
logger.info("Removing directory")
shutil.rmtree(write_dir)

Check warning on line 27 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L22-L27

Added lines #L22 - L27 were not covered by tests
else:
logger.error("Overwrite is `False`")
logger.error("Aborting")
sys.exit(1)

Check warning on line 31 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L29-L31

Added lines #L29 - L31 were not covered by tests

logger.info(f"Creating directory at {write_dir}")
os.makedirs(write_dir, exist_ok=False)

Check warning on line 34 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L33-L34

Added lines #L33 - L34 were not covered by tests

logger.info("Creating all necessary directories")
os.makedirs(os.path.join(write_dir, "bstates"))

Check warning on line 37 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L36-L37

Added lines #L36 - L37 were not covered by tests


def cli_run_westpa_setup():

Check warning on line 40 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L40

Added line #L40 was not covered by tests
# Get arguments and load json settings file.
parser = argparse.ArgumentParser(

Check warning on line 42 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L42

Added line #L42 was not covered by tests
description="Initialize WESTPA simulation for SubPEx purposes."
)
parser.add_argument(

Check warning on line 45 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L45

Added line #L45 was not covered by tests
"--write_dir",
type=str,
default="",
help="Directory to write input files.",
)
parser.add_argument(

Check warning on line 51 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L51

Added line #L51 was not covered by tests
"--yaml_subpex",
type=str,
nargs="+",
help="Paths to YAML files to use for subpex config in decreasing precedence.",
)
parser.add_argument(

Check warning on line 57 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L57

Added line #L57 was not covered by tests
"--yaml_westpa",
type=str,
nargs="+",
help="Paths to YAML files to use for westpa config in decreasing precedence.",
)
parser.add_argument(

Check warning on line 63 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L63

Added line #L63 was not covered by tests
"--overwrite",
action="store_true",
help="Remove and overwrite directory",
)
args = parser.parse_args()

Check warning on line 68 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L68

Added line #L68 was not covered by tests

subpex_config = SubpexConfig()
if args.yaml_subpex is None:
args.yaml_subpex = []
for yaml_path in reversed(args.yaml_subpex):
subpex_config.from_yaml(yaml_path)

Check warning on line 74 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L70-L74

Added lines #L70 - L74 were not covered by tests

westpa_config = WestpaConfig()
if args.yaml_westpa is None:
args.yaml_westpa = []
for yaml_path in reversed(args.yaml_westpa):
westpa_config.from_yaml(yaml_path)

Check warning on line 80 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L76-L80

Added lines #L76 - L80 were not covered by tests

run_westpa_setup(subpex_config, westpa_config, args.write_dir)

Check warning on line 82 in subpex/setup/westpa/main.py

View check run for this annotation

Codecov / codecov/patch

subpex/setup/westpa/main.py#L82

Added line #L82 was not covered by tests

0 comments on commit 63522ee

Please sign in to comment.