Sync copies of pizza

This commit is contained in:
Richard Berger
2021-06-02 13:09:52 -04:00
parent 3f1bbf7c71
commit 249a2a6783
6 changed files with 424 additions and 505 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,9 @@
# certain rights in this software. This software is distributed under # certain rights in this software. This software is distributed under
# the GNU General Public License. # the GNU General Public License.
# for python3 compatibility
from __future__ import print_function
# gnu tool # gnu tool
oneline = "Create plots via GnuPlot plotting program" oneline = "Create plots via GnuPlot plotting program"
@ -84,12 +87,13 @@ g.curve(N,'r') set color of curve N
# Imports and external programs # Imports and external programs
import types, os import os
import sys
try: from DEFAULTS import PIZZA_GNUPLOT try: from DEFAULTS import PIZZA_GNUPLOT
except: PIZZA_GNUPLOT = "gnuplot" except ImportError: PIZZA_GNUPLOT = "gnuplot -p"
try: from DEFAULTS import PIZZA_GNUTERM try: from DEFAULTS import PIZZA_GNUTERM
except: PIZZA_GNUTERM = "x11" except ImportError: PIZZA_GNUTERM = "x11"
# Class definition # Class definition
@ -119,6 +123,9 @@ class gnu:
def enter(self): def enter(self):
while 1: while 1:
if sys.version_info[0] == 3:
command = input("gnuplot> ")
else:
command = raw_input("gnuplot> ") command = raw_input("gnuplot> ")
if command == "quit" or command == "exit": return if command == "quit" or command == "exit": return
self.__call__(command) self.__call__(command)
@ -133,7 +140,7 @@ class gnu:
self.export(file,linear,vectors[0]) self.export(file,linear,vectors[0])
self.figures[self.current-1].ncurves = 1 self.figures[self.current-1].ncurves = 1
else: else:
if len(vectors) % 2: raise StandardError,"vectors must come in pairs" if len(vectors) % 2: raise Exception("vectors must come in pairs")
for i in range(0,len(vectors),2): for i in range(0,len(vectors),2):
file = self.file + ".%d.%d" % (self.current,i/2+1) file = self.file + ".%d.%d" % (self.current,i/2+1)
self.export(file,vectors[i],vectors[i+1]) self.export(file,vectors[i],vectors[i+1])
@ -167,13 +174,13 @@ class gnu:
def export(self,filename,*vectors): def export(self,filename,*vectors):
n = len(vectors[0]) n = len(vectors[0])
for vector in vectors: for vector in vectors:
if len(vector) != n: raise StandardError,"vectors must be same length" if len(vector) != n: raise Exception("vectors must be same length")
f = open(filename,'w') f = open(filename,'w')
nvec = len(vectors) nvec = len(vectors)
for i in xrange(n): for i in range(n):
for j in xrange(nvec): for j in range(nvec):
print >>f,vectors[j][i], print(str(vectors[j][i])+" ",file=f,end='')
print >>f print ("",file=f)
f.close() f.close()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -350,7 +357,7 @@ class gnu:
self.__call__("set key off") self.__call__("set key off")
cmd = 'plot ' cmd = 'plot '
for i in range(fig.ncurves): for i in range(int(fig.ncurves)):
file = self.file + ".%d.%d" % (self.current,i+1) file = self.file + ".%d.%d" % (self.current,i+1)
if len(fig.colors) > i and fig.colors[i]: if len(fig.colors) > i and fig.colors[i]:
cmd += "'" + file + "' using 1:2 with line %d, " % fig.colors[i] cmd += "'" + file + "' using 1:2 with line %d, " % fig.colors[i]

View File

