Skip to content

Commit 1ffc3c3

Browse files
committed
adding kcal_force_unit input parameter to get forces correct
1 parent 8209f87 commit 1ffc3c3

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

CodeEntropy/config/arg_config_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"default": None,
2525
"help": "String for file format as recognised by MDAnalysis",
2626
},
27+
"kcal_force_units": {
28+
"type": bool,
29+
"default": False,
30+
"help": "Set this to True if you have a separate force file with nonSI units.",
31+
},
2732
"selection_string": {
2833
"type": str,
2934
"help": "Selection string for CodeEntropy",

CodeEntropy/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ def run_entropy_workflow(self):
275275
.results["timeseries"]
276276
)
277277

278+
if args.kcal_force_units:
279+
# Convert from kcal to kJ
280+
forces *= 4.184
281+
278282
logger.debug("Merging forces with coordinates universe.")
279283
new_universe = mda.Merge(select_atom)
280284
new_universe.load_new(coordinates, forces=forces)

tests/test_CodeEntropy/test_run.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ def test_run_entropy_workflow(self):
308308
run_manager._config_manager.load_config.return_value = {
309309
"test_run": {
310310
"top_traj_file": ["/path/to/tpr", "/path/to/trr"],
311+
"force_file": None,
312+
"file_format": None,
311313
"selection_string": "all",
312314
"output_file": "output.json",
313315
"verbose": True,
@@ -335,6 +337,8 @@ def test_run_entropy_workflow(self):
335337
mock_args.output_file = "output.json"
336338
mock_args.verbose = True
337339
mock_args.top_traj_file = ["/path/to/tpr", "/path/to/trr"]
340+
mock_args.force_file = None
341+
mock_args.file_format = None
338342
mock_args.selection_string = "all"
339343
parser = run_manager._config_manager.setup_argparse.return_value
340344
parser.parse_known_args.return_value = (mock_args, [])
@@ -351,7 +355,9 @@ def test_run_entropy_workflow(self):
351355

352356
run_manager.run_entropy_workflow()
353357

354-
mock_universe.assert_called_once_with("/path/to/tpr", ["/path/to/trr"])
358+
mock_universe.assert_called_once_with(
359+
"/path/to/tpr", ["/path/to/trr"], format=None
360+
)
355361
mock_entropy_manager.execute.assert_called_once()
356362

357363
def test_run_configuration_warning(self):
@@ -522,22 +528,17 @@ def test_new_U_select_frame(self, MockMerge, MockAnalysisFromFunction):
522528
# Mock AnalysisFromFunction results for coordinates, forces, and dimensions
523529
coords = np.random.rand(10, 100, 3)
524530
forces = np.random.rand(10, 100, 3)
525-
dims = np.random.rand(10, 3)
526531

527532
mock_coords_analysis = MagicMock()
528533
mock_coords_analysis.run.return_value.results = {"timeseries": coords}
529534

530535
mock_forces_analysis = MagicMock()
531536
mock_forces_analysis.run.return_value.results = {"timeseries": forces}
532537

533-
mock_dims_analysis = MagicMock()
534-
mock_dims_analysis.run.return_value.results = {"timeseries": dims}
535-
536538
# Set the side effects for the three AnalysisFromFunction calls
537539
MockAnalysisFromFunction.side_effect = [
538540
mock_coords_analysis,
539541
mock_forces_analysis,
540-
mock_dims_analysis,
541542
]
542543

543544
# Mock the merge operation
@@ -557,7 +558,6 @@ def test_new_U_select_frame(self, MockMerge, MockAnalysisFromFunction):
557558
# Assert that the arrays are passed correctly
558559
np.testing.assert_array_equal(args[0], coords)
559560
np.testing.assert_array_equal(kwargs["forces"], forces)
560-
np.testing.assert_array_equal(kwargs["dimensions"], dims)
561561

562562
# Check if format was included in the kwargs
563563
self.assertIn("format", kwargs)
@@ -576,22 +576,17 @@ def test_new_U_select_atom(self, MockMerge, MockAnalysisFromFunction):
576576
# Mock AnalysisFromFunction results for coordinates, forces, and dimensions
577577
coords = np.random.rand(10, 100, 3)
578578
forces = np.random.rand(10, 100, 3)
579-
dims = np.random.rand(10, 3)
580579

581580
mock_coords_analysis = MagicMock()
582581
mock_coords_analysis.run.return_value.results = {"timeseries": coords}
583582

584583
mock_forces_analysis = MagicMock()
585584
mock_forces_analysis.run.return_value.results = {"timeseries": forces}
586585

587-
mock_dims_analysis = MagicMock()
588-
mock_dims_analysis.run.return_value.results = {"timeseries": dims}
589-
590586
# Set the side effects for the three AnalysisFromFunction calls
591587
MockAnalysisFromFunction.side_effect = [
592588
mock_coords_analysis,
593589
mock_forces_analysis,
594-
mock_dims_analysis,
595590
]
596591

597592
# Mock the merge operation
@@ -613,7 +608,6 @@ def test_new_U_select_atom(self, MockMerge, MockAnalysisFromFunction):
613608
# Assert that the arrays are passed correctly
614609
np.testing.assert_array_equal(args[0], coords)
615610
np.testing.assert_array_equal(kwargs["forces"], forces)
616-
np.testing.assert_array_equal(kwargs["dimensions"], dims)
617611

618612
# Check if format was included in the kwargs
619613
self.assertIn("format", kwargs)

0 commit comments

Comments
 (0)