# RDF calculation for one particle

I want to calculate the RDF for one particle. How to let the modifier do it only for one particle ?

```# Load a simulation trajectory consisting of several frames:
pipeline = import_file("input/simulation.dump")

# Insert the modifier into the pipeline:
modifier = CoordinationAnalysisModifier(cutoff = 12.0, number_of_bins = 200)
modifier.partial = True

pipeline.modifiers.append(modifier)

# Initialize array for accumulated RDF histogram to zero:
total_rdf = numpy.zeros((modifier.number_of_bins, 17))

# Iterate over all frames of the sequence.
for frame in range(pipeline.source.num_frames):
# Evaluate pipeline to let the modifier compute the RDF of the current frame:
data = pipeline.compute(frame)
# Accumulate RDF histograms:
total_rdf += data.tables['coordination-rdf'].xy()

# Averaging:
total_rdf /= pipeline.source.num_frames

# Export the average RDF to a text file:
numpy.savetxt("output/rdf.txt", total_rdf)```

Hi Betim,

the RDF computed by the Coordination analysis modifier is an average over your whole system. If you would like to analyze the neighborhood of a single particle you'll need to implement that yourself with a few lines of python code.

The good news is that OVITO's python interface provides a set of helper functions which you can use to easily find the neighbor particles of your particle in question and also compute all neighbor distances, see https://www.ovito.org/docs/current/python/modules/ovito_data.php#ovito.data.CutoffNeighborFinder

The code example in the manual already shows you how to access the neighbor distances. You can create a histogram of those neighbor distances using numpy.histogram() e.g., and don't forget to normalize it in the end.

-Constanze

Quote from Constanze Kalcher on August 27, 2020, 1:52 pm

Hi Betim,

the RDF computed by the Coordination analysis modifier is an average over your whole system. If you would like to analyze the neighborhood of a single particle you'll need to implement that yourself with a few lines of python code.

The good news is that OVITO's python interface provides a set of helper functions which you can use to easily find the neighbor particles of your particle in question and also compute all neighbor distances, see https://www.ovito.org/docs/current/python/modules/ovito_data.php#ovito.data.CutoffNeighborFinder

The code example in the manual already shows you how to access the neighbor distances. You can create a histogram of those neighbor distances using numpy.histogram() e.g., and don't forget to normalize it in the end.

-Constanze

But when i use the "partial" mode it calculates the RDF for each particle e.g. 1-1, 1-2, 1-3 and so on. Is it not possible to extract only 11-1,11-2 etc. ?

When you say "each particle" do you mean particle type? That is a completely different question. Indeed, you can request the calculation of element-specific (partial) RDFs by setting the option:

`partial = True`

as explained in the documentation: https://www.ovito.org/docs/current/python/modules/ovito_modifiers.php#ovito.modifiers.CoordinationAnalysisModifier

Quote from Constanze Kalcher on August 27, 2020, 2:38 pm

When you said "one particle" did you mean particle types? That is a completely different question? Indeed, you can request the calculation of element-specific (partial) RDFs by setting the option:

`partial = True`

as explained in the documentation: https://www.ovito.org/docs/current/python/modules/ovito_modifiers.php#ovito.modifiers.CoordinationAnalysisModifier

Exactly. I have set the option but how is it possible now to extract only RDF for my particle 11-1,11-2 and so on ? I cannot find anything in the documentation.

Note that `data.tables['coordination-rdf']` is an OVITO DataTable object.

`data.tables['coordination-rdf'].y` is the property containing the y-coordinates of the data points. If you compute partial rdfs with the Coordination analysis modifier this will be a vector property having more than one component per data point (analogous to how this looks like in the Data inspector in the GUI).

You can look up the shape of this array like this:

`print(data.tables['coordination-rdf'].y.shape)`

and look up the individual columns containing the partial rdfs like this:

```#1-1
print(rdf.y[:,0])
#1-2
print(rdf.y[:,1])```

Also, fyi, if you struggle with the python scripting interface, Time averaging can now be easily done with within the OVITO Pro GUI. Also, the plots of the time-averaged partial rdfs would then be directly visible in the Data Inspector.

So all of this can be achieved without any coding by using the out-of-the-box modifiers available in OVITO Pro.