Change output format to custom lammps/data from hoomd-blue gsd file

Hi,

I have a .gsd system file created with hoomd-blue and now I want to change the format to lammps/data using a python script with ovito. In the .gsd file the particle type indices start at “0” and have to be incremented by 1 to work with lammps. Additionally I use a custom hybrid bond charge pair style in lammps, so the data file should look like this:

LAMMPS data file via write_data, version 29 Oct 2020
1000 atoms
988 bonds
4 atom types
1 bond types
-12.0 12.0 xlo xhi
-12.0 12.0 ylo yhi
-12.0 12.0 zlo zhi

Masses

1 1
2 1
3 1
4 1

Atoms # hybrid

1 1 -4.8904447556 -9.0006971359 -4.4801688194 1 0.0 0 0 0
2 2 1.0052903891 1.9645963907 -10.9656629562 1 0.0 0 0 0
3 3 3.8270976543 -1.3371047974 -8.0224752426 1 0.0 0 0 0
4 4 2.8785529137 -1.7345225811 -7.4386529922 1 0.0 0 0 0

If i use the export file function of ovito:
export_file(pipeline, “test.data”, “lammps/data”, atom_style=“hybrid”, atom_substyles=(“bond”, “charge”))

the data file looks like this:

LAMMPS data file written by Ovito 3.7.12

1000 atoms
988 bonds
4 atom types
1 bond types
-12.0 12.0 xlo xhi
-12.0 12.0 ylo yhi
-12.0 12.0 zlo zhi

Atoms # hybrid bond charge

1 0 -4.8904447556 -9.0006971359 -4.4801688194 1 0.0
2 1 1.0052903891 1.9645963907 -10.9656629562 1 0.0
3 2 3.8270976543 -1.3371047974 -8.0224752426 1 0.0
4 3 2.8785529137 -1.7345225811 -7.4386529922 1 0.0

I tried to define some custom particle property “lammps particle type” and use something like
export_file(pipeline, “outputfile.dump”, “lammps/dump”,
columns = [“Position.X”, “Position.Y”, “Position.Z”, “My Property”])

or

export_file(pipeline, “FENE.xyz”, “xyz”, columns =
[“Particle Identifier”, “Particle Type”, “Position.X”, “Position.Y”, “Position.Z”])

to achive the right format for the columns, without success. I would be glad for any help you can give.
Best,
Hendrik

In the next release, OVITO 3.8.0, the LAMMPS data file writer will provide the option to renumber the atom types during export. This will solve the problem of zero-based type IDs from a GSD file.

In the meantime, you can insert a custom modifier into the pipeline to adjust the type IDs from 0-based to 1-based:

def increment_type_ids(frame: int, data: DataCollection):
    ptype_prop = data.particles_.particle_types_
    ptype_prop[...] += 1
    for t in ptype_prop.types:
        ptype_prop.make_mutable(t).id += 1

pipeline.modifiers.append(increment_type_ids)

This modifier function changes the numeric IDs of the ParticleType objects and increments the values stored in the per-atom type array.

Thank you again Dr Stukowski,

I tried it and it works perfectly. Of course the same change has to be done for bonds:

def increment_bondtype_ids(frame: int, data: DataCollection):
    btype_prop = data.particles_.bonds_.bond_types_
    btype_prop[...] += 1
    for t in btype_prop.types:
        btype_prop.make_mutable(t).id += 1

pipeline.modifiers.append(increment_bondtype_ids)

and I assume in other cases for angles, too.

Is it possible to include the masses with “export_file”? And is it possible to append the extra " 0 0 0" at the end of each line in the Atoms - section of the data file?