| 1 |
tim |
1692 |
#include "primitives/SRI.hpp"
|
| 2 |
|
|
#include "primitives/Atom.hpp"
|
| 3 |
|
|
#include <math.h>
|
| 4 |
|
|
#include <iostream>
|
| 5 |
|
|
#include <stdlib.h>
|
| 6 |
|
|
|
| 7 |
|
|
|
| 8 |
|
|
|
| 9 |
|
|
Bond::Bond(){
|
| 10 |
|
|
|
| 11 |
|
|
c_constraint = NULL;
|
| 12 |
|
|
c_is_constrained = 0;
|
| 13 |
|
|
}
|
| 14 |
|
|
|
| 15 |
|
|
void Bond::set_atoms( Atom &a, Atom &b ){
|
| 16 |
|
|
|
| 17 |
|
|
c_p_a = &a;
|
| 18 |
|
|
c_p_b = &b;
|
| 19 |
|
|
}
|
| 20 |
|
|
|
| 21 |
|
|
void Bond::constrain(double bond_distance){
|
| 22 |
|
|
|
| 23 |
|
|
double dsqr = bond_distance * bond_distance;
|
| 24 |
|
|
|
| 25 |
|
|
c_is_constrained = 1;
|
| 26 |
|
|
|
| 27 |
|
|
c_constraint = new Constraint();
|
| 28 |
tim |
1701 |
c_constraint->set_a( c_p_a->getLocalIndex() );
|
| 29 |
|
|
c_constraint->set_b( c_p_b->getLocalIndex() );
|
| 30 |
tim |
1692 |
c_constraint->set_dsqr( dsqr );
|
| 31 |
|
|
}
|
| 32 |
|
|
|
| 33 |
|
|
Bond::~Bond(){
|
| 34 |
|
|
delete c_constraint;
|
| 35 |
|
|
c_constraint = 0;
|
| 36 |
|
|
}
|
| 37 |
|
|
|
| 38 |
|
|
void Bond::calc_forces(){
|
| 39 |
|
|
|
| 40 |
|
|
/* return 0 if the bond is constrained and stop wasting cpu */
|
| 41 |
|
|
|
| 42 |
|
|
if(c_is_constrained){
|
| 43 |
|
|
|
| 44 |
|
|
c_potential_E = 0.0;
|
| 45 |
|
|
return;
|
| 46 |
|
|
}
|
| 47 |
|
|
|
| 48 |
|
|
vect r_ab; /*the vector whose origin is a and end is b */
|
| 49 |
|
|
double force; /* the force scaling factor. */
|
| 50 |
|
|
double Fab_x; /*the x,y, and z components of the force */
|
| 51 |
|
|
double Fab_y;
|
| 52 |
|
|
double Fab_z;
|
| 53 |
|
|
|
| 54 |
tim |
1701 |
Vector3d aR, bR;
|
| 55 |
|
|
Vector3d aF, bF;
|
| 56 |
tim |
1692 |
|
| 57 |
|
|
/* initialize the vector */
|
| 58 |
|
|
|
| 59 |
|
|
aR = c_p_a->getPos();
|
| 60 |
|
|
bR = c_p_b->getPos();
|
| 61 |
|
|
|
| 62 |
|
|
r_ab.x = bR[0] - aR[0];
|
| 63 |
|
|
r_ab.y = bR[1] - aR[1];
|
| 64 |
|
|
r_ab.z = bR[2] - aR[2];
|
| 65 |
|
|
|
| 66 |
|
|
r_ab.length = sqrt((r_ab.x * r_ab.x + r_ab.y * r_ab.y + r_ab.z * r_ab.z));
|
| 67 |
|
|
|
| 68 |
|
|
/* calculate the force here */
|
| 69 |
|
|
|
| 70 |
|
|
force = bond_force(r_ab.length);
|
| 71 |
|
|
|
| 72 |
|
|
Fab_x = -force * r_ab.x / r_ab.length;
|
| 73 |
|
|
Fab_y = -force * r_ab.y / r_ab.length;
|
| 74 |
|
|
Fab_z = -force * r_ab.z / r_ab.length;
|
| 75 |
|
|
|
| 76 |
|
|
aF[0] = Fab_x;
|
| 77 |
|
|
aF[1] = Fab_y;
|
| 78 |
|
|
aF[2] = Fab_z;
|
| 79 |
|
|
|
| 80 |
|
|
bF[0] = -Fab_x;
|
| 81 |
|
|
bF[1] = -Fab_y;
|
| 82 |
|
|
bF[2] = -Fab_z;
|
| 83 |
|
|
|
| 84 |
|
|
c_p_a->addFrc(aF);
|
| 85 |
|
|
c_p_b->addFrc(bF);
|
| 86 |
|
|
|
| 87 |
|
|
return;
|
| 88 |
|
|
}
|