From 06e3a11c2dd52dc7935027b28086fda9f8f63a25 Mon Sep 17 00:00:00 2001
From: Richard Berger <richard.berger@temple.edu>
Date: Wed, 7 Sep 2016 14:28:32 -0400
Subject: [PATCH] Add styles output to info command

Adds the ability to list all available styles in LAMMPS with:

```
info styles
```

Each style can also be printed separately using one of the following:

```
info atom_styles
info integrate_styles
info minimize_styles
info pair_styles
info bond_styles
info angle_styles
info dihedral_styles
info improper_styles
info kspace_styles
info fix_styles
info compute_styles
info region_styles
info dump_styles
```
---
 src/info.cpp | 332 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/info.h   |  18 +++
 2 files changed, 345 insertions(+), 5 deletions(-)

diff --git a/src/info.cpp b/src/info.cpp
index a791becf0e..0e8136278d 100644
--- a/src/info.cpp
+++ b/src/info.cpp
@@ -1,4 +1,5 @@
 /* ----------------------------------------------------------------------
+  fputs
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
@@ -12,7 +13,8 @@
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
-   Contributing author:  Axel Kohlmeyer (Temple U)
+   Contributing authors:  Axel Kohlmeyer (Temple U),
+                          Richard Berger (Temple U)
 ------------------------------------------------------------------------- */
 
 #include <string.h>
@@ -39,6 +41,9 @@
 #include "error.h"
 
 #include <time.h>
+#include <vector>
+#include <string>
+#include <algorithm>
 
 #ifdef _WIN32
 #define PSAPI_VERSION=1
@@ -70,9 +75,29 @@ enum {COMPUTES=1<<0,
       VARIABLES=1<<7,
       SYSTEM=1<<8,
       COMM=1<<9,
+      ATOM_STYLES=1<<10,
+      INTEGRATE_STYLES=1<<11,
+      MINIMIZE_STYLES=1<<12,
+      PAIR_STYLES=1<<13,
+      BOND_STYLES=1<<14,
+      ANGLE_STYLES=1<<15,
+      DIHEDRAL_STYLES=1<<16,
+      IMPROPER_STYLES=1<<17,
+      KSPACE_STYLES=1<<18,
+      FIX_STYLES=1<<19,
+      COMPUTE_STYLES=1<<20,
+      REGION_STYLES=1<<21,
+      DUMP_STYLES=1<<22,
+      COMMAND_STYLES=1<<23,
       ALL=~0};
+
+static const int STYLES = ATOM_STYLES | INTEGRATE_STYLES | MINIMIZE_STYLES | PAIR_STYLES | BOND_STYLES | \
+                         ANGLE_STYLES | DIHEDRAL_STYLES | IMPROPER_STYLES | KSPACE_STYLES | FIX_STYLES | \
+                         COMPUTE_STYLES | REGION_STYLES | DUMP_STYLES | COMMAND_STYLES;
+
 }
 
+
 static const char *varstyles[] = {
   "index", "loop", "world", "universe", "uloop", "string", "getenv",
   "file", "atomfile", "format", "equal", "atom", "python", "(unknown)"};
@@ -85,6 +110,9 @@ static const char *commlayout[] = { "uniform", "nonuniform", "irregular" };
 static const char bstyles[] = "pfsm";
 
 using namespace LAMMPS_NS;
+using namespace std;
+
+static void print_columns(FILE* fp, vector<string> & styles);
 
 /* ---------------------------------------------------------------------- */
 
@@ -122,16 +150,58 @@ void Info::command(int narg, char **arg)
       if ((out != screen) && (out != logfile)) fclose(out);
       out = fopen(arg[idx+2],"w");
       idx += 3;
