From 705096939926bdf05ed2eb30660297fc81a43f2d Mon Sep 17 00:00:00 2001 From: Marcello Sega Date: Tue, 6 Feb 2024 10:12:26 +0000 Subject: [PATCH] Profile: new density option allows to compute the profile of the average value of an observable, instead of its density, by passing density=False when calling the method get_values() --- pytim/observables/profile.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pytim/observables/profile.py b/pytim/observables/profile.py index 6451771..5c5c169 100644 --- a/pytim/observables/profile.py +++ b/pytim/observables/profile.py @@ -22,12 +22,12 @@ class Profile(object): None is supplied, it defaults to the number density. The number density is always calculated on a per atom basis. - :param ITIM interface: if provided, calculate the intrinsic - profile with respect to the first layers :param str direction: 'x','y', or 'z' : calculate the profile along this direction. (default: 'z' or the normal direction of the interface, if provided. + :param ITIM interface: if provided, calculate the intrinsic + profile with respect to the first layers :param bool MCnorm: if True (default) use a simple Monte Carlo estimate the effective volumes of the bins. @@ -113,8 +113,8 @@ class Profile(object): """ def __init__(self, - direction=None, observable=None, + direction=None, interface=None, symmetry='default', mode='default', @@ -246,7 +246,7 @@ def sample(self, group, **kargs): self.sampled_rnd_values += rnd_accum self._counts += 1 - def get_values(self, binwidth=None, nbins=None): + def get_values(self, binwidth=None, nbins=None, density=True): if self.sampled_values is None: print("Warning no profile sampled so far") # we use the largest box (largest number of bins) as reference. @@ -264,7 +264,7 @@ def get_values(self, binwidth=None, nbins=None): nbins += 1 vals = self.sampled_values.copy() - vals /= (np.average(self._totvol) / self._nbins) + if density: vals /= (np.average(self._totvol) / self._nbins) vals /= self._counts if self.interface is not None: # new versions of scipy.binned_statistic don't like inf