Allow for "computational electrophysiology" simulations (CompEl)
[alexxy/gromacs.git] / src / gromacs / gmxlib / index.c
index 824d883ae9f17d1d4a0c26520007e9f6d2b08028..0ba946faeb3de4678dedcc264fe592c68b3e1ad0 100644 (file)
@@ -98,7 +98,7 @@ t_blocka *new_blocka(void)
     return block;
 }
 
-void write_index(const char *outf, t_blocka *b, char **gnames)
+void write_index(const char *outf, t_blocka *b, char **gnames, gmx_bool bDuplicate, int natoms)
 {
     FILE *out;
     int   i, j, k;
@@ -118,6 +118,26 @@ void write_index(const char *outf, t_blocka *b, char **gnames)
         }
         fprintf(out, "\n");
     }
+
+    /* Duplicate copy, useful for computational electrophysiology double-layer setups */
+    if (bDuplicate)
+    {
+        fprintf(stderr, "Duplicating the whole system with an atom offset of %d atoms.\n", natoms);
+        for (i = 0; (i < b->nr); i++)
+        {
+            fprintf(out, "[ %s_copy ]\n", gnames[i]);
+            for (k = 0, j = b->index[i]; j < b->index[i+1]; j++, k++)
+            {
+                fprintf(out, "%4d ", b->a[j]+1 + natoms );
+                if ((k % 15) == 14)
+                {
+                    fprintf(out, "\n");
+                }
+            }
+            fprintf(out, "\n");
+        }
+    }
+
     gmx_fio_fclose(out);
 }