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 |
|
---|
20 | #include "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "atom.hpp"
|
---|
23 | #include "bondgraph.hpp"
|
---|
24 | #include "boundary.hpp"
|
---|
25 | #include "config.hpp"
|
---|
26 | #include "molecule.hpp"
|
---|
27 | #include "CodePatterns/Verbose.hpp"
|
---|
28 | #include "World.hpp"
|
---|
29 |
|
---|
30 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
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 |
|
---|
38 | #include <algorithm>
|
---|
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 |
|
---|
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 |
|
---|
59 | DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, lengths(" << params.lengths[0] << "," << params.lengths[1] << "," << params.lengths[2] << "), distances (" << params.distances[0] << "," << params.distances[1] << "," << params.distances[2] << "), MinDistance " << params.MinDistance << ", DoRotate " << params.DoRotate << "." << endl);
|
---|
60 | // construct water molecule
|
---|
61 | std::vector<molecule *> presentmolecules = World::getInstance().getAllMolecules();
|
---|
62 | // DoLog(0) && (Log() << Verbose(0) << presentmolecules.size() << " molecules initially are present." << std::endl);
|
---|
63 | std::string FilenameSuffix = params.fillername.string().substr(params.fillername.string().find_last_of('.')+1, params.fillername.string().length());
|
---|
64 | ifstream input;
|
---|
65 | input.open(params.fillername.string().c_str());
|
---|
66 | switch (FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix)) {
|
---|
67 | case mpqc:
|
---|
68 | {
|
---|
69 | MpqcParser mpqcparser;
|
---|
70 | mpqcparser.load(&input);
|
---|
71 | break;
|
---|
72 | }
|
---|
73 | case pcp:
|
---|
74 | {
|
---|
75 | PcpParser pcpparser;
|
---|
76 | pcpparser.load(&input);
|
---|
77 | break;
|
---|
78 | }
|
---|
79 | case pdb:
|
---|
80 | {
|
---|
81 | PdbParser pdbparser;
|
---|
82 | pdbparser.load(&input);
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | case tremolo:
|
---|
86 | {
|
---|
87 | TremoloParser tremoloparser;
|
---|
88 | tremoloparser.load(&input);
|
---|
89 | break;
|
---|
90 | }
|
---|
91 | case xyz:
|
---|
92 | {
|
---|
93 | XyzParser xyzparser;
|
---|
94 | xyzparser.load(&input);
|
---|
95 | break;
|
---|
96 | }
|
---|
97 | default:
|
---|
98 | DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << params.fillername << "." << endl);
|
---|
99 | break;
|
---|
100 | }
|
---|
101 |
|
---|
102 | // search the filler molecule that has been just parsed
|
---|
103 | molecule *filler = NULL;
|
---|
104 | for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
|
---|
105 | iter != World::getInstance().moleculeEnd();
|
---|
106 | ++iter)
|
---|
107 | filler = *iter; // get last molecule
|
---|
108 | filler->SetNameFromFilename(params.fillername.string().c_str());
|
---|
109 | World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
|
---|
110 |
|
---|
111 | // call routine
|
---|
112 | double distance[NDIM];
|
---|
113 | for (int i=0;i<NDIM;i++)
|
---|
114 | distance[i] = params.distances[i];
|
---|
115 | FillVoidWithMolecule(filler, *(World::getInstance().getConfig()), distance, params.lengths[0], params.lengths[1], params.lengths[2], params.MinDistance, params.DoRotate);
|
---|
116 |
|
---|
117 | // generate list of newly created molecules
|
---|
118 | // (we can in general remove more quickly from a list than a vector)
|
---|
119 | std::vector<molecule *> fillermolecules = World::getInstance().getAllMolecules();
|
---|
120 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules are present." << std::endl);
|
---|
121 | std::list<molecule *> fillermolecules_list;
|
---|
122 | std::copy( fillermolecules.begin(), fillermolecules.end(), std::back_inserter( fillermolecules_list ));
|
---|
123 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules have been copied." << std::endl);
|
---|
124 | for (std::vector<molecule *>::const_iterator iter = presentmolecules.begin();
|
---|
125 | iter != presentmolecules.end();
|
---|
126 | ++iter) {
|
---|
127 | fillermolecules_list.remove(*iter);
|
---|
128 | }
|
---|
129 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules left after removal." << std::endl);
|
---|
130 | fillermolecules.clear();
|
---|
131 | std::copy(fillermolecules_list.begin(), fillermolecules_list.end(), std::back_inserter( fillermolecules ));
|
---|
132 |
|
---|
133 | // DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules have been inserted." << std::endl);
|
---|
134 |
|
---|
135 | return Action::state_ptr(new MoleculeFillVoidWithMoleculeState(fillermolecules,params));
|
---|
136 | }
|
---|
137 |
|
---|
138 | Action::state_ptr MoleculeFillVoidWithMoleculeAction::performUndo(Action::state_ptr _state) {
|
---|
139 | MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
|
---|
140 |
|
---|
141 | MoleculeListClass *MolList = World::getInstance().getMolecules();
|
---|
142 |
|
---|
143 | BOOST_FOREACH(molecule *_mol, state->fillermolecules) {
|
---|
144 | MolList->erase(_mol);
|
---|
145 | if ((_mol != NULL) && (!(World::getInstance().getAllMolecules(MoleculeById(_mol->getId()))).empty())) {
|
---|
146 | for(molecule::iterator iter = _mol->begin();
|
---|
147 | !_mol->empty();
|
---|
148 | iter = _mol->begin()) {
|
---|
149 | atom *Walker = *iter;
|
---|
150 | _mol->erase(iter);
|
---|
151 | World::getInstance().destroyAtom(Walker);
|
---|
152 | }
|
---|
153 | World::getInstance().destroyMolecule(_mol);
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | // as molecules and atoms from state are removed, we have to create a new one
|
---|
158 | std::vector<molecule *> fillermolecules;
|
---|
159 | return Action::state_ptr(new MoleculeFillVoidWithMoleculeState(fillermolecules,state->params));
|
---|
160 | }
|
---|
161 |
|
---|
162 | Action::state_ptr MoleculeFillVoidWithMoleculeAction::performRedo(Action::state_ptr _state){
|
---|
163 | //MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
|
---|
164 |
|
---|
165 | return Action::failure;
|
---|
166 | //return Action::state_ptr(_state);
|
---|
167 | }
|
---|
168 |
|
---|
169 | bool MoleculeFillVoidWithMoleculeAction::canUndo() {
|
---|
170 | return true;
|
---|
171 | }
|
---|
172 |
|
---|
173 | bool MoleculeFillVoidWithMoleculeAction::shouldUndo() {
|
---|
174 | return true;
|
---|
175 | }
|
---|
176 | /** =========== end of function ====================== */
|
---|