plumed / plumed2

Development version of plumed 2
https://www.plumed.org
GNU Lesser General Public License v3.0
363 stars 289 forks source link

cmd(setNaturalUnits) doesn't work #364

Closed songbin6280 closed 6 years ago

songbin6280 commented 6 years ago

Hello Giovanni,

I noticed that calling cmd("setNaturalUnits") before cmd("init") inside the MD code, specifically ESPResSo++, does not work. "Units Natural" command has to been used in the plumed file. Can it be made to behave like "Units Natural"?

Best, Bin

GiovanniBussi commented 6 years ago

Can you try if this change fixes the problem?

I would anyway ask @gtribello to double check before merging

diff --git a/src/core/Atoms.cpp b/src/core/Atoms.cpp
index 938c159a3..ae844b20e 100644
--- a/src/core/Atoms.cpp
+++ b/src/core/Atoms.cpp
@@ -550,12 +550,12 @@ void Atoms::readBinary(std::istream&i) {
 }

 double Atoms::getKBoltzmann()const {
-  if(naturalUnits) return 1.0;
+  if(naturalUnits || MDnaturalUnits) return 1.0;
   else return kBoltzmann/units.getEnergy();
 }

 double Atoms::getMDKBoltzmann()const {
-  if(naturalUnits) return 1.0;
+  if(naturalUnits || MDnaturalUnits) return 1.0;
   else return kBoltzmann/MDUnits.getEnergy();
 }

diff --git a/src/core/Atoms.h b/src/core/Atoms.h
index dd45570d8..98dc1557d 100644
--- a/src/core/Atoms.h
+++ b/src/core/Atoms.h
@@ -265,7 +265,7 @@ ActionWithVirtualAtom* Atoms::getVirtualAtomsAction(AtomNumber i)const {

 inline
 bool Atoms::usingNaturalUnits() const {
-  return naturalUnits;
+  return naturalUnits || MDnaturalUnits;
 }

 inline
songbin6280 commented 6 years ago

I will try it.

songbin6280 commented 6 years ago

It worked like a charm. I ran a short simulation with metadynamics. The KbT was correct without "Units Natural" command in plumed input file. Thank you, Bin