Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ctk3b committed Jun 20, 2014
1 parent 8cfe79e commit 00ef3cd
Show file tree
Hide file tree
Showing 98 changed files with 622 additions and 742 deletions.
5 changes: 3 additions & 2 deletions intermol/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

class Atom(object):
__slots__ = ['index', 'name', 'residue_index', 'residue_name',
'_position', '_velocity', '_force', '_atomtype', 'bondtype', 'Z',
'_position', '_velocity', '_force', '_atomtype', 'bondtype',
'atomic_number',
'cgnr', '_mass', '_charge', 'ptype', '_sigma', '_epsilon']
def __init__(self, index, name=None, residue_index=-1, residue_name=None):
"""Create an Atom object
Expand Down Expand Up @@ -39,7 +40,7 @@ def __init__(self, index, name=None, residue_index=-1, residue_name=None):
# These are added after data is read in and come from [ atomtypes ]
self._atomtype = dict()
self.bondtype = None
self.Z = None
self.atomic_number = None
self.cgnr = None
self._mass = dict()
self._charge = dict()
Expand Down
64 changes: 32 additions & 32 deletions intermol/desmond_extension/desmond_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def load_ffio_block(self, lines, moleculeName, start, end, sysDirective, sysDire
vdwtypercol = 0

#DEFAULT VALUES WHEN CONVERTING TO GROMACS
System._sys._nbFunc = 1
System._sys._genpairs = 'yes'
System._sys.nonbonded_function = 1
System._sys.genpairs = 'yes'

logger.debug('Parsing [ molecule %s]'%(moleculeName))
logger.debug('Parsing [ ffio]')
Expand All @@ -197,11 +197,11 @@ def load_ffio_block(self, lines, moleculeName, start, end, sysDirective, sysDire
combrule = lines[i+combrcol]
if re.search("GEOMETRIC", combrule, re.IGNORECASE):
if re.search("ARITHMETIC", combrule, re.IGNORECASE):
System._sys._combinationRule = 2
System._sys.combination_rule = 2
else:
System._sys._combinationRule = 3
System._sys.combination_rule = 3
elif re.search("C6C12", combrule, re.IGNORECASE):
System._sys._combinationRule = 1
System._sys.combination_rule = 1
if (vdwtypercol > 0):
vdwrule = lines[i+vdwtypercol]
# MISSING: need to identify vdw rule here -- currently assuming LJ12_6_sig_epsilon!
Expand Down Expand Up @@ -279,21 +279,21 @@ def load_ffio_block(self, lines, moleculeName, start, end, sysDirective, sysDire

currentMolecule.addAtom(atom)
if not System._sys._atomtypes.get(AbstractAtomType(atom.getAtomType().get(0))): #if atomtype not in System, add it
if System._sys._combinationRule == 1:
if System._sys.combination_rule == 1:
sigma = (etemp/stemp)**(1/6)
epsilon = (stemp)/(4*sigma**6)
newAtomType = AtomCR1Type(split[ivdwtypes], #atomtype/name
split[ivdwtype], #bondtype
-1, #Z
-1, #atomic_number
float(split[imass]) * units.amu, #mass
float(split[icharge]) * units.elementary_charge, #charge--NEED TO CONVERT TO ACTUAL UNIT
'A', #pcharge...saw this in top--NEED TO CONVERT TO ACTUAL UNITS
sigma * units.kilocalorie_per_mole * angstroms**(6),
epsilon * units.kilocalorie_per_mole * unit.angstro,s**(12))
elif (System._sys._combinationRule == 2) or (System._sys._combinationRule == 3):
elif (System._sys.combination_rule == 2) or (System._sys.combination_rule == 3):
newAtomType = AtomCR23Type(split[ivdwtype], #atomtype/name
split[ivdwtype], #bondtype
-1, #Z
-1, #atomic_number
float(split[imass]) * units.amu, #mass--NEED TO CONVERT TO ACTUAL UNITS
float(split[icharge]) * units.elementary_charge, #charge--NEED TO CONVERT TO ACTUAL UNIT
'A', #pcharge...saw this in top--NEED TO CONVERT TO ACTUAL UNITS
Expand All @@ -311,7 +311,7 @@ def load_ffio_block(self, lines, moleculeName, start, end, sysDirective, sysDire
# now construct an atomlist with all the atoms
index = 0
for molecule in NewMolecules:
System._sys.addMolecule(molecule)
System._sys.add_molecule(molecule)
for atom in molecule._atoms:
# does this need to be a deep copy?
tmpatom = copy.deepcopy(atom)
Expand Down Expand Up @@ -437,18 +437,18 @@ def load_ffio_block(self, lines, moleculeName, start, end, sysDirective, sysDire
raise Exception("ReadError: didn't recognize type %s in line %s", split[3], entry_values[j])

if ljcorr:
if System._sys._ljCorrection:
if System._sys._ljCorrection != ljcorr:
if System._sys.lj_correction:
if System._sys.lj_correction != ljcorr:
raise Exception("ReadError: atoms have different LJ 1-4 correction terms")
else:
System._sys._ljCorrection = ljcorr
System._sys.lj_correction = ljcorr

if coulcorr:
if System._sys._coulombCorrection:
if System._sys._coulombCorrection != coulcorr:
if System._sys.coulomb_correction:
if System._sys.coulomb_correction != coulcorr:
raise Exception("ReadError: atoms have different Coulomb 1-4 correction terms")
else:
System._sys._coulombCorrection = coulcorr
System._sys.coulomb_correction = coulcorr

if newPairForce:
currentMoleculeType.pairForceSet.add(newPairForce)
Expand Down Expand Up @@ -856,7 +856,7 @@ def loadMAtoms(self, lines, start, end, currentMolecule, slength, sysDirective,
atom.residue_index = int(aline[rincol])
atom.residue_name = aline[rncol].strip()
try:
atom.Z = int(aline[azcol])
atom.atomic_number = int(aline[azcol])
except Exception as e:
logger.exception(e) # EDZ: just pass statement before, now exception is recorded, but supressed
atom.setPosition(float(aline[xcol]) * units.angstroms,
Expand Down Expand Up @@ -900,7 +900,7 @@ def loadMAtoms(self, lines, start, end, currentMolecule, slength, sysDirective,
return molecules


def loadBoxVector(self, lines, start, end, verbose = False):
def load_box_vector(self, lines, start, end, verbose = False):

# Loading Box Vector
# Create a Box Vector to load into the System
Expand All @@ -926,9 +926,9 @@ def loadBoxVector(self, lines, start, end, verbose = False):
v[j,k] = float(re.sub(r'\s', '', lines[i])) * units.angstrom
nvec += 1

System._sys.setBoxVector(v)
System._sys.box_vector = v

def readFile(self, filename, verbose=True):
def read_file(self, filename, verbose=True):

# Load in data from file

Expand Down Expand Up @@ -1034,10 +1034,10 @@ def readFile(self, filename, verbose=True):
#LOAD RAW BOX VECTOR-Same throughout cms

logger.debug("Reading Box Vector...")
self.loadBoxVector(lines, self.fblockpos[0], self.a_blockpos[0], verbose)
self.load_box_vector(lines, self.fblockpos[0], self.a_blockpos[0], verbose)

#
def writeFile(self, filename, verbose=True):
def write_file(self, filename, verbose=True):

# Write this topology to file
# Write out this topology in Desmond format
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def writeFile(self, filename, verbose=True):
lines.append(' :::\n')

#box vector
bv = System._sys.getBoxVector()
bv = System._sys.box_vector
lines.append(' "full system"\n')
for bi in range(3):
for bj in range(3):
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def writeFile(self, filename, verbose=True):
float(atom._position[2].in_units_of(units.angstroms)._value),
atom.residue_index,
'"%s"'%atom.residue_name,
atom.Z,
atom.atomic_number,
'"%s"'%atom.name,
float(atom._velocity[0].in_units_of(units.angstroms/units.picoseconds)._value),
float(atom._velocity[1].in_units_of(units.angstroms/units.picoseconds)._value),
Expand Down Expand Up @@ -1269,7 +1269,7 @@ def writeFile(self, filename, verbose=True):
float(atom._position[2].in_units_of(units.angstroms)._value),
atom.residue_index,
'"%s"'%atom.residue_name,
atom.Z,
atom.atomic_number,
'"%s"'%atom.name,
float(atom._velocity[0].in_units_of(units.angstroms/units.picoseconds)._value),
float(atom._velocity[1].in_units_of(units.angstroms/units.picoseconds)._value),
Expand Down Expand Up @@ -1338,11 +1338,11 @@ def writeFile(self, filename, verbose=True):
lines.append(' %s\n' % moleculetype.name)

#Adding Combination Rule
if System._sys._combinationRule == 1:
if System._sys.combination_rule == 1:
lines.append(' C612\n') # this may not exist in DESMOND, or if so, need to be corrected
elif System._sys._combinationRule == 2:
elif System._sys.combination_rule == 2:
lines.append(' ARITHMETIC/GEOMETRIC\n')
elif System._sys._combinationRule == 3:
elif System._sys.combination_rule == 3:
lines.append(' GEOMETRIC\n')


Expand All @@ -1357,7 +1357,7 @@ def writeFile(self, filename, verbose=True):
ep = None
stemp = None
etemp = None
combRule = System._sys._combinationRule
combRule = System._sys.combination_rule
for atom in molecule._atoms:
i+=1
if atom.residue_index:
Expand Down Expand Up @@ -1687,10 +1687,10 @@ def writeFile(self, filename, verbose=True):
i += 2
if isinstance(pair,LJ1PairCR23):
dlines.append(' %d %d %d %s %10.8f %10.8f\n' % (i-1, pair.atom1, pair.atom2, 'LJ12_6_sig_epsilon', pair.V.in_units_of(units.angstroms)._value,pair.W.in_units_of(units.kilocalorie_per_mole)._value))
dlines.append(' %d %d %d %s %10.8f <>\n' % (i, pair.atom1, pair.atom2, "Coulomb", System._sys._coulombCorrection))
dlines.append(' %d %d %d %s %10.8f <>\n' % (i, pair.atom1, pair.atom2, "Coulomb", System._sys.coulomb_correction))
elif re.match("Both", pair.type):
dlines.append(' %d %d %d %s %10.8f <>\n' % (i-1, pair.atom1, pair.atom2, "LJ", System._sys._ljCorrection))
dlines.append(' %d %d %d %s %10.8f <>\n' % (i, pair.atom1, pair.atom2, "Coulomb", System._sys._coulombCorrection))
dlines.append(' %d %d %d %s %10.8f <>\n' % (i-1, pair.atom1, pair.atom2, "LJ", System._sys.lj_correction))
dlines.append(' %d %d %d %s %10.8f <>\n' % (i, pair.atom1, pair.atom2, "Coulomb", System._sys.coulomb_correction))
else:
raise Exception("Unknown pair type!")

Expand Down
8 changes: 5 additions & 3 deletions intermol/forces/LJ1_pair_CR1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

class LJ1PairCR1(AbstractPair):
__slots__ = ['V', 'W']
@accepts_compatible_units(None, None, units.kilojoules_per_mole * units.nanometers**(6), units.kilojoules_per_mole * units.nanometers**(12))
def __init__(self, atom1, atom2, V = None, W = None):
@accepts_compatible_units(None, None,
units.kilojoules_per_mole * units.nanometers**(6),
units.kilojoules_per_mole * units.nanometers**(12))
def __init__(self, atom1, atom2, V=None, W=None):
"""
"""
AbstractPair.__init__(self, atom1, atom2)
self.V = V
self.W = W

def get_parameters(self):
return (self.atom1, self.atom2, self.V, self.W)
return (self.atom1, self.atom2, self.V, self.W)

def __repr__(self):
return str(self.atom1) +' '+ str(self.atom2) +' '+ str(self.V) +' '+ str(self.W)
Expand Down
4 changes: 3 additions & 1 deletion intermol/forces/LJ1_pair_CR23.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

class LJ1PairCR23(AbstractPair):
__slots__ = ['V', 'W']
@accepts_compatible_units(None, None, units.nanometers, units.kilojoules_per_mole)
@accepts_compatible_units(None, None,
units.nanometers,
units.kilojoules_per_mole)
def __init__(self, atom1, atom2, V, W):
"""
"""
Expand Down
17 changes: 11 additions & 6 deletions intermol/forces/LJ2_pair_CR1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from abstract_pair import *

class LJ2PairCR1(AbstractPair):

__slots__ = ['fudgeQQ', 'qi', 'qj', 'V', 'W']
@accepts_compatible_units(None, None, None, units.elementary_charge, units.elementary_charge, units.kilojoules_per_mole * units.nanometers**(6), units.kilojoules_per_mole * units.nanometers**(12))

@accepts_compatible_units(None, None, None,
units.elementary_charge, units.elementary_charge,
units.kilojoules_per_mole * units.nanometers**(6),
units.kilojoules_per_mole * units.nanometers**(12))
def __init__(self, atom1, atom2, fudgeQQ, qi, qj, V, W):
"""
"""
Expand All @@ -13,13 +16,15 @@ def __init__(self, atom1, atom2, fudgeQQ, qi, qj, V, W):
self.qi = qi
self.qj = qj
self.V = V
self.W = W
self.W = W

def get_parameters(self):
return (self.atom1, self.atom2, self.fudgeQQ, self.qi, self.qj, self.V, self.W)
return (self.atom1, self.atom2, self.fudgeQQ, self.qi, self.qj, self.V, self.W)

def __repr__(self):
return str(self.atom1) +' '+ str(self.atom2) +' '+ str(self.fudgeQQ) +' '+ str(self.qi)+' '+ str(self.qj) +' '+str(self.V)+' '+str(self.W)
return "{0} {1}: {2} {3} {4} {5}".format(self.atom1, self.atom2, self.atom3,
self.fudgeQQ, self.qi, self.qj, self.V, self.W)

def __str__(self):
return str(self.atom1) +' '+ str(self.atom2) +' '+ str(self.fudgeQQ) +' '+ str(self.qi)+' '+ str(self.qj) +' '+str(self.V)+' '+str(self.W)
return "{0} {1}: {2} {3} {4} {5}".format(self.atom1, self.atom2, self.atom3,
self.fudgeQQ, self.qi, self.qj, self.V, self.W)
12 changes: 7 additions & 5 deletions intermol/forces/LJ2_pair_CR23.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from abstract_pair import *

class LJ2PairCR23(AbstractPair):

__slots__ = ['fudgeQQ', 'qi', 'qj', 'V', 'W']
@accepts_compatible_units(None, None, None, units.elementary_charge, units.elementary_charge, units.nanometers, units.kilojoules_per_mole)

@accepts_compatible_units(None, None, None,
units.elementary_charge, units.elementary_charge,
units.nanometers, units.kilojoules_per_mole)
def __init__(self, atom1, atom2, fudgeQQ, qi, qj, V, W):
"""
"""
Expand All @@ -13,13 +15,13 @@ def __init__(self, atom1, atom2, fudgeQQ, qi, qj, V, W):
self.qi = qi
self.qj = qj
self.V = V
self.W = W
self.W = W

def get_parameters(self):
return (self.atom1, self.atom2, self.fudgeQQ, self.qi, self.qj, self.V, self.W)

def __repr__(self):
return str(self.atom1) +' '+ str(self.atom2) +' '+ str(self.fudgeQQ) +' '+ str(self.qi)+' '+ str(self.qj) +' '+str(self.V)+' '+str(self.W)

def __str__(self):
return str(self.atom1) +' '+ str(self.atom2) +' '+ str(self.fudgeQQ) +' '+ str(self.qi)+' '+ str(self.qj) +' '+str(self.V)+' '+str(self.W)
return str(self.atom1) +' '+ str(self.atom2) +' '+ str(self.fudgeQQ) +' '+ str(self.qi)+' '+ str(self.qj) +' '+str(self.V)+' '+str(self.W)
7 changes: 5 additions & 2 deletions intermol/forces/LJ_nonbonded_pair_CR1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from abstract_pair import *

class LJNBPairCR1(AbstractPair):

__slots__ = ['fudgeQQ', 'qi', 'qj', 'V', 'W']
@accepts_compatible_units(None, None, units.elementary_charge, units.elementary_charge, units.kilojoules_per_mole * units.nanometers**(6), units.kilojoules_per_mole * units.nanometers**(12))

@accepts_compatible_units(None, None,
units.elementary_charge, units.elementary_charge,
units.kilojoules_per_mole * units.nanometers**(6),
units.kilojoules_per_mole * units.nanometers**(12))
def __init__(self, atom1, atom2, qi, qj, V, W):
"""
"""
Expand Down
7 changes: 4 additions & 3 deletions intermol/forces/LJ_nonbonded_pair_CR23.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from intermol.decorators import *
from abstract_pair import *


class LJNBPairCR23(AbstractPair):

__slots__ = ['fudgeQQ', 'qi', 'qj', 'V', 'W']
@accepts_compatible_units(None, None, units.elementary_charge, units.elementary_charge, units.nanometers, units.kilojoules_per_mole)

@accepts_compatible_units(None, None,
units.elementary_charge, units.elementary_charge,
units.nanometers, units.kilojoules_per_mole)
def __init__(self, atom1, atom2, qi, qj, V, W):
"""
"""
Expand Down
Loading

0 comments on commit 00ef3cd

Please sign in to comment.