Move types/atoms.h to topology/
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 24 May 2014 04:20:48 +0000 (07:20 +0300)
committerRoland Schulz <roland@rschulz.eu>
Sat, 24 May 2014 15:43:32 +0000 (17:43 +0200)
- Make all the structs forward-declarable, and use that in a few
  headers.
- Adjust existing few includes.
- Move functions that operate on these types from typedefs.[ch] to
  topology/ as well.

Nearly all code still depends on including this through
typedefs.h->types/topology.h, but that can wait.

Change-Id: If870711a061756a77451f52598d91e72d8948d92

16 files changed:
src/gromacs/fileio/confio.h
src/gromacs/fileio/pdbio.h
src/gromacs/fileio/tngio_for_tools.cpp
src/gromacs/fileio/tpxio.h
src/gromacs/fileio/trx.h
src/gromacs/fileio/trxio.h
src/gromacs/gmxlib/typedefs.c
src/gromacs/gmxpreprocess/read-conformation.cpp
src/gromacs/gmxpreprocess/read-conformation.h
src/gromacs/legacyheaders/index.h
src/gromacs/legacyheaders/typedefs.h
src/gromacs/legacyheaders/types/topology.h
src/gromacs/pbcutil/rmpbc.h
src/gromacs/topology/CMakeLists.txt
src/gromacs/topology/atoms.cpp [new file with mode: 0644]
src/gromacs/topology/atoms.h [moved from src/gromacs/legacyheaders/types/atoms.h with 78% similarity]

index 85b6f9f55260b4c346eddb577f2472c280d014ec..ba6d246b0794196d7211c083db76157daa8e368d 100644 (file)
@@ -40,7 +40,6 @@
 
 #include <stdio.h>
 
-#include "../legacyheaders/types/atoms.h"
 #include "../legacyheaders/types/simple.h"
 #include "../legacyheaders/types/topology.h"
 
@@ -53,6 +52,8 @@
 extern "C" {
 #endif
 
+struct t_atoms;
+
 int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line);
 /* read a Gromos96 coordinate or trajectory file,                       *
  * returns the number of atoms                                          *
@@ -71,23 +72,23 @@ gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr);
 int gro_first_x_or_v(FILE *status, t_trxframe *fr);
 /* read first/next x and/or v frame from gro file */
 
-void write_hconf_indexed_p(FILE *out, const char *title, t_atoms *atoms,
+void write_hconf_indexed_p(FILE *out, const char *title, struct t_atoms *atoms,
                            int nx, const atom_id index[], int ndec,
                            rvec *x, rvec *v, matrix box);
 
-void write_hconf_p(FILE *out, const char *title, t_atoms *atoms, int ndec,
+void write_hconf_p(FILE *out, const char *title, struct t_atoms *atoms, int ndec,
                    rvec *x, rvec *v, matrix box);
 /* Write a Gromos file with precision ndec: number of decimal places in x,
  * v has one place more. */
 
 void write_sto_conf_indexed(const char *outfile, const char *title,
-                            t_atoms *atoms,
+                            struct t_atoms *atoms,
                             rvec x[], rvec *v, int ePBC, matrix box,
                             atom_id nindex, atom_id index[]);
 /* like write_sto_conf, but indexed */
 
 void write_sto_conf(const char *outfile, const char *title,
-                    t_atoms *atoms,
+                    struct t_atoms *atoms,
                     rvec x[], rvec *v, int ePBC, matrix box);
 /* write atoms, x, v (if .gro and not NULL) and box (if not NULL)
  * to an STO (.gro or .pdb) file */
@@ -101,7 +102,7 @@ void get_stx_coordnum (const char *infile, int *natoms);
 /* read the number of atoms from an STX file */
 
 void read_stx_conf(const char *infile, char *title,
-                   t_atoms *atoms,
+                   struct t_atoms *atoms,
                    rvec x[], rvec *v, int *ePBC, matrix box);
 /* Read atoms, x, v and box from an STX file.
  * If ePBC!=NULL return the type of pbc in *ePBC or -1 if unknown.
index c5c86e7cf25e0f3b1323e62c7a16faf9799ac58a..ae775df0f0a157664b50d2f9e53cc9673a61f520 100644 (file)
@@ -47,6 +47,8 @@
 extern "C" {
 #endif
 
+struct t_atoms;
+
 typedef struct gmx_conect_t *gmx_conect;
 
 /* THE pdb format (for ATOM/HETATOM lines) */
@@ -86,7 +88,7 @@ void write_pdbfile_indexed(FILE *out, const char *title, t_atoms *atoms,
                            gmx_conect conect, gmx_bool bTerSepChains);
 /* REALLY low level */
 
-void write_pdbfile(FILE *out, const char *title, t_atoms *atoms,
+void write_pdbfile(FILE *out, const char *title, struct t_atoms *atoms,
                    rvec x[], int ePBC, matrix box, char chain,
                    int model_nr, gmx_conect conect, gmx_bool bTerSepChains);
 /* Low level pdb file writing routine.
@@ -102,18 +104,18 @@ void write_pdbfile(FILE *out, const char *title, t_atoms *atoms,
  * which may be useful for visualization purposes.
  */
 
-void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps);
+void get_pdb_atomnumber(struct t_atoms *atoms, gmx_atomprop_t aps);
 /* Routine to extract atomic numbers from the atom names */
 
 int read_pdbfile(FILE *in, char *title, int *model_nr,
-                 t_atoms *atoms, rvec x[], int *ePBC, matrix box,
+                 struct t_atoms *atoms, rvec x[], int *ePBC, matrix box,
                  gmx_bool bChange, gmx_conect conect);
 /* Function returns number of atoms found.
  * ePBC and gmx_conect structure may be NULL.
  */
 
 void read_pdb_conf(const char *infile, char *title,
-                   t_atoms *atoms, rvec x[], int *ePBC, matrix box,
+                   struct t_atoms *atoms, rvec x[], int *ePBC, matrix box,
                    gmx_bool bChange, gmx_conect conect);
 /* Read a pdb file and extract ATOM and HETATM fields.
  * Read a box from the CRYST1 line, return 0 box when no CRYST1 is found.
index d81fef7fb2359d7a6d812243e79ad701e5efad09..93a3b130a9dd959457480ef7d42a14b921c7f293 100644 (file)
@@ -47,8 +47,6 @@
 #include "../../external/tng_io/include/tng_io.h"
 #endif
 
-#include "gromacs/legacyheaders/types/atoms.h"
-
 #include "gromacs/math/units.h"
 #include "gromacs/utility/common.h"
 #include "gromacs/utility/fatalerror.h"
index 50f6a7b7a7a9d1586c4f6777e2a69cebd4052f76..8279544c1f7433b54ef95248783eb22184e2d254 100644 (file)
@@ -56,6 +56,9 @@
 extern "C" {
 #endif
 
+struct t_atoms;
+struct t_block;
+
 typedef struct
 {
     int   bIr;       /* Non zero if input_rec is present               */
@@ -145,7 +148,7 @@ gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top,
  * else if bMass=TRUE, read the masses into top.atoms from the mass database.
  */
 
-void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols);
+void tpx_make_chain_identifiers(struct t_atoms *atoms, struct t_block *mols);
 
 #ifdef __cplusplus
 }
index 3a0727b18a9db569ae3ff0d85bb4b88e3518c895..70a32b9fd87e2965dee0887b07f631ddb1069e35 100644 (file)
@@ -2,8 +2,8 @@
  * 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, by the GROMACS development team, led by
+ * 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.
 #ifndef GMX_FILEIO_TRX_H
 #define GMX_FILEIO_TRX_H
 
-#include "../legacyheaders/types/atoms.h"
+#include "gromacs/math/vectypes.h"
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/real.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct t_atoms;
+
 typedef struct gmxvmdplugin t_gmxvmdplugin;
 
 typedef struct trxframe
@@ -75,7 +79,7 @@ typedef struct trxframe
     real            lambda;    /* free energy perturbation lambda  */
     int             fep_state; /* which fep state are we in? */
     gmx_bool        bAtoms;
-    t_atoms        *atoms;     /* atoms struct (natoms)            */
+    struct t_atoms *atoms;     /* atoms struct (natoms)            */
     gmx_bool        bPrec;
     real            prec;      /* precision of x, fraction of 1 nm */
     gmx_bool        bX;
index 175e64fbccf324bd6f791c8c984c45f504c842cc..6953e50883c3502e392157bd56cd6157129bdbbf 100644 (file)
@@ -53,6 +53,8 @@ extern "C" {
 }
 #endif
 
+struct t_atoms;
+
 /* a dedicated status type contains fp, etc. */
 typedef struct t_trxstatus t_trxstatus;
 
@@ -95,7 +97,7 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc);
  * gc is important for pdb file writing only and may be NULL.
  */
 
