Author Topic: LAMMPS input file with atomic mass information?  (Read 106 times)

RU

  • Newbie
  • *
  • Posts: 12
LAMMPS input file with atomic mass information?
« on: August 28, 2018, 10:21:59 AM »
Hey,

I would like to read the mass information from LAMMPS data files into Ovito for further processing. But it seems to me that the information from the Masses-block is not red by Ovito?
I have a MWE for a data file (atom style: full) containing two atoms with masses:
Code: [Select]
# boundaries
0.000  10.000 xlo xhi
0.000  10.000 ylo yhi
0.000  10.000 zlo zhi
0.000  0.000 0.000 xy xz yz

# number of different atoms/bond 
2 atom types
1 bond types

# number of different atoms/bond
2 atoms
1 bonds

Masses

1   1   
2   2

Atoms

1  1 1 0.000000 4.0 5.0 5.0
2  1 2 0.000000 6.0 5.0 5.0


Velocities

1   0.0 0.0 0.0
2   0.0 0.0 0.0

Bonds

1 1 1 2
When loading the data file of the MWE, I can not find the masses at any point (Color coding; Compute Property;...)
Am I missing something or does Ovito really not read the masses?
If so, is there a workaround to read the data from the LAMMPS data file?
Thanks!

RU

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 464
Re: LAMMPS input file with atomic mass information?
« Reply #1 on: August 28, 2018, 08:07:41 PM »
Dear RU,

That's true, the current versions of OVITO ignore the mass values in a LAMMPS data file. Mainly this is because OVITO stores masses on a per-particle basis, while data files specify mass values on a per-type basis. But of course it would be possible to simply map the per-type masses to the "Mass" per-particle property in OVITO. And I will certainly extend OVITO in the future to do exactly this.

In the meantime, you could manually assign the masses within the program, for example using the Compute property modifier. For the example you posted, with only two atom types, you could enter the following compute expression to assign the right masses:

Code: [Select]
ParticleType==1 ? 1 : 2

A more advanced solution, requiring more work, would be to write a user-defined modifier function in Python that actually parses the masses from the data file and assigns them to the particles. 

-Alex

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 464
Re: LAMMPS input file with atomic mass information?
« Reply #2 on: August 28, 2018, 08:22:59 PM »
I've created a feature request in our issue tracker to keep track of the planned addition:

https://gitlab.com/stuko/ovito/issues/110

RU

  • Newbie
  • *
  • Posts: 12
Re: LAMMPS input file with atomic mass information?
« Reply #3 on: August 29, 2018, 03:03:19 PM »
Dear Alex,

thank you for your answer.

I wrote a python script (for version 2.x!), that assigns the mass to the particle propertie, based on the particle type.
The particle type corresponds to the atomic number for my models.
Maybe the corresponding code snippet (not working as a single script) helps others:
Code: [Select]
    MASS_HYDROGEN       = 1.008
    MASS_CARBON         = 12.011   

    node.source.create_particle_property(ParticleProperty.Type.Mass)
   
    particle_mass = node.source.particle_properties.mass
    particle_type = node.source.particle_properties.particle_type

    for id in range(0,particle_mass.size):
        if particle_type.marray[id] == 1:
            particle_mass.marray[id] = MASS_HYDROGEN       
        elif particle_type.marray[id] == 6:
            particle_mass.marray[id] = MASS_CARBON   
        else:
            particle_mass.marray[id]=0
    particle_mass.changed()

-----

However, for version 3.x my script is not working properly, although I dont get an error.
Maybe you could help me to figure out why the mass property is not set correctly.
This is a MWE with which I dont get an error message, but also not the mass property defined...:
Code: [Select]
import ovito
if __name__ == '__main__':
   
    pipeline    = ovito.scene.selected_pipeline
    data        = pipeline.compute()
           
    prop        = data.particles.create_property('Mass')
    with prop:
        for id in range(0,data.particles.count):
            # just an example
            if data.particles['Particle Type'][id] == 1:
                prop[id] = 1.0
            else:
                prop[id] = 2.0
   
    # dont know if this line is needed?
    data.objects.append(prop)


Best regards
RU
« Last Edit: August 29, 2018, 04:33:34 PM by RU »

Constanze Kalcher

  • Administrator
  • Jr. Member
  • *****
  • Posts: 62
Re: LAMMPS input file with atomic mass information?
« Reply #4 on: September 03, 2018, 11:21:44 AM »
Hi RU,

here is an example how you would do it in the scripting interface of OVITO 3 with a Python script modifier that uses the user-defined function "assign_mass". Note, that you need to invoke pipeline.compute() to make the particle property "mass" part of your pipeline.

Code: [Select]
from ovito.data import *
from ovito.modifiers import PythonScriptModifier

# Load some input data:
pipeline = import_file("input/simulation.data")

def assign_mass(frame, input, output):
    p_types = input.particles['Particle Type']
    mass = output.particles.create_property('Mass')
    with mass:
        mass[(p_types == 1)] = 1.008
        mass[(p_types == 6)] = 12.011

pipeline.modifiers.append(PythonScriptModifier(function = assign_mass))

# Evaluate data pipeline. This will result in a call to assign_mass() from above.
data = pipeline.compute()

-Constanze

Constanze Kalcher

  • Administrator
  • Jr. Member
  • *****
  • Posts: 62
Re: LAMMPS input file with atomic mass information?
« Reply #5 on: September 03, 2018, 12:50:50 PM »
Alternatively,
if you only have the two particle types 1 and 6 in your system using the Compute Property Modifier as suggested by Alex will work as well:

Code: [Select]
pipeline.modifiers.append(ComputePropertyModifier(output_property = 'Mass', expressions = ['(ParticleType == 1) ? 1.008 : 12.011'] ))
pipeline.compute()