Skip to content

Commit f1f73bd

Browse files
authored
Merge pull request #5 from OpenBioSim/feature_json
Add support for modification dictionary and JSON output
2 parents 506e506 + 7dfa3f5 commit f1f73bd

4 files changed

Lines changed: 192 additions & 39 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ stream file for the perturbable molecule, or AMBER or GROMACS files for the two
101101
The format can be specified using the the `--output-format` option. If you require input
102102
for a free-energy perturbation simulation, e.g. a hybrid GROMACS toplogy file, the you can
103103
use the stream file with [BioSimSpace](https://biosimspace.openbiosim.org) to generate the
104-
required input files.
104+
required input files. Additionally, the program will output a JSON file summarising the
105+
modifications that were made.
106+
107+
```bash
105108

106109
> [!NOTE]
107110
> When a stream file is used as input, the `--mapping` option is ignored. and

src/ghostly/_cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def run():
3535
from loguru import logger
3636

3737
import argparse
38+
import json
3839
import os
3940
import sys
4041

@@ -268,7 +269,7 @@ def run():
268269
try:
269270
if args.system is None:
270271
system = merged.toSystem()._sire_object
271-
system = modify(
272+
system, modifications = modify(
272273
system,
273274
k_hard.value(),
274275
k_soft.value(),
@@ -307,3 +308,11 @@ def run():
307308
sys.exit(1)
308309
else:
309310
sr.stream.save(system, f"{args.output_prefix}.bss")
311+
312+
# Try to save the modifications to JSON.
313+
try:
314+
with open(f"{args.output_prefix}_modifications.json", "w") as f:
315+
json.dump(modifications, f, indent=4)
316+
except Exception as e:
317+
logger.error(f"An error occurred while saving the modifications to JSON: {e}")
318+
sys.exit(1)

0 commit comments

Comments
 (0)