source: src/Dynamics/BondVectors.cpp@ 9861d0

AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity PythonUI_with_named_parameters StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 9861d0 was 9861d0, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

BondVectors now return subset of BondVectors for a given atom.

  • functionality extracted from ForceAnnealing::annealWithBondgraph().
  • also the mapped_t type is now kept up-to-date internally as we need it for returning the subset efficiently over a number of atoms, e.g. all in the given range.
  • also moved a few simple implementations over to _impl module.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2017 Frederik Heber. 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 * BondVectors.cpp
25 *
26 * Created on: Jun 13, 2017
27 * Author: heber
28 */
29
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36//#include "CodePatterns/MemDebug.hpp"
37
38#include "BondVectors.hpp"
39
40#include <algorithm>
41#include <iterator>
42
43#include "CodePatterns/Assert.hpp"
44#include "CodePatterns/Log.hpp"
45
46#include "Atom/atom.hpp"
47#include "Bond/bond.hpp"
48
49void BondVectors::recalculateBondVectorsAtStep(
50 const size_t &_step) const
51{
52 current_mapped_vectors.clear();
53
54 ASSERT( !container.empty(),
55 "BondVectors::getBondVectors() - container empty, not set properly?");
56 for (container_t::const_iterator iter = container.begin();
57 iter != container.end(); ++iter) {
58 const bond::ptr &current_bond = *iter;
59 Vector BondVector = current_bond->leftatom->getPositionAtStep(_step)
60 - current_bond->rightatom->getPositionAtStep(_step);
61 BondVector.Normalize();
62 current_mapped_vectors.insert( std::make_pair(current_bond, BondVector) );
63 }
64 ASSERT( current_mapped_vectors.size() == container.size(),
65 "BondVectors::getBondVectors() - not same amount of bond vectors as bonds?");
66
67 map_is_dirty = false;
68 current_step_for_map = _step;
69}
70
71size_t BondVectors::getIndexForBond(const bond::ptr &_bond) const
72{
73 std::pair<
74 container_t::const_iterator,
75 container_t::const_iterator> iters =
76 std::equal_range(container.begin(), container.end(), _bond);
77 if (iters.first != container.end())
78 return std::distance(container.begin(), iters.first);
79 else
80 return (size_t)-1;
81}
82
83std::vector<Vector> BondVectors::getAtomsBondVectorsAtStep(
84 const atom &_walker,
85 const size_t &_step) const
86{
87 if (map_is_dirty || (current_step_for_map != _step))
88 recalculateBondVectorsAtStep(_step);
89
90 std::vector<Vector> BondVectors;
91 // gather subset of BondVectors for the current atom
92 const BondList& ListOfBonds = _walker.getListOfBonds();
93 for(BondList::const_iterator bonditer = ListOfBonds.begin();
94 bonditer != ListOfBonds.end(); ++bonditer) {
95 const bond::ptr &current_bond = *bonditer;
96 const BondVectors::mapped_t::const_iterator bviter =
97 current_mapped_vectors.find(current_bond);
98 ASSERT( bviter != current_mapped_vectors.end(),
99 "ForceAnnealing() - cannot find current_bond ?");
100 ASSERT( bviter != current_mapped_vectors.end(),
101 "ForceAnnealing - cannot find current bond "+toString(*current_bond)
102 +" in bonds.");
103 BondVectors.push_back(bviter->second);
104 }
105 LOG(4, "DEBUG: BondVectors for atom #" << _walker.getId() << ": " << BondVectors);
106
107 return BondVectors;
108}
Note: See TracBrowser for help on using the repository browser.