Author Topic: Visulaise the Molecule in dump xyz lammps file  (Read 571 times)

jaguarjom123

  • Newbie
  • *
  • Posts: 9
Visulaise the Molecule in dump xyz lammps file
« on: May 10, 2019, 07:48:22 AM »
Dear Ovito and users,
Sorry to post my question here but I can't post in a new thread can you tell me how to post my future new question on OVITO?

My question is I have (H2O)+H2+O2+ Pt, structure (i.e Pt nanoparticle immersed inside the solvent ),
some type of molecules will be formed, I can get only the number and type of molecules formatted by lammps but I can't extract the (x,y,z) for those molecules. I still have the dump.xyz file which includes all atoms in the structure and molecules, so may I know please how can I use OVITO to only extract the molecules formed and visualize them (which can be like the diffusion of those molecules also), for example, the formation of  H2O3 or HO, which only form near the surface of Pt?
I tried to use "creat-bond" and then "Cluster" analysis, but cannot get to know how to proceed further,

looking to your help and support

Thank you

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #1 on: May 10, 2019, 11:23:26 AM »
Dear jaguarjom123,

no worries, I opened a new topic for you. In principle you can just click on "New Topic" on the Forum main page, and after if is approved by an admin it will be visible to the public.

It is a little difficult to help you without having detailed information on your system, so if you like you can upload an example file here in the forum using the "Attachements" function below the text-editor. That way I can have a look at your system and give you more specific advice.
But as a starting point: You said that your data includes molecule ID's. Note that you can use the Expression selection modifier to select molecules based on their ID's then and even delete all other atoms from the scene. Furthermore, you could calculate the center of mass of each molecule and e.g. use the Generate trajectory lines modifier to visualize their trajectories. You could also use a custom Python script modifier to calculate mean squared displacement etc.
Let me know if you have questions regarding any of those analyses.

-Constanze
« Last Edit: May 10, 2019, 11:25:05 AM by Constanze Kalcher »

jaguarjom123

  • Newbie
  • *
  • Posts: 9
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #2 on: May 10, 2019, 07:08:53 PM »
thank you for your reply,
yes I have for example this kind of data (it included several time frames of the x,y,z coordinated of particles) as in attachment 1
in attachment number 2 it is one of the time steps of the structure image I have,
this structure must include many molecules which formed over time, I do interested in specific types which are near and close to the surface of the material in the middle.
looking for your guidance and help

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #3 on: May 13, 2019, 11:47:23 AM »
Hi,

so do you still need to identify the molecules that formed (i.e. which atoms belong to which molecule), or do you have that information in your xyz file? If not, you probably first need to use the "Create bonds" modifier to
take care of that:
https://ovito.org/manual_testing/particles.modifiers.create_bonds.html
Then, you could select the atoms in the center and again use a bond-based criterion, or a Compute property modifier to count the molecules in the vicinity of your selected atoms.

In any case, I need to see the data to give you more specific input.
-Constanze

jaguarjom123

  • Newbie
  • *
  • Posts: 9
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #4 on: May 19, 2019, 05:28:43 AM »
Dear Constanze Kalcher
Thank for your reply,
I have applied those modifiers in this order:
"Creat Bonds"
Then I  choose "Expression select" --> "ParticleType==4"
then I applied to "compute properties" but then how can apply the conditions
like what shall I choose  for example is "Molecule Identifier" is the correct to show molecules only,
and then how to delete other atoms and visualize those molecules?
here I attached some steps of my structure "extracted2", my original structure is much larger, so I hope this can be uploaded,
looking at your reply and guidance soon
Thank you
« Last Edit: May 19, 2019, 06:05:37 AM by jaguarjom123 »

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #5 on: May 22, 2019, 04:50:51 PM »
Dear jaguarjom123,

I had a look at your structure you uploaded and the only information that you have in your data is the atom type and the positions - nothing more. That makes the analysis a little bit more complicated for you.

So in order to be able to calculate how many molecules are close to the surface of your Pt nanoparticle, you first need to teach ovito which atom belongs to which molecule. You could store that information in a particle property "Molecule ID" e.g..
The way to do this is to e.g. use the Create bonds modifier with an appropriate cutoff to identify particles that share a bond with other particles in conjunction with a Python script modifier. Below is an example of a custom python script modifier that checks which atoms are connected through bonds and assigns these groups a unique Molecule ID as particle property.
There is certainly more than one solution to do this, the following is just an example for you to know where to start:
Code: [Select]
from ovito.data import *
import numpy as np
def modify(frame, data):
   
    molecule_counter = 1
    molecule_ids = data.particles_.create_property("Molecule Identifier")
    bond_topology = data.particles.bonds.topology  # array with bond topology
   
    # Create bonds enumerator object.
    bonds_enum = BondsEnumerator(data.particles.bonds)

    # Loop over atoms.
    for particle_index in range(data.particles.count):
        # Loop over bonds of current atom.
        bond_pairs = [ (bond_topology[bond_index][0],bond_topology[bond_index][1]) for bond_index in bonds_enum.bonds_of_particle(particle_index)]
        if len(bond_pairs) != 0:
            neighbor_indices = np.unique(bond_pairs)
            if (np.all( [molecule_ids[i] for i in neighbor_indices]) == 0):
                    with molecule_ids:
                        molecule_ids[neighbor_indices] = molecule_counter
                    molecule_counter+=1
           

