From 032ccd57214c5489755383588a5d4a3e0edd7a6e Mon Sep 17 00:00:00 2001
From: Marco <mark.nava@gmail.com>
Date: Thu, 9 Mar 2017 14:02:29 +0100
Subject: [PATCH] Applied suggested modifications: citation and virial.

* Citation fixed as suggested
* Added PBC-friendly virial contributions: compared with the numerical derivatives
  for a configuration and the same with a dimer shifted by the lattice vector on one of its components.
---
 src/colvar/Dimer.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/colvar/Dimer.cpp b/src/colvar/Dimer.cpp
index 9bc3c7781..758e06f66 100644
--- a/src/colvar/Dimer.cpp
+++ b/src/colvar/Dimer.cpp
@@ -23,6 +23,8 @@
 
 #include "Colvar.h"
 #include "ActionRegister.h"
+#include "core/PlumedMain.h"
+
 #include <string>
 #include <cmath>
 #include <cassert>
@@ -165,7 +167,7 @@ Dimer::Dimer(const ActionOptions& ao):
 	PLUMED_COLVAR_INIT(ao)
 {
 	
-	log<<" Please cite J. Chem. Theory Comput. 13, 425(2017)";
+	log<<" Bibliography "<<plumed.cite("M Nava, F. Palazzesi, C. Perego and M. Parrinello, J. Chem. Theory Comput. 13, 425(2017)")<<"\n";
 	parseVector("DSIGMA",dsigmas);
 	parse("Q",qexp);
 	parse("TEMP",temperature);
@@ -245,6 +247,7 @@ Dimer::Dimer(const ActionOptions& ao):
 void Dimer::calculate()
 {
 	double cv_val=0;
+	Tensor virial;
 	vector<Vector> derivatives;
 	vector<Vector> my_pos=getPositions();
 	int atms = my_pos.size();
@@ -272,6 +275,13 @@ void Dimer::calculate()
 		}
 		derivatives.push_back(der_val);
 		der_b2.push_back(mder_val);
+		
+		// virial part: each dimer contributes -x_{ij}*ds/dx_{ij}  (s is the CV)
+		double dfunc = fac1qm1/(beta*dsigquad);
+		Vector dd(dfunc*dist);
+  		Tensor vv(dd,dist);
+		virial -= vv;
+		
 	}
 	
 	derivatives.insert(derivatives.end(), der_b2.begin(), der_b2.end());
@@ -279,8 +289,8 @@ void Dimer::calculate()
 	for(unsigned int i=0;i<derivatives.size();i++)
 		setAtomsDerivatives(i,derivatives[i]);
 	
-	setBoxDerivativesNoPbc();
 	setValue(cv_val);
+	setBoxDerivatives(virial);
 	
 }
 
-- 
GitLab