File: viz_vmd.py

package info (click to toggle)
lammps 20250204%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 474,368 kB
  • sloc: cpp: 1,060,070; python: 27,785; ansic: 8,956; f90: 7,254; sh: 6,044; perl: 4,171; fortran: 2,442; xml: 1,714; makefile: 1,352; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (91 lines) | stat: -rwxr-xr-x 2,128 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python -i
# preceding line should have path for Python on your machine

# viz_vmd.py
# Purpose: viz running LAMMPS simulation via VMD
# Syntax:  viz_vmd.py in.lammps Nfreq Nsteps
#          in.lammps = LAMMPS input script
#          Nfreq = dump and viz shapshot every this many steps
#          Nsteps = run for this many steps

from __future__ import print_function
import sys
sys.path.append("./pizza")

# parse command line

argv = sys.argv
if len(argv) != 4:
  print("Syntax: viz_vmd.py in.lammps Nfreq Nsteps")
  sys.exit()

infile = sys.argv[1]
nfreq = int(sys.argv[2])
nsteps = int(sys.argv[3])

me = 0
# uncomment this if running in parallel via mpi4py
#from mpi4py import MPI
#me = MPI.COMM_WORLD.Get_rank()
#nprocs = MPI.COMM_WORLD.Get_size()

from lammps import lammps
lmp = lammps()

# run infile all at once
# assumed to have no run command in it

lmp.file(infile)
lmp.command("thermo %d" % nfreq)
lmp.command("dump python all atom %d tmp.dump" % nfreq)

# initial 0-step run to generate dump file and image

lmp.command("run 0 pre yes post no")
ntimestep = 0

# wrapper on VMD window via Pizza.py vmd tool
# just proc 0 handles reading of dump file and viz

if me == 0:
  from vmd import vmd
  v = vmd()
  v('menu main off')
  v.rep('VDW')

  from dump import dump
  from pdbfile import pdbfile

  d = dump('tmp.dump',0)
  p = pdbfile(d)
  d.next()
  d.unscale()
  p.single(ntimestep)
  v.new('tmp.pdb','pdb')

# run nfreq steps at a time w/out pre/post, read dump snapshot, display it

while ntimestep < nsteps:
  lmp.command("run %d pre no post no" % nfreq)
  ntimestep += nfreq
  if me == 0:
    d.next()
    d.unscale()
    p.single(ntimestep)
    # add frame to current data set
    v.append('tmp.pdb','pdb')
    # delete all frame and add new.
    #v.update('tmp.dump')

lmp.command("run 0 pre no post yes")

if me == 0:
  v.flush()
  # uncomment the following, if you want to work with the viz some more.
  #v('menu main on')
  #print("type quit to terminate.")
  #v.enter()
  #v.stop()

# uncomment if running in parallel via mpi4py
#print("Proc %d out of %d procs has" % (me,nprocs), lmp)