NAMD
Public Member Functions | List of all members
GroupRestraintParam Class Reference

#include <GroupRestraintsParam.h>

Public Member Functions

 GroupRestraintParam (void)
 
 ~GroupRestraintParam (void)
 
void SetGroup1AtomFileIndices (const char *fileName)
 
void SetGroup1AtomListIndices (const char *list)
 
void SetGroup1RefPosition (const char *vec)
 
void SetGroup2AtomFileIndices (const char *fileName)
 
void SetGroup2AtomListIndices (const char *list)
 
void SetGroupName (const char *name)
 
void SetForce (const BigReal force)
 
void SetExponent (const int exponent)
 
void SetResCenter (const char *vec)
 
void SetResDirection (const char *status, const int component)
 
void SetUseDistMagnitude (const char *status)
 
void CheckParam (void)
 
void PrintSummary ()
 
const char * GetGroupName () const
 
int GetExponent () const
 
double GetForce () const
 
Vector GetGroupRes1Position () const
 
Vector GetResDirection () const
 
Vector GetResCenter () const
 
const std::vector< int > & GetGroup1AtomIndex () const
 
const std::vector< int > & GetGroup2AtomIndex () const
 
bool GetUseDistMagnitude () const
 

Detailed Description

Group restraint parameter class. Stores parameters required for harmonic restraints. Make sure that all necessary parameters are provided. Read atom indicies from file. Print summary of parameters.

Definition at line 18 of file GroupRestraintsParam.h.

Constructor & Destructor Documentation

◆ GroupRestraintParam()

GroupRestraintParam::GroupRestraintParam ( void  )

< Default restraint exponent is 2




< Default force



< Default reference COM position for group 1


< Default restraint in X,Y, and Z direction

< Default center of restraint
< Default is to use vector distance, not magnitude

Definition at line 5 of file GroupRestraintsParam.C.

5  {
6  groupNameDefined = false;
7  restraintForceDefined = false;
8  group1RefPositionDefined = false;
9  restraintCenterDefined = false;
10  groupName = NULL;
11  group1Idx.clear();
12  group2Idx.clear();
13  restraintExp = 2;
14  restraintForce = 0.0;
15  group1RefPosition = 0.0;
16  restraintDir = 1.0;
17  restraintCenter = 0.0;
18  useDistanceMagnitude = false;
19 }

◆ ~GroupRestraintParam()

GroupRestraintParam::~GroupRestraintParam ( void  )

Definition at line 21 of file GroupRestraintsParam.C.

21  {
22  if (groupName) delete [] groupName;
23 }

Member Function Documentation

◆ CheckParam()

void GroupRestraintParam::CheckParam ( void  )

Check all necessary parameters in group restraint are set

Check all necessary parameters are set

Definition at line 275 of file GroupRestraintsParam.C.

References Vector::length2(), and NAMD_die().

275  {
276  char err_msg[512];
277 
278  if (!groupNameDefined) {
279  sprintf(err_msg, "Group restraints: Key or tag name is not defined!\n");
280  NAMD_die(err_msg);
281  }
282 
283  if (!restraintForceDefined) {
284  sprintf(err_msg, "Group restraints: Restraint Force constant is not defined for %s!\n", groupName);
285  NAMD_die(err_msg);
286  }
287 
288  if (!restraintCenterDefined) {
289  sprintf(err_msg, "Group restraints: Restraint center is not defined for %s!\n", groupName);
290  NAMD_die(err_msg);
291  }
292 
293  if (!(restraintExp > 0)) {
294  sprintf(err_msg, "Group restraints: Restraint exponent must be positive value for %s!\n", groupName);
295  NAMD_die(err_msg);
296  }
297 
298  if (restraintExp % 2) {
299  sprintf(err_msg, "Group restraints: Restraint exponent must be an even number for %s!\n", groupName);
300  NAMD_die(err_msg);
301  }
302 
303  if (!(restraintForce > 0)) {
304  sprintf(err_msg, "Group restraints: Restraint Force constant must be positive value for %s!\n", groupName);
305  NAMD_die(err_msg);
306  }
307 
308  if (!group1RefPositionDefined && !group1Idx.size()) {
309  sprintf(err_msg, "Group restraints: Either reference COM position or atom indices for group 1 must be defined for %s!\n", groupName);
310  NAMD_die(err_msg);
311  }
312 
313  if (group1RefPositionDefined && group1Idx.size()) {
314  sprintf(err_msg, "Group restraints: Reference COM position and atom indices for group 1 cannot be defined together for %s!\n", groupName);
315  NAMD_die(err_msg);
316  }
317 
318  if (!(group2Idx.size())) {
319  sprintf(err_msg, "Group restraints: No atom is defined for group 2 to be restrained for %s!\n", groupName);
320  NAMD_die(err_msg);
321  }
322 
323  if (!(restraintDir.length2())) {
324  sprintf(err_msg, "Group restraints: At least one component of restraint distance "
325  "must be selected for %s!\n", groupName);
326  NAMD_die(err_msg);
327  }
328 }
NAMD_HOST_DEVICE BigReal length2(void) const
Definition: Vector.h:206
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ GetExponent()

