Skip to content

Commit 9a796ed

Browse files
committed
Merging forces from separate trajectory file
1 parent a6d7047 commit 9a796ed

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

CodeEntropy/config/arg_config_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
"top_traj_file": {
1313
"type": str,
1414
"nargs": "+",
15-
"help": "Path to Structure/topology file followed by Trajectory file(s)",
15+
"help": "Path to structure/topology file followed by trajectory file",
16+
},
17+
"force_file": {
18+
"type": str,
19+
"nargs": "+",
20+
"default": None,
21+
"help": "Optional path to force file if forces are not in trajectory file",
1622
},
1723
"selection_string": {
1824
"type": str,

CodeEntropy/run.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,34 @@ def run_entropy_workflow(self):
250250
logger.debug(f"Loading Universe with {tprfile} and {trrfile}")
251251
u = mda.Universe(tprfile, trrfile)
252252

253+
# If forces are in separate file merge them with the
254+
# coordinates from the trajectory file
255+
forcefile = args.force_file[0]
256+
if forcefile is not None:
257+
u_force = mda.Universe(tprfile, forcefile)
258+
select_atom = u.select_atoms("all")
259+
select_atom_force = u_force.select_atoms("all")
260+
261+
coordinates = (
262+
AnalysisFromFunction(
263+
lambda ag: ag.positions.copy(), select_atom
264+
)
265+
.run()
266+
.results["timeseries"]
267+
)
268+
forces = (
269+
AnalysisFromFunction(
270+
lambda ag: ag.positions.copy(), select_atom_force
271+
)
272+
.run()
273+
.results["timeseries"]
274+
)
275+
276+
new_universe = mda.Merge(select_atom)
277+
new_universe.load_new(coordinates, forces=forces)
278+
279+
u = new_universe
280+
253281
self._config_manager.input_parameters_validation(u, args)
254282

255283
# Create LevelManager instance

0 commit comments

Comments
 (0)