1 |
tim |
1769 |
/* |
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/EAMAtomTypesSectionParser.hpp" |
27 |
|
|
|
28 |
|
|
namespace oopse { |
29 |
|
|
|
30 |
|
|
EAMAtomTypesSectionParser::EAMAtomTypesSectionParser() { |
31 |
|
|
setSectionName("EAMAtomTypes"); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
void EAMAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
35 |
|
|
AtomType* atomType; |
36 |
|
|
std::string atomTypeName; |
37 |
|
|
double mass; |
38 |
|
|
StringTokenizer tokenizer(line); |
39 |
|
|
|
40 |
|
|
if (tokenizer.countTokens() >= 2) { |
41 |
|
|
atomTypeName = tokenizer.nextToken(); |
42 |
|
|
std::string potentialParamFile = tokenizer.nextToken(); |
43 |
|
|
|
44 |
|
|
AtomType* atomType = ff.getAtomType(atomTypeName); |
45 |
|
|
if (atomType != NULL) { |
46 |
|
|
atomType->setEAM(); |
47 |
|
|
parseEAMParamFile(atomType, potentialParamFile, atomType->getIdent()); |
48 |
|
|
} else { |
49 |
|
|
|
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
} else { |
53 |
|
|
sprintf( painCave.errMsg, |
54 |
|
|
"Not enough tokens when parsing EAM Force Field : %s\n" |
55 |
|
|
"in line %d : %s\n", |
56 |
|
|
filename.c_str(), lineNo, line); |
57 |
|
|
painCave.severity = OOPSE_ERROR; |
58 |
|
|
painCave.isFatal = 1; |
59 |
|
|
simError(); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void EAMAtomTypesSectionParser::parseEAMParamFile(AtomType* atomType, |
66 |
|
|
const std::string& potentialParamFile, int ident) { |
67 |
|
|
|
68 |
|
|
ifstrstream* ppfStream; |
69 |
|
|
ppfStream = openForceFiledFile(potentialParamFile); |
70 |
|
|
const int bufferSize = 65535; |
71 |
|
|
char buffer[bufferSize]; |
72 |
|
|
std::string line; |
73 |
|
|
|
74 |
|
|
//skip first line |
75 |
|
|
ppfStream->getline(buffer, bufferSize); |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
//The Second line contains atomic number, atomic mass, a lattice constant and lattic type |
79 |
|
|
int junk; |
80 |
|
|
double mass; |
81 |
|
|
double latticeConstant; |
82 |
|
|
std::string lattice; |
83 |
|
|
if (ppfStream->getline(buffer, bufferSize)) { |
84 |
|
|
StringTokenizer tokenizer1(buffer); |
85 |
|
|
ident = tokenizer1.nextTokenAsInt(); |
86 |
|
|
|
87 |
|
|
if (tokenizer1.countTokens() >= 4) { |
88 |
|
|
junk = tokenizer1.nextTokenAsInt(); |
89 |
|
|
mass = tokenizer1.nextTokenAsDouble(); |
90 |
|
|
latticeConstant = tokenizer1.nextTokenAsDouble(); |
91 |
|
|
lattice = tokenizer1.nextToken(); |
92 |
|
|
}else { |
93 |
|
|
std::cerr << "Not enought tokens" << std::endl; |
94 |
|
|
} |
95 |
|
|
} else { |
96 |
|
|
|
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
// The third line is nrho, drho, nr, dr and rcut |
100 |
|
|
EAMParam eamParam; |
101 |
|
|
eamParam.latticeConstant = latticeConstant; |
102 |
|
|
|
103 |
|
|
if (ppfStream->getline(buffer, bufferSize)) { |
104 |
|
|
StringTokenizer tokenizer2(buffer); |
105 |
|
|
|
106 |
|
|
if (tokenizer2.countTokens() >= 5){ |
107 |
|
|
eamParam.nrho = tokenizer2.nextTokenAsInt(); |
108 |
|
|
eamParam.drho = tokenizer2.nextTokenAsDouble(); |
109 |
|
|
eamParam.nr = tokenizer2.nextTokenAsInt(); |
110 |
|
|
eamParam.dr = tokenizer2.nextTokenAsDouble(); |
111 |
|
|
eamParam.rcut = tokenizer2.nextTokenAsDouble(); |
112 |
|
|
}else { |
113 |
|
|
std::cerr << "Not enought tokens" << std::endl; |
114 |
|
|
} |
115 |
|
|
} else { |
116 |
|
|
|
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
parseEAMArray(ppfStream, eamParam.rvals, eamParam.nr); |
120 |
|
|
parseEAMArray(ppfStream, eamParam.rhovals, eamParam.nr); |
121 |
|
|
parseEAMArray(ppfStream, eamParam.Frhovals, eamParam.nrho); |
122 |
|
|
|
123 |
|
|
atomType->addProperty(EAMParamGenericData("EAM", eamParam)); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
void EAMAtomTypesSectionParser::parseEAMArray(ifstrstream* ppfStream, |
127 |
|
|
std::vector<double>& array, int num) { |
128 |
|
|
|
129 |
|
|
const int dataPerLine = 5; |
130 |
|
|
if (num % dataPerLine != 0) { |
131 |
|
|
|
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
const int bufferSize = 65535; |
135 |
|
|
char buffer[bufferSize]; |
136 |
|
|
std::string line; |
137 |
|
|
int readLines = num/dataPerLine; |
138 |
|
|
int lineCount = 0; |
139 |
|
|
while(ffStream.getline(buffer, bufferSize) && lineCount < num){ |
140 |
|
|
|
141 |
|
|
StringTokenizer tokenizer(buffer); |
142 |
|
|
if (tokenizer.countTokens() >= dataPerLine) { |
143 |
tim |
1770 |
for (int i = 0; i < dataPerLine; ++i) { |
144 |
tim |
1769 |
array.push_back(tokenizer.nextTokenAsDouble())); |
145 |
|
|
} |
146 |
|
|
} else { |
147 |
|
|
|
148 |
|
|
} |
149 |
|
|
++lineCount; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
if (lineCount < num) { |
153 |
|
|
|
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
|
159 |
|
|
} //end namespace oopse |
160 |
|
|
|