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

Create bonds

Hi

I want to calculate the bonding between certain types of atoms, but the script I write doesn't work?
How to write the script correctly?

from ovito.modifiers import CreateBondsModifier 
from ovito.io import import_file 
import numpy as np 

path = r"E:\动力学\1900K\1900K-cfg.lammpstrj" 

pipeline = import_file(path)
pipeline.modifiers.append(CreateBondsModifier(mode=CreateBondsModifier.Mode.Pairwise,set_pairwise_cutoff=(1, 1, 3.24))) 

for i in range(pipeline.source.num_frames): 
    atom = [] 
    data = pipeline.compute(i) 
    for a, b in data.particles.bonds.topology: 
        atom.append([a, b]) 
        atom_np = np.array(atom) 
        print(atom_np)

 

Uploaded files:
  • error.jpg

Hi,

set_pairwise_cutoff() is a method of the CreateBondsModifier class not a property. You can do the following:

from ovito.modifiers import CreateBondsModifier 
from ovito.io import import_file 
import numpy as np 
path = r"E:\动力学\1900K\1900K-cfg.lammpstrj" 
pipeline = import_file(path)

bonds_mod = CreateBondsModifier(mode=CreateBondsModifier.Mode.Pairwise)
bonds_mod.set_pairwise_cutoff(1, 1, 3.24)
pipeline.modifiers.append(bonds_mod) 

for frame in range(pipeline.source.num_frames): 
    data = pipeline.compute(frame)
    #....

 

The problem has been solved, thank you very much for your help