Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - dekoning

Pages: [1]
Support Forum / Re: Applying modifier in script
« on: December 14, 2017, 07:23:13 PM »
Hi Alex,

I'd like to calculate the bisector vectors of rigid water molecules. To do this I need generate the bond vectors between oxygens and protons.
The way I was doing it (which, of course, works) is to use the graphical interface to generate the bonds and then computing the bisectors using
the custom modifier. I would like the entire process to be done using a single python script. That was why I was trying to use the CreateBondsModifier within
the function.



Support Forum / Applying modifier in script
« on: December 14, 2017, 01:44:57 PM »
Hi Alex,

I'm trying to append a modifier to the pipeline in a custom Modifier using the following code.
I'm getting the error "AttributeError: DataCollection does not have an attribute named 'modifiers'."
How can I fix this? Thanks!


from ovito.modifiers import *
import numpy as np

def modify(frame, input, output):
   print("The input contains %i particles." % input.number_of_particles)
   b = CreateBondsModifier()
   b.mode = CreateBondsModifier.Mode.Pairwise
   b.set_pairwise_cutoff("Type 1","Type 2",1.1)

Thanks Alex, your suggestion of assigning a new instance of the VectorDisplay class worked.


Now, how can I draw the 3-component elements of output.particle_properties["Bisectors"] as an arrow?

For instance, with a standard property such as one can write

vector_display = node.source.particle_properties.force.display
vector_display.color = (1.0, 0.5, 0.5)

but this (i.e., adding .display at the end) is not working for the Bisectors case.


I'm trying to define a new particle property called "Bisectors" to contain
a 3 dimensional vector that I'd like to plot. The python script (to be called after creating bonds) is included below.
Everything seems to be fine up to the moment I make the call

vector_display = output.particle_properties.bisectors.display

where it complains: AttributeError: DataCollection does not contain the particle property 'bisectors'.

But when I call


it returns ['Particle Identifier', 'Particle Type', 'Position', 'Bisectors']. So it seems to be there.

Any ideas as to what might be going on?



from ovito.vis import VectorDisplay
import numpy as np

def modify(frame, input, output):
   print("The input contains %i particles." % input.number_of_particles)
   bisectors = output.create_user_particle_property("Bisectors","float",3)
   particle_positions = input.particle_properties.position.array
   nparticles = len(particle_positions)
   bonds_array = input.bonds.array
   bond_vectors = particle_positions[bonds_array[:,1]] - particle_positions[bonds_array[:,0]]
   bond_vectors +=[:,:3], output.bonds.pbc_vectors.T).T
   type = input.particle_properties.particle_type.array
   for i in range(len(bonds_array)):
      particle = bonds_array[i,0]
      if type[particle]==1:
         bisectors.marray[particle] += bond_vectors[i,:]       
   bisectors_norm = np.empty([nparticles],float)
   for i in range(nparticles):
      bisectors_norm = sum(bisectors.marray[i,:]**2)
      if type == 1:
         bisectors.marray[i,:] /= np.sqrt(bisectors_norm)

   vector_display = output.particle_properties.bisectors.display
   vector_display.enabled = True 
   vector_display.color = (0.0, 1.0, 0.0)

Support Forum / Writing LAMMPS data file
« on: December 08, 2016, 12:53:52 PM »
I' trying to write a lammps data file of a water system, which requires information on the number of bonds, bond angles,
bond topology. The file should begin with the information below. Is it possible to export data in this format using Ovito? I've tried several lammps data formats but none of them produces the desired output.

Water or ice system -- ready for LAMMPS

       49278  atoms
       32852  bonds
       16426  angles
           0  dihedrals
           0  impropers
           2  atom types
           1  bond types
           1  angle types
           0  dihedral types
           0  improper types
  -1.0199900000000000        162.01200000000000       xlo xhi
 -0.85399899999999995        165.68400000000000       ylo yhi
 -1.00000000000000000        21.000000000000000       zlo zhi


           1   15.999400
           2   1.0079401


           1           1           1  -1.1794000000000000       0.95439302900000000        4.0402598400000000       8.39004517000000033E-002
           4           2           1  -1.1794000000000000        5.8201699299999996        3.8705799600000002       2.86998748999999984E-002
           7           3           1  -1.1794000000000000        9.3335199400000004        1.3312100200000001       0.36179924000000002

Support Forum / Re: Python Modifier Script
« on: December 08, 2016, 12:48:33 PM »
Thanks, that worked.

Support Forum / Re: Python Modifier Script
« on: November 23, 2016, 12:15:41 PM »
Thanks Alexander,

Yes, I am using version 2.7.1.

The modifier I would like to write should allow one to select Molecules (not atoms) according to some positional information. For instance, considering a cell containing water molecules, I would like to select those molecules with the z-coordinates of the oxygens within certain limits.

Any suggestions?

Support Forum / Python Modifier Script
« on: November 22, 2016, 07:25:53 PM »
I'm trying to use the Python script option from the Modifier Dropdown menu. The first thing I tried was to use the example in
the documentation that explains the use of the DataCollection.copy_if_needed() method. It is copied below.
My problem is that the script does not get past the first assert test, whether the cell of the input and output DataObjects are the same.
So apparently they are different. Any idea what' going on?

def modify(frame, input, output):

    # Original simulation cell is passed through by default.
    # Output simulation cell is just a reference to the input cell.
    assert(output.cell is input.cell)

    # Make a copy of the simulation cell:
    cell = output.copy_if_needed(output.cell)

    # copy_if_needed() made a deep copy of the simulation cell object.
    # Now the the input and output each point to different objects.
    assert(cell is output.cell)
    assert(cell is not input.cell)

    # Now it's safe to modify the object copy:
    cell.pbc = (False, False, False)

Pages: [1]