ConstraintSet.C 20.2 KB
Newer Older
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
15 16 17 18 19
// ConstraintSet.C
//
////////////////////////////////////////////////////////////////////////////////

#include "ConstraintSet.h"
20
#include "PositionConstraint.h"
21 22 23 24 25
#include "DistanceConstraint.h"
#include "AngleConstraint.h"
#include "TorsionConstraint.h"
#include "Atom.h"
#include "AtomSet.h"
26
#include <cstring>
27 28 29
#include "Context.h"
#include <iostream>
#include <iomanip>
30
#include <cstdlib> // atof
31
#include <cstring> // strcmp
32 33
using namespace std;

34
const int constraints_maxiter = 50;
35

36 37 38 39 40 41 42
////////////////////////////////////////////////////////////////////////////////
ConstraintSet::~ConstraintSet(void)
{
  for ( int ic = 0; ic < constraint_list.size(); ic++ )
    delete constraint_list[ic];
}

43
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
44
bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv)
45
{
46
  enum constraint_type { unknown, position_type, distance_type,
47 48
                         angle_type, torsion_type }
    type = unknown;
49
  const double position_tolerance = 1.0e-7;
50 51 52
  const double distance_tolerance = 1.0e-7;
  const double angle_tolerance = 1.0e-4;
  const bool onpe0 = ctxt_.onpe0();
53

Francois Gygi committed
54 55
  // argv[0] == "constraint"
  // argv[1] == "define"
56
  // argv[2] == {"position", "distance", "angle", "torsion"}
Francois Gygi committed
57 58 59 60
  // argv[3] == constraint name
  // argv[4-(5,6,7)] == atom names
  // argv[{5,6,7}] == {distance,angle,angle}
  // argv[{6,7,8}] == velocity
61 62 63 64 65

  if ( argc < 2 )
  {
    if ( onpe0 )
    {
66
      cout << " Use: constraint define position constraint_name atom_name"
67
           << endl;
68 69
      cout << " Use: constraint define distance constraint_name "
           << "atom_name1 atom_name2 distance_value [velocity]"
70
           << endl;
71 72
      cout << "      constraint define angle constraint_name "
           << "name1 name2 name3 angle_value [velocity]"
73
           << endl;
74 75
      cout << "      constraint define torsion constraint_name "
           << "name1 name2 name3 name4 angle_value"
76
           << " [velocity] "
77 78
           << endl;
    }
Francois Gygi committed
79
    return false;
80
  }
Francois Gygi committed
81
  const string constraint_type = argv[2];
82 83 84 85 86
  if ( constraint_type == "position" )
  {
    type = position_type;
  }
  else if ( constraint_type == "distance" )
87 88 89
  {
    type = distance_type;
  }
Francois Gygi committed
90
  else if ( constraint_type == "angle" )
91 92 93
  {
    type = angle_type;
  }
Francois Gygi committed
94
  else if ( constraint_type == "torsion" )
95 96 97 98 99
  {
    type = torsion_type;
  }
  else
  {
100
    if ( onpe0 )
101
      cout << " Incorrect constraint type " << constraint_type << endl;
102 103
    return false;
  }
104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
  if ( type == position_type )
  {
    // define position name A

    if ( argc != 5 )
    {
      if ( onpe0 )
        cout << " Incorrect number of arguments for position constraint"
             << endl;
      return false;
    }
    string name = argv[3];
    string name1 = argv[4];

    Atom *a1 = atoms.findAtom(name1);

    if ( a1 == 0 )
    {
      if ( onpe0 )
      {
        cout << " ConstraintSet: could not find atom " << name1 << endl;
        cout << " ConstraintSet: could not define constraint" << endl;
      }
      return false;
    }

    // check if constraint is already defined
    bool found = false;
    Constraint *pc = 0;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      pc = constraint_list[i];
      assert(pc != 0);
      // check if a constraint with same name or with same atom is defined
      if ( pc->type() == "position" )
        found = ( pc->name() == name ) || ( pc->names(0) == name1 );
    }

    if ( found )
    {
      if ( onpe0 )
        cout << " ConstraintSet: constraint is already defined:\n"
             << " cannot define constraint" << endl;
      return false;
    }
    else
    {
      PositionConstraint *c =
        new PositionConstraint(name,name1,position_tolerance);
      constraint_list.push_back(c);
    }
  }
  else if ( type == distance_type )
