NAMD
GlobalMasterEasy.C
Go to the documentation of this file.
1 
7 /*
8  Forwards atoms to master node for force evaluation.
9 */
10 
11 #include "InfoStream.h"
12 #include "Node.h"
13 #include "PatchMap.h"
14 #include "PatchMap.inl"
15 #include "AtomMap.h"
16 
17 #include "GlobalMaster.h"
18 #include "GlobalMasterEasy.h"
19 
20 #include "PatchMgr.h"
21 #include "Molecule.h"
22 #include "ReductionMgr.h"
23 #include "ComputeMgr.h"
24 #include "ComputeMgr.decl.h"
25 #include <stdio.h>
26 
27 //#define DEBUGM
28 #define MIN_DEBUG_LEVEL 1
29 #include "Debug.h"
30 
31 
32 GlobalMasterEasy::GlobalMasterEasy(const char *the_config_name) {
33  DebugM(1,"Here\n");
34 
35  molecule = Node::Object()->molecule;
36  int len = strlen(the_config_name);
37  configName = new char[len+1];
38  strcpy(configName,the_config_name);
39 
41 
42  initialize();
43 }
44 
46  delete [] configName;
47  delete reduction;
48 }
49 
51  getAtomID(const char *segid, int resid, const char *aname)
52 {
53  return molecule->get_atom_from_name(segid,resid,aname);
54 }
55 
57  getNumAtoms(const char* segid, int resid) // 0 on error
58 {
59  return molecule->get_residue_size(segid,resid);
60 }
61 
63  getAtomID(const char *segid, int resid, int index)
64 {
65  return molecule->get_atom_from_index_in_residue(segid,resid,index);
66 }
67 
68 double GlobalMasterEasy::getMass(int atomid)
69 {
70  if ( atomid < 0 || atomid >= molecule->numAtoms ) return -1.; // failure
71  return molecule->atommass(atomid);
72 }
73 
74 
76 {
77  if ( atomid < 0 || atomid >= molecule->numAtoms ) return -1; // failure
78  modifyRequestedAtoms().add(atomid);
79  return 0; // success
80 }
81 
82 int GlobalMasterEasy::getPosition(int atomid, Position &position)
83 {
87  for ( ; a_i != a_e; ++a_i, ++p_i ) {
88  if ( *a_i == atomid ) {
89  position = *p_i;
90  return 0; // success
91  }
92  }
93  return -1; // failure
94 }
95 
96 int GlobalMasterEasy::addForce(int atomid, Force force)
97 {
98  if ( atomid < 0 || atomid >= molecule->numAtoms ) return -1; // failure
99  modifyForcedAtoms().add(atomid);
100  modifyAppliedForces().add(force);
101  return 0; // success
102 }
103 
105  energy += e;
106 }
107 
108 void GlobalMasterEasy::initialize() {
109  DebugM(1,"Here\n");
110  DebugM(4,"Initializing master\n");
111 
112  // Get the script for subclasses
113  StringList *script = Node::Object()->configList->find(configName);
114 
115  config = new char[1];
116  config[0] = '\0';
117 
118  for ( ; script; script = script->next) {
119  if ( strstr(script->data,"\n") ) {
120  size_t add_len = strlen(script->data);
121  size_t config_len = 0;
122  config_len = strlen(config);
123  char *new_config = new char[config_len + add_len + 2];
124  strcpy(new_config,config);
125  strcat(new_config,script->data);
126  strcat(new_config,"\n"); // just to be safe
127  delete [] config;
128  config = new_config;
129  } else {
130  FILE *infile = fopen(script->data,"r");
131  if ( ! infile ) {
132  char errmsg[256];
133  sprintf(errmsg,"Error trying to read file %s!\n",script->data);
134  NAMD_die(errmsg);
135  }
136  fseek(infile,0,SEEK_END);
137  size_t add_len = ftell(infile);
138  size_t config_len = 0;
139  config_len = strlen(config);
140  char *new_config = new char[config_len + add_len + 3];
141  strcpy(new_config,config);
142  delete [] config;
143  config = new_config;
144  new_config += config_len;
145  rewind(infile);
146  fread(new_config,sizeof(char),add_len,infile);
147  new_config += add_len;
148  new_config[0] = '\n';
149  new_config[1] = '\0';
150  fclose(infile);
151  }
152  }
153 
154 }
155 
156 void GlobalMasterEasy::calculate() {
157  DebugM(1,"Here\n");
158 
159  /* zero out the forces */
162 
163  /* XXX is this necessary? */
165  modifyGroupForces().setall(Vector(0,0,0));
166  energy = 0.0;
167 
168  // Build results here
169  easy_calc();
170 
171  reduction->item(REDUCTION_MISC_ENERGY) += energy;
172  reduction->submit();
173 }
174 
175 void GlobalMasterEasy::easy_init(const char *) {
176  CkPrintf("Default GlobalMasterEasy::easy_init() called.\n");
177 }
178 
180  CkPrintf("Default GlobalMasterEasy::easy_calc() called.\n");
181 }
static Node * Object()
Definition: Node.h:86
int get_atom_from_name(const char *segid, int resid, const char *aname) const
Definition: Molecule.C:121
int get_residue_size(const char *segid, int resid) const
Definition: Molecule.C:144
virtual ~GlobalMasterEasy()
ForceList & modifyAppliedForces()
Definition: GlobalMaster.C:162
AtomIDList & modifyRequestedAtoms()
Definition: GlobalMaster.C:127
int getPosition(int atomid, Position &position)
double getMass(int atomid)
const Elem * const_iterator
Definition: ResizeArray.h:38
AtomIDList::const_iterator getAtomIdBegin()
Definition: GlobalMaster.C:190
Definition: Vector.h:64
int getAtomID(const char *segid, int resid, const char *aname)
int addForce(int atomid, Force force)
BigReal & item(int i)
Definition: ReductionMgr.h:312
#define DebugM(x, y)
Definition: Debug.h:59
int get_atom_from_index_in_residue(const char *segid, int resid, int index) const
Definition: Molecule.C:158
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
PositionList::const_iterator getAtomPositionBegin()
Definition: GlobalMaster.C:198
BigRealList::const_iterator getGroupMassEnd()
Definition: GlobalMaster.C:239
GlobalMasterEasy(const char *the_config_name)
int getNumAtoms(const char *segid, int resid)
int requestAtom(int atomid)
void setall(const Elem &elem)
Definition: ResizeArray.h:90
void addEnergy(BigReal)
AtomIDList & modifyForcedAtoms()
Definition: GlobalMaster.C:157
int numAtoms
Definition: Molecule.h:556
void NAMD_die(const char *err_msg)
Definition: common.C:83
BigRealList::const_iterator getGroupMassBegin()
Definition: GlobalMaster.C:234
ForceList & modifyGroupForces()
Definition: GlobalMaster.C:167
ConfigList * configList
Definition: Node.h:179
virtual void easy_init(const char *)
int add(const Elem &elem)
Definition: ResizeArray.h:97
StringList * next
Definition: ConfigList.h:49
void resize(int i)
Definition: ResizeArray.h:84
AtomIDList::const_iterator getAtomIdEnd()
Definition: GlobalMaster.C:194
char * data
Definition: ConfigList.h:48
StringList * find(const char *name) const
Definition: ConfigList.C:341
virtual void easy_calc(void)
Real atommass(int anum) const
Definition: Molecule.h:1038
void submit(void)
Definition: ReductionMgr.h:323
Molecule * molecule
Definition: Node.h:176
double BigReal
Definition: common.h:114