Make PBC type enumeration into PbcType enum class
[alexxy/gromacs.git] / src / gromacs / fileio / pdbio.cpp
index 115a556804ac97c0e7418f35df92b1aabadfdb26..74f776ed90bb112aa382bd4f5b4e6dfe9083619a 100644 (file)
@@ -113,16 +113,16 @@ static std::string xlate_atomname_gmx2pdb(std::string name)
 }
 
 
-void gmx_write_pdb_box(FILE* out, int ePBC, const matrix box)
+void gmx_write_pdb_box(FILE* out, PbcType pbcType, const matrix box)
 {
     real alpha, beta, gamma;
 
-    if (ePBC == -1)
+    if (pbcType == PbcType::Unset)
     {
-        ePBC = guess_ePBC(box);
+        pbcType = guessPbcType(box);
     }
 
-    if (ePBC == epbcNONE)
+    if (pbcType == PbcType::No)
     {
         return;
     }
@@ -152,7 +152,7 @@ void gmx_write_pdb_box(FILE* out, int ePBC, const matrix box)
         gamma = 90;
     }
     fprintf(out, "REMARK    THIS IS A SIMULATION BOX\n");
-    if (ePBC != epbcSCREW)
+    if (pbcType != PbcType::Screw)
     {
         fprintf(out, "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %-11s%4d\n", 10 * norm(box[XX]),
                 10 * norm(box[YY]), 10 * norm(box[ZZ]), alpha, beta, gamma, "P 1", 1);
@@ -165,17 +165,17 @@ void gmx_write_pdb_box(FILE* out, int ePBC, const matrix box)
     }
 }
 
-static void read_cryst1(char* line, int* ePBC, matrix box)
+static void read_cryst1(char* line, PbcType* pbcType, matrix box)
 {
 #define SG_SIZE 11
-    char   sa[12], sb[12], sc[12], sg[SG_SIZE + 1], ident;
-    double fa, fb, fc, alpha, beta, gamma, cosa, cosb, cosg, sing;
-    int    syma, symb, symc;
-    int    ePBC_file;
+    char    sa[12], sb[12], sc[12], sg[SG_SIZE + 1], ident;
+    double  fa, fb, fc, alpha, beta, gamma, cosa, cosb, cosg, sing;
+    int     syma, symb, symc;
+    PbcType pbcTypeFile;
 
     sscanf(line, "%*s%s%s%s%lf%lf%lf", sa, sb, sc, &alpha, &beta, &gamma);
 
-    ePBC_file = -1;
+    pbcTypeFile = PbcType::Unset;
     if (strlen(line) >= 55)
     {
         strncpy(sg, line + 55, SG_SIZE);
@@ -187,17 +187,17 @@ static void read_cryst1(char* line, int* ePBC, matrix box)
         sscanf(sg, "%c %d %d %d", &ident, &syma, &symb, &symc);
         if (ident == 'P' && syma == 1 && symb <= 1 && symc <= 1)
         {
-            fc        = strtod(sc, nullptr) * 0.1;
-            ePBC_file = (fc > 0 ? epbcXYZ : epbcXY);
+            fc          = strtod(sc, nullptr) * 0.1;
+            pbcTypeFile = (fc > 0 ? PbcType::Xyz : PbcType::XY);
         }
         if (ident == 'P' && syma == 21 && symb == 1 && symc == 1)
         {
-            ePBC_file = epbcSCREW;
+            pbcTypeFile = PbcType::Screw;
         }
     }
-    if (ePBC)
+    if (pbcType)
     {
-        *ePBC = ePBC_file;
+        *pbcType = pbcTypeFile;
     }
 
     if (box)
@@ -205,7 +205,7 @@ static void read_cryst1(char* line, int* ePBC, matrix box)
         fa = strtod(sa, nullptr) * 0.1;
         fb = strtod(sb, nullptr) * 0.1;
         fc = strtod(sc, nullptr) * 0.1;
-        if (ePBC_file == epbcSCREW)
+        if (pbcTypeFile == PbcType::Screw)
         {
             fa *= 0.5;
         }
@@ -290,7 +290,7 @@ void write_pdbfile_indexed(FILE*          out,
                            const char*    title,
                            const t_atoms* atoms,
                            const rvec     x[],
-                           int            ePBC,
+                           PbcType        pbcType,
                            const matrix   box,
                            char           chainid,
                            int            model_nr,
@@ -309,7 +309,7 @@ void write_pdbfile_indexed(FILE*          out,
     fprintf(out, "TITLE     %s\n", (title && title[0]) ? title : gmx::bromacs().c_str());
     if (box && ((norm2(box[XX]) != 0.0F) || (norm2(box[YY]) != 0.0F) || (norm2(box[ZZ]) != 0.0F)))
     {
-        gmx_write_pdb_box(out, ePBC, box);
+        gmx_write_pdb_box(out, pbcType, box);
     }
     if (atoms->havePdbInfo)
     {
@@ -415,7 +415,7 @@ void write_pdbfile(FILE*          out,
                    const char*    title,
                    const t_atoms* atoms,
                    const rvec     x[],
-                   int            ePBC,
+                   PbcType        pbcType,
                    const matrix   box,
                    char           chainid,
                    int            model_nr,
@@ -428,7 +428,7 @@ void write_pdbfile(FILE*          out,
     {
         index[i] = i;
     }
-    write_pdbfile_indexed(out, title, atoms, x, ePBC, box, chainid, model_nr, atoms->nr, index,
+    write_pdbfile_indexed(out, title, atoms, x, pbcType, box, chainid, model_nr, atoms->nr, index,
                           conect, false);
     sfree(index);
 }
@@ -839,7 +839,7 @@ int read_pdbfile(FILE*      in,
                  t_atoms*   atoms,
                  t_symtab*  symtab,
                  rvec       x[],
-                 int*       ePBC,
+                 PbcType*   pbcType,
                  matrix     box,
                  gmx_bool   bChange,
                  gmx_conect conect)
@@ -853,10 +853,10 @@ int read_pdbfile(FILE*      in,
     int           natom, chainnum;
     gmx_bool      bStop = FALSE;
 
-    if (ePBC)
+    if (pbcType)
     {
         /* Only assume pbc when there is a CRYST1 entry */
-        *ePBC = epbcNONE;
+        *pbcType = PbcType::No;
     }
     if (box != nullptr)
     {
@@ -891,7 +891,7 @@ int read_pdbfile(FILE*      in,
                 }
                 break;
 
-            case epdbCRYST1: read_cryst1(line, ePBC, box); break;
+            case epdbCRYST1: read_cryst1(line, pbcType, box); break;
 
             case epdbTITLE:
             case epdbHEADER:
@@ -1009,11 +1009,11 @@ void get_pdb_coordnum(FILE* in, int* natoms)
     }
 }
 
-void gmx_pdb_read_conf(const char* infile, t_symtab* symtab, char** name, t_atoms* atoms, rvec x[], int* ePBC, matrix box)
+void gmx_pdb_read_conf(const char* infile, t_symtab* symtab, char** name, t_atoms* atoms, rvec x[], PbcType* pbcType, matrix box)
 {
     FILE* in = gmx_fio_fopen(infile, "r");
     char  title[STRLEN];
-    read_pdbfile(in, title, nullptr, atoms, symtab, x, ePBC, box, TRUE, nullptr);
+    read_pdbfile(in, title, nullptr, atoms, symtab, x, pbcType, box, TRUE, nullptr);
     if (name != nullptr)
     {
         *name = gmx_strdup(title);