1 |
tim |
1740 |
/* |
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 |
gezelter |
1490 |
|
26 |
tim |
1740 |
#include "UseTheForce/LJFF.hpp" |
27 |
gezelter |
1634 |
#include "UseTheForce/DarkSide/lj_interface.h" |
28 |
gezelter |
1490 |
|
29 |
tim |
1740 |
namespace oopse { |
30 |
gezelter |
1490 |
|
31 |
tim |
1740 |
//definition of createLJFF |
32 |
|
|
ForceField* createLJFF() { |
33 |
|
|
return new LJFF(); |
34 |
|
|
} |
35 |
gezelter |
1490 |
|
36 |
tim |
1740 |
//register createLJFF to ForceFieldCreator |
37 |
|
|
ForceFieldFactory::getInstance()->registerForceField("LJFF", createLJFF); |
38 |
gezelter |
1490 |
|
39 |
tim |
1740 |
void LJFF::parse(const std::string& filename) { |
40 |
|
|
ifstrstream* ffStream; |
41 |
|
|
ffStream = openForceFiledFile(filename); |
42 |
|
|
const int bufferSize = 65535; |
43 |
|
|
char line[bufferSize]; |
44 |
|
|
AtomType* atomType; |
45 |
|
|
std::string atomTypeName; |
46 |
gezelter |
1490 |
double mass; |
47 |
tim |
1740 |
double epsilon; |
48 |
gezelter |
1490 |
double sigma; |
49 |
tim |
1740 |
int status; |
50 |
|
|
int ident = 1; //ident begins from 1 (c++ does not need to know it, fortran's index begins from 1) |
51 |
|
|
int lineNo = 0; |
52 |
gezelter |
1490 |
|
53 |
tim |
1740 |
ffStream.getline(line, bufferSize); |
54 |
|
|
while( !ffStream.eof() ){ |
55 |
|
|
++lineNo; |
56 |
gezelter |
1490 |
|
57 |
tim |
1740 |
//a line begins with '#' or '!' is comment which is skipped |
58 |
|
|
if (line[0] != '#' ||line[0] != '!') { |
59 |
|
|
StringTokenizer tokenizer(line); |
60 |
|
|
|
61 |
|
|
if (tokenizer.countToken() >= 4) { |
62 |
|
|
atomTypeName = tokenizer.nextToken(); |
63 |
|
|
mass = tokenizer.nextTokenAsFloat(); |
64 |
|
|
epsilon = tokenizer.nextTokenAsFloat(); |
65 |
|
|
sigma = tokenizer.nextTokenAsFloat(); |
66 |
gezelter |
1490 |
|
67 |
tim |
1740 |
atomType = new AtomType(); |
68 |
|
|
atomType->setName(atomTypeName); |
69 |
|
|
atomType->setMass(mass); |
70 |
|
|
|
71 |
|
|
//by default, all of the properties in AtomTypeProperties is set to 0 |
72 |
|
|
//In Lennard-Jones Force Field, we only need to set Lennard-Jones to true |
73 |
|
|
atomType->setLennardJones(); |
74 |
gezelter |
1490 |
|
75 |
tim |
1740 |
atomType->setIdent(ident); |
76 |
|
|
atomType->addProperty(new DoubleGenericData("Epsilon", epsilon)); |
77 |
|
|
atomType->addProperty(new DoubleGenericData("Sigma", sigma)); |
78 |
|
|
atomType->complete(); |
79 |
|
|
//notify a new LJtype atom type is created |
80 |
|
|
newLJtype(&ident, &sigma, &epsilon, &status); |
81 |
gezelter |
1490 |
|
82 |
tim |
1740 |
//add atom type to AtomTypeContainer |
83 |
|
|
addAtomType(atomTypeName, atomType); |
84 |
|
|
++ident; |
85 |
|
|
|
86 |
|
|
} else { |
87 |
|
|
sprintf( painCave.errMsg, |
88 |
|
|
"Not enough tokens when parsing Lennard-Jones Force Field : %s\n" |
89 |
|
|
"in line %d : %s\n", |
90 |
|
|
filename.c_str(), lineNo, line); |
91 |
|
|
painCave.severity = OOPSE_ERROR; |
92 |
|
|
painCave.isFatal = 1; |
93 |
|
|
simError(); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
} |
97 |
gezelter |
1490 |
|
98 |
tim |
1740 |
ffStream.getline(line, bufferSize); |
99 |
gezelter |
1490 |
} |
100 |
|
|
|
101 |
tim |
1740 |
delete ffStream; |
102 |
gezelter |
1490 |
} |
103 |
|
|
|
104 |
|
|
|
105 |
tim |
1740 |
} //end namespace oopse |