Ratio between first max. and first min. of g[r] vs time from Coordination analysis


I’m trying to calculate the ratio between first max. and the first min. value of g[r] .
I did a coordination analysis(for calculating RDF) and then using a python script modifier implemented max() and min() function.
But the problem with this is, it’s not finding the 1st max. and 1min. value. For min. it takes 0. Also if there is two-particle type in the system then it can not take value for rdf.y and return nan.

So, is there any possible way to do it in Ovito by using python modifier.

I tried something like this:

`from ovito.data import *
import numpy as np
def modify(frame, data, output):
rdf = data.tables[‘coordination-rdf’]
rdf_max = np.max(rdf.y)
rdf_min = np.min(rdf.y)
rdf_ratio = (rdf_min/rdf_max)

Thank you

Hi Prash,

yes, that is the expected behavior of the numpy.max() and numpy.min() functions, please refer to the numpy documentation https://numpy.org/doc/stable/.

There are a lot of different ways of finding local maxima or minima in a 1-d numpy array with python, see e.g. https://stackoverflow.com/questions/4624970/finding-local-maxima-minima-with-numpy-in-a-1d-numpy-array.

Concerning the shape of rdf.y : Please note that when you activate the option “Compute partial RDFs” within the Coordination Analysis modifier settings, data.tables[‘coordination-rdf’].y will be a numpy array of shape (n, X), where n is the number of bins and X is the number of possible particle type pair-combinations. If your system consists of 2 particle types, you will thus get three columns, i.e. for the 1-1, 1-2 and 2-2 type pair interactions, and you can access them like this: