[eee966] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * FillVoidWithMoleculeAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 10, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[eee966] | 21 |
|
---|
| 22 | #include "atom.hpp"
|
---|
| 23 | #include "bondgraph.hpp"
|
---|
| 24 | #include "boundary.hpp"
|
---|
| 25 | #include "config.hpp"
|
---|
| 26 | #include "molecule.hpp"
|
---|
[ad011c] | 27 | #include "CodePatterns/Verbose.hpp"
|
---|
[eee966] | 28 | #include "World.hpp"
|
---|
| 29 |
|
---|
[66fd49] | 30 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
[eee966] | 31 | #include "Parser/MpqcParser.hpp"
|
---|
| 32 | #include "Parser/PcpParser.hpp"
|
---|
| 33 | #include "Parser/PdbParser.hpp"
|
---|
| 34 | #include "Parser/TremoloParser.hpp"
|
---|
| 35 | #include "Parser/XyzParser.hpp"
|
---|
| 36 | #include "Parser/FormatParserStorage.hpp"
|
---|
| 37 |
|
---|
[66fd49] | 38 | #include <algorithm>
|
---|
[eee966] | 39 | #include <iostream>
|
---|
| 40 | #include <string>
|
---|
| 41 |
|
---|
| 42 | using namespace std;
|
---|
| 43 |
|
---|
| 44 | #include "Actions/MoleculeAction/FillVoidWithMoleculeAction.hpp"
|
---|
| 45 |
|
---|
| 46 | // and construct the stuff
|
---|
| 47 | #include "FillVoidWithMoleculeAction.def"
|
---|
| 48 | #include "Action_impl_pre.hpp"
|
---|
| 49 | /** =========== define the function ====================== */
|
---|
| 50 | Action::state_ptr MoleculeFillVoidWithMoleculeAction::performCall() {
|
---|
| 51 | // obtain information
|
---|
| 52 | getParametersfromValueStorage();
|
---|
| 53 |
|
---|
[66fd49] | 54 | if (!boost::filesystem::exists(params.fillername)) {
|
---|
| 55 | DoeLog(1) && (eLog() << Verbose(1) << "File with filler molecule " << params.fillername << " does not exist!" << endl);
|
---|
| 56 | return Action::failure;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[d6f886] | 59 | DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, "
|
---|
| 60 | << " minimum distance to molecules" << params.boundary
|
---|
| 61 | << ", random atom displacement " << params.RandAtomDisplacement
|
---|
| 62 | << ", random molecule displacement " << params.RandMoleculeDisplacement
|
---|
| 63 | << ", distances between fillers (" << params.distances[0] << "," << params.distances[1] << "," << params.distances[2]
|
---|
| 64 | << "), MinDistance " << params.MinDistance
|
---|
| 65 | << ", DoRotate " << params.DoRotate << "." << endl);
|
---|
[eee966] | 66 | // construct water molecule
|
---|
[66fd49] | 67 | std::vector<molecule *> presentmolecules = World::getInstance().getAllMolecules();
|
---|
| 68 | // DoLog(0) && (Log() << Verbose(0) << presentmolecules.size() << " molecules initially are present." << std::endl);
|
---|
[e4afb4] | 69 | std::string FilenameSuffix = params.fillername.string().substr(params.fillername.string().find_last_of('.')+1, params.fillername.string().length());
|
---|
[eee966] | 70 | ifstream input;
|
---|
[e4afb4] | 71 | input.open(params.fillername.string().c_str());
|
---|
[eee966] | 72 | switch (FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix)) {
|
---|
| 73 | case mpqc:
|
---|
| 74 | {
|
---|
| 75 | MpqcParser mpqcparser;
|
---|
| 76 | mpqcparser.load(&input);
|
---|
| 77 | break;
|
---|
| 78 | }
|
---|
| 79 | case pcp:
|
---|
| 80 | {
|
---|
| 81 | PcpParser pcpparser;
|
---|
| 82 | pcpparser.load(&input);
|
---|
| 83 | break;
|
---|
| 84 | }
|
---|
| 85 | case pdb:
|
---|
| 86 | {
|
---|
| 87 | PdbParser pdbparser;
|
---|
| 88 | pdbparser.load(&input);
|
---|
| 89 | break;
|
---|
| 90 | }
|
---|
| 91 | case tremolo:
|
---|
| 92 | {
|
---|
| 93 | TremoloParser tremoloparser;
|
---|
| 94 | tremoloparser.load(&input);
|
---|
| 95 | break;
|
---|
| 96 | }
|
---|
| 97 | case xyz:
|
---|
| 98 | {
|
---|
| 99 | XyzParser xyzparser;
|
---|
| 100 | xyzparser.load(&input);
|
---|
| 101 | break;
|
---|
| 102 | }
|
---|
| 103 | default:
|
---|
| 104 | DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << params.fillername << "." << endl);
|
---|
| 105 | break;
|
---|
| 106 | }
|
---|
[66fd49] | 107 |
|
---|
| 108 | // search the filler molecule that has been just parsed
|
---|
| 109 | molecule *filler = NULL;
|
---|
| 110 | for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
|
---|
| 111 | iter != World::getInstance().moleculeEnd();
|
---|
| 112 | ++iter)
|
---|
[eee966] | 113 | filler = *iter; // get last molecule
|
---|
[e4afb4] | 114 | filler->SetNameFromFilename(params.fillername.string().c_str());
|
---|
[eee966] | 115 | World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
|
---|
| 116 |
|
---|
| 117 | // call routine
|
---|
| 118 | double distance[NDIM];
|
---|
| 119 | for (int i=0;i<NDIM;i++)
|
---|
| 120 | distance[i] = params.distances[i];
|
---|
[d6f886] | 121 | FillVoidWithMolecule(
|
---|
| 122 | filler,
|
---|
| 123 | *(World::getInstance().getConfig()),
|
---|
| 124 | distance,
|
---|
| 125 | params.boundary,
|
---|
| 126 | params.RandAtomDisplacement,
|
---|
| 127 | params.RandMoleculeDisplacement,
|
---|
| 128 | params.MinDistance,
|
---|
| 129 | params.DoRotate);
|
---|
[66fd49] | 130 |
|
---|
| 131 | // generate list of newly created molecules
|
---|
| 132 | // (we can in general remove more quickly from a list than a vector)
|
---|
| 133 | std::vector<molecule *> fillermolecules = World::getInstance().getAllMolecules();
|
---|
| 134 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules are present." << std::endl);
|
---|
| 135 | std::list<molecule *> fillermolecules_list;
|
---|
| 136 | std::copy( fillermolecules.begin(), fillermolecules.end(), std::back_inserter( fillermolecules_list ));
|
---|
| 137 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules have been copied." << std::endl);
|
---|
| 138 | for (std::vector<molecule *>::const_iterator iter = presentmolecules.begin();
|
---|
| 139 | iter != presentmolecules.end();
|
---|
| 140 | ++iter) {
|
---|
| 141 | fillermolecules_list.remove(*iter);
|
---|
| 142 | }
|
---|
| 143 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules left after removal." << std::endl);
|
---|
| 144 | fillermolecules.clear();
|
---|
| 145 | std::copy(fillermolecules_list.begin(), fillermolecules_list.end(), std::back_inserter( fillermolecules ));
|
---|
| 146 |
|
---|
| 147 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules have been inserted." << std::endl);
|
---|
[eee966] | 148 |
|
---|
[66fd49] | 149 | return Action::state_ptr(new MoleculeFillVoidWithMoleculeState(fillermolecules,params));
|
---|
[eee966] | 150 | }
|
---|
| 151 |
|
---|
| 152 | Action::state_ptr MoleculeFillVoidWithMoleculeAction::performUndo(Action::state_ptr _state) {
|
---|
[66fd49] | 153 | MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
|
---|
| 154 |
|
---|
| 155 | MoleculeListClass *MolList = World::getInstance().getMolecules();
|
---|
| 156 |
|
---|
| 157 | BOOST_FOREACH(molecule *_mol, state->fillermolecules) {
|
---|
| 158 | MolList->erase(_mol);
|
---|
| 159 | if ((_mol != NULL) && (!(World::getInstance().getAllMolecules(MoleculeById(_mol->getId()))).empty())) {
|
---|
| 160 | for(molecule::iterator iter = _mol->begin();
|
---|
| 161 | !_mol->empty();
|
---|
| 162 | iter = _mol->begin()) {
|
---|
| 163 | atom *Walker = *iter;
|
---|
| 164 | _mol->erase(iter);
|
---|
| 165 | World::getInstance().destroyAtom(Walker);
|
---|
| 166 | }
|
---|
| 167 | World::getInstance().destroyMolecule(_mol);
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
[eee966] | 170 |
|
---|
[66fd49] | 171 | // as molecules and atoms from state are removed, we have to create a new one
|
---|
| 172 | std::vector<molecule *> fillermolecules;
|
---|
| 173 | return Action::state_ptr(new MoleculeFillVoidWithMoleculeState(fillermolecules,state->params));
|
---|
[eee966] | 174 | }
|
---|
| 175 |
|
---|
| 176 | Action::state_ptr MoleculeFillVoidWithMoleculeAction::performRedo(Action::state_ptr _state){
|
---|
[66fd49] | 177 | //MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
|
---|
| 178 |
|
---|
| 179 | return Action::failure;
|
---|
| 180 | //return Action::state_ptr(_state);
|
---|
[eee966] | 181 | }
|
---|
| 182 |
|
---|
| 183 | bool MoleculeFillVoidWithMoleculeAction::canUndo() {
|
---|
[66fd49] | 184 | return true;
|
---|
[eee966] | 185 | }
|
---|
| 186 |
|
---|
| 187 | bool MoleculeFillVoidWithMoleculeAction::shouldUndo() {
|
---|
[66fd49] | 188 | return true;
|
---|
[eee966] | 189 | }
|
---|
| 190 | /** =========== end of function ====================== */
|
---|