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: 1768
Committed: Tue Nov 23 04:35:55 2004 UTC (19 years, 7 months ago) by tim
File size: 3899 byte(s)
Log Message:
add BondTypesSectionParser, BendTypesSectionParser and TorsionTypeSectionParser

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
28 namespace oopse {
29
30 BondTypesSectionParser::BondTypesSectionParser() {
31 setSectionName("BondTypes");
32 }
33
34 void BondTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
35 StringTokenizer tokenizer(line);
36 std::string at1;
37 std::string at2;
38 std::string bt;
39 BondType* bondType = NULL;
40 double b0;
41
42 int nTokens = tokenizer.countTokens();
43
44 if (nTokens < 4) {
45
46 return;
47 }
48
49 at1 = tokenizer.nextToken();
50 at2 = tokenizer.nextToken();
51 bt = tokenizer.nextToken();
52 b0 = tokenizer.nextTokenAsDouble();
53 nTokens -= 4;
54
55 //switch is a maintain nightmare
56 switch(bt) {
57 case "Fixed" :
58 bondType = new FixedBondType();
59 break;
60
61 case "Harmonic" :
62 if (nTokens < 1) {
63
64 } else {
65
66 double kb = tokenizer.nextTokenAsDouble();
67 bondType = new HarmonicBondType(b0, kb);
68 }
69
70 break;
71
72 case "Cubic" :
73 if (nTokens < 4) {
74
75 } else {
76
77 double k3 = tokenizer.nextTokenAsDouble();
78 double k2 = tokenizer.nextTokenAsDouble();
79 double k1 = tokenizer.nextTokenAsDouble();
80 double k0 = tokenizer.nextTokenAsDouble();
81
82 bondType = new CubicBondType(b0, k3, k2, k1, k0);
83 }
84 break;
85
86 case "Quartic" :
87 if (nTokens < 5) {
88
89 } else {
90
91 b0 = tokenizer.nextTokenAsDouble();
92 double k4 = tokenizer.nextTokenAsDouble();
93 double k3 = tokenizer.nextTokenAsDouble();
94 double k2 = tokenizer.nextTokenAsDouble();
95 double k1 = tokenizer.nextTokenAsDouble();
96 double k0 = tokenizer.nextTokenAsDouble();
97
98 bondType = new QuadraticBondType(b0, k4, k3, k2, k1, k0);
99 }
100 break;
101
102 case "Polynomial" :
103 if (nTokens < 2 || nTokens % 2 != 0) {
104
105 } else {
106 int nPairs = nTokens / 2;
107 int power;
108 double coefficient;
109 PolynomialBondType pbt = new PolynomialBondType();
110
111 for (int i = 0; i < nPairs; ++i) {
112 power = tokenizer.nextTokenAsInt();
113 coefficient = tokenizer.nextTokenAsDouble();
114 pbt->setCoefficient(power, coefficient);
115 }
116 }
117
118 break;
119
120 default:
121
122 }
123
124 if (bondType != NULL) {
125 ff.addBondType(at1, at2, bondType);
126 }
127
128 }
129
130 } //end namespace oopse
131