Skip to content

Commit 3e2d734

Browse files
committed
Add CLI entry-point for Boresch ghost atom modifications.
1 parent f4c9f69 commit 3e2d734

File tree

4 files changed

+95
-11
lines changed

4 files changed

+95
-11
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ can be controlled via the `--null-energy` option. The number of neighbours shoul
149149
be chosen as a trade off between accuracy and computational cost. A value of around
150150
20% of the number of replicas has been found to be a good starting point.
151151

152+
## Ghost atom modifications
153+
154+
We support the modification of ghost atom bonded terms to avoid spurious coupling
155+
to the physical system using the approach described in [this](https://pubs.acs.org/doi/10.1021/acs.jctc.0c01328) paper.
156+
These are enabled by default, but can be disabled using the ``--no-ghost-modifications``
157+
option. Alternatively, we also provide the `ghostly` command-line tool that can
158+
be used to apply the modifications to perturbable system without running a simulation,
159+
e.g. for use elsewhere. This can be used via:
160+
161+
```bash
162+
ghostly perturbable_system.bss --output perturbable_system_ghosted.bss --log-level debug
163+
```
164+
165+
(Here the log level is set to debug to provide more information on the modifications
166+
that are applied.)
167+
152168
## Note for SOMD1 users
153169

154170
For existing users of `somd1`, it's possible to generate input for `somd2` by passing

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ dynamic = ["version"]
2020
license-files = ["LICENSE"]
2121

2222
[project.scripts]
23-
somd2 = "somd2.app:cli"
23+
somd2 = "somd2.app:somd2"
24+
ghostly = "somd2.app:ghostly"
2425

2526
[project.urls]
2627
repository = "https://github.com/OpenBioSim/somd2"

src/somd2/app/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
.. autosummary::
2929
:toctree: generated/
3030
31-
cli
31+
somd2
32+
ghostly
3233
"""
3334

34-
from .run import *
35+
from ._cli import *
Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@
2020
#####################################################################
2121

2222
"""
23-
The somd2 command line program.
24-
25-
Usage:
26-
To get the help for this program and list all of the
27-
arguments (with defaults) use:
28-
29-
somd2 --help
23+
SOMD2 command line interface.
3024
"""
3125

3226

33-
def cli():
27+
def somd2():
3428
"""
3529
SOMD2: Command line interface.
3630
"""
@@ -91,3 +85,75 @@ def cli():
9185
except Exception as e:
9286
_logger.error(f"An error occurred during the simulation: {e}")
9387
exit(1)
88+
89+
90+
def ghostly():
91+
"""
92+
SOMD2: Command line interface.
93+
"""
94+
95+
import argparse
96+
import sys
97+
98+
import sire as sr
99+
100+
from somd2 import _logger
101+
from somd2._utils._ghosts import boresch
102+
103+
parser = argparse.ArgumentParser(
104+
description="Ghostly: ghost atom bonded term modifications"
105+
)
106+
107+
parser.add_argument(
108+
"system",
109+
type=str,
110+
help="Path to a stream file containing the perturbable system.",
111+
)
112+
113+
parser.add_argument(
114+
"--output",
115+
type=str,
116+
help="File prefix for the output file.",
117+
default="ghostly",
118+
required=False,
119+
)
120+
121+
parser.add_argument(
122+
"--log-level",
123+
type=str,
124+
help="Log level for the logger.",
125+
default="info",
126+
choices=["debug", "info", "warning", "error", "critical"],
127+
required=False,
128+
)
129+
130+
# Parse the arguments.
131+
args = parser.parse_args()
132+
133+
# Set the logger level.
134+
_logger.remove()
135+
_logger.add(sys.stderr, level=args.log_level.upper(), enqueue=True)
136+
137+
# Try to load the system.
138+
try:
139+
system = sr.stream.load(args.system)
140+
system = sr.morph.link_to_reference(system)
141+
except Exception as e:
142+
_logger.error(f"An error occurred while loading the system: {e}")
143+
exit(1)
144+
145+
# Try to apply the modifications.
146+
try:
147+
system = boresch(system)
148+
except Exception as e:
149+
_logger.error(
150+
f"An error occurred while applying the ghost atom modifications: {e}"
151+
)
152+
exit(1)
153+
154+
# Try to save the system.
155+
try:
156+
sr.stream.save(system, f"{args.output}.bss")
157+
except Exception as e:
158+
_logger.error(f"An error occurred while saving the system: {e}")
159+
exit(1)

0 commit comments

Comments
 (0)