Commit 974e1eb0 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13396 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 2729e19d
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -598,7 +598,7 @@ int colvarmodule::calc() {
      write_traj(cv_traj_os);
    }

    if (restart_out_freq) {
    if (restart_out_freq && cv_traj_os.is_open()) {
      // flush the trajectory file if we are at the restart frequency
      if ( (cvm::step_relative() > 0) &&
           ((cvm::step_absolute() % restart_out_freq) == 0) ) {
@@ -683,8 +683,10 @@ int colvarmodule::reset()
  index_groups.clear();
  index_group_names.clear();

  if (cv_traj_os.is_open()) {
    // Do not close file here, as we might not be done with it yet.
    cv_traj_os.flush();
  }

  return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
}
@@ -826,8 +828,11 @@ int colvarmodule::write_output_files()
  }
  cvm::decrease_depth();

  if (cv_traj_os.is_open()) {
    // do not close to avoid problems with multiple NAMD runs
    cv_traj_os.flush();
  }

  return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
}

@@ -985,8 +990,9 @@ std::ostream & colvarmodule::write_traj_label(std::ostream &os)
    (*bi)->write_traj_label(os);
  }
  os << "\n";
  if (cvm::debug())
  if (cvm::debug()) {
    os.flush();
  }
  cvm::decrease_depth();
  return os;
}
@@ -1010,8 +1016,9 @@ std::ostream & colvarmodule::write_traj(std::ostream &os)
    (*bi)->write_traj(os);
  }
  os << "\n";
  if (cvm::debug())
  if (cvm::debug()) {
    os.flush();
  }
  cvm::decrease_depth();
  return os;
}
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
#define COLVARMODULE_H

#ifndef COLVARS_VERSION
#define COLVARS_VERSION "2015-02-27"
#define COLVARS_VERSION "2015-03-15"
#endif

#ifndef COLVARS_DEBUG
+70 −57
Original line number Diff line number Diff line
@@ -25,45 +25,7 @@ int colvarscript::run(int argc, char const *argv[]) {
  }

  if (argc < 2) {
    result = "usage: "+std::string(argv[0])+" <subcommand> [args...]\n\
\n\
Managing the colvars module:\n\
  configfile <file name>      -- read configuration from a file\n\
  config <string>             -- read configuration from the given string\n\
  reset                       -- delete all internal configuration\n\
  delete                      -- delete this colvars module instance\n\
  version                     -- return version of colvars code\n\
  \n\
Input and output:\n\
  list                        -- return a list of all variables\n\
  list biases                 -- return a list of all biases\n\
  load <file name>            -- load a state file (requires configuration)\n\
  update                      -- recalculate colvars and biases based\n\
  printframe                  -- return a summary of the current frame\n\
  printframelabels            -- return labels to annotate printframe's output\n";

  if (proxy->frame() != COLVARS_NOT_IMPLEMENTED) {
      result += "\
  frame                       -- return current frame number\n\
  frame <new_frame>           -- set frame number\n";
  }

  result += "\n\
Accessing collective variables:\n\
  colvar <name> value         -- return the current value of colvar <name>\n\
  colvar <name> update        -- recalculate colvar <name>\n\
  colvar <name> type          -- return the type of colvar <name>\n\
  colvar <name> delete        -- delete colvar <name>\n\
  colvar <name> addforce <F>  -- apply given force on colvar <name>\n\
  colvar <name> getconfig     -- return config string of colvar <name>\n\
\n\
Accessing biases:\n\
  bias <name> energy          -- return the current energy of bias <name>\n\
  bias <name> update          -- recalculate bias <name>\n\
  bias <name> delete          -- delete bias <name>\n\
  bias <name> getconfig       -- return config string of bias <name>\n\
\n\
";
    result = help_string();
    return COLVARSCRIPT_OK;
  }

@@ -117,7 +79,7 @@ Accessing biases:\n\
      }
      return COLVARSCRIPT_OK;
    } else {
      result = "Wrong arguments to command \"list\"";
      result = "Wrong arguments to command \"list\"\n" + help_string();
      return COLVARSCRIPT_ERROR;
    }
  }
@@ -125,12 +87,13 @@ Accessing biases:\n\
  /// Parse config from file
  if (cmd == "configfile") {
    if (argc < 3) {
      result = "Missing arguments";
      result = "Missing arguments\n" + help_string();
      return COLVARSCRIPT_ERROR;
    }
    if (colvars->read_config_file(argv[2]) == COLVARS_OK) {
      return COLVARSCRIPT_OK;
    } else {
      result = "Error parsing configuration file";
      return COLVARSCRIPT_ERROR;
    }
  }
@@ -138,13 +101,14 @@ Accessing biases:\n\
  /// Parse config from string
  if (cmd == "config") {
    if (argc < 3) {
      result = "Missing arguments";
      result = "Missing arguments\n" + help_string();
      return COLVARSCRIPT_ERROR;
    }
    std::string conf = argv[2];
    if (colvars->read_config_string(conf) == COLVARS_OK) {
      return COLVARSCRIPT_OK;
    } else {
      result = "Error parsing configuration string";
      return COLVARSCRIPT_ERROR;
    }
  }
