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