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

cna don't update

Dear Constanze & Alex

I have deposition simulation in which the total number of atoms (N) is changing over time. I am trying to count the number of atoms with each structure using CNA. However, the CNA values in the below script remain unchanged. I used it before for a different system with constant N in ovito  2.9.0. Now, I am using ovito 3.0.0-dev794 and I appreciate any help. Please also find attached an example dump file.

Kind regards,

Movaffaq

from ovito.io import import_file, export_file
from ovito.modifiers import SelectTypeModifier, CommonNeighborAnalysisModifier
from ovito import dataset
import numpy as np

# Load a simulation trajectory consisting of several frames:
finput = "../dump"
foutput = "./cna.txt"
print("The input file is %s" %finput)
step = 1
pipeline = import_file(finput, multiple_frames = True)

# Insert the modifier into the pipeline:
select_type = SelectTypeModifier(types = {1,3})
pipeline.modifiers.append(select_type)
cna = CommonNeighborAnalysisModifier(only_selected = True)
pipeline.modifiers.append(cna)

f = open(foutput,"w+")
f.write("Common neighbor analysis %s\n" %foutput)
f.write("frame fcc bcc hcp ico none\n")
# Loop over all/some frames
for frame in range(0,pipeline.source.num_frames,step):
    print('Current frame: ',frame)
    pipeline.compute(frame)
    fcc = pipeline.output.attributes['CommonNeighborAnalysis.counts.FCC']
    bcc = pipeline.output.attributes['CommonNeighborAnalysis.counts.BCC']
    hcp = pipeline.output.attributes['CommonNeighborAnalysis.counts.HCP']
    ico = pipeline.output.attributes['CommonNeighborAnalysis.counts.ICO']
    none = pipeline.output.attributes['CommonNeighborAnalysis.counts.OTHER']
    #print(fcc,bcc,hcp,ico,none)
    f.write("%d %d %d %d %d %d\n" %(frame,fcc,bcc,hcp,ico,none))
f.close() 
print("Fin!")

 

Dear Movaffaq,

please note that the ObjectNode.output field has been removed. It used to provide access to the cached results of the data pipeline after a call to ObjectNode.compute(). Now the computation results should be requested using compute() and stored in a local variable instead.

You should change your lines 25 to 30 as shown below:

from ovito.io import import_file, export_file
from ovito.modifiers import SelectTypeModifier, CommonNeighborAnalysisModifier
import numpy as np
# Load a simulation trajectory consisting of several frames:                                                                            
finput = "./test.dump"
foutput = "./cna.txt"
print("The input file is %s" %finput)
step = 1
pipeline = import_file(finput, multiple_frames = True)
# Insert the modifier into the pipeline:                                                                                                
select_type = SelectTypeModifier(types = {1,3})
pipeline.modifiers.append(select_type)
cna = CommonNeighborAnalysisModifier(only_selected = True)
pipeline.modifiers.append(cna)
f = open(foutput,"w+")
f.write("Common neighbor analysis %s\n" %foutput)
f.write("frame fcc bcc hcp ico none\n")
# Loop over all/some frames                                                                                                             
for frame in range(0,pipeline.source.num_frames,step):
        print('Current frame: ',frame)
        data = pipeline.compute(frame)
        fcc = data.attributes['CommonNeighborAnalysis.counts.FCC']
        bcc = data.attributes['CommonNeighborAnalysis.counts.BCC']
        hcp = data.attributes['CommonNeighborAnalysis.counts.HCP']
        ico = data.attributes['CommonNeighborAnalysis.counts.ICO']
        none = data.attributes['CommonNeighborAnalysis.counts.OTHER']
        #print(fcc,bcc,hcp,ico,none)                                                                                                    
        f.write("%d %d %d %d %d %d\n" %(frame,fcc,bcc,hcp,ico,none))
f.close()
print("Fin!")

You also might find the OVITO 2.9 migration guide in the manual helpful: https://www.ovito.org/docs/current/python/introduction/version_changes.php.

By the way, global attributes can be conveniently exported by using OVITO's file-export function with the option "txt/attr".
https://www.ovito.org/docs/current/python/modules/ovito_io.php#ovito.io.export_file

You may shorten your script like this:

from ovito.io import import_file, export_file
from ovito.modifiers import SelectTypeModifier, CommonNeighborAnalysisModifier

finput = "./test.dump"
pipeline = import_file(finput, multiple_frames = True)

pipeline.modifiers.append(SelectTypeModifier(types = {1,3}))
pipeline.modifiers.append(CommonNeighborAnalysisModifier(only_selected = True))

export_file(pipeline, "cna.txt", "txt/attr",
              columns=["Timestep", "CommonNeighborAnalysis.counts.FCC", "CommonNeighborAnalysis.counts.FCC", "CommonNeighborAnalysis.counts.HCP", "CommonNeighborAnalysis.counts.ICO", "CommonNeighborAnalysis.counts.OTHER" ],multiple_frames = True )

-Constanze

Thanks a lot,

This version change link saves me a lot of trouble.

Bests,

Movaffaq