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

python interface: persistent default periodic boundary condition

I am trying to change the periodic boundary condition to (True,True,False), but after adding modifier, it is still the default conditions: (True,True,True). Am I missing something? Really appreciate your help in advance.

The python script is below:

from import import_file, export_file
from ovito.modifiers import DislocationAnalysisModifier
from import DislocationNetwork
import sys
import numpy as np

pipeline = import_file(sys.argv[1])

print(celldata.cell.pbc) # prints (True,True,False)

modifier = DislocationAnalysisModifier()
modifier.input_crystal_structure = DislocationAnalysisModifier.Lattice.FCC
data = pipeline.compute()

print(data.cell.pbc) # prints (True,True,True)


Note that the Pipeline.compute() method returns an independent copy of the data pipeline output. If you make any changes to the contents of this DataCollection, the pipeline will not see these changes. The modifiers in the pipeline always see the original DataCollection that the file source reads from the external simulation file.

There are two ways to achieve what you want. The file source manages an internal data cache, which feeds the data pipeline. Thus, if you alter the contents of that cache, the modifiers will receive a different input:

pipeline = import_file(sys.argv[1]) = (True,True,False)

The second option is to insert a user-defined modifier function at the beginning of the data pipeline, which makes the desired changes to the DataCollection. Subsequent modifiers in the pipeline will then see the modified dataset:

pipeline = import_file(sys.argv[1])
def change_pbc(frame, data):
    data.cell_.pbc = (True,True,False)

Dear Dr. Stukowski,

Thank you very much for your suggestions and this time it works nicely.

Sorry that I was not aware that one can put code in a special format in the post, and I will keep that in mind next time when I post.

Thank you again!

Duancheng Ma