Skip to content

Commit fc807d6

Browse files
committed
Fixing an off by one indexing error when slicing trajectories.
1 parent 54446d2 commit fc807d6

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

CodeEntropy/config/arg_config_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"end": {
2727
"type": int,
28-
"help": "Stop analysing the trajectory at this frame index",
28+
"help": "Stop analysing the trajectory at this frame index. This is the frame index of the last frame to be included, so for example if start=0 and end=500 there would be 501 frames analysed. The default -1 will include everything up to the last frame.",
2929
"default": -1,
3030
},
3131
"step": {

CodeEntropy/main_mcc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ def main():
127127
if step is None:
128128
step = 1
129129
# Count number of frames, easy if not slicing
130+
# MDAnalysis trajectory slicing only includes up to end-1
131+
# This works the way we want it to if the whole trajectory is being included
130132
if start == 0 and end == -1 and step == 1:
133+
end = len(u.trajectory)
131134
number_frames = len(u.trajectory)
132135
elif end == -1:
133136
end = len(u.trajectory)
134-
number_frames = math.floor((end - start) / step) + 1
137+
number_frames = math.floor((end - start) / step)
135138
else:
136-
number_frames = math.floor((end - start) / step) + 1
139+
end = end + 1
140+
number_frames = math.floor((end - start) / step)
137141
logger.debug(f"Number of Frames: {number_frames}")
138142

139143
# Create pandas data frame for results

0 commit comments

Comments
 (0)