ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/UseTheForce/DUFF.cpp
Revision: 1741
Committed: Tue Nov 16 02:07:14 2004 UTC (19 years, 7 months ago) by tim
File size: 3910 byte(s)
Log Message:
adding DUFF class; adding checking statement to nextTokenAsInt and nextTokenAsFloat in StringTokenizer

File Contents

# Content
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/DUFF.hpp"
27 #include "UseTheForce/DarkSide/lj_interface.h"
28
29 namespace oopse {
30
31 //definition of createDUFF
32 ForceField* createDUFF() {
33 return new DUFF();
34 }
35
36 //register createDUFF to ForceFieldCreator
37 ForceFieldFactory::getInstance()->registerForceField("DUFF", createDUFF);
38
39 void DUFF::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 (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 which is skipped
57 if (line[0] != '#' ||line[0] != '!') {
58 StringTokenizer tokenizer(line);
59
60 if (tokenizer.countTokens() >= 4) {
61 atomTypeName = tokenizer.nextToken();
62 mass = tokenizer.nextTokenAsFloat();
63 epsilon = tokenizer.nextTokenAsFloat();
64 sigma = tokenizer.nextTokenAsFloat();
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 //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 }
96 }
97
98 delete ffStream;
99 }
100
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
115 } //end namespace oopse
116