ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/UseTheForce/LJFF.cpp
Revision: 1783
Committed: Wed Nov 24 21:33:00 2004 UTC (19 years, 9 months ago) by tim
File size: 3803 byte(s)
Log Message:
UseTheForce get built

File Contents

# User Rev Content
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 tim 1783 ffStream = openForceFieldFile(filename);
42 tim 1740 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 1741 while(ffStream.getline(line, bufferSize)){
54 tim 1740 ++lineNo;
55 gezelter 1490
56 tim 1753 //a line begins with '#' or '!' is comment
57 tim 1740 if (line[0] != '#' ||line[0] != '!') {
58     StringTokenizer tokenizer(line);
59    
60     if (tokenizer.countToken() >= 4) {
61     atomTypeName = tokenizer.nextToken();
62 tim 1753 mass = tokenizer.nextTokenAsDouble();
63     epsilon = tokenizer.nextTokenAsDouble();
64     sigma = tokenizer.nextTokenAsDouble();
65 gezelter 1490
66 tim 1740 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 gezelter 1490
74 tim 1740 atomType->setIdent(ident);
75     atomType->addProperty(new DoubleGenericData("Epsilon", epsilon));
76     atomType->addProperty(new DoubleGenericData("Sigma", sigma));
77     atomType->complete();
78 tim 1753
79     //notify fortran a new LJtype atom type is created
80 tim 1740 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     }
99    
100 tim 1740 delete ffStream;
101 gezelter 1490 }
102    
103    
104 tim 1740 } //end namespace oopse