-    } else if (strncmp(arg[idx],"communication",4) == 0) {
+    } else if (strncmp(arg[idx],"atom_styles",3) == 0) {
+      flags |= ATOM_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"integrate_styles",3) == 0) {
+      flags |= INTEGRATE_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"minimize_styles",3) == 0) {
+      flags |= MINIMIZE_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"pair_styles",3) == 0) {
+      flags |= PAIR_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"bond_styles",3) == 0) {
+      flags |= BOND_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"angle_styles",3) == 0) {
+      flags |= ANGLE_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"dihedral_styles",3) == 0) {
+      flags |= DIHEDRAL_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"improper_styles",3) == 0) {
+      flags |= IMPROPER_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"kspace_styles",3) == 0) {
+      flags |= KSPACE_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"fix_styles",3) == 0) {
+      flags |= FIX_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"compute_styles",5) == 0) {
+      flags |= COMPUTE_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"region_styles",3) == 0) {
+      flags |= REGION_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"dump_styles",3) == 0) {
+      flags |= DUMP_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"command_styles",5) == 0) {
+      flags |= COMMAND_STYLES;
+      ++idx;
+    } else if (strncmp(arg[idx],"communication",5) == 0) {
       flags |= COMM;
       ++idx;
-    } else if (strncmp(arg[idx],"computes",4) == 0) {
+    } else if (strncmp(arg[idx],"computes",5) == 0) {
       flags |= COMPUTES;
       ++idx;
-    } else if (strncmp(arg[idx],"dumps",3) == 0) {
+    } else if (strncmp(arg[idx],"dumps",5) == 0) {
       flags |= DUMPS;
       ++idx;
-    } else if (strncmp(arg[idx],"fixes",3) == 0) {
+    } else if (strncmp(arg[idx],"fixes",5) == 0) {
       flags |= FIXES;
       ++idx;
     } else if (strncmp(arg[idx],"groups",3) == 0) {
@@ -152,6 +222,9 @@ void Info::command(int narg, char **arg)
     } else if (strncmp(arg[idx],"system",3) == 0) {
       flags |= SYSTEM;
       ++idx;
+    } else if (strncmp(arg[idx],"styles",3) == 0) {
+      flags |= STYLES;
+      ++idx;
     } else {
       error->warning(FLERR,"Ignoring unknown or incorrect info command flag");
       ++idx;
@@ -457,6 +530,10 @@ void Info::command(int narg, char **arg)
             cpuh,cpum,cpus,wallh,wallm,walls);
   }
 
+  if (flags & STYLES) {
+    available_styles(out, flags);
+  }
+
   fputs("\nInfo-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info\n\n",out);
 
   // close output file pointer if opened locally thus forcing a hard sync.
@@ -464,6 +541,211 @@ void Info::command(int narg, char **arg)
     fclose(out);
 }
 
