Commit eecbc400 authored by Germain Clavier's avatar Germain Clavier
Browse files

Ok so basically the simple rewriting I wanted to do will be much more

important than expected. Partly because this is all old python2 files,
but also because tk and pyopengl was dropped. Rewriting a visualisation
tool using glumpy or any other library might be a better bet to replace
gnu.py, vcr and all those loosy classes. Why am I inflicting this again?
parent fe99bb9f
Loading
Loading
Loading
Loading
+18
Changes for src/Notes.md: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Notes on the version change

## Dependencies
* Only numpy has been ported to python 3. Not numeric.
* PIL is now Pillow (original PIL dev stopped in 2011).
  - Correct the example with
```
    from PIL import Image, ImageTk
```
   retrocompatibility must be checked.
* Check Pmw compatibility with python3.4+
* Togl support has been dropped by PyopenGL devs. Is it still relevant?
* Globally installation advices should be rewritten using pip or conda
* Is the use of some tools such as MatLab, Gnuplot or Raster3d still
  necessary given the existence of python libs (numpy, scipy, matplotlib...)

## Changes
+63 −41
Changes for src/animate.py: 63 added lines, 41 removed lines.
Original line number Diff line number Diff line
@@ -5,12 +5,29 @@
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
# certain rights in this software.  This software is distributed under
# the GNU General Public License.

#
# animate tool
#
# History
#   8/05, Matt Jones (BYU): original version
#
# ToDo list
#   make image window non-resizable while displaying an image
#   allow for file conversion, e.g. animate("png","image*jpg")
#
# Variables
#   tkroot = root of entire Tk
#   files = list of file names
#   images = list of Tkimage objects
#   nframes = number of images
#   index = current frame (0 to N-1)
#   loop_flag = set to 1 or -1 when play or back pushed
#               set to 0 when stop is pushed
#   delay_value = delay between frames (secs)
#   delay_msec = delay in millisec

oneline = "Animate a series of image files"

docstr = """
"""
Animate a series of image files
a = animate("image*.png")     create GUI to animate set of image files
a = animate("image*.png",1)   2nd arg = sort filenames, 0 = no sort, def = 1

