ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Atom.cpp
Revision: 1452
Committed: Mon Aug 23 15:11:36 2004 UTC (19 years, 10 months ago) by tim
File size: 3475 byte(s)
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <iostream>
2
3 using namespace std;
4
5 #include "simError.h"
6 #include "Atom.hpp"
7
8 Atom::Atom(int theIndex, SimState* theConfig) {
9
10 objType = OT_ATOM;
11 myConfig = theConfig;
12 hasCoords = false;
13
14 has_dipole = 0;
15 has_charge = 0;
16
17 index = theIndex;
18 offset = 0;
19 offsetX = offset;
20 offsetY = offset+1;
21 offsetZ = offset+2;
22
23 Axx = 0;
24 Axy = Axx+1;
25 Axz = Axx+2;
26
27 Ayx = Axx+3;
28 Ayy = Axx+4;
29 Ayz = Axx+5;
30
31 Azx = Axx+6;
32 Azy = Axx+7;
33 Azz = Axx+8;
34 }
35
36 void Atom::setIndex(int theIndex) {
37 index = theIndex;
38 }
39
40 void Atom::setCoords(void){
41
42 if( myConfig->isAllocated() ){
43
44 myConfig->getAtomPointers( index,
45 &pos,
46 &vel,
47 &frc,
48 &trq,
49 &Amat,
50 &mu,
51 &ul,
52 &quat);
53 }
54 else{
55 sprintf( painCave.errMsg,
56 "Attempted to set Atom %d coordinates with an unallocated "
57 "SimState object.\n", index );
58 painCave.isFatal = 1;
59 simError();
60 }
61
62 hasCoords = true;
63
64 }
65
66 void Atom::getPos( double theP[3] ){
67
68 if( hasCoords ){
69 theP[0] = pos[offsetX];
70 theP[1] = pos[offsetY];
71 theP[2] = pos[offsetZ];
72 }
73 else{
74
75 sprintf( painCave.errMsg,
76 "Attempt to get Pos for atom %d before coords set.\n",
77 index );
78 painCave.isFatal = 1;
79 simError();
80 }
81 }
82
83 void Atom::setPos( double theP[3] ){
84
85 if( hasCoords ){
86 pos[offsetX] = theP[0];
87 pos[offsetY] = theP[1];
88 pos[offsetZ] = theP[2];
89 }
90 else{
91
92 sprintf( painCave.errMsg,
93 "Attempt to set Pos for atom %d before coords set.\n",
94 index );
95 painCave.isFatal = 1;
96 simError();
97 }
98 }
99
100 void Atom::getVel( double theV[3] ){
101
102 if( hasCoords ){
103 theV[0] = vel[offsetX];
104 theV[1] = vel[offsetY];
105 theV[2] = vel[offsetZ];
106 }
107 else{
108
109 sprintf( painCave.errMsg,
110 "Attempt to get vel for atom %d before coords set.\n",
111 index );
112 painCave.isFatal = 1;
113 simError();
114 }
115
116 }
117
118 void Atom::setVel( double theV[3] ){
119
120 if( hasCoords ){
121 vel[offsetX] = theV[0];
122 vel[offsetY] = theV[1];
123 vel[offsetZ] = theV[2];
124 }
125 else{
126
127 sprintf( painCave.errMsg,
128 "Attempt to set vel for atom %d before coords set.\n",
129 index );
130 painCave.isFatal = 1;
131 simError();
132 }
133 }
134
135 void Atom::getFrc( double theF[3] ){
136
137 if( hasCoords ){
138 theF[0] = frc[offsetX];
139 theF[1] = frc[offsetY];
140 theF[2] = frc[offsetZ];
141 }
142 else{
143
144 sprintf( painCave.errMsg,
145 "Attempt to get frc for atom %d before coords set.\n",
146 index );
147 painCave.isFatal = 1;
148 simError();
149 }
150 }
151
152 void Atom::setFrc( double theF[3] ){
153
154 if( hasCoords ){
155 frc[offsetX] = theF[0];
156 frc[offsetY] = theF[1];
157 frc[offsetZ] = theF[2];
158 }
159 else{
160
161 sprintf( painCave.errMsg,
162 "Attempt to set frc for atom %d before coords set.\n",
163 index );
164 painCave.isFatal = 1;
165 simError();
166 }
167 }
168
169 void Atom::addFrc( double theF[3] ){
170
171 if( hasCoords ){
172 frc[offsetX] += theF[0];
173 frc[offsetY] += theF[1];
174 frc[offsetZ] += theF[2];
175 }
176 else{
177
178 sprintf( painCave.errMsg,
179 "Attempt to add frc for atom %d before coords set.\n",
180 index );
181 painCave.isFatal = 1;
182 simError();
183 }
184 }
185
186
187 void Atom::zeroForces( void ){
188
189 if( hasCoords ){
190 frc[offsetX] = 0.0;
191 frc[offsetY] = 0.0;
192 frc[offsetZ] = 0.0;
193 }
194 else{
195
196 sprintf( painCave.errMsg,
197 "Attempt to zero frc for atom %d before coords set.\n",
198 index );
199 painCave.isFatal = 1;
200 simError();
201 }
202 }
203