LCOV - code coverage report
Current view: top level - isdb - FretEfficiency.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 36 38 94.7 %
Date: 2024-10-11 08:09:47 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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 "colvar/Colvar.h"
      23             : #include "colvar/ActionRegister.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "tools/Pbc.h"
      26             : 
      27             : #include <string>
      28             : #include <cmath>
      29             : 
      30             : namespace PLMD {
      31             : namespace isdb {
      32             : 
      33             : //+PLUMEDOC ISDB_COLVAR FRET
      34             : /*
      35             : Calculates the FRET efficiency between a pair of atoms.
      36             : The efficiency is calculated using the Forster relation:
      37             : 
      38             : \f[
      39             : E=\frac{1}{1+(R/R_0)^6}
      40             : \f]
      41             : 
      42             : where \f$R\f$ is the distance and \f$R_0\f$ is the Forster radius.
      43             : 
      44             : By default the distance is computed taking into account periodic
      45             : boundary conditions. This behavior can be changed with the NOPBC flag.
      46             : 
      47             : 
      48             : \par Examples
      49             : 
      50             : The following input tells plumed to print the FRET efficiencies
      51             : calculated as a function of the distance between atoms 3 and 5 and
      52             : the distance between atoms 2 and 4.
      53             : \plumedfile
      54             : fe1:  FRET ATOMS=3,5 R0=5.5
      55             : fe2:  FRET ATOMS=2,4 R0=5.5
      56             : PRINT ARG=fe1,fe2
      57             : \endplumedfile
      58             : 
      59             : The following input computes the FRET efficiency calculated on the
      60             : terminal atoms of a polymer
      61             : of 100 atoms and keeps it at a value around 0.5.
      62             : \plumedfile
      63             : WHOLEMOLECULES ENTITY0=1-100
      64             : fe: FRET ATOMS=1,100 R0=5.5 NOPBC
      65             : RESTRAINT ARG=fe KAPPA=100 AT=0.5
      66             : \endplumedfile
      67             : 
      68             : Notice that NOPBC is used
      69             : to be sure that if the distance is larger than half the simulation
      70             : box the distance is compute properly. Also notice that, since many MD
      71             : codes break molecules across cell boundary, it might be necessary to
      72             : use the \ref WHOLEMOLECULES keyword (also notice that it should be
      73             : _before_ FRET).
      74             : Just be sure that the ordered list provide to WHOLEMOLECULES has the following
      75             : properties:
      76             : - Consecutive atoms should be closer than half-cell throughout the entire simulation.
      77             : - Atoms required later for the distance (e.g. 1 and 100) should be included in the list
      78             : 
      79             : */
      80             : //+ENDPLUMEDOC
      81             : 
      82             : class FretEfficiency : public Colvar {
      83             :   bool pbc;
      84             :   double R0_;
      85             : 
      86             : public:
      87             :   static void registerKeywords( Keywords& keys );
      88             :   explicit FretEfficiency(const ActionOptions&);
      89             : // active methods:
      90             :   void calculate() override;
      91             : };
      92             : 
      93       10447 : PLUMED_REGISTER_ACTION(FretEfficiency,"FRET")
      94             : 
      95          15 : void FretEfficiency::registerKeywords( Keywords& keys ) {
      96          15 :   Colvar::registerKeywords( keys );
      97          30 :   keys.add("atoms","ATOMS","the pair of atom that we are calculating the distance between");
      98          30 :   keys.add("compulsory","R0","The value of the Forster radius.");
      99          15 : }
     100             : 
     101          14 : FretEfficiency::FretEfficiency(const ActionOptions&ao):
     102             :   PLUMED_COLVAR_INIT(ao),
     103          14 :   pbc(true)
     104             : {
     105             :   std::vector<AtomNumber> atoms;
     106          28 :   parseAtomList("ATOMS",atoms);
     107          14 :   if(atoms.size()!=2)
     108           0 :     error("Number of specified atoms should be 2");
     109          14 :   parse("R0",R0_);
     110          14 :   bool nopbc=!pbc;
     111          14 :   parseFlag("NOPBC",nopbc);
     112          14 :   pbc=!nopbc;
     113          14 :   checkRead();
     114             : 
     115          14 :   log.printf("  between atoms %d %d\n",atoms[0].serial(),atoms[1].serial());
     116          14 :   log.printf("  with Forster radius set to %lf\n",R0_);
     117             : 
     118          14 :   if(pbc) log.printf("  using periodic boundary conditions\n");
     119           0 :   else    log.printf("  without periodic boundary conditions\n");
     120             : 
     121          28 :   log << " Bibliography" << plumed.cite("Bonomi, Camilloni, Bioinformatics, 33, 3999 (2017)") << "\n";
     122             : 
     123          14 :   addValueWithDerivatives();
     124          14 :   setNotPeriodic();
     125             : 
     126          14 :   requestAtoms(atoms);
     127          14 : }
     128             : 
     129             : 
     130             : // calculator
     131         238 : void FretEfficiency::calculate() {
     132             : 
     133         238 :   if(pbc) makeWhole();
     134             : 
     135         238 :   Vector distance=delta(getPosition(0),getPosition(1));
     136         238 :   const double dist_mod=distance.modulo();
     137         238 :   const double inv_dist_mod=1.0/dist_mod;
     138             : 
     139         238 :   const double ratiosix=std::pow(dist_mod/R0_,6);
     140         238 :   const double fret_eff = 1.0/(1.0+ratiosix);
     141             : 
     142         238 :   const double der = -6.0*fret_eff*fret_eff*ratiosix*inv_dist_mod;
     143             : 
     144         238 :   setAtomsDerivatives(0,-inv_dist_mod*der*distance);
     145         238 :   setAtomsDerivatives(1, inv_dist_mod*der*distance);
     146         238 :   setBoxDerivativesNoPbc();
     147         238 :   setValue(fret_eff);
     148             : 
     149         238 : }
     150             : 
     151             : }
     152             : }
     153             : 
     154             : 
     155             : 

Generated by: LCOV version 1.15