OVITO > Support Forum

dump bond length for each atom

(1/3) > >>

zfan:
Dear OVITOS users,

I know "ovitos" can create bonds and compute bond length. But how can I export/dump all bond lengths and its bond type (bond A-A or A-B or B-B) for each atom into a file? Thanks.

Sincerely,
Zhao

Alexander Stukowski:
Dear Zhao,
would you like an answer for Ovito 2.9.0 or for the new 3.0.0 development release?

zfan:
Dear Alexander,

I installed 2.9.0 on one HPC and 3.0.0 on other one. I found there seems no ComputeBondlengthsModifilers on 3.0, it's right? Or there is something wrong on my installation?

ComputeBondlengthsModifilers is OK in my 2.9. So could you please give me an answer for 2.9? Thanks.

Zhao

Alexander Stukowski:
Here is a Python code snippet for Ovito 2.9.0, which prints the list of all bonds in a data collection, listing the types of the two atoms connected by a bond and the bond's length:


--- Code: --- # Get the atom type property:
atom_types = data.particle_properties['Particle Type'].array

# Get the array containing the bond topology, i.e. pairs of atom indices;
bonds_list = data.bonds.array

# The the 'Length' bond property array previously computed by the Compute Bond Lengths modifier:
bond_lengths = data.bond_properties['Length'].array

# Simultaneously iterate over the bond topology array and the bond lengths array:
for atom_pair, bond_length in zip(bonds_list, bond_lengths):

# Skip every other half-bond, because Ovito 2.9 stores A->B and B->A bonds.
if atom_pair[0] < atom_pair[1]: continue

# Use the atom index pair to look up the types of the two atoms connected by the current bond:
print(atom_types[atom_pair], bond_length)

--- End code ---
The code assumes that you have applied the Compute Bond Lengths modifier, which creates the 'Length' bond property being accessed in the script.

The code produces output that looks like this:


--- Code: ---[1 2] 1.22793
[2 1] 1.13556
[1 2] 1.17782
[2 1] 1.21634
[1 2] 1.24922
...

--- End code ---

Alexander Stukowski:
For Ovito 3.0.0-dev the code looks similar:


--- Code: ---    atom_types = data.particles['Particle Type']
    bond_list = data.bonds['Topology']
    bond_lengths = data.bonds['Length']
    for atom_pair, bond_length in zip(bond_list, bond_lengths):
        print(atom_types[atom_pair], bond_length)

--- End code ---

The main difference is that Ovito 3.0.0 works with full bonds, not half-bonds. Thus, it is no longer necessary to skip every other bond in the loop.

The Compute Bond Lengths modifier has been removed in Ovito 3.0.0. The simple type of computation it performs can now be accomplished with the standard Compute Property modifier. You should set it to operate on bonds instead of particles, set the output property name to "Length", and enter "BondLength" as expression.

Navigation

[0] Message Index

[#] Next page

Go to full version