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

mistake when create bonds using pairwise mode

Dear all

I am attempting to make a list of bonds between different types such as [1,1],[1,2].But when I use the example as follewed

# Import OVITO modules.
from ovito.io import *
from ovito.modifiers import *
from ovito.data import *

# Import standard Python and NumPy modules.
import sys
import numpy

# Load the simulation dataset to be analyzed.
node = import_file("E:/results/01/R-cluster/12/dump.PdZnOH.ff.1200")
cutoff = 3.0

create_bonds_modifier = CreateBondsModifier(mode=CreateBondsModifier.Mode.Pairwise)
create_bonds_modifier.set_pairwise_cutoff('Type 1', 'Type 1', 3.0)
node.modifiers.append(create_bonds_modifier)
out = node.compute()

a mistake occurs.RuntimeError: Data pipeline failure: Modifier 'Create bonds' reported: At least one positive bond cutoff must be set for a valid pair of particle types.

I search a lot but failed to solve it.

Thanks.

Bao

 

Dear Bao,

This could actually be a bug in OVITO, because the CreateBondsModifier apparently cannot find a particle type named "Type 1". Please try specifying the numeric type ID instead:

create_bonds_modifier.set_pairwise_cutoff(1, 1, 3.0)

Note that the method set_pairwise_cutoff() accepts numeric type IDs as well as type names. When loading a LAMMPS dump file, particle types have no real names, just implicitly generated names like "Type <id>". Thus, referring to them by numeric ID in a Python script is safer.

Let me know if the problem persists. In the meantime I will check if the issue can be fixed in the OVITO source code.

-Alex

Thank you, Alex. The problem is solved.I am sorry for my late reply.Now I want to create 3 bonds between 11 ,12 ,22,so I want to konw if i can get the output at once by assigning different values such as create_bonds_modifier1.numbonds. So far I get the output through get three CreateBonds.num_bonds.I mean that use these values in the meantime.

 

Thanks

-Bao

Dear Bao,

if you want to create bonds between two specific particles a and b it's easiest to use the create_bond(a,b) function of the Bonds class, see manual:
https://www.ovito.org/docs/current/python/modules/ovito_data.php#ovito.data.Bonds

If you were asking how to set different pair-wise cutoffs, that can be simply done like this:

create_bonds_mod = CreateBondsModifier(mode=CreateBondsModifier.Mode.Pairwise)
create_bonds_mod.set_pairwise_cutoff(1, 1, 2.7)
create_bonds_mod.set_pairwise_cutoff(1, 2, 2.9)
create_bonds_mod.set_pairwise_cutoff(2, 2, 3.3)
node.modifiers.append(create_bonds_mod)

There is no need to use 3 individual CreateBondsModifier instances.

-Constanze

Bao, I might not have understood your question correctly. Did you maybe ask how to count different bond types? In that case, you could do this with a few lines of python code. Here is an example of a modifier function that looks up the particle types of all particles present in the Bond topology array and then counts the frequency of all possible pairs. Finally, this information is stored as global attributes. If you like you can try it:

from ovito.data import *
import numpy as np

def modify(frame, data):
    bonds = data.bonds.topology
    types = data.particles.particle_types
    bond_types = types[bonds]
    
    type, count = np.unique(np.sort(bond_types), return_counts = True, axis = 0)
    
    for t, c in zip(type,count):
        attribute_name = "bond-type {}".format(t)
        data.attributes[attribute_name] = c

-Constanze