158
  {
159 160
    // define distance name A B value
    // define distance name A B value velocity
161

Francois Gygi committed
162
    if ( argc < 7 || argc > 8 )
163
    {
164
      if ( onpe0 )
165 166
        cout << " Incorrect number of arguments for distance constraint"
             << endl;
167 168
      return false;
    }
169
    double distance, velocity=0.0;
Francois Gygi committed
170 171 172
    string name = argv[3];
    string name1 = argv[4];
    string name2 = argv[5];
173

174 175
    Atom *a1 = atoms.findAtom(name1);
    Atom *a2 = atoms.findAtom(name2);
176

177 178
    if ( a1 == 0 || a2 == 0 )
    {
Francois Gygi committed
179 180 181
      if ( onpe0 )
      {
        if ( a1 == 0 )
182
          cout << " ConstraintSet: could not find atom " << name1 << endl;
Francois Gygi committed
183
        if ( a2 == 0 )
184 185
          cout << " ConstraintSet: could not find atom " << name2 << endl;
        cout << " ConstraintSet: could not define constraint" << endl;
Francois Gygi committed
186 187
      }
      return false;
188 189 190
    }
    if ( name1 == name2 )
    {
191
      if ( onpe0 )
192 193
        cout << " ConstraintSet: cannot define distance constraint between "
             << name1 << " and " << name2 << endl;
Francois Gygi committed
194
      return false;
195
    }
196

197 198 199 200 201 202 203 204 205 206 207 208
    // define distance value
    if ( !strcmp(argv[6],"*") )
    {
      // use current distance
      distance = length(a1->position()-a2->position());
      if ( onpe0 )
        cout << "ConstraintSet::define_constraint: using current distance "
             << distance << endl;
    }
    else
      distance = atof(argv[6]);

Francois Gygi committed
209
    if ( argc == 8 )
210
    {
Francois Gygi committed
211
      velocity = atof(argv[7]);
212
    }
213

214 215 216
    if ( distance <= 0.0 )
    {
      if ( onpe0 )
217 218
        cout << " ConstraintSet: distance must be positive" << endl
             << " ConstraintSet: could not define constraint" << endl;
Francois Gygi committed
219
      return false;
220
    }
221

Francois Gygi committed
222
    // check if constraint is already defined
223 224 225 226 227 228 229
    bool found = false;
    Constraint *pc = 0;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      pc = constraint_list[i];
      assert(pc != 0);
      // check if a constraint (name1,name2) or (name2,name1) is defined
230 231 232 233
      if ( pc->type() == "distance" )
        found = ( pc->names(0) == name1 && pc->names(1) == name2 ) ||
                ( pc->names(1) == name1 && pc->names(0) == name2 ) ||
                ( pc->name() == name );
234
    }
235

236 237 238
    if ( found )
    {
      if ( onpe0 )
239 240 241 242
        cout << " ConstraintSet: a distance constraint named " << name << endl
             << " or involving atoms " << name1 << " " << name2 << endl
             << " is already defined" << endl
             << " ConstraintSet: cannot define constraint" << endl;
Francois Gygi committed
243
      return false;
244 245 246 247
    }
    else
    {
      DistanceConstraint *c =
Francois Gygi committed
248
        new DistanceConstraint(name,name1,name2,distance,
249
                               velocity,distance_tolerance);
250

251 252 253 254 255
      constraint_list.push_back(c);
    }
  }
  else if ( type == angle_type )
  {
256 257
    // constraint define angle name A B C value
    // constraint define angle name A B C value velocity
258

Francois Gygi committed
259
    if ( argc < 8  || argc > 9 )
260 261
    {
      if ( onpe0 )
262
        cout << " Incorrect number of arguments for angle constraint"
263 264 265
             << endl;
      return false;
    }
Francois Gygi committed
266 267 268 269
    string name = argv[3];
    string name1 = argv[4];
    string name2 = argv[5];
    string name3 = argv[6];
270

271 272 273
    Atom *a1 = atoms.findAtom(name1);
    Atom *a2 = atoms.findAtom(name2);
    Atom *a3 = atoms.findAtom(name3);
274

275 276
    if ( a1 == 0 || a2 == 0 || a3 == 0 )
    {
277
      if ( onpe0 )
Francois Gygi committed
278 279
      {
        if ( a1 == 0 )
280
          cout << " ConstraintSet: could not find atom " << name1 << endl;
Francois Gygi committed
281
        if ( a2 == 0 )
282
          cout << " ConstraintSet: could not find atom " << name2 << endl;
Francois Gygi committed
283
        if ( a3 == 0 )
284 285
          cout << " ConstraintSet: could not find atom " << name3 << endl;
        cout << " ConstraintSet: could not define constraint" << endl;
Francois Gygi committed
286 287
      }
      return false;
288
    }
289

290 291
    if ( name1 == name2 || name1 == name3 || name2 == name3)
    {
292
      if ( onpe0 )
293 294
        cout << " ConstraintSet: cannot define angle constraint between "
             << name1 << " " << name2 << " and " << name3 << endl;
Francois Gygi committed
295
      return false;
296
    }
297

298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    // define angle value
    double angle = 0.0;
    if ( !strcmp(argv[7],"*") )
    {
      // use current angle
      D3vector r12(a1->position()-a2->position());
      D3vector r32(a3->position()-a2->position());
      if ( norm2(r12) == 0.0 || norm2(r32) == 0.0 )
      {
        if ( onpe0 )
        {
          cout << " ConstraintSet: cannot define angle constraint." << endl;
          cout << " ConstraintSet: atoms are too close" << endl;
          return false;
        }
      }
      const double sp = normalized(r12) * normalized(r32);
      const double c = max(-1.0,min(1.0,sp));
      angle = (180.0/M_PI)*acos(c);

      if ( onpe0 )
        cout << "ConstraintSet::define_constraint: using current angle "
             << angle << endl;
    }
    else
      angle = atof(argv[7]);

Francois Gygi committed
325 326
    double velocity = 0.0;
    if ( argc == 9 )
327
    {
Francois Gygi committed
328
      velocity = atof(argv[8]);
329
    }
330

331 332 333
    if ( angle < 0.0 || angle > 180.0 )
    {
      if ( onpe0 )
334 335
        cout << " ConstraintSet: angle must be in [0,180]" << endl
             << " ConstraintSet: could not define constraint" << endl;
Francois Gygi committed
336
      return false;
337
    }
338

339 340 341 342 343 344 345
    // check if equivalent constraint is already defined
    bool found = false;
    Constraint *pc = 0;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      pc = constraint_list[i];
      assert(pc != 0);
346
      // check if a constraint (name1,name2,name3) or
347
      // (name3,name2,name1) is defined
348 349 350 351 352 353 354 355
      if ( pc->type() == "angle" )
        found = ( pc->names(0) == name1 &&
                  pc->names(1) == name2 &&
                  pc->names(2) == name3 ) ||
                ( pc->names(0) == name3 &&
                  pc->names(1) == name2 &&
                  pc->names(2) == name1 ) ||
                ( pc->name() == name );
356
    }
357

