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,11 @@
# pair tool
# Imports and external programs
from __future__ import absolute_import
from math import sqrt
oneline = "Compute LAMMPS pairwise energies"
docstr = """
@ -41,10 +46,6 @@ e_vdwl,e_coul = p.single(rsq,itype,jtype,q1,q2,...) compute LJ/Coul energy
# Variables
# Imports and external programs
from math import sqrt
# Class definition
class pair:
@ -68,7 +69,7 @@ class pair:
self.init_func = self.init_lj_charmm_coul_charmm
self.single_func = self.single_lj_charmm_coul_charmm
else:
raise StandardError, "this pair style not yet supported"
raise Exception("this pair style not yet supported")
# --------------------------------------------------------------------
# generic coeff method
@ -99,10 +100,10 @@ class pair:
self.lj3 = []
self.lj4 = []
for i in xrange(ntypes):
for i in range(ntypes):
self.lj3.append(ntypes * [0])
self.lj4.append(ntypes * [0])
for j in xrange(ntypes):
for j in range(ntypes):
epsilon_ij = sqrt(epsilon[i]*epsilon[j])
sigma_ij = sqrt(sigma[i]*sigma[j])
self.lj3[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,12.0);
@ -143,10 +144,10 @@ class pair:
self.lj3 = []
self.lj4 = []
for i in xrange(ntypes):
for i in range(ntypes):
self.lj3.append(ntypes * [0])
self.lj4.append(ntypes * [0])
for j in xrange(ntypes):
for j in range(ntypes):
epsilon_ij = sqrt(epsilon[i]*epsilon[j])
sigma_ij = sqrt(sigma[i]*sigma[j])
self.lj3[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,12.0);
@ -197,10 +198,10 @@ class pair:
self.lj3 = []
self.lj4 = []
for i in xrange(ntypes):
for i in range(ntypes):
self.lj3.append(ntypes * [0])
self.lj4.append(ntypes * [0])
for j in xrange(ntypes):
for j in range(ntypes):
epsilon_ij = sqrt(epsilon[i]*epsilon[j])
sigma_ij = 0.5 * (sigma[i] + sigma[j])
self.lj3[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,12.0);