ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Bond.cpp
Revision: 610
Committed: Tue Jul 15 15:50:55 2003 UTC (20 years, 11 months ago) by gezelter
File size: 1550 byte(s)
Log Message:
more archaic code fixes

File Contents

# Content
1 #include "SRI.hpp"
2 #include "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 c_constraint->set_a( c_p_a->getIndex() );
29 c_constraint->set_b( c_p_b->getIndex() );
30 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 /* initialize the vector */
55
56 r_ab.x = c_p_b->getX() - c_p_a->getX();
57 r_ab.y = c_p_b->getY() - c_p_a->getY();
58 r_ab.z = c_p_b->getZ() - c_p_a->getZ();
59 r_ab.length = sqrt((r_ab.x * r_ab.x + r_ab.y * r_ab.y + r_ab.z * r_ab.z));
60
61 /* calculate the force here */
62
63 force = bond_force(r_ab.length);
64
65 Fab_x = -force * r_ab.x / r_ab.length;
66 Fab_y = -force * r_ab.y / r_ab.length;
67 Fab_z = -force * r_ab.z / r_ab.length;
68
69 c_p_a->addFx(Fab_x);
70 c_p_a->addFy(Fab_y);
71 c_p_a->addFz(Fab_z);
72
73 c_p_b->addFx(-Fab_x);
74 c_p_b->addFy(-Fab_y);
75 c_p_b->addFz(-Fab_z);
76
77 return;
78 }