ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Molecule.cpp
Revision: 1109
Committed: Wed Apr 14 16:32:15 2004 UTC (20 years, 2 months ago) by gezelter
File size: 4043 byte(s)
Log Message:
fixed for get_potential

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<myRigidBodies.size(); i++) {
95 myRigidBodies[i]->updateAtoms();
96 }
97
98 for(i=0; i<nBonds; i++){
99 myPot += myBonds[i]->get_potential();
100 }
101
102 for(i=0; i<nBends; i++){
103 myPot += myBends[i]->get_potential();
104 }
105
106 for(i=0; i<nTorsions; i++){
107 myPot += myTorsions[i]->get_potential();
108 }
109
110 return myPot;
111 }
112
113 void Molecule::printMe( void ){
114
115 int i;
116
117 for(i=0; i<nBonds; i++){
118 myBonds[i]->printMe();
119 }
120
121 for(i=0; i<nBends; i++){
122 myBends[i]->printMe();
123 }
124
125 for(i=0; i<nTorsions; i++){
126 myTorsions[i]->printMe();
127 }
128
129 }
130
131 void Molecule::moveCOM(double delta[3]){
132 double aPos[3];
133 int i, j;
134
135 for(i=0; i<nAtoms; i++) {
136 if(myAtoms[i] != NULL ) {
137
138 myAtoms[i]->getPos( aPos );
139
140 for (j=0; j< 3; j++)
141 aPos[j] += delta[j];
142
143 myAtoms[i]->setPos( aPos );
144 }
145 }
146
147 for(i=0; i<myRigidBodies.size(); i++) {
148
149 myRigidBodies[i]->getPos( aPos );
150
151 for (j=0; j< 3; j++)
152 aPos[j] += delta[j];
153
154 myRigidBodies[i]->setPos( aPos );
155 }
156 }
157
158 void Molecule::atoms2rigidBodies( void ) {
159 int i;
160 for (i = 0; i < myRigidBodies.size(); i++) {
161 myRigidBodies[i]->calcForcesAndTorques();
162 }
163 }
164
165 void Molecule::getCOM( double COM[3] ) {
166
167 double mass, mtot;
168 double aPos[3];
169 int i, j;
170
171 for (j=0; j<3; j++)
172 COM[j] = 0.0;
173
174 mtot = 0.0;
175
176 for (i=0; i < nAtoms; i++) {
177 if (myAtoms[i] != NULL) {
178
179 mass = myAtoms[i]->getMass();
180 mtot += mass;
181
182 myAtoms[i]->getPos( aPos );
183
184 for( j = 0; j < 3; j++)
185 COM[j] += aPos[j] * mass;
186
187 }
188 }
189
190 for (j = 0; j < 3; j++)
191 COM[j] /= mtot;
192 }
193
194 double Molecule::getCOMvel( double COMvel[3] ) {
195
196 double mass, mtot;
197 double aVel[3];
198 int i, j;
199
200
201 for (j=0; j<3; j++)
202 COMvel[j] = 0.0;
203
204 mtot = 0.0;
205
206 for (i=0; i < nAtoms; i++) {
207 if (myAtoms[i] != NULL) {
208
209 mass = myAtoms[i]->getMass();
210 mtot += mass;
211
212 myAtoms[i]->getVel(aVel);
213
214 for (j=0; j<3; j++)
215 COMvel[j] += aVel[j]*mass;
216
217 }
218 }
219
220 for (j=0; j<3; j++)
221 COMvel[j] /= mtot;
222
223 return mtot;
224
225 }
226
227 double Molecule::getTotalMass()
228 {
229 int natoms;
230 Atom** atoms;
231 double totalMass;
232
233 natoms = getNAtoms();
234 atoms = getMyAtoms();
235 totalMass = 0;
236 for(int i =0; i < natoms; i++){
237 totalMass += atoms[i]->getMass();
238 }
239
240 return totalMass;
241 }