358 359 360
    if ( found )
    {
      if ( onpe0 )
361 362 363 364
        cout << " ConstraintSet: an angle constraint named " << name << endl
             << " or involving atoms "
             << name1 << " " << name2 << " " << name3 << endl
             << " is already defined" << endl
365
             << " ConstraintSet: cannot define constraint" << endl;
Francois Gygi committed
366
      return false;
367 368 369 370
    }
    else
    {
      AngleConstraint *c =
Francois Gygi committed
371 372
      new AngleConstraint(name, name1,name2,name3,angle,
        velocity,angle_tolerance);
373 374 375 376 377
      constraint_list.push_back(c);
    }
  }
  else if ( type == torsion_type )
  {
378 379
    // constraint define torsion name A B C D angle
    // constraint define torsion name A B C D angle velocity
380

Francois Gygi committed
381
    if ( argc < 9  || argc > 10 )
382 383
    {
      if ( onpe0 )
384
        cout << " Incorrect number of arguments for torsion constraint"
385 386 387
             << endl;
      return false;
    }
Francois Gygi committed
388 389 390 391 392
    string name = argv[3];
    string name1 = argv[4];
    string name2 = argv[5];
    string name3 = argv[6];
    string name4 = argv[7];
393

394 395 396 397
    Atom *a1 = atoms.findAtom(name1);
    Atom *a2 = atoms.findAtom(name2);
    Atom *a3 = atoms.findAtom(name3);
    Atom *a4 = atoms.findAtom(name4);
398

399 400
    if ( a1 == 0 || a2 == 0 || a3 == 0 || a4 == 0 )
    {
Francois Gygi committed
401
      if ( onpe0 )
402
      {
Francois Gygi committed
403
        if ( a1 == 0 )
404
          cout << " ConstraintSet: could not find atom " << name1 << endl;
Francois Gygi committed
405
        if ( a2 == 0 )
406
          cout << " ConstraintSet: could not find atom " << name2 << endl;
Francois Gygi committed
407
        if ( a3 == 0 )
408
          cout << " ConstraintSet: could not find atom " << name3 << endl;
Francois Gygi committed
409
        if ( a4 == 0 )
410 411
          cout << " ConstraintSet: could not find atom " << name4 << endl;
        cout << " ConstraintSet: could not define constraint" << endl;
Francois Gygi committed
412 413
      }
      return false;
414 415 416 417
    }
    if ( name1 == name2 || name1 == name3 || name1 == name4 ||
         name2 == name3 || name2 == name4 || name3 == name4 )
    {
418
      if ( onpe0 )
419
        cout << " ConstraintSet: cannot define torsion constraint using "
420
             << name1 << " " << name2 << " " << name3 << " " << name4
421
             << endl;
Francois Gygi committed
422
      return false;
423
    }
424

425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
    // define angle value
    double angle = 0.0;
    if ( !strcmp(argv[8],"*") )
    {
      // use current angle
      D3vector r12(a1->position()-a2->position());
      D3vector r32(a3->position()-a2->position());
      D3vector r43(a4->position()-a3->position());
      if ( norm2(r12) == 0.0 || norm2(r32) == 0.0 || norm2(r43) == 0.0 )
      {
        if ( onpe0 )
        {
          cout << " ConstraintSet: cannot define torsion constraint." << endl;
          cout << " ConstraintSet: atoms are too close" << endl;
          return false;
        }
      }

      D3vector e12(normalized(r12));
      D3vector e32(normalized(r32));
      D3vector e23(-e32);
      D3vector e43(normalized(r43));

      const double sin123 = length(e12^e32);
      const double sin234 = length(e23^e43);

      if ( sin123 != 0.0 && sin234 != 0.0 )
      {
        D3vector e123 = normalized(e12^e32);
        D3vector e234 = normalized(e23^e43);
        double cc = max(min(e123*e234,1.0),-1.0);
        double ss = max(min((e123^e234)*e32,1.0),-1.0);
        angle = (180.0/M_PI) * atan2(ss,cc);
      }

      if ( onpe0 )
        cout << "ConstraintSet::define_constraint: using current angle "
             << angle << endl;
    }
    else
      angle = atof(argv[8]);

467 468 469 470 471
    if ( angle > 180.0 )
      while ( angle > 180.0 ) angle -= 360.0;
    else if ( angle < -180.0 )
      while ( angle < -180.0 ) angle += 360.0;

Francois Gygi committed
472 473
    double velocity = 0.0;
    if ( argc == 10 )
474
    {
Francois Gygi committed
475
      velocity = atof(argv[9]);
476
    }
477

478 479 480 481 482 483 484
    // check if equivalent constraint is already defined
    bool found = false;
    Constraint *pc = 0;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      pc = constraint_list[i];
      assert(pc != 0);
485
      // check if an equivalent constraint (name1,name2,name3,name4) or
486
      // (name4,name3,name2,name1) is defined
487
      if ( pc->type() == "torsion" )
488 489 490 491 492 493 494 495 496
        found = ( pc->names(0) == name1 &&
                  pc->names(1) == name2 &&
                  pc->names(2) == name3 &&
                  pc->names(3) == name4 ) ||
                ( pc->names(0) == name4 &&
                  pc->names(1) == name3 &&
                  pc->names(2) == name2 &&
                  pc->names(3) == name1 ) ||
                ( pc->name() == name );
497
    }
