source: src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp@ 66fd49

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 66fd49 was 66fd49, checked in by Frederik Heber <heber@…>, 14 years ago

Rewrite of FillVoidWithMoleculeAction.

FillVoidWithMoleculeAction:

  • new parameter MinDistance and default value of 0.
  • BUGFIX: filler is already created when parsing file, removed useless creation of it initially (also caused lots of confusion due to an "extra" molecule).
  • Undo implemented, regression test inserted.
  • Redo is somewhat hard to implement, as one would use performCall() if it only it would not retrieve its values from ValueStorage ...

FillVoidWithMolecule():

  • filler is now the zeroth not the last molecule, marked by firstInsertion and firstInserter. Filler is removed if no molecules are filled.
  • outsourced stuff into smaller functions
  • removed FillIt to through every atom despite only CurrentPosition, indepedent of atom position, is checked.

TESTFIXES:

  • Analysis/3: test.xyz changed because boundary is now 1.5 instead of 2.1 as 2.1 is not enough of molecules get filled in (and the filler already is).
  • Analysis/3: tensid.data was actually lacking water at (0,0,0) which is after the rewrite present.
  • Property mode set to 100644
File size: 6.3 KB
Line 
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
42using 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 ====================== */
50Action::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
138Action::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
162Action::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
169bool MoleculeFillVoidWithMoleculeAction::canUndo() {
170 return true;
171}
172
173bool MoleculeFillVoidWithMoleculeAction::shouldUndo() {
174 return true;
175}
176/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.