int GroupRestraintParam::GetExponent ( ) const
inline

Get the restraint exponent

Definition at line 68 of file GroupRestraintsParam.h.

68 {return restraintExp;}

◆ GetForce()

double GroupRestraintParam::GetForce ( ) const
inline

Get the restraint force constant

Definition at line 71 of file GroupRestraintsParam.h.

71 {return restraintForce;}

◆ GetGroup1AtomIndex()

const std::vector<int>& GroupRestraintParam::GetGroup1AtomIndex ( ) const
inline

Get reference to restrained atom indicies in group 1

Definition at line 83 of file GroupRestraintsParam.h.

83 {return group1Idx;}

◆ GetGroup2AtomIndex()

const std::vector<int>& GroupRestraintParam::GetGroup2AtomIndex ( ) const
inline

Get reference to restrained atom indicies in group 2

Definition at line 86 of file GroupRestraintsParam.h.

86 {return group2Idx;}

◆ GetGroupName()

const char* GroupRestraintParam::GetGroupName ( ) const
inline

Get restraint group name

Definition at line 65 of file GroupRestraintsParam.h.

65 {return groupName;}

◆ GetGroupRes1Position()

Vector GroupRestraintParam::GetGroupRes1Position ( ) const
inline

Get the reference COM position for group 1

Definition at line 74 of file GroupRestraintsParam.h.

74 {return group1RefPosition;}

◆ GetResCenter()

Vector GroupRestraintParam::GetResCenter ( ) const
inline

Get the center of restraint

Definition at line 80 of file GroupRestraintsParam.h.

80 {return restraintCenter;}

◆ GetResDirection()

Vector GroupRestraintParam::GetResDirection ( ) const
inline

Get restraint vector component (X, Y, Z)

Definition at line 77 of file GroupRestraintsParam.h.

77 {return restraintDir;}

◆ GetUseDistMagnitude()

bool GroupRestraintParam::GetUseDistMagnitude ( ) const
inline

Definition at line 89 of file GroupRestraintsParam.h.

89 {return useDistanceMagnitude;}

◆ PrintSummary()

void GroupRestraintParam::PrintSummary ( )

Print summary of parameters in group restraint

Definition at line 331 of file GroupRestraintsParam.C.

References endi(), iINFO(), iout, Vector::length(), Vector::x, Vector::y, and Vector::z.

