Author Topic: dump bond length for each atom  (Read 120 times)

zfan

  • Newbie
  • *
  • Posts: 9
dump bond length for each atom
« on: February 12, 2019, 03:35:38 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: dump bond length for each atom
« Reply #1 on: February 12, 2019, 08:42:48 AM »
Dear Zhao,
would you like an answer for Ovito 2.9.0 or for the new 3.0.0 development release?

zfan

  • Newbie
  • *
  • Posts: 9
Re: dump bond length for each atom
« Reply #2 on: February 12, 2019, 05:06:37 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: dump bond length for each atom
« Reply #3 on: February 12, 2019, 06:32:39 PM »
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: [Select]
# 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)
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: [Select]
[1 2] 1.22793
[2 1] 1.13556
[1 2] 1.17782
[2 1] 1.21634
[1 2] 1.24922
...

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: dump bond length for each atom
« Reply #4 on: February 12, 2019, 06:39:53 PM »
For Ovito 3.0.0-dev the code looks similar:

Code: [Select]
    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)

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.
« Last Edit: February 12, 2019, 06:41:31 PM by Alexander Stukowski »

zfan

  • Newbie
  • *
  • Posts: 9
Re: dump bond length for each atom
« Reply #5 on: February 12, 2019, 07:47:18 PM »
Thanks, Alexander, for your solution, which works on both versions.

But can I dump bond informations for each atom? In other words, I want to know, in a given cutoff distance, for each atom, how many neighboring atoms it have, how long the distance between the central and every neighboring atoms (bond length of the central atom to every neighboring atom) is, and what's atom type of every neighboring atoms of the central atom?

Obviously, each atom have different number of neighboring atoms and thus bond length is not a particle property. So I have some trouble to dump bond information for every central atom. Hope you could give me more help.

Thanks,
Zhao

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: dump bond length for each atom
« Reply #6 on: February 12, 2019, 07:56:25 PM »
I see, you seem to want a method for visiting all neighbors of an atom within a certain cutoff range, independent of whether they are bonded to the central atom or not. For this purpose the Ovito scripting interface provides the CutoffNeighborFinder utility class:

http://ovito.org/manual_testing/python/modules/ovito_data.html#ovito.data.CutoffNeighborFinder

The example script (for Ovito 3.0) shows how to print a list of neighbors for each atom, their distance from the central atom and how to access their type.

Is that what you were looking for?

zfan

  • Newbie
  • *
  • Posts: 9
Re: dump bond length for each atom
« Reply #7 on: February 12, 2019, 07:56:51 PM »
Seems I can know the bonds you printed in the code snippet above belongs which two atoms just though atom IDs stored in atom_pair. So I could write some code to assign all these bonds to each central atom, which may be not difficult.

zfan

  • Newbie
  • *
  • Posts: 9
Re: dump bond length for each atom
« Reply #8 on: February 12, 2019, 08:03:28 PM »
Thanks Alexander. Yes, it is exactly what I want to obtain. Can CutoffNeighborFinder be used on version 2.9?

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: dump bond length for each atom
« Reply #9 on: February 12, 2019, 08:06:31 PM »
Yes, the class is available in Ovito 2.9.0 as well:

http://ovito.org/manual/python/modules/ovito_data.html#ovito.data.CutoffNeighborFinder

It's just the example script in the old docs doesn't demonstrate how to access properties of the neighboring atom such as their chemical type. But it works the same way as shown in the newer documentation for Ovito 3.0.0: You simply need to use the neigh.index field to look up the neighbor's information in the 'Particle Type' property array.

zfan

  • Newbie
  • *
  • Posts: 9
Re: dump bond length for each atom
« Reply #10 on: February 12, 2019, 11:16:17 PM »
Thank, Alexander, very much for your solutions, which worked pretty well.
Zhao