ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Molecule.cpp
Revision: 1104
Committed: Tue Apr 13 16:26:03 2004 UTC (20 years, 2 months ago) by gezelter
File size: 3959 byte(s)
Log Message:
Now molecules can keep track of their own IntegrableObjects (and
RigidBodies).  Also a bug-fix so that SimInfo can keep track of
RigidBodies (which was done incorrectly before).

File Contents

# Content
1 #include <stdlib.h>
2
3
4 #include "Molecule.hpp"
5 #include "simError.h"
6
7
8
9 Molecule::Molecule( void ){
10
11 myAtoms = NULL;
12 myBonds = NULL;
13 myBends = NULL;
14 myTorsions = NULL;
15
16 }
17
18 Molecule::~Molecule( void ){
19 int i;
20
21 if( myAtoms != NULL ){
22 for(i=0; i<nAtoms; i++) if(myAtoms[i] != NULL ) delete myAtoms[i];
23 delete[] myAtoms;
24 }
25
26 if( myBonds != NULL ){
27 for(i=0; i<nBonds; i++) if(myBonds[i] != NULL ) delete myBonds[i];
28 delete[] myBonds;
29 }
30
31 if( myBends != NULL ){
32 for(i=0; i<nBends; i++) if(myBends[i] != NULL ) delete myBends[i];
33 delete[] myBends;
34 }
35
36 if( myTorsions != NULL ){
37 for(i=0; i<nTorsions; i++) if(myTorsions[i] != NULL ) delete myTorsions[i];
38 delete[] myTorsions;
39 }
40
41 }
42
43
44 void Molecule::initialize( molInit &theInit ){
45
46 nAtoms = theInit.nAtoms;
47 nMembers = nAtoms;
48 nBonds = theInit.nBonds;
49 nBends = theInit.nBends;
50 nTorsions = theInit.nTorsions;
51 nRigidBodies = theInit.nRigidBodies;
52 nOriented = theInit.nOriented;
53
54 myAtoms = theInit.myAtoms;
55 myBonds = theInit.myBonds;
56 myBends = theInit.myBends;
57 myTorsions = theInit.myTorsions;
58 myRigidBodies = theInit.myRigidBodies;
59
60 myIntegrableObjects = theInit.myIntegrableObjects;
61
62 }
63
64 void Molecule::calcForces( void ){
65
66 int i;
67
68 for(i=0; i<myRigidBodies.size(); i++) {
69 myRigidBodies[i]->updateAtoms();
70 }
71
72 for(i=0; i<nBonds; i++){
73 myBonds[i]->calc_forces();
74 }
75
76 for(i=0; i<nBends; i++){
77 myBends[i]->calc_forces();
78 }
79
80 for(i=0; i<nTorsions; i++){
81 myTorsions[i]->calc_forces();
82 }
83
84 // Rigid Body forces and torques are done after the fortran force loop
85
86 }
87
88
89 double Molecule::getPotential( void ){
90
91 int i;
92 double myPot = 0.0;
93
94 for(i=0; i<nBonds; i++){
95 myPot += myBonds[i]->get_potential();
96 }
97
98 for(i=0; i<nBends; i++){
99 myPot += myBends[i]->get_potential();
100 }
101
102 for(i=0; i<nTorsions; i++){
103 myPot += myTorsions[i]->get_potential();
104 }
105
106 return myPot;
107 }
108
109 void Molecule::printMe( void ){
110
111 int i;
112
113 for(i=0; i<nBonds; i++){
114 myBonds[i]->printMe();
115 }
116
117 for(i=0; i<nBends; i++){
118 myBends[i]->printMe();
119 }
120
121 for(i=0; i<nTorsions; i++){
122 myTorsions[i]->printMe();
123 }
124
125 }
126
127 void Molecule::moveCOM(double delta[3]){
128 double aPos[3];
129 int i, j;
130
131 for(i=0; i<nAtoms; i++) {
132 if(myAtoms[i] != NULL ) {
133
134 myAtoms[i]->getPos( aPos );
135
136 for (j=0; j< 3; j++)
137 aPos[j] += delta[j];
138
139 myAtoms[i]->setPos( aPos );
140 }
141 }
142
143 for(i=0; i<myRigidBodies.size(); i++) {
144
145 myRigidBodies[i]->getPos( aPos );
146
147 for (j=0; j< 3; j++)
148 aPos[j] += delta[j];
149
150 myRigidBodies[i]->setPos( aPos );
151 }
152 }
153
154 void Molecule::atoms2rigidBodies( void ) {
155 int i;
156 for (i = 0; i < myRigidBodies.size(); i++) {
157 myRigidBodies[i]->calcForcesAndTorques();
158 }
159 }
160
161 void Molecule::getCOM( double COM[3] ) {
162
163 double mass, mtot;
164 double aPos[3];
165 int i, j;
166
167 for (j=0; j<3; j++)
168 COM[j] = 0.0;
169
170 mtot = 0.0;
171
172 for (i=0; i < nAtoms; i++) {
173 if (myAtoms[i] != NULL) {
174
175 mass = myAtoms[i]->getMass();
176 mtot += mass;
177
178 myAtoms[i]->getPos( aPos );
179
180 for( j = 0; j < 3; j++)
181 COM[j] += aPos[j] * mass;
182
183 }
184 }
185
186 for (j = 0; j < 3; j++)
187 COM[j] /= mtot;
188 }
189
190 double Molecule::getCOMvel( double COMvel[3] ) {
191
192 double mass, mtot;
193 double aVel[3];
194 int i, j;
195
196
197 for (j=0; j<3; j++)
198 COMvel[j] = 0.0;
199
200 mtot = 0.0;
201
202 for (i=0; i < nAtoms; i++) {
203 if (myAtoms[i] != NULL) {
204
205 mass = myAtoms[i]->getMass();
206 mtot += mass;
207
208 myAtoms[i]->getVel(aVel);
209
210 for (j=0; j<3; j++)
211 COMvel[j] += aVel[j]*mass;
212
213 }
214 }
215
216 for (j=0; j<3; j++)
217 COMvel[j] /= mtot;
218
219 return mtot;
220
221 }
222
223 double Molecule::getTotalMass()
224 {
225 int natoms;
226 Atom** atoms;
227 double totalMass;
228
229 natoms = getNAtoms();
230 atoms = getMyAtoms();
231 totalMass = 0;
232 for(int i =0; i < natoms; i++){
233 totalMass += atoms[i]->getMass();
234 }
235
236 return totalMass;
237 }