ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/nanoparticleBuilder/icosahedralBuilder.cpp
Revision: 2071
Committed: Sat Mar 7 21:41:51 2015 UTC (10 years, 2 months ago) by gezelter
File size: 7866 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

File Contents

# Content
1 /*
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 #include "clusters/Icosahedron.hpp"
51 #include "clusters/Decahedron.hpp"
52
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 while (!oldMdFile.eof()) {
70
71 //correct molecule number
72 if (strstr(buffer, "nMol") != NULL) {
73 sprintf(buffer, "\tnMol = %i;", nMol);
74 newMdFile << buffer << std::endl;
75 } else {
76 newMdFile << buffer << std::endl;
77 }
78
79 oldMdFile.getline(buffer, MAXLEN);
80 }
81
82 oldMdFile.close();
83 newMdFile.close();
84 }
85
86 int main(int argc, char *argv []) {
87
88 gengetopt_args_info args_info;
89 std::string inputFileName;
90 std::string outputFileName;
91
92 MoLocator* locator;
93 RealType latticeConstant(0.0);
94 int nShells(-1);
95
96 DumpWriter *writer;
97
98 // Parse Command Line Arguments
99 if (cmdline_parser(argc, argv, &args_info) != 0)
100 exit(1);
101
102 /* get input file name */
103 if (args_info.inputs_num)
104 inputFileName = args_info.inputs[0];
105 else {
106 sprintf(painCave.errMsg, "No input .md file name was specified "
107 "on the command line");
108 painCave.isFatal = 1;
109 cmdline_parser_print_help();
110 simError();
111 }
112
113 if (args_info.shells_given) {
114 nShells = args_info.shells_arg;
115 if( nShells < 0 ) {
116 sprintf(painCave.errMsg, "icosahedralBuilder: The number of shells\n"
117 "\tmust be greater than or equal to zero.");
118 painCave.isFatal = 1;
119 cmdline_parser_print_help();
120 simError();
121 }
122 } else {
123 sprintf(painCave.errMsg, "icosahedralBuilder: The number of shells\n"
124 "\tis required to build a Mackay Icosahedron.");
125 painCave.isFatal = 1;
126 cmdline_parser_print_help();
127 simError();
128 }
129
130 if (args_info.latticeConstant_given) {
131 latticeConstant = args_info.latticeConstant_arg;
132 } else {
133 sprintf(painCave.errMsg, "icosahedralBuilder: No lattice constant\n"
134 "\tgiven.");
135 painCave.isFatal = 1;
136 cmdline_parser_print_help();
137 simError();
138 }
139
140 /* parse md file and set up the system */
141 SimCreator oldCreator;
142 SimInfo* oldInfo = oldCreator.createSim(inputFileName, false);
143
144 vector<Vector3d> Points;
145 if (args_info.ico_given){
146 Icosahedron* ico = new Icosahedron();
147 Points = ico->getPoints(nShells);
148 } else if (args_info.deca_given) {
149 RegularDecahedron* deca = new RegularDecahedron(nShells);
150 Points = deca->getPoints();
151 } else if (args_info.ino_given) {
152 int columnAtoms = args_info.columnAtoms_arg;
153 InoDecahedron* ino = new InoDecahedron(columnAtoms, nShells);
154 Points = ino->getPoints();
155 } else if (args_info.marks_given) {
156 int columnAtoms = args_info.columnAtoms_arg;
157 int twinAtoms = args_info.twinAtoms_arg;
158 Decahedron* marks = new Decahedron(columnAtoms, nShells, twinAtoms);
159 Points = marks->getPoints();
160 }
161 else if (args_info.stone_given) {
162 int columnAtoms = args_info.columnAtoms_arg;
163 int twinAtoms = args_info.twinAtoms_arg;
164 int truncatedPlanes = args_info.truncatedPlanes_arg;
165 CurlingStoneDecahedron* csd = new CurlingStoneDecahedron(columnAtoms, nShells, twinAtoms, truncatedPlanes);
166 Points = csd->getPoints();
167 }
168
169 outputFileName = args_info.output_arg;
170
171 // create a new .md file on fly which corrects the number of
172 // molecules
173
174 createMdFile(inputFileName, outputFileName, Points.size());
175
176 delete oldInfo;
177
178 SimCreator newCreator;
179 SimInfo* NewInfo = newCreator.createSim(outputFileName, false);
180
181 // Place molecules
182 Molecule* mol;
183 SimInfo::MoleculeIterator mi;
184 mol = NewInfo->beginMolecule(mi);
185
186 int l = 0;
187
188 locator = new MoLocator(NewInfo->getMoleculeStamp(0),
189 NewInfo->getForceField());
190
191 Vector3d boxMax;
192 Vector3d boxMin;
193
194 for (unsigned int n = 0; n < Points.size(); n++) {
195 mol = NewInfo->getMoleculeByGlobalIndex(l);
196 Vector3d location = Points[n] * latticeConstant;
197 Vector3d orientation = Vector3d(0, 0, 1.0);
198
199 if (n == 0) {
200 boxMax = location;
201 boxMin = location;
202 } else {
203 for (int i = 0; i < 3; i++) {
204 boxMax[i] = max(boxMax[i], location[i]);
205 boxMin[i] = min(boxMin[i], location[i]);
206 }
207 }
208
209 locator->placeMol(location, orientation, mol);
210 l++;
211 }
212
213 Mat3x3d boundingBox;
214 boundingBox(0,0) = 10.0*(boxMax[0] - boxMin[0]);
215 boundingBox(1,1) = 10.0*(boxMax[1] - boxMin[1]);
216 boundingBox(2,2) = 10.0*(boxMax[2] - boxMin[2]);
217
218 //set Hmat
219 NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat( boundingBox );
220
221 //create dumpwriter and write out the coordinates
222 writer = new DumpWriter(NewInfo, outputFileName);
223
224 if (writer == NULL) {
225 sprintf(painCave.errMsg, "Error in creating dumpwriter object ");
226 painCave.isFatal = 1;
227 simError();
228 }
229
230 writer->writeDump();
231
232 // deleting the writer will put the closing at the end of the dump file
233
234 delete writer;
235
236 // clean up by calling simError.....
237 sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been "
238 "generated.\n", outputFileName.c_str());
239 painCave.isFatal = 0;
240 painCave.severity = OPENMD_INFO;
241 simError();
242 return 0;
243 }

Properties

Name Value
svn:eol-style native