GlobalMasterMisc.C

Go to the documentation of this file.
00001 
00007 /*
00008    Forwards atoms to master node for force evaluation.
00009 */
00010 
00011 #include "InfoStream.h"
00012 #include "NamdTypes.h"
00013 #include "GlobalMaster.h"
00014 #include "GlobalMasterMisc.h"
00015 
00016 //#define DEBUGM
00017 #define MIN_DEBUG_LEVEL 1
00018 #include "Debug.h"
00019 
00020 GlobalMasterMisc::GlobalMasterMisc() : GlobalMasterEasy("miscForcesScript") {
00021   // Initialize subclass
00022   easy_init(config);
00023   delete[] config;
00024 }
00025 
00026 GlobalMasterMisc::~GlobalMasterMisc() {
00027   ;
00028 }
00029 
00030 /* you may use the following in easy_init or easy_calc
00031   int getAtomID(const char *segid, int resid, const char *aname); // zero-based
00032   int getNumAtoms(const char* segid, int resid); // 0 on error
00033   int getAtomID(const char *segid, int resid, int index);
00034   double getMass(int atomid); // -1.0 on error
00035 */
00036 
00037 /* you may use the following only in easy_init()
00038   int requestAtom(int atomid); // 0 on success, -1 on error
00039 */
00040 
00041 void GlobalMasterMisc::easy_init(const char *config) {
00042   iout << iINFO << "  MISC FORCES CONFIG\n";
00043   iout << iINFO << "**********************\n";
00044   iout << config;
00045   iout << iINFO << "**********************\n" << endi;
00046 
00047   requestAtom(0);
00048 
00049   firstTime = true;
00050 }
00051 
00052 /* you may use the following only in easy_calc()
00053   int getPosition(int atomid, Position &position); // 0 on success, -1 on error
00054   int addForce(int atomid, Force force); // 0 on success, -1 on error
00055   void addEnergy(BigReal);
00056 */
00057 
00058 /* EXAMPEL: harmonically restrain atom 0 to its original position */
00059 
00060 void GlobalMasterMisc::easy_calc() {
00061   if(firstTime) {
00062     if(getPosition(0,originalPosition)) {
00063       NAMD_die("Couldn't get initial position.");
00064     }
00065     iout << iINFO << "Initial pos: " << originalPosition << "\n" << endi;
00066     firstTime = false;
00067   }
00068 
00069   Vector myp;
00070   BigReal k = 100.0;
00071   if(getPosition(0,myp)) {
00072     NAMD_die("Couldn't get position.");
00073   }
00074   iout << iINFO << "Atom 0 is at " << myp << "\n" << endi;
00075   addForce(0,-k * (myp-originalPosition));
00076   iout<<iINFO << "Adding force " << -k*(myp-originalPosition) << "\n" << endi;
00077   addEnergy(0.5 * k * (myp-originalPosition).length2());
00078 }
00079 

Generated on Thu Sep 21 01:17:12 2017 for NAMD by  doxygen 1.4.7