Add flags for optional t_atoms entries
authorBerk Hess <hess@kth.se>
Wed, 8 Jun 2016 11:40:59 +0000 (13:40 +0200)
committerDavid van der Spoel <davidvanderspoel@gmail.com>
Thu, 29 Sep 2016 07:15:21 +0000 (09:15 +0200)
Instead of checking for (non-)NULL pointer, we can now determine
the presence of optional entries in t_atoms using booleans.
Moved the mass generation from confio.cpp to a function in atoms.cpp.
Most changes are caused by checking havePdbInfo iso pdbinfo!=NULL.

Change-Id: I6e2c8ffaa2240056f34da4c93f1713c40a00f391

23 files changed:
src/gromacs/fileio/confio.cpp
src/gromacs/fileio/espio.cpp
src/gromacs/fileio/g96io.cpp
src/gromacs/fileio/groio.cpp
src/gromacs/fileio/pdbio.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxana/edittop.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gmx_confrms.cpp
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/gmxana/gmx_dyndom.cpp
src/gromacs/gmxana/gmx_editconf.cpp
src/gromacs/gmxana/gmx_make_ndx.cpp
src/gromacs/gmxana/gmx_rmsf.cpp
src/gromacs/gmxana/gmx_traj.cpp
src/gromacs/gmxana/gmx_trjconv.cpp
src/gromacs/gmxpreprocess/topio.cpp
src/gromacs/selection/centerofmass.cpp
src/gromacs/selection/sm_simple.cpp
src/gromacs/selection/tests/toputils.cpp
src/gromacs/topology/atoms.cpp
src/gromacs/topology/atoms.h
src/gromacs/topology/mtop_util.cpp

index a370d48890df143cacf5fde6a60ff4445b478b55..21f80c60a21a995c8e4db09a73cad32f62614036 100644 (file)
@@ -50,7 +50,6 @@
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/vec.h"
-#include "gromacs/topology/atomprop.h"
 #include "gromacs/topology/atoms.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/mtop_util.h"
@@ -384,10 +383,9 @@ gmx_bool read_tps_conf(const char *infile, t_topology *top, int *ePBC,
                        rvec **x, rvec **v, matrix box, gmx_bool bMass)
 {
     t_tpxheader      header;
-    int              natoms, i;
+    int              natoms;
     gmx_bool         bTop, bXNULL = FALSE;
     gmx_mtop_t      *mtop;
-    gmx_atomprop_t   aps;
 
     bTop  = fn2bTPX(infile);
     if (ePBC != NULL)
@@ -442,24 +440,7 @@ gmx_bool read_tps_conf(const char *infile, t_topology *top, int *ePBC,
         }
         if (bMass)
         {
-            aps = gmx_atomprop_init();
-            for (i = 0; (i < natoms); i++)
-            {
-                if (!gmx_atomprop_query(aps, epropMass,
-                                        *top->atoms.resinfo[top->atoms.atom[i].resind].name,
-                                        *top->atoms.atomname[i],
-                                        &(top->atoms.atom[i].m)))
-                {
-                    if (debug)
-                    {
-                        fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
-                                *top->atoms.resinfo[top->atoms.atom[i].resind].name,
-                                top->atoms.resinfo[top->atoms.atom[i].resind].nr,
-                                *top->atoms.atomname[i]);
-                    }
-                }
-            }
-            gmx_atomprop_destroy(aps);
+            atomsSetMassesBasedOnNames(&top->atoms);
         }
         top->idef.ntypes = -1;
     }