@@ -152,13 +116,14 @@ Accessing biases:\n\
  /// Load an input state file
  if (cmd == "load") {
    if (argc < 3) {
      result = "Missing arguments";
      result = "Missing arguments\n" + help_string();
      return COLVARSCRIPT_ERROR;
    }
    proxy->input_prefix_str = argv[2];
    if (colvars->setup_input() == COLVARS_OK) {
      return COLVARSCRIPT_OK;
    } else {
      result = "Error loading state file";
      return COLVARSCRIPT_ERROR;
    }
  }
@@ -197,27 +162,28 @@ Accessing biases:\n\
      result = cvm::to_str(f);
      return COLVARSCRIPT_OK;
    } else {
      result = "Wrong arguments to command \"frame\"";
      result = "Wrong arguments to command \"frame\"\n" + help_string();
      return COLVARSCRIPT_ERROR;
    }
  }

  result = "Syntax error";
  result = "Syntax error\n" + help_string();
  return COLVARSCRIPT_ERROR;
}


int colvarscript::proc_colvar(int argc, char const *argv[]) {
  if (argc < 3) {
    result = "Missing parameters\n" + help_string();
    return COLVARSCRIPT_ERROR;
  }

  std::string name = argv[1];
  colvar *cv = cvm::colvar_by_name(name);
  if (cv == NULL) {
    result = "Colvar not found: " + name;
    return COLVARSCRIPT_ERROR;
  }
  if (argc < 3) {
    result = "Missing parameters";
    return COLVARSCRIPT_ERROR;
  }
  std::string subcmd = argv[2];

  if (subcmd == "value") {
@@ -261,7 +227,7 @@ int colvarscript::proc_colvar(int argc, char const *argv[]) {

  if (subcmd == "addforce") {
    if (argc < 4) {
      result = "addforce: missing parameter: force value";
      result = "addforce: missing parameter: force value\n" + help_string();
      return COLVARSCRIPT_ERROR;
    }
    std::string f_str = argv[3];
@@ -279,12 +245,17 @@ int colvarscript::proc_colvar(int argc, char const *argv[]) {
    return COLVARSCRIPT_OK;
  }

  result = "Syntax error";
  result = "Syntax error\n" + help_string();
  return COLVARSCRIPT_ERROR;
}


int colvarscript::proc_bias(int argc, char const *argv[]) {
  if (argc < 3) {
    result = "Missing parameters\n" + help_string();
    return COLVARSCRIPT_ERROR;
  }

  std::string name = argv[1];
  colvarbias *b = cvm::bias_by_name(name);
  if (b == NULL) {
@@ -292,10 +263,6 @@ int colvarscript::proc_bias(int argc, char const *argv[]) {
    return COLVARSCRIPT_ERROR;
  }

  if (argc < 3) {
    result = "Missing parameters";
    return COLVARSCRIPT_ERROR;
  }
  std::string subcmd = argv[2];

  if (subcmd == "energy") {
@@ -362,9 +329,55 @@ int colvarscript::proc_bias(int argc, char const *argv[]) {
      return COLVARSCRIPT_OK;
    }

    result = "Syntax error";
    result = "Syntax error\n" + help_string();
    return COLVARSCRIPT_ERROR;
  }
  result = "Syntax error";

  result = "Syntax error\n" + help_string();
  return COLVARSCRIPT_ERROR;
}


std::string colvarscript::help_string()
{
  std::string buf;
  buf = "Usage: cv <subcommand> [args...]\n\
\n\
Managing the colvars module:\n\
  configfile <file name>      -- read configuration from a file\n\
  config <string>             -- read configuration from the given string\n\
  reset                       -- delete all internal configuration\n\
  delete                      -- delete this colvars module instance\n\
  version                     -- return version of colvars code\n\
  \n\
Input and output:\n\
  list                        -- return a list of all variables\n\
  list biases                 -- return a list of all biases\n\
  load <file name>            -- load a state file (requires configuration)\n\
  update                      -- recalculate colvars and biases based\n\
  printframe                  -- return a summary of the current frame\n\
  printframelabels            -- return labels to annotate printframe's output\n";

  if (proxy->frame() != COLVARS_NOT_IMPLEMENTED) {
      buf += "\
  frame                       -- return current frame number\n\
  frame <new_frame>           -- set frame number\n";
  }

  buf += "\n\
Accessing collective variables:\n\
  colvar <name> value         -- return the current value of colvar <name>\n\
  colvar <name> update        -- recalculate colvar <name>\n\
  colvar <name> type          -- return the type of colvar <name>\n\
  colvar <name> delete        -- delete colvar <name>\n\
  colvar <name> addforce <F>  -- apply given force on colvar <name>\n\
  colvar <name> getconfig     -- return config string of colvar <name>\n\
\n\
Accessing biases:\n\
  bias <name> energy          -- return the current energy of bias <name>\n\
  bias <name> update          -- recalculate bias <name>\n\
  bias <name> delete          -- delete bias <name>\n\
  bias <name> getconfig       -- return config string of bias <name>\n";

  return buf;
}
+4 −0
Original line number Diff line number Diff line
@@ -36,11 +36,15 @@ public:
  /// Run script command with given positional arguments
  int run(int argc, char const *argv[]);

private:
  /// Run subcommands on colvar
  int proc_colvar(int argc, char const *argv[]);

  /// Run subcommands on bias
  int proc_bias(int argc, char const *argv[]);

  /// Builds and return a short help
  std::string help_string(void);
};