|
| 1 | +import click |
| 2 | + |
| 3 | +import paths_cli.utils |
| 4 | +from paths_cli.parameters import APPEND_FILE, ENGINE, MULTI_TAG |
| 5 | +from paths_cli import OPSCommandPlugin |
| 6 | + |
| 7 | + |
| 8 | +@click.command( |
| 9 | + "load-trajectory", |
| 10 | + short_help="Load an external trajectory file", |
| 11 | +) |
| 12 | +@click.argument('traj_file') |
| 13 | +@click.option( |
| 14 | + '--top', |
| 15 | + help=( |
| 16 | + "Topology information (typically PDB). Only for required " |
| 17 | + "formats." |
| 18 | + ), |
| 19 | + default=None, |
| 20 | +) |
| 21 | +@APPEND_FILE.clicked(required=True) |
| 22 | +@MULTI_TAG.clicked() |
| 23 | +def load_trajectory(traj_file, top, append, tag): |
| 24 | + """Load a trajectory from a file. |
| 25 | +
|
| 26 | + This uses MDTraj under the hood, and can load any file format that |
| 27 | + MDTraj can. NB: This stores in a format based on OpenMM snapshots. |
| 28 | + Trajectories loaded this way will work with engines compatible with |
| 29 | + that input (e.g., GROMACS). |
| 30 | + """ |
| 31 | + import mdtraj as md |
| 32 | + from openpathsampling.engines.openmm.tools import ops_load_trajectory |
| 33 | + traj = ops_load_trajectory(traj_file, top=top) |
| 34 | + storage = append.get() |
| 35 | + storage.save(traj) |
| 36 | + for tag_name in tag: |
| 37 | + storage.tags[tag_name] = traj |
| 38 | + |
| 39 | + |
| 40 | + # tests: |
| 41 | + # * check that we load PDB |
| 42 | + # * check that if we load PDB with top as well works |
| 43 | + # * check that we can load trr / xtc files (only with top) |
| 44 | + # * maybe check for error if top doesn't match traj file? (atom numbers) |
| 45 | + |
| 46 | +PLUGIN = OPSCommandPlugin( |
| 47 | + command=load_trajectory, |
| 48 | + section="Miscellaneous", |
| 49 | + requires_ops=(1, 6), |
| 50 | + requires_cli=(0, 4), |
| 51 | +) |
0 commit comments