ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/generic_stamps/MoleculeStamp.cpp
Revision: 165
Committed: Thu Nov 7 17:53:29 2002 UTC (22 years, 5 months ago) by mmeineke
File size: 6900 byte(s)
Log Message:
working on the conversion of the BASS inititialization to be parrallel safe

File Contents

# Content
1 #include <cstdlib>
2 #include <cstdio>
3 #include <cstring>
4 #include <iostream>
5
6 #include "MoleculeStamp.hpp"
7
8 MoleculeStamp::MoleculeStamp(){
9
10 n_atoms = 0;
11 n_bonds = 0;
12 n_bends = 0;
13 n_torsions = 0;
14
15 unhandled = NULL;
16 atoms = NULL;
17 bonds = NULL;
18 bends = NULL;
19 torsions = NULL;
20
21 have_name = 0;
22 have_atoms = 0;
23 have_bonds = 0;
24 have_bends = 0;
25 have_torsions = 0;
26
27 }
28
29 MoleculeStamp::~MoleculeStamp(){
30 int i;
31
32 if( unhandled != NULL) delete unhandled;
33
34 if( atoms != NULL ){
35 for( i=0; i<n_atoms; i++ ) delete atoms[i];
36 }
37
38 if( bonds != NULL ){
39 for( i=0; i<n_bonds; i++ ) delete bonds[i];
40 }
41
42 if( bends != NULL ){
43 for( i=0; i<n_bends; i++ ) delete bends[i];
44 }
45
46 if( torsions != NULL ){
47 for( i=0; i<n_torsions; i++ ) delete torsions[i];
48 }
49
50 }
51
52 char* MoleculeStamp::assignString( char* lhs, char* rhs ){
53
54 if( !strcmp( lhs, "name" ) ){
55 strcpy( name, rhs );
56 have_name = 1;
57 }
58 else{
59 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
60 else unhandled->add( lhs, rhs );
61 have_extras = 1;
62 }
63 return NULL;
64 }
65
66 char* MoleculeStamp::assignDouble( char* lhs, double rhs ){
67 int i;
68
69 if( !strcmp( lhs, "nAtoms" ) ){
70 n_atoms = (int)rhs;
71
72 if( have_atoms ){
73 sprintf( errMsg,
74 "MoleculeStamp error, n_atoms already declared"
75 "for molecule: %s\n",
76 name);
77 return strdup( errMsg );
78 }
79 have_atoms = 1;
80 atoms = new AtomStamp*[n_atoms];
81 for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
82 }
83
84 else if( !strcmp( lhs, "nBonds" ) ){
85 n_bonds = (int)rhs;
86
87 if( have_bonds ){
88 sprintf( errMsg,
89 "MoleculeStamp error, n_bonds already declared for"
90 " molecule: %s\n",
91 name);
92 return strdup( errMsg );
93 }
94 have_bonds = 1;
95 bonds = new BondStamp*[n_bonds];
96 for( i=0; i<n_bonds; i++ ) bonds[i] = NULL;
97 }
98
99 else if( !strcmp( lhs, "nBends" ) ){
100 n_bends = (int)rhs;
101
102 if( have_bends ){
103 sprintf( errMsg,
104 "MoleculeStamp error, n_bends already declared for"
105 " molecule: %s\n",
106 name);
107 return strdup( errMsg );
108 }
109 have_bends = 1;
110 bends = new BendStamp*[n_bends];
111 for( i=0; i<n_bends; i++ ) bends[i] = NULL;
112 }
113
114 else if( !strcmp( lhs, "nTorsions" ) ){
115 n_torsions = (int)rhs;
116
117 if( have_torsions ){
118 sprintf( errMsg,
119 "MoleculeStamp error, n_torsions already declared for"
120 " molecule: %s\n",
121 name );
122 return strdup( errMsg );
123 }
124 have_torsions = 1;
125 torsions = new TorsionStamp*[n_torsions];
126 for( i=0; i<n_torsions; i++ ) torsions[i] = NULL;
127 }
128 else{
129 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
130 else unhandled->add( lhs, rhs );
131 have_extras = 1;
132 }
133 return NULL;
134 }
135
136 char* MoleculeStamp::assignInt( char* lhs, int rhs ){
137 int i;
138
139 if( !strcmp( lhs, "nAtoms" ) ){
140 n_atoms = rhs;
141
142 if( have_atoms ){
143 sprintf( errMsg,
144 "MoleculeStamp error, n_atoms already declared for"
145 " molecule: %s\n",
146 name);
147 return strdup( errMsg );
148 }
149 have_atoms = 1;
150 atoms = new AtomStamp*[n_atoms];
151 for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
152 }
153
154 else if( !strcmp( lhs, "nBonds" ) ){
155 n_bonds = rhs;
156
157 if( have_bonds ){
158 sprintf( errMsg,
159 "MoleculeStamp error, n_bonds already declared for"
160 " molecule: %s\n",
161 name);
162 return strdup( errMsg );
163 }
164 have_bonds = 1;
165 bonds = new BondStamp*[n_bonds];
166 for( i=0; i<n_bonds; i++ ) bonds[i] = NULL;
167 }
168
169 else if( !strcmp( lhs, "nBends" ) ){
170 n_bends = rhs;
171
172 if( have_bends ){
173 sprintf( errMsg,
174 "MoleculeStamp error, n_bends already declared for"
175 " molecule: %s\n",
176 name );
177 return strdup( errMsg );
178 }
179 have_bends = 1;
180 bends = new BendStamp*[n_bends];
181 for( i=0; i<n_bends; i++ ) bends[i] = NULL;
182 }
183
184 else if( !strcmp( lhs, "nTorsions" ) ){
185 n_torsions = rhs;
186
187 if( have_torsions ){
188 sprintf( errMsg,
189 "MoleculeStamp error, n_torsions already declared for"
190 " molecule: %s\n",
191 name);
192 return strdup( errMsg );
193 }
194 have_torsions = 1;
195 torsions = new TorsionStamp*[n_torsions];
196 for( i=0; i<n_torsions; i++ ) torsions[i] = NULL;
197 }
198 else{
199 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
200 else unhandled->add( lhs, rhs );
201 have_extras = 1;
202 }
203 return NULL;
204 }
205
206 char* MoleculeStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
207
208 char err[200];
209
210 if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
211 else{
212 if( have_atoms ){
213 sprintf( err, "MoleculeStamp error, %d out of nAtoms range",
214 atomIndex );
215 return strdup( err );
216 }
217 else return strdup("MoleculeStamp error, nAtoms not given before"
218 "first atom declaration." );
219 }
220
221 return NULL;
222 }
223
224 char* MoleculeStamp::addBond( BondStamp* the_bond, int bondIndex ){
225
226 char err[200];
227
228 if( have_bonds && bondIndex < n_bonds ) bonds[bondIndex] = the_bond;
229 else{
230 if( have_bonds ){
231 sprintf( err, "MoleculeStamp error, %d out of nBonds range",
232 bondIndex );
233 return strdup( err );
234 }
235 else return strdup("MoleculeStamp error, nBonds not given before"
236 "first bond declaration." );
237 }
238
239 return NULL;
240 }
241
242 char* MoleculeStamp::addBend( BendStamp* the_bend, int bendIndex ){
243
244 char err[200];
245
246 if( have_bends && bendIndex < n_bends ) bends[bendIndex] = the_bend;
247 else{
248 if( have_bends ){
249 sprintf( err, "MoleculeStamp error, %d out of nBends range",
250 bendIndex );
251 return strdup( err );
252 }
253 else return strdup("MoleculeStamp error, nBends not given before"
254 "first bend declaration." );
255 }
256
257 return NULL;
258 }
259
260 char* MoleculeStamp::addTorsion( TorsionStamp* the_torsion, int torsionIndex ){
261
262 char err[200];
263
264 if( have_torsions && torsionIndex < n_torsions )
265 torsions[torsionIndex] = the_torsion;
266 else{
267 if( have_torsions ){
268 sprintf( err, "MoleculeStamp error, %d out of nTorsions range",
269 torsionIndex );
270 return strdup( err );
271 }
272 else return strdup("MoleculeStamp error, nTorsions not given before"
273 "first torsion declaration." );
274 }
275
276 return NULL;
277 }
278
279 char* MoleculeStamp::checkMe( void ){
280
281 int i;
282 short int no_atom;
283 char err[120];
284
285 if( !have_name || !have_atoms ){
286 if( !have_name ) return strdup( "MoleculeStamp error. Molecule's name"
287 " was not given.\n" );
288 else return strdup( "MoleculeStamp error. Molecule contains no atoms." );
289 }
290
291 no_atom = 0;
292 for( i=0; i<n_atoms; i++ ){
293 if( atoms[i] == NULL ) no_atom = 1;
294 }
295
296 if( no_atom ){
297 sprintf( err,
298 "MoleculeStamp error. Not all of the atoms were"
299 " declared in molecule \"%s\".\n", name );
300 return strdup( err );
301 }
302
303 return NULL;
304 }