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 "UseTheForce/LJFF.hpp" |
27 |
#include "UseTheForce/DarkSide/lj_interface.h" |
28 |
|
29 |
namespace oopse { |
30 |
|
31 |
//definition of createLJFF |
32 |
ForceField* createLJFF() { |
33 |
return new LJFF(); |
34 |
} |
35 |
|
36 |
//register createLJFF to ForceFieldCreator |
37 |
ForceFieldFactory::getInstance()->registerForceField("LJFF", createLJFF); |
38 |
|
39 |
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 |
double mass; |
47 |
double epsilon; |
48 |
double sigma; |
49 |
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 |
|
53 |
while(ffStream.getline(line, bufferSize)){ |
54 |
++lineNo; |
55 |
|
56 |
//a line begins with '#' or '!' is comment |
57 |
if (line[0] != '#' ||line[0] != '!') { |
58 |
StringTokenizer tokenizer(line); |
59 |
|
60 |
if (tokenizer.countToken() >= 4) { |
61 |
atomTypeName = tokenizer.nextToken(); |
62 |
mass = tokenizer.nextTokenAsDouble(); |
63 |
epsilon = tokenizer.nextTokenAsDouble(); |
64 |
sigma = tokenizer.nextTokenAsDouble(); |
65 |
|
66 |
atomType = new AtomType(); |
67 |
atomType->setName(atomTypeName); |
68 |
atomType->setMass(mass); |
69 |
|
70 |
//by default, all of the properties in AtomTypeProperties is set to 0 |
71 |
//In Lennard-Jones Force Field, we only need to set Lennard-Jones to true |
72 |
atomType->setLennardJones(); |
73 |
|
74 |
atomType->setIdent(ident); |
75 |
atomType->addProperty(new DoubleGenericData("Epsilon", epsilon)); |
76 |
atomType->addProperty(new DoubleGenericData("Sigma", sigma)); |
77 |
atomType->complete(); |
78 |
|
79 |
//notify fortran a new LJtype atom type is created |
80 |
newLJtype(&ident, &sigma, &epsilon, &status); |
81 |
|
82 |
//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 |
|
98 |
} |
99 |
|
100 |
delete ffStream; |
101 |
} |
102 |
|
103 |
|
104 |
} //end namespace oopse |