This is the code I use to get the time-averaged pair correlation function for a 3D material in OVITO. How do I modify it for a 2d materials?
from ovito.io import import_file, export_file
from ovito.modifiers import CoordinationAnalysisModifier, TimeAveragingModifier
import numpy
pipeline = import_file(“coords.dump”)
print(“Number of MD frames:”, pipeline.num_frames)
pipeline.modifiers.append(CoordinationAnalysisModifier(cutoff = 20.0, number_of_bins = 1000))
pipeline.modifiers.append(TimeAveragingModifier(operate_on=‘table:coordination-rdf’))
total_rdf = pipeline.compute().tables[‘coordination-rdf[average]’].xy()
numpy.savetxt(“gr-3d.dat”, total_rdf)
Since the dimensionality of a simulation is not encoded in LAMMPS dump files, OVITO assumes that the simulation is two-dimensional if the dump file contains no z-coordinates. You can override this at the level of the simulation cell after import if necessary.
https://www.ovito.org/docs/current/reference/pipelines/data_objects/simulation_cell.html#scene-objects-simulation-cell
Other than that, no code modification should be necessary.
So I tried to override the dimensionality after importing the data file by doing the following:
from ovito.io import import_file, export_file
from ovito.modifiers import CoordinationAnalysisModifier, TimeAveragingModifier
import numpy
pipeline = import_file(“coords.dump”)
print(“Number of MD frames:”, pipeline.num_frames)
pipeline.compute().cell_.is2D=(True)
pipeline.compute().cell_.pbc=(True,True,False)
pipeline.modifiers.append(CoordinationAnalysisModifier(cutoff = 50.0, number_of_bins = 2000))
pipeline.modifiers.append(TimeAveragingModifier(operate_on=‘table:coordination-rdf’))
total_rdf = pipeline.compute().tables[‘coordination-rdf[average]’].xy()
numpy.savetxt(“gr.dat”, total_rdf)
But this gives me same data as it would give for the 3D setup, which means overriding the dimensionality did not work in this case. I know I could do the overriding from the interface of the OVITO software by selecting 2D. But If I want to do it in python script, how should I change my script?