Author Topic: Define a new properties  (Read 57 times)

akhoursh

  • Newbie
  • *
  • Posts: 10
Define a new properties
« on: August 27, 2018, 04:59:04 PM »
Dear OVITO users,
Hi,

Using the following command in python tab, I can define a new property in Ovito 3. But, it doesn't work in Ovito 2.9.

xyz_prime = output.particles.create_property('xyz_prime', dtype = float, components = (1))

I tried to use the below command :

xyz_prime = output.create_user_particle_property("xyz_prime","float",1)

But it gives me the error:
  File "<string>", line 81, in modify
AttributeError: __exit__


Line 81 and 82 of my code is:
with xyz_prime:
                        xyz_prime[particle_index] = 1

I wonder if you could please help me out.
Thanks,
Ali


Constanze Kalcher

  • Administrator
  • Jr. Member
  • *****
  • Posts: 62
Re: Define a new properties
« Reply #1 on: August 27, 2018, 06:06:32 PM »
Dear Ali,

write-access to particle properties was done differently in OVITO 2.9.

In that case, instead of using a with statement in your "lines 81-82" you need to access your particle property "xyz_prime" like this

Code: [Select]
xyz_prime.marray[particle_index] = 1
xyz_prime.changed()

as described in more detail in this Section in the Manual.
Does this solve your problem?

-Constanze

akhoursh

  • Newbie
  • *
  • Posts: 10
Re: Define a new properties
« Reply #2 on: August 27, 2018, 11:05:22 PM »
Hi Constanze,

Thanks for your comment. Yes, it is working now.
Regards,
Ali