331  {
332  iout << iINFO << "GROUP RESTRAINT KEY " << groupName << "\n" << endi;
333  if (useDistanceMagnitude) {
334  iout << iINFO << " RESTRAINT DISTANCE MAGNITUDE " << "ACTIVE\n" << endi;
335  iout << iINFO << " RESTRAINT CENTER " << restraintCenter.length() << "\n" << endi;
336  } else {
337  iout << iINFO << " RESTRAINT DISTANCE VECTOR " << "ACTIVE\n" << endi;
338  iout << iINFO << " RESTRAINT CENTER " << restraintCenter << "\n" << endi;
339  }
340  iout << iINFO << " RESTRAINT FORCE " << restraintForce << "\n" << endi;
341  iout << iINFO << " RESTRAINT EXPONENT " << restraintExp << "\n" << endi;
342  iout << iINFO << " RESTRAINT COMPONENT X " << (restraintDir.x ? "YES" : "NO") << "\n" << endi;
343  iout << iINFO << " RESTRAINT COMPONENT Y " << (restraintDir.y ? "YES" : "NO") << "\n" << endi;
344  iout << iINFO << " RESTRAINT COMPONENT Z " << (restraintDir.z ? "YES" : "NO") << "\n" << endi;
345  iout << iINFO << " RESTRAINED ATOMS IN GROUP 2 " << group2Idx.size() << "\n" << endi;
346  if (group1RefPositionDefined) {
347  iout << iINFO << " COM REF. POSITION IN GROUP 1 " << group1RefPosition << "\n" << endi;
348  } else {
349  iout << iINFO << " RESTRAINED ATOMS IN GROUP 1 " << group1Idx.size() << "\n" << endi;
350  }
351 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
#define iout
Definition: InfoStream.h:51
NAMD_HOST_DEVICE BigReal length(void) const
Definition: Vector.h:202
BigReal x
Definition: Vector.h:74
BigReal y
Definition: Vector.h:74

◆ SetExponent()

void GroupRestraintParam::SetExponent ( const int  exponent)

Set the restraint exponent

Definition at line 207 of file GroupRestraintsParam.C.

Referenced by GroupRestraintList::SetExponent().

207  {
208  restraintExp = exponent;
209 }

◆ SetForce()

void GroupRestraintParam::SetForce ( const BigReal  force)

Set the restraint force constant

Definition at line 195 of file GroupRestraintsParam.C.

References endi(), iout, and iWARN().

Referenced by GroupRestraintList::SetForce().

195  {
196  char err_msg[512]; // Buffer for error message
197  if (restraintForceDefined) {
198  sprintf(err_msg, "Group restraints: Redefining restraint force for %s!\n",
199  groupName);
200  iout << iWARN << err_msg << "\n" << endi;
201  }
202  restraintForce = force;
203  restraintForceDefined = true;
204 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51

◆ SetGroup1AtomFileIndices()

void GroupRestraintParam::SetGroup1AtomFileIndices ( const char *  fileName)

Read the restrained atom indicies for group 1 from file and store it

Read the restrained atom indices for group 1 from file and store it

Definition at line 26 of file GroupRestraintsParam.C.

References endi(), iINFO(), iout, iWARN(), NAMD_blank_string(), NAMD_die(), and NAMD_read_line().

Referenced by GroupRestraintList::SetGroup1AtomFileIndices().

26  {
27  char err_msg[512]; // Buffer for error message
28  char buffer[512]; // Buffer for file reading
29 
30  if(group1Idx.size()) {
31  group1Idx.clear();
32  sprintf(err_msg, "Group restraints: Redefining existing group 1 indices for %s!\n",
33  groupName);
34  iout << iWARN << err_msg << "\n" << endi;
35  }
36 
37  if (! fileName) {
38  sprintf(err_msg, "Group restraints: No group 1 restraint file is defined for '%s'!\n", groupName);
39  NAMD_die(err_msg);
40  }
41 
42  FILE *file = fopen(fileName, "r");
43  if (!file) {
44  sprintf(err_msg, "Group restraints: Unable to open group 1 restraint file '%s'!\n", fileName);
45  NAMD_die(err_msg);
46  } else {
47  iout << iINFO << "Reading group 1 restraint file " << fileName << " for group " <<
48  groupName << "\n" << endi;
49  }
50 
51  while (true) {
52  int index;
53  int badLine = 0;
54  int return_code = 0;
55  do {
56  return_code = NAMD_read_line(file, buffer, 512);
57  } while ( (return_code == 0) && (NAMD_blank_string(buffer)) );
58 
59  if (return_code) {
60  break;
61  }
62  if (sscanf(buffer, "%d", &index) != 1) {
63  sprintf(err_msg, "Group restraints: Bad line in group 1 restraint file '%s': %s!\n", fileName, buffer);
64  NAMD_die(err_msg);
65  } else {
66  group1Idx.push_back(index);
67  }
68  }
69  fclose(file);
70 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int NAMD_read_line(FILE *fd, char *buf, int bufsize)
Definition: strlib.C:38
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
int NAMD_blank_string(char *str)
Definition: strlib.C:222
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ SetGroup1AtomListIndices()

void GroupRestraintParam::SetGroup1AtomListIndices ( const char *  list)

Set the restrained atom indicies for group 1 from a list

Set the restrained atom indices for group 1 from a list

Definition at line 120 of file GroupRestraintsParam.C.

References endi(), iout, iWARN(), and NAMD_die().

Referenced by GroupRestraintList::SetGroup1AtomListIndices().

120  {
121  char err_msg[512]; // Buffer for error message
122  int index, numRead;
123  int i = 0;
124 
125  if(group1Idx.size()) {
126  group1Idx.clear();
127  sprintf(err_msg, "Group restraints: Redefining existing group 1 restraint indices for %s!\n",
128  groupName);
129  iout << iWARN << err_msg << "\n" << endi;
130  }
131 
132  // Get the length of string
133  int strLength = strlen(list);
134  // Read the index and advance the number of read char
135  // until we reach to the end of it
136  while (i < strLength) {
137  if(sscanf(list,"%d%n", &index, &numRead) != 1) {
138  sprintf(err_msg, "Group restraints: Bad line in group 1 restraint list for '%s': %s!\n",
139  groupName, list);
140  NAMD_die(err_msg);
141  } else {
142  list += numRead + 1;
143  i += numRead + 1;
144  group1Idx.push_back(index);
145  }
146  }
147 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ SetGroup1RefPosition()

void GroupRestraintParam::SetGroup1RefPosition ( const char *  vec)

Set the reference COM position for group 1

Definition at line 212 of file GroupRestraintsParam.C.

References endi(), iout, iWARN(), NAMD_die(), and Vector::set().

Referenced by GroupRestraintList::SetGroup1RefPosition().

212  {
213  char err_msg[512]; // Buffer for error message
214  if (group1RefPositionDefined) {
215  sprintf(err_msg, "Group restraints: Redefining group 1 reference COM position for %s!\n",
216  groupName);
217  iout << iWARN << err_msg << "\n" << endi;
218  }
219 
220  if(group1RefPosition.set(vec)) {
221  group1RefPositionDefined = true;
222  } else {
223  sprintf(err_msg, "Group restraints: Bad reference COM position for %s: { %s }. %s\n",
224  groupName, vec, "Expect a {x y z} vector.");
225  NAMD_die(err_msg);
226  }
227 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
void NAMD_die(const char *err_msg)
Definition: common.C:147
Bool set(const char *s)
Definition: Vector.h:261

◆ SetGroup2AtomFileIndices()

void GroupRestraintParam::SetGroup2AtomFileIndices ( const char *  fileName)

Read the restained atom indicies for group 2 from file and store it

Read the restrained atom indices for group 2 from file and store it

Definition at line 73 of file GroupRestraintsParam.C.

References endi(), iINFO(), iout, iWARN(), NAMD_blank_string(), NAMD_die(), and NAMD_read_line().

Referenced by GroupRestraintList::SetGroup2AtomFileIndices().

73  {
74  char err_msg[512]; // Buffer for error message
75  char buffer[512]; // Buffer for file reading
76 
77  if(group2Idx.size()) {
78  group2Idx.clear();
79  sprintf(err_msg, "Group restraints: Redefining existing group 2 indices for %s!\n",
80  groupName);
81  iout << iWARN << err_msg << "\n" << endi;
82  }
83 
84  if (! fileName) {
85  sprintf(err_msg, "Group restraints: No group 2 restraint file is defined for '%s'!\n", groupName);
86  NAMD_die(err_msg);
87  }
88 
89  FILE *file = fopen(fileName, "r");
90  if (!file) {
91  sprintf(err_msg, "Group restraints: Unable to open group 2 restraint file '%s'!\n", fileName);
92  NAMD_die(err_msg);
93  } else {
94  iout << iINFO << "Reading group 2 restraint file " << fileName << " for group " <<
95  groupName << "\n" << endi;
96  }
97 
98  while (true) {
99  int index;
100  int badLine = 0;
101  int return_code = 0;
102  do {
103  return_code = NAMD_read_line(file, buffer, 512);
104  } while ( (return_code == 0) && (NAMD_blank_string(buffer)) );
105 
106  if (return_code) {
107  break;
108  }
109  if (sscanf(buffer, "%d", &index) != 1) {
110  sprintf(err_msg, "Group restraints: Bad line in group 2 restraint file '%s': %s!\n", fileName, buffer);
111  NAMD_die(err_msg);
112  } else {
113  group2Idx.push_back(index);
114  }
115  }
116  fclose(file);
117 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int NAMD_read_line(FILE *fd, char *buf, int bufsize)
Definition: strlib.C:38
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
int NAMD_blank_string(char *str)
Definition: strlib.C:222
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ SetGroup2AtomListIndices()

void GroupRestraintParam::SetGroup2AtomListIndices ( const char *  list)

Set the restrained atom indicies for group 2 from a list

Set the restrained atom indices for group 2 from a list

Definition at line 150 of file GroupRestraintsParam.C.

References endi(), iout, iWARN(), and NAMD_die().

Referenced by GroupRestraintList::SetGroup2AtomListIndices().

150  {
151  char err_msg[512]; // Buffer for error message
152  int index, numRead;
153  int i = 0;
154 
155  if(group2Idx.size()) {
156  group2Idx.clear();
157  sprintf(err_msg, "Group restraints: Redefining existing group 2 restraint indices for %s!\n",
158  groupName);
159  iout << iWARN << err_msg << "\n" << endi;
160  }
161 
162  // Get the length of string
163  int strLength = strlen(list);
164  // Read the index and advance the number of read char
165  // until we reach to the end of it
166  while (i < strLength) {
167  if(sscanf(list,"%d%n", &index, &numRead) != 1) {
168  sprintf(err_msg, "Group restraints: Bad line in group 2 restraint list for '%s': %s!\n",
169  groupName, list);
170  NAMD_die(err_msg);
171  } else {
172  list += numRead + 1;
173  i += numRead + 1;
174  group2Idx.push_back(index);
175  }
176  }
177 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ SetGroupName()

void GroupRestraintParam::SetGroupName ( const char *  name)

Set restraint group name

Definition at line 180 of file GroupRestraintsParam.C.

References NAMD_die().

180  {
181  char err_msg[512]; // Buffer for error message
182  if (groupName) {
183  sprintf(err_msg, "Group restraints: Redefining existing group restraint name from %s to %s!\n",
184  groupName, name);
185  NAMD_die(err_msg);
186  } else {
187  groupNameDefined = true;
188  int nameLength = strlen(name);
189  groupName = new char[nameLength + 1];
190  strncpy(groupName, name, nameLength + 1);
191  }
192 }
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ SetResCenter()

void GroupRestraintParam::SetResCenter ( const char *  vec)

Set the center of equilibrium value of restraint

Set the center or equilibrium value of restraint

Definition at line 230 of file GroupRestraintsParam.C.

References endi(), iout, iWARN(), NAMD_die(), and Vector::set().

Referenced by GroupRestraintList::SetResCenter().

230  {
231  char err_msg[512]; // Buffer for error message
232  if (restraintCenterDefined) {
233  sprintf(err_msg, "Group restraints: Redefining restraint center for %s!\n",
234  groupName);
235  iout << iWARN << err_msg << "\n" << endi;
236  }
237 
238  if(restraintCenter.set(vec)) {
239  restraintCenterDefined = true;
240  } else {
241  sprintf(err_msg, "Group restraints: Bad restraint center value for %s: { %s }. %s\n",
242  groupName, vec, "Expect a {x y z} vector.");
243  NAMD_die(err_msg);
244  }
245 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
void NAMD_die(const char *err_msg)
Definition: common.C:147
Bool set(const char *s)
Definition: Vector.h:261

◆ SetResDirection()

void GroupRestraintParam::SetResDirection ( const char *  status,
const int  component 
)

Set restraint vector component (X, Y, Z)

Definition at line 248 of file GroupRestraintsParam.C.

References NAMD_die(), Vector::x, Vector::y, and Vector::z.

Referenced by GroupRestraintList::SetResDirectionX(), GroupRestraintList::SetResDirectionY(), and GroupRestraintList::SetResDirectionZ().

248  {
249  // Only modify the resDir if we turn off the specific component
250  // because the default behaviour is that we apply restraint in
251  // all direction
252  BigReal value = this->CheckStatus<BigReal>(status);
253 
254  switch (component) {
255  case 0 :
256  restraintDir.x = value;
257  break;
258  case 1 :
259  restraintDir.y = value;
260  break;
261  case 2 :
262  restraintDir.z = value;
263  break;
264  default :
265  NAMD_die("Group restraints: Unknown vector component in SetResDirection function! \n");
266  }
267 }
BigReal z
Definition: Vector.h:74
BigReal x
Definition: Vector.h:74
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal y
Definition: Vector.h:74
double BigReal
Definition: common.h:123

◆ SetUseDistMagnitude()

void GroupRestraintParam::SetUseDistMagnitude ( const char *  status)

Set restraint distance mode (magnitude or vector)

Definition at line 270 of file GroupRestraintsParam.C.

Referenced by GroupRestraintList::SetUseDistMagnitude().

270  {
271  useDistanceMagnitude = this->CheckStatus<bool>(status);
272 }

The documentation for this class was generated from the following files: