python 3 compatibility for src/*.py files

move imports to top of files
add from __future__ import
commands module -> subprocesses module
print statement -> print() function
exec statement -> exec() function
xrange -> range
map() -> list(map())
StandardError -> Exception
integer division: / -> //
x.has_key(y) -> y in x
sort(): use functools.cmp_to_key
type(x) is y -> isinstance(x, y)
raw_input -> input
change variable names 'list' to avoid clashes with list class
This commit is contained in:
danielque
2023-08-10 13:19:02 +02:00
parent d560b34214
commit 597e606bde
34 changed files with 1463 additions and 1352 deletions

View File

@ -8,6 +8,12 @@
# patch tool
# Imports and external programs
from __future__ import absolute_import
from math import sqrt,pi,cos,sin
from data import data
oneline = "Create patchy Lennard-Jones particles for LAMMPS input"
docstr = """
@ -61,11 +67,6 @@ p.write("data.patch") write out system to LAMMPS data file
# seed = random seed
# molecules = list of atoms, grouped by molecule
# Imports and external programs
from math import sqrt,pi,cos,sin
from data import data
# Class definition
class patch:
@ -98,8 +99,14 @@ class patch:
if style == "linebox" or style == "linetri": self.style = "line"
if style == "tritet" or style == "tribox": self.style = "tri"
cmd = "atoms,bonds,tris,segments,volume = self.%s(*types)" % style
for i in xrange(n):
exec cmd
for i in range(n):
ldict = {'i':i,'self':self,'types':types}
exec(cmd,globals(),ldict)
atoms = ldict['atoms']
bonds = ldict['bonds']
tris = ldict['tris']
segments = ldict['segments']
volume = ldict['volume']
self.molecules.append([atoms,bonds,tris,segments])
self.volume += volume
@ -131,7 +138,7 @@ class patch:
latflag = 1
if self.lattice[0]*self.lattice[1]*self.lattice[2] != \
len(self.molecules):
raise StandardError,"lattice inconsistent with # of molecules"
raise Exception("lattice inconsistent with # of molecules")
else: latflag = 0
idatom = idbond = idtri = idmol = 0
@ -343,7 +350,7 @@ class patch:
if self.lattice[0] or self.lattice[1]:
latflag = 1
if self.lattice[0]*self.lattice[1] != len(self.molecules):
raise StandardError,"lattice inconsistent with # of molecules"
raise Exception("lattice inconsistent with # of molecules")
else: latflag = 0
idatom = idbond = idmol = 0
@ -885,7 +892,7 @@ class patch:
sep = params[1]
type = params[2]
if n % 2 == 0:
raise StandardError, "N in patch::star2d is not odd"
raise Exception("N in patch::star2d is not odd")
middle = n/2
atoms = []
@ -1131,7 +1138,7 @@ class patch:
# --------------------------------------------------------------------
def random(self):
k = self.seed/IQ
k = self.seed//IQ
self.seed = IA*(self.seed-k*IQ) - IR*k
if self.seed < 0:
self.seed += IM