1#!/usr/bin/env python -i
2# preceding line should have path for Python on your machine
3
4# viz_atomeye.py
5# Purpose: viz running LAMMPS simulation via AtomEye
6# Syntax:  viz_atomeye.py in.lammps Nfreq Nsteps
7#          in.lammps = LAMMPS input script
8#          Nfreq = dump and viz shapshot every this many steps
9#          Nsteps = run for this many steps
10
11from __future__ import print_function
12import sys,os
13
14# set this to point to AtomEye version 3 executable
15# first line if want AtomEye output to screen, 2nd line to file
16#ATOMEYE3 = "/home/sjplimp/tools/atomeye3/A3.i686-20060530"
17ATOMEYE3 = "/home/sjplimp/tools/atomeye3/A3.i686-20060530 > atomeye.out"
18
19# parse command line
20
21argv = sys.argv
22if len(argv) != 4:
23  print("Syntax: viz_atomeye.py in.lammps Nfreq Nsteps")
24  sys.exit()
25
26infile = sys.argv[1]
27nfreq = int(sys.argv[2])
28nsteps = int(sys.argv[3])
29
30me = 0
31# uncomment this if running in parallel via mpi4py
32#from mpi4py import MPI
33#me = MPI.COMM_WORLD.Get_rank()
34#nprocs = MPI.COMM_WORLD.Get_size()
35
36from lammps import lammps
37lmp = lammps()
38
39# run infile all at once
40# assumed to have no run command in it
41# dump a file in extended CFG format for AtomEye
42
43lmp.file(infile)
44lmp.command("thermo %d" % nfreq)
45lmp.command("dump python all cfg %d tmp.cfg.* mass type xs ys zs id" % nfreq)
46
47# initial 0-step run to generate dump file and image
48
49lmp.command("run 0 pre yes post no")
50ntimestep = 0
51
52# wrapper on GL window via Pizza.py gl tool
53# just proc 0 handles reading of dump file and viz
54
55if me == 0:
56  a = os.popen(ATOMEYE3,'w')
57  a.write("load_config tmp.cfg.0\n")
58  a.flush()
59
60# run nfreq steps at a time w/out pre/post, read dump snapshot, display it
61
62while ntimestep < nsteps:
63  lmp.command("run %d pre no post no" % nfreq)
64  ntimestep += nfreq
65  if me == 0:
66    a.write("load_config tmp.cfg.%d\n" % ntimestep)
67    a.flush()
68
69lmp.command("run 0 pre no post yes")
70
71# uncomment if running in parallel via mpi4py
72#print("Proc %d out of %d procs has" % (me,nprocs), lmp)
73