ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionEvaluator.cpp
(Generate patch)

Comparing trunk/src/selection/SelectionEvaluator.cpp (file contents):
Revision 278 by tim, Tue Feb 1 22:49:23 2005 UTC vs.
Revision 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
40   */
41  
42 + #include <stack>
43   #include "selection/SelectionEvaluator.hpp"
44 < namespace oopse {
44 > #include "primitives/Atom.hpp"
45 > #include "primitives/DirectionalAtom.hpp"
46 > #include "primitives/RigidBody.hpp"
47 > #include "primitives/Molecule.hpp"
48 > #include "io/basic_ifstrstream.hpp"
49  
50 + namespace OpenMD {
51  
52 < bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) {
52 >
53 >  SelectionEvaluator::SelectionEvaluator(SimInfo* si)
54 >    : info(si), nameFinder(info), distanceFinder(info), indexFinder(info),
55 >      isLoaded_(false){    
56 >      nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies();
57 >    }            
58 >
59 >  bool SelectionEvaluator::loadScript(const std::string& filename,
60 >                                      const std::string& script) {
61 >    clearDefinitionsAndLoadPredefined();
62      this->filename = filename;
63      this->script = script;
64      if (! compiler.compile(filename, script)) {
65 <        error = true;
66 <        errorMessage = compiler.getErrorMessage();
67 <        return false;
65 >      error = true;
66 >      errorMessage = compiler.getErrorMessage();
67 >
68 >      sprintf( painCave.errMsg,
69 >               "SelectionCompiler Error: %s\n", errorMessage.c_str());
70 >      painCave.severity = OPENMD_ERROR;
71 >      painCave.isFatal = 1;
72 >      simError();
73 >      return false;
74      }
75  
76      pc = 0;
77      aatoken = compiler.getAatokenCompiled();
78      linenumbers = compiler.getLineNumbers();
79      lineIndices = compiler.getLineIndices();
80 +
81 +    std::vector<std::vector<Token> >::const_iterator i;  
82 +
83 +    isDynamic_ = false;
84 +    for (i = aatoken.begin(); i != aatoken.end(); ++i) {
85 +      if (containDynamicToken(*i)) {
86 +        isDynamic_ = true;
87 +        break;
88 +      }
89 +    }
90 +
91 +    isLoaded_ = true;
92      return true;
93 < }
93 >  }
94  
95 < void SelectionEvaluator::clearState() {
63 <    for (int i = scriptLevelMax; --i >= 0; )
64 <        stack[i] = null;
65 <    scriptLevel = 0;
95 >  void SelectionEvaluator::clearState() {
96      error = false;
97 <    errorMessage = null;
98 < }
97 >    errorMessage = "";
98 >  }
99  
100 < bool SelectionEvaluator::loadScriptString(const std::string& script) {
100 >  bool SelectionEvaluator::loadScriptString(const std::string& script) {
101      clearState();
102 <    return loadScript(null, script);
103 < }
102 >    return loadScript("", script);
103 >  }
104  
105 < bool SelectionEvaluator::loadScriptFile(const std::string& filename) {
105 >  bool SelectionEvaluator::loadScriptFile(const std::string& filename) {
106      clearState();
107      return loadScriptFileInternal(filename);
108 < }
108 >  }
109  
110 <
111 < void SelectionEvaluator::instructionDispatchLoop(){
112 <
113 <    while ( pc < aatoken.length) {
84 <        statement = aatoken[pc++];
85 <        statementLength = statement.length;
86 <        Token token = statement[0];
87 <        switch (token.tok) {
88 <            case Token.define:
89 <                define();
90 <            break;
91 <            case Token.select:
92 <                select();
93 <            break;
94 <            default:
95 <                unrecognizedCommand(token);
96 <            return;
97 <        }
110 >  bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) {
111 >    ifstrstream ifs(filename.c_str());
112 >    if (!ifs.is_open()) {
113 >      return false;
114      }
115 < }
116 <
117 <  void SelectionEvaluator::predefine(String script) {
118 <    if (compiler.compile("#predefine", script)) {
119 <      Token [][] aatoken = compiler.getAatokenCompiled();
120 <      if (aatoken.length != 1) {
121 <        viewer.scriptStatus("predefinition does not have exactly 1 command:"
122 <                            + script);
123 <        return;
115 >    
116 >    const int bufferSize = 65535;
117 >    char buffer[bufferSize];
118 >    std::string script;
119 >    while(ifs.getline(buffer, bufferSize)) {
120 >      script += buffer;
121 >    }
122 >    return loadScript(filename, script);
123 >  }
124 >  
125 >  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){
126 >    
127 >    while ( pc < aatoken.size()) {
128 >      statement = aatoken[pc++];
129 >      statementLength = statement.size();
130 >      Token token = statement[0];
131 >      switch (token.tok) {
132 >      case Token::define:
133 >        define();
134 >        break;
135 >      case Token::select:
136 >        select(bs);
137 >        break;
138 >      default:
139 >        unrecognizedCommand(token);
140 >        return;
141        }
109      Token[] statement = aatoken[0];
110      if (statement.length > 2) {
111        int tok = statement[1].tok;
112        if (tok == Token.identifier ||
113            (tok & Token.predefinedset) == Token.predefinedset) {
114          String variable = (String)statement[1].value;
115          variables.put(variable, statement);
116        } else {
117          viewer.scriptStatus("invalid variable name:" + script);
118        }
119      } else {
120        viewer.scriptStatus("bad predefinition length:" + script);
121      }
122    } else {
123      viewer.scriptStatus("predefined set compile error:" + script +
124                          "\ncompile error:" + compiler.getErrorMessage());
142      }
143 +
144    }
145  
146 <
147 <
148 <  BitSet SelectionEvaluator::expression(Token[] code, int pcStart) throws ScriptException {
149 <    int numberOfAtoms = viewer.getAtomCount();
150 <    BitSet bs;
151 <    BitSet[] stack = new BitSet[10];
134 <    int sp = 0;
135 <
136 <    for (int pc = pcStart; ; ++pc) {
146 >  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
147 >                                             int pcStart) {
148 >    OpenMDBitSet bs;
149 >    std::stack<OpenMDBitSet> stack;
150 >  
151 >    for (int pc = pcStart; pc < code.size(); ++pc) {
152        Token instruction = code[pc];
153 <      if (logMessages)
139 <        viewer.scriptStatus("instruction=" + instruction);
153 >
154        switch (instruction.tok) {
155 <      case Token.expressionBegin:
155 >      case Token::expressionBegin:
156          break;
157 <      case Token.expressionEnd:
144 <        break expression_loop;
145 <      case Token.all:
146 <        bs = stack[sp++] = new BitSet(numberOfAtoms);
147 <        for (int i = numberOfAtoms; --i >= 0; )
148 <          bs.set(i);
157 >      case Token::expressionEnd:
158          break;
159 <      case Token.none:
160 <        stack[sp++] = new BitSet();
159 >      case Token::all:
160 >        bs = OpenMDBitSet(nStuntDouble);
161 >        bs.setAll();
162 >        stack.push(bs);            
163          break;
164 <      case Token.opOr:
165 <        bs = stack[--sp];
166 <        stack[sp-1].or(bs);
164 >      case Token::none:
165 >        bs = OpenMDBitSet(nStuntDouble);
166 >        stack.push(bs);            
167          break;
168 <      case Token.opAnd:
169 <        bs = stack[--sp];
170 <        stack[sp-1].and(bs);
168 >      case Token::opOr:
169 >        bs = stack.top();
170 >        stack.pop();
171 >        stack.top() |= bs;
172          break;
173 <      case Token.opNot:
174 <        bs = stack[sp - 1];
175 <        notSet(bs);
173 >      case Token::opAnd:
174 >        bs = stack.top();
175 >        stack.pop();
176 >        stack.top() &= bs;
177          break;
178 <      case Token.within:
179 <        bs = stack[sp - 1];
167 <        stack[sp - 1] = new BitSet();
168 <        withinInstruction(instruction, bs, stack[sp - 1]);
178 >      case Token::opNot:
179 >        stack.top().flip();
180          break;
181 <      case Token.selected:
182 <        stack[sp++] = copyBitSet(viewer.getSelectionSet());
181 >      case Token::within:
182 >        withinInstruction(instruction, stack.top());
183          break;
184 <      case Token.y:
185 <      case Token.amino:
186 <      case Token.backbone:
187 <      case Token.solvent:
188 <      case Token.identifier:
178 <      case Token.sidechain:
179 <      case Token.surface:
180 <        stack[sp++] = lookupIdentifierValue((String)instruction.value);
184 >        //case Token::selected:
185 >        //  stack.push(getSelectionSet());
186 >        //  break;
187 >      case Token::name:
188 >        stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
189          break;
190 <      case Token.opLT:
191 <      case Token.opLE:
184 <      case Token.opGE:
185 <      case Token.opGT:
186 <      case Token.opEQ:
187 <      case Token.opNE:
188 <        bs = stack[sp++] = new BitSet();
189 <        comparatorInstruction(instruction, bs);
190 >      case Token::index:
191 >        stack.push(indexInstruction(instruction.value));
192          break;
193 +      case Token::identifier:
194 +        stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
195 +        break;
196 +      case Token::opLT:
197 +      case Token::opLE:
198 +      case Token::opGE:
199 +      case Token::opGT:
200 +      case Token::opEQ:
201 +      case Token::opNE:
202 +        stack.push(comparatorInstruction(instruction));
203 +        break;
204        default:
205          unrecognizedExpression();
206        }
207      }
208 <    if (sp != 1)
208 >    if (stack.size() != 1)
209        evalError("atom expression compiler error - stack over/underflow");
210 <    return stack[0];
210 >          
211 >    return stack.top();
212    }
213  
214  
215  
216 <  void SelectionEvaluator::comparatorInstruction(Token instruction, BitSet bs) {
216 >  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
217      int comparator = instruction.tok;
218      int property = instruction.intValue;
219 <    float propertyValue = 0; // just for temperature
220 <    int comparisonValue = ((Integer)instruction.value).intValue();
221 <    int numberOfAtoms = viewer.getAtomCount();
222 <    Frame frame = viewer.getFrame();
223 <    for (int i = 0; i < numberOfAtoms; ++i) {
224 <      Atom atom = frame.getAtomAt(i);
225 <      switch (property) {
226 <      case Token.atomno:
227 <        propertyValue = atom.getAtomNumber();
228 <        break;
229 <      case Token.elemno:
230 <        propertyValue = atom.getElementNumber();
231 <        break;
232 <      case Token.temperature:
233 <        propertyValue = atom.getBfactor100();
234 <        if (propertyValue < 0)
235 <          continue;
222 <        propertyValue /= 100;
223 <        break;
224 <      case Token._atomID:
225 <        propertyValue = atom.getSpecialAtomID();
226 <        if (propertyValue < 0)
227 <          continue;
228 <        break;
229 <      case Token._structure:
230 <        propertyValue = getProteinStructureType(atom);
231 <        if (propertyValue == -1)
232 <          continue;
233 <        break;
234 <      case Token.radius:
235 <        propertyValue = atom.getRasMolRadius();
236 <        break;
237 <      case Token._bondedcount:
238 <        propertyValue = atom.getCovalentBondCount();
239 <        break;
240 <      case Token.model:
241 <        propertyValue = atom.getModelTagNumber();
242 <        break;
243 <      default:
244 <        unrecognizedAtomProperty(property);
219 >    float comparisonValue = boost::any_cast<float>(instruction.value);
220 >    float propertyValue;
221 >    OpenMDBitSet bs(nStuntDouble);
222 >    bs.clearAll();
223 >    
224 >    SimInfo::MoleculeIterator mi;
225 >    Molecule* mol;
226 >    Molecule::AtomIterator ai;
227 >    Atom* atom;
228 >    Molecule::RigidBodyIterator rbIter;
229 >    RigidBody* rb;
230 >
231 >    for (mol = info->beginMolecule(mi); mol != NULL;
232 >         mol = info->nextMolecule(mi)) {
233 >
234 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
235 >        compareProperty(atom, bs, property, comparator, comparisonValue);
236        }
237 <      boolean match = false;
238 <      switch (comparator) {
239 <      case Token.opLT:
240 <        match = propertyValue < comparisonValue;
250 <        break;
251 <      case Token.opLE:
252 <        match = propertyValue <= comparisonValue;
253 <        break;
254 <      case Token.opGE:
255 <        match = propertyValue >= comparisonValue;
256 <        break;
257 <      case Token.opGT:
258 <        match = propertyValue > comparisonValue;
259 <        break;
260 <      case Token.opEQ:
261 <        match = propertyValue == comparisonValue;
262 <        break;
263 <      case Token.opNE:
264 <        match = propertyValue != comparisonValue;
265 <        break;
237 >    
238 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
239 >           rb = mol->nextRigidBody(rbIter)) {
240 >        compareProperty(rb, bs, property, comparator, comparisonValue);
241        }
267      if (match)
268        bs.set(i);
242      }
243 +
244 +    return bs;
245    }
246  
247 < void SelectionEvaluator::withinInstruction(Token instruction, BitSet bs, BitSet bsResult)
247 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
248 >                                           int property, int comparator,
249 >                                           float comparisonValue) {
250 >    RealType propertyValue = 0.0;
251 >    switch (property) {
252 >    case Token::mass:
253 >      propertyValue = sd->getMass();
254 >      break;
255 >    case Token::charge:
256 >      if (sd->isAtom()){
257 >        Atom* atom = static_cast<Atom*>(sd);
258 >        propertyValue = getCharge(atom);
259 >      } else if (sd->isRigidBody()) {
260 >        RigidBody* rb = static_cast<RigidBody*>(sd);
261 >        RigidBody::AtomIterator ai;
262 >        Atom* atom;
263 >        for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
264 >          propertyValue+=  getCharge(atom);
265 >        }
266 >      }
267 >      break;
268 >    case Token::x:
269 >      propertyValue = sd->getPos().x();
270 >      break;
271 >    case Token::y:
272 >      propertyValue = sd->getPos().y();
273 >      break;
274 >    case Token::z:
275 >      propertyValue = sd->getPos().z();
276 >      break;
277 >    default:
278 >      unrecognizedAtomProperty(property);
279 >    }
280 >        
281 >    bool match = false;
282 >    switch (comparator) {
283 >    case Token::opLT:
284 >      match = propertyValue < comparisonValue;
285 >      break;
286 >    case Token::opLE:
287 >      match = propertyValue <= comparisonValue;
288 >      break;
289 >    case Token::opGE:
290 >      match = propertyValue >= comparisonValue;
291 >      break;
292 >    case Token::opGT:
293 >      match = propertyValue > comparisonValue;
294 >      break;
295 >    case Token::opEQ:
296 >      match = propertyValue == comparisonValue;
297 >      break;
298 >    case Token::opNE:
299 >      match = propertyValue != comparisonValue;
300 >      break;
301 >    }
302 >    if (match)
303 >      bs.setBitOn(sd->getGlobalIndex());
304 >    
305 >  }
306  
307 <    Object withinSpec = instruction.value;
308 <    if (withinSpec instanceof Float) {
309 <        withinDistance(((Float)withinSpec).floatValue(), bs, bsResult);
310 <        return;
307 >  void SelectionEvaluator::withinInstruction(const Token& instruction,
308 >                                             OpenMDBitSet& bs){
309 >    
310 >    boost::any withinSpec = instruction.value;
311 >    float distance;
312 >    if (withinSpec.type() == typeid(float)){
313 >      distance = boost::any_cast<float>(withinSpec);
314 >    } else if (withinSpec.type() == typeid(int)) {
315 >      distance = boost::any_cast<int>(withinSpec);    
316 >    } else {
317 >      evalError("casting error in withinInstruction");
318 >      bs.clearAll();
319      }
320 <    evalError("Unrecognized within parameter:" + withinSpec);
321 < }
320 >    
321 >    bs = distanceFinder.find(bs, distance);            
322 >  }
323 >  
324 >  void SelectionEvaluator::define() {
325 >    assert(statement.size() >= 3);
326 >    
327 >    std::string variable = boost::any_cast<std::string>(statement[1].value);
328 >    
329 >    variables.insert(VariablesType::value_type(variable,
330 >                                               expression(statement, 2)));
331 >  }
332 >  
333  
334 <  void SelectionEvaluator::withinDistance(float distance, BitSet bs, BitSet bsResult) {
335 <    Frame frame = viewer.getFrame();
336 <    for (int i = frame.getAtomCount(); --i >= 0; ) {
337 <      if (bs.get(i)) {
338 <        Atom atom = frame.getAtomAt(i);
339 <        AtomIterator iterWithin =
340 <          frame.getWithinIterator(atom, distance);
341 <        while (iterWithin.hasNext())
342 <          bsResult.set(iterWithin.next().getAtomIndex());
334 >  /** @todo */
335 >  void SelectionEvaluator::predefine(const std::string& script) {
336 >    
337 >    if (compiler.compile("#predefine", script)) {
338 >      std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled();
339 >      if (aatoken.size() != 1) {
340 >        evalError("predefinition does not have exactly 1 command:"
341 >                  + script);
342 >        return;
343        }
344 +      std::vector<Token> statement = aatoken[0];
345 +      if (statement.size() > 2) {
346 +        int tok = statement[1].tok;
347 +        if (tok == Token::identifier ||
348 +            (tok & Token::predefinedset) == Token::predefinedset) {
349 +          std::string variable = boost::any_cast<std::string>(statement[1].value);
350 +          variables.insert(VariablesType::value_type(variable, statement));
351 +          
352 +        } else {
353 +          evalError("invalid variable name:" + script);
354 +        }
355 +      }else {
356 +        evalError("bad predefinition length:" + script);
357 +      }      
358 +        
359 +    } else {
360 +      evalError("predefined set compile error:" + script +
361 +                "\ncompile error:" + compiler.getErrorMessage());
362      }
363    }
364  
365 <  void SelectionEvaluator::define() throws ScriptException {
366 <    String variable = (String)statement[1].value;
297 <    variables.put(variable, (expression(statement, 2)));
365 >  void SelectionEvaluator::select(OpenMDBitSet& bs){
366 >    bs = expression(statement, 1);
367    }
368 < }
368 >  
369 >  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){
370 >    
371 >    OpenMDBitSet bs(nStuntDouble);
372 >    std::map<std::string, boost::any>::iterator i = variables.find(variable);
373 >    
374 >    if (i != variables.end()) {
375 >      if (i->second.type() == typeid(OpenMDBitSet)) {
376 >        return boost::any_cast<OpenMDBitSet>(i->second);
377 >      } else if (i->second.type() ==  typeid(std::vector<Token>)){
378 >        bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
379 >        i->second =  bs; /**@todo fixme */
380 >        return bs;
381 >      }
382 >    } else {
383 >      unrecognizedIdentifier(variable);
384 >    }
385 >    
386 >    return bs;
387 >  }
388 >  
389 >  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){    
390 >    return nameFinder.match(name);    
391 >  }    
392  
393 <  void SelectionEvaluator::predefine(Token[] statement) {
394 <    String variable = (String)statement[1].value;
395 <    variables.put(variable, statement);
393 >  bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){
394 >    std::vector<Token>::const_iterator i;
395 >    for (i = tokens.begin(); i != tokens.end(); ++i) {
396 >      if (i->tok & Token::dynamic) {
397 >        return true;
398 >      }
399 >    }
400 >    
401 >    return false;
402 >  }    
403 >
404 >  void SelectionEvaluator::clearDefinitionsAndLoadPredefined() {
405 >    variables.clear();
406 >    //load predefine
407 >    //predefine();
408    }
409  
410 <  void SelectionEvaluator::select(){
411 <    // NOTE this is called by restrict()
412 <    if (statementLength == 1) {
413 <      viewer.selectAll();
414 <      if (!viewer.getRasmolHydrogenSetting())
311 <        viewer.excludeSelectionSet(getHydrogenSet());
312 <      if (!viewer.getRasmolHeteroSetting())
313 <        viewer.excludeSelectionSet(getHeteroSet());
314 <    } else {
315 <      viewer.setSelectionSet(expression(statement, 1));
410 >  OpenMDBitSet SelectionEvaluator::evaluate() {
411 >    OpenMDBitSet bs(nStuntDouble);
412 >    if (isLoaded_) {
413 >      pc = 0;
414 >      instructionDispatchLoop(bs);
415      }
416 <    viewer.scriptStatus("" + viewer.getSelectionCount() + " atoms selected");
416 >
417 >    return bs;
418    }
419 <  
420 <  }
419 >
420 >  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
421 >    OpenMDBitSet bs(nStuntDouble);
422 >
423 >    if (value.type() == typeid(int)) {
424 >      int index = boost::any_cast<int>(value);
425 >      if (index < 0 || index >= bs.size()) {
426 >        invalidIndex(index);
427 >      } else {
428 >        bs = indexFinder.find(index);
429 >      }
430 >    } else if (value.type() == typeid(std::pair<int, int>)) {
431 >      std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
432 >      assert(indexRange.first <= indexRange.second);
433 >      if (indexRange.first < 0 || indexRange.second >= bs.size()) {
434 >        invalidIndexRange(indexRange);
435 >      }else {
436 >        bs = indexFinder.find(indexRange.first, indexRange.second);
437 >      }
438 >    }
439 >
440 >    return bs;
441 >  }
442 >
443 >
444 >  RealType SelectionEvaluator::getCharge(Atom* atom) {
445 >    RealType charge =0.0;
446 >    AtomType* atomType = atom->getAtomType();
447 >    if (atomType->isCharge()) {
448 >      GenericData* data = atomType->getPropertyByName("Charge");
449 >      if (data != NULL) {
450 >        DoubleGenericData* doubleData= dynamic_cast<DoubleGenericData*>(data);
451 >
452 >        if (doubleData != NULL) {
453 >          charge = doubleData->getData();
454 >
455 >        } else {
456 >          sprintf( painCave.errMsg,
457 >                   "Can not cast GenericData to DoubleGenericData\n");
458 >          painCave.severity = OPENMD_ERROR;
459 >          painCave.isFatal = 1;
460 >          simError();          
461 >        }
462 >      }
463 >    }
464 >
465 >    return charge;
466 >  }
467 >
468 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines