ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/io/TorsionTypesSectionParser.cpp
Revision: 1801
Committed: Tue Nov 30 04:43:29 2004 UTC (19 years, 7 months ago) by tim
File size: 5102 byte(s)
Log Message:
Section Parsers get compiled

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/TorsionTypesSectionParser.hpp"
27 #include "types/TorsionType.hpp"
28 #include "types/CubicTorsionType.hpp"
29 #include "types/QuarticTorsionType.hpp"
30 #include "types/PolynomialTorsionType.hpp"
31 #include "types/CharmmTorsionType.hpp"
32 #include "UseTheForce/ForceField.hpp"
33
34 namespace oopse {
35
36 TorsionTypesSectionParser::TorsionTypesSectionParser() {
37 setSectionName("TorsionTypes");
38
39
40 stringToEnumMap_["Cubic"] = ttCubic;
41 stringToEnumMap_["Quartic"] = ttQuartic;
42 stringToEnumMap_["Polynomial"] = ttPolynomial;
43 stringToEnumMap_["Charmm"] = ttCharmm;
44
45 }
46
47 void TorsionTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
48 StringTokenizer tokenizer(line);
49 TorsionType* torsionType = NULL;
50
51 int nTokens = tokenizer.countTokens();
52
53 if (nTokens < 5) {
54
55 return;
56 }
57
58 std::string at1 = tokenizer.nextToken();
59 std::string at2 = tokenizer.nextToken();
60 std::string at3 = tokenizer.nextToken();
61 std::string at4 = tokenizer.nextToken();
62 TorsionTypeEnum tt = getTorsionTypeEnum(tokenizer.nextToken());
63
64 nTokens -= 5;
65
66 switch(tt) {
67
68 case TorsionTypesSectionParser::ttCubic :
69 if (nTokens < 4) {
70
71 } else {
72
73 double k3 = tokenizer.nextTokenAsDouble();
74 double k2 = tokenizer.nextTokenAsDouble();
75 double k1 = tokenizer.nextTokenAsDouble();
76 double k0 = tokenizer.nextTokenAsDouble();
77
78 torsionType = new CubicTorsionType(k3, k2, k1, k0);
79 }
80 break;
81
82 case TorsionTypesSectionParser::ttQuartic:
83 if (nTokens < 5) {
84
85 } else {
86
87 double k4 = tokenizer.nextTokenAsDouble();
88 double k3 = tokenizer.nextTokenAsDouble();
89 double k2 = tokenizer.nextTokenAsDouble();
90 double k1 = tokenizer.nextTokenAsDouble();
91 double k0 = tokenizer.nextTokenAsDouble();
92
93 torsionType = new QuarticTorsionType( k4, k3, k2, k1, k0);
94 }
95 break;
96
97
98 case TorsionTypesSectionParser::ttPolynomial:
99 if (nTokens < 2 || nTokens % 2 != 0) {
100
101 } else {
102 int nPairs = nTokens / 2;
103 int power;
104 double coefficient;
105 PolynomialTorsionType* ptt = new PolynomialTorsionType();
106
107 for (int i = 0; i < nPairs; ++i) {
108 power = tokenizer.nextTokenAsInt();
109 coefficient = tokenizer.nextTokenAsDouble();
110 ptt->setCoefficient(power, coefficient);
111 }
112 }
113
114 break;
115
116 case TorsionTypesSectionParser::ttCharmm:
117
118 if (nTokens < 3 || nTokens % 3 != 0) {
119
120 } else {
121 int nSets = nTokens / 3;
122
123 CharmmTorsionType* ctt = new CharmmTorsionType();
124
125 for (int i = 0; i < nSets; ++i) {
126 double kchi = tokenizer.nextTokenAsDouble();
127 int n = tokenizer.nextTokenAsInt();
128 double delta = tokenizer.nextTokenAsDouble();
129
130 ctt->setCharmmTorsionParameter(kchi, n, delta);
131 }
132 }
133
134 break;
135
136 case TorsionTypesSectionParser::ttUnknown :
137 default:
138
139 break;
140
141 }
142
143 if (torsionType != NULL) {
144 ff.addTorsionType(at1, at2, at3, at4, torsionType);
145 }
146
147 }
148
149 TorsionTypesSectionParser::TorsionTypeEnum TorsionTypesSectionParser::getTorsionTypeEnum(const std::string& str) {
150 std::map<std::string, TorsionTypeEnum>::iterator i;
151 i = stringToEnumMap_.find(str);
152
153 return i == stringToEnumMap_.end() ? TorsionTypesSectionParser::ttUnknown : i->second;
154 }
155
156 } //end namespace oopse
157
158
159