Commit df2b723d authored by leeping's avatar leeping
Browse files

Merge branch 'master' of github.com:SimTk/openmm

parents a0f16cc0 7be6e8fb
...@@ -31,8 +31,7 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ...@@ -31,8 +31,7 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE. USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
from __future__ import division, print_function, absolute_import
from __future__ import division
__author__ = "Christopher M. Bruns" __author__ = "Christopher M. Bruns"
__version__ = "0.5" __version__ = "0.5"
...@@ -40,15 +39,18 @@ __version__ = "0.5" ...@@ -40,15 +39,18 @@ __version__ = "0.5"
import math import math
import sys import sys
from mymatrix import MyMatrix, zeros from .mymatrix import MyMatrix, zeros
from basedimension import BaseDimension from .basedimension import BaseDimension
from baseunit import BaseUnit from .baseunit import BaseUnit
from standard_dimensions import * from .standard_dimensions import *
class Unit(object): class Unit(object):
""" """
Physical unit such as meter or ampere. Physical unit such as meter or ampere.
""" """
__array_priority__ = 100
def __init__(self, base_or_scaled_units): def __init__(self, base_or_scaled_units):
"""Create a new Unit. """Create a new Unit.
...@@ -495,6 +497,8 @@ class ScaledUnit(object): ...@@ -495,6 +497,8 @@ class ScaledUnit(object):
ScaledUnit and BaseUnit are both used in the internals of Unit. They ScaledUnit and BaseUnit are both used in the internals of Unit. They
should only be used during the construction of Units. should only be used during the construction of Units.
""" """
__array_priority__ = 100
def __init__(self, factor, master, name, symbol): def __init__(self, factor, master, name, symbol):
self.factor = factor self.factor = factor
# Convert to one base_unit per dimension # Convert to one base_unit per dimension
...@@ -576,6 +580,14 @@ class ScaledUnit(object): ...@@ -576,6 +580,14 @@ class ScaledUnit(object):
+ ", symbol=" + repr(self.symbol) + ")" + ", symbol=" + repr(self.symbol) + ")"
class UnitSystem(object): class UnitSystem(object):
"""
A complete system of units defining the *base* unit in each dimension
Parameters
----------
units: ``list``
List of base units from which to construct the unit system
"""
def __init__(self, units): def __init__(self, units):
self.units = units self.units = units
self._unit_conversion_cache = {} self._unit_conversion_cache = {}
......
...@@ -30,16 +30,16 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE ...@@ -30,16 +30,16 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE. USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
from __future__ import division from __future__ import division, print_function, absolute_import
__author__ = "Christopher M. Bruns" __author__ = "Christopher M. Bruns"
__version__ = "0.6" __version__ = "0.6"
from baseunit import BaseUnit from .baseunit import BaseUnit
from standard_dimensions import * from .standard_dimensions import *
from unit import Unit, ScaledUnit, UnitSystem, dimensionless from .unit import Unit, ScaledUnit, UnitSystem, dimensionless
from unit_operators import * ; # needed for manipulation of units from .unit_operators import * ; # needed for manipulation of units
from prefix import * from .prefix import *
import math import math
import sys import sys
...@@ -303,20 +303,20 @@ mmHg = Unit({mmHg_base_unit: 1.0}) ...@@ -303,20 +303,20 @@ mmHg = Unit({mmHg_base_unit: 1.0})
ampere_base_unit = ScaledUnit(1.0, coulomb/second, "ampere", "A") ampere_base_unit = ScaledUnit(1.0, coulomb/second, "ampere", "A")
si_unit_system = UnitSystem([\ si_unit_system = UnitSystem([
meter_base_unit,\ meter_base_unit,
kilogram_base_unit,\ kilogram_base_unit,
second_base_unit,\ second_base_unit,
ampere_base_unit, ampere_base_unit,
kelvin_base_unit, kelvin_base_unit,
mole_base_unit, mole_base_unit,
candela_base_unit, candela_base_unit,
radian_base_unit]) radian_base_unit])
cgs_unit_system = UnitSystem([\ cgs_unit_system = UnitSystem([
centimeter_base_unit,\ centimeter_base_unit,
gram_base_unit,\ gram_base_unit,
second_base_unit,\ second_base_unit,
ampere_base_unit, ampere_base_unit,
kelvin_base_unit, kelvin_base_unit,
mole_base_unit, mole_base_unit,
...@@ -324,10 +324,10 @@ cgs_unit_system = UnitSystem([\ ...@@ -324,10 +324,10 @@ cgs_unit_system = UnitSystem([\
dalton_base_unit = ScaledUnit(1.0, gram/mole, "dalton", "Da") dalton_base_unit = ScaledUnit(1.0, gram/mole, "dalton", "Da")
md_unit_system = UnitSystem([\ md_unit_system = UnitSystem([
nanometer_base_unit,\ nanometer_base_unit,
dalton_base_unit, dalton_base_unit,
picosecond_base_unit,\ picosecond_base_unit,
elementary_charge_base_unit, elementary_charge_base_unit,
kelvin_base_unit, kelvin_base_unit,
mole_base_unit, mole_base_unit,
......
...@@ -31,16 +31,15 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ...@@ -31,16 +31,15 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE. USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
from __future__ import division, print_function, absolute_import
from __future__ import division
__author__ = "Christopher M. Bruns" __author__ = "Christopher M. Bruns"
__version__ = "0.5" __version__ = "0.5"
import math import math
from quantity import is_quantity from .quantity import is_quantity
from unit_definitions import * from .unit_definitions import *
#################### ####################
### TRIGONOMETRY ### ### TRIGONOMETRY ###
......
...@@ -46,12 +46,13 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ...@@ -46,12 +46,13 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE. USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
from __future__ import print_function, absolute_import, division
__author__ = "Christopher M. Bruns" __author__ = "Christopher M. Bruns"
__version__ = "0.5" __version__ = "0.5"
from unit import Unit, is_unit from .unit import Unit, is_unit
from quantity import Quantity, is_quantity from .quantity import Quantity, is_quantity
# Attach methods of Unit class that return a Quantity to Unit class. # Attach methods of Unit class that return a Quantity to Unit class.
# I put them here to avoid circular dependence in imports. # I put them here to avoid circular dependence in imports.
......
...@@ -180,6 +180,7 @@ UNITS = { ...@@ -180,6 +180,7 @@ UNITS = {
("*", "getParticleMass") : ("unit.amu", ()), ("*", "getParticleMass") : ("unit.amu", ()),
("*", "getPlatform") : (None, ()), ("*", "getPlatform") : (None, ()),
("*", "getPlatformByName") : (None, ()), ("*", "getPlatformByName") : (None, ()),
("*", "getPluginLoadFailures"): (None, ()),
("*", "getRandomNumberSeed") : (None, ()), ("*", "getRandomNumberSeed") : (None, ()),
("*", "getReactionFieldDielectric") : (None, ()), ("*", "getReactionFieldDielectric") : (None, ()),
("*", "getSoluteDielectric") : (None, ()), ("*", "getSoluteDielectric") : (None, ()),
...@@ -413,7 +414,8 @@ UNITS = { ...@@ -413,7 +414,8 @@ UNITS = {
("Platform", "getSpeed") : (None, ()), ("Platform", "getSpeed") : (None, ()),
("RBTorsionForce", "getTorsionParameters") ("RBTorsionForce", "getTorsionParameters")
: (None, (None, None, None, None, : (None, (None, None, None, None,
None, None, None, None, None, None)), 'unit.kilojoules_per_mole', 'unit.kilojoules_per_mole', 'unit.kilojoules_per_mole',
'unit.kilojoules_per_mole', 'unit.kilojoules_per_mole', 'unit.kilojoules_per_mole')),
("System", "getConstraintParameters") : (None, (None, None, 'unit.nanometer')), ("System", "getConstraintParameters") : (None, (None, None, 'unit.nanometer')),
("System", "getForce") : (None, ()), ("System", "getForce") : (None, ()),
("System", "getVirtualSite") : (None, ()), ("System", "getVirtualSite") : (None, ()),
......
...@@ -448,7 +448,7 @@ class TestUnits(QuantityTestCase): ...@@ -448,7 +448,7 @@ class TestUnits(QuantityTestCase):
self.assertAlmostEqualQuantities(n, 2.05834818672e-17 * u.mole) self.assertAlmostEqualQuantities(n, 2.05834818672e-17 * u.mole)
self.assertAlmostEqualQuantities(V, 5.2359833333333e-19 * u.meters**3) self.assertAlmostEqualQuantities(V, 5.2359833333333e-19 * u.meters**3)
self.assertEqual(str(T), '310.0 K') self.assertEqual(str(T), '310.0 K')
self.assertEqual(str(u.MOLAR_GAS_CONSTANT_R), '8.31447247122 J/(K mol)') self.assertEqual(str(1*u.joules/u.kelvin/u.mole), '1 J/(K mol)')
self.assertTrue(u.is_quantity(V)) self.assertTrue(u.is_quantity(V))
# Checks trouble with complicated unit conversion factors # Checks trouble with complicated unit conversion factors
p1 = 1.0 * u.atmospheres p1 = 1.0 * u.atmospheres
...@@ -638,6 +638,7 @@ class TestUnits(QuantityTestCase): ...@@ -638,6 +638,7 @@ class TestUnits(QuantityTestCase):
self.assertEqual(str(u.meters*u.meters), 'meter**2') self.assertEqual(str(u.meters*u.meters), 'meter**2')
self.assertEqual(str(u.meter*u.meter), 'meter**2') self.assertEqual(str(u.meter*u.meter), 'meter**2')
@unittest.skipIf(np is None, 'Skipping numpy units tests')
class TestNumpyUnits(QuantityTestCase): class TestNumpyUnits(QuantityTestCase):
def testNumpyQuantity(self): def testNumpyQuantity(self):
...@@ -686,6 +687,14 @@ class TestNumpyUnits(QuantityTestCase): ...@@ -686,6 +687,14 @@ class TestNumpyUnits(QuantityTestCase):
b = a.reshape((5, 2)) b = a.reshape((5, 2))
self.assertTrue(u.is_quantity(b)) self.assertTrue(u.is_quantity(b))
if np is None: def testMultiplication(self):
# Support lack of numpy """ Tests that units override numpy.ndarray multiplication """
del TestNumpyUnits self.assertIsInstance(np.arange(10)*u.angstroms, u.Quantity)
# This only works with versions of numpy > 1.7 due to a bug in older
# versions. Since Travis-CI installs Python 1.6.1 from aptitude, and we
# don't want it to report test failures *every time*, just disable this
# particular test for the numpy versions known to be bad.
if np.version.version > '1.7':
x = np.array([1]) * u.liters
self.assertIsInstance(x, u.Quantity)
self.assertIsInstance(np.arange(10) * x, u.Quantity)
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