LCOV - code coverage report
Current view: top level - tools - AtomDistribution.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 5 7 71.4 %
Date: 2025-12-04 11:19:34 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2025 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             : #ifndef __PLUMED_tools_AtomDistribution_h
      23             : #define __PLUMED_tools_AtomDistribution_h
      24             : 
      25             : #include "Vector.h"
      26             : #include "Tools.h"
      27             : #include "Random.h"
      28             : #include "TrajectoryParser.h"
      29             : 
      30             : #include <vector>
      31             : namespace PLMD {
      32             : ///tested in regtest/tools/rt-make-AtomicDistribution
      33             : ///Acts as a template for any distribution
      34             : struct AtomDistribution {
      35             :   ///Update the input vectors with the position and the box of the frame
      36             :   virtual void frame(std::vector<Vector>& posToUpdate,
      37             :                      std::vector<double>& box,
      38             :                      unsigned /*step*/,
      39             :                      Random& /*rng*/)=0;
      40             :   virtual ~AtomDistribution() noexcept {}
      41             :   ///If necessary changes the number of atoms, returns true if that number has been changed
      42           0 :   virtual bool overrideNat(unsigned& ) {
      43           0 :     return false;
      44             :   }
      45             :   static std::unique_ptr<AtomDistribution> getAtomDistribution(std::string_view atomicDistr);
      46             : };
      47             : 
      48             : ///A wiggly line of atoms
      49           1 : struct theLine:public AtomDistribution {
      50             :   void frame(std::vector<Vector>& posToUpdate,
      51             :              std::vector<double>& box,
      52             :              unsigned step,
      53             :              Random& rng) override;
      54             : };
      55             : 
      56             : ///Atom randomly distribuited in a sphere
      57           9 : struct uniformSphere:public AtomDistribution {
      58             :   void frame(std::vector<Vector>& posToUpdate,
      59             :              std::vector<double>& box,
      60             :              unsigned /*step*/,
      61             :              Random& rng) override;
      62             : };
      63             : 
      64             : ///Atom randomly distribuited between two not overlapping a spheres
      65           1 : struct twoGlobs: public AtomDistribution {
      66             :   void frame(std::vector<Vector>& posToUpdate,
      67             :              std::vector<double>& box,
      68             :              unsigned /*step*/,
      69             :              Random&rng) override;
      70             : };
      71             : 
      72           1 : struct uniformCube:public AtomDistribution {
      73             :   void frame(std::vector<Vector>& posToUpdate,
      74             :              std::vector<double>& box,
      75             :              unsigned /*step*/,
      76             :              Random& rng) override;
      77             : };
      78             : 
      79          11 : struct tiledSimpleCubic:public AtomDistribution {
      80             :   void frame(std::vector<Vector>& posToUpdate,
      81             :              std::vector<double>& box,
      82             :              unsigned /*step*/,
      83             :              Random& rng) override;
      84             : };
      85             : 
      86             : /// atomic distribution from a trajectory file
      87             : class fileTraj:public AtomDistribution {
      88             :   TrajectoryParser parser;
      89             :   std::vector<double> masses{};
      90             :   std::vector<double> charges{};
      91             :   std::vector<Vector> coordinates{};
      92             :   std::vector<double> cell{0.0,0.0,0.0,
      93             :         0.0,0.0,0.0,
      94             :         0.0,0.0,0.0};
      95             :   bool read=false;
      96             :   bool dont_read_pbc=false;
      97             :   void rewind();
      98             :   //read the next step
      99             :   void step(bool doRewind=true);
     100             : public:
     101             :   void frame(std::vector<Vector>& posToUpdate,
     102             :              std::vector<double>& box,
     103             :              unsigned /*step*/,
     104             :              Random& /*rng*/) override;
     105             : 
     106             :   fileTraj(std::string_view fmt,
     107             :            std::string_view fname,
     108             :            bool useMolfile,
     109             :            int command_line_natoms);
     110             :   bool overrideNat(unsigned& natoms) override;
     111             : };
     112             : 
     113             : ///a decorator for replicate the atomic distribution
     114             : class repliedTrajectory: public AtomDistribution {
     115             :   std::unique_ptr<AtomDistribution> distribution;
     116             :   unsigned rX=1;
     117             :   unsigned rY=1;
     118             :   unsigned rZ=1;
     119             :   std::vector<Vector> coordinates;
     120             : public:
     121             :   repliedTrajectory(std::unique_ptr<AtomDistribution>&& d,
     122             :                     const unsigned repeatX,
     123             :                     const unsigned repeatY,
     124             :                     const unsigned repeatZ,
     125             :                     // I think 4294967295 maximum atoms before the multiplication is more than enough
     126             :                     const unsigned nat);
     127             : 
     128             :   void frame(std::vector<Vector>& posToUpdate,
     129             :              std::vector<double>& box,
     130             :              unsigned step,
     131             :              Random& rng) override;
     132             : 
     133             :   bool overrideNat(unsigned& natoms) override;
     134             : };
     135             : } //namespace PLMD
     136             : #endif // __PLUMED_tools_AtomDistribution_h

Generated by: LCOV version 1.16