Move types/topology.h to topology/
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 25 May 2014 03:20:55 +0000 (06:20 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sun, 25 May 2014 03:20:55 +0000 (06:20 +0300)
- Make the types forward-declarable, and use that in a few headers.
- Adapt files that were including the file directly.
- Move functions that operate on these structs from typedefs.[ch] to
  topology/ as well, and make callers of those functions include
  topology.h.

typedefs.h still brings this header with it.  That will be cleaned up
separately in parts.

Change-Id: Iff50b854c335d10b97fd79c65d21791e5ae432a1

22 files changed:
src/gromacs/fileio/confio.c
src/gromacs/fileio/confio.h
src/gromacs/fileio/enxio.h
src/gromacs/fileio/mdoutf.h
src/gromacs/fileio/pdbio.h
src/gromacs/fileio/tpxio.c
src/gromacs/fileio/tpxio.h
src/gromacs/fileio/trxio.h
src/gromacs/gmxana/gmx_trjconv.c
src/gromacs/gmxana/nsfactor.c
src/gromacs/gmxana/nsfactor.h
src/gromacs/gmxlib/typedefs.c
src/gromacs/gmxpreprocess/addconf.c
src/gromacs/gmxpreprocess/grompp.c
src/gromacs/gmxpreprocess/topio.c
src/gromacs/legacyheaders/typedefs.h
src/gromacs/pbcutil/rmpbc.c
src/gromacs/selection/tests/toputils.cpp
src/gromacs/topology/CMakeLists.txt
src/gromacs/topology/topology.cpp [new file with mode: 0644]
src/gromacs/topology/topology.h [moved from src/gromacs/legacyheaders/types/topology.h with 88% similarity]
src/gromacs/trajectoryanalysis/analysissettings.cpp

index b6b5ca87d16726b7d4fc639fa51f7ce529de6d3d..ee227624c15da45864682032add73cd4f785206b 100644 (file)
 #include <math.h>
 
 #include "typedefs.h"
-#include "gromacs/utility/smalloc.h"
 #include "macros.h"
-#include "gromacs/utility/cstringutil.h"
 #include "confio.h"
 #include "gromacs/math/vec.h"
-#include "gromacs/topology/symtab.h"
 #include "gromacs/utility/futil.h"
 #include "xdrf.h"
 #include "filenm.h"
 #include "pdbio.h"
 #include "tpxio.h"
 #include "trxio.h"
-#include "gromacs/utility/fatalerror.h"
 #include "copyrite.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "mtop_util.h"
 #include "gmxfio.h"
 
+#include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
+
 #define CHAR_SHIFT 24
 
 static int read_g96_pos(char line[], t_symtab *symtab,
index ba6d246b0794196d7211c083db76157daa8e368d..6fbafb3ee485e1bcbf146f0ed14cce99dc8fa761 100644 (file)
@@ -41,7 +41,6 @@
 #include <stdio.h>
 
 #include "../legacyheaders/types/simple.h"
-#include "../legacyheaders/types/topology.h"
 
 #include "trx.h"
 
@@ -52,6 +51,7 @@
 extern "C" {
 #endif
 
+struct gmx_mtop_t;
 struct t_atoms;
 
 int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line);
@@ -94,7 +94,7 @@ void write_sto_conf(const char *outfile, const char *title,
  * to an STO (.gro or .pdb) file */
 
 void write_sto_conf_mtop(const char *outfile, const char *title,
-                         gmx_mtop_t *mtop,
+                         struct gmx_mtop_t *mtop,
                          rvec x[], rvec *v, int ePBC, matrix box);
 /* As write_sto_conf, but uses a gmx_mtop_t struct */
 
index d92cb040b37a5c92655a6a631be3fcf2f6311e1a..acf41f05f1a1e9e2e44f696a4ef3233f4c72db9a 100644 (file)
@@ -40,7 +40,6 @@
 #include "../legacyheaders/types/energy.h"
 #include "../legacyheaders/types/inputrec.h"
 #include "../legacyheaders/types/state.h"
-#include "../legacyheaders/types/topology.h"
 #include "gmxfio.h"
 #include "xdr_datatype.h"
 
@@ -48,6 +47,8 @@
 extern "C" {
 #endif
 
+struct gmx_groups_t;
+
 /**************************************************************
  * These are the base datatypes + functions for reading and
  * writing energy files (.edr). They are either called directly
@@ -187,7 +188,7 @@ gmx_bool do_enx(ener_file_t ef, t_enxframe *fr);
 /* Reads enx_frames, memory in fr is (re)allocated if necessary */
 
 void get_enx_state(const char *fn, real t,
-                   gmx_groups_t *groups, t_inputrec *ir,
+                   struct gmx_groups_t *groups, t_inputrec *ir,
                    t_state *state);
 /*
  * Reads state variables from enx file fn at time t.
index 0f87050184196202161e0539cb24739678301c19..243920ea90eaba1e6b40f07f05de6d5995a628b6 100644 (file)
@@ -38,7 +38,6 @@
 
 #include <stdio.h>
 
-#include "../legacyheaders/types/topology.h"
 #include "../legacyheaders/types/inputrec.h"
 #include "../legacyheaders/types/oenv.h"
 #include "../legacyheaders/network.h"
@@ -48,6 +47,8 @@
 #include "filenm.h"
 #include "enxio.h"
 
+struct gmx_mtop_t;
+
 typedef struct gmx_mdoutf *gmx_mdoutf_t;
 
 /*! \brief Allocate and initialize object to manager trajectory writing output
@@ -61,7 +62,7 @@ gmx_mdoutf_t init_mdoutf(FILE              *fplog,
                          int                mdrun_flags,
                          const t_commrec   *cr,
                          const t_inputrec  *ir,
-                         gmx_mtop_t        *mtop,
+                         struct gmx_mtop_t *mtop,
                          const output_env_t oenv);
 
 /*! \brief Getter for file pointer */
index ae775df0f0a157664b50d2f9e53cc9673a61f520..e3a69b44868cd5af833acc1885bf940d66fd903a 100644 (file)
 #include <stdio.h>
 
 #include "../legacyheaders/atomprop.h"
-#include "../legacyheaders/types/topology.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct t_atoms;
+struct t_topology;
 
 typedef struct gmx_conect_t *gmx_conect;
 
@@ -82,7 +82,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box);
  * This function is fundamentally broken as far as thread-safety is concerned.
  */
 
-void write_pdbfile_indexed(FILE *out, const char *title, t_atoms *atoms,
+void write_pdbfile_indexed(FILE *out, const char *title, struct t_atoms *atoms,
                            rvec x[], int ePBC, matrix box, char chain,
                            int model_nr, atom_id nindex, const atom_id index[],
                            gmx_conect conect, gmx_bool bTerSepChains);
@@ -141,7 +141,7 @@ gmx_bool gmx_conect_exist(gmx_conect conect, int ai, int aj);
 void gmx_conect_add(gmx_conect conect, int ai, int aj);
 /* Add a connection between ai and aj (numbered from 0 to natom-1) */
 
-gmx_conect gmx_conect_generate(t_topology *top);
+gmx_conect gmx_conect_generate(struct t_topology *top);
 /* Generate a conect structure from a topology */
 
 gmx_conect gmx_conect_init(void);
index 90c07f0cfbde0c69e94277536469507ddb18b284..d7fc7a4982a3bd46d860ff99684a78ffc8f24b50 100644 (file)
@@ -58,6 +58,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
index 8279544c1f7433b54ef95248783eb22184e2d254..3611be60d249fbc8c58fd80ac40b76f233bd6ec2 100644 (file)
  **************************************************************/
 #include "../legacyheaders/types/inputrec.h"
 #include "../legacyheaders/types/state.h"
-#include "../legacyheaders/types/topology.h"
 #include "gmxfio.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gmx_mtop_t;
 struct t_atoms;
 struct t_block;
+struct t_topology;
 
 typedef struct
 {
@@ -112,7 +113,7 @@ void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
  */
 
 void write_tpx_state(const char *fn,
-                     t_inputrec *ir, t_state *state, gmx_mtop_t *mtop);
+                     t_inputrec *ir, t_state *state, struct gmx_mtop_t *mtop);
 /* Write a file, and close it again.
  * If fn == NULL, an efTPA file will be written to stdout (which
  * will not be closed afterwards)
@@ -120,10 +121,10 @@ void write_tpx_state(const char *fn,
 
 void read_tpx_state(const char *fn,
                     t_inputrec *ir, t_state *state, rvec *f,
-                    gmx_mtop_t *mtop);
+                    struct gmx_mtop_t *mtop);
 int read_tpx(const char *fn,
              t_inputrec *ir, matrix box, int *natoms,
-             rvec *x, rvec *v, rvec *f, gmx_mtop_t *mtop);
+             rvec *x, rvec *v, rvec *f, struct gmx_mtop_t *mtop);
 /* Read a file, and close it again.
  * If fn == NULL, an efTPA file will be read from stdin (which
  * will not be closed afterwards)
@@ -133,13 +134,13 @@ int read_tpx(const char *fn,
 
 int read_tpx_top(const char *fn,
                  t_inputrec *ir, matrix box, int *natoms,
-                 rvec *x, rvec *v, rvec *f, t_topology *top);
+                 rvec *x, rvec *v, rvec *f, struct t_topology *top);
 /* As read_tpx, but for the old t_topology struct */
 
 gmx_bool fn2bTPX(const char *file);
 /* return if *file is one of the TPX file types */
 
-gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top,
+gmx_bool read_tps_conf(const char *infile, char *title, struct t_topology *top,
                        int *ePBC, rvec **x, rvec **v, matrix box, gmx_bool bMass);
 /* Read title, top.atoms, x, v (if not NULL) and box from an STX file,
  * memory for atoms, x and v will be allocated.
index 6953e50883c3502e392157bd56cd6157129bdbbf..3f7305984c6d19e9e779a4421ad1366d6dfc09c6 100644 (file)
@@ -38,7 +38,6 @@
 #ifndef GMX_FILEIO_TRXIO_H
 #define GMX_FILEIO_TRXIO_H
 
-#include "../legacyheaders/types/topology.h"
 #include "../legacyheaders/readinp.h"
 #include "../legacyheaders/oenv.h"
 
@@ -53,6 +52,7 @@ extern "C" {
 }
 #endif
 
+struct gmx_mtop_t;
 struct t_atoms;
 
 /* a dedicated status type contains fp, etc. */
@@ -105,15 +105,15 @@ int write_trx(t_trxstatus *status, int nind, const atom_id *ind, struct t_atoms
  * atoms can be NULL for file types which don't need atom names.
  */
 
-void trjtools_gmx_prepare_tng_writing(const char       *filename,
-                                      char              filemode,
-                                      t_trxstatus      *in,
-                                      t_trxstatus     **out,
-                                      const char       *infile,
-                                      const int         natoms,
-                                      const gmx_mtop_t *mtop,
-                                      const atom_id    *index,
-                                      const char       *index_group_name);
+void trjtools_gmx_prepare_tng_writing(const char               *filename,
+                                      char                      filemode,
+                                      t_trxstatus              *in,
+                                      t_trxstatus             **out,
+                                      const char               *infile,
+                                      const int                 natoms,
+                                      const struct gmx_mtop_t  *mtop,
+                                      const atom_id            *index,
+                                      const char               *index_group_name);
 /* Sets up *out for writing TNG. If *in != NULL and contains a TNG trajectory
  * some data, e.g. molecule system, will be copied over from *in to *out.
  * If *in == NULL a file name (infile) of a TNG file can be provided instead
index 5be71034a468786d609123e78ff2630da8905da1..9c1d72719f28727ca7586d2cdc8df725ff44dce0 100644 (file)
 
 #include "copyrite.h"
 #include "macros.h"
-#include "gromacs/utility/smalloc.h"
 #include "typedefs.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/tngio_for_tools.h"
-#include "gromacs/commandline/pargs.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/confio.h"
 #include "index.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/xtcio.h"
-#include "gromacs/pbcutil/rmpbc.h"
-#include "gromacs/pbcutil/pbc.h"
 #include "viewit.h"
-#include "gromacs/fileio/xvgr.h"
 #include "gmx_ana.h"
 
+#include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/xvgr.h"
 #include "gromacs/math/do_fit.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/pbcutil/rmpbc.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
index ad1517bb5712357e6cc3b11c8aec19f7f44acd97..475ee2b00a344f131c992da786f0715d643e0fa4 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
+#include "nsfactor.h"
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 #include <string.h>
 
-#include "gromacs/math/vec.h"
-#include "nsfactor.h"
-
-#include "gromacs/utility/futil.h"
 #include "gromacs/fileio/strdb.h"
+#include "gromacs/math/vec.h"
 #include "gromacs/random/random.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxomp.h"
 #include "gromacs/utility/smalloc.h"
 
index 367aaa1836ac59a99f18723c46ddbeeb8a65f445..ebe6b808745dafe5cfc91273b72fea6382baaa32 100644 (file)
 #include "gromacs/legacyheaders/index.h"
 #include "gromacs/legacyheaders/oenv.h"
 #include "gromacs/legacyheaders/types/simple.h"
-#include "gromacs/legacyheaders/types/topology.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct t_topology;
+
 typedef struct gmx_neutron_atomic_structurefactors_t {
     int       nratoms;
     int      *p;       /* proton number */
@@ -54,8 +55,8 @@ typedef struct gmx_neutron_atomic_structurefactors_t {
 } gmx_neutron_atomic_structurefactors_t;
 
 typedef struct gmx_sans_t {
-    t_topology *top;     /* topology */
-    double     *slength; /* scattering length for this topology */
+    struct t_topology *top;     /* topology */
+    double            *slength; /* scattering length for this topology */
 } gmx_sans_t;
 
 typedef struct gmx_radial_distribution_histogram_t {
@@ -80,7 +81,7 @@ void normalize_probability(int n, double *a);
 
 gmx_neutron_atomic_structurefactors_t *gmx_neutronstructurefactors_init(const char *datfn);
 
-gmx_sans_t *gmx_sans_init(t_topology *top, gmx_neutron_atomic_structurefactors_t *gnsf);
+gmx_sans_t *gmx_sans_init(struct t_topology *top, gmx_neutron_atomic_structurefactors_t *gnsf);
 
 gmx_radial_distribution_histogram_t *calc_radial_distribution_histogram  (gmx_sans_t  *gsans,
                                                                           rvec        *x,
index 641ed8e34206d3448beb84cbee3daa0c2d257968..390863ba91366f87c8ce9c708fb32f93da657a2a 100644 (file)
@@ -49,9 +49,6 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/random/random.h"
-#include "gromacs/topology/atoms.h"
-#include "gromacs/topology/block.h"
-#include "gromacs/topology/symtab.h"
 #include "gromacs/utility/smalloc.h"
 
 /* The source code in this file should be thread-safe.
@@ -108,48 +105,6 @@ char *gmx_step_str(gmx_int64_t i, char *buf)
     return buf;
 }
 
-void init_groups(gmx_groups_t *groups)
-{
-    int g;
-
-    groups->ngrpname = 0;
-    groups->grpname  = NULL;
-    for (g = 0; (g < egcNR); g++)
-    {
-        groups->grps[g].nm_ind = NULL;
-        groups->ngrpnr[g]      = 0;
-        groups->grpnr[g]       = NULL;
-    }
-
-}
-
-void init_mtop(gmx_mtop_t *mtop)
-{
-    mtop->name         = NULL;
-    mtop->nmoltype     = 0;
-    mtop->moltype      = NULL;
-    mtop->nmolblock    = 0;
-    mtop->molblock     = NULL;
-    mtop->maxres_renum = 0;
-    mtop->maxresnr     = -1;
-    init_groups(&mtop->groups);
-    init_block(&mtop->mols);
-    open_symtab(&mtop->symtab);
-}
-
-void init_top(t_topology *top)
-{
-    int i;
-
-    top->name = NULL;
-    init_atom (&(top->atoms));
-    init_atomtypes(&(top->atomtypes));
-    init_block(&top->cgs);
-    init_block(&top->mols);
-    init_blocka(&top->excls);
-    open_symtab(&top->symtab);
-}
-
 void init_inputrec(t_inputrec *ir)
 {
     memset(ir, 0, (size_t)sizeof(*ir));
@@ -158,84 +113,6 @@ void init_inputrec(t_inputrec *ir)
     snew(ir->simtempvals, 1);
 }
 
-void done_moltype(gmx_moltype_t *molt)
-{
-    int f;
-
-    done_atom(&molt->atoms);
-    done_block(&molt->cgs);
-    done_blocka(&molt->excls);
-
-    for (f = 0; f < F_NRE; f++)
-    {
-        sfree(molt->ilist[f].iatoms);
-        molt->ilist[f].nalloc = 0;
-    }
-}
-
-void done_molblock(gmx_molblock_t *molb)
-{
-    if (molb->nposres_xA > 0)
-    {
-        molb->nposres_xA = 0;
-        sfree(molb->posres_xA);
-    }
-    if (molb->nposres_xB > 0)
-    {
-        molb->nposres_xB = 0;
-        sfree(molb->posres_xB);
-    }
-}
-
-void done_mtop(gmx_mtop_t *mtop, gmx_bool bDoneSymtab)
-{
-    int i;
-
-    if (bDoneSymtab)
-    {
-        done_symtab(&mtop->symtab);
-    }
-
-    sfree(mtop->ffparams.functype);
-    sfree(mtop->ffparams.iparams);
-
-    for (i = 0; i < mtop->nmoltype; i++)
-    {
-        done_moltype(&mtop->moltype[i]);
-    }
-    sfree(mtop->moltype);
-    for (i = 0; i < mtop->nmolblock; i++)
-    {
-        done_molblock(&mtop->molblock[i]);
-    }
-    sfree(mtop->molblock);
-    done_block(&mtop->mols);
-}
-
-void done_top(t_topology *top)
-{
-    int f;
-
-    sfree(top->idef.functype);
-    sfree(top->idef.iparams);
-    for (f = 0; f < F_NRE; ++f)
-    {
-        sfree(top->idef.il[f].iatoms);
-        top->idef.il[f].iatoms = NULL;
-        top->idef.il[f].nalloc = 0;
-    }
-
-    done_atom (&(top->atoms));
-
-    /* For GB */
-    done_atomtypes(&(top->atomtypes));
-
-    done_symtab(&(top->symtab));
-    done_block(&(top->cgs));
-    done_block(&(top->mols));
-    done_blocka(&(top->excls));
-}
-
 static void done_pull_group(t_pull_group *pgrp)
 {
     if (pgrp->nat > 0)
index cc0bf57893280fb33b50ca465e7c3728b8f05eda..1ad661eacb6854b8fb59aad470797451e196962c 100644 (file)
@@ -57,6 +57,7 @@
 
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/block.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/smalloc.h"
 
 static real box_margin;
index 88a24a4243bbfdf444de8046d8c9d69e25e4172f..919a3632722796f2ee092ccc070677d5dbd4e4f1 100644 (file)
 #include "readir.h"
 #include "names.h"
 #include "grompp-impl.h"
-#include "gromacs/random/random.h"
 #include "gromacs/gmxpreprocess/gen_maxwell_velocities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "gromacs/commandline/pargs.h"
 #include "splitter.h"
 #include "gromacs/gmxpreprocess/sortwater.h"
 #include "convparm.h"
-#include "gromacs/utility/fatalerror.h"
 #include "warninp.h"
 #include "index.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "tomorse.h"
 #include "gromacs/imd/imd.h"
 
+#include "gromacs/commandline/pargs.h"
 #include "gromacs/pbcutil/pbc.h"
+#include "gromacs/random/random.h"
 #include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
 static int rm_interactions(int ifunc, int nrmols, t_molinfo mols[])
index 8ac7e65690e8c27a222c3afb9bb5f7d2b0e4a5fb..6154ded2c796ea6a6a659a673bf0e06ed85f4e95 100644 (file)
@@ -60,6 +60,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/fatalerror.h"
 #include "warninp.h"
 #include "vsite_parm.h"
index ea1da1e89ce65a9d59654ad317ea87a273c739b1..c47f5c1fbefd071e9ce2a57e0e141e874e58ddd6 100644 (file)
@@ -47,7 +47,7 @@
 #include "types/simple.h"
 #include "types/enums.h"
 #include "../fileio/trx.h"
-#include "types/topology.h"
+#include "../topology/topology.h"
 #include "types/energy.h"
 #include "types/inputrec.h"
 #include "types/nrnb.h"
@@ -118,8 +118,6 @@ char *gmx_step_str(gmx_int64_t i, char *buf);
 /* Functions to initiate and delete structures *
  * These functions are defined in gmxlib/typedefs.c
  */
-void init_mtop(gmx_mtop_t *mtop);
-void init_top(t_topology *top);
 void init_inputrec(t_inputrec *ir);
 void init_energyhistory(energyhistory_t * enerhist);
 void done_energyhistory(energyhistory_t * enerhist);
@@ -129,10 +127,6 @@ t_state *serial_init_local_state(t_state *state_global);
 void init_df_history(df_history_t *dfhist, int nlambda);
 void done_df_history(df_history_t *dfhist);
 void copy_df_history(df_history_t * df_dest, df_history_t *df_source);
-void done_moltype(gmx_moltype_t *molt);
-void done_molblock(gmx_molblock_t *molb);
-void done_mtop(gmx_mtop_t *mtop, gmx_bool bDoneSymtab);
-void done_top(t_topology *top);
 void done_inputrec(t_inputrec *ir);
 void done_state(t_state *state);
 
@@ -142,9 +136,6 @@ void set_box_rel(t_inputrec *ir, t_state *state);
 void preserve_box_shape(t_inputrec *ir, matrix box_rel, matrix b);
 /* Preserve the box shape, b can be box or boxv */
 
-t_atoms *mtop2atoms(gmx_mtop_t *mtop);
-/* generate a t_atoms struct for the system from gmx_mtop_t */
-
 real max_cutoff(real cutoff1, real cutoff2);
 /* Returns the maximum of the cut-off's, taking into account that 0=inf. */
 
index c2ef4f6f0559f4ce7a0a68057441c0ee437ec176..98d8d1204858ac58f95eea46cf883f48a643135d 100644 (file)
 #include <config.h>
 #endif
 
-#include "typedefs.h"
+#include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
-
-#include "gromacs/math/vec.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/idef.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
index 7d347fee4196ac9019c93c3091ba802cd72ec2c2..070f87d18ea3b85d002d699fa681493214ea4ed1 100644 (file)
 
 #include <cstring>
 
-#include "gromacs/legacyheaders/typedefs.h"
-
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
index f086663f2190123d0232bb544e134f5b035f73dd..dc207a7321d0e61601f22f23ea4f4cc59f4845e3 100644 (file)
@@ -39,7 +39,8 @@ set(TOPOLOGY_PUBLIC_HEADERS
     atoms.h
     block.h
     idef.h
-    symtab.h)
+    symtab.h
+    topology.h)
 
 gmx_install_headers(topology ${TOPOLOGY_PUBLIC_HEADERS})
 
diff --git a/src/gromacs/topology/topology.cpp b/src/gromacs/topology/topology.cpp
new file mode 100644 (file)
index 0000000..213d3ce
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gromacs/topology/topology.h"
+
+#include "gromacs/topology/symtab.h"
+#include "gromacs/utility/smalloc.h"
+
+static void init_groups(gmx_groups_t *groups)
+{
+    groups->ngrpname = 0;
+    groups->grpname  = NULL;
+    for (int g = 0; g < egcNR; g++)
+    {
+        groups->grps[g].nm_ind = NULL;
+        groups->ngrpnr[g]      = 0;
+        groups->grpnr[g]       = NULL;
+    }
+
+}
+
+void init_mtop(gmx_mtop_t *mtop)
+{
+    mtop->name         = NULL;
+    mtop->nmoltype     = 0;
+    mtop->moltype      = NULL;
+    mtop->nmolblock    = 0;
+    mtop->molblock     = NULL;
+    mtop->maxres_renum = 0;
+    mtop->maxresnr     = -1;
+    init_groups(&mtop->groups);
+    init_block(&mtop->mols);
+    open_symtab(&mtop->symtab);
+}
+
+void init_top(t_topology *top)
+{
+    top->name = NULL;
+    init_atom(&(top->atoms));
+    init_atomtypes(&(top->atomtypes));
+    init_block(&top->cgs);
+    init_block(&top->mols);
+    init_blocka(&top->excls);
+    open_symtab(&top->symtab);
+}
+
+
+void done_moltype(gmx_moltype_t *molt)
+{
+    done_atom(&molt->atoms);
+    done_block(&molt->cgs);
+    done_blocka(&molt->excls);
+
+    for (int f = 0; f < F_NRE; f++)
+    {
+        sfree(molt->ilist[f].iatoms);
+        molt->ilist[f].nalloc = 0;
+    }
+}
+
+void done_molblock(gmx_molblock_t *molb)
+{
+    if (molb->nposres_xA > 0)
+    {
+        molb->nposres_xA = 0;
+        sfree(molb->posres_xA);
+    }
+    if (molb->nposres_xB > 0)
+    {
+        molb->nposres_xB = 0;
+        sfree(molb->posres_xB);
+    }
+}
+
+void done_mtop(gmx_mtop_t *mtop, gmx_bool bDoneSymtab)
+{
+    if (bDoneSymtab)
+    {
+        done_symtab(&mtop->symtab);
+    }
+
+    sfree(mtop->ffparams.functype);
+    sfree(mtop->ffparams.iparams);
+
+    for (int i = 0; i < mtop->nmoltype; i++)
+    {
+        done_moltype(&mtop->moltype[i]);
+    }
+    sfree(mtop->moltype);
+    for (int i = 0; i < mtop->nmolblock; i++)
+    {
+        done_molblock(&mtop->molblock[i]);
+    }
+    sfree(mtop->molblock);
+    done_block(&mtop->mols);
+}
+
+void done_top(t_topology *top)
+{
+    sfree(top->idef.functype);
+    sfree(top->idef.iparams);
+    for (int f = 0; f < F_NRE; ++f)
+    {
+        sfree(top->idef.il[f].iatoms);
+        top->idef.il[f].iatoms = NULL;
+        top->idef.il[f].nalloc = 0;
+    }
+
+    done_atom(&(top->atoms));
+
+    /* For GB */
+    done_atomtypes(&(top->atomtypes));
+
+    done_symtab(&(top->symtab));
+    done_block(&(top->cgs));
+    done_block(&(top->mols));
+    done_blocka(&(top->excls));
+}
similarity index 88%
rename from src/gromacs/legacyheaders/types/topology.h
rename to src/gromacs/topology/topology.h
index 7093b5c776649ac8dd31f8fd0d040a7c6ae9d95e..b961fd932f8b762e51cc39bdc7b493ee0bce7b95 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifndef GMX_LEGACYHEADERS_TOPOLOGY_H
-#define GMX_LEGACYHEADERS_TOPOLOGY_H
+#ifndef GMX_TOPOLOGY_TOPOLOGY_H
+#define GMX_TOPOLOGY_TOPOLOGY_H
 
-#include "simple.h"
-#include "../../topology/idef.h"
-#include "../../topology/atoms.h"
-#include "../../topology/block.h"
-#include "../../topology/symtab.h"
+#include "../math/vectypes.h"
+#include "atoms.h"
+#include "block.h"
+#include "idef.h"
+#include "symtab.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -54,7 +54,8 @@ enum {
     egcNR
 };
 
-typedef struct {
+typedef struct gmx_moltype_t
+{
     char          **name;       /* Name of the molecule type            */
     t_atoms         atoms;      /* The atoms                            */
     t_ilist         ilist[F_NRE];
@@ -62,7 +63,8 @@ typedef struct {
     t_blocka        excls;      /* The exclusions                       */
 } gmx_moltype_t;
 
-typedef struct {
+typedef struct gmx_molblock_t
+{
     int            type;        /* The molcule type index in mtop.moltype */
     int            nmol;        /* The number of molecules in this block  */
     int            natoms_mol;  /* The number of atoms in one molecule    */
@@ -72,7 +74,8 @@ typedef struct {
     rvec          *posres_xB;   /* The posres coords for top B            */
 } gmx_molblock_t;
 
-typedef struct {
+typedef struct gmx_groups_t
+{
     t_grps            grps[egcNR];  /* Groups of things                     */
     int               ngrpname;     /* Number of groupnames                 */
     char           ***grpname;      /* Names of the groups                  */
@@ -88,7 +91,8 @@ typedef struct {
 
 /* The global, complete system topology struct, based on molecule types.
    This structure should contain no data that is O(natoms) in memory. */
-typedef struct {
+typedef struct gmx_mtop_t
+{
     char           **name;      /* Name of the topology                 */
     gmx_ffparams_t   ffparams;
     int              nmoltype;
@@ -105,17 +109,19 @@ typedef struct {
 } gmx_mtop_t;
 
 /* The mdrun node-local topology struct, completely written out */
-typedef struct {
-    t_idef        idef;         /* The interaction function definition */
+typedef struct gmx_localtop_t
+{
+    t_idef        idef;         /* The interaction function definition  */
     t_atomtypes   atomtypes;    /* Atomtype properties                  */
     t_block       cgs;          /* The charge groups                    */
     t_blocka      excls;        /* The exclusions                       */
 } gmx_localtop_t;
 
 /* The old topology struct, completely written out, used in analysis tools */
-typedef struct {
+typedef struct t_topology
+{
     char          **name;       /* Name of the topology                 */
-    t_idef          idef;       /* The interaction function definition */
+    t_idef          idef;       /* The interaction function definition  */
     t_atoms         atoms;      /* The atoms                            */
     t_atomtypes     atomtypes;  /* Atomtype properties                  */
     t_block         cgs;        /* The charge groups                    */
@@ -124,6 +130,16 @@ typedef struct {
     t_symtab        symtab;     /* The symbol table                     */
 } t_topology;
 
+void init_mtop(gmx_mtop_t *mtop);
+void init_top(t_topology *top);
+void done_moltype(gmx_moltype_t *molt);
+void done_molblock(gmx_molblock_t *molb);
+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 */
+
 #ifdef __cplusplus
 }
 #endif
index 53f7d7f060f8297fc63ef492398e9736e55307b0..b6e00a0173c119ee9aaf440d4895320a5964adea 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/smalloc.h"