ConstraintCmd.h 2.52 KB
Newer Older
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// ConstraintCmd.h:
//
////////////////////////////////////////////////////////////////////////////////

#ifndef CONSTRAINTCMD_H
#define CONSTRAINTCMD_H

#include "UserInterface.h"
#include "Sample.h"

class ConstraintCmd : public Cmd
{
  public:

  Sample *s;

  ConstraintCmd(Sample *sample) : s(sample) {};

33 34
  const char *name(void) const { return "constraint"; }
  const char *help_msg(void) const
35
  {
36
    return
37 38
    "\n constraint\n\n"
    " syntax:\n\n"
39
    "   constraint define position name atom\n"
Francois Gygi committed
40 41 42 43 44 45 46 47 48
    "   constraint define distance name atom1 atom2 distance [velocity]\n"
    "   constraint define angle name atom1 atom2 atom3 angle [velocity]\n"
    "   constraint define torsion name atom1 atom2 atom3 atom4 angle [velocity]\n"
    "   constraint set name value [velocity]\n"
    "   constraint delete name\n"
    "   constraint list\n"
    "   constraint enforce\n\n"
    "   Constraints are enforced at each MD step if ions are allowed to move.\n"
    "   Velocity parameters are optional.\n\n";
49 50 51 52
  }

  int action(int argc, char **argv)
  {
Francois Gygi committed
53 54 55 56 57 58 59
    const bool onpe0 = s->ctxt_.onpe0();
    if ( argc < 2 )
    {
      if ( onpe0 )
        cout << help_msg();
      return 1;
    }
60
    string subcmd(argv[1]);
Francois Gygi committed
61 62 63 64 65 66 67 68 69 70 71 72
    if ( subcmd == "define" )
    {
      return s->constraints.define_constraint(s->atoms,argc,argv);
    }
    else if ( subcmd == "set" )
    {
      return s->constraints.set_constraint(argc,argv);
    }
    else if ( subcmd == "delete" )
    {
      return s->constraints.delete_constraint(argc,argv);
    }
73 74 75
    else if ( subcmd == "enforce" )
    {
      s->constraints.enforce(s->atoms);
76 77
      // reset velocities to zero to avoid jump in temperature
      s->atoms.reset_velocities();
78 79
      // Note: should catch exception here if constraints could not be enforced
    }
Francois Gygi committed
80 81 82 83 84 85 86 87 88 89
    else if ( subcmd == "list" )
    {
      if ( onpe0 )
        s->constraints.list_constraints(cout);
    }
    else
    {
      if ( onpe0 )
        cout << help_msg();
    }
90

91 92 93 94
    return 0;
  }
};
#endif