ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/io/MetalNonMetalInteractionsSectionParser.cpp
Revision: 1162
Committed: Thu Jul 12 23:21:00 2007 UTC (17 years, 9 months ago) by chuckv
File size: 6312 byte(s)
Log Message:
More changes to MnM.

File Contents

# Content
1 /*
2 * Copyright (c) 2007 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
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
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 */
41
42 #include "io/MetalNonMetalInteractionsSectionParser.hpp"
43 #include "types/AtomType.hpp"
44 #include "types/ShiftedMorseInteractionType.hpp"
45 #include "types/MAWInteractionType.hpp"
46 #include "types/LennardJonesInteractionType.hpp"
47 #include "types/RepulsiveMorseInteractionType.hpp"
48 #include "UseTheForce/ForceField.hpp"
49 #include "utils/simError.h"
50 namespace oopse {
51
52 MetalNonMetalInteractionsSectionParser::MetalNonMetalInteractionsSectionParser(ForceFieldOptions& options) : options_(options){
53 setSectionName("MetalNonMetalInteractions");
54
55 stringToEnumMap_["MAW"] = MAW;
56 stringToEnumMap_["ShiftedMorse"] = ShiftedMorse;
57 stringToEnumMap_["LennardJones"] = LennardJones;
58 stringToEnumMap_["RepulsiveMorse"] = LennardJones;
59
60 }
61
62 void MetalNonMetalInteractionsSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
63 StringTokenizer tokenizer(line);
64 NonBondedInteractionType* nbiType = NULL;
65 int nTokens = tokenizer.countTokens();
66
67 if (nTokens < 3) {
68 sprintf(painCave.errMsg, "MetalNonMetalInteractionsSectionParser Error: Not enough tokens at line %d\n",
69 lineNo);
70 painCave.isFatal = 1;
71 simError();
72 }
73
74 std::string at1 = tokenizer.nextToken();
75 std::string at2 = tokenizer.nextToken();
76 MetalNonMetalInteractionTypeEnum nbit = getMetalNonMetalInteractionTypeEnum(tokenizer.nextToken());
77 nTokens -= 3;
78 NonBondedInteractionType* interactionType;
79
80 //switch is a nightmare to maintain
81 switch(nbit) {
82 case MAW :
83 if (nTokens < 6) {
84 sprintf(painCave.errMsg, "MetalNonMetalInteractionsSectionParser Error: Not enough tokens at line %d\n",
85 lineNo);
86 painCave.isFatal = 1;
87 simError();
88 } else {
89 RealType r0 = tokenizer.nextTokenAsDouble();
90 RealType D0 = tokenizer.nextTokenAsDouble();
91 RealType beta0 = tokenizer.nextTokenAsDouble();
92 RealType betaH = tokenizer.nextTokenAsDouble();
93 RealType gamma = tokenizer.nextTokenAsDouble();
94 RealType alpha = tokenizer.nextTokenAsDouble();
95 interactionType = new MAWInteractionType(D0, beta0, r0, betaH, gamma, alpha);
96 }
97 break;
98
99 case ShiftedMorse :
100 if (nTokens < 3) {
101 sprintf(painCave.errMsg, "MetalNonMetalInteractionsSectionParser Error: Not enough tokens at line %d\n",
102 lineNo);
103 painCave.isFatal = 1;
104 simError();
105 } else {
106 RealType r0 = tokenizer.nextTokenAsDouble();
107 RealType D0 = tokenizer.nextTokenAsDouble();
108 RealType beta0 = tokenizer.nextTokenAsDouble();
109 interactionType = new ShiftedMorseInteractionType(D0, beta0, r0);
110 }
111 break;
112
113 case RepulsiveMorse :
114 if (nTokens < 3) {
115 sprintf(painCave.errMsg, "MetalNonMetalInteractionsSectionParser Error: Not enough tokens at line %d\n",
116 lineNo);
117 painCave.isFatal = 1;
118 simError();
119 } else {
120 RealType r0 = tokenizer.nextTokenAsDouble();
121 RealType D0 = tokenizer.nextTokenAsDouble();
122 RealType beta0 = tokenizer.nextTokenAsDouble();
123 interactionType = new RepulsiveMorseInteractionType(D0, beta0, r0);
124 }
125 break;
126
127 case LennardJones :
128 if (nTokens < 2) {
129 sprintf(painCave.errMsg, "MetalNonMetalInteractionsSectionParser Error: Not enough tokens at line %d\n",
130 lineNo);
131 painCave.isFatal = 1;
132 simError();
133 } else {
134 RealType sigma = tokenizer.nextTokenAsDouble();
135 RealType epsilon = tokenizer.nextTokenAsDouble();
136 interactionType = new LennardJonesInteractionType(sigma, epsilon);
137 }
138 break;
139
140 case Unknown :
141 default:
142 sprintf(painCave.errMsg, "MetalNonMetalInteractionsSectionParser Error: Unknown Interaction Type at line %d\n",
143 lineNo);
144 painCave.isFatal = 1;
145 simError();
146
147 break;
148
149 }
150
151 if (interactionType != NULL) {
152 ff.addNonBondedInteractionType(at1, at2, interactionType);
153 }
154
155 }
156
157 MetalNonMetalInteractionsSectionParser::MetalNonMetalInteractionTypeEnum MetalNonMetalInteractionsSectionParser::getMetalNonMetalInteractionTypeEnum(const std::string& str) {
158 std::map<std::string, MetalNonMetalInteractionTypeEnum>::iterator i;
159 i = stringToEnumMap_.find(str);
160
161 return i == stringToEnumMap_.end() ? Unknown : i->second;
162 }
163
164 } //end namespace oopse
165