Then you could use the Select Type modifier (-> Particle Type 4) and after that the Expand selection with your desired cutoff value. This selects all atoms close to the surface of the sphere (and also inside, but you could delete these later if you don't want to look at them).
You should then apply another Expand selection modifier, this time with the option "bonded to a selected particle" (also increase number of iterations) to make sure you didn't only select half of a molecule with the previous modifier.
Now Invert and then delete the selection.
I attached the resulting picture in a screenshot.

-Constanze
« Last Edit: June 04, 2019, 11:40:00 AM by Constanze Kalcher »

jaguarjom123

  • Newbie
  • *
  • Posts: 9
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #6 on: May 24, 2019, 04:30:18 AM »
Dear Constanze Kalcher

Thank you so much,
it is really helpful even though I  the python script but was not running for me, but I followed your steps of using modifiers and it works nicely,
now I could get all molecules near nanoparticles, so if I may ask you please one more question,
it is possible for example to the number of (H2O2)  "for example" which is a group of atoms (3-2-3-2)?

thank you again

sincerely

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #7 on: May 24, 2019, 02:25:45 PM »
Dear jaguarjom123,

you would need to develop your own custom python script modifier function for that. In principle you could use the example function I posted above and modify it such that it also assigns a property "Molecule type" based on the number of neighbors that are found for each atom.
Then, within your selection of molecules close to the nanoparticle, you could specfically look for certain molecule types.

-Constanze

jaguarjom123

  • Newbie
  • *
  • Posts: 9
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #8 on: June 04, 2019, 03:55:12 AM »
Dear Constanze Kalcher

The script of OVITO code you have kindly written was not working for me (i tried to use and work for solving my problem),
it keeps giving "modify() takes 2 positional arguments but 3 were given". error.
I have previously 2.9 OVITO  version (windows) I deleted and try to use version 3.0 of ovito but this version doesn't work for me,
so I only can use ovito 2.9
so is it related to the package or something I don't understand I am really sorry but I am also new for python as well,
---------------------------------------------------
EDITEd1: I have used the Zip archive of version 3.0 of ovito windows and the error changed to "    File "<string>", line 16, in modify
TypeError: object of type 'bool' has no len()' 
EDITED2: it seems working after change the line 35 , " if len(bond_pairs)!= 0:"   instead of "len(bond_pairs != 0):"

will try now to show only H2O2 molecules
thank you again

Sincerely
« Last Edit: June 04, 2019, 05:35:30 AM by jaguarjom123 »

jaguarjom123

  • Newbie
  • *
  • Posts: 9
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #9 on: June 04, 2019, 08:34:16 AM »
Dear Constanze Kalcher

I would like to ask you  further questions please,
I have used one of your scripts (script A) http://forum.ovito.org/index.php?topic=469.0
to evaluate the neighbor atoms with the code you have already written previously for my current forum,
I have applied it (i.e script A) right after the molecules near nanoparticle shown but I still struggle that I cant '
write a proper script for extracting and visualizing specific molecules like H2O2, or OH from those all molecules,
also, I defined "    molecule_type = data.particles_.create_property("Molecule Type") "
but still  without a solution so can you please to help me update the script you wrote for me to show specific molecules,

thank you again

SIncerely 

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #10 on: June 04, 2019, 10:05:46 AM »
Dear jaguarjom123,

you're right, the code snippet I posted above was meant for ovito 3. And yes, the error in line 16 was a typo, thanks for pointing that out. I corrected that in the above version.
Concerning your second question, I think it's easiest if you loop over all particles and then - based on the particle property "Molecule ID" you created - check how many atoms (and atom types) belong to each molecule. That way you can easily distinguish H2O2 and HO e.g.

If you're not comfortable with the python scripting interface yet, you could try to achieve the same by using the Compute property modifier. As an example, this will count the number of atoms within the neighborhood of a particle that share the same property Molecule ID as the central particle.
Expression: 0
NeighborExpression: @MoleculeID == MoleculeID

-Constanze


jaguarjom123

  • Newbie
  • *
  • Posts: 9
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #11 on: June 04, 2019, 10:50:56 AM »
Dear Constanze Kalcher
Thank for your kind reply,

I am attaching a snip of the ovito compute property
I have signed Expression 0 (as default)
neighbor particle
cutoff 3
neighbor expression
Moleculeidentifier == 2488

so by this was I can trace the particle 2488 particle and its neighbor within 3 A cutoff distance?
and if I want to delete another particle shall I choose from expression select
MoleculeIdentifier==2401   
then invert and delete?
and how to apply for all molecules with this method,
Sorry for my question which could be very easy in some sense but I am confused for using ovito at first place, and thank again for your help

sincerely

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: Visulaise the Molecule in dump xyz lammps file
« Reply #12 on: June 04, 2019, 11:17:03 AM »
Hi,
no this is not how that works. The neighbor expression is really:
NeighborExpression: @MoleculeID == MoleculeID
Also, I assume the cutoff needs to be much larger, in order to assure that you're not missing any neighboring atoms. However, it seems like the Compute property modifier caused even more confusion.

So I suggest you to try to solve this with a python script like I explained above and let us know if you're stuck.

-Constanze
« Last Edit: June 04, 2019, 11:20:03 AM by Constanze Kalcher »