Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / tomorse.cpp
index 72d14acfd046ada31e8263052967861bc3421c87..514a35bcb08d77b65ad2f8d77b80e375b10fbc4a 100644 (file)
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
-typedef struct {
+typedef struct
+{
     char *ai, *aj;
     real  e_diss;
 } t_2morse;
 
-static t_2morse *read_dissociation_energies(int *n2morse)
+static t_2morse* read_dissociation_energies(int* n2morse)
 {
     char        ai[32], aj[32];
     double      e_diss;
-    const char *fn     = "edissoc.dat";
-    t_2morse   *t2m    = nullptr;
+    const charfn     = "edissoc.dat";
+    t_2morse*   t2m    = nullptr;
     int         maxn2m = 0, n2m = 0;
     int         nread;
 
@@ -90,8 +91,7 @@ static t_2morse *read_dissociation_energies(int *n2morse)
             n2m++;
         }
         /* If we did not read three items, quit reading */
-    }
-    while (nread == 3);
+    } while (nread == 3);
 
     /* Set the return values */
     *n2morse = n2m;
@@ -99,7 +99,7 @@ static t_2morse *read_dissociation_energies(int *n2morse)
     return t2m;
 }
 
-static int nequal(const char *a1, const char *a2)
+static int nequal(const char* a1, const char* a2)
 {
     int i;
 
@@ -122,7 +122,7 @@ static int nequal(const char *a1, const char *a2)
     return i;
 }
 
-static real search_e_diss(int n2m, t_2morse t2m[], const char *ai, const char *aj)
+static real search_e_diss(int n2m, t_2morse t2m[], const char* ai, const char* aj)
 {
     int  i;
     int  ibest = -1;
@@ -133,8 +133,8 @@ static real search_e_diss(int n2m, t_2morse t2m[], const char *ai, const char *a
     for (i = 0; (i < n2m); i++)
     {
         /* Check for a perfect match */
-        if (((gmx_strcasecmp(t2m[i].ai, ai) == 0) && (gmx_strcasecmp(t2m[i].aj, aj) == 0)) ||
-            ((gmx_strcasecmp(t2m[i].aj, ai) == 0) && (gmx_strcasecmp(t2m[i].ai, aj) == 0)))
+        if (((gmx_strcasecmp(t2m[i].ai, ai) == 0) && (gmx_strcasecmp(t2m[i].aj, aj) == 0))
+            || ((gmx_strcasecmp(t2m[i].aj, ai) == 0) && (gmx_strcasecmp(t2m[i].ai, aj) == 0)))
         {
             ibest = i;
             break;
@@ -146,8 +146,7 @@ static real search_e_diss(int n2m, t_2morse t2m[], const char *ai, const char *a
              */
             nii = nequal(t2m[i].ai, ai);
             njj = nequal(t2m[i].aj, aj);
-            if (((nii >  nbstii) && (njj >= nbstjj)) ||
-                ((nii >= nbstii) && (njj >  nbstjj)))
+            if (((nii > nbstii) && (njj >= nbstjj)) || ((nii >= nbstii) && (njj > nbstjj)))
             {
                 if ((nii > 0) && (njj > 0))
                 {
@@ -161,8 +160,7 @@ static real search_e_diss(int n2m, t_2morse t2m[], const char *ai, const char *a
                 /* Swap ai and aj (at least in counting the number of equal chars) */
                 nii = nequal(t2m[i].ai, aj);
                 njj = nequal(t2m[i].aj, ai);
-                if (((nii >  nbstii) && (njj >= nbstjj)) ||
-                    ((nii >= nbstii) && (njj >  nbstjj)))
+                if (((nii > nbstii) && (njj >= nbstjj)) || ((nii >= nbstii) && (njj > nbstjj)))
                 {
                     if ((nii > 0) && (njj > 0))
                     {
@@ -187,10 +185,10 @@ static real search_e_diss(int n2m, t_2morse t2m[], const char *ai, const char *a
     }
 }
 
-void convert_harmonics(gmx::ArrayRef<MoleculeInformation> mols, PreprocessingAtomTypes *atype)
+void convert_harmonics(gmx::ArrayRef<MoleculeInformation> mols, PreprocessingAtomTypesatype)
 {
     int       n2m;
-    t_2morse *t2m;
+    t_2morset2m;
 
     /* First get the data */
     t2m = read_dissociation_energies(&n2m);
@@ -202,7 +200,7 @@ void convert_harmonics(gmx::ArrayRef<MoleculeInformation> mols, PreprocessingAto
 
     /* For all the molecule types */
     int i = 0;
-    for (auto &mol : mols)
+    for (automol : mols)
     {
         /* Check how many morse and harmonic BONDSs there are, increase size of
          * morse with the number of harmonics
@@ -211,25 +209,24 @@ void convert_harmonics(gmx::ArrayRef<MoleculeInformation> mols, PreprocessingAto
         {
             if ((interaction_function[bb].flags & IF_BTYPE) && (bb != F_MORSE))
             {
-                int nrharm  = mol.interactions[bb].size();
+                int nrharm = mol.interactions[bb].size();
 
                 /* Now loop over the harmonics, trying to convert them */
                 for (auto harmonic = mol.interactions[bb].interactionTypes.begin();
-                     harmonic != mol.interactions[bb].interactionTypes.end(); )
+                     harmonic != mol.interactions[bb].interactionTypes.end();)
                 {
                     int  ni   = harmonic->ai();
                     int  nj   = harmonic->aj();
-                    real edis =
-                        search_e_diss(n2m, t2m,
-                                      atype->atomNameFromAtomType(mol.atoms.atom[ni].type),
-                                      atype->atomNameFromAtomType(mol.atoms.atom[nj].type));
+                    real edis = search_e_diss(n2m, t2m,
+                                              atype->atomNameFromAtomType(mol.atoms.atom[ni].type),
+                                              atype->atomNameFromAtomType(mol.atoms.atom[nj].type));
                     if (edis != 0)
                     {
-                        real              b0             = harmonic->c0();
-                        real              kb             = harmonic->c1();
-                        real              beta           = std::sqrt(kb/(2*edis));
-                        std::vector<int>  atoms          = {ni, nj};
-                        std::vector<real> forceParam     = {b0, edis, beta};
+                        real              b0         = harmonic->c0();
+                        real              kb         = harmonic->c1();
+                        real              beta       = std::sqrt(kb / (2 * edis));
+                        std::vector<int>  atoms      = { ni, nj };
+                        std::vector<real> forceParam = { b0, edis, beta };
                         mol.interactions[F_MORSE].interactionTypes.emplace_back(
                                 InteractionOfType(atoms, forceParam));
                         harmonic = mol.interactions[bb].interactionTypes.erase(harmonic);
@@ -242,7 +239,7 @@ void convert_harmonics(gmx::ArrayRef<MoleculeInformation> mols, PreprocessingAto
 
                 int newHarmonics = mol.interactions[bb].size();
                 fprintf(stderr, "Converted %d out of %d %s to morse bonds for mol %d\n",
-                        nrharm-newHarmonics, nrharm, interaction_function[bb].name, i);
+                        nrharm - newHarmonics, nrharm, interaction_function[bb].name, i);
             }
         }
         i++;