498

499 500 501
    if ( found )
    {
      if ( onpe0 )
502 503 504
        cout << " ConstraintSet: a torsion constraint named " << name << endl
             << " or involving atoms "
             << name1 << " " << name2 << " " << name3 << " " << name4 << endl
505
             << " is already defined" << endl
506
             << " ConstraintSet: cannot define constraint" << endl;
Francois Gygi committed
507
      return false;
508 509 510 511
    }
    else
    {
      TorsionConstraint *c =
Francois Gygi committed
512
      new TorsionConstraint(name,name1,name2,name3,name4,
513 514 515 516 517 518 519
                            angle,velocity,angle_tolerance);
      constraint_list.push_back(c);
    }
  }
  else
  {
    if ( onpe0 )
520
      cout << " ConstraintSet::set_constraint: internal error" << endl;
521 522
    return false;
  }
523

524 525 526
  // update total number of blocked degrees of freedom
  ndofs_ += constraint_list.back()->dofs();

527 528 529 530
  return true;
}

////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
531
bool ConstraintSet::set_constraint(int argc, char **argv)
532 533
{
  const bool onpe0 = ctxt_.onpe0();
Francois Gygi committed
534 535 536 537 538 539 540 541 542 543 544
  assert(argc==4||argc==5);
  // argv[0] == "constraint"
  // argv[1] == "set"
  // argv[2] == constraint_name
  // argv[3] == value
  // argv[4] (optional) == velocity
  string name = argv[2];
  const double value = atof(argv[3]);
  double velocity = 0.0;
  const bool set_velocity = ( argc == 5 );
  if ( set_velocity ) velocity = atof(argv[4]);
545

Francois Gygi committed
546 547
    // check if constraint is already defined
  bool found = false;
548 549 550 551 552 553 554
  vector<Constraint*>::iterator i = constraint_list.begin();
  while ( !found && i != constraint_list.end() )
  {
    Constraint *pc = *i;
    assert(pc != 0);

    if ( pc->name() == name )
Francois Gygi committed
555
    {
556
      found = true;
Francois Gygi committed
557 558 559 560
      pc->set_value(value);
      if ( set_velocity ) pc->set_velocity(velocity);
    }
    i++;
561
  }
562 563 564 565

  if ( !found )
  {
    if ( onpe0 )
566
      cout << " ConstraintSet: no such constraint" << endl;
567 568
    return false;
  }
Francois Gygi committed
569 570 571 572 573 574 575 576 577 578 579 580 581
  return true;
}

