from __future__ import print_function

import subprocess

from simlammps import read_data_file
from simlammps.cuba_extension import CUBAExtension

lammps_script = """# example of creating lammps data file (to be then used by SimPhoNy"
dimension	2
atom_style	atomic

# create geometry
lattice		hex 0.7
region		box block 0 20 0 10 -0.25 0.25
create_box	3 box
create_atoms	1 box

mass		1 1.0
mass		2 1.0
mass		3 1.0

# LJ potentials
pair_style	lj/cut 1.12246
pair_coeff	* * 1.0 1.0 1.12246

# define groups
region	     1 block INF INF INF 1.25 INF INF
group	     lower region 1
region	     2 block INF INF 8.75 INF INF INF
group	     upper region 2
group	     boundary union lower upper
group	     flow subtract all boundary

set	     group lower type 2
set	     group upper type 3

# initial velocities
compute      mobile flow temp
velocity     flow create 1.0 482748 temp mobile
velocity     boundary set 0.0 0.0 0.0

# write atoms to a lammps data file
write_data example.data"""

with open("lammps_example_script", "w") as script_file:
    script_file.write(lammps_script)

subprocess.check_call("lammps < lammps_example_script", shell=True)

particles_list = read_data_file("example.data")
print("\n\nFinished converting files")
print("\n{} Particles data-sets were read from the file:".format(
    len(particles_list)))

for particles in particles_list:
    number_particles = sum(1 for _ in particles.iter_particles())

    print("    '{}' has {} particles".format(particles.name,
                                             number_particles))

box_description = ""\
                  "Each has the following simulation box description:\n"\
                  "CUBAExtension.BOX_ORIGIN: {}\n" \
                  "CUBAExtension.BOX_VECTORS: {}"

print(box_description.format(
    particles_list[0].data_extension[CUBAExtension.BOX_ORIGIN],
    particles_list[0].data_extension[CUBAExtension.BOX_VECTORS]))

@@ -51,16 +51,61 @@
 rocess%0A%0A
+from simphony.core.cuds_item import CUDSItem%0A
 from sim
@@ -1192,21 +1192,28 @@
 articles
-_list
+, state_data
  = read_
@@ -1286,18 +1286,17 @@
 rint(%22%5Cn
-%7B%7D
+A
  Particl
@@ -1310,14 +1310,12 @@
 -set
-s
  w
-ere
+as
  rea
@@ -1335,265 +1335,252 @@
 le:%22
-.format(%0A
+)%0Aprint(%22
     
-len(particles_list)))%0A%0Afor particles in particles_list:%0A    number_particles = sum(1 for _ in particles.iter_particles())%0A%0A    print(%22    '%7B%7D' has %7B%7D particles%22.format(particles.name,%0A                                             number_particle
+'%7B%7D' has %7B%7D particles%22.format(%0A    particles.name,%0A    particles.count_of(CUDSItem.PARTICLE)))%0A%0Anumber_materials = sum(1 for _ in state_data.iter_materials())%0Aprint(%22%5Cn%7B%7D materials were read from the file.%5Cn%22.format(number_material
 s))%0A
@@ -1602,35 +1602,35 @@
 n = 
-%22%22
 %5C%0A    
-              %22Each
+%22%22%5C%0A    %22The data-set
  has
@@ -1676,39 +1676,29 @@
 on:%5Cn%22%5C%0A    
-         
+%22
     
- %22
 CUBAExtensio
@@ -1727,23 +1727,13 @@
     
+%22
     
-          %22
 CUBA
@@ -1799,32 +1799,24 @@
    particles
-_list%5B0%5D
 .data_extens
@@ -1863,16 +1863,8 @@
 cles
-_list%5B0%5D
 .dat

Upgrade file conversion example