Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow customizing trjconv output group #396

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
file_pattern: "docs/ _inv/ _reference/ _freeze/"
push_options: "--force"
- uses: peaceiris/actions-gh-pages@v4
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs
Expand Down
28 changes: 23 additions & 5 deletions src/kimmdy/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
For command line usage, run `kimmdy-analysis -h`.
"""

from typing import Union
from typing import Optional, Union
from pathlib import Path
import MDAnalysis as mda
import subprocess as sp
Expand Down Expand Up @@ -72,7 +72,11 @@ def get_step_directories(dir: Path, steps: Union[list[str], str] = "all") -> lis


def concat_traj(
dir: str, filetype: str, steps: Union[list[str], str], open_vmd: bool = False
dir: str,
filetype: str,
steps: Union[list[str], str],
open_vmd: bool = False,
output_group: Optional[str] = None,
):
"""Find and concatenate trajectories (.xtc files) from a KIMMDY run into one trajectory.
The concatenated trajectory is centered and pbc corrected.
Expand All @@ -85,6 +89,8 @@ def concat_traj(
List of steps e.g. ["equilibrium", "production"]. Or a string "all" to return all subdirectories
open_vmd
Open concatenated trajectory in VMD
output_group
index group for output. Default is "Protein" for xtc and "System" for trr.
"""
run_dir = Path(dir).expanduser().resolve()
analysis_dir = get_analysis_dir(run_dir)
Expand All @@ -97,7 +103,12 @@ def concat_traj(
raise NotImplementedError(
f"Filetype {filetype} not implemented as trajectory file type. Try 'xtc', 'trr'."
)
filetype_conv = {"xtc": 1, "trr": 0}

filetype_ouput_group_default = {"xtc": "Protein", "trr": "System"}
if output_group is None:
output = filetype_ouput_group_default[filetype]
else:
output = output_group

## gather trajectories
trajectories = []
Expand All @@ -121,7 +132,7 @@ def concat_traj(
cwd=run_dir,
)
run_shell_cmd(
f"echo '1 {filetype_conv[filetype]}' | gmx trjconv -f {tmp_xtc} -s {tprs[0]} -o {str(out_xtc)} -center -pbc mol",
f"echo 'Protein\n{output}' | gmx trjconv -dt 0 -f {tmp_xtc} -s {tprs[0]} -o {str(out_xtc)} -center -pbc mol",
cwd=run_dir,
)
run_shell_cmd(f"rm {tmp_xtc}", cwd=run_dir)
Expand Down Expand Up @@ -568,6 +579,11 @@ def get_analysis_cmdline_args() -> argparse.Namespace:
action="store_true",
help="Open VMD with the concatenated trajectory.",
)
parser_trjcat.add_argument(
"--output-group",
type=str,
help="Index group to include in the output. Default is 'Protein' for xtc and 'System' for trr.",
)

parser_energy = subparsers.add_parser(
name="energy", help="Plot GROMACS energy for a KIMMDY run"
Expand Down Expand Up @@ -698,7 +714,9 @@ def entry_point_analysis():
args = get_analysis_cmdline_args()

if args.module == "trjcat":
concat_traj(args.dir, args.filetype, args.steps, args.open_vmd)
concat_traj(
args.dir, args.filetype, args.steps, args.open_vmd, args.output_group
)
elif args.module == "energy":
plot_energy(args.dir, args.steps, args.terms, args.open_plot)
elif args.module == "radical_population":
Expand Down