1 //////////////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (c) 2008 The Regents of the University of California 4 // 5 // This file is part of Qbox 6 // 7 // Qbox is distributed under the terms of the GNU General Public License 8 // as published by the Free Software Foundation, either version 2 of 9 // the License, or (at your option) any later version. 10 // See the file COPYING in the root directory of this distribution 11 // or <http://www.gnu.org/licenses/>. 12 // 13 //////////////////////////////////////////////////////////////////////////////// 14 // 15 // ConstraintCmd.h: 16 // 17 //////////////////////////////////////////////////////////////////////////////// 18 19 #ifndef CONSTRAINTCMD_H 20 #define CONSTRAINTCMD_H 21 22 #include "UserInterface.h" 23 #include "Sample.h" 24 25 class ConstraintCmd : public Cmd 26 { 27 public: 28 29 Sample *s; 30 ConstraintCmd(Sample * sample)31 ConstraintCmd(Sample *sample) : s(sample) {}; 32 name(void)33 const char *name(void) const { return "constraint"; } help_msg(void)34 const char *help_msg(void) const 35 { 36 return 37 "\n constraint\n\n" 38 " syntax:\n\n" 39 " constraint define position name atom\n" 40 " constraint define distance name atom1 atom2 distance [velocity]\n" 41 " constraint define angle name atom1 atom2 atom3 angle [velocity]\n" 42 " constraint define torsion name atom1 atom2 atom3 atom4 angle [velocity]\n" 43 " constraint set name value [velocity]\n" 44 " constraint delete name\n" 45 " constraint list\n" 46 " constraint enforce\n\n" 47 " Constraints are enforced at each MD step if ions are allowed to move.\n" 48 " If a distance or angle is replaced by '*', the current value is used.\n" 49 " Velocity parameters are optional.\n\n"; 50 } 51 action(int argc,char ** argv)52 int action(int argc, char **argv) 53 { 54 if ( argc < 2 ) 55 { 56 if ( ui->onpe0() ) 57 cout << help_msg(); 58 return 1; 59 } 60 string subcmd(argv[1]); 61 if ( subcmd == "define" ) 62 { 63 return s->constraints.define_constraint(s->atoms,argc,argv); 64 } 65 else if ( subcmd == "set" ) 66 { 67 return s->constraints.set_constraint(argc,argv); 68 } 69 else if ( subcmd == "delete" ) 70 { 71 return s->constraints.delete_constraint(argc,argv); 72 } 73 else if ( subcmd == "enforce" ) 74 { 75 s->constraints.enforce(s->atoms); 76 // reset velocities to zero to avoid jump in temperature 77 s->atoms.reset_velocities(); 78 // Note: should catch exception here if constraints could not be enforced 79 } 80 else if ( subcmd == "list" ) 81 { 82 if ( ui->onpe0() ) 83 s->constraints.list_constraints(cout); 84 } 85 else 86 { 87 if ( ui->onpe0() ) 88 cout << help_msg(); 89 } 90 91 return 0; 92 } 93 }; 94 #endif 95