LCOV - code coverage report
Current view: top level - vatom - FixedAtom.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 33 33 100.0 %
Date: 2024-10-18 13:59:31 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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 "ActionWithVirtualAtom.h"
      23             : #include "core/ActionRegister.h"
      24             : #include "tools/Vector.h"
      25             : #include "tools/Exception.h"
      26             : 
      27             : namespace PLMD {
      28             : namespace vatom {
      29             : 
      30             : //+PLUMEDOC VATOM FIXEDATOM
      31             : /*
      32             : Add a virtual atom in a fixed position.
      33             : 
      34             : This action creates a virtual atom at a fixed position.
      35             : The coordinates can be specified in Cartesian components (by default)
      36             : or in scaled coordinates (SCALED_COMPONENTS).
      37             : It is also possible to assign a predefined charge or mass to the atom.
      38             : 
      39             : \attention
      40             : Similar to \ref POSITION this variable is not invariant for translation
      41             : of the system. Adding a force on it can create serious troubles.
      42             : 
      43             : Notice that the distance between two atoms created
      44             : using FIXEDATOM is invariant for translation.
      45             : Additionally, if one first align atoms to a reference using \ref FIT_TO_TEMPLATE,
      46             : then it is safe to add further fixed atoms without breaking translational invariance.
      47             : 
      48             : \par Examples
      49             : 
      50             : The following input instructs plumed to compute the angle between
      51             : distance of atoms 15 and 20 and the z axis and keeping it close to zero.
      52             : \plumedfile
      53             : a: FIXEDATOM AT=0,0,0
      54             : b: FIXEDATOM AT=0,0,1
      55             : an: ANGLE ATOMS=a,b,15,20
      56             : RESTRAINT ARG=an AT=0.0 KAPPA=100.0
      57             : \endplumedfile
      58             : 
      59             : The following input instructs plumed to align a protein to a template
      60             : and to then compute the distance between one of the atoms in the protein and the point
      61             : (10,20,30).
      62             : \plumedfile
      63             : FIT_TO_TEMPLATE STRIDE=1 REFERENCE=ref.pdb TYPE=SIMPLE
      64             : a: FIXEDATOM AT=10,20,30
      65             : d: DISTANCE ATOMS=a,20
      66             : PRINT ARG=d FILE=colvar
      67             : \endplumedfile
      68             : 
      69             : The reference structure to align to is provided in a pdb file called ref.pdb as shown below:
      70             : 
      71             : \auxfile{ref.pdb}
      72             : ATOM      8  HT3 ALA     2      -1.480  -1.560   1.212  1.00  1.00      DIA  H
      73             : ATOM      9  CAY ALA     2      -0.096   2.144  -0.669  1.00  1.00      DIA  C
      74             : ATOM     10  HY1 ALA     2       0.871   2.385  -0.588  1.00  1.00      DIA  H
      75             : ATOM     12  HY3 ALA     2      -0.520   2.679  -1.400  1.00  1.00      DIA  H
      76             : ATOM     14  OY  ALA     2      -1.139   0.931  -0.973  1.00  1.00      DIA  O
      77             : END
      78             : \endauxfile
      79             : 
      80             : 
      81             : */
      82             : //+ENDPLUMEDOC
      83             : 
      84             : 
      85             : class FixedAtom:
      86             :   public ActionWithVirtualAtom
      87             : {
      88             :   Vector coord;
      89             :   std::vector<Tensor> deriv;
      90             :   double mass,charge;
      91             :   bool scaled_components;
      92             : public:
      93             :   explicit FixedAtom(const ActionOptions&ao);
      94             :   void calculate() override;
      95             :   static void registerKeywords( Keywords& keys );
      96             : };
      97             : 
      98             : PLUMED_REGISTER_ACTION(FixedAtom,"FIXEDATOM")
      99             : 
     100          40 : void FixedAtom::registerKeywords(Keywords& keys) {
     101          40 :   ActionWithVirtualAtom::registerKeywords(keys);
     102          80 :   keys.add("compulsory","AT","coordinates of the virtual atom");
     103          80 :   keys.add("compulsory","SET_MASS","1","mass of the virtual atom");
     104          80 :   keys.add("compulsory","SET_CHARGE","0","charge of the virtual atom");
     105          80 :   keys.addFlag("SCALED_COMPONENTS",false,"use scaled components");
     106          40 : }
     107             : 
     108          35 : FixedAtom::FixedAtom(const ActionOptions&ao):
     109             :   Action(ao),
     110          35 :   ActionWithVirtualAtom(ao)
     111             : {
     112             :   std::vector<AtomNumber> atoms;
     113          70 :   parseAtomList("ATOMS",atoms);
     114          35 :   if(atoms.size()!=0) error("ATOMS should be empty");
     115             : 
     116          70 :   parseFlag("SCALED_COMPONENTS",scaled_components);
     117             : 
     118             :   std::vector<double> at;
     119          70 :   parseVector("AT",at);
     120          35 :   if(at.size()!=3) error("AT should be a list of three real numbers");
     121             : 
     122          35 :   parse("SET_MASS",mass);
     123          70 :   parse("SET_CHARGE",charge);
     124             : 
     125          35 :   coord[0]=at[0];
     126          35 :   coord[1]=at[1];
     127          35 :   coord[2]=at[2];
     128             : 
     129          35 :   checkRead();
     130          35 :   log<<"  AT position "<<coord[0]<<" "<<coord[1]<<" "<<coord[2]<<"\n";
     131          35 :   if(scaled_components) log<<"  position is in scaled components\n";
     132          35 : }
     133             : 
     134         735 : void FixedAtom::calculate() {
     135         735 :   deriv.resize(getNumberOfAtoms());
     136         735 :   if(scaled_components) {
     137           5 :     setPosition(getPbc().scaledToReal(coord));
     138             :   } else {
     139         730 :     setPosition(coord);
     140             :   }
     141         735 :   setMass(mass);
     142         735 :   setCharge(charge);
     143         735 :   setAtomsDerivatives(deriv);
     144             : // Virial contribution
     145         735 :   if(!scaled_components) setBoxDerivativesNoPbc();
     146             : // notice that with scaled components there is no additional virial contribution
     147         735 : }
     148             : 
     149             : }
     150             : }

Generated by: LCOV version 1.16