Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2023 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 "DataCollectionObject.h" 23 : #include "tools/PDB.h" 24 : 25 : namespace PLMD { 26 : namespace analysis { 27 : 28 7556 : void DataCollectionObject::setAtomNumbersAndArgumentNames( const std::string& action_label, const std::vector<AtomNumber>& ind, const std::vector<std::string>& arg_names ) { 29 7556 : myaction=action_label; indices.resize( ind.size() ); positions.resize( indices.size() ); 30 21193 : for(unsigned i=0; i<ind.size(); ++i) indices[i]=ind[i]; 31 16583 : for(unsigned i=0; i<arg_names.size(); ++i) args.insert( std::pair<std::string,double>( arg_names[i], 0.0 ) ); 32 7556 : } 33 : 34 7556 : void DataCollectionObject::setAtomPositions( const std::vector<Vector>& pos ) { 35 : plumed_dbg_assert( pos.size()==positions.size() && pos.size()==indices.size() ); 36 21193 : for(unsigned i=0; i<positions.size(); ++i) positions[i]=pos[i]; 37 7556 : } 38 : 39 16321 : void DataCollectionObject::setArgument( const std::string& name, const double& value ) { 40 : std::map<std::string,double>::iterator it = args.find(name); 41 16321 : if( it!=args.end() ) it->second = value; 42 6694 : else args.insert( std::pair<std::string,double>( name, value ) ); 43 16321 : } 44 : 45 522438 : bool DataCollectionObject::transferDataToPDB( PDB& mypdb ) { 46 : // Check if PDB contains argument names 47 522438 : std::vector<std::string> pdb_args( mypdb.getArgumentNames() ); 48 : // Now set the argument values 49 : std::map<std::string,double>::iterator it; 50 2024164 : for(unsigned i=0; i<pdb_args.size(); ++i) { 51 : it=args.find( pdb_args[i] ); 52 1501726 : if( it==args.end() ) return false; 53 1501726 : mypdb.setArgumentValue( pdb_args[i], it->second ); 54 : } 55 : // Now set the atomic positions 56 522438 : std::vector<AtomNumber> pdb_pos( mypdb.getAtomNumbers() ); 57 522438 : if( pdb_pos.size()==positions.size() ) mypdb.setAtomPositions( positions ); 58 29720 : else if( pdb_pos.size()>0 ) plumed_merror("This feature is currently not ready"); 59 : return true; 60 522438 : } 61 : 62 : } 63 : }