LCOV - code coverage report
Current view: top level - multicolvar - Torsions.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 34 100.0 %
Date: 2021-11-18 15:22:58 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-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 "MultiColvarBase.h"
      23             : #include "AtomValuePack.h"
      24             : #include "tools/Torsion.h"
      25             : #include "core/ActionRegister.h"
      26             : 
      27             : #include <string>
      28             : #include <cmath>
      29             : 
      30             : using namespace std;
      31             : 
      32             : namespace PLMD {
      33             : namespace multicolvar {
      34             : 
      35             : //+PLUMEDOC MCOLVAR TORSIONS
      36             : /*
      37             : Calculate whether or not a set of torsional angles are within a particular range.
      38             : 
      39             : \par Examples
      40             : 
      41             : The following provides an example of the input for the TORSIONS command
      42             : 
      43             : \plumedfile
      44             : TORSIONS ...
      45             : ATOMS1=168,170,172,188
      46             : ATOMS2=170,172,188,190
      47             : ATOMS3=188,190,192,230
      48             : BETWEEN={GAUSSIAN LOWER=0 UPPER=pi SMEAR=0.1}
      49             : LABEL=ab
      50             : ... TORSIONS
      51             : PRINT ARG=ab.* FILE=colvar STRIDE=10
      52             : \endplumedfile
      53             : 
      54             : Writing out the atoms involved in all the torsion angles in this way can be rather tedious. Thankfully if you are working with protein you
      55             : can avoid this by using the \ref MOLINFO command.  PLUMED uses the pdb file that you provide to this command to learn
      56             : about the topology of the protein molecule.  This means that you can specify torsion angles using the following syntax:
      57             : 
      58             : \plumedfile
      59             : #SETTINGS MOLFILE=regtest/basic/rt32/helix.pdb
      60             : MOLINFO MOLTYPE=protein STRUCTURE=myprotein.pdb
      61             : TORSIONS ...
      62             : ATOMS1=@phi-3
      63             : ATOMS2=@psi-3
      64             : ATOMS3=@phi-4
      65             : BETWEEN={GAUSSIAN LOWER=0 UPPER=pi SMEAR=0.1}
      66             : LABEL=ab
      67             : ... TORSIONS
      68             : PRINT ARG=ab.* FILE=colvar STRIDE=10
      69             : \endplumedfile
      70             : 
      71             : Here, \@phi-3 tells plumed that you would like to calculate the \f$\phi\f$ angle in the third residue of the protein.
      72             : Similarly \@psi-4 tells plumed that you want to calculate the \f$\psi\f$ angle of the fourth residue of the protein.
      73             : 
      74             : 
      75             : */
      76             : //+ENDPLUMEDOC
      77             : 
      78           4 : class Torsions : public MultiColvarBase {
      79             : public:
      80             :   static void registerKeywords( Keywords& keys );
      81             :   explicit Torsions(const ActionOptions&);
      82             :   virtual double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
      83           5 :   bool isPeriodic() { return true; }
      84           4 :   void retrieveDomain( std::string& min, std::string& max ) { min="-pi"; max="pi"; }
      85             : };
      86             : 
      87        7360 : PLUMED_REGISTER_ACTION(Torsions,"TORSIONS")
      88             : 
      89           3 : void Torsions::registerKeywords( Keywords& keys ) {
      90           3 :   MultiColvarBase::registerKeywords( keys );
      91          12 :   keys.add("numbered","ATOMS","the atoms involved in each of the torsion angles you wish to calculate. "
      92             :            "Keywords like ATOMS1, ATOMS2, ATOMS3,... should be listed and one torsion will be "
      93             :            "calculated for each ATOM keyword you specify (all ATOM keywords should "
      94             :            "provide the indices of four atoms).  The eventual number of quantities calculated by this "
      95             :            "action will depend on what functions of the distribution you choose to calculate.");
      96           9 :   keys.reset_style("ATOMS","atoms");
      97           9 :   keys.use("BETWEEN"); keys.use("HISTOGRAM");
      98           3 : }
      99             : 
     100           2 : Torsions::Torsions(const ActionOptions&ao):
     101             :   Action(ao),
     102           2 :   MultiColvarBase(ao)
     103             : {
     104             :   // Read in the atoms
     105           2 :   int natoms=4; std::vector<AtomNumber> all_atoms;
     106           4 :   readAtomsLikeKeyword( "ATOMS", natoms, all_atoms );
     107           2 :   setupMultiColvarBase( all_atoms );
     108           2 :   std::vector<bool> catom_ind(4, false);
     109             :   catom_ind[1]=catom_ind[2]=true;
     110           2 :   setAtomsForCentralAtom( catom_ind );
     111             :   // Read in the vessels
     112           2 :   readVesselKeywords();
     113             :   // And check everything has been read in correctly
     114           2 :   checkRead();
     115           2 : }
     116             : 
     117          36 : double Torsions::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
     118          36 :   Vector d0,d1,d2;
     119          72 :   d0=getSeparation(myatoms.getPosition(1),myatoms.getPosition(0));
     120          36 :   d1=getSeparation(myatoms.getPosition(2),myatoms.getPosition(1));
     121          36 :   d2=getSeparation(myatoms.getPosition(3),myatoms.getPosition(2));
     122             : 
     123          36 :   Vector dd0,dd1,dd2; PLMD::Torsion t;
     124          36 :   double value  = t.compute(d0,d1,d2,dd0,dd1,dd2);
     125             : 
     126          36 :   addAtomDerivatives(1,0,dd0,myatoms);
     127          36 :   addAtomDerivatives(1,1,dd1-dd0,myatoms);
     128          36 :   addAtomDerivatives(1,2,dd2-dd1,myatoms);
     129          36 :   addAtomDerivatives(1,3,-dd2,myatoms);
     130             : 
     131          36 :   myatoms.addBoxDerivatives  (1, -(extProduct(d0,dd0)+extProduct(d1,dd1)+extProduct(d2,dd2)));
     132             : 
     133          36 :   return value;
     134             : }
     135             : 
     136             : }
     137        5517 : }

Generated by: LCOV version 1.14