Commit 82a82741 authored by peastman's avatar peastman
Browse files

Merge pull request #1076 from swails/tests

Add a set of unit tests for unit handling in the core API.
parents 9b240457 e585fb6e
...@@ -1017,7 +1017,6 @@ if( isAmoeba ): ...@@ -1017,7 +1017,6 @@ if( isAmoeba ):
torsionTorsionUnit = 1.0 torsionTorsionUnit = 1.0
outputString = """ <AmoebaTorsionTorsionForce >""" outputString = """ <AmoebaTorsionTorsionForce >"""
tinkerXmlFile.write( "%s\n" % (outputString ) ) tinkerXmlFile.write( "%s\n" % (outputString ) )
conversion = 41.84/radian
torsionTorsions = forces['tortors'] torsionTorsions = forces['tortors']
for (index, torsionTorsion) in enumerate(torsionTorsions): for (index, torsionTorsion) in enumerate(torsionTorsions):
torInfo = torsionTorsion[0] torInfo = torsionTorsion[0]
......
...@@ -127,7 +127,7 @@ public: ...@@ -127,7 +127,7 @@ public:
* @param particle1 the index of the first particle connected by the angle * @param particle1 the index of the first particle connected by the angle
* @param particle2 the index of the second particle connected by the angle * @param particle2 the index of the second particle connected by the angle
* @param particle3 the index of the third particle connected by the angle * @param particle3 the index of the third particle connected by the angle
* @param length the angle measured in degrees * @param length the equilibrium angle, measured in degrees
* @param quadratic k the quadratic force constant for the angle, measured in kJ/mol/radian^2 * @param quadratic k the quadratic force constant for the angle, measured in kJ/mol/radian^2
* @return the index of the angle that was added * @return the index of the angle that was added
*/ */
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
* @param particle1 the index of the first particle connected by the angle * @param particle1 the index of the first particle connected by the angle
* @param particle2 the index of the second particle connected by the angle * @param particle2 the index of the second particle connected by the angle
* @param particle3 the index of the third particle connected by the angle * @param particle3 the index of the third particle connected by the angle
* @param length the equilibrium angle, measured in degress * @param length the equilibrium angle, measured in degrees
* @param quadratic k the quadratic force constant for the angle, measured in kJ/mol/radian^2 * @param quadratic k the quadratic force constant for the angle, measured in kJ/mol/radian^2
*/ */
void getAngleParameters(int index, int& particle1, int& particle2, int& particle3, double& length, double& quadraticK) const; void getAngleParameters(int index, int& particle1, int& particle2, int& particle3, double& length, double& quadraticK) const;
......
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
* *
* @return global cubicK term * @return global cubicK term
*/ */
double getAmoebaGlobalOutOfPlaneBendCubic(void) const; double getAmoebaGlobalOutOfPlaneBendCubic() const;
/** /**
* Set the global cubic term * Set the global cubic term
...@@ -88,7 +88,7 @@ public: ...@@ -88,7 +88,7 @@ public:
* *
* @return global quartic term * @return global quartic term
*/ */
double getAmoebaGlobalOutOfPlaneBendQuartic(void) const; double getAmoebaGlobalOutOfPlaneBendQuartic() const;
/** /**
* Set the global pentic term * Set the global pentic term
...@@ -102,7 +102,7 @@ public: ...@@ -102,7 +102,7 @@ public:
* *
* @return global penticK term * @return global penticK term
*/ */
double getAmoebaGlobalOutOfPlaneBendPentic(void) const; double getAmoebaGlobalOutOfPlaneBendPentic() const;
/** /**
* Set the global sextic term * Set the global sextic term
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
* *
* @return global sexticK term * @return global sexticK term
*/ */
double getAmoebaGlobalOutOfPlaneBendSextic(void) const; double getAmoebaGlobalOutOfPlaneBendSextic() const;
/** /**
* Add an out-of-plane bend term to the force field. * Add an out-of-plane bend term to the force field.
......
...@@ -10,6 +10,7 @@ import getopt ...@@ -10,6 +10,7 @@ import getopt
import re import re
import xml.etree.ElementTree as etree import xml.etree.ElementTree as etree
from distutils.version import LooseVersion from distutils.version import LooseVersion
import copy
try: try:
from html.parser import HTMLParser from html.parser import HTMLParser
...@@ -20,7 +21,6 @@ except ImportError: ...@@ -20,7 +21,6 @@ except ImportError:
INDENT = " " INDENT = " "
docTags = {'emphasis':'i', 'bold':'b', 'itemizedlist':'ul', 'listitem':'li', 'preformatted':'pre', 'computeroutput':'tt', 'subscript':'sub'} docTags = {'emphasis':'i', 'bold':'b', 'itemizedlist':'ul', 'listitem':'li', 'preformatted':'pre', 'computeroutput':'tt', 'subscript':'sub'}
def striphtmltags(s): def striphtmltags(s):
"""Strip a couple html tags used inside docstrings in the C++ source """Strip a couple html tags used inside docstrings in the C++ source
to produce something more easily read as plain text. to produce something more easily read as plain text.
...@@ -157,7 +157,7 @@ class SwigInputBuilder: ...@@ -157,7 +157,7 @@ class SwigInputBuilder:
skipAdditionalMethods=[], skipAdditionalMethods=[],
SWIG_VERSION='3.0.2'): SWIG_VERSION='3.0.2'):
self.nodeByID={} self.nodeByID={}
self.SWIG_COMPACT_ARGUMENTS = LooseVersion(SWIG_VERSION) < LooseVersion('3.0.6') self.SWIG_COMPACT_ARGUMENTS = LooseVersion(SWIG_VERSION) < LooseVersion('3.0.5')
self.configModule = __import__(os.path.splitext(configFilename)[0]) self.configModule = __import__(os.path.splitext(configFilename)[0])
...@@ -477,7 +477,7 @@ class SwigInputBuilder: ...@@ -477,7 +477,7 @@ class SwigInputBuilder:
valueUnits=[None, ()] valueUnits=[None, ()]
index=0 index=0
if valueUnits[0]: if valueUnits[0] is not None:
sys.stdout.write("%s.%s() returns %s\n" % sys.stdout.write("%s.%s() returns %s\n" %
(shortClassName, methName, valueUnits[0])) (shortClassName, methName, valueUnits[0]))
if len(valueUnits[1])>0: if len(valueUnits[1])>0:
...@@ -491,7 +491,7 @@ class SwigInputBuilder: ...@@ -491,7 +491,7 @@ class SwigInputBuilder:
% (addText, INDENT, valueUnits[0]) % (addText, INDENT, valueUnits[0])
for vUnit in valueUnits[1]: for vUnit in valueUnits[1]:
if vUnit!=None: if vUnit is not None:
addText = "%s%sval[%s]=unit.Quantity(val[%s], %s)\n" \ addText = "%s%sval[%s]=unit.Quantity(val[%s], %s)\n" \
% (addText, INDENT, index, index, vUnit) % (addText, INDENT, index, index, vUnit)
index+=1 index+=1
......
...@@ -216,22 +216,22 @@ UNITS = { ...@@ -216,22 +216,22 @@ UNITS = {
("AmoebaGeneralizedKirkwoodForce", "getDielectricOffset") : ( 'unit.nanometer', ()), ("AmoebaGeneralizedKirkwoodForce", "getDielectricOffset") : ( 'unit.nanometer', ()),
("AmoebaGeneralizedKirkwoodForce", "getIncludeCavityTerm") : ( None,()), ("AmoebaGeneralizedKirkwoodForce", "getIncludeCavityTerm") : ( None,()),
("AmoebaGeneralizedKirkwoodForce", "getProbeRadius") : ( 'unit.nanometer', ()), ("AmoebaGeneralizedKirkwoodForce", "getProbeRadius") : ( 'unit.nanometer', ()),
("AmoebaGeneralizedKirkwoodForce", "getSurfaceAreaFactor") : ( '(unit.nanometer*unit.nanometer)/unit.kilojoule_per_mole',()), ("AmoebaGeneralizedKirkwoodForce", "getSurfaceAreaFactor") : ( 'unit.kilojoule_per_mole/(unit.nanometer*unit.nanometer)',()),
("AmoebaAngleForce", "getAmoebaGlobalAngleCubic") : ( None,()), ("AmoebaAngleForce", "getAmoebaGlobalAngleCubic") : ( '1/unit.radian',()),
("AmoebaAngleForce", "getAmoebaGlobalAngleQuartic") : ( None,()), ("AmoebaAngleForce", "getAmoebaGlobalAngleQuartic") : ( '1/unit.radian**2',()),
("AmoebaAngleForce", "getAmoebaGlobalAnglePentic") : ( None,()), ("AmoebaAngleForce", "getAmoebaGlobalAnglePentic") : ( '1/unit.radian**3',()),
("AmoebaAngleForce", "getAmoebaGlobalAngleSextic") : ( None,()), ("AmoebaAngleForce", "getAmoebaGlobalAngleSextic") : ( '1/unit.radian**4',()),
("AmoebaAngleForce", "getAngleParameters") : ( None, (None, None, None, 'unit.radian', 'unit.kilojoule_per_mole/(unit.radian*unit.radian)')), ("AmoebaAngleForce", "getAngleParameters") : ( None, (None, None, None, 'unit.degree', 'unit.kilojoule_per_mole/(unit.radian*unit.radian)')),
("AmoebaBondForce", "getAmoebaGlobalBondCubic") : ( None,()), ("AmoebaBondForce", "getAmoebaGlobalBondCubic") : ( '1/unit.nanometer',()),
("AmoebaBondForce", "getAmoebaGlobalBondQuartic") : ( None,()), ("AmoebaBondForce", "getAmoebaGlobalBondQuartic") : ( '1/unit.nanometer**2',()),
("AmoebaBondForce", "getBondParameters") : ( None, (None, None, 'unit.nanometer', 'unit.kilojoule_per_mole/(unit.nanometer*unit.nanometer)')), ("AmoebaBondForce", "getBondParameters") : ( None, (None, None, 'unit.nanometer', 'unit.kilojoule_per_mole/(unit.nanometer*unit.nanometer)')),
("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAngleCubic") : ( None,()), ("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAngleCubic") : ( '1/unit.radian',()),
("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAngleQuartic") : ( None,()), ("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAngleQuartic") : ( '1/unit.radian**2',()),
("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAnglePentic") : ( None,()), ("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAnglePentic") : ( '1/unit.radian**3',()),
("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAngleSextic") : ( None,()), ("AmoebaInPlaneAngleForce", "getAmoebaGlobalInPlaneAngleSextic") : ( '1/unit.radian**4',()),
("AmoebaInPlaneAngleForce", "getAngleParameters") : ( None, (None, None, None, None, 'unit.radian', 'unit.kilojoule_per_mole/(unit.radian*unit.radian)')), ("AmoebaInPlaneAngleForce", "getAngleParameters") : ( None, (None, None, None, None, 'unit.radian', 'unit.kilojoule_per_mole/(unit.radian*unit.radian)')),
("AmoebaMultipoleForce", "getNumMultipoles") : ( None,()), ("AmoebaMultipoleForce", "getNumMultipoles") : ( None,()),
...@@ -256,7 +256,9 @@ UNITS = { ...@@ -256,7 +256,9 @@ UNITS = {
# void getCovalentMap(int index, CovalentType typeId, std::vector<int>& covalentAtoms ) # void getCovalentMap(int index, CovalentType typeId, std::vector<int>& covalentAtoms )
# void getCovalentMaps(int index, std::vector < std::vector<int> >& covalentLists ) # void getCovalentMaps(int index, std::vector < std::vector<int> >& covalentLists )
("AmoebaMultipoleForce", "getMultipoleParameters") : ( None, ()), ("AmoebaMultipoleForce", "getMultipoleParameters") : ( None, ('unit.elementary_charge', 'unit.elementary_charge/unit.nanometer',
'unit.elementary_charge/unit.nanometer**2', None, None, None, None, None, None,
'unit.nanometer**3')),
("AmoebaMultipoleForce", "getCovalentMap") : ( None, ()), ("AmoebaMultipoleForce", "getCovalentMap") : ( None, ()),
("AmoebaMultipoleForce", "getCovalentMaps") : ( None, ()), ("AmoebaMultipoleForce", "getCovalentMaps") : ( None, ()),
("AmoebaMultipoleForce", "getScalingDistanceCutoff") : ( 'unit.nanometer', ()), ("AmoebaMultipoleForce", "getScalingDistanceCutoff") : ( 'unit.nanometer', ()),
...@@ -268,17 +270,17 @@ UNITS = { ...@@ -268,17 +270,17 @@ UNITS = {
("AmoebaMultipoleForce", "getSystemMultipoleMoments") : ( None, ()), ("AmoebaMultipoleForce", "getSystemMultipoleMoments") : ( None, ()),
("AmoebaOutOfPlaneBendForce", "getNumOutOfPlaneBends") : ( None, ()), ("AmoebaOutOfPlaneBendForce", "getNumOutOfPlaneBends") : ( None, ()),
("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendCubic") : ( None,()), ("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendCubic") : ( '1/unit.radian',()),
("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendQuartic") : ( None,()), ("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendQuartic") : ( '1/unit.radian**2',()),
("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendPentic") : ( None,()), ("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendPentic") : ( '1/unit.radian**3',()),
("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendSextic") : ( None,()), ("AmoebaOutOfPlaneBendForce", "getAmoebaGlobalOutOfPlaneBendSextic") : ( '1/unit.radian**4',()),
("AmoebaOutOfPlaneBendForce", "getOutOfPlaneBendParameters") : ( None, (None, None, None, None, 'unit.kilojoule_per_mole')), ("AmoebaOutOfPlaneBendForce", "getOutOfPlaneBendParameters") : ( None, (None, None, None, None, 'unit.kilojoule_per_mole/unit.radians**2')),
("AmoebaPiTorsionForce", "getNumPiTorsions") : ( None, ()), ("AmoebaPiTorsionForce", "getNumPiTorsions") : ( None, ()),
("AmoebaPiTorsionForce", "getPiTorsionParameters") : ( None, (None, None, None, None, None, None, 'unit.kilojoule_per_mole')), ("AmoebaPiTorsionForce", "getPiTorsionParameters") : ( None, (None, None, None, None, None, None, 'unit.kilojoule_per_mole')),
("AmoebaStretchBendForce", "getNumStretchBends") : ( None, ()), ("AmoebaStretchBendForce", "getNumStretchBends") : ( None, ()),
("AmoebaStretchBendForce", "getStretchBendParameters") : ( None, (None, None, None, 'unit.nanometer', 'unit.nanometer', 'unit.radian', 'unit.kilojoule_per_mole/unit.nanometer/unit.degree', 'unit.kilojoule_per_mole/unit.nanometer/unit.degree')), ("AmoebaStretchBendForce", "getStretchBendParameters") : ( None, (None, None, None, 'unit.nanometer', 'unit.nanometer', 'unit.radian', 'unit.kilojoule_per_mole/unit.nanometer/unit.radian', 'unit.kilojoule_per_mole/unit.nanometer/unit.radian')),
("AmoebaTorsionTorsionForce", "getNumTorsionTorsions") : ( None, ()), ("AmoebaTorsionTorsionForce", "getNumTorsionTorsions") : ( None, ()),
("AmoebaTorsionTorsionForce", "getNumTorsionTorsionGrids") : ( None, ()), ("AmoebaTorsionTorsionForce", "getNumTorsionTorsionGrids") : ( None, ()),
...@@ -376,6 +378,9 @@ UNITS = { ...@@ -376,6 +378,9 @@ UNITS = {
("CustomTorsionForce", "getPerTorsionParameterName") : (None, ()), ("CustomTorsionForce", "getPerTorsionParameterName") : (None, ()),
("CustomTorsionForce", "getGlobalParameterName") : (None, ()), ("CustomTorsionForce", "getGlobalParameterName") : (None, ()),
("CustomTorsionForce", "getTorsionParameters") : (None, ()), ("CustomTorsionForce", "getTorsionParameters") : (None, ()),
("DrudeForce", "getParticleParameters") : (None, (None, None, None, None, None, 'unit.elementary_charge', 'unit.nanometer**3', None, None)),
("DrudeForce", "getNumScreenedPairs") : (None, ()),
("DrudeForce", "getScreenedPairParameters") : (None, ()),
("GBSAOBCForce", "getParticleParameters") ("GBSAOBCForce", "getParticleParameters")
: (None, ('unit.elementary_charge', : (None, ('unit.elementary_charge',
'unit.nanometer', None)), 'unit.nanometer', None)),
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
try: try:
import numpy import numpy
except: except ImportError:
pass numpy = None
import copy
import sys import sys
import math import math
RMIN_PER_SIGMA=math.pow(2, 1/6.0) RMIN_PER_SIGMA=math.pow(2, 1/6.0)
...@@ -224,3 +225,70 @@ class State(_object): ...@@ -224,3 +225,70 @@ class State(_object):
self._system = args[0] self._system = args[0]
self._integrator = args[1] self._integrator = args[1]
%} %}
%pythonprepend OpenMM::AmoebaAngleForce::addAngle %{
try:
length = args[3]
if isinstance(args, tuple):
args = list(args)
except (NameError, UnboundLocalError):
if unit.is_quantity(length):
length = length.value_in_unit(unit.degree)
else:
if unit.is_quantity(length):
args[3] = length.value_in_unit(unit.degree)
%}
%pythonprepend OpenMM::AmoebaAngleForce::setAngleParameters %{
try:
length = args[4]
if isinstance(args, tuple):
args = list(args)
except (NameError, UnboundLocalError):
if unit.is_quantity(length):
length = length.value_in_unit(unit.degree)
else:
if unit.is_quantity(length):
args[4] = length.value_in_unit(unit.degree)
%}
%pythonprepend OpenMM::AmoebaTorsionTorsionForce::setTorsionTorsionGrid %{
def deunitize_grid(grid):
if isinstance(grid, tuple):
grid = list(grid)
for i, row in enumerate(grid):
if isinstance(row, tuple):
row = list(row)
grid[i] = row
for i, column in enumerate(row):
if isinstance(column, tuple):
column = list(column)
row[i] = column
# Data is angle, angle, energy, de/dang1, de/dang2, d^2e/dang1dang2
if unit.is_quantity(column[0]):
column[0] = column[0].value_in_unit(unit.degree)
if unit.is_quantity(column[1]):
column[1] = column[1].value_in_unit(unit.degree)
if unit.is_quantity(column[2]):
column[2] = column[2].value_in_unit(unit.kilojoule_per_mole)
if len(column) > 3 and unit.is_quantity(column[3]):
column[3] = column[3].value_in_unit(unit.kilojoule_per_mole/unit.radians)
if len(column) > 4 and unit.is_quantity(column[4]):
column[4] = column[4].value_in_unit(unit.kilojoule_per_mole/unit.radians)
if len(column) > 5 and unit.is_quantity(column[5]):
column[5] = column[5].value_in_unit(unit.kilojoule_per_mole/unit.radians**2)
return grid
try:
grid = copy.deepcopy(args[1])
if isinstance(args, tuple):
args = list(args)
except (NameError, UnboundLocalError):
try:
# Support numpy arrays
grid = grid.tolist()
except AttributeError:
grid = copy.deepcopy(grid)
grid = deunitize_grid(grid)
else:
args[1] = deunitize_grid(grid)
%}
This diff is collapsed.
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