+
+void Info::available_styles(FILE * out, int flags)
+{
+
+  fprintf(out,"\nStyles information:\n");
+
+  if(flags & ATOM_STYLES)      atom_styles(out);
+  if(flags & INTEGRATE_STYLES) integrate_styles(out);
+  if(flags & MINIMIZE_STYLES)  minimize_styles(out);
+  if(flags & PAIR_STYLES)      pair_styles(out);
+  if(flags & BOND_STYLES)      bond_styles(out);
+  if(flags & ANGLE_STYLES)     angle_styles(out);
+  if(flags & DIHEDRAL_STYLES)  dihedral_styles(out);
+  if(flags & IMPROPER_STYLES)  improper_styles(out);
+  if(flags & KSPACE_STYLES)    kspace_styles(out);
+  if(flags & FIX_STYLES)       fix_styles(out);
+  if(flags & COMPUTE_STYLES)   compute_styles(out);
+  if(flags & REGION_STYLES)    region_styles(out);
+  if(flags & DUMP_STYLES)      dump_styles(out);
+  if(flags & COMMAND_STYLES)   command_styles(out);
+}
+
+void Info::atom_styles(FILE * out)
+{
+  fprintf(out, "\nAtom styles:\n");
+
+  vector<string> styles;
+#define ATOM_CLASS
+#define AtomStyle(key,Class) styles.push_back(#key);
+#include "style_atom.h"
+#undef ATOM_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::integrate_styles(FILE * out)
+{
+  fprintf(out, "\nIntegrate styles:\n");
+
+  vector<string> styles;
+#define INTEGRATE_CLASS
+#define IntegrateStyle(key,Class) styles.push_back(#key);
+#include "style_integrate.h"
+#undef INTEGRATE_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::minimize_styles(FILE * out)
+{
+  fprintf(out, "\nMinimize styles:\n");
+
+  vector<string> styles;
+#define MINIMIZE_CLASS
+#define MinimizeStyle(key,Class) styles.push_back(#key);
+#include "style_minimize.h"
+#undef MINIMIZE_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::pair_styles(FILE * out)
+{
+  fprintf(out, "\nPair styles:\n");
+
+  vector<string> styles;
+#define PAIR_CLASS
+#define PairStyle(key,Class) styles.push_back(#key);
+#include "style_pair.h"
+#undef PAIR_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::bond_styles(FILE * out)
+{
+  fprintf(out, "\nBond styles:\n");
+
+  vector<string> styles;
+#define BOND_CLASS
+#define BondStyle(key,Class) styles.push_back(#key);
+#include "style_bond.h"
+#undef BOND_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::angle_styles(FILE * out)
+{
+  fprintf(out, "\nAngle styles:\n");
+
+  vector<string> styles;
+#define ANGLE_CLASS
+#define AngleStyle(key,Class) styles.push_back(#key);
+#include "style_angle.h"
+#undef ANGLE_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::dihedral_styles(FILE * out)
+{
+  fprintf(out, "\nDihedral styles:\n");
+
+  vector<string> styles;
+#define DIHEDRAL_CLASS
+#define DihedralStyle(key,Class) styles.push_back(#key);
+#include "style_dihedral.h"
+#undef DIHEDRAL_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::improper_styles(FILE * out)
+{
+  fprintf(out, "\nImproper styles:\n");
+
+  vector<string> styles;
+#define IMPROPER_CLASS
+#define ImproperStyle(key,Class) styles.push_back(#key);
+#include "style_improper.h"
+#undef IMPROPER_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::kspace_styles(FILE * out)
+{
+  fprintf(out, "\nKSpace styles:\n");
+
+  vector<string> styles;
+#define KSPACE_CLASS
+#define KSpaceStyle(key,Class) styles.push_back(#key);
+#include "style_kspace.h"
+#undef KSPACE_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::fix_styles(FILE * out)
+{
+  fprintf(out, "\nFix styles:\n");
+
+  vector<string> styles;
+#define FIX_CLASS
+#define FixStyle(key,Class) styles.push_back(#key);
+#include "style_fix.h"
+#undef FIX_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::compute_styles(FILE * out)
+{
+  fprintf(out, "\nCompute styles:\n");
+
+  vector<string> styles;
+#define COMPUTE_CLASS
+#define ComputeStyle(key,Class) styles.push_back(#key);
+#include "style_compute.h"
+#undef COMPUTE_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::region_styles(FILE * out)
+{
+  fprintf(out, "\nRegion styles:\n");
+
+  vector<string> styles;
+#define REGION_CLASS
+#define RegionStyle(key,Class) styles.push_back(#key);
+#include "style_region.h"
+#undef REGION_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::dump_styles(FILE * out)
+{
+  fprintf(out, "\nDump styles:\n");
+
+  vector<string> styles;
+#define DUMP_CLASS
+#define DumpStyle(key,Class) styles.push_back(#key);
+#include "style_dump.h"
+#undef DUMP_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+void Info::command_styles(FILE * out)
+{
+  fprintf(out, "\nCommand styles (add-on input script commands):\n");
+
+  vector<string> styles;
+#define COMMAND_CLASS
+#define CommandStyle(key,Class) styles.push_back(#key);
+#include "style_command.h"
+#undef COMMAND_CLASS
+  print_columns(out, styles);
+  fprintf(out, "\n\n\n");
+}
+
+
 /* ---------------------------------------------------------------------- */
 
 // the is_active() function returns true if the selected style or name
@@ -681,3 +963,43 @@ bool Info::is_defined(const char *category, const char *name)
 
   return false;
 }
+
+static void print_columns(FILE* fp, vector<string> & styles)
+{
+  if (styles.size() == 0) {
+    fprintf(fp, "\nNone");
+    return;
+  }
+
+  std::sort(styles.begin(), styles.end());
+
+  int pos = 80;
+  for (int i = 0; i < styles.size(); ++i) {
+
+    // skip "secret" styles
+    if (isupper(styles[i][0])) continue;
+
+    int len = styles[i].length();
+    if (pos + len > 80) {
+      fprintf(fp,"\n");
+      pos = 0;
+    }
+
+    if (len < 16) {
+      fprintf(fp,"%-16s",styles[i].c_str());
+      pos += 16;
+    } else if (len < 32) {
+      fprintf(fp,"%-32s",styles[i].c_str());
+      pos += 32;
+    } else if (len < 48) {
+      fprintf(fp,"%-48s",styles[i].c_str());
+      pos += 48;
+    } else if (len < 64) {
+      fprintf(fp,"%-64s",styles[i].c_str());
+      pos += 64;
+    } else {
+      fprintf(fp,"%-80s",styles[i].c_str());
+      pos += 80;
+    }
+  }
+}
diff --git a/src/info.h b/src/info.h
index 4a7388d186..f4549badf7 100644
--- a/src/info.h
+++ b/src/info.h
@@ -32,6 +32,24 @@ class Info : protected Pointers {
   bool is_active(const char *, const char *);
   bool is_defined(const char *, const char *);
   bool is_available(const char *, const char *);
+
+private:
+  void available_styles(FILE * out, int flags);
+
+  void atom_styles(FILE * out);
+  void integrate_styles(FILE * out);
+  void minimize_styles(FILE * out);
+  void pair_styles(FILE * out);
+  void bond_styles(FILE * out);
+  void angle_styles(FILE * out);
+  void dihedral_styles(FILE * out);
+  void improper_styles(FILE * out);
+  void kspace_styles(FILE * out);
+  void fix_styles(FILE * out);
+  void compute_styles(FILE * out);
+  void region_styles(FILE * out);
+  void dump_styles(FILE * out);
+  void command_styles(FILE * out);
 };
 
 }
-- 
GitLab