|
20 | 20 | ##################################################################### |
21 | 21 |
|
22 | 22 | """ |
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. |
30 | 24 | """ |
31 | 25 |
|
32 | 26 |
|
33 | | -def cli(): |
| 27 | +def somd2(): |
34 | 28 | """ |
35 | 29 | SOMD2: Command line interface. |
36 | 30 | """ |
@@ -91,3 +85,75 @@ def cli(): |
91 | 85 | except Exception as e: |
92 | 86 | _logger.error(f"An error occurred during the simulation: {e}") |
93 | 87 | 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