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.


Topics - dekoning

Pages: [1]
1
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!

Maurice

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)
   output.modifiers.append(b)

2
Hi,

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

print(list(output.particle_properties.keys()))

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

Any ideas as to what might be going on?

Maurice

********************************************

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 += np.dot(output.cell.matrix[:,:3], output.bonds.pbc_vectors.T).T
   type = input.particle_properties.particle_type.array
   
   print(output)
   print(list(output.particle_properties.keys()))
   
   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)
   print("Done!")

3
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

 Masses

           1   15.999400
           2   1.0079401

 Atoms

           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

4
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]