@ -6,6 +6,9 @@
# certain rights in this software. This software is distributed under # certain rights in this software. This software is distributed under
# the GNU General Public License. # the GNU General Public License.
# for python3 compatibility
from __future__ import print_function
# pdb tool # pdb tool
oneline = "Read, write PDB files in combo with LAMMPS snapshots" oneline = "Read, write PDB files in combo with LAMMPS snapshots"
@ -51,6 +54,7 @@ index,time,flag = p.iterator(1)
# History # History
# 8/05, Steve Plimpton (SNL): original version # 8/05, Steve Plimpton (SNL): original version
# 3/17, Richard Berger (Temple U): improve Python 3 compatibility
# ToDo list # ToDo list
# for generic PDB file (no template) from a LJ unit system, # for generic PDB file (no template) from a LJ unit system,
@ -64,7 +68,13 @@ index,time,flag = p.iterator(1)
# Imports and external programs # Imports and external programs
import sys, types, glob, urllib import sys, glob, urllib
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
else:
string_types = basestring
# Class definition # Class definition
@ -74,7 +84,7 @@ class pdbfile:
def __init__(self,*args): def __init__(self,*args):
if len(args) == 1: if len(args) == 1:
if type(args[0]) is types.StringType: if type(args[0]) is string_types:
filestr = args[0] filestr = args[0]
self.data = None self.data = None
else: else:
@ -83,7 +93,7 @@ class pdbfile:
elif len(args) == 2: elif len(args) == 2:
filestr = args[0] filestr = args[0]
self.data = args[1] self.data = args[1]
else: raise StandardError, "invalid args for pdb()" else: raise Exception("invalid args for pdb()")
# flist = full list of all PDB input file names # flist = full list of all PDB input file names
# append .pdb if needed # append .pdb if needed
@ -94,17 +104,17 @@ class pdbfile:
for file in list: for file in list:
if '*' in file: flist += glob.glob(file) if '*' in file: flist += glob.glob(file)
else: flist.append(file) else: flist.append(file)
for i in xrange(len(flist)): for i in range(len(flist)):
if flist[i][-4:] != ".pdb": flist[i] += ".pdb" if flist[i][-4:] != ".pdb": flist[i] += ".pdb"
if len(flist) == 0: if len(flist) == 0:
raise StandardError,"no PDB file specified" raise Exception("no PDB file specified")
self.files = flist self.files = flist
else: self.files = [] else: self.files = []
if len(self.files) > 1 and self.data: if len(self.files) > 1 and self.data:
raise StandardError, "cannot use multiple PDB files with data object" raise Exception("cannot use multiple PDB files with data object")
if len(self.files) == 0 and not self.data: if len(self.files) == 0 and not self.data:
raise StandardError, "no input PDB file(s)" raise Exception("no input PDB file(s)")
# grab PDB file from http://rcsb.org if not a local file # grab PDB file from http://rcsb.org if not a local file
@ -112,7 +122,7 @@ class pdbfile:
try: try:
open(self.files[0],'r').close() open(self.files[0],'r').close()
except: except:
print "downloading %s from http://rcsb.org" % self.files[0] print("downloading %s from http://rcsb.org" % self.files[0])
fetchstr = "http://www.rcsb.org/pdb/cgi/export.cgi/%s?format=PDB&pdbId=2cpk&compression=None" % self.files[0] fetchstr = "http://www.rcsb.org/pdb/cgi/export.cgi/%s?format=PDB&pdbId=2cpk&compression=None" % self.files[0]
urllib.urlretrieve(fetchstr,self.files[0]) urllib.urlretrieve(fetchstr,self.files[0])
@ -142,20 +152,20 @@ class pdbfile:
which,time,flag = self.data.iterator(flag) which,time,flag = self.data.iterator(flag)
if flag == -1: break if flag == -1: break
self.convert(f,which) self.convert(f,which)
print >>f,"END" print("END",file=f)
print time, print(time,end='')
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
else: else:
for file in self.files: for file in self.files:
f.write(open(file,'r').read()) f.write(open(file,'r').read())
print >>f,"END" print("END",file=f)
print file, print(file,end='')
sys.stdout.flush() sys.stdout.flush()
f.close() f.close()
print "\nwrote %d datasets to %s in PDB format" % (n,file) print("\nwrote %d datasets to %s in PDB format" % (n,file))
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# write series of numbered PDB files # write series of numbered PDB files
@ -190,7 +200,7 @@ class pdbfile:
self.convert(f,which) self.convert(f,which)
f.close() f.close()
print time, print(time,end='')
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
@ -210,12 +220,12 @@ class pdbfile:
f = open(file,'w') f = open(file,'w')
f.write(open(infile,'r').read()) f.write(open(infile,'r').read())
f.close() f.close()
print file, print(file,end='')
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
print "\nwrote %d datasets to %s*.pdb in PDB format" % (n,root) print("\nwrote %d datasets to %s*.pdb in PDB format" % (n,root))
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# write a single PDB file # write a single PDB file
@ -280,10 +290,10 @@ class pdbfile:
if self.atomlines.has_key(id): if self.atomlines.has_key(id):
(begin,end) = self.atomlines[id] (begin,end) = self.atomlines[id]
line = "%s%8.3f%8.3f%8.3f%s" % (begin,atom[2],atom[3],atom[4],end) line = "%s%8.3f%8.3f%8.3f%s" % (begin,atom[2],atom[3],atom[4],end)
print >>f,line, print(line,file=f,end='')
else: else:
for atom in atoms: for atom in atoms:
begin = "ATOM %6d %2d R00 1 " % (atom[0],atom[1]) begin = "ATOM %6d %2d R00 1 " % (atom[0],atom[1])
middle = "%8.3f%8.3f%8.3f" % (atom[2],atom[3],atom[4]) middle = "%8.3f%8.3f%8.3f" % (atom[2],atom[3],atom[4])
end = " 1.00 0.00 NONE" end = " 1.00 0.00 NONE"
print >>f,begin+middle+end print(begin+middle+end,file=f)