ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/UseTheForce/ForceField.cpp
Revision: 1847
Committed: Sat Dec 4 05:24:07 2004 UTC (19 years, 9 months ago) by tim
File size: 7493 byte(s)
Log Message:
NVE conserved energy, however, potential is not the same as OOPSE-1.0
Step 1 argon in NVE, NVT, NPTi, NPTf and NPTxyz to test integrator
Step 2 SSD in NVE to test DLM, dipole, sticky
Step 3 Butane in NVE to test Bond Bend Torsion
Step 4 EAM
Step 5 Shape
Step 6 Constraint & Restraint

File Contents

# User Rev Content
1 tim 1720 /*
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     /**
27     * @file ForceField.cpp
28     * @author tlin
29     * @date 11/04/2004
30     * @time 22:51am
31     * @version 1.0
32     */
33    
34 gezelter 1711 #include "UseTheForce/ForceField.hpp"
35 tim 1783 #include "utils/simError.h"
36 tim 1720 namespace oopse {
37 gezelter 1711
38 tim 1809 ForceField::ForceField() {
39 tim 1720 char* tempPath;
40     tempPath = getenv("FORCE_PARAM_PATH");
41 gezelter 1711
42 tim 1720 if (tempPath == NULL) {
43     //convert a macro from compiler to a string in c++
44     STR_DEFINE(ffPath_, FRC_PATH );
45     } else {
46     ffPath_ = tempPath;
47     }
48 gezelter 1711 }
49    
50 tim 1720 AtomType* ForceField::getAtomType(const std::string &at) {
51     std::vector<std::string> keys;
52     keys.push_back(at);
53     return atomTypeCont_.find(keys);
54     }
55 gezelter 1711
56 tim 1720 BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) {
57     std::vector<std::string> keys;
58     keys.push_back(at1);
59     keys.push_back(at2);
60 gezelter 1711
61 tim 1847 //try exact match first
62     BondType* bondType = bondTypeCont_.find(keys);
63     if (bondType) {
64     return bondType;
65     } else {
66     //if no exact match found, try wild card match
67     return bondTypeCont_.find(keys, wildCardAtomTypeName_);
68     }
69    
70 tim 1720 }
71 gezelter 1711
72 tim 1720 BendType* ForceField::getBendType(const std::string &at1, const std::string &at2,
73     const std::string &at3) {
74     std::vector<std::string> keys;
75     keys.push_back(at1);
76     keys.push_back(at2);
77     keys.push_back(at3);
78 tim 1847
79     //try exact match first
80     BendType* bendType = bendTypeCont_.find(keys);
81     if (bendType) {
82     return bendType;
83     } else {
84     //if no exact match found, try wild card match
85     return bendTypeCont_.find(keys, wildCardAtomTypeName_);
86     }
87 tim 1720 }
88 gezelter 1711
89 tim 1720 TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2,
90     const std::string &at3, const std::string &at4) {
91     std::vector<std::string> keys;
92     keys.push_back(at1);
93     keys.push_back(at2);
94     keys.push_back(at3);
95     keys.push_back(at4);
96 tim 1847
97     TorsionType* torsionType = torsionTypeCont_.find(keys);
98     if (torsionType) {
99     return torsionType;
100     } else {
101     //if no exact match found, try wild card match
102     return torsionTypeCont_.find(keys, wildCardAtomTypeName_);
103     }
104    
105 tim 1720 return torsionTypeCont_.find(keys, wildCardAtomTypeName_);
106 gezelter 1711
107 tim 1720 }
108 gezelter 1711
109 tim 1783 BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){
110 tim 1770 std::vector<std::string> keys;
111     keys.push_back(at1);
112     keys.push_back(at2);
113     return bondTypeCont_.find(keys);
114     }
115    
116 tim 1783 BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2,
117 tim 1770 const std::string &at3){
118     std::vector<std::string> keys;
119     keys.push_back(at1);
120     keys.push_back(at2);
121     keys.push_back(at3);
122     return bendTypeCont_.find(keys);
123     }
124    
125 tim 1783 TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2,
126 tim 1770 const std::string &at3, const std::string &at4){
127     std::vector<std::string> keys;
128     keys.push_back(at1);
129     keys.push_back(at2);
130     keys.push_back(at3);
131     keys.push_back(at4);
132     return torsionTypeCont_.find(keys);
133     }
134 tim 1758 bool ForceField::addAtomType(const std::string &at, AtomType* atomType) {
135 tim 1720 std::vector<std::string> keys;
136     keys.push_back(at);
137 tim 1783 return atomTypeCont_.add(keys, atomType);
138 tim 1720 }
139 gezelter 1711
140 tim 1758 bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) {
141 tim 1720 std::vector<std::string> keys;
142     keys.push_back(at1);
143     keys.push_back(at2);
144 tim 1783 return bondTypeCont_.add(keys, bondType);
145 gezelter 1711
146 tim 1720 }
147 gezelter 1711
148 tim 1758 bool ForceField::addBendType(const std::string &at1, const std::string &at2,
149 tim 1720 const std::string &at3, BendType* bendType) {
150     std::vector<std::string> keys;
151     keys.push_back(at1);
152     keys.push_back(at2);
153     keys.push_back(at3);
154 tim 1783 return bendTypeCont_.add(keys, bendType);
155 tim 1720 }
156 gezelter 1711
157 tim 1758 bool ForceField::addTorsionType(const std::string &at1, const std::string &at2,
158 tim 1720 const std::string &at3, const std::string &at4, TorsionType* torsionType) {
159     std::vector<std::string> keys;
160     keys.push_back(at1);
161     keys.push_back(at2);
162     keys.push_back(at3);
163     keys.push_back(at4);
164 tim 1783 return torsionTypeCont_.add(keys, torsionType);
165 tim 1720 }
166 gezelter 1711
167 tim 1735 double ForceField::getRcutFromAtomType(AtomType* at) {
168 tim 1783 /**@todo */
169     GenericData* data;
170     double rcut = 0.0;
171    
172     if (at->isLennardJones()) {
173     data = at->getPropertyByName("LennardJones");
174     if (data != NULL) {
175     LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
176    
177     if (ljData != NULL) {
178     LJParam ljParam = ljData->getData();
179    
180     //by default use 2.5*sigma as cutoff radius
181     rcut = 2.5 * ljParam.sigma;
182    
183     } else {
184     sprintf( painCave.errMsg,
185     "Can not cast GenericData to LJParam\n");
186     painCave.severity = OOPSE_ERROR;
187     painCave.isFatal = 1;
188     simError();
189     }
190     } else {
191     sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
192     painCave.severity = OOPSE_ERROR;
193     painCave.isFatal = 1;
194     simError();
195     }
196     }
197    
198     return rcut;
199 tim 1720 }
200 gezelter 1711
201 tim 1740
202 tim 1783 ifstrstream* ForceField::openForceFieldFile(const std::string& filename) {
203 tim 1740 std::string forceFieldFilename(filename);
204     ifstrstream* ffStream = new ifstrstream();
205    
206     //try to open the force filed file in current directory first
207 tim 1783 ffStream->open(forceFieldFilename.c_str());
208     if(!ffStream->is_open()){
209 tim 1740
210     forceFieldFilename = ffPath_ + "/" + forceFieldFilename;
211 tim 1783 ffStream->open( forceFieldFilename.c_str() );
212 tim 1740
213     //if current directory does not contain the force field file,
214     //try to open it in the path
215 tim 1783 if(!ffStream->is_open()){
216 tim 1740
217     sprintf( painCave.errMsg,
218     "Error opening the force field parameter file:\n"
219     "\t%s\n"
220     "\tHave you tried setting the FORCE_PARAM_PATH environment "
221     "variable?\n",
222     forceFieldFilename.c_str() );
223     painCave.severity = OOPSE_ERROR;
224     painCave.isFatal = 1;
225     simError();
226     }
227     }
228    
229     return ffStream;
230    
231     }
232    
233 tim 1720 } //end namespace oopse