LCOV - code coverage report
Current view: top level - vatom - FixedAtom.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 34 100.0 %
Date: 2021-11-18 15:22:58 Functions: 9 11 81.8 %

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

Generated by: LCOV version 1.14