Forum Navigation
You need to log in to create posts and topics.

Modify Example M2: Custom order parameter calculations

Hello,
I want to modify the example M2 on python scripting such that, instead of squared_deviations, the order parameter is defined based on the structure type for the neighbor atoms. Therefore, I wanted to add the CommonNeighborAnalysis modifier on the data before the neigh_finder command. So, I added:

selection=data.modifiers.append(CommonNeighborAnalysisModifier(3.5))    

But it gives the following error :
‘ovito.plugins.PyScript.DataCollection’ object has no attribute ‘modifiers’

I appreciate your help how I should add ovito’s default modifier to a new modifier I develop by python scripting.
Best,
Sepi

Hi Sepi,

Note that the variable data in your script refers to a DataCollection object, not a Pipeline object. Appending a modifier is an operation only supported by pipelines, and that's why you get the error message.

Within your running modify() function, all you can do is applying another modifier to your data immediately by invoking the DataCollection.apply() method.  apply() executes the secondary modifier directly, letting it modify your DataCollection in place. The secondary modifier is employed like a subroutine within your own modifier function. It is an ad-hoc (temporary) object that never gets inserted into the data pipeline.

data.apply(CommonNeighborAnalysisModifier(3.5), frame)

After this statement, the DataCollection will contain the "Structure Type" particle property computed by the CNA modifier and you can use that information in subsequent operations within your modify() function.

-Alex

Thank you for your help. The problem is solved.

Sepi