index f101cda68c645d2ad61c99f4f2c0641fe01cbec4..308e23ff27a41b9616ac2e9f738bf8728de61198 100644 (file)
@@ -179,6 +179,12 @@ void gmx_espresso_read_conf(const char *infile,
 
     clear_mat(box);
 
+    atoms->haveMass    = FALSE;
+    atoms->haveCharge  = FALSE;
+    atoms->haveType    = FALSE;
+    atoms->haveBState  = FALSE;
+    atoms->havePdbInfo = FALSE;
+
     fp = gmx_fio_fopen(infile, "r");
 
     bFoundParticles = FALSE;
@@ -201,7 +207,15 @@ void gmx_espresso_read_conf(const char *infile,
                     {
                         bFoundProp    = TRUE;
                         prop[nprop++] = p;
-                        /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
+                        if (p == espQ)
+                        {
+                            atoms->haveCharge = TRUE;
+                        }
+
+                        if (debug)
+                        {
+                            fprintf(debug, "  prop[%d] = %s\n", nprop-1, esp_prop[prop[nprop-1]]);
+                        }
                     }
                 }
                 if (!bFoundProp && word[0] != '}')
index eafc2ede65fec231f02dc5dc97610caac2d8c3fa..bfaf13309ee934881070c36620d22e6855cd4778 100644 (file)
@@ -66,6 +66,14 @@ static int read_g96_pos(char line[], t_symtab *symtab,
     nwanted = fr->natoms;
 
     atoms = fr->atoms;
+    if (atoms != NULL)
+    {
+        atoms->haveMass    = FALSE;
+        atoms->haveCharge  = FALSE;
+        atoms->haveType    = FALSE;
+        atoms->haveBState  = FALSE;
+        atoms->havePdbInfo = FALSE;
+    }
 
     natoms = 0;
 
index 9b4e9f30585a15032d06cd8f02e6aaf2f6f59d9d..c8cda5f35b433556cc8f5f2a8a4b54d5aaeb7791 100644 (file)
@@ -116,6 +116,12 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                 " (%d)\n", natoms, atoms->nr);
     }
 
+    atoms->haveMass    = FALSE;
+    atoms->haveCharge  = FALSE;
+    atoms->haveType    = FALSE;
+    atoms->haveBState  = FALSE;
+    atoms->havePdbInfo = FALSE;
+
     bFirst = TRUE;
 
     bVel = FALSE;
index ddedd79e71c36e4097c92ab74d3c6e7095f1eba9..b690e78d1d3366a5065b932cd4098a20c9e1b2f8 100644 (file)
@@ -286,7 +286,7 @@ void write_pdbfile_indexed(FILE *out, const char *title,
     {
         gmx_write_pdb_box(out, ePBC, box);
     }
-    if (atoms->pdbinfo)
+    if (atoms->havePdbInfo)
     {
         /* Check whether any occupancies are set, in that case leave it as is,
          * otherwise set them all to one
@@ -870,6 +870,12 @@ int read_pdbfile(FILE *in, char *title, int *model_nr,
         clear_mat(box);
     }
 
+    atoms->haveMass    = FALSE;
+    atoms->haveCharge  = FALSE;
+    atoms->haveType    = FALSE;
+    atoms->haveBState  = FALSE;
+    atoms->havePdbInfo = (atoms->pdbinfo != NULL);
+
     bCOMPND  = FALSE;
     title[0] = '\0';
     natom    = 0;
@@ -886,7 +892,7 @@ int read_pdbfile(FILE *in, char *title, int *model_nr,
                 break;
 
             case epdbANISOU:
-                if (atoms->pdbinfo)
+                if (atoms->havePdbInfo)
                 {
                     read_anisou(line, natom, atoms);
                 }
index d46d4c7483e09e0426db5b5e6c74f9598d2a3df2..0829751582b78ff38458ee25bd1a72c8ec4bbd70 100644 (file)
@@ -68,6 +68,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/snprintf.h"
 #include "gromacs/utility/txtdump.h"
@@ -2413,6 +2414,16 @@ static void do_atoms(t_fileio *fio, t_atoms *atoms, gmx_bool bRead, t_symtab *sy
     }
     if (bRead)
     {
+        /* Since we have always written all t_atom properties in the tpr file
+         * (at least for all backward compatible versions), we don't store
+         * but simple set the booleans here.
+         */
+        atoms->haveMass    = TRUE;
+        atoms->haveCharge  = TRUE;
+        atoms->haveType    = TRUE;
+        atoms->haveBState  = TRUE;
+        atoms->havePdbInfo = FALSE;
+
         snew(atoms->atom, atoms->nr);
         snew(atoms->atomname, atoms->nr);
         snew(atoms->atomtype, atoms->nr);
@@ -2424,6 +2435,10 @@ static void do_atoms(t_fileio *fio, t_atoms *atoms, gmx_bool bRead, t_symtab *sy
         }
         atoms->pdbinfo = NULL;
     }
+    else
+    {
+        GMX_RELEASE_ASSERT(atoms->haveMass && atoms->haveCharge && atoms->haveType && atoms->haveBState, "Mass, charge, atomtype and B-state parameters should be present in t_atoms when writing a tpr file");
+    }
     for (i = 0; (i < atoms->nr); i++)
     {
         do_atom(fio, &atoms->atom[i], egcNR, bRead, file_version, groups, i);
index 3e69165cb76d2e13b63e826b66011ced485ef83d..41e7acb79014b5b135f885e9ec69966e37e2ba63 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) 2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016, 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.
@@ -181,7 +181,7 @@ static void delete_from_atoms(t_atoms *atoms, int inr)
         atoms->atom[i] = atoms->atom[i+1];
     }
 
