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