Author Topic: The partial radial distribution function calculation python script cannot run  (Read 46 times)


  • Newbie
  • *
  • Posts: 2
Dear forum users,
I am trying to calculate the partial RDF for my system. I am using the script Dr.Alexander Stukowski posted on the website.

from ovito.modifiers import *
from import *
import numpy as np

num_bins = 100
cutoff = 5.0

node = import_file("dump4.lammpstrj")

create_bonds_modifier = CreateBondsModifier(cutoff=cutoff, mode=CreateBondsModifier.Mode.Pairwise)
create_bonds_modifier.set_pairwise_cutoff('Type 4', 'Type 1', cutoff)

output = node.compute()
hist, bin_edges = np.histogram(output.bond_properties.length.array, bins=num_bins)

rho = output.number_of_particles / output.cell.volume
factor = 4./3. * np.pi * rho * output.number_of_particles

radii = bin_edges[:-1]
radii_right = bin_edges[1:]
rdf = hist / (factor * (radii_right**3 - radii**3))

I have changed the file name and the atom type I need for the calculation.
Before trying to running the python script, I have already loaded the dump4.lammpstrj file.
The problem is when I try to click the run button, nothing happened. And there is a small red triangle on the left of the python script modifications.
I assume there is something wrong with the code.

I would be really appreciated if anyone can help me with this.

Thank you very much.

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 284
The version of the script you posted is meant to be run from the terminal with the external ovitos script interpreter program (or using the Scripting/Run Script File function from the main menu of the graphical version of OVITO). It is a batch script that performs all operations from beginning to end (including data file import).

It seems that you have been trying to use this batch script like a user-defined modifier function inside the graphical version of OVITO. For this approach, you need to instead use the first version of the example script posted on this page:

If you want to learn more about the difference between batch scripts and user-defined modifier function scripts, see this page of the user manual:


  • Newbie
  • *
  • Posts: 2
Thank you very much, Dr.Alexander Stukowski!
I have successfully get the partial radial distribution function.