#include "gromacs/topology/ifunc.h"
#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/txtdump.h"
static void pr_harm(FILE *fp, const t_iparams *iparams, const char *r, const char *kr)
}
}
}
+
+void init_idef(t_idef *idef)
+{
+ idef->ntypes = 0;
+ idef->atnr = 0;
+ idef->functype = nullptr;
+ idef->iparams = nullptr;
+ idef->fudgeQQ = 0.0;
+ idef->iparams_posres = nullptr;
+ idef->iparams_fbposres = nullptr;
+ for (int f = 0; f < F_NRE; ++f)
+ {
+ idef->il[f].iatoms = nullptr;
+ idef->il[f].nalloc = 0;
+ idef->il[f].nr = 0;
+ idef->il[f].nr_nonperturbed = 0;
+ }
+ idef->cmap_grid.cmapdata = nullptr;
+ idef->iparams_posres_nalloc = 0;
+ idef->iparams_fbposres_nalloc = 0;
+ idef->ilsort = 0;
+}
+
+void done_idef(t_idef *idef)
+{
+ sfree(idef->functype);
+ sfree(idef->iparams);
+ sfree(idef->iparams_posres);
+ sfree(idef->iparams_fbposres);
+ for (int f = 0; f < F_NRE; ++f)
+ {
+ sfree(idef->il[f].iatoms);
+ }
+
+ sfree(idef->cmap_grid.cmapdata);
+ init_idef(idef);
+}
void pr_idef(FILE *fp, int indent, const char *title, const t_idef *idef,
gmx_bool bShowNumbers, gmx_bool bShowParameters);
+/*! \brief
+ * Properly initialize idef struct.
+ *
+ * \param[in] idef Pointer to idef struct to initialize.
+ */
+void init_idef(t_idef *idef);
+
+/*! \brief
+ * Properly clean up idef struct.
+ *
+ * \param[in] idef Pointer to idef struct to clean up.
+ */
+void done_idef(t_idef *idef);
+
#endif
void init_top(t_topology *top)
{
top->name = nullptr;
+ init_idef(&top->idef);
init_atom(&(top->atoms));
init_atomtypes(&(top->atomtypes));
init_block(&top->cgs);
void done_top(t_topology *top)
{
- sfree(top->idef.functype);
- sfree(top->idef.iparams);
- sfree(top->idef.cmap_grid.cmapdata);
- for (int f = 0; f < F_NRE; ++f)
- {
- sfree(top->idef.il[f].iatoms);
- top->idef.il[f].iatoms = nullptr;
- top->idef.il[f].nalloc = 0;
- }
-
+ done_idef(&top->idef);
done_atom(&(top->atoms));
/* For GB */
{
if (top != nullptr)
{
- for (int f = 0; f < F_NRE; ++f)
- {
- sfree(top->idef.il[f].iatoms);
- top->idef.il[f].iatoms = nullptr;
- top->idef.il[f].nalloc = 0;
- }
+ done_idef(&top->idef);
done_atom(&top->atoms);
done_block(&top->cgs);
done_blocka(&top->excls);
done_block(&top->mols);
done_symtab(&top->symtab);
open_symtab(&mtop->symtab);
- sfree(top->idef.functype);
- sfree(top->idef.iparams);
- sfree(top->idef.cmap_grid.cmapdata);
done_atomtypes(&(top->atomtypes));
}
}
}
+void init_localtop(gmx_localtop_t *top)
+{
+ init_block(&top->cgs);
+ init_blocka(&top->excls);
+ init_idef(&top->idef);
+ init_atomtypes(&top->atomtypes);
+}
+
void done_localtop(gmx_localtop_t *top)
{
if (top == nullptr)
{
return;
}
- sfree(top->idef.cmap_grid.cmapdata);
- sfree(top->idef.functype);
- sfree(top->idef.iparams);
+ done_idef(&top->idef);
done_block(&top->cgs);
done_blocka(&top->excls);
- for (int f = 0; f < F_NRE; f++)
- {
- sfree(top->idef.il[f].iatoms);
- }
- sfree(top->idef.iparams_posres);
- sfree(top->idef.iparams_fbposres);
done_atomtypes(&top->atomtypes);
}
// Frees both t_topology and gmx_mtop_t when the former has been created from
// the latter.
void done_top_mtop(t_topology *top, gmx_mtop_t *mtop);
+/*! \brief
+ * Properly initialize local topology.
+ *
+ * \param[in] top Pointer to topology to initialize.
+ */
+void init_localtop(gmx_localtop_t *top);
+/*! \brief
+ * Properly clear up local topology,
+ *
+ * \param[in] top Pointer to topology to clear up.
+ */
void done_localtop(gmx_localtop_t *top);
void done_and_sfree_localtop(gmx_localtop_t *top);