a bunch refactoring changes in the python pair style and the examples

- make all python potential classes derived from LAMMPSPairPotential
  which contains shared functionality. We currently don't check
  for supported atom types. may want to add that again later.
- keep track of skipped atom types in the C++ code.
- add test against units setting. must set self.units='...' in constructor
- make compute_force method consistent with Pair::single() in LAMMPS and return force/r instead of force.
- rename potentials.py to py_pot.py
- update test runs. some small tweaks.
This commit is contained in:
Axel Kohlmeyer
2017-05-17 20:55:48 -04:00
parent 1d48f287f0
commit 67962b15fc
18 changed files with 521 additions and 316 deletions

View File

@ -1,73 +1,65 @@
from __future__ import print_function
class LJCutMelt(object):
class LAMMPSPairPotential(object):
def __init__(self):
self.pmap=dict()
# set coeffs: eps, sig, 48*eps*sig**12, 24*eps*sig**6,
# 4*eps*sig**12, 4*eps*sig**6
self.coeff = {'lj' : {'lj' : (1.0,1.0,48.0,24.0,4.0,4.0),
'NULL': (0.0,1.0, 0.0, 0.0,0.0,0.0)},
'NULL': {'lj' : (0.0,1.0, 0.0, 0.0,0.0,0.0),
'NULL': (0.0,1.0, 0.0, 0.0,0.0,0.0)}}
self.units='lj'
def map_coeff(self,name,ltype):
self.pmap[ltype]=name
def check_units(self,units):
if (units != self.units):
raise Exception("Conflicting units: %s vs. %s" % (self.units,units))
def map_coeff(self,name,type):
if name in self.coeff:
self.pmap[type] = name
else:
raise Exception("cannot match atom type %s" % name)
class LJCutMelt(LAMMPSPairPotential):
def __init__(self):
super(LJCutMelt,self).__init__()
# set coeffs: 48*eps*sig**12, 24*eps*sig**6,
# 4*eps*sig**12, 4*eps*sig**6
self.units = 'lj'
self.coeff = {'lj' : {'lj' : (48.0,24.0,4.0,4.0)}}
def compute_force(self,rsq,itype,jtype):
coeff = self.coeff[self.pmap[itype]][self.pmap[jtype]]
r2inv = 1.0/rsq
r6inv = r2inv*r2inv*r2inv
lj1 = coeff[2]
lj2 = coeff[3]
return (r6inv * (lj1*r6inv - lj2))
lj1 = coeff[0]
lj2 = coeff[1]
return (r6inv * (lj1*r6inv - lj2))*r2inv
def compute_energy(self,rsq,itype,jtype):
coeff = self.coeff[self.pmap[itype]][self.pmap[jtype]]
r2inv = 1.0/rsq
r6inv = r2inv*r2inv*r2inv
lj3 = coeff[4]
lj4 = coeff[5]
lj3 = coeff[2]
lj4 = coeff[3]
return (r6inv * (lj3*r6inv - lj4))
class LJCutSPCE(object):
class LJCutSPCE(LAMMPSPairPotential):
def __init__(self):
self.pmap=dict()
# SPCE oxygen in real units
super(LJCutSPCE,self).__init__()
self.units='real'
# SPCE oxygen LJ parameters in real units
eps=0.15535
sig=3.166
# set coeffs: eps, sig, 48*eps*sig**12, 24*eps*sig**6,
# 4*eps*sig**12, 4*eps*sig**6
self.coeff = {'OW' : {'OW' : (1.0,1.0,
48.0*eps*sig**12,24.0*eps*sig**6,
4.0*eps*sig**12, 4.0*eps*sig**6),
'NULL': (0.0,1.0, 0.0, 0.0,0.0,0.0)},
'NULL': {'OW' : (0.0,1.0, 0.0, 0.0,0.0,0.0),
'NULL': (0.0,1.0, 0.0, 0.0,0.0,0.0)}}
def map_coeff(self,name,type):
if name in self.coeff:
self.pmap[type] = name
else:
raise Exception("cannot match atom type %s" % name)
self.coeff = {'OW' : {'OW' : (48.0*eps*sig**12,24.0*eps*sig**6,
4.0*eps*sig**12, 4.0*eps*sig**6),
'HW' : (0.0,0.0, 0.0,0.0)},
'HW' : {'OW' : (0.0,0.0, 0.0,0.0),
'HW' : (0.0,0.0, 0.0,0.0)}}
def compute_force(self,rsq,itype,jtype):
coeff = self.coeff[self.pmap[itype]][self.pmap[jtype]]
r2inv = 1.0/rsq
r6inv = r2inv*r2inv*r2inv
lj1 = coeff[2]
lj2 = coeff[3]
return (r6inv * (lj1*r6inv - lj2))
lj1 = coeff[0]
lj2 = coeff[1]
return (r6inv * (lj1*r6inv - lj2))*r2inv
def compute_energy(self,rsq,itype,jtype):
coeff = self.coeff[self.pmap[itype]][self.pmap[jtype]]
r2inv = 1.0/rsq
r6inv = r2inv*r2inv*r2inv
lj3 = coeff[4]
lj4 = coeff[5]
lj3 = coeff[2]
lj4 = coeff[3]
return (r6inv * (lj3*r6inv - lj4))