-int write_trx(t_trxstatus *status, int nind, const atom_id *ind, t_atoms *atoms,
+int write_trx(t_trxstatus *status, int nind, const atom_id *ind, struct t_atoms *atoms,
               int step, real time, matrix box, rvec x[], rvec *v,
               gmx_conect gc);
 /* Write an indexed frame to a TRX file.
index 3cad484e357361c318b4461860fe82a0164def4d..641ed8e34206d3448beb84cbee3daa0c2d257968 100644 (file)
@@ -49,6 +49,7 @@
 #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"
@@ -107,30 +108,6 @@ char *gmx_step_str(gmx_int64_t i, char *buf)
     return buf;
 }
 
-void init_atom(t_atoms *at)
-{
-    int i;
-
-    at->nr        = 0;
-    at->nres      = 0;
-    at->atom      = NULL;
-    at->resinfo   = NULL;
-    at->atomname  = NULL;
-    at->atomtype  = NULL;
-    at->atomtypeB = NULL;
-    at->pdbinfo   = NULL;
-}
-
-void init_atomtypes(t_atomtypes *at)
-{
-    at->nr         = 0;
-    at->radius     = NULL;
-    at->vol        = NULL;
-    at->atomnumber = NULL;
-    at->gb_radius  = NULL;
-    at->S_hct      = NULL;
-}
-
 void init_groups(gmx_groups_t *groups)
 {
     int g;
@@ -181,32 +158,6 @@ void init_inputrec(t_inputrec *ir)
     snew(ir->simtempvals, 1);
 }
 
-void done_atom (t_atoms *at)
-{
-    at->nr       = 0;
-    at->nres     = 0;
-    sfree(at->atom);
-    sfree(at->resinfo);
-    sfree(at->atomname);
-    sfree(at->atomtype);
-    sfree(at->atomtypeB);
-    if (at->pdbinfo)
-    {
-        sfree(at->pdbinfo);
-    }
-}
-
-void done_atomtypes(t_atomtypes *atype)
-{
-    atype->nr = 0;
-    sfree(atype->radius);
-    sfree(atype->vol);
-    sfree(atype->surftens);
-    sfree(atype->atomnumber);
-    sfree(atype->gb_radius);
-    sfree(atype->S_hct);
-}
-
 void done_moltype(gmx_moltype_t *molt)
 {
     int f;
@@ -662,202 +613,6 @@ void preserve_box_shape(t_inputrec *ir, matrix box_rel, matrix b)
     }
 }
 
-void add_t_atoms(t_atoms *atoms, int natom_extra, int nres_extra)
-{
-    int i;
-
-    if (natom_extra > 0)
-    {
-        srenew(atoms->atomname, atoms->nr+natom_extra);
-        srenew(atoms->atom, atoms->nr+natom_extra);
-        if (NULL != atoms->pdbinfo)
-        {
-            srenew(atoms->pdbinfo, atoms->nr+natom_extra);
-        }
-        if (NULL != atoms->atomtype)
-        {
-            srenew(atoms->atomtype, atoms->nr+natom_extra);
-        }
-        if (NULL != atoms->atomtypeB)
-        {
-            srenew(atoms->atomtypeB, atoms->nr+natom_extra);
-        }
-        for (i = atoms->nr; (i < atoms->nr+natom_extra); i++)
-        {
-            atoms->atomname[i] = NULL;
-            memset(&atoms->atom[i], 0, sizeof(atoms->atom[i]));
-            if (NULL != atoms->pdbinfo)
-            {
-                memset(&atoms->pdbinfo[i], 0, sizeof(atoms->pdbinfo[i]));
-            }
-            if (NULL != atoms->atomtype)
-            {
-                atoms->atomtype[i] = NULL;
-            }
-            if (NULL != atoms->atomtypeB)
-            {
-                atoms->atomtypeB[i] = NULL;
-            }
-        }
-        atoms->nr += natom_extra;
-    }
-    if (nres_extra > 0)
-    {
-        srenew(atoms->resinfo, atoms->nres+nres_extra);
-        for (i = atoms->nres; (i < atoms->nres+nres_extra); i++)
-        {
-            memset(&atoms->resinfo[i], 0, sizeof(atoms->resinfo[i]));
-        }
-        atoms->nres += nres_extra;
-    }
-}
-
-void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo)
-{
-    atoms->nr   = natoms;
-    atoms->nres = 0;
-    snew(atoms->atomname, natoms);
-    atoms->atomtype  = NULL;
-    atoms->atomtypeB = NULL;
-    snew(atoms->resinfo, natoms);
-    snew(atoms->atom, natoms);
-    if (bPdbinfo)
-    {
-        snew(atoms->pdbinfo, natoms);
-    }
-    else
-    {
-        atoms->pdbinfo = NULL;
-    }
-}
-
-t_atoms *copy_t_atoms(t_atoms *src)
-{
-    t_atoms *dst;
-    int      i;
-
-    snew(dst, 1);
-    init_t_atoms(dst, src->nr, (NULL != src->pdbinfo));
-    dst->nr = src->nr;
-    if (NULL != src->atomname)
-    {
-        snew(dst->atomname, src->nr);
-    }
-    if (NULL != src->atomtype)
-    {
-        snew(dst->atomtype, src->nr);
-    }
-    if (NULL != src->atomtypeB)
-    {
-        snew(dst->atomtypeB, src->nr);
-    }
-    for (i = 0; (i < src->nr); i++)
-    {
-        dst->atom[i] = src->atom[i];
-        if (NULL != src->pdbinfo)
-        {
-            dst->pdbinfo[i] = src->pdbinfo[i];
-        }
-        if (NULL != src->atomname)
-        {
-            dst->atomname[i]  = src->atomname[i];
-        }
-        if (NULL != src->atomtype)
-        {
-            dst->atomtype[i] = src->atomtype[i];
-        }
-        if (NULL != src->atomtypeB)
-        {
-            dst->atomtypeB[i] = src->atomtypeB[i];
-        }
-    }
-    dst->nres = src->nres;
-    for (i = 0; (i < src->nres); i++)
-    {
-        dst->resinfo[i] = src->resinfo[i];
-    }
-    return dst;
-}
-
-void t_atoms_set_resinfo(t_atoms *atoms, int atom_ind, t_symtab *symtab,
-                         const char *resname, int resnr, unsigned char ic,
-                         int chainnum, char chainid)
-{
-    t_resinfo *ri;
-
-    ri           = &atoms->resinfo[atoms->atom[atom_ind].resind];
-    ri->name     = put_symtab(symtab, resname);
-    ri->rtp      = NULL;
-    ri->nr       = resnr;
-    ri->ic       = ic;
-    ri->chainnum = chainnum;
-    ri->chainid  = chainid;
-}
-
-void free_t_atoms(t_atoms *atoms, gmx_bool bFreeNames)
-{
-    int i;
-
-    if (bFreeNames && atoms->atomname != NULL)
-    {
-        for (i = 0; i < atoms->nr; i++)
-        {
-            if (atoms->atomname[i] != NULL)
-            {
-                sfree(*atoms->atomname[i]);
-                *atoms->atomname[i] = NULL;
-            }
-        }
-    }
-    if (bFreeNames && atoms->resinfo != NULL)
-    {
-        for (i = 0; i < atoms->nres; i++)
-        {
-            if (atoms->resinfo[i].name != NULL)
-            {
-                sfree(*atoms->resinfo[i].name);
-                *atoms->resinfo[i].name = NULL;
-            }
-        }
-    }
-    if (bFreeNames && atoms->atomtype != NULL)
-    {
-        for (i = 0; i < atoms->nr; i++)
-        {
-            if (atoms->atomtype[i] != NULL)
-            {
-                sfree(*atoms->atomtype[i]);
-                *atoms->atomtype[i] = NULL;
-            }
-        }
-    }
-    if (bFreeNames && atoms->atomtypeB != NULL)
-    {
-        for (i = 0; i < atoms->nr; i++)
-        {
-            if (atoms->atomtypeB[i] != NULL)
-            {
-                sfree(*atoms->atomtypeB[i]);
-                *atoms->atomtypeB[i] = NULL;
-            }
-        }
-    }
-    sfree(atoms->atomname);
-    sfree(atoms->atomtype);
-    sfree(atoms->atomtypeB);
-    sfree(atoms->resinfo);
-    sfree(atoms->atom);
-    sfree(atoms->pdbinfo);
-    atoms->nr        = 0;
-    atoms->nres      = 0;
-    atoms->atomname  = NULL;
-    atoms->atomtype  = NULL;
-    atoms->atomtypeB = NULL;
-    atoms->resinfo   = NULL;
-    atoms->atom      = NULL;
-    atoms->pdbinfo   = NULL;
-}
-
 real max_cutoff(real cutoff1, real cutoff2)
 {
     if (cutoff1 == 0 || cutoff2 == 0)
index 5007a540fc47285acb8640c3501b7b7b9ac445ea..e282233aa2424bbb72df10e7b66d6c1ee11411f5 100644 (file)
@@ -37,8 +37,8 @@
 #include "gromacs/fileio/confio.h"
 #include "gromacs/legacyheaders/atomprop.h"
 #include "gromacs/legacyheaders/types/simple.h"
-#include "gromacs/legacyheaders/types/atoms.h"
 #include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/topology/atoms.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/smalloc.h"
 
index 13386af2ee369db78be967f3f18bc95000b44a34..be15b1d4fb596feffc80571d1cfe39a35de43b91 100644 (file)
 #define GMX_GMXPREPROCESS_READ_CONFORMATION_H
 
 #include "types/simple.h"
-#include "types/atoms.h"
 #include "atomprop.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct t_atoms;
+
 /*! \brief Allocate and fill an array of inter-atomic half distances
  *
  * These are either scaled VDW radii taken from vdwradii.dat, or the
  * default value. Used directly and indirectly by solvate and
  * insert-molecules for deciding whether molecules clash. The return
  * pointer should be freed by the caller. */
-real *makeExclusionDistances(const t_atoms *a, gmx_atomprop_t aps,
+real *makeExclusionDistances(const struct t_atoms *a, gmx_atomprop_t aps,
                              real defaultDistance, real scaleFactor);
 
 /*! \brief Read a conformation from a file, allocate and fill data structures.
@@ -57,7 +58,7 @@ real *makeExclusionDistances(const t_atoms *a, gmx_atomprop_t aps,
  * Used by solvate and insert-molecules. The returned pointers *x and
  * *v should be freed by the caller. atoms should have its destructor
  * called. */
-char *readConformation(const char *confin, t_atoms *atoms, rvec **x, rvec **v,
+char *readConformation(const char *confin, struct t_atoms *atoms, rvec **x, rvec **v,
                        int *ePBC, matrix box);
 
 #ifdef __cplusplus
index 731ffc7794ec17c670a7d9d7b88d68f095a76738..940dc0820b8c3b61ab7fa83847af1dc924e22c12 100644 (file)
 
 #include <stdio.h>
 
-#include "types/atoms.h"
+#include "types/simple.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct t_atoms;
 struct t_blocka;
 
 void check_index(char *gname, int n, atom_id index[],
@@ -79,7 +80,7 @@ void rd_index_nrs(char *statfile, int ngrps, int isize[],
                   atom_id *index[], char *grpnames[], int grpnr[]);
 /* the same but also reads the number of the selected group*/
 
-void get_index(t_atoms *atoms, const char *fnm, int ngrps,
+void get_index(struct t_atoms *atoms, const char *fnm, int ngrps,
                int isize[], atom_id *index[], char *grpnames[]);
 /* Does the same as rd_index, but if the fnm pointer is NULL it
  * will not read from fnm, but it will make default index groups
@@ -149,7 +150,7 @@ void write_index(const char *outf, struct t_blocka *b, char **gnames, gmx_bool b
 void add_grp(struct t_blocka *b, char ***gnames, int nra, atom_id a[], const char *name);
 /* Ads group a with name name to block b and namelist gnames */
 
-void analyse(t_atoms *atoms, struct t_blocka *gb, char ***gn,
+void analyse(struct t_atoms *atoms, struct t_blocka *gb, char ***gn,
              gmx_bool bASK, gmx_bool bVerb);
 /* Makes index groups gb with names gn for atoms in atoms.
  * bASK=FALSE gives default groups.
index 3579427edb9d585dfe7c1830071442c3a15a74b1..520f7730feb1bc95b8f8995928a050bf5f62d122 100644 (file)
@@ -47,7 +47,6 @@
 #include "types/simple.h"
 #include "types/enums.h"
 #include "types/idef.h"
-#include "types/atoms.h"
 #include "../fileio/trx.h"
 #include "types/topology.h"
 #include "types/energy.h"
@@ -120,7 +119,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_atom (t_atoms *at);
 void init_mtop(gmx_mtop_t *mtop);
 void init_top(t_topology *top);
 void init_inputrec(t_inputrec *ir);
@@ -132,7 +130,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_atom (t_atoms *at);
 void done_moltype(gmx_moltype_t *molt);
 void done_molblock(gmx_molblock_t *molb);
 void done_mtop(gmx_mtop_t *mtop, gmx_bool bDoneSymtab);
@@ -146,29 +143,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 */
 
-void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo);
-/* allocate memory for the arrays, set nr to natoms and nres to 0
- * set pdbinfo to NULL or allocate memory for it */
-
-t_atoms *copy_t_atoms(t_atoms *src);
-/* copy an atoms struct from src to a new one */
-
-void add_t_atoms(t_atoms *atoms, int natom_extra, int nres_extra);
-/* allocate extra space for more atoms and or residues */
-
-void t_atoms_set_resinfo(t_atoms *atoms, int atom_ind, struct t_symtab *symtab,
-                         const char *resname, int resnr, unsigned char ic,
-                         int chainnum, char chainid);
-/* Set the residue name, number, insertion code and chain identifier
- * of atom index atom_ind.
- */
-
-void free_t_atoms(t_atoms *atoms, gmx_bool bFreeNames);
-/* Free all the arrays and set the nr and nres to 0.
- * bFreeNames tells if to free the atom and residue name strings,
- * don't free them if they still need to be used in e.g. the topology struct.
- */
-
 t_atoms *mtop2atoms(gmx_mtop_t *mtop);
 /* generate a t_atoms struct for the system from gmx_mtop_t */
 
index 861ca360e292aa686d4ca77f26ffc3b9df8102c5..3acfe55301d615816ab975debcda95ca9a3334a3 100644 (file)
@@ -37,9 +37,9 @@
 #ifndef GMX_LEGACYHEADERS_TOPOLOGY_H
 #define GMX_LEGACYHEADERS_TOPOLOGY_H
 
-#include "atoms.h"
 #include "idef.h"
 #include "simple.h"
+#include "../../topology/atoms.h"
 #include "../../topology/block.h"
 #include "../../topology/symtab.h"
 
index 6f0f69b18bf1a5188c4cfb2421dfaf2017fc71eb..13223782b3ce2fea3e4edcbf262e113ef9bc51a9 100644 (file)
@@ -37,7 +37,6 @@
 #ifndef GMX_PBCUTIL_RMPBC_H
 #define GMX_PBCUTIL_RMPBC_H
 
-#include "../legacyheaders/types/atoms.h"
 #include "../legacyheaders/types/idef.h"
 #include "../fileio/trx.h"
 #include "../math/vectypes.h"
@@ -46,6 +45,8 @@
 extern "C" {
 #endif
 
+struct t_atoms;
+
 typedef struct gmx_rmpbc *gmx_rmpbc_t;
 
 gmx_rmpbc_t gmx_rmpbc_init(t_idef *idef, int ePBC, int natoms);
@@ -67,7 +68,7 @@ void gmx_rmpbc_copy(gmx_rmpbc_t gpbc, int natoms, matrix box, rvec x[],
 void gmx_rmpbc_trxfr(gmx_rmpbc_t gpbc, t_trxframe *fr);
 /* As gmx_rmpbc but operates on a t_trxframe data structure. */
 
-void rm_gropbc(t_atoms *atoms, rvec x[], matrix box);
+void rm_gropbc(struct t_atoms *atoms, rvec x[], matrix box);
 /* Simple routine for use in analysis tools that just have a pdb or
  * similar file.
  */
index fb7f0496ba4cc595047cb9167597cf1befc81599..1d20344bfeea1a5a1f2b5e4c15efbc10a9eab3f5 100644 (file)
@@ -36,6 +36,7 @@ file(GLOB TOPOLOGY_SOURCES *.cpp *.c)
 set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${TOPOLOGY_SOURCES} PARENT_SCOPE)
 
 set(TOPOLOGY_PUBLIC_HEADERS
+    atoms.h
     block.h
     symtab.h)
 
diff --git a/src/gromacs/topology/atoms.cpp b/src/gromacs/topology/atoms.cpp
new file mode 100644 (file)
index 0000000..f98f92e
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * 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/atoms.h"
+
+#include <cstring>
+
+#include "gromacs/topology/symtab.h"
+#include "gromacs/utility/smalloc.h"
+
+void init_atom(t_atoms *at)
+{
+    at->nr        = 0;
+    at->nres      = 0;
+    at->atom      = NULL;
+    at->resinfo   = NULL;
+    at->atomname  = NULL;
+    at->atomtype  = NULL;
+    at->atomtypeB = NULL;
+    at->pdbinfo   = NULL;
+}
+
+void init_atomtypes(t_atomtypes *at)
+{
+    at->nr         = 0;
+    at->radius     = NULL;
+    at->vol        = NULL;
+    at->atomnumber = NULL;
+    at->gb_radius  = NULL;
+    at->S_hct      = NULL;
+}
+
+void done_atom(t_atoms *at)
+{
+    at->nr       = 0;
+    at->nres     = 0;
+    sfree(at->atom);
+    sfree(at->resinfo);
+    sfree(at->atomname);
+    sfree(at->atomtype);
+    sfree(at->atomtypeB);
+    if (at->pdbinfo)
+    {
+        sfree(at->pdbinfo);
+    }
+}
+
+void done_atomtypes(t_atomtypes *atype)
+{
+    atype->nr = 0;
+    sfree(atype->radius);
+    sfree(atype->vol);
+    sfree(atype->surftens);
+    sfree(atype->atomnumber);
+    sfree(atype->gb_radius);
+    sfree(atype->S_hct);
+}
+
+void add_t_atoms(t_atoms *atoms, int natom_extra, int nres_extra)
+{
+    int i;
+
+    if (natom_extra > 0)
+    {
+        srenew(atoms->atomname, atoms->nr+natom_extra);
+        srenew(atoms->atom, atoms->nr+natom_extra);
+        if (NULL != atoms->pdbinfo)
+        {
+            srenew(atoms->pdbinfo, atoms->nr+natom_extra);
+        }
+        if (NULL != atoms->atomtype)
+        {
+            srenew(atoms->atomtype, atoms->nr+natom_extra);
+        }
+        if (NULL != atoms->atomtypeB)
+        {
+            srenew(atoms->atomtypeB, atoms->nr+natom_extra);
+        }
+        for (i = atoms->nr; (i < atoms->nr+natom_extra); i++)
+        {
+            atoms->atomname[i] = NULL;
+            memset(&atoms->atom[i], 0, sizeof(atoms->atom[i]));
+            if (NULL != atoms->pdbinfo)
+            {
+                std::memset(&atoms->pdbinfo[i], 0, sizeof(atoms->pdbinfo[i]));
+            }
+            if (NULL != atoms->atomtype)
+            {
+                atoms->atomtype[i] = NULL;
+            }
+            if (NULL != atoms->atomtypeB)
+            {
+                atoms->atomtypeB[i] = NULL;
+            }
+        }
+        atoms->nr += natom_extra;
+    }
+    if (nres_extra > 0)
+    {
+        srenew(atoms->resinfo, atoms->nres+nres_extra);
+        for (i = atoms->nres; (i < atoms->nres+nres_extra); i++)
+        {
+            std::memset(&atoms->resinfo[i], 0, sizeof(atoms->resinfo[i]));
+        }
+        atoms->nres += nres_extra;
+    }
+}
+
+void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo)
+{
+    atoms->nr   = natoms;
+    atoms->nres = 0;
+    snew(atoms->atomname, natoms);
+    atoms->atomtype  = NULL;
+    atoms->atomtypeB = NULL;
+    snew(atoms->resinfo, natoms);
+    snew(atoms->atom, natoms);
+    if (bPdbinfo)
+    {
+        snew(atoms->pdbinfo, natoms);
+    }
+    else
+    {
+        atoms->pdbinfo = NULL;
+    }
+}
+
+t_atoms *copy_t_atoms(t_atoms *src)
+{
+    t_atoms *dst;
+    int      i;
+
+    snew(dst, 1);
+    init_t_atoms(dst, src->nr, (NULL != src->pdbinfo));
+    dst->nr = src->nr;
+    if (NULL != src->atomname)
+    {
+        snew(dst->atomname, src->nr);
+    }
+    if (NULL != src->atomtype)
+    {
+        snew(dst->atomtype, src->nr);
+    }
+    if (NULL != src->atomtypeB)
+    {
+        snew(dst->atomtypeB, src->nr);
+    }
+    for (i = 0; (i < src->nr); i++)
+    {
+        dst->atom[i] = src->atom[i];
+        if (NULL != src->pdbinfo)
+        {
+            dst->pdbinfo[i] = src->pdbinfo[i];
+        }
+        if (NULL != src->atomname)
+        {
+            dst->atomname[i]  = src->atomname[i];
+        }
+        if (NULL != src->atomtype)
+        {
+            dst->atomtype[i] = src->atomtype[i];
+        }
+        if (NULL != src->atomtypeB)
+        {
+            dst->atomtypeB[i] = src->atomtypeB[i];
+        }
+    }
+    dst->nres = src->nres;
+    for (i = 0; (i < src->nres); i++)
+    {
+        dst->resinfo[i] = src->resinfo[i];
+    }
+    return dst;
+}
+
+void t_atoms_set_resinfo(t_atoms *atoms, int atom_ind, t_symtab *symtab,
+                         const char *resname, int resnr, unsigned char ic,
+                         int chainnum, char chainid)
+{
+    t_resinfo *ri;
+
+    ri           = &atoms->resinfo[atoms->atom[atom_ind].resind];
+    ri->name     = put_symtab(symtab, resname);
+    ri->rtp      = NULL;
+    ri->nr       = resnr;
+    ri->ic       = ic;
+    ri->chainnum = chainnum;
+    ri->chainid  = chainid;
+}
+
+void free_t_atoms(t_atoms *atoms, gmx_bool bFreeNames)
+{
+    int i;
+
+    if (bFreeNames && atoms->atomname != NULL)
+    {
+        for (i = 0; i < atoms->nr; i++)
+        {
+            if (atoms->atomname[i] != NULL)
+            {
+                sfree(*atoms->atomname[i]);
+                *atoms->atomname[i] = NULL;
+            }
+        }
+    }
+    if (bFreeNames && atoms->resinfo != NULL)
+    {
+        for (i = 0; i < atoms->nres; i++)
+        {
+            if (atoms->resinfo[i].name != NULL)
+            {
+                sfree(*atoms->resinfo[i].name);
+                *atoms->resinfo[i].name = NULL;
+            }
+        }
+    }
+    if (bFreeNames && atoms->atomtype != NULL)
+    {
+        for (i = 0; i < atoms->nr; i++)
+        {
+            if (atoms->atomtype[i] != NULL)
+            {
+                sfree(*atoms->atomtype[i]);
+                *atoms->atomtype[i] = NULL;
+            }
+        }
+    }
+    if (bFreeNames && atoms->atomtypeB != NULL)
+    {
+        for (i = 0; i < atoms->nr; i++)
+        {
+            if (atoms->atomtypeB[i] != NULL)
+            {
+                sfree(*atoms->atomtypeB[i]);
+                *atoms->atomtypeB[i] = NULL;
+            }
+        }
+    }
+    sfree(atoms->atomname);
+    sfree(atoms->atomtype);
+    sfree(atoms->atomtypeB);
+    sfree(atoms->resinfo);
+    sfree(atoms->atom);
+    sfree(atoms->pdbinfo);
+    atoms->nr        = 0;
+    atoms->nres      = 0;
+    atoms->atomname  = NULL;
+    atoms->atomtype  = NULL;
+    atoms->atomtypeB = NULL;
+    atoms->resinfo   = NULL;
+    atoms->atom      = NULL;
+    atoms->pdbinfo   = NULL;
+}
similarity index 78%
rename from src/gromacs/legacyheaders/types/atoms.h
rename to src/gromacs/topology/atoms.h
index 790520803ed9e03274b7068e4eaf74359541bf3e..4a619b0eb7d68c7a3bbb95cf8af695eeb86e762d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
  * 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 _atoms_h
-#define _atoms_h
+#ifndef GMX_TOPOLOGY_ATOMS_H
+#define GMX_TOPOLOGY_ATOMS_H
 
-
-#include "simple.h"
+#include "../utility/basedefinitions.h"
+#include "../utility/real.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct t_symtab;
+
 enum {
     eptAtom, eptNucleus, eptShell, eptBond, eptVSite, eptNR
 };
 /* The particle type */
 
-typedef struct {
+typedef struct t_atom
+{
     real           m, q;        /* Mass and charge                      */
     real           mB, qB;      /* Mass and charge for Free Energy calc */
     unsigned short type;        /* Atom type                            */
@@ -60,7 +63,8 @@ typedef struct {
     char           elem[4];     /* Element name                         */
 } t_atom;
 
-typedef struct {
+typedef struct t_resinfo
+{
     char          **name;       /* Pointer to the residue name          */
     int             nr;         /* Residue number                       */
     unsigned char   ic;         /* Code for insertion of residues       */
@@ -69,7 +73,8 @@ typedef struct {
     char          **rtp;        /* rtp building block name (optional)   */
 } t_resinfo;
 
-typedef struct {
+typedef struct t_pdbinfo
+{
     int      type;              /* PDB record name                      */
     int      atomnr;            /* PDB atom number                      */
     char     altloc;            /* Alternate location indicator         */
@@ -80,12 +85,14 @@ typedef struct {
     int      uij[6];            /* Anisotropic B-factor                 */
 } t_pdbinfo;
 
-typedef struct {
+typedef struct t_grps
+{
     int   nr;                   /* Number of different groups           */
     int  *nm_ind;               /* Index in the group names             */
 } t_grps;
 
-typedef struct {
+typedef struct t_atoms
+{
     int            nr;          /* Nr of atoms                          */
     t_atom        *atom;        /* Array of atoms (dim: nr)             */
                                 /* The following entries will not       */
@@ -101,7 +108,8 @@ typedef struct {
     t_pdbinfo       *pdbinfo;   /* PDB Information, such as aniso. Bfac */
 } t_atoms;
 
-typedef struct {
+typedef struct t_atomtypes
+{
     int           nr;           /* number of atomtypes                          */
     real         *radius;       /* GBSA radius for each atomtype                */
     real         *vol;          /* GBSA efective volume for each atomtype       */
@@ -111,9 +119,36 @@ typedef struct {
     int          *atomnumber;   /* Atomic number, used for QM/MM                */
 } t_atomtypes;
 
-
 #define PERTURBED(a) (((a).mB != (a).m) || ((a).qB != (a).q) || ((a).typeB != (a).type))
 
+void init_atom(t_atoms *at);
+void init_atomtypes(t_atomtypes *at);
+void done_atom(t_atoms *at);
+void done_atomtypes(t_atomtypes *at);
+
+void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo);
+/* allocate memory for the arrays, set nr to natoms and nres to 0
+ * set pdbinfo to NULL or allocate memory for it */
+
+t_atoms *copy_t_atoms(t_atoms *src);
+/* copy an atoms struct from src to a new one */
+
+void add_t_atoms(t_atoms *atoms, int natom_extra, int nres_extra);
+/* allocate extra space for more atoms and or residues */
+
+void t_atoms_set_resinfo(t_atoms *atoms, int atom_ind, struct t_symtab *symtab,
+                         const char *resname, int resnr, unsigned char ic,
+                         int chainnum, char chainid);
+/* Set the residue name, number, insertion code and chain identifier
+ * of atom index atom_ind.
+ */
+
+void free_t_atoms(t_atoms *atoms, gmx_bool bFreeNames);
+/* Free all the arrays and set the nr and nres to 0.
+ * bFreeNames tells if to free the atom and residue name strings,
+ * don't free them if they still need to be used in e.g. the topology struct.
+ */
+
 #ifdef __cplusplus
 }
 #endif