@@ -28,32 +45,17 @@ a.frame(31) set frame slider
a.delay(0.4)            set delay slider
"""

# History
#   8/05, Matt Jones (BYU): original version

# ToDo list
#   make image window non-resizable while displaying an image
#   allow for file conversion, e.g. animate("png","image*jpg")

# Variables
#   tkroot = root of entire Tk
#   files = list of file names
#   images = list of Tkimage objects
#   nframes = number of images
#   index = current frame (0 to N-1)
#   loop_flag = set to 1 or -1 when play or back pushed
#               set to 0 when stop is pushed
#   delay_value = delay between frames (secs)
#   delay_msec = delay in millisec

# Imports and external programs

import sys, os, commands, re, glob
from Tkinter import *
from ImageTk import PhotoImage
import sys
import glob
from tkinter import PhotoImage, Toplevel, Frame, Button, Scale
from tkinter import TOP, LEFT, BOTTOM, HORIZONTAL, Label, Tk

# Class definition


class animate:

    # --------------------------------------------------------------------
@@ -67,20 +69,25 @@ class animate:

        list = str.split(filestr)
        self.files = []
    for file in list: self.files += glob.glob(file)
        for file in list:
            self.files += glob.glob(file)
        self.nframes = len(self.files)
    if self.nframes == 0: raise StandardError, "No files to load"
    if sortflag: self.files.sort()
        if self.nframes == 0:
            sys.exit("No files to load")
        if sortflag:
            self.files.sort()

        # load all images

        self.images = []
    for i in xrange(self.nframes):
        for i in range(self.nframes):
            self.images.append(PhotoImage(file=self.files[i]))

        # grab Tk instance from main

    from __main__ import tkroot
        # from __main__ import tkroot

        tkroot = Tk()
        self.tkroot = tkroot

        # GUI control window
@@ -99,12 +106,23 @@ class animate:
        holder1.pack(side=TOP)

        holder2 = Frame(win1)
    self.slider_frame = Scale(holder2,from_=0,to=self.nframes-1,
                              command=self.frame,orient=HORIZONTAL,
                              label="       Frame")
    self.slider_delay = Scale(holder2,from_=0.0,to=1.0,resolution=0.1,
                              command=self.delay,orient=HORIZONTAL,
                              label="       Delay")
        self.slider_frame = Scale(
            holder2,
            from_=0,
            to=self.nframes - 1,
            command=self.frame,
            orient=HORIZONTAL,
            label="       Frame",
        )
        self.slider_delay = Scale(
            holder2,
            from_=0.0,
            to=1.0,
            resolution=0.1,
            command=self.delay,
            orient=HORIZONTAL,
            label="       Delay",
        )
        self.slider_frame.pack(side=LEFT)
        self.slider_delay.pack(side=LEFT)
        holder2.pack(side=TOP)
@@ -141,19 +159,22 @@ class animate:
    # --------------------------------------------------------------------

    def previous(self):
    if self.index > 0: self.index -= 1
        if self.index > 0:
            self.index -= 1
        self.display(self.index)

    # --------------------------------------------------------------------

    def next(self):
    if self.index < self.nframes - 1: self.index += 1
        if self.index < self.nframes - 1:
            self.index += 1
        self.display(self.index)

    # --------------------------------------------------------------------

    def back(self):
    if self.loop_flag != 0: return
        if self.loop_flag != 0:
            return
        self.loop_flag = -1
        if self.index == 0:
            self.index = self.nframes - 1
@@ -163,7 +184,8 @@ class animate:
    # --------------------------------------------------------------------

    def play(self):
    if self.loop_flag != 0: return
        if self.loop_flag != 0:
            return
        self.loop_flag = 1
        if self.index == self.nframes - 1:
            self.index = 0
@@ -183,7 +205,8 @@ class animate:
            self.loop_flag = 0
        if self.loop_flag == -1 and self.index == 0:
            self.loop_flag = 0
    if self.loop_flag == 0: return
        if self.loop_flag == 0:
            return

        self.index += self.loop_flag
        self.display(self.index)
@@ -211,4 +234,3 @@ class animate:
        self.delay_value = float(value)
        self.slider_delay.set(self.delay_value)
        self.delay_msec = int(1000 * self.delay_value)
  
+53 −50
Changes for src/bdump.py: 53 added lines, 50 removed lines.
Original line number Diff line number Diff line
@@ -8,9 +8,8 @@

# bdump tool

oneline = "Read dump files with bond info"

docstr = """
"""
Read dump files with bond info
b = bdump("dump.one")             read in one or more dump files
b = bdump("dump.1 dump.2.gz")     can be gzipped
b = bdump("dump.*")               wildcard expands to multiple files
@@ -62,39 +61,40 @@ time,box,atoms,bonds,tris,lines = b.viz(index) return list of viz objects

# Imports and external programs

import sys, commands, re, glob, types
import sys
import re
import glob
import types
from os import popen

try:
import numpy as np
    oldnumeric = False
except:
    import Numeric as np
    oldnumeric = True

try: from DEFAULTS import PIZZA_GUNZIP
except: PIZZA_GUNZIP = "gunzip"
try:
    from DEFAULTS import PIZZA_GUNZIP
except (ModuleNotFoundError, ImportError):
    PIZZA_GUNZIP = "gunzip"

# Class definition


class bdump:

    # --------------------------------------------------------------------

  def __init__(self,*list):
    def __init__(self, *args):
        self.snaps = []
        self.nsnaps = 0
        self.names = {}

        # flist = list of all dump file names

    words = list[0].split()
        words = args[0].split()
        self.flist = []
    for word in words: self.flist += glob.glob(word)
    if len(self.flist) == 0 and len(list) == 1:
      raise StandardError,"no bdump file specified"
        for word in words:
            self.flist += glob.glob(word)
        if len(self.flist) == 0 and len(args) == 1:
            sys.exit("no bdump file specified")

    if len(list) == 1:
        if len(args) == 1:
            self.increment = 0
            self.read_all()
        else:
@@ -111,44 +111,47 @@ class bdump:

        for file in self.flist:
            if file[-3:] == ".gz":
        f = popen("%s -c %s" % (PIZZA_GUNZIP,file),'r')
      else: f = open(file)
                f = popen("%s -c %s" % (PIZZA_GUNZIP, file), "r")
            else:
                f = open(file)

            snap = self.read_snapshot(f)
            while snap:
                self.snaps.append(snap)
        print snap.time,
                print(snap.time)
                sys.stdout.flush()
                snap = self.read_snapshot(f)

            f.close()
    print
        print()

        # sort entries by timestep, cull duplicates

    self.snaps.sort(self.compare_time)
        self.snaps = sorted(self.snaps, key=lambda x: x.time)
        self.cull()
        self.nsnaps = len(self.snaps)
    print "read %d snapshots" % self.nsnaps
        print("read %d snapshots" % self.nsnaps)

    # --------------------------------------------------------------------
    # read next snapshot from list of files

    def next(self):

    if not self.increment: raise StandardError,"cannot read incrementally"
        if not self.increment:
            sys.exit("cannot read incrementally")

        # read next snapshot in current file using eof as pointer
        # if fail, try next file
        # if new snapshot time stamp already exists, read next snapshot

        while 1:
      f = open(self.flist[self.nextfile],'rb')
            f = open(self.flist[self.nextfile], "rb")
            f.seek(self.eof)
            snap = self.read_snapshot(f)
            if not snap:
                self.nextfile += 1
	if self.nextfile == len(self.flist): return -1
                if self.nextfile == len(self.flist):
                    return -1
                f.close()
                self.eof = 0
                continue
@@ -157,7 +160,8 @@ class bdump:
            try:
                self.findtime(snap.time)
                continue
      except: break
            except:
                break

        self.snaps.append(snap)
        snap = self.snaps[self.nsnaps]
@@ -188,18 +192,18 @@ class bdump:
            if snap.natoms:
                words = f.readline().split()
                ncol = len(words)
        for i in xrange(1,snap.natoms):
                for i in range(1, snap.natoms):
                    words += f.readline().split()
                floats = map(float, words)
        if oldnumeric: atoms = np.zeros((snap.natoms,ncol),np.Float)
        else: atoms = np.zeros((snap.natoms,ncol),np.float)
                atoms = np.zeros((snap.natoms, ncol), np.float)
                start = 0
                stop = ncol
        for i in xrange(snap.natoms):
                for i in range(snap.natoms):
                    atoms[i] = floats[start:stop]
                    start = stop
                    stop += ncol
      else: atoms = None
            else:
                atoms = None
            snap.atoms = atoms
            return snap
        except:
@@ -210,7 +214,7 @@ class bdump:

    def map(self, *pairs):
        if len(pairs) % 2 != 0:
      raise StandardError, "bdump map() requires pairs of mappings"
            sys.exit("bdump map() requires pairs of mappings")
        for i in range(0, len(pairs), 2):
            j = i + 1
            self.names[pairs[j]] = pairs[i] - 1
@@ -226,17 +230,6 @@ class bdump:
            i += 1
        return vec

  # --------------------------------------------------------------------
  # sort snapshots on time stamp

  def compare_time(self,a,b):
    if a.time < b.time:
      return -1
    elif a.time > b.time:
      return 1
    else:
      return 0

    # --------------------------------------------------------------------
    # delete successive snapshots with duplicate time stamp

@@ -253,13 +246,15 @@ class bdump:
    # if called with flag, then index is timestep, so convert to snapshot index

    def viz(self, index, flag=0):
    if not flag: isnap = index
        if not flag:
            isnap = index
        else:
            times = self.time()
            n = len(times)
            i = 0
            while i < n:
        if times[i] > index: break
                if times[i] > index:
                    break
                i += 1
            isnap = i - 1
        snap = self.snaps[isnap]
@@ -274,15 +269,23 @@ class bdump:
        # abs() of type since could be negative

        bonds = []
    for i in xrange(snap.natoms):
        for i in range(snap.natoms):
            atom = snap.atoms[i]
      bonds.append([int(atom[id]),abs(int(atom[type])),
                    int(atom[atom1]),int(atom[atom2])])
            bonds.append(
                [
                    int(atom[id]),
                    abs(int(atom[type])),
                    int(atom[atom1]),
                    int(atom[atom2]),
                ]
            )

        return time, None, None, bonds, None, None


# --------------------------------------------------------------------
# one snapshot


class Snap:
    pass
+927 −611

File changed.

Preview size limit exceeded, changes collapsed.

+101 −73
Changes for src/cfg.py: 101 added lines, 73 removed lines.
Original line number Diff line number Diff line
@@ -5,41 +5,41 @@
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
# certain rights in this software.  This software is distributed under
# the GNU General Public License.

#
# cfg tool

oneline = "Convert LAMMPS snapshots to AtomEye CFG format"

docstr = """
c = cfg(d)		d = object containing atom coords (dump, data)

