| 1 | < | /* | 
| 1 | > | /* | 
| 2 |  | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 |  | * | 
| 4 |  | * The University of Notre Dame grants you ("Licensee") a | 
| 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 | < | */ | 
| 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 |  | namespace oopse { | 
| 54 |  |  | 
| 55 | < | ForceField::ForceField() { | 
| 55 | > | ForceField::ForceField() { | 
| 56 |  | char* tempPath; | 
| 57 |  | tempPath = getenv("FORCE_PARAM_PATH"); | 
| 58 |  |  | 
| 59 |  | if (tempPath == NULL) { | 
| 60 | < | //convert a macro from compiler to a string in c++ | 
| 61 | < | STR_DEFINE(ffPath_, FRC_PATH ); | 
| 60 | > | //convert a macro from compiler to a string in c++ | 
| 61 | > | STR_DEFINE(ffPath_, FRC_PATH ); | 
| 62 |  | } else { | 
| 63 | < | ffPath_ = tempPath; | 
| 63 | > | ffPath_ = tempPath; | 
| 64 |  | } | 
| 65 | < | } | 
| 65 | > | } | 
| 66 |  |  | 
| 67 | < | AtomType* ForceField::getAtomType(const std::string &at) { | 
| 67 | > |  | 
| 68 | > | ForceField::~ForceField() { | 
| 69 | > | deleteAtypes(); | 
| 70 | > | } | 
| 71 | > |  | 
| 72 | > | AtomType* ForceField::getAtomType(const std::string &at) { | 
| 73 |  | std::vector<std::string> keys; | 
| 74 |  | keys.push_back(at); | 
| 75 |  | return atomTypeCont_.find(keys); | 
| 76 | < | } | 
| 76 | > | } | 
| 77 |  |  | 
| 78 | < | BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { | 
| 78 | > | BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { | 
| 79 |  | std::vector<std::string> keys; | 
| 80 |  | keys.push_back(at1); | 
| 81 |  | keys.push_back(at2); | 
| 83 |  | //try exact match first | 
| 84 |  | BondType* bondType = bondTypeCont_.find(keys); | 
| 85 |  | if (bondType) { | 
| 86 | < | return bondType; | 
| 86 | > | return bondType; | 
| 87 |  | } else { | 
| 88 | < | //if no exact match found, try wild card match | 
| 89 | < | return bondTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 88 | > | //if no exact match found, try wild card match | 
| 89 | > | return bondTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 90 |  | } | 
| 91 |  |  | 
| 92 | < | } | 
| 92 | > | } | 
| 93 |  |  | 
| 94 | < | BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, | 
| 95 | < | const std::string &at3) { | 
| 94 | > | BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, | 
| 95 | > | const std::string &at3) { | 
| 96 |  | std::vector<std::string> keys; | 
| 97 |  | keys.push_back(at1); | 
| 98 |  | keys.push_back(at2); | 
| 101 |  | //try exact match first | 
| 102 |  | BendType* bendType = bendTypeCont_.find(keys); | 
| 103 |  | if (bendType) { | 
| 104 | < | return bendType; | 
| 104 | > | return bendType; | 
| 105 |  | } else { | 
| 106 | < | //if no exact match found, try wild card match | 
| 107 | < | return bendTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 106 | > | //if no exact match found, try wild card match | 
| 107 | > | return bendTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 108 |  | } | 
| 109 | < | } | 
| 109 | > | } | 
| 110 |  |  | 
| 111 | < | TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, | 
| 112 | < | const std::string &at3, const std::string &at4) { | 
| 111 | > | TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, | 
| 112 | > | const std::string &at3, const std::string &at4) { | 
| 113 |  | std::vector<std::string> keys; | 
| 114 |  | keys.push_back(at1); | 
| 115 |  | keys.push_back(at2); | 
| 118 |  |  | 
| 119 |  | TorsionType* torsionType = torsionTypeCont_.find(keys); | 
| 120 |  | if (torsionType) { | 
| 121 | < | return torsionType; | 
| 121 | > | return torsionType; | 
| 122 |  | } else { | 
| 123 | < | //if no exact match found, try wild card match | 
| 124 | < | return torsionTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 123 | > | //if no exact match found, try wild card match | 
| 124 | > | return torsionTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 125 |  | } | 
| 126 |  |  | 
| 127 |  | return torsionTypeCont_.find(keys, wildCardAtomTypeName_); | 
| 128 |  |  | 
| 129 | < | } | 
| 129 | > | } | 
| 130 |  |  | 
| 131 | < | BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ | 
| 131 | > | BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ | 
| 132 |  | std::vector<std::string> keys; | 
| 133 |  | keys.push_back(at1); | 
| 134 |  | keys.push_back(at2); | 
| 135 |  | return bondTypeCont_.find(keys); | 
| 136 | < | } | 
| 136 | > | } | 
| 137 |  |  | 
| 138 | < | BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, | 
| 139 | < | const std::string &at3){ | 
| 138 | > | BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, | 
| 139 | > | const std::string &at3){ | 
| 140 |  | std::vector<std::string> keys; | 
| 141 |  | keys.push_back(at1); | 
| 142 |  | keys.push_back(at2); | 
| 143 |  | keys.push_back(at3); | 
| 144 |  | return bendTypeCont_.find(keys); | 
| 145 | < | } | 
| 145 | > | } | 
| 146 |  |  | 
| 147 | < | TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, | 
| 148 | < | const std::string &at3, const std::string &at4){ | 
| 147 | > | TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, | 
| 148 | > | const std::string &at3, const std::string &at4){ | 
| 149 |  | std::vector<std::string> keys; | 
| 150 |  | keys.push_back(at1); | 
| 151 |  | keys.push_back(at2); | 
| 152 |  | keys.push_back(at3); | 
| 153 |  | keys.push_back(at4); | 
| 154 |  | return torsionTypeCont_.find(keys); | 
| 155 | < | } | 
| 156 | < | bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { | 
| 155 | > | } | 
| 156 | > | bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { | 
| 157 |  | std::vector<std::string> keys; | 
| 158 |  | keys.push_back(at); | 
| 159 |  | return atomTypeCont_.add(keys, atomType); | 
| 160 | < | } | 
| 160 | > | } | 
| 161 |  |  | 
| 162 | < | bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { | 
| 162 | > | bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { | 
| 163 |  | std::vector<std::string> keys; | 
| 164 |  | keys.push_back(at1); | 
| 165 |  | keys.push_back(at2); | 
| 166 |  | return bondTypeCont_.add(keys, bondType); | 
| 167 |  |  | 
| 168 | < | } | 
| 168 | > | } | 
| 169 |  |  | 
| 170 | < | bool ForceField::addBendType(const std::string &at1, const std::string &at2, | 
| 171 | < | const std::string &at3, BendType* bendType) { | 
| 170 | > | bool ForceField::addBendType(const std::string &at1, const std::string &at2, | 
| 171 | > | const std::string &at3, BendType* bendType) { | 
| 172 |  | std::vector<std::string> keys; | 
| 173 |  | keys.push_back(at1); | 
| 174 |  | keys.push_back(at2); | 
| 175 |  | keys.push_back(at3); | 
| 176 |  | return bendTypeCont_.add(keys, bendType); | 
| 177 | < | } | 
| 177 | > | } | 
| 178 |  |  | 
| 179 | < | bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, | 
| 180 | < | const std::string &at3, const std::string &at4, TorsionType* torsionType) { | 
| 179 | > | bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, | 
| 180 | > | const std::string &at3, const std::string &at4, TorsionType* torsionType) { | 
| 181 |  | std::vector<std::string> keys; | 
| 182 |  | keys.push_back(at1); | 
| 183 |  | keys.push_back(at2); | 
| 184 |  | keys.push_back(at3); | 
| 185 |  | keys.push_back(at4); | 
| 186 |  | return torsionTypeCont_.add(keys, torsionType); | 
| 187 | < | } | 
| 187 | > | } | 
| 188 |  |  | 
| 189 | < | double ForceField::getRcutFromAtomType(AtomType* at) { | 
| 189 | > | double ForceField::getRcutFromAtomType(AtomType* at) { | 
| 190 |  | /**@todo */ | 
| 191 |  | GenericData* data; | 
| 192 |  | double rcut = 0.0; | 
| 193 |  |  | 
| 194 |  | if (at->isLennardJones()) { | 
| 195 | < | data = at->getPropertyByName("LennardJones"); | 
| 196 | < | if (data != NULL) { | 
| 197 | < | LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); | 
| 195 | > | data = at->getPropertyByName("LennardJones"); | 
| 196 | > | if (data != NULL) { | 
| 197 | > | LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); | 
| 198 |  |  | 
| 199 | < | if (ljData != NULL) { | 
| 200 | < | LJParam ljParam = ljData->getData(); | 
| 199 | > | if (ljData != NULL) { | 
| 200 | > | LJParam ljParam = ljData->getData(); | 
| 201 |  |  | 
| 202 | < | //by default use 2.5*sigma as cutoff radius | 
| 203 | < | rcut = 2.5 * ljParam.sigma; | 
| 202 | > | //by default use 2.5*sigma as cutoff radius | 
| 203 | > | rcut = 2.5 * ljParam.sigma; | 
| 204 |  |  | 
| 205 | < | } else { | 
| 206 | < | sprintf( painCave.errMsg, | 
| 207 | < | "Can not cast GenericData to LJParam\n"); | 
| 208 | < | painCave.severity = OOPSE_ERROR; | 
| 209 | < | painCave.isFatal = 1; | 
| 210 | < | simError(); | 
| 211 | < | } | 
| 212 | < | } else { | 
| 213 | < | sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); | 
| 214 | < | painCave.severity = OOPSE_ERROR; | 
| 215 | < | painCave.isFatal = 1; | 
| 216 | < | simError(); | 
| 217 | < | } | 
| 205 | > | } else { | 
| 206 | > | sprintf( painCave.errMsg, | 
| 207 | > | "Can not cast GenericData to LJParam\n"); | 
| 208 | > | painCave.severity = OOPSE_ERROR; | 
| 209 | > | painCave.isFatal = 1; | 
| 210 | > | simError(); | 
| 211 | > | } | 
| 212 | > | } else { | 
| 213 | > | sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); | 
| 214 | > | painCave.severity = OOPSE_ERROR; | 
| 215 | > | painCave.isFatal = 1; | 
| 216 | > | simError(); | 
| 217 | > | } | 
| 218 |  | } | 
| 219 |  |  | 
| 220 |  | return rcut; | 
| 221 | < | } | 
| 221 | > | } | 
| 222 |  |  | 
| 223 |  |  | 
| 224 | < | ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { | 
| 224 | > | ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { | 
| 225 |  | std::string forceFieldFilename(filename); | 
| 226 |  | ifstrstream* ffStream = new ifstrstream(); | 
| 227 |  |  | 
| 229 |  | ffStream->open(forceFieldFilename.c_str()); | 
| 230 |  | if(!ffStream->is_open()){ | 
| 231 |  |  | 
| 232 | < | forceFieldFilename = ffPath_ + "/" + forceFieldFilename; | 
| 233 | < | ffStream->open( forceFieldFilename.c_str() ); | 
| 232 | > | forceFieldFilename = ffPath_ + "/" + forceFieldFilename; | 
| 233 | > | ffStream->open( forceFieldFilename.c_str() ); | 
| 234 |  |  | 
| 235 | < | //if current directory does not contain the force field file, | 
| 236 | < | //try to open it in the path | 
| 237 | < | if(!ffStream->is_open()){ | 
| 235 | > | //if current directory does not contain the force field file, | 
| 236 | > | //try to open it in the path | 
| 237 | > | if(!ffStream->is_open()){ | 
| 238 |  |  | 
| 239 | < | sprintf( painCave.errMsg, | 
| 240 | < | "Error opening the force field parameter file:\n" | 
| 241 | < | "\t%s\n" | 
| 242 | < | "\tHave you tried setting the FORCE_PARAM_PATH environment " | 
| 243 | < | "variable?\n", | 
| 244 | < | forceFieldFilename.c_str() ); | 
| 245 | < | painCave.severity = OOPSE_ERROR; | 
| 246 | < | painCave.isFatal = 1; | 
| 247 | < | simError(); | 
| 248 | < | } | 
| 239 | > | sprintf( painCave.errMsg, | 
| 240 | > | "Error opening the force field parameter file:\n" | 
| 241 | > | "\t%s\n" | 
| 242 | > | "\tHave you tried setting the FORCE_PARAM_PATH environment " | 
| 243 | > | "variable?\n", | 
| 244 | > | forceFieldFilename.c_str() ); | 
| 245 | > | painCave.severity = OOPSE_ERROR; | 
| 246 | > | painCave.isFatal = 1; | 
| 247 | > | simError(); | 
| 248 | > | } | 
| 249 |  | } | 
| 250 |  |  | 
| 251 |  | return ffStream; | 
| 252 |  |  | 
| 253 | < | } | 
| 253 | > | } | 
| 254 |  |  | 
| 255 |  | } //end namespace oopse |