Author Topic: Colouring of atoms  (Read 360 times)

jb2191

  • Newbie
  • *
  • Posts: 4
Colouring of atoms
« on: April 10, 2018, 03:59:54 PM »
Hello Everybody

Does anybody know how to colour atoms in OVITO according a column in an input file for example if say I put a column in the input file called colour, can OVITO read hex or RGB?

Thanks

Jonathan


Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 476
Re: Colouring of atoms
« Reply #1 on: April 10, 2018, 05:55:35 PM »
Yes, you can let OVITO read in per-atom color values. You will need three extra columns in your input file with the RGB components in the range [0,1].

Make sure these columns get mapped to the Color.R, Color.G and Color.B particle properties during file import. Depending on the file format you are using, it may be possible to add some metadata to the header of the input file so that this mapping happens automatically.

jb2191

  • Newbie
  • *
  • Posts: 4
Re: Colouring of atoms
« Reply #2 on: April 14, 2018, 02:23:13 PM »
Great! Thank you for your help!

jb2191

  • Newbie
  • *
  • Posts: 4
Re: Colouring of atoms
« Reply #3 on: June 03, 2018, 04:03:57 PM »
Furthermore to this I've now created the file with the following columns: color.R, color.B and color.G but using the "color coding" modification I can only visualise each channel individually. Rather I would like to visualise all simultaneously so [R, G, B] -> [color.R, color.G, color.B]

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 476
Re: Colouring of atoms
« Reply #4 on: June 03, 2018, 05:21:07 PM »
There is no need to use the Color Coding modifier. The purpose of this modifier is to map a scalar particle property to an RGB triplet. But in your case you already have the triplet.

Property names are case-sensitive in OVITO. Only if a property is named "Color" and has three vector components, then OVITO will use the stored values to color the particles during visualization. If the property is named "color", then it will treated as a user-defined property by the program with no further meaning. OVITO will not use its values when rendering the particles.

Please adjust the naming of the columns in the input file accordingly. If you need help with that, please post the header of the input file. I am still not sure what kind of file format you are dealing with.

jb2191

  • Newbie
  • *
  • Posts: 4
Re: Colouring of atoms
« Reply #5 on: June 04, 2018, 03:31:27 PM »
Ok I have the following in the input file (lammps trj format)

ITEM: TIMESTEP
0
ITEM: NUMBER OF ATOMS
1999
ITEM: BOX BOUNDS pp pp pp
0 40.05
0 40.05
0 40.05
ITEM: ATOMS id type x y z fx fy fz Color.R Color.G Color.B

I can remap these to the correct colours but it doesn't happen automatically.




Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 476
Re: Colouring of atoms
« Reply #6 on: June 04, 2018, 04:02:34 PM »
I see. The automatic mapping only works for other file formats. The LAMMPS dump file parser of OVITO doesn't perform the mapping automatically, mainly because LAMMPS doesn't typically write out any color information. Maybe I can change that behaviour in a future version of OVITO if needed.

There are several workarounds which you can use in the meantime:

The Compute Property modifier of OVITO allows you to copy the values from the color.r, color.g and color.b properties over to the standard Color particle property. You can insert an instance of this modifier at program startup from the command line by using a Python script command:

Code: [Select]
ovito --exec "import ovito.modifiers; ovito.dataset.selected_node.modifiers.append(ovito.modifiers.ComputePropertyModifier(output_property='Color', expressions=['color.r','color.g','color.b']));" inputfile.dump

Or you save a preconfigured Compute Property modifier as a modifier preset for quick access within OVITO.

Alternatively, you can use a script command at program startup to import the LAMMPS dump file, override the default behavior and explicitly specify the column mapping:

Code: [Select]
ovito --exec "from ovito.io import import_file; import_file('inputfile.dump', columns=['Particle Identifier','Particle Type','Position.X','Position.Y','Position.Z','Force.X','Force.Y','Force.Z','Color.R','Color.G','Color.B']).add_to_scene();"