void gmx_write_tng_from_trxframe(tng_trajectory_t        output,
                                 const t_trxframe       *frame,
                                 int                     natoms)
{
#if GMX_USE_TNG
    if (frame->step > 0)
    {
        double timePerFrame = frame->time * PICO / frame->step;
        tng_time_per_frame_set(output, timePerFrame);
    }
    if (natoms < 0)
    {
        natoms = frame->natoms;
    }
    gmx_fwrite_tng(output,
                   TRUE,
                   frame->step,
                   frame->time,
                   0,
                   frame->box,
                   natoms,
                   frame->x,
                   frame->v,
                   frame->f);
#else
    GMX_UNUSED_VALUE(output);
    GMX_UNUSED_VALUE(frame);
    GMX_UNUSED_VALUE(natoms);
#endif
}
示例#2
0
void gmx_tng_prepare_md_writing(tng_trajectory_t  tng,
                                const gmx_mtop_t *mtop,
                                const t_inputrec *ir)
{
#ifdef GMX_USE_TNG
    gmx_tng_add_mtop(tng, mtop);
    set_writing_intervals(tng, FALSE, ir);
    tng_time_per_frame_set(tng, ir->delta_t * PICO);
#else
    GMX_UNUSED_VALUE(tng);
    GMX_UNUSED_VALUE(mtop);
    GMX_UNUSED_VALUE(ir);
#endif
}
示例#3
0
void gmx_tng_prepare_low_prec_writing(tng_trajectory_t  tng,
                                      const gmx_mtop_t *mtop,
                                      const t_inputrec *ir)
{
#ifdef GMX_USE_TNG
    gmx_tng_add_mtop(tng, mtop);
    add_selection_groups(tng, mtop);
    set_writing_intervals(tng, TRUE, ir);
    tng_time_per_frame_set(tng, ir->delta_t * PICO);
    gmx_tng_set_compression_precision(tng, ir->x_compression_precision);
#else
    GMX_UNUSED_VALUE(tng);
    GMX_UNUSED_VALUE(mtop);
    GMX_UNUSED_VALUE(ir);
#endif
}
示例#4
0
static int write_tng_timestep(void *v, const molfile_timestep_t *ts)
{
    float box_shape[9];
    tngdata *tng = (tngdata *)v;
    double time;

    /* If there are fewer particles in the TNG mol system (write_tng_structure
     * has not already been performed) compensate by creating implicit particles,
     * which will not have full atom information. */
    tng_implicit_num_particles_set(tng->tng_traj, tng->natoms);

    if(!ts)
    {
        return MOLFILE_ERROR;
    }

    time = ts->physical_time * PICO;

    convert_vmd_box_shape_to_tng(ts, box_shape);
    if(tng->step == 1 && ts->physical_time != 0)
    {
        tng->time_per_frame = time;
        tng_time_per_frame_set(tng->tng_traj, tng->time_per_frame);
    }
    if(tng->time_per_frame < 0)
    {
//         fprintf(stderr, "tngplugin) Writing frame without time stamp\n");
        tng_util_box_shape_write(tng->tng_traj, tng->step, box_shape);
        tng_util_pos_write(tng->tng_traj, tng->step, ts->coords);
    }
    else
    {
//         fprintf(stderr, "tngplugin) Writing frame with time stamp\n");
        tng_util_box_shape_with_time_write(tng->tng_traj, tng->step, time,
                                           box_shape);
        tng_util_pos_with_time_write(tng->tng_traj, tng->step, time,
                                     ts->coords);
    }
    if(tng->step == 0)
    {
        tng_util_pos_write_interval_set(tng->tng_traj, 1);
        tng_util_box_shape_write_interval_set(tng->tng_traj, 1);
    }
    if(ts->velocities)
    {
        fprintf(stderr, "tngplugin) Writing TNG velocities\n");
        if(tng->time_per_frame < 0)
        {
            tng_util_vel_write(tng->tng_traj, tng->step, ts->velocities);
        }
        else
        {
            tng_util_vel_with_time_write(tng->tng_traj, tng->step, time,
                                         ts->velocities);
        }
        if(tng->step == 0)
        {
            tng_util_vel_write_interval_set(tng->tng_traj, 1);
        }
    }

    tng->step++;

    return MOLFILE_SUCCESS;
}
void gmx_prepare_tng_writing(const char              *filename,
                             char                     mode,
                             tng_trajectory_t        *input,
                             tng_trajectory_t        *output,
                             int                      nAtoms,
                             const gmx_mtop_t        *mtop,
                             const int               *index,
                             const char              *indexGroupName)
{
#if GMX_USE_TNG
    /* FIXME after 5.0: Currently only standard block types are read */
    const int           defaultNumIds              = 5;
    static gmx_int64_t  fallbackIds[defaultNumIds] =
    {
        TNG_TRAJ_BOX_SHAPE, TNG_TRAJ_POSITIONS,
        TNG_TRAJ_VELOCITIES, TNG_TRAJ_FORCES,
        TNG_GMX_LAMBDA
    };
    static char         fallbackNames[defaultNumIds][32] =
    {
        "BOX SHAPE", "POSITIONS", "VELOCITIES",
        "FORCES", "LAMBDAS"
    };

    typedef tng_function_status (*set_writing_interval_func_pointer)(tng_trajectory_t,
                                                                     const gmx_int64_t,
                                                                     const gmx_int64_t,
                                                                     const gmx_int64_t,
                                                                     const char*,
                                                                     const char,
                                                                     const char);
#if GMX_DOUBLE
    set_writing_interval_func_pointer set_writing_interval = tng_util_generic_write_interval_double_set;
#else
    set_writing_interval_func_pointer set_writing_interval = tng_util_generic_write_interval_set;
#endif

    gmx_tng_open(filename, mode, output);

    /* Do we have an input file in TNG format? If so, then there's
       more data we can copy over, rather than having to improvise. */
    if (*input)
    {
        /* Set parameters (compression, time per frame, molecule
         * information, number of frames per frame set and writing
         * intervals of positions, box shape and lambdas) of the
         * output tng container based on their respective values int
         * the input tng container */
        double      time, compression_precision;
        gmx_int64_t n_frames_per_frame_set, interval = -1;

        tng_compression_precision_get(*input, &compression_precision);
        tng_compression_precision_set(*output, compression_precision);
        // TODO make this configurable in a future version
        char compression_type = TNG_TNG_COMPRESSION;

        tng_molecule_system_copy(*input, *output);

        tng_time_per_frame_get(*input, &time);
        tng_time_per_frame_set(*output, time);

        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);

        for (int i = 0; i < defaultNumIds; i++)
        {
            if (tng_data_get_stride_length(*input, fallbackIds[i], -1, &interval)
                == TNG_SUCCESS)
            {
                switch (fallbackIds[i])
                {
                    case TNG_TRAJ_POSITIONS:
                    case TNG_TRAJ_VELOCITIES:
                        set_writing_interval(*output, interval, 3, fallbackIds[i],
                                             fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
                                             compression_type);
                        break;
                    case TNG_TRAJ_FORCES:
                        set_writing_interval(*output, interval, 3, fallbackIds[i],
                                             fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
                                             TNG_GZIP_COMPRESSION);
                        break;
                    case TNG_TRAJ_BOX_SHAPE:
                        set_writing_interval(*output, interval, 9, fallbackIds[i],
                                             fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
                                             TNG_GZIP_COMPRESSION);
                        break;
                    case TNG_GMX_LAMBDA:
                        set_writing_interval(*output, interval, 1, fallbackIds[i],
                                             fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
                                             TNG_GZIP_COMPRESSION);
                    default:
                        continue;
                }
            }
        }

    }
    else
    {
        /* TODO after trjconv is modularized: fix this so the user can
           change precision when they are doing an operation where
           this makes sense, and not otherwise.

           char compression = bUseLossyCompression ? TNG_TNG_COMPRESSION : TNG_GZIP_COMPRESSION;
           gmx_tng_set_compression_precision(*output, ndec2prec(nDecimalsOfPrecision));
         */
        gmx_tng_add_mtop(*output, mtop);
        tng_num_frames_per_frame_set_set(*output, 1);
    }

    if (index && nAtoms > 0)
    {
        gmx_tng_setup_atom_subgroup(*output, nAtoms, index, indexGroupName);
    }

    /* If for some reason there are more requested atoms than there are atoms in the
     * molecular system create a number of implicit atoms (without atom data) to
     * compensate for that. */
    if (nAtoms >= 0)
    {
        tng_implicit_num_particles_set(*output, nAtoms);
    }
#else
    GMX_UNUSED_VALUE(filename);
    GMX_UNUSED_VALUE(mode);
    GMX_UNUSED_VALUE(input);
    GMX_UNUSED_VALUE(output);
    GMX_UNUSED_VALUE(nAtoms);
    GMX_UNUSED_VALUE(mtop);
    GMX_UNUSED_VALUE(index);
    GMX_UNUSED_VALUE(indexGroupName);
#endif
}