LCOV - code coverage report
Current view: top level - reference - ReferenceAtoms.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 43 61 70.5 %
Date: 2018-12-19 07:49:13 Functions: 8 10 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2018 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         992 : ReferenceAtoms::ReferenceAtoms( const ReferenceConfigurationOptions& ro ):
      29             :   ReferenceConfiguration(ro),
      30         992 :   checks_were_disabled(false)
      31             : {
      32         992 : }
      33             : 
      34         386 : void ReferenceAtoms::readAtomsFromPDB( const PDB& pdb, const bool allowblocks  ) {
      35         386 :   if( !allowblocks && pdb.getNumberOfAtomBlocks()!=1 ) error("found multi-atom-block pdb format but expecting only one block of atoms");
      36             : 
      37        7426 :   for(unsigned i=0; i<pdb.size(); ++i) {
      38        7040 :     indices.push_back( pdb.getAtomNumbers()[i] ); reference_atoms.push_back( pdb.getPositions()[i] );
      39        7040 :     align.push_back( pdb.getOccupancy()[i] ); displace.push_back( pdb.getBeta()[i] );
      40             :   }
      41         386 :   atom_der_index.resize( reference_atoms.size() );
      42         386 : }
      43             : 
      44         560 : void ReferenceAtoms::setAtomNumbers( const std::vector<AtomNumber>& numbers ) {
      45         560 :   reference_atoms.resize( numbers.size() ); align.resize( numbers.size() );
      46         560 :   displace.resize( numbers.size() ); atom_der_index.resize( numbers.size() );
      47         560 :   indices.resize( numbers.size() );
      48       12717 :   for(unsigned i=0; i<numbers.size(); ++i) {
      49       12157 :     indices[i]=numbers[i]; atom_der_index[i]=i;
      50             :   }
      51         560 : }
      52             : 
      53           5 : void ReferenceAtoms::printAtoms( OFile& ofile, const double& lunits ) const {
      54           5 :   plumed_assert( indices.size()==reference_atoms.size() && align.size()==reference_atoms.size() && displace.size()==reference_atoms.size() );
      55          71 :   for(unsigned i=0; i<reference_atoms.size(); ++i) {
      56             :     ofile.printf("ATOM  %5d  X   RES  %4u    %8.3f%8.3f%8.3f%6.2f%6.2f\n",
      57          66 :                  indices[i].serial(), i,
      58         198 :                  lunits*reference_atoms[i][0], lunits*reference_atoms[i][1], lunits*reference_atoms[i][2],
      59         330 :                  align[i], displace[i] );
      60             :   }
      61           5 : }
      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           0 :     AtomNumber atom;
      73           0 :     if( !Tools::convert(strings[i],atom ) ) error("could not convert " + strings[i] + " into atom number");
      74             : 
      75           0 :     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           0 :   return true;
      82             : }
      83             : 
      84         389 : void ReferenceAtoms::getAtomRequests( std::vector<AtomNumber>& numbers, bool disable_checks ) {
      85         389 :   singleDomainRequests(numbers,disable_checks);
      86         389 : }
      87             : 
      88         389 : void ReferenceAtoms::singleDomainRequests( std::vector<AtomNumber>& numbers, bool disable_checks ) {
      89         389 :   checks_were_disabled=disable_checks;
      90         389 :   atom_der_index.resize( indices.size() );
      91             : 
      92         389 :   if( numbers.size()==0 ) {
      93        3392 :     for(unsigned i=0; i<indices.size(); ++i) {
      94        3298 :       numbers.push_back( indices[i] );
      95        3298 :       atom_der_index[i]=i;
      96             :     }
      97             :   } else {
      98         295 :     if(!disable_checks) {
      99         295 :       if( numbers.size()!=indices.size() ) error("mismatched numbers of atoms in pdb frames");
     100             :     }
     101             : 
     102             :     bool found;
     103        4082 :     for(unsigned i=0; i<indices.size(); ++i) {
     104        3787 :       found=false;
     105        3787 :       if(!disable_checks) {
     106        3787 :         if( indices[i]!=numbers[i] ) error("found mismatched reference atoms in pdb frames");
     107        3787 :         atom_der_index[i]=i;
     108             :       } else {
     109           0 :         for(unsigned j=0; j<numbers.size(); ++j) {
     110           0 :           if( indices[i]==numbers[j] ) { found=true; atom_der_index[i]=j; break; }
     111             :         }
     112           0 :         if( !found ) {
     113           0 :           atom_der_index[i]=numbers.size(); numbers.push_back( indices[i] );
     114             :         }
     115             :       }
     116             :     }
     117             :   }
     118         389 : }
     119             : 
     120        2523 : }

Generated by: LCOV version 1.13