-    if (atoms->pdbinfo)
+    if (atoms->havePdbInfo)
     {
         /* Shift the pdbatom struct down */
         for (i = inr; (i < atoms->nr-1); i++)
index 5f227ed9a378286da320e7f3c8ae221aac427b0e..f3412fcb5f6bc291f2d9760127b9aba270d6ff8a 100644 (file)
@@ -1144,6 +1144,8 @@ static void order_params(FILE *log,
     {
         real x0, y0, z0;
 
+        atoms->havePdbInfo = TRUE;
+
         if (NULL == atoms->pdbinfo)
         {
             snew(atoms->pdbinfo, atoms->nr);
index 7285a059bdcd212450c9b640b180997a46dd2acc..a5ed70c7ea61e0a449ba2945e2bf9d1b2979c959 100644 (file)
@@ -739,6 +739,8 @@ int gmx_confrms(int argc, char *argv[])
                 srenew(atoms1->pdbinfo, atoms1->nr);
                 srenew(atoms1->atom, atoms1->nr); /* Why renew atom? */
 
+                atoms1->havePdbInfo = TRUE;
+
                 /* Avoid segfaults when writing the pdb-file */
                 for (i = 0; i < atoms1->nr; i++)
                 {
index 58413e45eaf951785c97162559a9eb03c351ca92..a689d91d969046101afeff76a85b1caa889fee22 100644 (file)
@@ -770,6 +770,7 @@ int gmx_disre(int argc, char *argv[])
         {
             snew(atoms->pdbinfo, atoms->nr);
         }
+        atoms->havePdbInfo = TRUE;
     }
 
     top = gmx_mtop_generate_local_top(&mtop, ir.efep != efepNO);
index 0ac5265afd8089503101562b3b710b97bcbdfe96..362a783db12de13498fa72cfc2d00e12dc179dd6 100644 (file)
@@ -223,7 +223,8 @@ int gmx_dyndom(int argc, char *argv[])
     {
         snew(atoms.pdbinfo, atoms.nr);
     }
-    natoms = atoms.nr;
+    atoms.havePdbInfo = TRUE;
+    natoms            = atoms.nr;
     snew(xout, natoms);
     snew(vout, natoms);
 
index 87fa1bc7004d8142a5f1021c3885c67a9cd6be3f..7973df30fd808937ee605b34089edf779d40f330 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) 2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016, 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.
@@ -797,6 +797,8 @@ int gmx_editconf(int argc, char *argv[])
     {
         snew(atoms.pdbinfo, atoms.nr);
     }
+    atoms.havePdbInfo = TRUE;
+
     if (fn2ftp(infile) == efPDB)
     {
         get_pdb_atomnumber(&atoms, aps);
index 56cfa2eb44616fade78a263a7aab5f013dfd5eef..f777dcd1625dc87d792267c2d11fac42330fe8db 100644 (file)
@@ -1012,7 +1012,7 @@ static gmx_bool parse_entry(char **string, int natoms, const t_atoms *atoms,
         if (check_have_atoms(atoms, ostring) &&
             parse_names(string, &n_names, names))
         {
-            if (atoms->atomtype == NULL)
+            if (!(atoms->haveType))
             {
                 printf("Need a run input file to select atom types\n");
             }
index 0cdbd1a2fc341fc5ac0cf475245285d8be62efb5..4195da3eba601f570fb106dec36a3dc3057ed5de 100644 (file)
@@ -331,6 +331,7 @@ int gmx_rmsf(int argc, char *argv[])
         refatoms  = &top.atoms;
         pdbx      = xref;
         snew(pdbatoms->pdbinfo, pdbatoms->nr);
+        pdbatoms->havePdbInfo = TRUE;
         copy_mat(box, pdbbox);
     }
 
index 28dbbd9e7981024ec12b1dd5dcad3b56a0b8651c..bc0bfebea7a056aa7cf104aa468d00b1328d9ee9 100644 (file)
@@ -511,6 +511,8 @@ static void write_pdb_bfac(const char *fname, const char *xname,
         {
             snew(atoms->pdbinfo, atoms->nr);
         }
+        atoms->havePdbInfo = TRUE;
+
         if (onedim == -1)
         {
             for (i = 0; i < isize; i++)
index d7769a86334313eddc6b1029bf87245d9c1bdcba..a28040b72f782cae6057b239e927bb99fadc441d 100644 (file)
@@ -1244,14 +1244,14 @@ int gmx_trjconv(int argc, char *argv[])
             /* get memory for stuff to go in .pdb file, and initialize
              * the pdbinfo structure part if the input has it.
              */
-            init_t_atoms(&useatoms, atoms->nr, (atoms->pdbinfo != NULL));
+            init_t_atoms(&useatoms, atoms->nr, atoms->havePdbInfo);
             sfree(useatoms.resinfo);
             useatoms.resinfo = atoms->resinfo;
             for (i = 0; (i < nout); i++)
             {
                 useatoms.atomname[i] = atoms->atomname[index[i]];
                 useatoms.atom[i]     = atoms->atom[index[i]];
-                if (atoms->pdbinfo != NULL)
+                if (atoms->havePdbInfo)
                 {
                     useatoms.pdbinfo[i]  = atoms->pdbinfo[index[i]];
                 }
index e37e6d3c31aa28afa7b37f598bea299527392c66..b503a14fab8a04fd1bee552fdf49456861e99937 100644 (file)
@@ -927,8 +927,13 @@ static char **read_topol(const char *infile, const char *outfile,
 
                             push_molt(symtab, &nmol, molinfo, pline, wi);
                             srenew(block2, nmol);
-                            block2[nmol-1].nr = 0;
-                            mi0               = &((*molinfo)[nmol-1]);
+                            block2[nmol-1].nr      = 0;
+                            mi0                    = &((*molinfo)[nmol-1]);
+                            mi0->atoms.haveMass    = TRUE;
+                            mi0->atoms.haveCharge  = TRUE;
+                            mi0->atoms.haveType    = TRUE;
+                            mi0->atoms.haveBState  = TRUE;
+                            mi0->atoms.havePdbInfo = FALSE;
                             break;
                         }
                         case d_atoms:
index 7be8c4ed4c2f681aa65ed49b6b38d58d9b445b43..5b1b00d4fb0f96b0a0f5c146b824de65efcda909 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016, 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.
@@ -79,7 +79,7 @@ gmx_calc_com(const t_topology *top, rvec x[], int nrefat, const int index[], rve
     int                 m, j, ai;
     real                mass, mtot;
 
-    GMX_RELEASE_ASSERT(top != nullptr,
+    GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
                        "No masses available while mass weighting was requested");
     clear_rvec(xout);
     mtot = 0;
@@ -109,7 +109,7 @@ gmx_calc_cog_f(const t_topology *top, rvec f[], int nrefat, const int index[], r
     int                 m, j, ai;
     real                mass, mtot;
 
-    GMX_RELEASE_ASSERT(top != nullptr,
+    GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
                        "No masses available while mass weighting was requested");
     clear_rvec(fout);
     mtot = 0;
@@ -267,7 +267,7 @@ gmx_calc_com_pbc(const t_topology *top, rvec x[], t_pbc *pbc,
     real                mass, mtot;
     rvec                dx, xtest;
 
-    GMX_RELEASE_ASSERT(top != nullptr,
+    GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
                        "No masses available while mass weighting was requested");
     /* First simple calculation */
     clear_rvec(xout);
@@ -379,7 +379,7 @@ gmx_calc_com_block(const t_topology *top, rvec x[], const t_block *block, const
     rvec                xb;
     real                mass, mtot;
 
-    GMX_RELEASE_ASSERT(top != nullptr,
+    GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
                        "No masses available while mass weighting was requested");
     for (b = 0; b < block->nr; ++b)
     {
@@ -414,7 +414,7 @@ gmx_calc_cog_f_block(const t_topology *top, rvec f[], const t_block *block, cons
     rvec                fb;
     real                mass, mtot;
 
-    GMX_RELEASE_ASSERT(top != nullptr,
+    GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
                        "No masses available while mass weighting was requested");
     for (b = 0; b < block->nr; ++b)
     {
index 8f7af415a9f8b74b7f14f9b45bd5e0acb25648c8..e25da1ef03e9a048a34825092eac8d39e738b41c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016, 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.
@@ -646,7 +646,7 @@ check_atomtype(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */
 {
     bool bOk;
 
-    bOk = (top != NULL && top->atoms.atomtype != NULL);
+    bOk = (top != NULL && (top->atoms.haveType));
     if (!bOk)
     {
         GMX_THROW(gmx::InconsistentInputError("Atom types not available in topology"));
index 4b13741d8ae10f283bfb6c8ea97bd920247113e9..160d961cfd9bae8b14eb0dbe0ae26ff057bf50ec 100644 (file)
@@ -159,6 +159,7 @@ void TopologyManager::initAtoms(int count)
     {
         top_->atoms.atom[i].m = (i % 3 == 0 ? 2.0 : 1.0);
     }
+    top_->atoms.haveMass = TRUE;
     if (frame_ != NULL)
     {
         frame_->natoms = count;
@@ -193,6 +194,7 @@ void TopologyManager::initAtomTypes(const ConstArrayRef<const char *> &types)
         }
         top_->atoms.atomtype[i] = &atomtypes_[j];
     }
+    top_->atoms.haveType = TRUE;
 }
 
 void TopologyManager::initUniformResidues(int residueSize)
index 12df5df44c2d645c4c90b417d1f41001fdce5320..f9fced2d61debefdd5c80771a078655ddd767cf2 100644 (file)
 
 #include <algorithm>
 
+#include "gromacs/topology/atomprop.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/compare.h"
+#include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/txtdump.h"
 
@@ -54,14 +56,19 @@ const char *ptype_str[eptNR+1] = {
 
 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;
+    at->nr          = 0;
+    at->nres        = 0;
+    at->atom        = NULL;
+    at->resinfo     = NULL;
+    at->atomname    = NULL;
+    at->atomtype    = NULL;
+    at->atomtypeB   = NULL;
+    at->pdbinfo     = NULL;
+    at->haveMass    = FALSE;
+    at->haveCharge  = FALSE;
+    at->haveType    = FALSE;
+    at->haveBState  = FALSE;
+    at->havePdbInfo = FALSE;
 }
 
 void init_atomtypes(t_atomtypes *at)
@@ -155,7 +162,12 @@ void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo)
     atoms->atomtypeB = NULL;
     snew(atoms->resinfo, natoms);
     snew(atoms->atom, natoms);
-    if (bPdbinfo)
+    atoms->haveMass    = FALSE;
+    atoms->haveCharge  = FALSE;
+    atoms->haveType    = FALSE;
+    atoms->haveBState  = FALSE;
+    atoms->havePdbInfo = bPdbinfo;
+    if (atoms->havePdbInfo)
     {
         snew(atoms->pdbinfo, natoms);
     }
@@ -372,3 +384,37 @@ void cmp_atoms(FILE *fp, const t_atoms *a1, const t_atoms *a2, real ftol, real a
         }
     }
 }
+
+void atomsSetMassesBasedOnNames(t_atoms *atoms)
+{
+    if (atoms->haveMass)
+    {
+        /* We could decide to anyhow assign then or generate a fatal error,
+         * but it's probably most useful to keep the masses we have.
+         */
+        return;
+    }
+
+    gmx_atomprop_t aps = gmx_atomprop_init();
+
+    for (int i = 0; i < atoms->nr; i++)
+    {
+        if (!gmx_atomprop_query(aps, epropMass,
+                                *atoms->resinfo[atoms->atom[i].resind].name,
+                                *atoms->atomname[i],
+                                &atoms->atom[i].m))
+        {
+            if (debug)
+            {
+                fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
+                        *atoms->resinfo[atoms->atom[i].resind].name,
+                        atoms->resinfo[atoms->atom[i].resind].nr,
+                        *atoms->atomname[i]);
+            }
+            atoms->atom[i].m = 1;
+        }
+    }
+    gmx_atomprop_destroy(aps);
+
+    atoms->haveMass = TRUE;
+}
index e790fb478424b9cec69cee32d3bce26fe967765d..f0bacfd5ec2be513e428a1484c779ee9fb07463e 100644 (file)
@@ -103,19 +103,29 @@ typedef struct t_grps
 
 typedef struct t_atoms
 {
-    int            nr;          /* Nr of atoms                          */
-    t_atom        *atom;        /* Array of atoms (dim: nr)             */
+    int          nr;            /* Nr of atoms                          */
+    t_atom      *atom;          /* Array of atoms (dim: nr)             */
                                 /* The following entries will not       */
                                 /* always be used (nres==0)             */
-    char          ***atomname;  /* Array of pointers to atom name       */
+    char      ***atomname;      /* Array of pointers to atom name       */
                                 /* use: (*(atomname[i]))                */
-    char          ***atomtype;  /* Array of pointers to atom types      */
+    char      ***atomtype;      /* Array of pointers to atom types      */
                                 /* use: (*(atomtype[i]))                */
-    char          ***atomtypeB; /* Array of pointers to B atom types    */
+    char      ***atomtypeB;     /* Array of pointers to B atom types    */
                                 /* use: (*(atomtypeB[i]))               */
-    int              nres;      /* The number of resinfo entries        */
-    t_resinfo       *resinfo;   /* Array of residue names and numbers   */
-    t_pdbinfo       *pdbinfo;   /* PDB Information, such as aniso. Bfac */
+    int          nres;          /* The number of resinfo entries        */
+    t_resinfo   *resinfo;       /* Array of residue names and numbers   */
+    t_pdbinfo   *pdbinfo;       /* PDB Information, such as aniso. Bfac */
+
+    /* Flags that tell if properties are set for all nr atoms.
+     * For B-state parameters, both haveBState and the mass/charge/type
+     * flag should be TRUE.
+     */
+    gmx_bool     haveMass;      /* Mass available                       */
+    gmx_bool     haveCharge;    /* Charge available                     */
+    gmx_bool     haveType;      /* Atom type available                  */
+    gmx_bool     haveBState;    /* B-state parameters available         */
+    gmx_bool     havePdbInfo;   /* pdbinfo available                    */
 } t_atoms;
 
 typedef struct t_atomtypes
@@ -162,4 +172,10 @@ void pr_atomtypes(FILE *fp, int indent, const char *title,
 
 void cmp_atoms(FILE *fp, const t_atoms *a1, const t_atoms *a2, real ftol, real abstol);
 
+/*! \brief Set mass for each atom using the atom and residue names using a database
+ *
+ * If atoms->haveMass = TRUE does nothing.
+ */
+void atomsSetMassesBasedOnNames(t_atoms *atoms);
+
 #endif
index 5ec58477747454534a9b2b2726ebf992dffaefb0..3ee459fddae261ef123ae95700252fa44f67bd22 100644 (file)
@@ -779,13 +779,40 @@ static void atomcat(t_atoms *dest, t_atoms *src, int copies,
     int srcnr  = src->nr;
     int destnr = dest->nr;
 
+    if (dest->nr == 0)
+    {
+        dest->haveMass    = src->haveMass;
+        dest->haveType    = src->haveType;
+        dest->haveCharge  = src->haveCharge;
+        dest->haveBState  = src->haveBState;
+        dest->havePdbInfo = src->havePdbInfo;
+    }
+    else
+    {
+        dest->haveMass    = dest->haveMass    && src->haveMass;
+        dest->haveType    = dest->haveType    && src->haveType;
+        dest->haveCharge  = dest->haveCharge  && src->haveCharge;
+        dest->haveBState  = dest->haveBState  && src->haveBState;
+        dest->havePdbInfo = dest->havePdbInfo && src->havePdbInfo;
+    }
+
     if (srcnr)
     {
         size = destnr+copies*srcnr;
         srenew(dest->atom, size);
         srenew(dest->atomname, size);
-        srenew(dest->atomtype, size);
-        srenew(dest->atomtypeB, size);
+        if (dest->haveType)
+        {
+            srenew(dest->atomtype, size);
+            if (dest->haveBState)
+            {
+                srenew(dest->atomtypeB, size);
+            }
+        }
+        if (dest->havePdbInfo)
+        {
+            srenew(dest->pdbinfo, size);
+        }
     }
     if (src->nres)
     {
@@ -802,14 +829,25 @@ static void atomcat(t_atoms *dest, t_atoms *src, int copies,
 
     for (l = destnr, j = 0; (j < copies); j++, l += srcnr)
     {
-        memcpy((char *) &(dest->atomname[l]), (char *) &(src->atomname[0]),
-               (size_t)(srcnr*sizeof(src->atomname[0])));
-        memcpy((char *) &(dest->atomtype[l]), (char *) &(src->atomtype[0]),
-               (size_t)(srcnr*sizeof(src->atomtype[0])));
-        memcpy((char *) &(dest->atomtypeB[l]), (char *) &(src->atomtypeB[0]),
-               (size_t)(srcnr*sizeof(src->atomtypeB[0])));
         memcpy((char *) &(dest->atom[l]), (char *) &(src->atom[0]),
                (size_t)(srcnr*sizeof(src->atom[0])));
+        memcpy((char *) &(dest->atomname[l]), (char *) &(src->atomname[0]),
+               (size_t)(srcnr*sizeof(src->atomname[0])));
+        if (dest->haveType)
+        {
+            memcpy((char *) &(dest->atomtype[l]), (char *) &(src->atomtype[0]),
+                   (size_t)(srcnr*sizeof(src->atomtype[0])));
+            if (dest->haveBState)
+            {
+                memcpy((char *) &(dest->atomtypeB[l]), (char *) &(src->atomtypeB[0]),
+                       (size_t)(srcnr*sizeof(src->atomtypeB[0])));
+            }
+        }
+        if (dest->havePdbInfo)
+        {
+            memcpy((char *) &(dest->pdbinfo[l]), (char *) &(src->pdbinfo[0]),
+                   (size_t)(srcnr*sizeof(src->pdbinfo[0])));
+        }
     }
 
     /* Increment residue indices */