*/
struct gmx_tng_trajectory
{
- tng_trajectory_t tng; //!< Actual TNG handle (pointer)
- bool lastStepDataIsValid; //!< True if lastStep has been set
- std::int64_t lastStep; //!< Index/step used for last frame
- bool lastTimeDataIsValid; //!< True if lastTime has been set
- double lastTime; //!< Time of last frame (TNG unit is seconds)
- bool timePerFrameIsSet; //!< True if we have set the time per frame
+ tng_trajectory_t tng; //!< Actual TNG handle (pointer)
+ bool lastStepDataIsValid; //!< True if lastStep has been set
+ std::int64_t lastStep; //!< Index/step used for last frame
+ bool lastTimeDataIsValid; //!< True if lastTime has been set
+ double lastTime; //!< Time of last frame (TNG unit is seconds)
+ bool timePerFrameIsSet; //!< True if we have set the time per frame
+ int boxOutputInterval; //!< Number of steps between the output of box size
+ int lambdaOutputInterval; //!< Number of steps between the output of lambdas
};
#if GMX_USE_TNG
break;
default:
gmx_fatal(FARGS, "Invalid file opening mode %c", mode);
- p = "";
- break;
}
return p;
}
static void addTngMoleculeFromTopology(gmx_tng_trajectory_t gmx_tng,
const char *moleculeName,
const t_atoms *atoms,
- gmx_int64_t numMolecules,
+ int64_t numMolecules,
tng_molecule_t *tngMol)
{
tng_trajectory_t tng = gmx_tng->tng;
atomCharges.reserve(mtop->natoms);
atomMasses.reserve(mtop->natoms);
- for (int molIndex = 0; molIndex < mtop->nmolblock; molIndex++)
+ for (const gmx_molblock_t &molBlock : mtop->molblock)
{
tng_molecule_t tngMol = nullptr;
- const gmx_moltype_t *molType = &mtop->moltype[mtop->molblock[molIndex].type];
+ const gmx_moltype_t *molType = &mtop->moltype[molBlock.type];
/* Add a molecule to the TNG trajectory with the same name as the
* current molecule. */
addTngMoleculeFromTopology(gmx_tng,
*(molType->name),
&molType->atoms,
- mtop->molblock[molIndex].nmol,
+ molBlock.nmol,
&tngMol);
/* Bonds have to be deduced from interactions (constraints etc). Different
atomCharges.push_back(molType->atoms.atom[atomCounter].q);
atomMasses.push_back(molType->atoms.atom[atomCounter].m);
}
- for (int molCounter = 1; molCounter < mtop->molblock[molIndex].nmol; molCounter++)
+ for (int molCounter = 1; molCounter < molBlock.nmol; molCounter++)
{
std::copy_n(atomCharges.end() - molType->atoms.nr, molType->atoms.nr, std::back_inserter(atomCharges));
std::copy_n(atomMasses.end() - molType->atoms.nr, molType->atoms.nr, std::back_inserter(atomMasses));
/* Define pointers to specific writing functions depending on if we
* write float or double data */
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 int64_t,
+ const int64_t,
+ const int64_t,
const char*,
const char,
const char);
set_writing_interval(tng, gcd, 9, TNG_TRAJ_BOX_SHAPE,
"BOX SHAPE", TNG_NON_PARTICLE_BLOCK_DATA,
TNG_GZIP_COMPRESSION);
+ gmx_tng->lambdaOutputInterval = gcd;
+ gmx_tng->boxOutputInterval = gcd;
if (gcd < lowest / 10)
{
gmx_warning("The lowest common denominator of trajectory output is "
static gmx_bool all_atoms_selected(const gmx_mtop_t *mtop,
const int gtype)
{
- const gmx_moltype_t *molType;
- const t_atoms *atoms;
-
/* Iterate through all atoms in the molecule system and
* check if they belong to a selection group of the
* requested type. */
- for (int molIndex = 0, i = 0; molIndex < mtop->nmoltype; molIndex++)
+ int i = 0;
+ for (const gmx_molblock_t &molBlock : mtop->molblock)
{
- molType = &mtop->moltype[mtop->molblock[molIndex].type];
-
- atoms = &molType->atoms;
+ const gmx_moltype_t &molType = mtop->moltype[molBlock.type];
+ const t_atoms &atoms = molType.atoms;
- for (int j = 0; j < mtop->molblock[molIndex].nmol; j++)
+ for (int j = 0; j < molBlock.nmol; j++)
{
- for (int atomIndex = 0; atomIndex < atoms->nr; atomIndex++, i++)
+ for (int atomIndex = 0; atomIndex < atoms.nr; atomIndex++, i++)
{
if (ggrpnr(&mtop->groups, gtype, i) != 0)
{
static void add_selection_groups(gmx_tng_trajectory_t gmx_tng,
const gmx_mtop_t *mtop)
{
- const gmx_moltype_t *molType;
const t_atoms *atoms;
const t_atom *at;
const t_resinfo *resInfo;
tng_residue_t res;
tng_atom_t atom;
tng_bond_t tngBond;
- gmx_int64_t nMols;
+ int64_t nMols;
char *groupName;
tng_trajectory_t tng = gmx_tng->tng;
tng_molecule_alloc(tng, &mol);
tng_molecule_name_set(tng, mol, groupName);
tng_molecule_chain_add(tng, mol, "", &chain);
- for (int molIndex = 0, i = 0; molIndex < mtop->nmolblock; molIndex++)
+ int i = 0;
+ for (const gmx_molblock_t &molBlock : mtop->molblock)
{
- molType = &mtop->moltype[mtop->molblock[molIndex].type];
+ const gmx_moltype_t &molType = mtop->moltype[molBlock.type];
- atoms = &molType->atoms;
+ atoms = &molType.atoms;
- for (int j = 0; j < mtop->molblock[molIndex].nmol; j++)
+ for (int j = 0; j < molBlock.nmol; j++)
{
bool bAtomsAdded = FALSE;
for (int atomIndex = 0; atomIndex < atoms->nr; atomIndex++, i++)
}
else
{
- res_name = (char *)"";
+ res_name = const_cast<char*>("");
res_id = 0;
}
if (tng_chain_residue_find(tng, chain, res_name, res_id, &res)
{
if (IS_CHEMBOND(k))
{
- ilist = &molType->ilist[k];
+ ilist = &molType.ilist[k];
if (ilist)
{
int l = 1;
}
}
/* Settle is described using three atoms */
- ilist = &molType->ilist[F_SETTLE];
+ ilist = &molType.ilist[F_SETTLE];
if (ilist)
{
int l = 1;
tng_molecule_existing_add(tng, &mol);
tng_molecule_cnt_set(tng, mol, 1);
tng_num_molecule_types_get(tng, &nMols);
- for (gmx_int64_t k = 0; k < nMols; k++)
+ for (int64_t k = 0; k < nMols; k++)
{
tng_molecule_of_index_get(tng, k, &iterMol);
if (iterMol == mol)
void gmx_fwrite_tng(gmx_tng_trajectory_t gmx_tng,
const gmx_bool bUseLossyCompression,
- gmx_int64_t step,
+ int64_t step,
real elapsedPicoSeconds,
real lambda,
const rvec *box,
{
#if GMX_USE_TNG
typedef tng_function_status (*write_data_func_pointer)(tng_trajectory_t,
- const gmx_int64_t,
+ const int64_t,
const double,
const real*,
- const gmx_int64_t,
- const gmx_int64_t,
+ const int64_t,
+ const int64_t,
const char*,
const char,
const char);
static write_data_func_pointer write_data = tng_util_generic_with_time_write;
#endif
double elapsedSeconds = elapsedPicoSeconds * PICO;
- gmx_int64_t nParticles;
+ int64_t nParticles;
char compression;
}
tng_num_particles_get(tng, &nParticles);
- if (nAtoms != (int)nParticles)
+ if (nAtoms != static_cast<int>(nParticles))
{
tng_implicit_num_particles_set(tng, nAtoms);
}
}
}
- /* TNG-MF1 compression only compresses positions and velocities. Use lossless
- * compression for lambdas and box shape regardless of output mode */
- if (write_data(tng, step, elapsedSeconds,
- reinterpret_cast<const real *>(box),
- 9, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE",
- TNG_NON_PARTICLE_BLOCK_DATA,
- TNG_GZIP_COMPRESSION) != TNG_SUCCESS)
+ if (box)
{
- gmx_file("Cannot write TNG trajectory frame; maybe you are out of disk space?");
+ /* TNG-MF1 compression only compresses positions and velocities. Use lossless
+ * compression for box shape regardless of output mode */
+ if (write_data(tng, step, elapsedSeconds,
+ reinterpret_cast<const real *>(box),
+ 9, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE",
+ TNG_NON_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION) != TNG_SUCCESS)
+ {
+ gmx_file("Cannot write TNG trajectory frame; maybe you are out of disk space?");
+ }
}
- if (write_data(tng, step, elapsedSeconds,
- reinterpret_cast<const real *>(&lambda),
- 1, TNG_GMX_LAMBDA, "LAMBDAS",
- TNG_NON_PARTICLE_BLOCK_DATA,
- TNG_GZIP_COMPRESSION) != TNG_SUCCESS)
+ if (lambda >= 0)
{
- gmx_file("Cannot write TNG trajectory frame; maybe you are out of disk space?");
+ /* TNG-MF1 compression only compresses positions and velocities. Use lossless
+ * compression for lambda regardless of output mode */
+ if (write_data(tng, step, elapsedSeconds,
+ reinterpret_cast<const real *>(&lambda),
+ 1, TNG_GMX_LAMBDA, "LAMBDAS",
+ TNG_NON_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION) != TNG_SUCCESS)
+ {
+ gmx_file("Cannot write TNG trajectory frame; maybe you are out of disk space?");
+ }
}
// Update the data in the wrapper
float gmx_tng_get_time_of_final_frame(gmx_tng_trajectory_t gmx_tng)
{
#if GMX_USE_TNG
- gmx_int64_t nFrames;
+ int64_t nFrames;
double time;
float fTime;
tng_trajectory_t tng = gmx_tng->tng;
tng_trajectory_t *input = (gmx_tng_input && *gmx_tng_input) ? &(*gmx_tng_input)->tng : nullptr;
/* FIXME after 5.0: Currently only standard block types are read */
const int defaultNumIds = 5;
- static gmx_int64_t fallbackIds[defaultNumIds] =
+ static int64_t fallbackIds[defaultNumIds] =
{
TNG_TRAJ_BOX_SHAPE, TNG_TRAJ_POSITIONS,
TNG_TRAJ_VELOCITIES, TNG_TRAJ_FORCES,
};
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 int64_t,
+ const int64_t,
+ const int64_t,
const char*,
const char,
const char);
* 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;
+ int64_t n_frames_per_frame_set, interval = -1;
tng_compression_precision_get(*input, &compression_precision);
tng_compression_precision_set(*output, compression_precision);
set_writing_interval(*output, interval, 9, fallbackIds[i],
fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
TNG_GZIP_COMPRESSION);
+ (*gmx_tng_output)->boxOutputInterval = interval;
break;
case TNG_GMX_LAMBDA:
set_writing_interval(*output, interval, 1, fallbackIds[i],
fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
TNG_GZIP_COMPRESSION);
+ (*gmx_tng_output)->lambdaOutputInterval = interval;
break;
default:
continue;
{
for (j = 0; j < nValues; j++)
{
- to[i*nValues+j] = reinterpret_cast<gmx_int64_t *>(from)[i*nValues+j] * fact;
+ to[i*nValues+j] = reinterpret_cast<int64_t *>(from)[i*nValues+j] * fact;
}
}
break;
break;
default:
gmx_incons("Illegal datatype when converting values to a real array!");
- return;
}
- return;
}
real getDistanceScaleFactor(gmx_tng_trajectory_t in)
{
- gmx_int64_t exp = -1;
+ int64_t exp = -1;
real distanceScaleFactor;
// TODO Hopefully, TNG 2.0 will do this kind of thing for us
const char *name)
{
#if GMX_USE_TNG
- gmx_int64_t nAtoms, cnt, nMols;
+ int64_t nAtoms, cnt, nMols;
tng_molecule_t mol, iterMol;
tng_chain_t chain;
tng_residue_t res;
* other molecules to 0 */
tng_molecule_cnt_set(tng, mol, 1);
tng_num_molecule_types_get(tng, &nMols);
- for (gmx_int64_t k = 0; k < nMols; k++)
+ for (int64_t k = 0; k < nMols; k++)
{
tng_molecule_of_index_get(tng, k, &iterMol);
if (iterMol == mol)
* and lose no information. */
gmx_bool gmx_read_next_tng_frame(gmx_tng_trajectory_t gmx_tng_input,
t_trxframe *fr,
- gmx_int64_t *requestedIds,
+ int64_t *requestedIds,
int numRequestedIds)
{
#if GMX_USE_TNG
tng_trajectory_t input = gmx_tng_input->tng;
gmx_bool bOK = TRUE;
tng_function_status stat;
- gmx_int64_t numberOfAtoms = -1, frameNumber = -1;
- gmx_int64_t nBlocks, blockId, *blockIds = nullptr, codecId;
+ int64_t numberOfAtoms = -1, frameNumber = -1;
+ int64_t nBlocks, blockId, *blockIds = nullptr, codecId;
char datatype = -1;
void *values = nullptr;
double frameTime = -1.0;
int size, blockDependency;
double prec;
const int defaultNumIds = 5;
- static gmx_int64_t fallbackRequestedIds[defaultNumIds] =
+ static int64_t fallbackRequestedIds[defaultNumIds] =
{
TNG_TRAJ_BOX_SHAPE, TNG_TRAJ_POSITIONS,
TNG_TRAJ_VELOCITIES, TNG_TRAJ_FORCES,
&frameNumber,
&nBlocks,
&blockIds);
- gmx::unique_cptr<gmx_int64_t, gmx::free_wrapper> blockIdsGuard(blockIds);
+ gmx::unique_cptr<int64_t, gmx::free_wrapper> blockIdsGuard(blockIds);
if (!nextFrameExists)
{
return FALSE;
return FALSE;
}
- for (gmx_int64_t i = 0; i < nBlocks; i++)
+ for (int64_t i = 0; i < nBlocks; i++)
{
blockId = blockIds[i];
tng_data_block_dependency_get(input, blockId, &blockDependency);
switch (datatype)
{
case TNG_INT_DATA:
- size = sizeof(gmx_int64_t);
+ size = sizeof(int64_t);
break;
case TNG_FLOAT_DATA:
size = sizeof(float);
case TNG_TRAJ_VELOCITIES:
srenew(fr->v, fr->natoms);
convert_array_to_real_array(values,
- (real *) fr->v,
+ reinterpret_cast<real *>(fr->v),
getDistanceScaleFactor(gmx_tng_input),
fr->natoms,
DIM,
FILE *stream)
{
#if GMX_USE_TNG
- gmx_int64_t nMolecules, nChains, nResidues, nAtoms, nFramesRead;
- gmx_int64_t strideLength, nParticlesRead, nValuesPerFrameRead, *molCntList;
+ int64_t nMolecules, nChains, nResidues, nAtoms, nFramesRead;
+ int64_t strideLength, nParticlesRead, nValuesPerFrameRead, *molCntList;
tng_molecule_t molecule;
tng_chain_t chain;
tng_residue_t residue;
/* Can the number of particles change in the trajectory or is it constant? */
tng_num_particles_variable_get(input, &varNAtoms);
- for (gmx_int64_t i = 0; i < nMolecules; i++)
+ for (int64_t i = 0; i < nMolecules; i++)
{
tng_molecule_of_index_get(input, i, &molecule);
tng_molecule_name_get(input, molecule, str, 256);
if (varNAtoms == TNG_CONSTANT_N_ATOMS)
{
- if ((int)molCntList[i] == 0)
+ if (static_cast<int>(molCntList[i]) == 0)
{
continue;
}
- fprintf(stream, "Molecule: %s, count: %d\n", str, (int)molCntList[i]);
+ fprintf(stream, "Molecule: %s, count: %d\n", str, static_cast<int>(molCntList[i]));
}
else
{
tng_molecule_num_chains_get(input, molecule, &nChains);
if (nChains > 0)
{
- for (gmx_int64_t j = 0; j < nChains; j++)
+ for (int64_t j = 0; j < nChains; j++)
{
tng_molecule_chain_of_index_get(input, molecule, j, &chain);
tng_chain_name_get(input, chain, str, 256);
fprintf(stream, "\tChain: %s\n", str);
tng_chain_num_residues_get(input, chain, &nResidues);
- for (gmx_int64_t k = 0; k < nResidues; k++)
+ for (int64_t k = 0; k < nResidues; k++)
{
tng_chain_residue_of_index_get(input, chain, k, &residue);
tng_residue_name_get(input, residue, str, 256);
fprintf(stream, "\t\tResidue: %s\n", str);
tng_residue_num_atoms_get(input, residue, &nAtoms);
- for (gmx_int64_t l = 0; l < nAtoms; l++)
+ for (int64_t l = 0; l < nAtoms; l++)
{
tng_residue_atom_of_index_get(input, residue, l, &atom);
tng_atom_name_get(input, atom, str, 256);
tng_molecule_num_residues_get(input, molecule, &nResidues);
if (nResidues > 0)
{
- for (gmx_int64_t k = 0; k < nResidues; k++)
+ for (int64_t k = 0; k < nResidues; k++)
{
tng_molecule_residue_of_index_get(input, molecule, k, &residue);
tng_residue_name_get(input, residue, str, 256);
fprintf(stream, "\t\tResidue: %s\n", str);
tng_residue_num_atoms_get(input, residue, &nAtoms);
- for (gmx_int64_t l = 0; l < nAtoms; l++)
+ for (int64_t l = 0; l < nAtoms; l++)
{
tng_residue_atom_of_index_get(input, residue, l, &atom);
tng_atom_name_get(input, atom, str, 256);
else
{
tng_molecule_num_atoms_get(input, molecule, &nAtoms);
- for (gmx_int64_t l = 0; l < nAtoms; l++)
+ for (int64_t l = 0; l < nAtoms; l++)
{
tng_molecule_atom_of_index_get(input, molecule, l, &atom);
tng_atom_name_get(input, atom, str, 256);
datatype);
fprintf(stream, "Atom Charges (%d):\n", int(nAtoms));
- for (gmx_int64_t i = 0; i < nAtoms; i += 10)
+ for (int64_t i = 0; i < nAtoms; i += 10)
{
fprintf(stream, "Atom Charges [%8d-]=[", int(i));
- for (gmx_int64_t j = 0; (j < 10 && i + j < nAtoms); j++)
+ for (int64_t j = 0; (j < 10 && i + j < nAtoms); j++)
{
fprintf(stream, " %12.5e", atomCharges[i + j]);
}
datatype);
fprintf(stream, "Atom Masses (%d):\n", int(nAtoms));
- for (gmx_int64_t i = 0; i < nAtoms; i += 10)
+ for (int64_t i = 0; i < nAtoms; i += 10)
{
fprintf(stream, "Atom Masses [%8d-]=[", int(i));
- for (gmx_int64_t j = 0; (j < 10 && i + j < nAtoms); j++)
+ for (int64_t j = 0; (j < 10 && i + j < nAtoms); j++)
{
fprintf(stream, " %12.5e", atomMasses[i + j]);
}
gmx_bool gmx_get_tng_data_block_types_of_next_frame(gmx_tng_trajectory_t gmx_tng_input,
int frame,
int nRequestedIds,
- gmx_int64_t *requestedIds,
- gmx_int64_t *nextFrame,
- gmx_int64_t *nBlocks,
- gmx_int64_t **blockIds)
+ int64_t *requestedIds,
+ int64_t *nextFrame,
+ int64_t *nBlocks,
+ int64_t **blockIds)
{
#if GMX_USE_TNG
tng_function_status stat;
}
gmx_bool gmx_get_tng_data_next_frame_of_block_type(gmx_tng_trajectory_t gmx_tng_input,
- gmx_int64_t blockId,
+ int64_t blockId,
real **values,
- gmx_int64_t *frameNumber,
+ int64_t *frameNumber,
double *frameTime,
- gmx_int64_t *nValuesPerFrame,
- gmx_int64_t *nAtoms,
+ int64_t *nValuesPerFrame,
+ int64_t *nAtoms,
real *prec,
char *name,
int maxLen,
#if GMX_USE_TNG
tng_function_status stat;
char datatype = -1;
- gmx_int64_t codecId;
+ int64_t codecId;
int blockDependency;
void *data = nullptr;
double localPrec;
return FALSE;
#endif
}
+
+int gmx_tng_get_box_output_interval(gmx_tng_trajectory_t gmx_tng)
+{
+#if GMX_USE_TNG
+ return gmx_tng->boxOutputInterval;
+#else
+ GMX_UNUSED_VALUE(gmx_tng);
+#endif
+}
+
+int gmx_tng_get_lambda_output_interval(gmx_tng_trajectory_t gmx_tng)
+{
+#if GMX_USE_TNG
+ return gmx_tng->lambdaOutputInterval;
+#else
+ GMX_UNUSED_VALUE(gmx_tng);
+#endif
+}