ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/nanoparticleBuilder/icosahedralBuilder.cpp
Revision: 1942
Committed: Tue Nov 5 18:33:42 2013 UTC (11 years, 7 months ago) by gezelter
File size: 7905 byte(s)
Log Message:
Fixed some warning messages and NanoVolume issues.

File Contents

# User Rev Content
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     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;
94     int nShells;
95 gezelter 1862
96 gezelter 1860 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 gezelter 1862 } else {
133 gezelter 1860 sprintf(painCave.errMsg, "icosahedralBuilder: No lattice constant\n"
134 gezelter 1862 "\tgiven.");
135 gezelter 1860 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     Globals* simParams = oldInfo->getSimParams();
144    
145 gezelter 1862 vector<Vector3d> Points;
146     if (args_info.ico_given){
147     Icosahedron* ico = new Icosahedron();
148     Points = ico->getPoints(nShells);
149     } else if (args_info.deca_given) {
150     RegularDecahedron* deca = new RegularDecahedron(nShells);
151     Points = deca->getPoints();
152     } else if (args_info.ino_given) {
153     int columnAtoms = args_info.columnAtoms_arg;
154     InoDecahedron* ino = new InoDecahedron(columnAtoms, nShells);
155     Points = ino->getPoints();
156     } else if (args_info.marks_given) {
157     int columnAtoms = args_info.columnAtoms_arg;
158     int twinAtoms = args_info.twinAtoms_arg;
159     Decahedron* marks = new Decahedron(columnAtoms, nShells, twinAtoms);
160     Points = marks->getPoints();
161     }
162     else if (args_info.stone_given) {
163     int columnAtoms = args_info.columnAtoms_arg;
164     int twinAtoms = args_info.twinAtoms_arg;
165     int truncatedPlanes = args_info.truncatedPlanes_arg;
166     CurlingStoneDecahedron* csd = new CurlingStoneDecahedron(columnAtoms, nShells, twinAtoms, truncatedPlanes);
167     Points = csd->getPoints();
168     }
169 gezelter 1860
170     outputFileName = args_info.output_arg;
171    
172 gezelter 1942 // create a new .md file on fly which corrects the number of
173     // molecules
174 gezelter 1860
175     createMdFile(inputFileName, outputFileName, Points.size());
176    
177 gezelter 1874 delete oldInfo;
178 gezelter 1860
179     SimCreator newCreator;
180     SimInfo* NewInfo = newCreator.createSim(outputFileName, false);
181    
182     // Place molecules
183     Molecule* mol;
184     SimInfo::MoleculeIterator mi;
185     mol = NewInfo->beginMolecule(mi);
186    
187     int l = 0;
188    
189     locator = new MoLocator(NewInfo->getMoleculeStamp(0),
190     NewInfo->getForceField());
191    
192     Vector3d boxMax;
193     Vector3d boxMin;
194    
195 gezelter 1876 for (unsigned int n = 0; n < Points.size(); n++) {
196 gezelter 1860 mol = NewInfo->getMoleculeByGlobalIndex(l);
197     Vector3d location = Points[n] * latticeConstant;
198     Vector3d orientation = Vector3d(0, 0, 1.0);
199 gezelter 1876
200 gezelter 1860 if (n == 0) {
201     boxMax = location;
202     boxMin = location;
203     } else {
204     for (int i = 0; i < 3; i++) {
205     boxMax[i] = max(boxMax[i], location[i]);
206     boxMin[i] = min(boxMin[i], location[i]);
207     }
208     }
209    
210     locator->placeMol(location, orientation, mol);
211     l++;
212     }
213    
214     Mat3x3d boundingBox;
215     boundingBox(0,0) = 10.0*(boxMax[0] - boxMin[0]);
216     boundingBox(1,1) = 10.0*(boxMax[1] - boxMin[1]);
217     boundingBox(2,2) = 10.0*(boxMax[2] - boxMin[2]);
218    
219     //set Hmat
220     NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat( boundingBox );
221    
222     //create dumpwriter and write out the coordinates
223     writer = new DumpWriter(NewInfo, outputFileName);
224    
225     if (writer == NULL) {
226     sprintf(painCave.errMsg, "Error in creating dumpwriter object ");
227     painCave.isFatal = 1;
228     simError();
229     }
230    
231     writer->writeDump();
232    
233     // deleting the writer will put the closing at the end of the dump file
234    
235     delete writer;
236    
237 gezelter 1942 // clean up by calling simError.....
238 gezelter 1860 sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been "
239     "generated.\n", outputFileName.c_str());
240     painCave.isFatal = 0;
241     painCave.severity = OPENMD_INFO;
242     simError();
243     return 0;
244     }

Properties

Name Value
svn:eol-style native