Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2013-2019 The plumed team
3 : (see the PEOPLE file at the root of the distribution for a list of names)
4 :
5 : See http://www.plumed.org for more information.
6 :
7 : This file is part of plumed, version 2.
8 :
9 : plumed is free software: you can redistribute it and/or modify
10 : it under the terms of the GNU Lesser General Public License as published by
11 : the Free Software Foundation, either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : plumed 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 Lesser General Public License for more details.
18 :
19 : You should have received a copy of the GNU Lesser General Public License
20 : along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 : #include "LandmarkSelectionBase.h"
23 : #include "reference/MultiReferenceBase.h"
24 :
25 : namespace PLMD {
26 : namespace analysis {
27 :
28 1 : LandmarkSelectionOptions::LandmarkSelectionOptions( const std::vector<std::string>& input, AnalysisWithLandmarks* myanalysis ):
29 : words(input),
30 1 : action(myanalysis)
31 : {
32 1 : }
33 :
34 1 : LandmarkSelectionBase::LandmarkSelectionBase( const LandmarkSelectionOptions& lo ):
35 : style(lo.words[0]),
36 : input(lo.words),
37 2 : action(lo.action)
38 : {
39 : input.erase( input.begin() );
40 1 : if( style=="ALL" ) {
41 1 : novoronoi=true;
42 : } else {
43 0 : parse("N",nlandmarks);
44 0 : parseFlag("NOVORONOI",novoronoi);
45 : }
46 2 : parseFlag("IGNORE_WEIGHTS",noweights);
47 1 : }
48 :
49 2 : LandmarkSelectionBase::~LandmarkSelectionBase() {
50 1 : }
51 :
52 1 : void LandmarkSelectionBase::parseFlag(const std::string& key, bool& t) {
53 1 : Tools::parseFlag(input,key,t);
54 1 : }
55 :
56 1 : void LandmarkSelectionBase::checkRead() const {
57 1 : if(!input.empty()) {
58 0 : std::string msg="cannot understand the following words from landmark selection input : ";
59 0 : for(unsigned i=0; i<input.size(); ++i) msg = msg + input[i] + ", ";
60 0 : plumed_merror(msg);
61 : }
62 1 : }
63 :
64 1 : std::string LandmarkSelectionBase::description() {
65 2 : std::ostringstream ostr;
66 2 : if( style=="ALL") {
67 1 : ostr<<"using all data";
68 : } else {
69 0 : ostr<<"selecting "<<nlandmarks<<" using "<<style<<" algorithm to analyze\n";
70 0 : ostr<<" "<<rest_of_description()<<"\n";
71 0 : if(noweights) ostr<<" ignoring all reweighting of data during landmark selection\n";
72 0 : if(novoronoi) ostr<<" voronoi weights will not be ascribed to points\n";
73 : }
74 1 : return ostr.str();
75 : }
76 :
77 0 : double LandmarkSelectionBase::getWeightOfFrame( const unsigned& iframe ) {
78 0 : if(noweights) return 1.0;
79 0 : return action->getWeight(iframe);
80 : }
81 0 : double LandmarkSelectionBase::getDistanceBetweenFrames( const unsigned& iframe, const unsigned& jframe ) {
82 0 : return distance( action->getPbc(), action->getArguments(), action->data[iframe], action->data[jframe], false );
83 : }
84 :
85 200 : void LandmarkSelectionBase::selectFrame( const unsigned& iframe, MultiReferenceBase* myframes) {
86 200 : plumed_assert( myframes->getNumberOfReferenceFrames()<nlandmarks );
87 400 : myframes->copyFrame( action->data[iframe] );
88 200 : }
89 :
90 2 : void LandmarkSelectionBase::selectLandmarks( MultiReferenceBase* myframes ) {
91 : // Select landmarks
92 2 : myframes->clearFrames(); select( myframes );
93 0 : plumed_assert( myframes->getNumberOfReferenceFrames()==nlandmarks );
94 :
95 : // Now calculate voronoi weights
96 2 : if( !novoronoi ) {
97 0 : unsigned rank=action->comm.Get_rank();
98 0 : unsigned size=action->comm.Get_size();
99 0 : std::vector<double> weights( nlandmarks, 0.0 );
100 0 : for(unsigned i=rank; i<action->data.size(); i+=size) {
101 : unsigned closest=0;
102 0 : double mindist=distance( action->getPbc(), action->getArguments(), action->data[i], myframes->getFrame(0), false );
103 0 : for(unsigned j=1; j<nlandmarks; ++j) {
104 0 : double dist=distance( action->getPbc(), action->getArguments(), action->data[i], myframes->getFrame(j), false );
105 0 : if( dist<mindist ) { mindist=dist; closest=j; }
106 : }
107 0 : weights[closest] += getWeightOfFrame(i);
108 : }
109 0 : action->comm.Sum( &weights[0], weights.size() );
110 0 : myframes->setWeights( weights );
111 : }
112 2 : }
113 :
114 : }
115 4839 : }
116 :
|