1 |
/* |
2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
* |
4 |
* Contact: oopse@oopse.org |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public License |
8 |
* as published by the Free Software Foundation; either version 2.1 |
9 |
* of the License, or (at your option) any later version. |
10 |
* All we ask is that proper credit is given for our work, which includes |
11 |
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
* of your source code files, and to any copyright notice that you may distribute |
13 |
* with programs based on this work. |
14 |
* |
15 |
* This program is distributed in the hope that it will be useful, |
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* GNU Lesser General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU Lesser General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
* |
24 |
*/ |
25 |
|
26 |
#include "io/BondTypesSectionParser.hpp" |
27 |
#include "types/FixedBondType.hpp" |
28 |
#include "types/HarmonicBondType.hpp" |
29 |
#include "types/CubicBondType.hpp" |
30 |
#include "types/QuarticBondType.hpp" |
31 |
#include "types/PolynomialBondType.hpp" |
32 |
#include "UseTheForce/ForceField.hpp" |
33 |
namespace oopse { |
34 |
|
35 |
BondTypesSectionParser::BondTypesSectionParser() { |
36 |
setSectionName("BondTypes"); |
37 |
|
38 |
stringToEnumMap_["Fixed"] = btFixed; |
39 |
stringToEnumMap_["Harmonic"] = btHarmonic; |
40 |
stringToEnumMap_["Cubic"] = btCubic; |
41 |
stringToEnumMap_["Quartic"] = btQuartic; |
42 |
stringToEnumMap_["Polynomial"] = btPolynomial; |
43 |
} |
44 |
|
45 |
void BondTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
46 |
StringTokenizer tokenizer(line); |
47 |
BondType* bondType = NULL; |
48 |
int nTokens = tokenizer.countTokens(); |
49 |
|
50 |
if (nTokens < 4) { |
51 |
|
52 |
return; |
53 |
} |
54 |
|
55 |
std::string at1 = tokenizer.nextToken(); |
56 |
std::string at2 = tokenizer.nextToken(); |
57 |
BondTypeEnum bt = getBondTypeEnum(tokenizer.nextToken()); |
58 |
double b0 = tokenizer.nextTokenAsDouble(); |
59 |
nTokens -= 4; |
60 |
|
61 |
//switch is a maintain nightmare |
62 |
switch(bt) { |
63 |
case btFixed : |
64 |
bondType = new FixedBondType(b0); |
65 |
break; |
66 |
|
67 |
case btHarmonic : |
68 |
if (nTokens < 1) { |
69 |
|
70 |
} else { |
71 |
|
72 |
double kb = tokenizer.nextTokenAsDouble(); |
73 |
bondType = new HarmonicBondType(b0, kb); |
74 |
} |
75 |
|
76 |
break; |
77 |
|
78 |
case btCubic : |
79 |
if (nTokens < 4) { |
80 |
|
81 |
} else { |
82 |
|
83 |
double k3 = tokenizer.nextTokenAsDouble(); |
84 |
double k2 = tokenizer.nextTokenAsDouble(); |
85 |
double k1 = tokenizer.nextTokenAsDouble(); |
86 |
double k0 = tokenizer.nextTokenAsDouble(); |
87 |
|
88 |
bondType = new CubicBondType(b0, k3, k2, k1, k0); |
89 |
} |
90 |
break; |
91 |
|
92 |
case btQuartic : |
93 |
if (nTokens < 5) { |
94 |
|
95 |
} else { |
96 |
|
97 |
b0 = tokenizer.nextTokenAsDouble(); |
98 |
double k4 = tokenizer.nextTokenAsDouble(); |
99 |
double k3 = tokenizer.nextTokenAsDouble(); |
100 |
double k2 = tokenizer.nextTokenAsDouble(); |
101 |
double k1 = tokenizer.nextTokenAsDouble(); |
102 |
double k0 = tokenizer.nextTokenAsDouble(); |
103 |
|
104 |
bondType = new QuarticBondType(b0, k4, k3, k2, k1, k0); |
105 |
} |
106 |
break; |
107 |
|
108 |
case btPolynomial : |
109 |
if (nTokens < 2 || nTokens % 2 != 0) { |
110 |
|
111 |
} else { |
112 |
int nPairs = nTokens / 2; |
113 |
int power; |
114 |
double coefficient; |
115 |
PolynomialBondType* pbt = new PolynomialBondType(b0); |
116 |
|
117 |
for (int i = 0; i < nPairs; ++i) { |
118 |
power = tokenizer.nextTokenAsInt(); |
119 |
coefficient = tokenizer.nextTokenAsDouble(); |
120 |
pbt->setCoefficient(power, coefficient); |
121 |
} |
122 |
} |
123 |
|
124 |
break; |
125 |
|
126 |
case btUnknown : |
127 |
default: |
128 |
break; |
129 |
|
130 |
} |
131 |
|
132 |
if (bondType != NULL) { |
133 |
ff.addBondType(at1, at2, bondType); |
134 |
} |
135 |
|
136 |
} |
137 |
|
138 |
BondTypesSectionParser::BondTypeEnum BondTypesSectionParser::getBondTypeEnum(const std::string& str) { |
139 |
std::map<std::string, BondTypeEnum>::iterator i; |
140 |
i = stringToEnumMap_.find(str); |
141 |
|
142 |
return i == stringToEnumMap_.end() ? btUnknown : i->second; |
143 |
} |
144 |
|
145 |
} //end namespace oopse |
146 |
|