mirror of
https://github.com/ParticulateFlow/LPP.git
synced 2025-12-08 06:37:46 +00:00
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:
25
src/chain.py
25
src/chain.py
@ -8,6 +8,12 @@
|
||||
|
||||
# chain tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, division, absolute_import
|
||||
import math
|
||||
from data import data
|
||||
|
||||
oneline = "Create bead-spring chains for LAMMPS input"
|
||||
|
||||
docstr = """
|
||||
@ -52,11 +58,6 @@ c.write("data.file") write out all built chains to LAMMPS data file
|
||||
# xlo,ylo,zlo = -xyz prd / 2
|
||||
# xhi,yhi,zhi = x,y,zprd /2
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import math
|
||||
from data import data
|
||||
|
||||
# Class definition
|
||||
|
||||
class chain:
|
||||
@ -92,12 +93,12 @@ class chain:
|
||||
self.zlo = -self.zprd/2.0
|
||||
self.zhi = self.zprd/2.0
|
||||
|
||||
print "Simulation box: %g by %g by %g" % (self.xprd,self.yprd,self.zprd)
|
||||
print("Simulation box: %g by %g by %g" % (self.xprd,self.yprd,self.zprd))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def build(self,n,nper):
|
||||
for ichain in xrange(n):
|
||||
for ichain in range(n):
|
||||
atoms = []
|
||||
bonds = []
|
||||
id_atom_prev = id_mol_prev = id_bond_prev = 0
|
||||
@ -107,7 +108,7 @@ class chain:
|
||||
if len(self.bonds):
|
||||
id_bond_prev = self.bonds[-1][0]
|
||||
|
||||
for imonomer in xrange(nper):
|
||||
for imonomer in range(nper):
|
||||
if imonomer == 0:
|
||||
x = self.xlo + self.random()*self.xprd
|
||||
y = self.ylo + self.random()*self.yprd
|
||||
@ -146,7 +147,7 @@ class chain:
|
||||
if idmol > nper/2:
|
||||
idmol = nper - imonomer
|
||||
else:
|
||||
raise StandardError,"chain ID is not a valid value"
|
||||
raise Exception("chain ID is not a valid value")
|
||||
|
||||
atoms.append([idatom,idmol,self.mtype,x,y,z,ix,iy,iz])
|
||||
if imonomer:
|
||||
@ -160,8 +161,8 @@ class chain:
|
||||
|
||||
def write(self,file):
|
||||
if len(self.atoms) != self.n:
|
||||
raise StandardError,"%d monomers instead of requested %d" % \
|
||||
(len(self.atoms),self.n)
|
||||
raise Exception("%d monomers instead of requested %d" % \
|
||||
(len(self.atoms),self.n))
|
||||
|
||||
list = [atom[2] for atom in self.atoms]
|
||||
atypes = max(list)
|
||||
@ -229,7 +230,7 @@ class chain:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user