Remove read_stx_conf() and get_stx_coordnum() uses
authorTeemu Murtola <teemu.murtola@gmail.com>
Fri, 14 Aug 2015 12:32:54 +0000 (15:32 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 28 Aug 2015 18:31:59 +0000 (20:31 +0200)
Replace all uses with read_tps_conf(), which is superior in multiple
ways:
 - It removes the need for most boilerplate code needed to read stuff,
   and makes the ugliness of needing to read the same file twice
   internal to confio.cpp.
 - read_tps_conf() at least provides an API that makes it possible to
   not leak memory.  Nearly all callers that used to call
   read_stx_conf() still leak it, though, including read_tps_conf(), but
   at least it is now possible to fix incrementally.

Change-Id: Ic489087f5947bbfd764a1801cbf4e85cb046a812

17 files changed:
src/gromacs/fileio/confio.cpp
src/gromacs/fileio/confio.h
src/gromacs/fileio/tests/confio.cpp
src/gromacs/gmxana/gmx_anadock.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gmx_dyndom.cpp
src/gromacs/gmxana/gmx_editconf.cpp
src/gromacs/gmxana/gmx_genpr.cpp
src/gromacs/gmxana/gmx_make_edi.cpp
src/gromacs/gmxana/gmx_make_ndx.cpp
src/gromacs/gmxana/gmx_morph.cpp
src/gromacs/gmxana/gmx_rmsf.cpp
src/gromacs/gmxpreprocess/genconf.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/pdb2gmx.cpp
src/gromacs/gmxpreprocess/read-conformation.cpp
src/gromacs/gmxpreprocess/x2top.cpp

index ac6390b2a79847f6c1ed2d66cdef4dad199f06f6..4cccd6e3e582f53941ab3d9026dc02ef7230adce 100644 (file)
@@ -201,7 +201,7 @@ void write_sto_conf_mtop(const char *outfile, const char *title,
     }
 }
 
-void get_stx_coordnum(const char *infile, int *natoms)
+static void get_stx_coordnum(const char *infile, int *natoms)
 {
     FILE      *in;
     int        ftp, tpxver, tpxgen;
@@ -294,8 +294,8 @@ static void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
     }
 }
 
-void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
-                   rvec x[], rvec *v, int *ePBC, matrix box)
+static void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
+                          rvec x[], rvec *v, int *ePBC, matrix box)
 {
     FILE       *in;
     gmx_mtop_t *mtop;
@@ -407,7 +407,10 @@ gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *eP
     gmx_atomprop_t   aps;
 
     bTop  = fn2bTPX(infile);
-    *ePBC = -1;
+    if (ePBC != NULL)
+    {
+        *ePBC = -1;
+    }
     if (bTop)
     {
         read_tpxheader(infile, &header, TRUE, &version, &generation);
@@ -420,8 +423,13 @@ gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *eP
             snew(*v, header.natoms);
         }
         snew(mtop, 1);
-        *ePBC = read_tpx(infile, NULL, box, &natoms,
-                         (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
+        int ePBC_tmp
+            = read_tpx(infile, NULL, box, &natoms,
+                       (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
+        if (ePBC != NULL)
+        {
+            *ePBC = ePBC_tmp;
+        }
         *top = gmx_mtop_t_to_t_topology(mtop);
         /* In this case we need to throw away the group data too */
         done_gmx_groups_t(&mtop->groups);
index 2c5dc2dc0e8ff2c80033708c6d47f6ade0f3fa38..b7edadde6aca03eec187f300cb0b11464f30198f 100644 (file)
@@ -69,16 +69,6 @@ void write_sto_conf_mtop(const char *outfile, const char *title,
                          rvec x[], rvec *v, int ePBC, matrix box);
 /* As write_sto_conf, but uses a gmx_mtop_t struct */
 
-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,
-                   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.
- */
-
 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,
index eb747f4b60afea945e7e51f74f4d1941d763adf7..6895390439a0d2ffa118bd8abae1fffe5aa1424a 100644 (file)
@@ -109,21 +109,6 @@ class StructureIORoundtripTest : public gmx::test::StringTestBase,
                            refBox_);
         }
 
-        void readReferenceFileStx()
-        {
-            int natoms = -1;
-            get_stx_coordnum(referenceFilename_.c_str(), &natoms);
-            ASSERT_EQ(refTop_->atoms.nr, natoms)
-            << "get_stx_coordnum() returned unexpected number of atoms";
-            char title[STRLEN];
-            snew(testTop_, 1);
-            init_t_atoms(&testTop_->atoms, natoms, GetParam() == efPDB);
-            snew(testX_, natoms);
-            read_stx_conf(referenceFilename_.c_str(), title, &testTop_->atoms,
-                          testX_, NULL, NULL, testBox_);
-            testTop_->name = put_symtab(&testTop_->symtab, title);
-        }
-
         void readReferenceFileTps()
         {
             snew(testTop_, 1);
@@ -214,14 +199,6 @@ class StructureIORoundtripTest : public gmx::test::StringTestBase,
         matrix                          testBox_;
 };
 
-TEST_P(StructureIORoundtripTest, ReadWriteStxConf)
-{
-    writeReferenceFile();
-    readReferenceFileStx();
-    testTopologies();
-    writeTestFileAndTest();
-}
-
 TEST_P(StructureIORoundtripTest, ReadWriteTpsConf)
 {
     writeReferenceFile();
index b377b02c1474ec92f8fcaf9d7bf2a13fab214ac8..a179c62bf27e36cc2b57d085b870902da8bf2d44 100644 (file)
@@ -70,15 +70,13 @@ static t_pdbfile *read_pdbf(const char *fn)
     t_pdbfile *pdbf;
     double     e;
     char       buf[256], *ptr;
-    int        natoms;
     FILE      *fp;
 
     snew(pdbf, 1);
-    get_stx_coordnum (fn, &natoms);
-    init_t_atoms(&(pdbf->atoms), natoms, FALSE);
-    snew(pdbf->x, natoms);
-    read_stx_conf(fn, buf, &pdbf->atoms, pdbf->x, NULL, &pdbf->ePBC, pdbf->box);
-    fp = gmx_ffopen(fn, "r");
+    t_topology top;
+    read_tps_conf(fn, buf, &top, &pdbf->ePBC, &pdbf->x, NULL, pdbf->box, FALSE);
+    pdbf->atoms = top.atoms;
+    fp          = gmx_ffopen(fn, "r");
     do
     {
         ptr = fgets2(buf, 255, fp);
index e49878148f5e9b053a639f40e55357640759bd8b..201676c46acbb7b529a8e8f78abcb670a523f631 100644 (file)
@@ -1351,8 +1351,7 @@ int gmx_chi(int argc, char *argv[])
     };
 
     FILE              *log;
-    int                natoms, nlist, idum, nbin;
-    t_atoms            atoms;
+    int                nlist, idum, nbin;
     rvec              *x;
     int                ePBC;
     matrix             box;
@@ -1443,10 +1442,14 @@ int gmx_chi(int argc, char *argv[])
     nbin     = 360/ndeg;
 
     /* Find the chi angles using atoms struct and a list of amino acids */
-    get_stx_coordnum(ftp2fn(efSTX, NFILE, fnm), &natoms);
-    init_t_atoms(&atoms, natoms, TRUE);
-    snew(x, natoms);
-    read_stx_conf(ftp2fn(efSTX, NFILE, fnm), title, &atoms, x, NULL, &ePBC, box);
+    t_topology *top;
+    snew(top, 1);
+    read_tps_conf(ftp2fn(efSTX, NFILE, fnm), title, top, &ePBC, &x, NULL, box, FALSE);
+    t_atoms    &atoms = top->atoms;
+    if (atoms.pdbinfo == NULL)
+    {
+        snew(atoms.pdbinfo, atoms.nr);
+    }
     fprintf(log, "Title: %s\n", title);
 
     gmx_residuetype_init(&rt);
index 91f1c96e34317bf172513e65d5dfc9b8dc0b7f73..ad0793e85b60fb543b423b4823cc835d5eb6c54f 100644 (file)
@@ -48,6 +48,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/atoms.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -191,7 +192,6 @@ int gmx_dyndom(int argc, char *argv[])
     t_trxstatus *status;
     atom_id     *index = NULL, *index_all;
     char         title[256], *grpname;
-    t_atoms      atoms;
     real         angle, trans;
     rvec        *x, *v, *xout, *vout;
     matrix       box;
@@ -215,11 +215,15 @@ int gmx_dyndom(int argc, char *argv[])
         gmx_fatal(FARGS, "maxangle not given");
     }
 
-    get_stx_coordnum (opt2fn("-f", NFILE, fnm), &natoms);
-    init_t_atoms(&atoms, natoms, TRUE);
-    snew(x, natoms);
-    snew(v, natoms);
-    read_stx_conf(opt2fn("-f", NFILE, fnm), title, &atoms, x, v, NULL, box);
+    t_topology *top;
+    snew(top, 1);
+    read_tps_conf(opt2fn("-f", NFILE, fnm), title, top, NULL, &x, &v, box, FALSE);
+    t_atoms  &atoms = top->atoms;
+    if (atoms.pdbinfo == NULL)
+    {
+        snew(atoms.pdbinfo, atoms.nr);
+    }
+    natoms = atoms.nr;
     snew(xout, natoms);
     snew(vout, natoms);
 
index c32cfb6b928c678d8f190e4848cb312d6ff4c4f5..559812a9a2bb8091326af38191d54e62323a8d88 100644 (file)
@@ -703,7 +703,6 @@ int gmx_editconf(int argc, char *argv[])
     double        *bfac    = NULL, c6, c12;
     int           *bfac_nr = NULL;
     t_topology    *top     = NULL;
-    t_atoms        atoms;
     char          *grpname, *sgrpname, *agrpname;
     int            isize, ssize, asize;
     atom_id       *index, *sindex, *aindex;
@@ -790,11 +789,15 @@ int gmx_editconf(int argc, char *argv[])
                   " when using the -mead option\n");
     }
 
-    get_stx_coordnum(infile, &natom);
-    init_t_atoms(&atoms, natom, TRUE);
-    snew(x, natom);
-    snew(v, natom);
-    read_stx_conf(infile, title, &atoms, x, v, &ePBC, box);
+    t_topology *top_tmp;
+    snew(top_tmp, 1);
+    read_tps_conf(infile, title, top_tmp, &ePBC, &x, &v, box, FALSE);
+    t_atoms  &atoms = top_tmp->atoms;
+    natom = atoms.nr;
+    if (atoms.pdbinfo == NULL)
+    {
+        snew(atoms.pdbinfo, atoms.nr);
+    }
     if (fn2ftp(infile) == efPDB)
     {
         get_pdb_atomnumber(&atoms, aps);
index 579721d4579921fe69aa68b61d40c298344dfc7e..fd204d62fe2abc29c7464694edf03d37199c45bc 100644 (file)
@@ -158,13 +158,15 @@ int gmx_genpr(int argc, char *argv[])
 
     if (xfn != NULL)
     {
-        snew(atoms, 1);
-        get_stx_coordnum(xfn, &(atoms->nr));
-        init_t_atoms(atoms, atoms->nr, TRUE);
-        snew(x, atoms->nr);
-        snew(v, atoms->nr);
         fprintf(stderr, "\nReading structure file\n");
-        read_stx_conf(xfn, title, atoms, x, v, NULL, box);
+        t_topology *top;
+        snew(top, 1);
+        read_tps_conf(xfn, title, top, NULL, &x, &v, box, FALSE);
+        atoms = &top->atoms;
+        if (atoms->pdbinfo == NULL)
+        {
+            snew(atoms->pdbinfo, atoms->nr);
+        }
     }
 
     if (bFreeze)
index da86456f4be663c06d69091c1246a7acb65c88bf..5104c99fb3a7be89bbc67c02489424d0a7004601 100644 (file)
@@ -394,25 +394,14 @@ void write_the_whole_thing(FILE* fp, t_edipar *edpars, rvec** eigvecs,
     write_t_edx(fp, edpars->sori, "NORIGIN, XORIGIN");
 }
 
-int read_conffile(const char *confin, char *title, rvec *x[])
+int read_conffile(const char *confin, char *title, rvec **x)
 {
-/* read coordinates out of STX file  */
-    int      natoms;
-    t_atoms  confat;
-    matrix   box;
+    t_topology  top;
+    matrix      box;
     printf("read coordnumber from file %s\n", confin);
-    get_stx_coordnum(confin, &natoms);
-    printf("number of coordinates in file %d\n", natoms);
-/*  if (natoms != ncoords)
-     gmx_fatal(FARGS,"number of coordinates in coordinate file (%s, %d)\n"
-           "             does not match topology (= %d)",
-           confin,natoms,ncoords);
-   else {*/
-    /* make space for coordinates and velocities */
-    init_t_atoms(&confat, natoms, FALSE);
-    snew(*x, natoms);
-    read_stx_conf(confin, title, &confat, *x, NULL, NULL, box);
-    return natoms;
+    read_tps_conf(confin, title, &top, NULL, x, NULL, box, FALSE);
+    printf("number of coordinates in file %d\n", top.atoms.nr);
+    return top.atoms.nr;
 }
 
 
index 4bd93584a5fe6de862d502c299639301e7c90a00..67d324ff5376f2817c8bfccd243d2f59937636fa 100644 (file)
@@ -1585,13 +1585,15 @@ int gmx_make_ndx(int argc, char *argv[])
 
     if (stxfile)
     {
-        snew(atoms, 1);
-        get_stx_coordnum(stxfile, &(atoms->nr));
-        init_t_atoms(atoms, atoms->nr, TRUE);
-        snew(x, atoms->nr);
-        snew(v, atoms->nr);
+        t_topology *top;
+        snew(top, 1);
         fprintf(stderr, "\nReading structure file\n");
-        read_stx_conf(stxfile, title, atoms, x, v, &ePBC, box);
+        read_tps_conf(stxfile, title, top, &ePBC, &x, &v, box, FALSE);
+        atoms = &top->atoms;
+        if (atoms->pdbinfo == NULL)
+        {
+            snew(atoms->pdbinfo, atoms->nr);
+        }
         natoms  = atoms->nr;
         bNatoms = TRUE;
     }
index f185477853954e7f90d42e959567d90fc21630b4..93c64cda7b256cde39b8d94aaa7111ea70127a8d 100644 (file)
@@ -46,6 +46,7 @@
 #include "gromacs/math/do_fit.h"
 #include "gromacs/topology/atoms.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/topology/topology.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
@@ -115,8 +116,7 @@ int gmx_morph(int argc, char *argv[])
     int              i, isize, is_lsq, nat1, nat2;
     t_trxstatus     *status;
     atom_id         *index, *index_lsq, *index_all, *dummy;
-    t_atoms          atoms;
-    rvec            *x1, *x2, *xx, *v;
+    rvec            *x1, *x2, *xx;
     matrix           box;
     real             rms1, rms2, fac, *mass;
     char             title[STRLEN], *grpname;
@@ -129,22 +129,20 @@ int gmx_morph(int argc, char *argv[])
     {
         return 0;
     }
-    get_stx_coordnum (opt2fn("-f1", NFILE, fnm), &nat1);
-    get_stx_coordnum (opt2fn("-f2", NFILE, fnm), &nat2);
+
+    t_topology *top;
+    snew(top, 1);
+    read_tps_conf(opt2fn("-f1", NFILE, fnm), title, top, NULL, &x1, NULL, box, FALSE);
+    nat1 = top->atoms.nr;
+    read_tps_conf(opt2fn("-f2", NFILE, fnm), title, top, NULL, &x2, NULL, box, FALSE);
+    nat2 = top->atoms.nr;
     if (nat1 != nat2)
     {
         gmx_fatal(FARGS, "Number of atoms in first structure is %d, in second %d",
                   nat1, nat2);
     }
-
-    init_t_atoms(&atoms, nat1, TRUE);
-    snew(x1, nat1);
-    snew(x2, nat1);
     snew(xx, nat1);
-    snew(v, nat1);
-
-    read_stx_conf(opt2fn("-f1", NFILE, fnm), title, &atoms, x1, v, NULL, box);
-    read_stx_conf(opt2fn("-f2", NFILE, fnm), title, &atoms, x2, v, NULL, box);
+    t_atoms  &atoms = top->atoms;
 
     snew(mass, nat1);
     snew(index_all, nat1);
index 3d08a0f3db4b55d11d3d19582ce2779813d33b52..2f0b36133aa46aad9992cb2571bd0a29b3fe19a4 100644 (file)
@@ -232,7 +232,6 @@ int gmx_rmsf(int argc, char *argv[])
     matrix           box, pdbbox;
     rvec            *x, *pdbx, *xref;
     t_trxstatus     *status;
-    int              npdbatoms;
     const char      *label;
     char             title[STRLEN];
 
@@ -311,23 +310,23 @@ int gmx_rmsf(int argc, char *argv[])
 
     if (bReadPDB)
     {
-        get_stx_coordnum(opt2fn("-q", NFILE, fnm), &npdbatoms);
+        t_topology *top_pdb;
+        snew(top_pdb, 1);
+        /* Read coordinates twice */
+        read_tps_conf(opt2fn("-q", NFILE, fnm), title, top_pdb, NULL, NULL, NULL, pdbbox, FALSE);
         snew(pdbatoms, 1);
+        *pdbatoms = top_pdb->atoms;
+        read_tps_conf(opt2fn("-q", NFILE, fnm), title, top_pdb, NULL, &pdbx, NULL, pdbbox, FALSE);
         snew(refatoms, 1);
-        init_t_atoms(pdbatoms, npdbatoms, TRUE);
-        init_t_atoms(refatoms, npdbatoms, TRUE);
-        snew(pdbx, npdbatoms);
-        /* Read coordinates twice */
-        read_stx_conf(opt2fn("-q", NFILE, fnm), title, pdbatoms, pdbx, NULL, NULL, pdbbox);
-        read_stx_conf(opt2fn("-q", NFILE, fnm), title, refatoms, pdbx, NULL, NULL, pdbbox);
+        *refatoms = top_pdb->atoms;
+        sfree(top_pdb);
     }
     else
     {
         pdbatoms  = &top.atoms;
         refatoms  = &top.atoms;
         pdbx      = xref;
-        npdbatoms = pdbatoms->nr;
-        snew(pdbatoms->pdbinfo, npdbatoms);
+        snew(pdbatoms->pdbinfo, pdbatoms->nr);
         copy_mat(box, pdbbox);
     }
 
index 01c998a13871720ccfdd54ff5dc642cb40686123..f9a7e53fa6c22aeff15c795dbe1c867ee598d9da 100644 (file)
@@ -226,21 +226,18 @@ int gmx_genconf(int argc, char *argv[])
 
     vol = nx*ny*nz; /* calculate volume in grid points (= nr. molecules) */
 
-    get_stx_coordnum(opt2fn("-f", NFILE, fnm), &natoms);
-    snew(atoms, 1);
+    t_topology *top;
+    snew(top, 1);
+    atoms = &top->atoms;
+    read_tps_conf(opt2fn("-f", NFILE, fnm), title, top, &ePBC, &x, &v, box, FALSE);
+    natoms = atoms->nr;
+    nres   = atoms->nres;          /* nr of residues in one element? */
     /* make space for all the atoms */
-    init_t_atoms(atoms, natoms*vol, FALSE);
-    snew(x, natoms*vol);           /* get space for coordinates of all atoms */
+    add_t_atoms(atoms, natoms*(vol-1), nres*(vol-1));
+    srenew(x, natoms*vol);         /* get space for coordinates of all atoms */
+    srenew(v, natoms*vol);         /* velocities. not really needed? */
     snew(xrot, natoms);            /* get space for rotation matrix? */
-    snew(v, natoms*vol);           /* velocities. not really needed? */
     snew(vrot, natoms);
-    /* set atoms->nr to the number in one box *
-     * to avoid complaints in read_stx_conf   *
-     */
-    atoms->nr = natoms;
-    read_stx_conf(opt2fn("-f", NFILE, fnm), title, atoms, x, v, &ePBC, box);
-
-    nres = atoms->nres;            /* nr of residues in one element? */
 
     if (bTRX)
     {
index 1bb75e56cce4ceb01a9124ce74f61cb6b413b488..683a7e71ca54b9869a2ded27dff2ea99e9500cd5 100644 (file)
@@ -509,7 +509,6 @@ new_status(const char *topfile, const char *topppfile, const char *confin,
     t_molinfo      *molinfo = NULL;
     int             nmolblock;
     gmx_molblock_t *molblock, *molbs;
-    t_atoms        *confat;
     int             mb, i, nrmols, nmismatch;
     char            buf[STRLEN];
     gmx_bool        bGB = FALSE;
@@ -600,51 +599,47 @@ new_status(const char *topfile, const char *topppfile, const char *confin,
         fprintf(stderr, "processing coordinates...\n");
     }
 
-    get_stx_coordnum(confin, &state->natoms);
+    char        title[STRLEN];
+    t_topology *conftop;
+    snew(conftop, 1);
+    init_state(state, 0, 0, 0, 0, 0);
+    read_tps_conf(confin, title, conftop, NULL, &state->x, &state->v, state->box, FALSE);
+    state->natoms = state->nalloc = conftop->atoms.nr;
     if (state->natoms != sys->natoms)
     {
         gmx_fatal(FARGS, "number of coordinates in coordinate file (%s, %d)\n"
                   "             does not match topology (%s, %d)",
                   confin, state->natoms, topfile, sys->natoms);
     }
-    else
-    {
-        /* make space for coordinates and velocities */
-        char title[STRLEN];
-        snew(confat, 1);
-        init_t_atoms(confat, state->natoms, FALSE);
-        init_state(state, state->natoms, 0, 0, 0, 0);
-        read_stx_conf(confin, title, confat, state->x, state->v, NULL, state->box);
-        /* This call fixes the box shape for runs with pressure scaling */
-        set_box_rel(ir, state);
+    /* This call fixes the box shape for runs with pressure scaling */
+    set_box_rel(ir, state);
 
-        nmismatch = check_atom_names(topfile, confin, sys, confat);
-        free_t_atoms(confat, TRUE);
-        sfree(confat);
+    nmismatch = check_atom_names(topfile, confin, sys, &conftop->atoms);
+    done_top(conftop);
+    sfree(conftop);
 
-        if (nmismatch)
-        {
-            sprintf(buf, "%d non-matching atom name%s\n"
-                    "atom names from %s will be used\n"
-                    "atom names from %s will be ignored\n",
-                    nmismatch, (nmismatch == 1) ? "" : "s", topfile, confin);
-            warning(wi, buf);
-        }
+    if (nmismatch)
+    {
+        sprintf(buf, "%d non-matching atom name%s\n"
+                "atom names from %s will be used\n"
+                "atom names from %s will be ignored\n",
+                nmismatch, (nmismatch == 1) ? "" : "s", topfile, confin);
+        warning(wi, buf);
+    }
 
-        /* Do more checks, mostly related to constraints */
-        if (bVerbose)
-        {
-            fprintf(stderr, "double-checking input for internal consistency...\n");
-        }
-        {
-            int bHasNormalConstraints = 0 < (nint_ftype(sys, molinfo, F_CONSTR) +
-                                             nint_ftype(sys, molinfo, F_CONSTRNC));
-            int bHasAnyConstraints = bHasNormalConstraints || 0 < nint_ftype(sys, molinfo, F_SETTLE);
-            double_check(ir, state->box,
-                         bHasNormalConstraints,
-                         bHasAnyConstraints,
-                         wi);
-        }
+    /* Do more checks, mostly related to constraints */
+    if (bVerbose)
+    {
+        fprintf(stderr, "double-checking input for internal consistency...\n");
+    }
+    {
+        int bHasNormalConstraints = 0 < (nint_ftype(sys, molinfo, F_CONSTR) +
+                                         nint_ftype(sys, molinfo, F_CONSTRNC));
+        int bHasAnyConstraints = bHasNormalConstraints || 0 < nint_ftype(sys, molinfo, F_SETTLE);
+        double_check(ir, state->box,
+                     bHasNormalConstraints,
+                     bHasAnyConstraints,
+                     wi);
     }
 
     if (bGenVel)
@@ -816,7 +811,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
     rvec           *x, *v, *xp;
     dvec            sum;
     double          totmass;
-    t_atoms         dumat;
+    t_topology     *top;
     matrix          box, invbox;
     int             natoms, npbcdim = 0;
     char            warn_buf[STRLEN], title[STRLEN];
@@ -825,16 +820,16 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
     t_params       *pr, *prfb;
     t_atom         *atom;
 
-    get_stx_coordnum(fn, &natoms);
+    snew(top, 1);
+    read_tps_conf(fn, title, top, NULL, &x, &v, box, FALSE);
+    natoms = top->atoms.nr;
+    done_top(top);
+    sfree(top);
     if (natoms != mtop->natoms)
     {
         sprintf(warn_buf, "The number of atoms in %s (%d) does not match the number of atoms in the topology (%d). Will assume that the first %d atoms in the topology and %s match.", fn, natoms, mtop->natoms, std::min(mtop->natoms, natoms), fn);
         warning(wi, warn_buf);
     }
-    snew(x, natoms);
-    snew(v, natoms);
-    init_t_atoms(&dumat, natoms, FALSE);
-    read_stx_conf(fn, title, &dumat, x, v, NULL, box);
 
     npbcdim = ePBC2npbcdim(ePBC);
     clear_rvec(com);
@@ -983,7 +978,6 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
         }
     }
 
-    free_t_atoms(&dumat, TRUE);
     sfree(x);
     sfree(v);
     sfree(hadAtom);
index f025990f80936e4d56f9c1cec60140126cfd0a16..cf2a3a19a6290e4f052dc623a27f37f09050294c 100644 (file)
@@ -538,10 +538,16 @@ static int read_pdball(const char *inf, const char *outf, char *title,
 
     /* READ IT */
     printf("Reading %s...\n", inf);
-    get_stx_coordnum(inf, &natom);
-    init_t_atoms(atoms, natom, TRUE);
-    snew(*x, natom);
-    read_stx_conf(inf, title, atoms, *x, NULL, ePBC, box);
+    t_topology *top;
+    snew(top, 1);
+    read_tps_conf(inf, title, top, ePBC, x, NULL, box, FALSE);
+    *atoms = top->atoms;
+    sfree(top);
+    natom = atoms->nr;
+    if (atoms->pdbinfo == NULL)
+    {
+        snew(atoms->pdbinfo, atoms->nr);
+    }
     if (fn2ftp(inf) == efPDB)
     {
         get_pdb_atomnumber(atoms, aps);
index 900c719eb945720e7da8ce9d38aaaff499ce0d59..f7e8c4dc6c442b0466e54d815e2b39298d22d5f2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, 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.
@@ -72,25 +72,18 @@ real *makeExclusionDistances(const t_atoms *a, gmx_atomprop_t aps,
 char *readConformation(const char *confin, t_atoms *atoms, rvec **x, rvec **v,
                        int *ePBC, matrix box, const char *statusTitle)
 {
-    char *title;
-    int   natoms;
+    t_topology *top;
+    char       *title;
 
+    snew(top, 1);
     snew(title, STRLEN);
-    get_stx_coordnum(confin, &natoms);
 
-    /* allocate memory for atom coordinates of configuration */
-    snew(*x, natoms);
-    if (v)
-    {
-        snew(*v, natoms);
-    }
-    init_t_atoms(atoms, natoms, FALSE);
-
-    /* read residue number, residue names, atomnames, coordinates etc. */
     fprintf(stderr, "Reading %s configuration%s\n", statusTitle, v ? " and velocities" : "");
-    read_stx_conf(confin, title, atoms, *x, v ? *v : NULL, ePBC, box);
+    read_tps_conf(confin, title, top, ePBC, x, v, box, FALSE);
+    *atoms = top->atoms;
     fprintf(stderr, "%s\nContaining %d atoms in %d residues\n",
             title, atoms->nr, atoms->nres);
+    sfree(top);
 
     return title;
 }
index 56a2fcd9fcc0f70b193915f112c61ec897a836b7..c4435f4a0b2b96d867b88a69d7a015860dd86e76 100644 (file)
@@ -439,7 +439,6 @@ int gmx_x2top(int argc, char *argv[])
     FILE              *fp;
     t_params           plist[F_NRE];
     t_excls           *excls;
-    t_atoms           *atoms; /* list with all atoms */
     gpp_atomtype_t     atype;
     t_nextnb           nnb;
     t_nm2type         *nm2t;
@@ -542,14 +541,15 @@ int gmx_x2top(int argc, char *argv[])
     init_plist(plist);
 
     /* Read coordinates */
-    get_stx_coordnum(opt2fn("-f", NFILE, fnm), &natoms);
-    snew(atoms, 1);
-
-    /* make space for all the atoms */
-    init_t_atoms(atoms, natoms, TRUE);
-    snew(x, natoms);
-
-    read_stx_conf(opt2fn("-f", NFILE, fnm), title, atoms, x, NULL, &epbc, box);
+    t_topology *top;
+    snew(top, 1);
+    read_tps_conf(opt2fn("-f", NFILE, fnm), title, top, &epbc, &x, NULL, box, FALSE);
+    t_atoms  *atoms = &top->atoms;
+    natoms = atoms->nr;
+    if (atoms->pdbinfo == NULL)
+    {
+        snew(atoms->pdbinfo, natoms);
+    }
 
     sprintf(n2t, "%s", ffdir);
     nm2t = rd_nm2type(n2t, &nnm);