c.one()                 write all snapshots to tmp.cfg
c.one("new")            write all snapshots to new.cfg
c.many()                write snapshots to tmp0000.cfg, tmp0001.cfg, etc
c.many("new")           write snapshots to new0000.cfg, new0001.cfg, etc
c.single(N)             write snapshot for timestep N to tmp.cfg 
c.single(N,"file")      write snapshot for timestep N to file.cfg 
"""

#
# History
#   11/06, Aidan Thompson (SNL): original version

#
# ToDo list
# should decide if dump is scaled or not, since CFG prints in scaled coords
# this creates a simple AtomEye CFG format
#   there is more complex format we could write out
#   which allows for extra atom info, e.g. to do atom coloring on
# how to dump for a triclinic box, since AtomEye accepts this

#
# Variables
#   data = data file to read from

#
# Imports and external programs

"""
Convert LAMMPS snapshots to AtomEye CFG format
c = cfg(d)              d = object containing atom coords (dump, data)

c.one()                 write all snapshots to tmp.cfg
c.one("new")            write all snapshots to new.cfg
c.many()                write snapshots to tmp0000.cfg, tmp0001.cfg, etc
c.many("new")           write snapshots to new0000.cfg, new0001.cfg, etc
c.single(N)             write snapshot for timestep N to tmp.cfg
c.single(N,"file")      write snapshot for timestep N to file.cfg
"""

import sys

# Class definition


class cfg:

    # --------------------------------------------------------------------
@@ -50,33 +50,37 @@ class cfg:
    # --------------------------------------------------------------------

    def one(self, *args):
    if len(args) == 0: file = "tmp.cfg"
    elif args[0][-4:] == ".cfg": file = args[0]
    else: file = args[0] + ".cfg"
        if len(args) == 0:
            file = "tmp.cfg"
        elif args[0][-4:] == ".cfg":
            file = args[0]
        else:
            file = args[0] + ".cfg"

        f = open(file, "w")
        n = flag = 0
        while 1:
            which, time, flag = self.data.iterator(flag)
      if flag == -1: break
            if flag == -1:
                break
            time, box, atoms, bonds, tris, lines = self.data.viz(which)

            xlen = box[3] - box[0]
            ylen = box[4] - box[1]
            zlen = box[5] - box[2]

      print >>f,"Number of particles = %d " % len(atoms)
      print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
      print >>f,"H0(1,1) = %20.10f A " % xlen
      print >>f,"H0(1,2) = 0.0 A " 
      print >>f,"H0(1,3) = 0.0 A " 
      print >>f,"H0(2,1) = 0.0 A " 
      print >>f,"H0(2,2) = %20.10f A " % ylen
      print >>f,"H0(2,3) = 0.0 A " 
      print >>f,"H0(3,1) = 0.0 A " 
      print >>f,"H0(3,2) = 0.0 A " 
      print >>f,"H0(3,3) = %20.10f A " % zlen
      print >>f,"#"
            f.write("Number of particles = %d \n" % len(atoms))
            f.write("# Timestep %d \n#\nA = 1.0 Angstrom\n" % time)
            f.write("H0(1,1) = %20.10f A \n" % xlen)
            f.write("H0(1,2) = 0.0 A \n")
            f.write("H0(1,3) = 0.0 A \n")
            f.write("H0(2,1) = 0.0 A \n")
            f.write("H0(2,2) = %20.10f A \n" % ylen)
            f.write("H0(2,3) = 0.0 A \n")
            f.write("H0(3,1) = 0.0 A \n")
            f.write("H0(3,2) = 0.0 A \n")
            f.write("H0(3,3) = %20.10f A \n" % zlen)
            f.write("#\n")

            for atom in atoms:
                itype = int(atom[1])
@@ -84,25 +88,34 @@ class cfg:
                yfrac = (atom[3] - box[1]) / ylen
                zfrac = (atom[4] - box[2]) / zlen
                #        print >>f,"1.0  %d   %15.10f  %15.10f  %15.10f  %15.10f  %15.10f  %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7])
        print >>f,"1.0  %d   %15.10f  %15.10f  %15.10f  0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
      
      print time,
                f.write("1.0  %d   %15.10f  %15.10f  %15.10f  0.0 0.0 0.0 \n" % (
                    itype,
                    xfrac,
                    yfrac,
                    zfrac,
                    )
                )

            print(time)
            sys.stdout.flush()
            n += 1

        f.close()
    print "\nwrote %d snapshots to %s in CFG format" % (n,file)
        print("\nwrote %d snapshots to %s in CFG format" % (n, file))

    # --------------------------------------------------------------------

    def many(self, *args):
    if len(args) == 0: root = "tmp"
    else: root = args[0]
        if len(args) == 0:
            root = "tmp"
        else:
            root = args[0]

        n = flag = 0
        while 1:
            which, time, flag = self.data.iterator(flag)
      if flag == -1: break
            if flag == -1:
                break
            time, box, atoms, bonds, tris, lines = self.data.viz(which)

            if n < 10:
@@ -120,18 +133,18 @@ class cfg:
            ylen = box[4] - box[1]
            zlen = box[5] - box[2]

      print >>f,"Number of particles = %d " % len(atoms)
      print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
      print >>f,"H0(1,1) = %20.10f A " % xlen
      print >>f,"H0(1,2) = 0.0 A " 
      print >>f,"H0(1,3) = 0.0 A " 
      print >>f,"H0(2,1) = 0.0 A " 
      print >>f,"H0(2,2) = %20.10f A " % ylen
      print >>f,"H0(2,3) = 0.0 A " 
      print >>f,"H0(3,1) = 0.0 A " 
      print >>f,"H0(3,2) = 0.0 A " 
      print >>f,"H0(3,3) = %20.10f A " % zlen
      print >>f,"#"
            f.write("Number of particles = %d \n" % len(atoms))
            f.write("# Timestep %d \n#\nA = 1.0 Angstrom\n" % time)
            f.write("H0(1,1) = %20.10f A \n" % xlen)
            f.write("H0(1,2) = 0.0 A \n")
            f.write("H0(1,3) = 0.0 A \n")
            f.write("H0(2,1) = 0.0 A \n")
            f.write("H0(2,2) = %20.10f A \n" % ylen)
            f.write("H0(2,3) = 0.0 A \n")
            f.write("H0(3,1) = 0.0 A \n")
            f.write("H0(3,2) = 0.0 A \n")
            f.write("H0(3,3) = %20.10f A \n" % zlen)
            f.write("#\n")

            for atom in atoms:
                itype = int(atom[1])
@@ -139,21 +152,30 @@ class cfg:
                yfrac = (atom[3] - box[1]) / ylen
                zfrac = (atom[4] - box[2]) / zlen
                #        print >>f,"1.0  %d   %15.10f  %15.10f  %15.10f  %15.10f  %15.10f  %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7])
        print >>f,"1.0  %d   %15.10f  %15.10f  %15.10f  0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
      
      print time,
                f.write("1.0  %d   %15.10f  %15.10f  %15.10f  0.0 0.0 0.0 \n" % (
                    itype,
                    xfrac,
                    yfrac,
                    zfrac,
                    )
                )

            print(time)
            sys.stdout.flush()
            f.close()
            n += 1

    print "\nwrote %s snapshots in CFG format" % n
        print("\nwrote %s snapshots in CFG format" % n)

    # --------------------------------------------------------------------

    def single(self, time, *args):
    if len(args) == 0: file = "tmp.cfg"
    elif args[0][-4:] == ".cfg": file = args[0]
    else: file = args[0] + ".cfg"
        if len(args) == 0:
            file = "tmp.cfg"
        elif args[0][-4:] == ".cfg":
            file = args[0]
        else:
            file = args[0] + ".cfg"

        which = self.data.findtime(time)
        time, box, atoms, bonds, tris, lines = self.data.viz(which)
@@ -163,18 +185,18 @@ class cfg:
        ylen = box[4] - box[1]
        zlen = box[5] - box[2]

    print >>f,"Number of particles = %d " % len(atoms)
    print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
    print >>f,"H0(1,1) = %20.10f A " % xlen
    print >>f,"H0(1,2) = 0.0 A " 
    print >>f,"H0(1,3) = 0.0 A " 
    print >>f,"H0(2,1) = 0.0 A " 
    print >>f,"H0(2,2) = %20.10f A " % ylen
    print >>f,"H0(2,3) = 0.0 A " 
    print >>f,"H0(3,1) = 0.0 A " 
    print >>f,"H0(3,2) = 0.0 A " 
    print >>f,"H0(3,3) = %20.10f A " % zlen
    print >>f,"#"
        f.write("Number of particles = %d \n" % len(atoms))
        f.write("# Timestep %d \n#\nA = 1.0 Angstrom\n" % time)
        f.write("H0(1,1) = %20.10f A \n" % xlen)
        f.write("H0(1,2) = 0.0 A \n")
        f.write("H0(1,3) = 0.0 A \n")
        f.write("H0(2,1) = 0.0 A \n")
        f.write("H0(2,2) = %20.10f A \n" % ylen)
        f.write("H0(2,3) = 0.0 A \n")
        f.write("H0(3,1) = 0.0 A \n")
        f.write("H0(3,2) = 0.0 A \n")
        f.write("H0(3,3) = %20.10f A \n" % zlen)
        f.write("#\n")

        for atom in atoms:
            itype = int(atom[1])
@@ -182,6 +204,12 @@ class cfg:
            yfrac = (atom[3] - box[1]) / ylen
            zfrac = (atom[4] - box[2]) / zlen
            #        print >>f,"1.0  %d   %15.10f  %15.10f  %15.10f  %15.10f  %15.10f  %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7])
      print >>f,"1.0  %d   %15.10f  %15.10f  %15.10f  0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
            f.write("1.0  %d   %15.10f  %15.10f  %15.10f  0.0 0.0 0.0 \n" % (
                itype,
                xfrac,
                yfrac,
                zfrac,
                )
            )

        f.close()
Loading