diff --git a/yaff/sampling/harmonic.py b/yaff/sampling/harmonic.py index 0286f684..7d673fab 100644 --- a/yaff/sampling/harmonic.py +++ b/yaff/sampling/harmonic.py @@ -166,7 +166,7 @@ def estimate_elastic(ff, eps=1e-4, do_frozen=False, ridge=1e-4): """ cell = ff.system.cell if cell.nvec == 0: - raise VelueError('The elastic constants can only be computed if the system is periodic.') + raise ValueError('The elastic constants can only be computed if the system is periodic.') dof = StrainCellDOF(ff, do_frozen=do_frozen) vol0 = cell.volume if do_frozen: diff --git a/yaff/sampling/npt.py b/yaff/sampling/npt.py index fee1910a..bc12022e 100644 --- a/yaff/sampling/npt.py +++ b/yaff/sampling/npt.py @@ -635,7 +635,10 @@ def post(self, iterative, chainvel0 = None): # propagate the barostat self.baro(iterative, chainvel0) # calculate the correction due to the barostat alone - self.econs_correction = self.press*iterative.ff.system.cell.volume + self._compute_ekin_baro() + self.econs_correction = self._compute_ekin_baro() + # add the PV term if the volume is not constrained + if not self.vol_constraint: + self.econs_correction += self.press*iterative.ff.system.cell.volume if self.baro_thermo is not None: # add the correction due to the barostat thermostat self.econs_correction += self.baro_thermo.chain.get_econs_correction() diff --git a/yaff/sampling/verlet.py b/yaff/sampling/verlet.py index 65b00b64..9d08f0ff 100644 --- a/yaff/sampling/verlet.py +++ b/yaff/sampling/verlet.py @@ -493,7 +493,7 @@ def get(self): if self.counter > 0: ekin_var = self.ekin_sumsq/self.counter - (self.ekin_sum/self.counter)**2 max_contrib = max(self.ekin_sumsq/self.counter, (self.ekin_sum/self.counter)**2) - if np.abs(ekin_var)/max_contrib > 10.*self.eps: + if max_contrib > 10.*self.eps and np.abs(ekin_var)/max_contrib > 10.*self.eps: # only calculate further if the variance is substantially different from zero, # to mediate precision errors econs_var = self.econs_sumsq/self.counter - (self.econs_sum/self.counter)**2