--- trunk/src/applications/dump2Xyz/Dump2XYZ.cpp 2004/11/05 21:45:14 211 +++ trunk/src/applications/dump2Xyz/Dump2XYZ.cpp 2005/03/09 17:30:29 413 @@ -1,216 +1,236 @@ + /* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * redistribute this software in source and binary code form, provided + * that the following conditions are met: + * + * 1. Acknowledgement of the program authors must be made in any + * publication of scientific results based in part on use of the + * program. An acceptable form of acknowledgement is citation of + * the article in which the program was described (Matthew + * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher + * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented + * Parallel Simulation Engine for Molecular Dynamics," + * J. Comput. Chem. 26, pp. 252-271 (2005)) + * + * 2. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 3. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * arising out of the use of or inability to use software, even if the + * University of Notre Dame has been advised of the possibility of + * such damages. + */ + #include #include #include -#include "brains/SimSetup.hpp" #include "applications/dump2Xyz/Dump2XYZCmd.h" +#include "brains/Register.hpp" +#include "brains/SimCreator.hpp" +#include "brains/SimInfo.hpp" +#include "io/DumpReader.hpp" +#include "utils/simError.h" #include "visitors/AtomVisitor.hpp" #include "visitors/CompositeVisitor.hpp" #include "visitors/RigidBodyVisitor.hpp" #include "visitors/OtherVisitor.hpp" #include "visitors/ZconsVisitor.hpp" +#include "selection/SelectionEvaluator.hpp" +#include "selection/SelectionManager.hpp" +#include "visitors/LipidTransVisitor.hpp" -using namespace std; +using namespace oopse; int main(int argc, char* argv[]){ - gengetopt_args_info args_info; - string dumpFileName; - string mdFileName; - char inFileName[2002]; - string xyzFileName; - SimInfo* info; - SimSetup startMe; - DumpReader* dumpReader; - ofstream xyzStream; - int nframes; - Molecule* mol; - vector integrableObjects; - vector::iterator iter; - vector myRigidBodies; - vector::iterator rbIter; - CompositeVisitor* compositeVisitor; - SSDAtomVisitor* ssdVisitor; - LinearAtomVisitor* linearVisitor; - DefaultAtomVisitor* defaultAtomVisitor; - LipidHeadVisitor* lipidVisitor; - RBCOMVisitor* rbCOMVisitor; - ReplicateVisitor* replicateVisitor; - WrappingVisitor* wrappingVisitor; - IgnoreVisitor* ignoreVisitor; - XYZVisitor* xyzVisitor; - ZConsVisitor* zconsVisitor; - PrepareVisitor* prepareVisitor; - WaterTypeVisitor* waterTypeVisitor; + //register force fields + registerForceFields(); + gengetopt_args_info args_info; + std::string dumpFileName; + std::string mdFileName; + std::string xyzFileName; + //parse the command line option - if (cmdline_parser (argc, argv, &args_info) != 0) - exit(1) ; - - + if (cmdline_parser (argc, argv, &args_info) != 0) { + exit(1) ; + } + //get the dumpfile name and meta-data file name if (args_info.input_given){ dumpFileName = args_info.input_arg; - } - else{ - cerr << "Does not have input file name" << endl; + } else { + std::cerr << "Does not have input file name" << std::endl; exit(1); } + mdFileName = dumpFileName; mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md"; if (args_info.output_given){ xyzFileName = args_info.output_arg; - } - else{ + } else { xyzFileName = dumpFileName; xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz"; } - + //parse md file and set up the system - info = new SimInfo(); - startMe.setSimInfo(info ); - - strcpy(inFileName, mdFileName.c_str() ); - startMe.parseFile( inFileName ); - - startMe.createSim(); - + SimCreator creator; + SimInfo* info = creator.createSim(mdFileName, false); + + //creat visitor list - compositeVisitor = new CompositeVisitor(); - - //creat ignore visitor - if(args_info.ignore_given ||args_info.water_flag){ + CompositeVisitor* compositeVisitor = new CompositeVisitor(); - ignoreVisitor = new IgnoreVisitor(); - - for(int i = 0; i < args_info.ignore_given; i++) - ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]); - - //ignore water - if(args_info.water_flag){ - ignoreVisitor->addIgnoreType("SSD"); - ignoreVisitor->addIgnoreType("SSD1"); - ignoreVisitor->addIgnoreType("SSD_E"); - ignoreVisitor->addIgnoreType("SSD_RF"); - ignoreVisitor->addIgnoreType("TIP3P_RB_0"); - ignoreVisitor->addIgnoreType("TIP4P_RB_0"); - ignoreVisitor->addIgnoreType("TIP5P_RB_0"); - ignoreVisitor->addIgnoreType("SPCE_RB_0"); - ignoreVisitor->addIgnoreType("DPD_RB_0"); - } - - compositeVisitor->addVisitor(ignoreVisitor, 1000); - } - //creat RigidBody Visitor if(args_info.rigidbody_flag){ - rbCOMVisitor = new RBCOMVisitor(info); + RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info); compositeVisitor->addVisitor(rbCOMVisitor, 900); } - - //compositeVisitor->addVisitor(lipidVisitor, 900); - + //creat SSD atom visitor - ssdVisitor = new SSDAtomVisitor(info); + SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info); compositeVisitor->addVisitor(ssdVisitor, 800); - linearVisitor = new LinearAtomVisitor(info); + + LinearAtomVisitor* linearVisitor = new LinearAtomVisitor(info); compositeVisitor->addVisitor(linearVisitor, 750); - + //creat default atom visitor - defaultAtomVisitor = new DefaultAtomVisitor(info); + DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info); compositeVisitor->addVisitor(defaultAtomVisitor, 700); - + //creat waterType visitor if(args_info.watertype_flag){ - waterTypeVisitor = new WaterTypeVisitor; + WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor; compositeVisitor->addVisitor(waterTypeVisitor, 600); } - + //create ZconsVisitor if(args_info.zconstraint_flag){ - - zconsVisitor = new ZConsVisitor(info); - if(zconsVisitor->haveZconsMol()) + ZConsVisitor* zconsVisitor = new ZConsVisitor(info); + + if(zconsVisitor->haveZconsMol()) { compositeVisitor->addVisitor(zconsVisitor, 500); - else + } else { delete zconsVisitor; + } } - + //creat wrapping visitor - + if(args_info.periodicBox_flag){ - wrappingVisitor = new WrappingVisitor(info); + WrappingVisitor* wrappingVisitor = new WrappingVisitor(info); compositeVisitor->addVisitor(wrappingVisitor, 400); } - + //creat replicate visitor if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){ - IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg); - replicateVisitor = new ReplicateVisitor(info, replicateOpt); + Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg); + ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt); compositeVisitor->addVisitor(replicateVisitor, 300); } + + //create rotation visitor + if (args_info.refsele_given&& args_info.originsele_given) { + compositeVisitor->addVisitor(new LipidTransVisitor(info, args_info.originsele_arg, args_info.refsele_arg), 250); + } else if (args_info.refsele_given || args_info.originsele_given) { + std::cerr << "Both of --refsele and --originsele should appear by pair" << std::endl; + exit(1); + } + //creat xyzVisitor - xyzVisitor = new XYZVisitor(info); + XYZVisitor* xyzVisitor; + if (args_info.selection_given) { + xyzVisitor = new XYZVisitor(info, args_info.selection_arg); + } else { + xyzVisitor = new XYZVisitor(info); + } compositeVisitor->addVisitor(xyzVisitor, 200); - - cout << compositeVisitor->toString(); - + + std::cout << compositeVisitor->toString(); + //creat prepareVisitor - prepareVisitor = new PrepareVisitor(); - + PrepareVisitor* prepareVisitor = new PrepareVisitor(); + //open dump file - dumpReader = new DumpReader(dumpFileName.c_str()); - nframes = dumpReader->getNframes(); - + DumpReader* dumpReader = new DumpReader(info, dumpFileName); + int nframes = dumpReader->getNFrames(); + + + std::ofstream xyzStream; xyzStream .open(xyzFileName.c_str()); + + SimInfo::MoleculeIterator miter; + Molecule::IntegrableObjectIterator iiter; + Molecule::RigidBodyIterator rbIter; + Molecule* mol; + StuntDouble* integrableObject; + RigidBody* rb; + for (int i = 0; i < nframes; i += args_info.frame_arg){ - dumpReader->readFrame(info, i); - - mol = info->molecules; - + dumpReader->readFrame(i); + //update atoms of rigidbody - for(int j = 0; j < info->n_mol; j++){ - myRigidBodies = mol[j].getMyRigidBodies(); - - for(rbIter = myRigidBodies.begin(); rbIter != myRigidBodies.end(); ++rbIter) - (*rbIter)->updateAtoms(); - } - + for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { + + //change the positions of atoms which belong to the rigidbodies + for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { + rb->updateAtoms(); + } + } //prepare visit - for(int j = 0; j < info->n_mol; j++){ - integrableObjects = mol[j].getIntegrableObjects(); - - for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter) - (*iter)->accept(prepareVisitor); - } - + for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { + for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(iiter)) { + integrableObject->accept(prepareVisitor); + } + } + //update visitor compositeVisitor->update(); - - //visit stuntdouble - for(int j = 0; j < info->n_mol; j++){ - integrableObjects = mol[j].getIntegrableObjects(); - for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter) - (*iter)->accept(compositeVisitor); - } + //visit stuntdouble + for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { + for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(iiter)) { + integrableObject->accept(compositeVisitor); + } + } + xyzVisitor->writeFrame(xyzStream); xyzVisitor->clear(); }//end for (int i = 0; i < nframes; i += args_info.frame_arg) - + xyzStream.close(); - - + + delete compositeVisitor; delete info; - - + }