| 1 |
/* |
| 2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
* |
| 4 |
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
* non-exclusive, royalty free, license to use, modify and |
| 6 |
* redistribute this software in source and binary code form, provided |
| 7 |
* that the following conditions are met: |
| 8 |
* |
| 9 |
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
* publication of scientific results based in part on use of the |
| 11 |
* program. An acceptable form of acknowledgement is citation of |
| 12 |
* the article in which the program was described (Matthew |
| 13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
* |
| 18 |
* 2. Redistributions of source code must retain the above copyright |
| 19 |
* notice, this list of conditions and the following disclaimer. |
| 20 |
* |
| 21 |
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
* notice, this list of conditions and the following disclaimer in the |
| 23 |
* documentation and/or other materials provided with the |
| 24 |
* distribution. |
| 25 |
* |
| 26 |
* This software is provided "AS IS," without a warranty of any |
| 27 |
* kind. All express or implied conditions, representations and |
| 28 |
* warranties, including any implied warranty of merchantability, |
| 29 |
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
* be liable for any damages suffered by licensee as a result of |
| 32 |
* using, modifying or distributing the software or its |
| 33 |
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
* damages, however caused and regardless of the theory of liability, |
| 37 |
* arising out of the use of or inability to use software, even if the |
| 38 |
* University of Notre Dame has been advised of the possibility of |
| 39 |
* such damages. |
| 40 |
*/ |
| 41 |
|
| 42 |
/** |
| 43 |
* @file ForceField.cpp |
| 44 |
* @author tlin |
| 45 |
* @date 11/04/2004 |
| 46 |
* @time 22:51am |
| 47 |
* @version 1.0 |
| 48 |
*/ |
| 49 |
|
| 50 |
#include "UseTheForce/ForceField.hpp" |
| 51 |
#include "utils/simError.h" |
| 52 |
#include "UseTheForce/DarkSide/atype_interface.h" |
| 53 |
#include "UseTheForce/DarkSide/fForceOptions_interface.h" |
| 54 |
namespace oopse { |
| 55 |
|
| 56 |
ForceField::ForceField() { |
| 57 |
char* tempPath; |
| 58 |
tempPath = getenv("FORCE_PARAM_PATH"); |
| 59 |
|
| 60 |
if (tempPath == NULL) { |
| 61 |
//convert a macro from compiler to a string in c++ |
| 62 |
STR_DEFINE(ffPath_, FRC_PATH ); |
| 63 |
} else { |
| 64 |
ffPath_ = tempPath; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
ForceField::~ForceField() { |
| 70 |
deleteAtypes(); |
| 71 |
} |
| 72 |
|
| 73 |
AtomType* ForceField::getAtomType(const std::string &at) { |
| 74 |
std::vector<std::string> keys; |
| 75 |
keys.push_back(at); |
| 76 |
return atomTypeCont_.find(keys); |
| 77 |
} |
| 78 |
|
| 79 |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
| 80 |
std::vector<std::string> keys; |
| 81 |
keys.push_back(at1); |
| 82 |
keys.push_back(at2); |
| 83 |
|
| 84 |
//try exact match first |
| 85 |
BondType* bondType = bondTypeCont_.find(keys); |
| 86 |
if (bondType) { |
| 87 |
return bondType; |
| 88 |
} else { |
| 89 |
//if no exact match found, try wild card match |
| 90 |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
| 91 |
} |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
| 96 |
const std::string &at3) { |
| 97 |
std::vector<std::string> keys; |
| 98 |
keys.push_back(at1); |
| 99 |
keys.push_back(at2); |
| 100 |
keys.push_back(at3); |
| 101 |
|
| 102 |
//try exact match first |
| 103 |
BendType* bendType = bendTypeCont_.find(keys); |
| 104 |
if (bendType) { |
| 105 |
return bendType; |
| 106 |
} else { |
| 107 |
//if no exact match found, try wild card match |
| 108 |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
| 113 |
const std::string &at3, const std::string &at4) { |
| 114 |
std::vector<std::string> keys; |
| 115 |
keys.push_back(at1); |
| 116 |
keys.push_back(at2); |
| 117 |
keys.push_back(at3); |
| 118 |
keys.push_back(at4); |
| 119 |
|
| 120 |
TorsionType* torsionType = torsionTypeCont_.find(keys); |
| 121 |
if (torsionType) { |
| 122 |
return torsionType; |
| 123 |
} else { |
| 124 |
//if no exact match found, try wild card match |
| 125 |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
| 126 |
} |
| 127 |
|
| 128 |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
| 133 |
std::vector<std::string> keys; |
| 134 |
keys.push_back(at1); |
| 135 |
keys.push_back(at2); |
| 136 |
return bondTypeCont_.find(keys); |
| 137 |
} |
| 138 |
|
| 139 |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
| 140 |
const std::string &at3){ |
| 141 |
std::vector<std::string> keys; |
| 142 |
keys.push_back(at1); |
| 143 |
keys.push_back(at2); |
| 144 |
keys.push_back(at3); |
| 145 |
return bendTypeCont_.find(keys); |
| 146 |
} |
| 147 |
|
| 148 |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
| 149 |
const std::string &at3, const std::string &at4){ |
| 150 |
std::vector<std::string> keys; |
| 151 |
keys.push_back(at1); |
| 152 |
keys.push_back(at2); |
| 153 |
keys.push_back(at3); |
| 154 |
keys.push_back(at4); |
| 155 |
return torsionTypeCont_.find(keys); |
| 156 |
} |
| 157 |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
| 158 |
std::vector<std::string> keys; |
| 159 |
keys.push_back(at); |
| 160 |
return atomTypeCont_.add(keys, atomType); |
| 161 |
} |
| 162 |
|
| 163 |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
| 164 |
std::vector<std::string> keys; |
| 165 |
keys.push_back(at1); |
| 166 |
keys.push_back(at2); |
| 167 |
return bondTypeCont_.add(keys, bondType); |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
| 172 |
const std::string &at3, BendType* bendType) { |
| 173 |
std::vector<std::string> keys; |
| 174 |
keys.push_back(at1); |
| 175 |
keys.push_back(at2); |
| 176 |
keys.push_back(at3); |
| 177 |
return bendTypeCont_.add(keys, bendType); |
| 178 |
} |
| 179 |
|
| 180 |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
| 181 |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
| 182 |
std::vector<std::string> keys; |
| 183 |
keys.push_back(at1); |
| 184 |
keys.push_back(at2); |
| 185 |
keys.push_back(at3); |
| 186 |
keys.push_back(at4); |
| 187 |
return torsionTypeCont_.add(keys, torsionType); |
| 188 |
} |
| 189 |
|
| 190 |
double ForceField::getRcutFromAtomType(AtomType* at) { |
| 191 |
/**@todo */ |
| 192 |
GenericData* data; |
| 193 |
double rcut = 0.0; |
| 194 |
|
| 195 |
if (at->isLennardJones()) { |
| 196 |
data = at->getPropertyByName("LennardJones"); |
| 197 |
if (data != NULL) { |
| 198 |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
| 199 |
|
| 200 |
if (ljData != NULL) { |
| 201 |
LJParam ljParam = ljData->getData(); |
| 202 |
|
| 203 |
//by default use 2.5*sigma as cutoff radius |
| 204 |
rcut = 2.5 * ljParam.sigma; |
| 205 |
|
| 206 |
} else { |
| 207 |
sprintf( painCave.errMsg, |
| 208 |
"Can not cast GenericData to LJParam\n"); |
| 209 |
painCave.severity = OOPSE_ERROR; |
| 210 |
painCave.isFatal = 1; |
| 211 |
simError(); |
| 212 |
} |
| 213 |
} else { |
| 214 |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
| 215 |
painCave.severity = OOPSE_ERROR; |
| 216 |
painCave.isFatal = 1; |
| 217 |
simError(); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
return rcut; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
| 226 |
std::string forceFieldFilename(filename); |
| 227 |
ifstrstream* ffStream = new ifstrstream(); |
| 228 |
|
| 229 |
//try to open the force filed file in current directory first |
| 230 |
ffStream->open(forceFieldFilename.c_str()); |
| 231 |
if(!ffStream->is_open()){ |
| 232 |
|
| 233 |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
| 234 |
ffStream->open( forceFieldFilename.c_str() ); |
| 235 |
|
| 236 |
//if current directory does not contain the force field file, |
| 237 |
//try to open it in the path |
| 238 |
if(!ffStream->is_open()){ |
| 239 |
|
| 240 |
sprintf( painCave.errMsg, |
| 241 |
"Error opening the force field parameter file:\n" |
| 242 |
"\t%s\n" |
| 243 |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
| 244 |
"variable?\n", |
| 245 |
forceFieldFilename.c_str() ); |
| 246 |
painCave.severity = OOPSE_ERROR; |
| 247 |
painCave.isFatal = 1; |
| 248 |
simError(); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
return ffStream; |
| 253 |
|
| 254 |
} |
| 255 |
|
| 256 |
void ForceField::setFortranForceOptions(){ |
| 257 |
ForceOptions theseFortranOptions; |
| 258 |
forceFieldOptions_.makeFortranOptions(theseFortranOptions); |
| 259 |
setfForceOptions(&theseFortranOptions); |
| 260 |
} |
| 261 |
} //end namespace oopse |