Unverified Commit 3aa4bb8c authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Code cleanup (#3014)

parent 84a93cf8
......@@ -42,7 +42,6 @@ from openmm.app.internal.charmm.topologyobjects import (
UreyBradleyType, NoUreyBradley)
from openmm.app.internal.charmm.exceptions import CharmmFileError
from openmm.app.element import Element, get_by_symbol
import openmm.unit as u
import warnings
class CharmmParameterSet(object):
......
......@@ -1535,8 +1535,6 @@ class CharmmPsfFile(object):
# Multiply by 0.73 to account for ion exclusions, and multiply
# by 10 to convert to 1/nm from 1/angstroms
implicitSolventKappa *= 7.3
elif implicitSolvent is None:
implicitSolventKappa = 0.0
if u.is_quantity(implicitSolventKappa):
implicitSolventKappa = implicitSolventKappa.value_in_unit(
......
......@@ -32,7 +32,6 @@ from __future__ import absolute_import
__author__ = "Robert McGibbon"
__version__ = "1.0"
import openmm as mm
import os
import os.path
......
......@@ -37,7 +37,7 @@ import os
import time
import struct
import math
from openmm.unit import picoseconds, nanometers, angstroms, is_quantity, norm
from openmm.unit import picoseconds, nanometers, is_quantity, norm
from openmm import Vec3
from openmm.app.internal.unitcell import computeLengthsAndAngles
......
......@@ -32,7 +32,6 @@ from __future__ import absolute_import
__author__ = "Peter Eastman"
__version__ = "1.0"
import openmm as mm
from openmm.app import DCDFile
from openmm.unit import nanometer
......
......@@ -285,7 +285,6 @@ class DesmondDMSFile(object):
gammaN = gamma_conv*(igamma+0.*sgamma)#AGBNP must have only one gamma
alphaN = alpha_conv*(ialpha+salpha)
# delta parameter is ignored
hbtypeN = hbtype
hbwN = en_conv * hbw
gb_p.append([radiusN,chargeN,gammaN,alphaN,hbtype,hbwN,ishydrogenN])
return gb_p
......@@ -831,7 +830,6 @@ class DesmondDMSFile(object):
go.append(True)
if go[fcounter] and (not self._hasTable('posre_harm_param',tables)):
raise IOError('DMS file lacks posre_harm_param table even though posre_harm_term table is present.')
return
if not any(go):
return
......
......@@ -44,7 +44,6 @@ from collections import defaultdict
import openmm as mm
import openmm.unit as unit
from . import element as elem
from openmm.app import Topology
from openmm.app.internal.singleton import Singleton
from openmm.app.internal import compiled
......@@ -589,16 +588,16 @@ class ForceField(object):
self.atomParameters = {}
self.atomTemplateIndexes = {}
self.atoms = list(topology.atoms())
self.excludeAtomWith = [[] for a in self.atoms]
self.excludeAtomWith = [[] for _ in self.atoms]
self.virtualSites = {}
self.bonds = [ForceField._BondData(bond[0].index, bond[1].index) for bond in topology.bonds()]
self.angles = []
self.propers = []
self.impropers = []
self.atomBonds = [[] for a in self.atoms]
self.atomBonds = [[] for _ in self.atoms]
self.isAngleConstrained = []
self.constraints = {}
self.bondedToAtom = [set() for a in self.atoms]
self.bondedToAtom = [set() for _ in self.atoms]
# Record which atoms are bonded to each other atom
......@@ -994,9 +993,7 @@ class ForceField(object):
bondedToAtom[index] is the list of atom indices bonded to atom `index`
"""
bondedToAtom = []
for atom in topology.atoms():
bondedToAtom.append(set())
bondedToAtom = [set() for _ in topology.atoms()]
for (atom1, atom2) in topology.bonds():
bondedToAtom[atom1.index].add(atom2.index)
bondedToAtom[atom2.index].add(atom1.index)
......@@ -2169,7 +2166,7 @@ class PeriodicTorsionGenerator(object):
force.addTorsion(torsion[0], torsion[1], torsion[2], torsion[3], match.periodicity[i], match.phase[i], match.k[i])
impr_cache = {}
for torsion in data.impropers:
t1, t2, t3, t4 = tatoms = [data.atomType[data.atoms[torsion[i]]] for i in range(4)]
t1, t2, t3, t4 = [data.atomType[data.atoms[torsion[i]]] for i in range(4)]
sig = (t1, t2, t3, t4)
match = impr_cache.get(sig, None)
if match == -1:
......@@ -3086,7 +3083,7 @@ class CustomHbondGenerator(object):
type1 = data.atomType[atom]
for i in range(len(self.donorTypes1)):
types1 = self.donorTypes1[i]
if type1 in self.donorTypes1[i]:
if type1 in types1:
force.addDonor(atom.index, -1, -1, self.donorParamValues[i])
elif self.particlesPerDonor == 2:
for bond in data.bonds:
......@@ -3118,7 +3115,7 @@ class CustomHbondGenerator(object):
type1 = data.atomType[atom]
for i in range(len(self.acceptorTypes1)):
types1 = self.acceptorTypes1[i]
if type1 in self.acceptorTypes1[i]:
if type1 in types1:
force.addAcceptor(atom.index, -1, -1, self.acceptorParamValues[i])
elif self.particlesPerAcceptor == 2:
for bond in data.bonds:
......@@ -3685,7 +3682,6 @@ class AmoebaOutOfPlaneBendGenerator(object):
# find atom shared by both bonds making up the angle
middleAtom = -1
for atomIndex in angle:
isMiddle = 0
for bond in data.atomBonds[atomIndex]:
......@@ -3733,8 +3729,6 @@ class AmoebaOutOfPlaneBendGenerator(object):
inPlaneAngles = []
nonInPlaneAngles = []
nonInPlaneAnglesConstrained = []
idealAngles = []*len(data.angles)
for (angle, isConstrained) in zip(data.angles, data.isAngleConstrained):
......@@ -4026,12 +4020,12 @@ class AmoebaPiTorsionGenerator(object):
else:
force = existing[0]
for bond in data.bonds:
for bond1 in data.bonds:
# search for bonds with both atoms in bond having covalency == 3
atom1 = bond.atom1
atom2 = bond.atom2
atom1 = bond1.atom1
atom2 = bond1.atom2
if (len(data.atomBonds[atom1]) == 3 and len(data.atomBonds[atom2]) == 3):
......@@ -4283,9 +4277,9 @@ class AmoebaTorsionTorsionGenerator(object):
ia = bondedAtom2
if (ia != ic and ia != id):
for bondIndex in data.atomBonds[id]:
bondedAtom1 = data.bonds[bondIndex].atom1
bondedAtom2 = data.bonds[bondIndex].atom2
for bondIndex2 in data.atomBonds[id]:
bondedAtom1 = data.bonds[bondIndex2].atom1
bondedAtom2 = data.bonds[bondIndex2].atom2
if (bondedAtom1 != id):
ie = bondedAtom1
else:
......@@ -4409,10 +4403,6 @@ class AmoebaStretchBendGenerator(object):
for angleDict in angleList:
angle = angleDict['angle']
if ('isConstrained' in angleDict):
isConstrained = angleDict['isConstrained']
else:
isConstrained = 0
type1 = data.atomType[data.atoms[angle[0]]]
type2 = data.atomType[data.atoms[angle[1]]]
......@@ -4522,7 +4512,6 @@ class AmoebaVdwGenerator(object):
generator.radiustype != element.attrib['radiustype'] or generator.radiussize != element.attrib['radiussize']:
raise ValueError('Found multiple AmoebaVdwForce tags with different combining rules')
generator.params.parseDefinitions(element)
two_six = 1.122462048309372
#=============================================================================================
......@@ -5096,10 +5085,10 @@ class AmoebaMultipoleGenerator(object):
zaxis = xaxis
xaxis = swapI
else:
for bondedAtomXIndex in bondedAtomIndices:
bondedAtomX1Type = int(data.atomType[data.atoms[bondedAtomXIndex]])
if( bondedAtomX1Type == kx and bondedAtomXIndex != bondedAtomZIndex and bondedAtomXIndex < xaxis ):
xaxis = bondedAtomXIndex
for bondedAtomXIndex2 in bondedAtomIndices:
bondedAtomX1Type = int(data.atomType[data.atoms[bondedAtomXIndex2]])
if( bondedAtomX1Type == kx and bondedAtomXIndex2 != bondedAtomZIndex and bondedAtomXIndex2 < xaxis ):
xaxis = bondedAtomXIndex2
savedMultipoleDict = multipoleDict
hit = 1
......@@ -5160,10 +5149,10 @@ class AmoebaMultipoleGenerator(object):
# select xaxis w/ smallest index
for bondedAtomXIndex in bondedAtom13Indices:
bondedAtomX1Type = int(data.atomType[data.atoms[bondedAtomXIndex]])
if( bondedAtomX1Type == kx and bondedAtomXIndex != bondedAtomZIndex and bondedAtomZIndex in bonded12ParticleSets[bondedAtomXIndex] and bondedAtomXIndex < xaxis ):
xaxis = bondedAtomXIndex
for bondedAtomXIndex2 in bondedAtom13Indices:
bondedAtomX1Type = int(data.atomType[data.atoms[bondedAtomXIndex2]])
if( bondedAtomX1Type == kx and bondedAtomXIndex2 != bondedAtomZIndex and bondedAtomZIndex in bonded12ParticleSets[bondedAtomXIndex2] and bondedAtomXIndex2 < xaxis ):
xaxis = bondedAtomXIndex2
savedMultipoleDict = multipoleDict
hit = 3
......
......@@ -32,12 +32,10 @@ from __future__ import absolute_import
__author__ = "Lee-Ping Wang"
__version__ = "1.0"
import os
import sys
from openmm import Vec3
from openmm.app.internal.unitcell import reducePeriodicBoxVectors
from re import sub, match
from openmm.unit import nanometers, angstroms, Quantity
from openmm.unit import nanometers, Quantity
from . import element as elem
try:
import numpy
......@@ -158,7 +156,6 @@ class GromacsGroFile(object):
pos = [float(line[20+i*digits:20+(i+1)*digits]) for i in range(3)]
xyz.append(Vec3(pos[0], pos[1], pos[2]))
elif _is_gro_box(line) and ln == na + 2:
sline = line.split()
boxes.append(_construct_box_vectors(line))
xyzs.append(xyz*nanometers)
xyz = []
......
......@@ -42,7 +42,7 @@ from __future__ import absolute_import, print_function
import os
import re
from math import ceil, cos, sin, asin, sqrt, pi
from math import ceil, cos, sin, asin, sqrt
import warnings
try:
......@@ -1190,14 +1190,10 @@ class AmberAsciiRestart(object):
coordinates = np.zeros((self.natom, 3), np.float32)
if hasvels:
velocities = np.zeros((self.natom, 3), np.float32)
if hasbox:
boxVectors = np.zeros((3, 3), np.float32)
else:
coordinates = [Vec3(0.0, 0.0, 0.0) for i in range(self.natom)]
if hasvels:
velocities = [Vec3(0.0, 0.0, 0.0) for i in range(self.natom)]
if hasbox:
boxVectors = [[0.0, 0.0, 0.0] for i in range(3)]
# Now it's time to parse. Coordinates first
startline = 2
......
......@@ -21,7 +21,6 @@ simulation with CHARMM; specifically PSF, PAR, RTF, and STR files
field parameter files
"""
__all__ = ['psf', 'parameters']
__authors__ = 'Jason Swails'
__contributors__ = ''
__license__ = 'MIT'
......
......@@ -34,10 +34,9 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import absolute_import
from openmm.app.internal.charmm.exceptions import (
SplitResidueWarning, BondError, ResidueError, CmapError,
BondError, ResidueError, CmapError,
MissingParameter)
import openmm.unit as u
import warnings
TINY = 1e-8
......@@ -160,6 +159,8 @@ class AtomType(object):
def __ne__(self, other):
return not self == other
__hash__ = None
def set_lj_params(self, eps, rmin, eps14=None, rmin14=None):
""" Sets Lennard-Jones parameters on this atom type """
if eps14 is None:
......@@ -229,6 +230,8 @@ class WildCard(AtomType):
def __le__(self, other): return True
def __ge__(self, other): return True
__hash__ = None
WildCard = WildCard() # Turn it into a singleton
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
......@@ -473,6 +476,8 @@ class Residue(object):
def __ne__(self, thing):
return not self.__eq__(thing)
__hash__ = None
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class ResidueList(list):
......@@ -992,6 +997,8 @@ class BondType(object):
def __ne__(self, other):
return not self == other
__hash__ = None
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class AngleType(object):
......@@ -1015,6 +1022,8 @@ class AngleType(object):
def __ne__(self, other):
return not self == other
__hash__ = None
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class UreyBradleyType(BondType):
......@@ -1059,6 +1068,8 @@ class DihedralType(object):
def __ne__(self, other):
return not self == other
__hash__ = None
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class ImproperType(object):
......@@ -1082,6 +1093,8 @@ class ImproperType(object):
def __ne__(self, other):
return not self == other
__hash__ = None
def __repr__(self):
return '<ImproperType; k=%s; phieq=%s>' % (self.k, self.phieq)
......@@ -1120,6 +1133,8 @@ class CmapType(object):
def __ne__(self, other):
return not self == other
__hash__ = None
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Take the CmapGrid class from the Chamber prmtop topology objects
......@@ -1220,6 +1235,8 @@ class _CmapGrid(object):
def __ne__(self, other):
return not self == other
__hash__ = None
def switch_range(self):
"""
Returns a grid object whose range is 0 to 360 degrees in both dimensions
......
......@@ -1020,8 +1020,6 @@ if __name__=='__main__':
# print str(a)
assert str(a).rstrip() == pdb_line.rstrip()
a = Atom("ATOM 2209 CB TYR A 299 6.167 22.607 20.046 1.00 8.12 C")
# misaligned residue name - bad
try:
a = Atom("ATOM 2209 CB TYRA 299 6.167 22.607 20.046 1.00 8.12 C")
......
......@@ -35,12 +35,11 @@ __author__ = "Peter Eastman"
__version__ = "1.0"
from openmm.app import Topology, PDBFile, ForceField
from openmm.app.forcefield import HAngles, AllBonds, CutoffNonPeriodic, CutoffPeriodic, _createResidueSignature, DrudeGenerator
from openmm.app.topology import Residue
from openmm.app.forcefield import AllBonds, CutoffNonPeriodic, CutoffPeriodic, DrudeGenerator
from openmm.app.internal import compiled
from openmm.vec3 import Vec3
from openmm import System, Context, NonbondedForce, CustomNonbondedForce, HarmonicBondForce, HarmonicAngleForce, VerletIntegrator, LangevinIntegrator, LocalEnergyMinimizer
from openmm.unit import nanometer, molar, elementary_charge, amu, gram, liter, degree, sqrt, acos, is_quantity, dot, norm, kilojoules_per_mole
from openmm.unit import nanometer, molar, elementary_charge, degree, acos, is_quantity, dot, norm, kilojoules_per_mole
import openmm.unit as unit
from . import element as elem
import gc
......@@ -478,7 +477,6 @@ class Modeller(object):
vectors = self.topology.getPeriodicBoxVectors().value_in_unit(nanometer)
if box is None:
raise ValueError('Neither the box size, box vectors, nor padding was specified, and the Topology does not define unit cell dimensions')
invBox = Vec3(1.0/box[0], 1.0/box[1], 1.0/box[2])
# Have the ForceField build a System for the solute from which we can determine van der Waals radii.
......@@ -1030,9 +1028,7 @@ class Modeller(object):
"""
# Record which atoms are bonded to each other atom.
bondedToAtom = []
for atom in self.topology.atoms():
bondedToAtom.append(set())
bondedToAtom = [set() for _ in self.topology.atoms()]
for atom1, atom2 in self.topology.bonds():
bondedToAtom[atom1.index].add(atom2.index)
bondedToAtom[atom2.index].add(atom1.index)
......
......@@ -42,7 +42,7 @@ from openmm import Vec3, Platform
from openmm.app.internal.pdbstructure import PdbStructure
from openmm.app.internal.unitcell import computeLengthsAndAngles
from openmm.app import Topology
from openmm.unit import nanometers, angstroms, is_quantity, norm, Quantity, dot
from openmm.unit import nanometers, angstroms, is_quantity, norm, Quantity
from . import element as elem
try:
import numpy
......
......@@ -32,7 +32,6 @@ from __future__ import absolute_import
__author__ = "Peter Eastman"
__version__ = "1.0"
import openmm as mm
from openmm.app import PDBFile, PDBxFile
class PDBReporter(object):
......
......@@ -40,7 +40,7 @@ from datetime import date
from openmm.app.internal.pdbx.reader.PdbxReader import PdbxReader
from openmm.app.internal.unitcell import computePeriodicBoxVectors, computeLengthsAndAngles
from openmm.app import Topology, PDBFile
from openmm.unit import nanometers, angstroms, is_quantity, norm, Quantity, dot
from openmm.unit import nanometers, angstroms, is_quantity, norm, Quantity
from . import element as elem
try:
import numpy
......
......@@ -79,6 +79,15 @@ class BaseDimension(object):
"""
return self._index < other._index
def __le__(self, other):
return self._index <= other._index
def __gt__(self, other):
return self._index > other._index
def __ge__(self, other):
return self._index >= other._index
def __hash__(self):
"""
Needed for using BaseDimensions as hash keys.
......
......@@ -118,7 +118,7 @@ class Quantity(object):
# Is value a container?
is_container = True
try:
i = iter(value)
_ = iter(value)
except TypeError:
is_container = False
if is_container:
......@@ -287,6 +287,8 @@ class Quantity(object):
def __lt__(self, other):
return self._value < (other.value_in_unit(self.unit))
__hash__ = None
_reduce_cache = {}
def reduce_unit(self, guide_unit=None):
......
......@@ -40,7 +40,6 @@ __version__ = "0.5"
import math
import sys
from .mymatrix import MyMatrix, zeros
from .basedimension import BaseDimension
from .baseunit import BaseUnit
from .standard_dimensions import *
......@@ -192,6 +191,15 @@ class Unit(object):
raise TypeError('Unit "%s" is not compatible with Unit "%s".', (self, other))
return self.conversion_factor_to(other) < 1.0
def __le__(self, other):
return self.__lt__(other) or self.__eq__(other)
def __gt__(self, other):
return other.__lt__(self)
def __ge__(self, other):
return other.__lt__(self) or other.__eq__(self)
def __hash__(self):
"""
Compute a hash code for this object.
......
......@@ -129,8 +129,6 @@ def _unit_class_mul(self, other):
return Quantity(value, unit).reduce_unit(self)
else:
# print "scalar * unit"
value = other
unit = self
# Is reduce_unit needed here? I hope not, there is a performance issue...
# return Quantity(other, self).reduce_unit(self)
return Quantity(other, self)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment