25 |
|
|
26 |
|
#include "UseTheForce/DUFF.hpp" |
27 |
|
#include "UseTheForce/DarkSide/lj_interface.h" |
28 |
+ |
#include "UseTheForce/DarkSide/charge_interface.h" |
29 |
+ |
#include "UseTheForce/DarkSide/dipole_interface.h" |
30 |
+ |
#include "UseTheForce/DarkSide/sticky_interface.h" |
31 |
+ |
#include "UseTheForce/ForceFieldFactory.hpp" |
32 |
+ |
#include "io/DirectionalAtomTypesSectionParser.hpp" |
33 |
+ |
#include "io/AtomTypesSectionParser.hpp" |
34 |
+ |
#include "io/LennardJonesAtomTypesSectionParser.hpp" |
35 |
+ |
#include "io/ElectrostaticAtomTypesSectionParser.hpp" |
36 |
+ |
#include "io/EAMAtomTypesSectionParser.hpp" |
37 |
+ |
#include "io/StickyAtomTypesSectionParser.hpp" |
38 |
+ |
#include "io/BondTypesSectionParser.hpp" |
39 |
+ |
#include "io/BendTypesSectionParser.hpp" |
40 |
+ |
#include "io/TorsionTypesSectionParser.hpp" |
41 |
+ |
#include "UseTheForce/ForceFieldCreator.hpp" |
42 |
|
|
43 |
|
namespace oopse { |
44 |
|
|
45 |
< |
//definition of createDUFF |
46 |
< |
ForceField* createDUFF() { |
47 |
< |
return new DUFF(); |
34 |
< |
} |
45 |
> |
//static ForceFieldBuilder<DUFF>* DUFFCreator = new ForceFieldBuilder<DUFF>("DUFF"); |
46 |
> |
|
47 |
> |
DUFF::DUFF(){ |
48 |
|
|
49 |
< |
//register createDUFF to ForceFieldCreator |
50 |
< |
ForceFieldFactory::getInstance()->registerForceField("DUFF", createDUFF); |
49 |
> |
//set default force field filename |
50 |
> |
setForceFieldFileName("DUFF.frc"); |
51 |
|
|
52 |
+ |
//the order of adding section parsers are important |
53 |
+ |
//DirectionalAtomTypesSectionParser should be added before AtomTypesSectionParser Since |
54 |
+ |
//These two section parsers will actually create "real" AtomTypes (AtomTypesSectionParser will create |
55 |
+ |
//AtomType and DirectionalAtomTypesSectionParser will creat DirectionalAtomType which is a subclass |
56 |
+ |
//of AtomType, therefore it should come first). Other AtomTypes Section Parser will not create the |
57 |
+ |
//"real" AtomType, they only add and set some attribute of the AtomType. Thus their order are not |
58 |
+ |
//important. AtomTypesSectionParser should be added before other atom type section parsers. |
59 |
+ |
//Make sure they are added after DirectionalAtomTypesSectionParser and AtomTypesSectionParser. |
60 |
+ |
//The order of BondTypesSectionParser, BendTypesSectionParser and TorsionTypesSectionParser are |
61 |
+ |
//not important. |
62 |
+ |
spMan_.push_back(new DirectionalAtomTypesSectionParser()); |
63 |
+ |
spMan_.push_back(new AtomTypesSectionParser()); |
64 |
+ |
spMan_.push_back(new LennardJonesAtomTypesSectionParser()); |
65 |
+ |
spMan_.push_back(new ElectrostaticAtomTypesSectionParser()); |
66 |
+ |
spMan_.push_back(new EAMAtomTypesSectionParser()); |
67 |
+ |
spMan_.push_back(new StickyAtomTypesSectionParser()); |
68 |
+ |
spMan_.push_back(new BondTypesSectionParser()); |
69 |
+ |
spMan_.push_back(new BendTypesSectionParser()); |
70 |
+ |
spMan_.push_back(new TorsionTypesSectionParser()); |
71 |
+ |
|
72 |
+ |
} |
73 |
+ |
|
74 |
|
void DUFF::parse(const std::string& filename) { |
75 |
|
ifstrstream* ffStream; |
76 |
< |
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 (fortran's index begins from 1) |
51 |
< |
int lineNo = 0; |
76 |
> |
ffStream = openForceFieldFile(filename); |
77 |
|
|
78 |
< |
while(ffStream.getline(line, bufferSize)){ |
54 |
< |
++lineNo; |
78 |
> |
spMan_.parse(*ffStream, *this); |
79 |
|
|
80 |
< |
//a line begins with '#' or '!' is comment which is skipped |
81 |
< |
if (line[0] != '#' ||line[0] != '!') { |
58 |
< |
StringTokenizer tokenizer(line); |
59 |
< |
|
60 |
< |
if (tokenizer.countTokens() >= 4) { |
61 |
< |
atomTypeName = tokenizer.nextToken(); |
62 |
< |
mass = tokenizer.nextTokenAsDouble(); |
63 |
< |
epsilon = tokenizer.nextTokenAsDouble(); |
64 |
< |
sigma = tokenizer.nextTokenAsDouble(); |
80 |
> |
ForceField::AtomTypeContainer::MapTypeIterator i; |
81 |
> |
AtomType* at; |
82 |
|
|
83 |
< |
atomType = new AtomType(); |
84 |
< |
atomType->setName(atomTypeName); |
85 |
< |
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(); |
83 |
> |
for (at = atomTypeCont_.beginType(i); at != NULL; at = atomTypeCont_.nextType(i)) { |
84 |
> |
at->makeFortranAtomType(); |
85 |
> |
} |
86 |
|
|
87 |
< |
atomType->setIdent(ident); |
88 |
< |
atomType->addProperty(new DoubleGenericData("Epsilon", epsilon)); |
76 |
< |
atomType->addProperty(new DoubleGenericData("Sigma", sigma)); |
77 |
< |
atomType->complete(); |
78 |
< |
//notify a new LJtype atom type is created |
79 |
< |
newLJtype(&ident, &sigma, &epsilon, &status); |
80 |
< |
|
81 |
< |
//add atom type to AtomTypeContainer |
82 |
< |
addAtomType(atomTypeName, atomType); |
83 |
< |
++ident; |
84 |
< |
|
85 |
< |
} else { |
86 |
< |
sprintf( painCave.errMsg, |
87 |
< |
"Not enough tokens when parsing Lennard-Jones Force Field : %s\n" |
88 |
< |
"in line %d : %s\n", |
89 |
< |
filename.c_str(), lineNo, line); |
90 |
< |
painCave.severity = OOPSE_ERROR; |
91 |
< |
painCave.isFatal = 1; |
92 |
< |
simError(); |
93 |
< |
} |
94 |
< |
|
95 |
< |
} |
87 |
> |
for (at = atomTypeCont_.beginType(i); at != NULL; at = atomTypeCont_.nextType(i)) { |
88 |
> |
at->complete(); |
89 |
|
} |
90 |
|
|
98 |
– |
delete ffStream; |
91 |
|
} |
92 |
|
|
101 |
– |
|
102 |
– |
void DUFF::parseAtomType(){ |
103 |
– |
} |
104 |
– |
|
105 |
– |
void DUFF::parseBondType(){ |
106 |
– |
} |
107 |
– |
|
108 |
– |
void DUFF::parseBendType(){ |
109 |
– |
} |
110 |
– |
|
111 |
– |
void DUFF::parseTorsionType(){ |
112 |
– |
|
113 |
– |
} |
114 |
– |
|
93 |
|
} //end namespace oopse |
116 |
– |
|