From 5845530f1fbca467e5644d01b702e58df77074dd Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Sun, 25 May 2014 06:20:55 +0300 Subject: [PATCH] Move types/topology.h to topology/ - 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 --- src/gromacs/fileio/confio.c | 10 +- src/gromacs/fileio/confio.h | 4 +- src/gromacs/fileio/enxio.h | 5 +- src/gromacs/fileio/mdoutf.h | 5 +- src/gromacs/fileio/pdbio.h | 6 +- src/gromacs/fileio/tpxio.c | 1 + src/gromacs/fileio/tpxio.h | 13 +- src/gromacs/fileio/trxio.h | 20 +-- src/gromacs/gmxana/gmx_trjconv.c | 11 +- src/gromacs/gmxana/nsfactor.c | 9 +- src/gromacs/gmxana/nsfactor.h | 9 +- src/gromacs/gmxlib/typedefs.c | 123 -------------- src/gromacs/gmxpreprocess/addconf.c | 1 + src/gromacs/gmxpreprocess/grompp.c | 7 +- src/gromacs/gmxpreprocess/topio.c | 1 + src/gromacs/legacyheaders/typedefs.h | 11 +- src/gromacs/pbcutil/rmpbc.c | 6 +- src/gromacs/selection/tests/toputils.cpp | 4 +- src/gromacs/topology/CMakeLists.txt | 3 +- src/gromacs/topology/topology.cpp | 151 ++++++++++++++++++ .../types => topology}/topology.h | 46 ++++-- .../trajectoryanalysis/analysissettings.cpp | 1 + 22 files changed, 248 insertions(+), 199 deletions(-) create mode 100644 src/gromacs/topology/topology.cpp rename src/gromacs/{legacyheaders/types => topology}/topology.h (88%) diff --git a/src/gromacs/fileio/confio.c b/src/gromacs/fileio/confio.c index b6b5ca87d1..ee227624c1 100644 --- a/src/gromacs/fileio/confio.c +++ b/src/gromacs/fileio/confio.c @@ -42,24 +42,26 @@ #include #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, diff --git a/src/gromacs/fileio/confio.h b/src/gromacs/fileio/confio.h index ba6d246b07..6fbafb3ee4 100644 --- a/src/gromacs/fileio/confio.h +++ b/src/gromacs/fileio/confio.h @@ -41,7 +41,6 @@ #include #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 */ diff --git a/src/gromacs/fileio/enxio.h b/src/gromacs/fileio/enxio.h index d92cb040b3..acf41f05f1 100644 --- a/src/gromacs/fileio/enxio.h +++ b/src/gromacs/fileio/enxio.h @@ -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. diff --git a/src/gromacs/fileio/mdoutf.h b/src/gromacs/fileio/mdoutf.h index 0f87050184..243920ea90 100644 --- a/src/gromacs/fileio/mdoutf.h +++ b/src/gromacs/fileio/mdoutf.h @@ -38,7 +38,6 @@ #include -#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 */ diff --git a/src/gromacs/fileio/pdbio.h b/src/gromacs/fileio/pdbio.h index ae775df0f0..e3a69b4486 100644 --- a/src/gromacs/fileio/pdbio.h +++ b/src/gromacs/fileio/pdbio.h @@ -41,13 +41,13 @@ #include #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); diff --git a/src/gromacs/fileio/tpxio.c b/src/gromacs/fileio/tpxio.c index 90c07f0cfb..d7fc7a4982 100644 --- a/src/gromacs/fileio/tpxio.c +++ b/src/gromacs/fileio/tpxio.c @@ -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" diff --git a/src/gromacs/fileio/tpxio.h b/src/gromacs/fileio/tpxio.h index 8279544c1f..3611be60d2 100644 --- a/src/gromacs/fileio/tpxio.h +++ b/src/gromacs/fileio/tpxio.h @@ -49,15 +49,16 @@ **************************************************************/ #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. diff --git a/src/gromacs/fileio/trxio.h b/src/gromacs/fileio/trxio.h index 6953e50883..3f7305984c 100644 --- a/src/gromacs/fileio/trxio.h +++ b/src/gromacs/fileio/trxio.h @@ -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 diff --git a/src/gromacs/gmxana/gmx_trjconv.c b/src/gromacs/gmxana/gmx_trjconv.c index 5be71034a4..9c1d72719f 100644 --- a/src/gromacs/gmxana/gmx_trjconv.c +++ b/src/gromacs/gmxana/gmx_trjconv.c @@ -44,14 +44,12 @@ #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" @@ -59,14 +57,17 @@ #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 diff --git a/src/gromacs/gmxana/nsfactor.c b/src/gromacs/gmxana/nsfactor.c index ad1517bb57..475ee2b00a 100644 --- a/src/gromacs/gmxana/nsfactor.c +++ b/src/gromacs/gmxana/nsfactor.c @@ -32,20 +32,21 @@ * 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 #endif #include -#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" diff --git a/src/gromacs/gmxana/nsfactor.h b/src/gromacs/gmxana/nsfactor.h index 367aaa1836..ebe6b80874 100644 --- a/src/gromacs/gmxana/nsfactor.h +++ b/src/gromacs/gmxana/nsfactor.h @@ -39,12 +39,13 @@ #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, diff --git a/src/gromacs/gmxlib/typedefs.c b/src/gromacs/gmxlib/typedefs.c index 641ed8e342..390863ba91 100644 --- a/src/gromacs/gmxlib/typedefs.c +++ b/src/gromacs/gmxlib/typedefs.c @@ -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) diff --git a/src/gromacs/gmxpreprocess/addconf.c b/src/gromacs/gmxpreprocess/addconf.c index cc0bf57893..1ad661eacb 100644 --- a/src/gromacs/gmxpreprocess/addconf.c +++ b/src/gromacs/gmxpreprocess/addconf.c @@ -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; diff --git a/src/gromacs/gmxpreprocess/grompp.c b/src/gromacs/gmxpreprocess/grompp.c index 88a24a4243..919a363272 100644 --- a/src/gromacs/gmxpreprocess/grompp.c +++ b/src/gromacs/gmxpreprocess/grompp.c @@ -55,15 +55,12 @@ #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" @@ -84,8 +81,12 @@ #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[]) diff --git a/src/gromacs/gmxpreprocess/topio.c b/src/gromacs/gmxpreprocess/topio.c index 8ac7e65690..6154ded2c7 100644 --- a/src/gromacs/gmxpreprocess/topio.c +++ b/src/gromacs/gmxpreprocess/topio.c @@ -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" diff --git a/src/gromacs/legacyheaders/typedefs.h b/src/gromacs/legacyheaders/typedefs.h index ea1da1e89c..c47f5c1fbe 100644 --- a/src/gromacs/legacyheaders/typedefs.h +++ b/src/gromacs/legacyheaders/typedefs.h @@ -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. */ diff --git a/src/gromacs/pbcutil/rmpbc.c b/src/gromacs/pbcutil/rmpbc.c index c2ef4f6f05..98d8d12048 100644 --- a/src/gromacs/pbcutil/rmpbc.c +++ b/src/gromacs/pbcutil/rmpbc.c @@ -40,11 +40,11 @@ #include #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" diff --git a/src/gromacs/selection/tests/toputils.cpp b/src/gromacs/selection/tests/toputils.cpp index 7d347fee41..070f87d18e 100644 --- a/src/gromacs/selection/tests/toputils.cpp +++ b/src/gromacs/selection/tests/toputils.cpp @@ -43,11 +43,11 @@ #include -#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" diff --git a/src/gromacs/topology/CMakeLists.txt b/src/gromacs/topology/CMakeLists.txt index f086663f21..dc207a7321 100644 --- a/src/gromacs/topology/CMakeLists.txt +++ b/src/gromacs/topology/CMakeLists.txt @@ -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 index 0000000000..213d3ceecd --- /dev/null +++ b/src/gromacs/topology/topology.cpp @@ -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)); +} diff --git a/src/gromacs/legacyheaders/types/topology.h b/src/gromacs/topology/topology.h similarity index 88% rename from src/gromacs/legacyheaders/types/topology.h rename to src/gromacs/topology/topology.h index 7093b5c776..b961fd932f 100644 --- a/src/gromacs/legacyheaders/types/topology.h +++ b/src/gromacs/topology/topology.h @@ -34,14 +34,14 @@ * 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 diff --git a/src/gromacs/trajectoryanalysis/analysissettings.cpp b/src/gromacs/trajectoryanalysis/analysissettings.cpp index 53f7d7f060..b6e00a0173 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings.cpp +++ b/src/gromacs/trajectoryanalysis/analysissettings.cpp @@ -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" -- 2.22.0