////////////////////////////////////////////////////////////////////////////////
bool ConstraintSet::delete_constraint(int argc, char **argv)
{
  assert(argc==3);
  // argv[0] == "constraint"
  // argv[1] == "delete"
  // argv[2] == constraint_name
  string name = argv[2];
  const bool onpe0 = ctxt_.onpe0();

582 583 584 585 586 587 588 589 590 591 592 593 594
  bool found = false;
  // note next loop in reverse: avoid use of invalidated iterators
  // after erase operation

  vector<Constraint*>::iterator i = constraint_list.begin();
  while ( !found && i != constraint_list.end() )
  {
    Constraint *pc = *i;
    assert(pc != 0);

    // note structure of if else test to avoid incrementing
    // invalidated iterator after erase (see Meyers STL, p.45)
    if ( pc->name() == name )
Francois Gygi committed
595
    {
596
      found = true;
597 598 599 600

      // update total number of blocked degrees of freedom
      ndofs_ -= pc->dofs();

601 602 603 604 605 606 607 608 609
      delete pc;

      // remove constraint pointer from the list
      // note: iterator is incremented before erasing, remains valid
      constraint_list.erase(i++);
    }
    else
    {
      i++;
Francois Gygi committed
610
    }
611
  }
612

Francois Gygi committed
613
  if ( !found )
614
  {
615
    if ( onpe0 ) cout << " No such constraint" << endl;
616 617 618 619 620 621 622 623
    return false;
  }
  return true;
}

////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::list_constraints(ostream &os)
{
Francois Gygi committed
624
  if ( !constraint_list.empty() )
625
  {
Francois Gygi committed
626 627 628 629 630 631 632
    os << " <constraint_set>" << endl;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      Constraint *c = constraint_list[i];
      os << *c << endl;
    }
    os << " </constraint_set>" << endl;
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  }
}

////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::enforce(AtomSet& atoms)
{
  vector<vector<double> > r0,rp,v0;
  setup(atoms);
  atoms.get_positions(r0);
  rp=r0;
  atoms.get_velocities(v0);
  enforce_r(r0,rp);
  atoms.set_positions(rp);
  enforce_v(r0,v0);
  atoms.set_velocities(v0);
}
////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::enforce_r(const vector<vector<double> > &r0,
                              vector<vector<double> > &rp)
{
  const bool onpe0 = ctxt_.onpe0();
  int iter = 0;
  bool done = false;
656
  while ( !done && (iter < constraints_maxiter) )
657 658 659 660 661 662 663 664 665 666
  {
    done = true;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      Constraint *c = constraint_list[i];
      bool b = c->enforce_r(r0,rp);
      done &= b;
    }
    iter++;
  }
667

668 669 670
  if ( !done )
  {
    if ( onpe0 )
671 672
      cout << " ConstraintSet: could not enforce position constraints in "
           << constraints_maxiter << " iterations" << endl;
673 674 675 676 677 678 679 680 681 682
  }
}

////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::enforce_v(const vector<vector<double> > &r0,
                              vector<vector<double> > &v0)
{
  const bool onpe0 = ctxt_.onpe0();
  int iter = 0;
  bool done = false;
683
  while ( !done && (iter < constraints_maxiter) )
684 685 686 687 688 689 690 691 692
  {
    done = true;
    for ( int i = 0; i < constraint_list.size(); i++ )
    {
      bool b = constraint_list[i]->enforce_v(r0,v0);
      done &= b;
    }
    iter++;
  }
693

694 695 696
  if ( !done )
  {
    if ( onpe0 )
697 698
      cout << " ConstraintSet: could not enforce velocity constraints in "
           << constraints_maxiter << " iterations" << endl;
699 700 701 702
  }
}

////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
703 704
void ConstraintSet::compute_forces(const vector<vector<double> > &r0,
 const vector<vector<double> > &f)
705 706 707
{
  for ( int i = 0; i < constraint_list.size(); i++ )
  {
Francois Gygi committed
708
    constraint_list[i]->compute_force(r0,f);
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
  }
}

////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::update_constraints(double dt)
{
  for ( int i = 0; i < constraint_list.size(); i++ )
  {
    constraint_list[i]->update(dt);
  }
}

////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::setup(AtomSet& atoms)
{
  for ( int i = 0; i < constraint_list.size(); i++ )
  {
    constraint_list[i]->setup(atoms);
  }
}
Francois Gygi committed
729 730 731 732 733 734 735 736 737

////////////////////////////////////////////////////////////////////////////////
void ConstraintSet::reset(void)
{
  for ( int i = 0; i < constraint_list.size(); i++ )
    delete constraint_list[i];
  ndofs_ = 0;
  constraint_list.resize(0);
}