Allow TNG to TNG file conversion without time per frame info
authorMagnus Lundborg <magnus.lundborg@scilifelab.se>
Fri, 29 Oct 2021 18:36:42 +0000 (18:36 +0000)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 29 Oct 2021 18:36:42 +0000 (18:36 +0000)
src/gromacs/fileio/tngio.cpp

index 485d3e35b21741d4e27e03eba96240c9fadfd71f..8604b59a75c147404f5da4d3a1352cdc26277615 100644 (file)
@@ -1063,9 +1063,15 @@ void gmx_prepare_tng_writing(const char*              filename,
         tng_molecule_system_copy(*input, *output);
 
         tng_time_per_frame_get(*input, &time);
-        tng_time_per_frame_set(*output, time);
-        // Since we have copied the value from the input TNG we should not change it again
-        (*gmx_tng_output)->timePerFrameIsSet = true;
+        /* Only write the time per frame if it was written (and valid). E.g., single
+         * frame files do not usually contain any time per frame information. */
+        if (time >= 0)
+        {
+            (*gmx_tng_input)->timePerFrameIsSet = true;
+            tng_time_per_frame_set(*output, time);
+            // Since we have copied the value from the input TNG we should not change it again
+            (*gmx_tng_output)->timePerFrameIsSet = true;
+        }
 
         tng_num_frames_per_frame_set_get(*input, &n_frames_per_frame_set);
         tng_num_frames_per_frame_set_set(*output, n_frames_per_frame_set);