Merge branch release-2016
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_rmsf.cpp
index 8b5118003ef44f5e39f94c28a23a6537b2a144bc..6c78ce216500c5b78ca063bbe0e77bbef84ee738 100644 (file)
@@ -36,6 +36,7 @@
  */
 #include "gmxpre.h"
 
+#include <cassert>
 #include <cmath>
 #include <cstring>
 
@@ -72,7 +73,7 @@ static real find_pdb_bfac(const t_atoms *atoms, t_resinfo *ri, char *atomnm)
         if ((ri->nr == atoms->resinfo[atoms->atom[i].resind].nr) &&
             (ri->ic == atoms->resinfo[atoms->atom[i].resind].ic) &&
             (std::strcmp(*atoms->resinfo[atoms->atom[i].resind].name, rresnm) == 0) &&
-            (std::strstr(*atoms->atomname[i], atomnm) != NULL))
+            (std::strstr(*atoms->atomname[i], atomnm) != nullptr))
         {
             break;
         }
@@ -119,15 +120,19 @@ static void average_residues(double f[], double **U, int uind,
     start = 0;
     av    = 0;
     m     = 0;
+    if (!f)
+    {
+        assert(U);
+    }
     for (i = 0; i < isize; i++)
     {
-        av += w_rls[index[i]]*(f != NULL ? f[i] : U[i][uind]);
+        av += w_rls[index[i]]*(f != nullptr ? f[i] : U[i][uind]);
         m  += w_rls[index[i]];
         if (i+1 == isize ||
             atoms->atom[index[i]].resind != atoms->atom[index[i+1]].resind)
         {
             av /= m;
-            if (f != NULL)
+            if (f != nullptr)
             {
                 for (j = start; j <= i; j++)
                 {
@@ -249,22 +254,22 @@ int gmx_rmsf(int argc, char *argv[])
     real              bfac, pdb_bfac, *Uaver;
     double          **U, *xav;
     int               aid;
-    rvec             *rmsd_x = NULL;
+    rvec             *rmsd_x = nullptr;
     double           *rmsf, invcount, totmass;
     int               d;
     real              count = 0;
     rvec              xcm;
-    gmx_rmpbc_t       gpbc = NULL;
+    gmx_rmpbc_t       gpbc = nullptr;
 
     gmx_output_env_t *oenv;
 
     const char       *leg[2] = { "MD", "X-Ray" };
 
     t_filenm          fnm[] = {
-        { efTRX, "-f",  NULL,     ffREAD  },
-        { efTPS, NULL,  NULL,     ffREAD  },
-        { efNDX, NULL,  NULL,     ffOPTRD },
-        { efPDB, "-q",  NULL,     ffOPTRD },
+        { efTRX, "-f",  nullptr,     ffREAD  },
+        { efTPS, nullptr,  nullptr,     ffREAD  },
+        { efNDX, nullptr,  nullptr,     ffOPTRD },
+        { efPDB, "-q",  nullptr,     ffOPTRD },
         { efPDB, "-oq", "bfac",   ffOPTWR },
         { efPDB, "-ox", "xaver",  ffOPTWR },
         { efXVG, "-o",  "rmsf",   ffWRITE },
@@ -275,7 +280,7 @@ int gmx_rmsf(int argc, char *argv[])
 #define NFILE asize(fnm)
 
     if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_CAN_VIEW,
-                           NFILE, fnm, asize(pargs), pargs, asize(desc), desc, 0, NULL,
+                           NFILE, fnm, asize(pargs), pargs, asize(desc), desc, 0, nullptr,
                            &oenv))
     {
         return 0;
@@ -285,7 +290,7 @@ int gmx_rmsf(int argc, char *argv[])
     devfn    = opt2fn_null("-od", NFILE, fnm);
     dirfn    = opt2fn_null("-dir", NFILE, fnm);
 
-    read_tps_conf(ftp2fn(efTPS, NFILE, fnm), &top, &ePBC, &xref, NULL, box, TRUE);
+    read_tps_conf(ftp2fn(efTPS, NFILE, fnm), &top, &ePBC, &xref, nullptr, box, TRUE);
     const char *title = *top.name;
     snew(w_rls, top.atoms.nr);
 
@@ -316,10 +321,10 @@ int gmx_rmsf(int argc, char *argv[])
         t_topology *top_pdb;
         snew(top_pdb, 1);
         /* Read coordinates twice */
-        read_tps_conf(opt2fn("-q", NFILE, fnm), top_pdb, NULL, NULL, NULL, pdbbox, FALSE);
+        read_tps_conf(opt2fn("-q", NFILE, fnm), top_pdb, nullptr, nullptr, nullptr, pdbbox, FALSE);
         snew(pdbatoms, 1);
         *pdbatoms = top_pdb->atoms;
-        read_tps_conf(opt2fn("-q", NFILE, fnm), top_pdb, NULL, &pdbx, NULL, pdbbox, FALSE);
+        read_tps_conf(opt2fn("-q", NFILE, fnm), top_pdb, nullptr, &pdbx, nullptr, pdbbox, FALSE);
         /* TODO Should this assert that top_pdb->atoms.nr == top.atoms.nr?
          * See discussion at https://gerrit.gromacs.org/#/c/6430/1 */
         title = *top_pdb->name;
@@ -333,6 +338,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);
     }
 
@@ -431,7 +437,7 @@ int gmx_rmsf(int argc, char *argv[])
     {
         for (d = 0; d < DIM*DIM; d++)
         {
-            average_residues(NULL, U, d, isize, index, w_rls, &top.atoms);
+            average_residues(nullptr, U, d, isize, index, w_rls, &top.atoms);
         }
     }
 
@@ -529,7 +535,7 @@ int gmx_rmsf(int argc, char *argv[])
         }
         if (bRes)
         {
-            average_residues(rmsf, NULL, 0, isize, index, w_rls, &top.atoms);
+            average_residues(rmsf, nullptr, 0, isize, index, w_rls, &top.atoms);
         }
         /* Write RMSD output */
         fp = xvgropen(devfn, "RMS Deviation", label, "(nm)", oenv);
@@ -553,7 +559,7 @@ int gmx_rmsf(int argc, char *argv[])
             rvec_inc(pdbx[index[i]], xcm);
         }
         write_sto_conf_indexed(opt2fn("-oq", NFILE, fnm), title, pdbatoms, pdbx,
-                               NULL, ePBC, pdbbox, isize, index);
+                               nullptr, ePBC, pdbbox, isize, index);
     }
     if (opt2bSet("-ox", NFILE, fnm))
     {
@@ -567,7 +573,7 @@ int gmx_rmsf(int argc, char *argv[])
             }
         }
         /* Write a .pdb file with B-factors and optionally anisou records */
-        write_sto_conf_indexed(opt2fn("-ox", NFILE, fnm), title, pdbatoms, bFactorX, NULL,
+        write_sto_conf_indexed(opt2fn("-ox", NFILE, fnm), title, pdbatoms, bFactorX, nullptr,
                                ePBC, pdbbox, isize, index);
         sfree(bFactorX);
     }