| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | *
|
|---|
| 7 | *
|
|---|
| 8 | * This file is part of MoleCuilder.
|
|---|
| 9 | *
|
|---|
| 10 | * MoleCuilder is free software: you can redistribute it and/or modify
|
|---|
| 11 | * it under the terms of the GNU General Public License as published by
|
|---|
| 12 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 13 | * (at your option) any later version.
|
|---|
| 14 | *
|
|---|
| 15 | * MoleCuilder is distributed in the hope that it will be useful,
|
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 18 | * GNU General Public License for more details.
|
|---|
| 19 | *
|
|---|
| 20 | * You should have received a copy of the GNU General Public License
|
|---|
| 21 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | * Extractors.cpp
|
|---|
| 26 | *
|
|---|
| 27 | * Created on: 15.10.2012
|
|---|
| 28 | * Author: heber
|
|---|
| 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 <utility>
|
|---|
| 39 | #include <vector>
|
|---|
| 40 | #include <boost/assign.hpp>
|
|---|
| 41 |
|
|---|
| 42 | #include "CodePatterns/Log.hpp"
|
|---|
| 43 |
|
|---|
| 44 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 45 |
|
|---|
| 46 | #include "FunctionApproximation/Extractors.hpp"
|
|---|
| 47 | #include "FunctionApproximation/FunctionArgument.hpp"
|
|---|
| 48 |
|
|---|
| 49 | using namespace boost::assign;
|
|---|
| 50 |
|
|---|
| 51 | FunctionModel::arguments_t
|
|---|
| 52 | Extractors::_detail::gatherAllDistanceArguments(
|
|---|
| 53 | const Fragment::positions_t &positions,
|
|---|
| 54 | const size_t globalid)
|
|---|
| 55 | {
|
|---|
| 56 | FunctionModel::arguments_t result;
|
|---|
| 57 |
|
|---|
| 58 | // go through current configuration and gather all other distances
|
|---|
| 59 | Fragment::positions_t::const_iterator firstpositer = positions.begin();
|
|---|
| 60 | for (;firstpositer != positions.end(); ++firstpositer) {
|
|---|
| 61 | Fragment::positions_t::const_iterator secondpositer = positions.begin();//firstpositer;
|
|---|
| 62 | for (; secondpositer != positions.end(); ++secondpositer) {
|
|---|
| 63 | if (firstpositer == secondpositer)
|
|---|
| 64 | continue;
|
|---|
| 65 | argument_t arg;
|
|---|
| 66 | const Vector firsttemp((*firstpositer)[0],(*firstpositer)[1],(*firstpositer)[2]);
|
|---|
| 67 | const Vector secondtemp((*secondpositer)[0],(*secondpositer)[1],(*secondpositer)[2]);
|
|---|
| 68 | arg.distance = firsttemp.distance(secondtemp);
|
|---|
| 69 | arg.indices = std::make_pair(
|
|---|
| 70 | std::distance(
|
|---|
| 71 | positions.begin(), firstpositer),
|
|---|
| 72 | std::distance(
|
|---|
| 73 | positions.begin(), secondpositer)
|
|---|
| 74 | );
|
|---|
| 75 | arg.globalid = globalid;
|
|---|
| 76 | result.push_back(arg);
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | return result;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | FunctionModel::arguments_t
|
|---|
| 84 | Extractors::gatherFirstDistance(
|
|---|
| 85 | const Fragment& fragment,
|
|---|
| 86 | const size_t index,
|
|---|
| 87 | const size_t firstelement,
|
|---|
| 88 | const size_t secondelement
|
|---|
| 89 | ) {
|
|---|
| 90 | const Fragment::charges_t charges = fragment.getCharges();
|
|---|
| 91 | const Fragment::positions_t positions = fragment.getPositions();
|
|---|
| 92 | typedef Fragment::charges_t::const_iterator chargeiter_t;
|
|---|
| 93 | std::vector< chargeiter_t > firstpair;
|
|---|
| 94 | firstpair.reserve(2);
|
|---|
| 95 | firstpair +=
|
|---|
| 96 | std::find(charges.begin(), charges.end(), firstelement),
|
|---|
| 97 | std::find(charges.begin(), charges.end(), secondelement);
|
|---|
| 98 | if ((firstpair[0] == charges.end()) || (firstpair[1] == charges.end())) {
|
|---|
| 99 | // complain if tuple not found
|
|---|
| 100 | ELOG(1, "Could not find pair " << firstelement << "," << secondelement
|
|---|
| 101 | << " in fragment " << fragment);
|
|---|
| 102 | return FunctionModel::arguments_t();
|
|---|
| 103 | }
|
|---|
| 104 | // convert position_t to Vector
|
|---|
| 105 | std::vector< std::pair<Vector, size_t> > DistancePair;
|
|---|
| 106 | for (std::vector<chargeiter_t>::const_iterator firstpairiter = firstpair.begin();
|
|---|
| 107 | firstpairiter != firstpair.end(); ++firstpairiter) {
|
|---|
| 108 | Fragment::positions_t::const_iterator positer = positions.begin();
|
|---|
| 109 | const size_t steps = std::distance(charges.begin(), *firstpairiter);
|
|---|
| 110 | std::advance(positer, steps);
|
|---|
| 111 | DistancePair.push_back(
|
|---|
| 112 | std::make_pair(Vector((*positer)[0], (*positer)[1], (*positer)[2]),
|
|---|
| 113 | steps));
|
|---|
| 114 | }
|
|---|
| 115 | // finally convert Vector pair to distance-like argument
|
|---|
| 116 | argument_t arg;
|
|---|
| 117 | arg.indices.first = DistancePair[0].second;
|
|---|
| 118 | arg.indices.second = DistancePair[1].second;
|
|---|
| 119 | arg.distance = DistancePair[0].first.distance(DistancePair[1].first);
|
|---|
| 120 | arg.globalid = index;
|
|---|
| 121 |
|
|---|
| 122 | return FunctionModel::arguments_t(1, arg);
|
|---|
| 123 | }
|
|---|