}
}
-static void done_gmx_groups_t(gmx_groups_t *g)
-{
- int i;
-
- for (i = 0; (i < egcNR); i++)
- {
- if (NULL != g->grps[i].nm_ind)
- {
- sfree(g->grps[i].nm_ind);
- g->grps[i].nm_ind = NULL;
- }
- if (NULL != g->grpnr[i])
- {
- sfree(g->grpnr[i]);
- g->grpnr[i] = NULL;
- }
- }
- /* The contents of this array is in symtab, don't free it here */
- sfree(g->grpname);
-}
-
static void readConfAndAtoms(const char *infile,
t_symtab *symtab, char ***name, t_atoms *atoms,
int *ePBC,
snew(mtop, 1);
readConfAndTopology(infile, &haveTopology, mtop, ePBC, x, v, box);
- *top = gmx_mtop_t_to_t_topology(mtop);
- /* In this case we need to throw away the group data too */
- done_gmx_groups_t(&mtop->groups);
+ *top = gmx_mtop_t_to_t_topology(mtop, true);
sfree(mtop);
tpx_make_chain_identifiers(&top->atoms, &top->mols);
ePBC = read_tpx(fn, ir, box, natoms, x, v, &mtop);
- *top = gmx_mtop_t_to_t_topology(&mtop);
+ *top = gmx_mtop_t_to_t_topology(&mtop, true);
return ePBC;
}
}
std::vector<size_t> atom_index = get_atom_index(&mtop);
- top = gmx_mtop_t_to_t_topology(&mtop);
+ top = gmx_mtop_t_to_t_topology(&mtop, true);
bM = TRUE;
int ndim = DIM*atom_index.size();
* We should implement direct mtop comparison,
* but it might be useful to keep t_topology comparison as an option.
*/
- top[0] = gmx_mtop_t_to_t_topology(&mtop[0]);
- top[1] = gmx_mtop_t_to_t_topology(&mtop[1]);
+ top[0] = gmx_mtop_t_to_t_topology(&mtop[0], false);
+ top[1] = gmx_mtop_t_to_t_topology(&mtop[1], false);
cmp_top(stdout, &top[0], &top[1], ftol, abstol);
cmp_groups(stdout, &mtop[0].groups, &mtop[1].groups,
mtop[0].natoms, mtop[1].natoms);
* We should implement direct mtop comparison,
* but it might be useful to keep t_topology comparison as an option.
*/
- top[0] = gmx_mtop_t_to_t_topology(&mtop[0]);
+ top[0] = gmx_mtop_t_to_t_topology(&mtop[0], true);
cmp_top(stdout, &top[0], NULL, ftol, abstol);
}
}
int *invindex;
int i;
- top = gmx_mtop_t_to_t_topology(mtop);
+ top = gmx_mtop_t_to_t_topology(mtop, false);
bKeep = bKeepIt(gnx, top.atoms.nr, index);
invindex = invind(gnx, top.atoms.nr, index);
{
if (bSysTop)
{
- top = gmx_mtop_t_to_t_topology(&mtop);
+ top = gmx_mtop_t_to_t_topology(&mtop, false);
}
if (available(stdout, &tpx, 0, fn))
return top;
}
-t_topology gmx_mtop_t_to_t_topology(gmx_mtop_t *mtop)
+static void done_gmx_groups_t(gmx_groups_t *g)
+{
+ int i;
+
+ for (i = 0; (i < egcNR); i++)
+ {
+ if (NULL != g->grps[i].nm_ind)
+ {
+ sfree(g->grps[i].nm_ind);
+ g->grps[i].nm_ind = NULL;
+ }
+ if (NULL != g->grpnr[i])
+ {
+ sfree(g->grpnr[i]);
+ g->grpnr[i] = NULL;
+ }
+ }
+ /* The contents of this array is in symtab, don't free it here */
+ sfree(g->grpname);
+}
+
+t_topology gmx_mtop_t_to_t_topology(gmx_mtop_t *mtop, bool freeMTop)
{
int mt, mb;
gmx_localtop_t ltop;
top.bIntermolecularInteractions = mtop->bIntermolecularInteractions;
top.symtab = mtop->symtab;
- /* We only need to free the moltype and molblock data,
- * all other pointers have been copied to top.
- *
- * Well, except for the group data, but we can't free those, because they
- * are used somewhere even after a call to this function.
- */
- for (mt = 0; mt < mtop->nmoltype; mt++)
+ if (freeMTop)
{
- done_moltype(&mtop->moltype[mt]);
- }
- sfree(mtop->moltype);
+ // Free pointers that have not been copied to top.
+ for (mt = 0; mt < mtop->nmoltype; mt++)
+ {
+ done_moltype(&mtop->moltype[mt]);
+ }
+ sfree(mtop->moltype);
- for (mb = 0; mb < mtop->nmolblock; mb++)
- {
- done_molblock(&mtop->molblock[mb]);
+ for (mb = 0; mb < mtop->nmolblock; mb++)
+ {
+ done_molblock(&mtop->molblock[mb]);
+ }
+ sfree(mtop->molblock);
+
+ done_gmx_groups_t(&mtop->groups);
}
- sfree(mtop->molblock);
return top;
}
/* Generate a 'local' topology for the whole system.
- * When feeEnergyInteractionsAtEnd == true, the free energy interactions will
+ * When freeEnergyInteractionsAtEnd == true, the free energy interactions will
* be sorted to the end.
*/
gmx_localtop_t *
/* Converts a gmx_mtop_t struct to t_topology.
- * All memory relating only to mtop will be freed.
+ *
+ * If freeMTop == true, memory related to mtop will be freed so that done_top()
+ * on the result value will free all memory.
+ * If freeMTop == false, mtop and the return value will share some of their
+ * memory, and there is currently no way to consistently free all the memory.
*/
t_topology
-gmx_mtop_t_to_t_topology(gmx_mtop_t *mtop);
+gmx_mtop_t_to_t_topology(gmx_mtop_t *mtop, bool freeMTop);
/*! \brief Get vector of atoms indices from topology
*
void done_mtop(gmx_mtop_t *mtop, gmx_bool bDoneSymtab);
void done_top(t_topology *top);
-t_atoms *mtop2atoms(gmx_mtop_t *mtop);
-/* generate a t_atoms struct for the system from gmx_mtop_t */
-
void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
gmx_bool bShowNumbers);
void pr_top(FILE *fp, int indent, const char *title, const t_topology *top, gmx_bool bShowNumbers);