source: src/Actions/MoleculeAction/StretchBondAction.cpp

Candidate_v1.7.1 stable v1.7.1
Last change on this file was d2be22, checked in by Frederik Heber <frederik.heber@…>, 7 weeks ago

Actions relying on BondGraph fail if not bond table is loaded.

  • this is to ensure to not stumble over missing optimal bond lengths from the table, like with StretchBondAction.
  • TESTFIX: All regression tests that use these actions need to load the bond-table now.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * StretchBondAction.cpp
25 *
26 * Created on: Sep 26, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include "Actions/MoleculeAction/StretchBondAction.hpp"
38
39#include <boost/bind.hpp>
40
41#include "CodePatterns/Log.hpp"
42#include "CodePatterns/Verbose.hpp"
43
44#include "LinearAlgebra/Plane.hpp"
45
46#include "Atom/atom.hpp"
47#include "Bond/bond.hpp"
48#include "Bond/StretchBond.hpp"
49#include "Graph/BondGraph.hpp"
50#include "Graph/BoostGraphHelpers.hpp"
51#include "World.hpp"
52
53using namespace MoleCuilder;
54
55// and construct the stuff
56#include "StretchBondAction.def"
57#include "Action_impl_pre.hpp"
58
59
60/** =========== define the function ====================== */
61ActionState::ptr MoleculeStretchBondAction::performCall()
62{
63 BondGraph *BG = World::getInstance().getBondGraph();
64 if (!BG->IsBondLengthTableLoaded()) {
65 STATUS("BondLength table has not been loaded.");
66 return Action::failure;
67 }
68
69 const std::vector< atom *> atoms = World::getInstance().getSelectedAtoms();
70 StretchBondUtil stretcher(atoms);
71
72 const double bonddistance = params.bonddistance.get();
73 bool status = stretcher(bonddistance);
74
75 if (status) {
76 MoleculeStretchBondState *UndoState =
77 new MoleculeStretchBondState(
78 stretcher.getShift(),
79 stretcher.getBondSides(),
80 &stretcher.getMolecule(),
81 params);
82 return ActionState::ptr(UndoState);
83 } else {
84 STATUS("Failed, exactly two atoms must be selected.");
85 return Action::failure;
86 }
87}
88
89ActionState::ptr MoleculeStretchBondAction::performUndo(ActionState::ptr _state) {
90 MoleculeStretchBondState *state = assert_cast<MoleculeStretchBondState*>(_state.get());
91
92 // use given plane to undo
93 Box &domain = World::getInstance().getDomain();
94 for (size_t i=0;i<2;++i) {
95 for (BoostGraphHelpers::Nodeset_t::const_iterator iter = state->bondside_sets[i].begin();
96 iter != state->bondside_sets[i].end(); ++iter) {
97 atom &walker = *World::getInstance().getAtom(AtomById(*iter));
98 const Vector &position = walker.getPosition();
99 walker.setPosition( domain.enforceBoundaryConditions(position-state->Shift[i]) );
100 }
101 }
102
103 return ActionState::ptr(_state);
104}
105
106ActionState::ptr MoleculeStretchBondAction::performRedo(ActionState::ptr _state){
107 MoleculeStretchBondState *state = assert_cast<MoleculeStretchBondState*>(_state.get());
108
109 Box &domain = World::getInstance().getDomain();
110 for (size_t i=0;i<2;++i) {
111 for (BoostGraphHelpers::Nodeset_t::const_iterator iter = state->bondside_sets[i].begin();
112 iter != state->bondside_sets[i].end(); ++iter) {
113 atom &walker = *World::getInstance().getAtom(AtomById(*iter));
114 const Vector &position = walker.getPosition();
115 walker.setPosition( domain.enforceBoundaryConditions(position+state->Shift[i]) );
116 }
117 }
118
119 return ActionState::ptr(_state);
120}
121
122bool MoleculeStretchBondAction::canUndo() {
123 return true;
124}
125
126bool MoleculeStretchBondAction::shouldUndo() {
127 return true;
128}
129/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.