| 1 | gezelter | 1860 | /* | 
| 2 |  |  | * Copyright (c) 2013 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. Redistributions of source code must retain the above copyright | 
| 10 |  |  | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  |  | * | 
| 12 |  |  | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 |  |  | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  |  | *    documentation and/or other materials provided with the | 
| 15 |  |  | *    distribution. | 
| 16 |  |  | * | 
| 17 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 18 |  |  | * kind. All express or implied conditions, representations and | 
| 19 |  |  | * warranties, including any implied warranty of merchantability, | 
| 20 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 23 |  |  | * using, modifying or distributing the software or its | 
| 24 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 25 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 27 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 28 |  |  | * arising out of the use of or inability to use software, even if the | 
| 29 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 30 |  |  | * such damages. | 
| 31 |  |  | * | 
| 32 |  |  | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 |  |  | * research, please cite the appropriate papers when you publish your | 
| 34 |  |  | * work.  Good starting points are: | 
| 35 |  |  | * | 
| 36 |  |  | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 |  |  | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 |  |  | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 |  |  | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 |  |  | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 |  |  | */ | 
| 42 |  |  |  | 
| 43 |  |  | #include "config.h" | 
| 44 |  |  | #include "icosahedralBuilderCmd.h" | 
| 45 |  |  | #include "utils/MoLocator.hpp" | 
| 46 |  |  | #include "utils/Tuple.hpp" | 
| 47 |  |  | #include "brains/SimInfo.hpp" | 
| 48 |  |  | #include "brains/SimCreator.hpp" | 
| 49 |  |  | #include "io/DumpWriter.hpp" | 
| 50 | gezelter | 1862 | #include "clusters/Icosahedron.hpp" | 
| 51 |  |  | #include "clusters/Decahedron.hpp" | 
| 52 | gezelter | 1860 |  | 
| 53 |  |  | using namespace OpenMD; | 
| 54 |  |  | using namespace std; | 
| 55 |  |  |  | 
| 56 |  |  | void createMdFile(const std::string&oldMdFileName, | 
| 57 |  |  | const std::string&newMdFileName, | 
| 58 |  |  | int nMol) { | 
| 59 |  |  | ifstream oldMdFile; | 
| 60 |  |  | ofstream newMdFile; | 
| 61 |  |  | const int MAXLEN = 65535; | 
| 62 |  |  | char buffer[MAXLEN]; | 
| 63 |  |  |  | 
| 64 |  |  | //create new .md file based on old .md file | 
| 65 |  |  | oldMdFile.open(oldMdFileName.c_str()); | 
| 66 |  |  | newMdFile.open(newMdFileName.c_str()); | 
| 67 |  |  | oldMdFile.getline(buffer, MAXLEN); | 
| 68 |  |  |  | 
| 69 |  |  | unsigned int i = 0; | 
| 70 |  |  | while (!oldMdFile.eof()) { | 
| 71 |  |  |  | 
| 72 |  |  | //correct molecule number | 
| 73 |  |  | if (strstr(buffer, "nMol") != NULL) { | 
| 74 |  |  | sprintf(buffer, "\tnMol = %i;", nMol); | 
| 75 |  |  | newMdFile << buffer << std::endl; | 
| 76 |  |  | } else { | 
| 77 |  |  | newMdFile << buffer << std::endl; | 
| 78 |  |  | } | 
| 79 |  |  |  | 
| 80 |  |  | oldMdFile.getline(buffer, MAXLEN); | 
| 81 |  |  | } | 
| 82 |  |  |  | 
| 83 |  |  | oldMdFile.close(); | 
| 84 |  |  | newMdFile.close(); | 
| 85 |  |  | } | 
| 86 |  |  |  | 
| 87 |  |  | int main(int argc, char *argv []) { | 
| 88 |  |  |  | 
| 89 |  |  | gengetopt_args_info args_info; | 
| 90 |  |  | std::string inputFileName; | 
| 91 |  |  | std::string outputFileName; | 
| 92 |  |  |  | 
| 93 |  |  | MoLocator* locator; | 
| 94 |  |  | RealType latticeConstant; | 
| 95 |  |  | int nShells; | 
| 96 | gezelter | 1862 |  | 
| 97 | gezelter | 1860 | DumpWriter *writer; | 
| 98 |  |  |  | 
| 99 |  |  | // Parse Command Line Arguments | 
| 100 |  |  | if (cmdline_parser(argc, argv, &args_info) != 0) | 
| 101 |  |  | exit(1); | 
| 102 |  |  |  | 
| 103 |  |  | /* get input file name */ | 
| 104 |  |  | if (args_info.inputs_num) | 
| 105 |  |  | inputFileName = args_info.inputs[0]; | 
| 106 |  |  | else { | 
| 107 |  |  | sprintf(painCave.errMsg, "No input .md file name was specified " | 
| 108 |  |  | "on the command line"); | 
| 109 |  |  | painCave.isFatal = 1; | 
| 110 |  |  | cmdline_parser_print_help(); | 
| 111 |  |  | simError(); | 
| 112 |  |  | } | 
| 113 |  |  |  | 
| 114 |  |  | if (args_info.shells_given) { | 
| 115 |  |  | nShells = args_info.shells_arg; | 
| 116 |  |  | if( nShells < 0 ) { | 
| 117 |  |  | sprintf(painCave.errMsg, "icosahedralBuilder:  The number of shells\n" | 
| 118 |  |  | "\tmust be greater than or equal to zero."); | 
| 119 |  |  | painCave.isFatal = 1; | 
| 120 |  |  | cmdline_parser_print_help(); | 
| 121 |  |  | simError(); | 
| 122 |  |  | } | 
| 123 |  |  | } else { | 
| 124 |  |  | sprintf(painCave.errMsg, "icosahedralBuilder:  The number of shells\n" | 
| 125 |  |  | "\tis required to build a Mackay Icosahedron."); | 
| 126 |  |  | painCave.isFatal = 1; | 
| 127 |  |  | cmdline_parser_print_help(); | 
| 128 |  |  | simError(); | 
| 129 |  |  | } | 
| 130 |  |  |  | 
| 131 |  |  | if (args_info.latticeConstant_given) { | 
| 132 |  |  | latticeConstant = args_info.latticeConstant_arg; | 
| 133 | gezelter | 1862 | } else  { | 
| 134 | gezelter | 1860 | sprintf(painCave.errMsg, "icosahedralBuilder:  No lattice constant\n" | 
| 135 | gezelter | 1862 | "\tgiven."); | 
| 136 | gezelter | 1860 | painCave.isFatal = 1; | 
| 137 |  |  | cmdline_parser_print_help(); | 
| 138 |  |  | simError(); | 
| 139 |  |  | } | 
| 140 |  |  |  | 
| 141 |  |  | /* parse md file and set up the system */ | 
| 142 |  |  | SimCreator oldCreator; | 
| 143 |  |  | SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); | 
| 144 |  |  | Globals* simParams = oldInfo->getSimParams(); | 
| 145 |  |  |  | 
| 146 | gezelter | 1862 | vector<Vector3d> Points; | 
| 147 |  |  | if (args_info.ico_given){ | 
| 148 |  |  | Icosahedron* ico = new Icosahedron(); | 
| 149 |  |  | Points = ico->getPoints(nShells); | 
| 150 |  |  | } else if (args_info.deca_given) { | 
| 151 |  |  | RegularDecahedron* deca = new RegularDecahedron(nShells); | 
| 152 |  |  | Points = deca->getPoints(); | 
| 153 |  |  | } else if (args_info.ino_given) { | 
| 154 |  |  | int columnAtoms = args_info.columnAtoms_arg; | 
| 155 |  |  | InoDecahedron* ino = new InoDecahedron(columnAtoms, nShells); | 
| 156 |  |  | Points = ino->getPoints(); | 
| 157 |  |  | } else if (args_info.marks_given) { | 
| 158 |  |  | int columnAtoms = args_info.columnAtoms_arg; | 
| 159 |  |  | int twinAtoms = args_info.twinAtoms_arg; | 
| 160 |  |  | Decahedron* marks = new Decahedron(columnAtoms, nShells, twinAtoms); | 
| 161 |  |  | Points = marks->getPoints(); | 
| 162 |  |  | } | 
| 163 |  |  | else if (args_info.stone_given) { | 
| 164 |  |  | int columnAtoms = args_info.columnAtoms_arg; | 
| 165 |  |  | int twinAtoms = args_info.twinAtoms_arg; | 
| 166 |  |  | int truncatedPlanes = args_info.truncatedPlanes_arg; | 
| 167 |  |  | CurlingStoneDecahedron* csd = new CurlingStoneDecahedron(columnAtoms, nShells, twinAtoms, truncatedPlanes); | 
| 168 |  |  | Points = csd->getPoints(); | 
| 169 |  |  | } | 
| 170 |  |  |  | 
| 171 |  |  |  | 
| 172 | gezelter | 1860 |  | 
| 173 |  |  | outputFileName = args_info.output_arg; | 
| 174 |  |  |  | 
| 175 |  |  | //creat new .md file on fly which corrects the number of molecule | 
| 176 |  |  |  | 
| 177 |  |  | createMdFile(inputFileName, outputFileName, Points.size()); | 
| 178 |  |  |  | 
| 179 | gezelter | 1874 | delete oldInfo; | 
| 180 | gezelter | 1860 |  | 
| 181 |  |  | SimCreator newCreator; | 
| 182 |  |  | SimInfo* NewInfo = newCreator.createSim(outputFileName, false); | 
| 183 |  |  |  | 
| 184 |  |  | // Place molecules | 
| 185 |  |  | Molecule* mol; | 
| 186 |  |  | SimInfo::MoleculeIterator mi; | 
| 187 |  |  | mol = NewInfo->beginMolecule(mi); | 
| 188 |  |  |  | 
| 189 |  |  | int l = 0; | 
| 190 |  |  |  | 
| 191 |  |  | locator = new MoLocator(NewInfo->getMoleculeStamp(0), | 
| 192 |  |  | NewInfo->getForceField()); | 
| 193 |  |  |  | 
| 194 |  |  | Vector3d boxMax; | 
| 195 |  |  | Vector3d boxMin; | 
| 196 |  |  |  | 
| 197 |  |  | for (int n = 0; n < Points.size(); n++) { | 
| 198 |  |  | mol = NewInfo->getMoleculeByGlobalIndex(l); | 
| 199 |  |  | Vector3d location = Points[n] * latticeConstant; | 
| 200 |  |  | Vector3d orientation = Vector3d(0, 0, 1.0); | 
| 201 |  |  |  | 
| 202 |  |  | if (n == 0) { | 
| 203 |  |  | boxMax = location; | 
| 204 |  |  | boxMin = location; | 
| 205 |  |  | } else { | 
| 206 |  |  | for (int i = 0; i < 3; i++) { | 
| 207 |  |  | boxMax[i] = max(boxMax[i], location[i]); | 
| 208 |  |  | boxMin[i] = min(boxMin[i], location[i]); | 
| 209 |  |  | } | 
| 210 |  |  | } | 
| 211 |  |  |  | 
| 212 |  |  | locator->placeMol(location, orientation, mol); | 
| 213 |  |  | l++; | 
| 214 |  |  | } | 
| 215 |  |  |  | 
| 216 |  |  | Mat3x3d boundingBox; | 
| 217 |  |  | boundingBox(0,0) = 10.0*(boxMax[0] - boxMin[0]); | 
| 218 |  |  | boundingBox(1,1) = 10.0*(boxMax[1] - boxMin[1]); | 
| 219 |  |  | boundingBox(2,2) = 10.0*(boxMax[2] - boxMin[2]); | 
| 220 |  |  |  | 
| 221 |  |  | //set Hmat | 
| 222 |  |  | NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat( boundingBox ); | 
| 223 |  |  |  | 
| 224 |  |  | //create dumpwriter and write out the coordinates | 
| 225 |  |  | writer = new DumpWriter(NewInfo, outputFileName); | 
| 226 |  |  |  | 
| 227 |  |  | if (writer == NULL) { | 
| 228 |  |  | sprintf(painCave.errMsg, "Error in creating dumpwriter object "); | 
| 229 |  |  | painCave.isFatal = 1; | 
| 230 |  |  | simError(); | 
| 231 |  |  | } | 
| 232 |  |  |  | 
| 233 |  |  | writer->writeDump(); | 
| 234 |  |  |  | 
| 235 |  |  | // deleting the writer will put the closing at the end of the dump file | 
| 236 |  |  |  | 
| 237 |  |  | delete writer; | 
| 238 |  |  |  | 
| 239 |  |  | // cleanup a by calling sim error..... | 
| 240 |  |  | sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been " | 
| 241 |  |  | "generated.\n", outputFileName.c_str()); | 
| 242 |  |  | painCave.isFatal = 0; | 
| 243 |  |  | painCave.severity = OPENMD_INFO; | 
| 244 |  |  | simError(); | 
| 245 |  |  | return 0; | 
| 246 |  |  | } |