6     groupNameDefined = 
false;
     7     restraintForceDefined = 
false;
     8     group1RefPositionDefined = 
false;
     9     restraintCenterDefined = 
false;
    15     group1RefPosition = 0.0;   
    17     restraintCenter = 0.0;     
    18     useDistanceMagnitude = 
false; 
    22     if (groupName) 
delete [] groupName;
    30     if(group1Idx.size()) {
    32         sprintf(err_msg, 
"Group restraints: Redefining existing group 1 indices for %s!\n",
    38         sprintf(err_msg, 
"Group restraints: No group 1 restraint file is defined for '%s'!\n", groupName);
    42     FILE *file = fopen(fileName, 
"r");
    44         sprintf(err_msg, 
"Group restraints: Unable to open group 1 restraint file '%s'!\n", fileName);
    47         iout << 
iINFO << 
"Reading group 1 restraint file " << fileName << 
" for group " <<
    48                 groupName << 
"\n" << 
endi; 
    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);
    66             group1Idx.push_back(index);
    77     if(group2Idx.size()) {
    79         sprintf(err_msg, 
"Group restraints: Redefining existing group 2 indices for %s!\n",
    85         sprintf(err_msg, 
"Group restraints: No group 2 restraint file is defined for '%s'!\n", groupName);
    89     FILE *file = fopen(fileName, 
"r");
    91         sprintf(err_msg, 
"Group restraints: Unable to open group 2 restraint file '%s'!\n", fileName);
    94         iout << 
iINFO << 
"Reading group 2 restraint file " << fileName << 
" for group " <<
    95                 groupName << 
"\n" << 
endi; 
   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);
   113             group2Idx.push_back(index);
   125     if(group1Idx.size()) {
   127         sprintf(err_msg, 
"Group restraints: Redefining existing group 1 restraint indices for %s!\n",
   133     int strLength = strlen(list);
   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",
   144             group1Idx.push_back(index);
   155     if(group2Idx.size()) {
   157         sprintf(err_msg, 
"Group restraints: Redefining existing group 2 restraint indices for %s!\n",
   163     int strLength = strlen(list);
   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",
   174             group2Idx.push_back(index);
   183         sprintf(err_msg, 
"Group restraints: Redefining existing group restraint name from %s to %s!\n",
   187         groupNameDefined = 
true;
   188         int nameLength = strlen(name);
   189         groupName = 
new char[nameLength + 1];
   190         strncpy(groupName, name, nameLength + 1);
   197     if (restraintForceDefined) {
   198         sprintf(err_msg, 
"Group restraints: Redefining restraint force for %s!\n",
   202     restraintForce = force; 
   203     restraintForceDefined = 
true;
   208     restraintExp = exponent; 
   214     if (group1RefPositionDefined) {
   215         sprintf(err_msg, 
"Group restraints: Redefining group 1 reference COM position for %s!\n",
   220     if(group1RefPosition.
set(vec)) {
   221         group1RefPositionDefined = 
true; 
   223         sprintf(err_msg, 
"Group restraints: Bad reference COM position for %s: { %s }. %s\n",
   224             groupName, vec, 
"Expect a {x y z} vector.");
   232     if (restraintCenterDefined) {
   233         sprintf(err_msg, 
"Group restraints: Redefining restraint center for %s!\n",
   238     if(restraintCenter.
set(vec)) {
   239         restraintCenterDefined = 
true; 
   241         sprintf(err_msg, 
"Group restraints: Bad restraint center value for %s: { %s }. %s\n",
   242             groupName, vec, 
"Expect a {x y z} vector.");
   252     BigReal value = this->CheckStatus<BigReal>(status);
   256             restraintDir.
x = value;
   259             restraintDir.
y = value;
   262             restraintDir.
z = value;
   265             NAMD_die(
"Group restraints: Unknown vector component in SetResDirection function! \n");
   271     useDistanceMagnitude = this->CheckStatus<bool>(status); 
   278     if (!groupNameDefined) {
   279         sprintf(err_msg, 
"Group restraints: Key or tag name is not defined!\n");
   283     if (!restraintForceDefined) {
   284         sprintf(err_msg, 
"Group restraints: Restraint Force constant is not defined for %s!\n", groupName);
   288     if (!restraintCenterDefined) {
   289         sprintf(err_msg, 
"Group restraints: Restraint center is not defined for %s!\n", groupName);
   293     if (!(restraintExp > 0)) {
   294         sprintf(err_msg, 
"Group restraints: Restraint exponent must be positive value for %s!\n", groupName);
   298     if (restraintExp % 2) {
   299         sprintf(err_msg, 
"Group restraints: Restraint exponent must be an even number for %s!\n", groupName);
   303     if (!(restraintForce > 0)) {
   304         sprintf(err_msg, 
"Group restraints: Restraint Force constant must be positive value for %s!\n", groupName);
   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);
   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);
   318     if (!(group2Idx.size())) {
   319         sprintf(err_msg, 
"Group restraints: No atom is defined for group 2 to be restrained for %s!\n", groupName);
   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);
   332     iout << 
iINFO << 
"GROUP RESTRAINT KEY                  " << groupName << 
"\n" << 
endi;
   333     if (useDistanceMagnitude) {
   334         iout << 
iINFO << 
"       RESTRAINT DISTANCE MAGNITUDE  " << 
"ACTIVE\n" << 
endi;
   337         iout << 
iINFO << 
"       RESTRAINT DISTANCE VECTOR     " << 
"ACTIVE\n" << 
endi;
   338         iout << 
iINFO << 
"       RESTRAINT CENTER              " << restraintCenter << 
"\n" << 
endi;
   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;
   349         iout << 
iINFO << 
"       RESTRAINED ATOMS IN GROUP 1   " << group1Idx.size() << 
"\n" << 
endi;
   354 template<
typename Type>
   355 Type GroupRestraintParam::CheckStatus(
const char *status)
 const {
   356     Type state = 
static_cast<Type
>(1);
   357     if (0 == strcasecmp(status, 
"no") || 
   358         0 == strcasecmp(status, 
"off") || 
   359         0 == strcasecmp(status, 
"false")) {
   360         state = 
static_cast<Type
>(0);
   361     } 
else if (0 == strcasecmp(status, 
"yes") || 
   362         0 == strcasecmp(status, 
"on") || 
   363         0 == strcasecmp(status, 
"true")) {
   364         state = 
static_cast<Type
>(1);
   367         sprintf(err_msg, 
"Group restraints: Unknown status keyword '%s'!"    368             " Options are: no, off, false, yes, on, true.\n", status);
   379     for (
auto it = groupRestraints.begin(); it != groupRestraints.end(); ++it) {
   458     for (
auto it = groupRestraints.begin(); it != groupRestraints.end(); ++it) {
   459         it->second->CheckParam();
   465     for (
auto it = groupRestraints.begin(); it != groupRestraints.end(); ++it) {
   466         it->second->PrintSummary();
   473     std::string groupName(tag);
   474     auto it = groupRestraints.find(groupName);
   475     if (it == groupRestraints.end()) {
   478         groupRestraints.insert(std::make_pair(groupName, resParam));
   479         return groupRestraints.find(groupName)->second; 
 std::ostream & iINFO(std::ostream &s)
 
void SetExponent(const int exponent)
 
~GroupRestraintParam(void)
 
void SetGroup2AtomListIndices(const char *groupTag, const char *list)
 
int NAMD_read_line(FILE *fd, char *buf, int bufsize)
 
void SetResCenter(const char *groupTag, const char *vec)
 
GroupRestraintParam(void)
 
std::ostream & endi(std::ostream &s)
 
void SetForce(const BigReal force)
 
std::ostream & iWARN(std::ostream &s)
 
void SetResDirectionY(const char *groupTag, const char *status)
 
void SetGroup1AtomFileIndices(const char *groupTag, const char *fileName)
 
void SetGroup1AtomListIndices(const char *list)
 
void SetGroup2AtomFileIndices(const char *fileName)
 
void SetResDirectionX(const char *groupTag, const char *status)
 
void SetGroup2AtomFileIndices(const char *groupTag, const char *fileName)
 
NAMD_HOST_DEVICE BigReal length(void) const
 
int NAMD_blank_string(char *str)
 
void SetResCenter(const char *vec)
 
void SetGroup2AtomListIndices(const char *list)
 
void SetResDirectionZ(const char *groupTag, const char *status)
 
void SetGroupName(const char *name)
 
NAMD_HOST_DEVICE BigReal length2(void) const
 
void SetForce(const char *groupTag, const BigReal force)
 
void NAMD_die(const char *err_msg)
 
void CheckGroupRestraints()
 
void SetGroup1RefPosition(const char *groupTag, const char *vec)
 
void PrintGroupRestraints()
 
void SetResDirection(const char *status, const int component)
 
void SetUseDistMagnitude(const char *groupTag, const char *status)
 
void SetGroup1RefPosition(const char *vec)
 
void SetGroup1AtomFileIndices(const char *fileName)
 
void SetUseDistMagnitude(const char *status)
 
void SetExponent(const char *groupTag, const int exponent)
 
void SetGroup1AtomListIndices(const char *groupTag, const char *list)