LCOV - code coverage report
Current view: top level - reference - ReferenceAtoms.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 30 33 90.9 %
Date: 2024-10-11 08:09:47 Functions: 5 6 83.3 %

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

Generated by: LCOV version 1.15