ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/BondTypesSectionParser.cpp
Revision: 1957
Committed: Tue Jan 25 17:45:23 2005 UTC (19 years, 5 months ago) by tim
File size: 6815 byte(s)
Log Message:
(1) complete section parser's error message
(2) add GhostTorsion
(3) accumulate inertial tensor from the directional atoms before calculate rigidbody's inertial tensor

File Contents

# Content
1 /*
2 * Copyright (c) 2005 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/BondTypesSectionParser.hpp"
43 #include "types/FixedBondType.hpp"
44 #include "types/HarmonicBondType.hpp"
45 #include "types/CubicBondType.hpp"
46 #include "types/QuarticBondType.hpp"
47 #include "types/PolynomialBondType.hpp"
48 #include "UseTheForce/ForceField.hpp"
49 #include "utils/simError.h"
50 namespace oopse {
51
52 BondTypesSectionParser::BondTypesSectionParser() {
53 setSectionName("BondTypes");
54
55 stringToEnumMap_["Fixed"] = btFixed;
56 stringToEnumMap_["Harmonic"] = btHarmonic;
57 stringToEnumMap_["Cubic"] = btCubic;
58 stringToEnumMap_["Quartic"] = btQuartic;
59 stringToEnumMap_["Polynomial"] = btPolynomial;
60 }
61
62 void BondTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
63 StringTokenizer tokenizer(line);
64 BondType* bondType = NULL;
65 int nTokens = tokenizer.countTokens();
66
67 if (nTokens < 4) {
68 sprintf(painCave.errMsg, "BondTypesSectionParser 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 BondTypeEnum bt = getBondTypeEnum(tokenizer.nextToken());
77 double b0 = tokenizer.nextTokenAsDouble();
78 nTokens -= 4;
79
80 //switch is a maintain nightmare
81 switch(bt) {
82 case btFixed :
83 bondType = new FixedBondType(b0);
84 break;
85
86 case btHarmonic :
87 if (nTokens < 1) {
88 sprintf(painCave.errMsg, "BondTypesSectionParser Error: Not enough tokens at line %d\n",
89 lineNo);
90 painCave.isFatal = 1;
91 simError();
92 } else {
93
94 double kb = tokenizer.nextTokenAsDouble();
95 bondType = new HarmonicBondType(b0, kb);
96 }
97
98 break;
99
100 case btCubic :
101 if (nTokens < 4) {
102 sprintf(painCave.errMsg, "BondTypesSectionParser Error: Not enough tokens at line %d\n",
103 lineNo);
104 painCave.isFatal = 1;
105 simError();
106 } else {
107
108 double k3 = tokenizer.nextTokenAsDouble();
109 double k2 = tokenizer.nextTokenAsDouble();
110 double k1 = tokenizer.nextTokenAsDouble();
111 double k0 = tokenizer.nextTokenAsDouble();
112
113 bondType = new CubicBondType(b0, k3, k2, k1, k0);
114 }
115 break;
116
117 case btQuartic :
118 if (nTokens < 5) {
119
120 sprintf(painCave.errMsg, "BondTypesSectionParser Error: Not enough tokens at line %d\n",
121 lineNo);
122 painCave.isFatal = 1;
123 simError();
124
125 } else {
126
127 b0 = tokenizer.nextTokenAsDouble();
128 double k4 = tokenizer.nextTokenAsDouble();
129 double k3 = tokenizer.nextTokenAsDouble();
130 double k2 = tokenizer.nextTokenAsDouble();
131 double k1 = tokenizer.nextTokenAsDouble();
132 double k0 = tokenizer.nextTokenAsDouble();
133
134 bondType = new QuarticBondType(b0, k4, k3, k2, k1, k0);
135 }
136 break;
137
138 case btPolynomial :
139 if (nTokens < 2 || nTokens % 2 != 0) {
140 sprintf(painCave.errMsg, "BondTypesSectionParser Error: Not enough tokens at line %d\n",
141 lineNo);
142 painCave.isFatal = 1;
143 simError();
144
145 } else {
146 int nPairs = nTokens / 2;
147 int power;
148 double coefficient;
149 PolynomialBondType* pbt = new PolynomialBondType(b0);
150
151 for (int i = 0; i < nPairs; ++i) {
152 power = tokenizer.nextTokenAsInt();
153 coefficient = tokenizer.nextTokenAsDouble();
154 pbt->setCoefficient(power, coefficient);
155 }
156 }
157
158 break;
159
160 case btUnknown :
161 default:
162 sprintf(painCave.errMsg, "BondTypesSectionParser Error: Unknown Bond Type at line %d\n",
163 lineNo);
164 painCave.isFatal = 1;
165 simError();
166
167 break;
168
169 }
170
171 if (bondType != NULL) {
172 ff.addBondType(at1, at2, bondType);
173 }
174
175 }
176
177 BondTypesSectionParser::BondTypeEnum BondTypesSectionParser::getBondTypeEnum(const std::string& str) {
178 std::map<std::string, BondTypeEnum>::iterator i;
179 i = stringToEnumMap_.find(str);
180
181 return i == stringToEnumMap_.end() ? btUnknown : i->second;
182 }
183
184 } //end namespace oopse
185