### Author Topic: Exporting properties of selected atoms and Bond Angles  (Read 190 times)

#### ffa126

• Newbie
• Posts: 5
##### Exporting properties of selected atoms and Bond Angles
« on: May 08, 2018, 12:25:10 AM »
Hi Dr. Stukowski,

I have two questions:

1) I want to output the x-, y- and z- coordinates of a set of atoms I have selected in the order that I selected them. How would I achieve this?

2) I want to find the angle which a bond makes with respect to a given axis. How would I achieve this?

Regards,

Farheen Ahmed

#### Alexander Stukowski

• Sr. Member
• Posts: 465
##### Re: Exporting properties of selected atoms and Bond Angles
« Reply #1 on: May 08, 2018, 07:40:51 AM »
1)
This may be difficult, because particle selection sets don't have a particular ordering. The ordering is always the same and equal to the ordering of the full list of particles. OVITO's file export function will always write the list in that same order.

How exactly did you select the atoms that you want to export? Using the Manual Selection modifier?

2)
Most likely you will need to use a Python script modifier for this and write a short Python function, because there is no built-in function for this particular computation in OVITO. The user-defined modifier function would first compute the bond vectors and then the angles. Finally, this modifier function would output the angles as a new bond property.

-Alex

#### ffa126

• Newbie
• Posts: 5
##### Re: Exporting properties of selected atoms and Bond Angles
« Reply #2 on: May 09, 2018, 12:02:01 AM »
Hi Dr. Stukowski,

1) Yes.

2) Okay. I tried building a python code to extract the bond vectors. (This python code is in the pipeline above the Create Bonds modifier.) The code isn't working and I'm not sure what is wrong with it:

Code: [Select]
`from ovito.io import *from ovito.data import *from ovito.modifiers import *import numpy as npdef modify (frame, input, output): particle_positions = node.output.particle_properties.position.array bonds_array = node.output.bonds.array bond_vectors = particle_positions[bonds_array[:,1]] - particle_positions[bonds_array[:,0]]`Do you know what is wrong with it?

Regards,

Farheen
« Last Edit: May 09, 2018, 05:07:49 PM by Alexander Stukowski »

#### Alexander Stukowski

• Sr. Member
• Posts: 465
##### Re: Exporting properties of selected atoms and Bond Angles
« Reply #3 on: May 09, 2018, 05:12:38 PM »
Unlike in the example where you copied this code from, which was operating on the output of a data pipeline ("node.output"), in the present context you have to take the atomic coordinates from the input of the user-defined modifier function. Thus, replace "node.output" with "input" in the first two lines of the function.

Then the existing code should work with an error message showing up. You can then continue and compute the angles formed by the bond vectors.

#### ffa126

• Newbie
• Posts: 5
##### Re: Exporting properties of selected atoms and Bond Angles
« Reply #4 on: May 09, 2018, 09:57:07 PM »
Okay. Thank you.

I just tried building a python code which finds the angle between the bond normal and the y-axis.
Code: [Select]
`from ovito.io import *from ovito.data import *from ovito.modifiers import *import numpy as npdef modify (frame, input, output): particle_positions = input.particle_properties.position.array bonds_array = input.bonds.array BondProperty.bond_vectors = particle_positions[bonds_array[:,1]] - particle_positions[bonds_array[:,0]] bondlength=len(BondProperty.bond_vectors) for i in range(1 bondlength) # find angle between normal and y-axis for each bond. BondProperty.Denom(i)=((BondProperty.bond_vectors[i,1])^2+(BondProperty.bond_vectors[i,2])^2)^0.5 BondProperty.cosfi(i)=(BondProperty.bond_vectors[:,2])/BondProperty.Denom(i) BondProperty.fi(i)=arccos(BondProperty.fi)(i) break output=BondProperty.cosfi output=BondProperty.fi`
The code will not run, though. I get an error message with the for-loop and also fi I try outputting BondProperty. What am I doing wrong with this code?

Regards,

Farheen
« Last Edit: May 09, 2018, 10:23:32 PM by Alexander Stukowski »

#### Alexander Stukowski

`def modify (frame, input, output): particle_positions = input.particle_properties.position.array bonds_array = input.bonds.array bond_vectors = particle_positions[bonds_array[:,1]] - particle_positions[bonds_array[:,0]] bond_vectors += numpy.dot(input.cell.matrix[:,:3], input.bonds.pbc_vectors.T).T numpy.savetxt('bond_vectors.txt', bond_vectors)`