LCOV - code coverage report
Current view: top level - tools - AtomDistributionFiles.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 39 43 90.7 %
Date: 2026-11-05 10:19:04 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2026 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 "AtomDistributionFiles.h"
      23             : #include "View.h"
      24             : 
      25             : namespace PLMD {
      26             : 
      27           1 : void fileTraj::rewind() {
      28           1 :   auto errormessage=parser.rewind();
      29           1 :   if (errormessage) {
      30             :     // A workarounf for not implemented rewind is to dump the trajectory in an xyz and then read that
      31           0 :     plumed_error()<<*errormessage;
      32             :   }
      33             :   //the extra false prevents an infinite loop in case of unexpected consecutice EOFs after a rewind
      34           1 :   step(false);
      35           1 : }
      36             : 
      37             : //read the next step
      38           4 : void fileTraj::step(bool doRewind) {
      39           4 :   read=false;
      40           4 :   long long int mystep=0;
      41             :   double timeStep;
      42           4 :   std::optional<std::string> errormessage;
      43           4 :   if (masses.empty()) {
      44           2 :     errormessage=parser.readHeader(
      45             :                    mystep,
      46             :                    timeStep
      47             :                  );
      48           1 :     if (errormessage) {
      49           0 :       plumed_error()<<*errormessage;
      50             :     }
      51           1 :     const size_t natoms = parser.nOfAtoms();
      52             : 
      53           1 :     masses.assign(natoms,0.0);
      54           1 :     charges.assign(natoms,0.0);
      55           1 :     coordinates.assign(natoms,Vector(0.0,0.0,0.0));
      56           1 :     cell.assign(9,0.0);
      57           1 :     errormessage=parser.readAtoms(1,
      58           1 :                                   dont_read_pbc,
      59             :                                   false,
      60             :                                   0,
      61             :                                   0,
      62             :                                   mystep,
      63             :                                   masses.data(),
      64             :                                   charges.data(),
      65             :                                   &coordinates[0][0],
      66             :                                   cell.data()
      67             :                                  );
      68             :   } else {
      69           6 :     errormessage=parser.readFrame(1,
      70           3 :                                   dont_read_pbc,
      71             :                                   false,
      72             :                                   0,
      73             :                                   0,
      74             :                                   mystep,
      75             :                                   timeStep,
      76             :                                   masses.data(),
      77             :                                   charges.data(),
      78             :                                   &coordinates[0][0],
      79             :                                   cell.data()
      80             :                                  );
      81             :   }
      82             : 
      83           4 :   if (errormessage) {
      84           1 :     if (*errormessage =="EOF" && doRewind) {
      85           1 :       rewind();
      86             :     } else {
      87           0 :       plumed_error()<<*errormessage;
      88             :     }
      89             :   }
      90           4 : }
      91             : 
      92           3 : void fileTraj::frame(View<Vector> posToUpdate,
      93             :                      View<double,9> box,
      94             :                      unsigned /*step*/,
      95             :                      Random& /*rng*/) {
      96           3 :   if (read) {
      97           2 :     step();
      98             :   }
      99           3 :   read=true;
     100             :   std::copy(coordinates.begin(),coordinates.end(),posToUpdate.begin());
     101             :   std::copy(cell.begin(),cell.end(),box.begin());
     102           3 : }
     103             : 
     104           1 : fileTraj::fileTraj(std::string_view fmt,
     105             :                    std::string_view fname,
     106             :                    bool useMolfile,
     107           1 :                    int command_line_natoms) {
     108             :   auto errormessage=parser.init(fmt,
     109             :                                 fname,
     110             :                                 useMolfile,
     111           1 :                                 command_line_natoms);
     112           1 :   if(errormessage) {
     113           0 :     plumed_error()<<*errormessage;
     114             :   }
     115           1 :   step();
     116           1 : }
     117             : 
     118           1 : bool fileTraj::overrideNat(unsigned& natoms) {
     119           1 :   natoms = masses.size();
     120           1 :   return true;
     121             : }
     122             : 
     123             : } //namespace PLMD

Generated by: LCOV version 1.16