LCOV - code coverage report
Current view: top level - reference - ReferenceAtoms.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 44 58 75.9 %
Date: 2020-11-18 11:20:57 Functions: 9 11 81.8 %

          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 "ReferenceAtoms.h"
      23             : #include "tools/OFile.h"
      24             : #include "tools/PDB.h"
      25             : 
      26             : namespace PLMD {
      27             : 
      28        1256 : ReferenceAtoms::ReferenceAtoms( const ReferenceConfigurationOptions& ro ):
      29             :   ReferenceConfiguration(ro),
      30        1256 :   checks_were_disabled(false)
      31             : {
      32        1256 : }
      33             : 
      34         446 : void ReferenceAtoms::readAtomsFromPDB( const PDB& pdb, const bool allowblocks  ) {
      35         446 :   if( !allowblocks && pdb.getNumberOfAtomBlocks()!=1 ) error("found multi-atom-block pdb format but expecting only one block of atoms");
      36             : 
      37       16006 :   for(unsigned i=0; i<pdb.size(); ++i) {
      38       23340 :     indices.push_back( pdb.getAtomNumbers()[i] ); reference_atoms.push_back( pdb.getPositions()[i] );
      39       23340 :     align.push_back( pdb.getOccupancy()[i] ); displace.push_back( pdb.getBeta()[i] );
      40             :   }
      41         892 :   atom_der_index.resize( reference_atoms.size() );
      42         446 : }
      43             : 
      44         764 : void ReferenceAtoms::setAtomNumbers( const std::vector<AtomNumber>& numbers ) {
      45        2292 :   reference_atoms.resize( numbers.size() ); align.resize( numbers.size() );
      46        2292 :   displace.resize( numbers.size() ); atom_der_index.resize( numbers.size() );
      47        1528 :   indices.resize( numbers.size() );
      48       39610 :   for(unsigned i=0; i<numbers.size(); ++i) {
      49       25388 :     indices[i]=numbers[i]; atom_der_index[i]=i;
      50             :   }
      51         764 : }
      52             : 
      53          18 : void ReferenceAtoms::printAtoms( OFile& ofile, const double& lunits ) const {
      54          54 :   plumed_assert( indices.size()==reference_atoms.size() && align.size()==reference_atoms.size() && displace.size()==reference_atoms.size() );
      55         741 :   for(unsigned i=0; i<reference_atoms.size(); ++i) {
      56        1410 :     ofile.printf("ATOM  %5d  X   RES  %4u    %8.3f%8.3f%8.3f%6.2f%6.2f\n",
      57             :                  indices[i].serial(), i,
      58         940 :                  lunits*reference_atoms[i][0], lunits*reference_atoms[i][1], lunits*reference_atoms[i][2],
      59             :                  align[i], displace[i] );
      60             :   }
      61          18 : }
      62             : 
      63           0 : bool ReferenceAtoms::parseAtomList( const std::string& key, std::vector<unsigned>& numbers ) {
      64           0 :   plumed_assert( numbers.size()==0 );
      65             : 
      66           0 :   std::vector<std::string> strings;
      67           0 :   if( !parseVector(key,strings,true) ) return false;
      68           0 :   Tools::interpretRanges(strings);
      69             : 
      70           0 :   numbers.resize( strings.size() );
      71           0 :   for(unsigned i=0; i<strings.size(); ++i) {
      72             :     AtomNumber atom;
      73           0 :     if( !Tools::convert(strings[i],atom ) ) error("could not convert " + strings[i] + " into atom number");
      74             : 
      75             :     bool found=false;
      76           0 :     for(unsigned j=0; j<indices.size(); ++j) {
      77           0 :       if( atom==indices[j] ) { found=true; numbers[i]=j; break; }
      78             :     }
      79           0 :     if(!found) error("atom labelled " + strings[i] + " is not present in pdb input file");
      80             :   }
      81             :   return true;
      82             : }
      83             : 
      84         445 : void ReferenceAtoms::getAtomRequests( std::vector<AtomNumber>& numbers, bool disable_checks ) {
      85         445 :   singleDomainRequests(numbers,disable_checks);
      86         445 : }
      87             : 
      88         445 : void ReferenceAtoms::singleDomainRequests( std::vector<AtomNumber>& numbers, bool disable_checks ) {
      89         445 :   checks_were_disabled=disable_checks;
      90         890 :   atom_der_index.resize( indices.size() );
      91             : 
      92         445 :   if( numbers.size()==0 ) {
      93       10263 :     for(unsigned i=0; i<indices.size(); ++i) {
      94        3355 :       numbers.push_back( indices[i] );
      95        3355 :       atom_der_index[i]=i;
      96             :     }
      97             :   } else {
      98         346 :     if(!disable_checks) {
      99         346 :       if( numbers.size()!=indices.size() ) error("mismatched numbers of atoms in pdb frames");
     100             :     }
     101             : 
     102       14042 :     for(unsigned i=0; i<indices.size(); ++i) {
     103             :       bool found=false;
     104        4450 :       if(!disable_checks) {
     105        4450 :         if( indices[i]!=numbers[i] ) error("found mismatched reference atoms in pdb frames");
     106        4450 :         atom_der_index[i]=i;
     107             :       } else {
     108           0 :         for(unsigned j=0; j<numbers.size(); ++j) {
     109           0 :           if( indices[i]==numbers[j] ) { found=true; atom_der_index[i]=j; break; }
     110             :         }
     111             :         if( !found ) {
     112           0 :           atom_der_index[i]=numbers.size(); numbers.push_back( indices[i] );
     113             :         }
     114             :       }
     115             :     }
     116             :   }
     117         445 : }
     118             : 
     119         494 : void ReferenceAtoms::displaceReferenceAtoms( const double& weight, const std::vector<Vector>& dir ) {
     120             :   plumed_dbg_assert( dir.size()==reference_atoms.size() );
     121        1872 :   for(unsigned i=0; i<dir.size(); ++i) reference_atoms[i] += weight*dir.size()*dir[i];
     122         494 : }
     123             : 
     124        4839 : }

Generated by: LCOV version 1.13