ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/io/BondTypesSectionParser.cpp
Revision: 1800
Committed: Tue Nov 30 04:14:43 2004 UTC (19 years, 8 months ago) by tim
File size: 4694 byte(s)
Log Message:
minor fixed

File Contents

# Content
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 std::string at1;
48 std::string at2;
49 std::string bt;
50 BondType* bondType = NULL;
51 double b0;
52
53 int nTokens = tokenizer.countTokens();
54
55 if (nTokens < 4) {
56
57 return;
58 }
59
60 at1 = tokenizer.nextToken();
61 at2 = tokenizer.nextToken();
62 BondTypeEnum bt = getTorsionTypeEnum(tokenizer.nextToken());
63 b0 = tokenizer.nextTokenAsDouble();
64 nTokens -= 4;
65
66 //switch is a maintain nightmare
67 switch(bt) {
68 case btFixed :
69 bondType = new FixedBondType();
70 break;
71
72 case btHarmonic :
73 if (nTokens < 1) {
74
75 } else {
76
77 double kb = tokenizer.nextTokenAsDouble();
78 bondType = new HarmonicBondType(b0, kb);
79 }
80
81 break;
82
83 case btCubic :
84 if (nTokens < 4) {
85
86 } else {
87
88 double k3 = tokenizer.nextTokenAsDouble();
89 double k2 = tokenizer.nextTokenAsDouble();
90 double k1 = tokenizer.nextTokenAsDouble();
91 double k0 = tokenizer.nextTokenAsDouble();
92
93 bondType = new CubicBondType(b0, k3, k2, k1, k0);
94 }
95 break;
96
97 case btQuartic :
98 if (nTokens < 5) {
99
100 } else {
101
102 b0 = tokenizer.nextTokenAsDouble();
103 double k4 = tokenizer.nextTokenAsDouble();
104 double k3 = tokenizer.nextTokenAsDouble();
105 double k2 = tokenizer.nextTokenAsDouble();
106 double k1 = tokenizer.nextTokenAsDouble();
107 double k0 = tokenizer.nextTokenAsDouble();
108
109 bondType = new QuarticBondType(b0, k4, k3, k2, k1, k0);
110 }
111 break;
112
113 case btPolynomial :
114 if (nTokens < 2 || nTokens % 2 != 0) {
115
116 } else {
117 int nPairs = nTokens / 2;
118 int power;
119 double coefficient;
120 PolynomialBondType pbt = new PolynomialBondType();
121
122 for (int i = 0; i < nPairs; ++i) {
123 power = tokenizer.nextTokenAsInt();
124 coefficient = tokenizer.nextTokenAsDouble();
125 pbt->setCoefficient(power, coefficient);
126 }
127 }
128
129 break;
130
131 default:
132
133 }
134
135 if (bondType != NULL) {
136 ff.addBondType(at1, at2, bondType);
137 }
138
139 }
140
141 BondTypeEnum BondTypesSectionParser::getTorsionTypeEnum(const std::string& str) {
142 std::map<std::string, BondTypeEnum>::iterator i;
143 i = stringToEnumMap_.find(str);
144
145 return i == stringToEnumMap_.end() ? TorsionTypesSectionParser::ttUnknown : i->second;
146 }
147
148 } //end namespace oopse
149