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
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import division
from __future__ import division, print_function, absolute_import
__author__ = "Christopher M. Bruns"
__version__ = "0.5"
......@@ -40,15 +39,18 @@ __version__ = "0.5"
import math
import sys
from mymatrix import MyMatrix, zeros
from basedimension import BaseDimension
from baseunit import BaseUnit
from standard_dimensions import *
from .mymatrix import MyMatrix, zeros
from .basedimension import BaseDimension
from .baseunit import BaseUnit
from .standard_dimensions import *
class Unit(object):
"""
Physical unit such as meter or ampere.
"""
__array_priority__ = 100
def __init__(self, base_or_scaled_units):
"""Create a new Unit.
......@@ -495,6 +497,8 @@ class ScaledUnit(object):
ScaledUnit and BaseUnit are both used in the internals of Unit. They
should only be used during the construction of Units.
"""
__array_priority__ = 100
def __init__(self, factor, master, name, symbol):
self.factor = factor
# Convert to one base_unit per dimension
......@@ -576,6 +580,14 @@ class ScaledUnit(object):
+ ", symbol=" + repr(self.symbol) + ")"
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):
self.units = units
self._unit_conversion_cache = {}
......
......@@ -30,16 +30,16 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import division
from __future__ import division, print_function, absolute_import
__author__ = "Christopher M. Bruns"
__version__ = "0.6"
from baseunit import BaseUnit
from standard_dimensions import *
from unit import Unit, ScaledUnit, UnitSystem, dimensionless
from unit_operators import * ; # needed for manipulation of units
from prefix import *
from .baseunit import BaseUnit
from .standard_dimensions import *
from .unit import Unit, ScaledUnit, UnitSystem, dimensionless
from .unit_operators import * ; # needed for manipulation of units
from .prefix import *
import math
import sys
......@@ -303,20 +303,20 @@ mmHg = Unit({mmHg_base_unit: 1.0})
ampere_base_unit = ScaledUnit(1.0, coulomb/second, "ampere", "A")
si_unit_system = UnitSystem([\
meter_base_unit,\
kilogram_base_unit,\
second_base_unit,\
si_unit_system = UnitSystem([
meter_base_unit,
kilogram_base_unit,
second_base_unit,
ampere_base_unit,
kelvin_base_unit,
mole_base_unit,
candela_base_unit,
radian_base_unit])
cgs_unit_system = UnitSystem([\
centimeter_base_unit,\
gram_base_unit,\
second_base_unit,\
cgs_unit_system = UnitSystem([
centimeter_base_unit,
gram_base_unit,
second_base_unit,
ampere_base_unit,
kelvin_base_unit,
mole_base_unit,
......@@ -324,10 +324,10 @@ cgs_unit_system = UnitSystem([\
dalton_base_unit = ScaledUnit(1.0, gram/mole, "dalton", "Da")
md_unit_system = UnitSystem([\
nanometer_base_unit,\
md_unit_system = UnitSystem([
nanometer_base_unit,
dalton_base_unit,
picosecond_base_unit,\
picosecond_base_unit,
elementary_charge_base_unit,
kelvin_base_unit,
mole_base_unit,
......
......@@ -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
USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import division
from __future__ import division, print_function, absolute_import
__author__ = "Christopher M. Bruns"
__version__ = "0.5"
import math
from quantity import is_quantity
from unit_definitions import *
from .quantity import is_quantity
from .unit_definitions import *
####################
### TRIGONOMETRY ###
......
......@@ -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
USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import print_function, absolute_import, division
__author__ = "Christopher M. Bruns"
__version__ = "0.5"
from unit import Unit, is_unit
from quantity import Quantity, is_quantity
from .unit import Unit, is_unit
from .quantity import Quantity, is_quantity
# Attach methods of Unit class that return a Quantity to Unit class.
# I put them here to avoid circular dependence in imports.
......
......@@ -180,6 +180,7 @@ UNITS = {
("*", "getParticleMass") : ("unit.amu", ()),
("*", "getPlatform") : (None, ()),
("*", "getPlatformByName") : (None, ()),
("*", "getPluginLoadFailures"): (None, ()),
("*", "getRandomNumberSeed") : (None, ()),
("*", "getReactionFieldDielectric") : (None, ()),
("*", "getSoluteDielectric") : (None, ()),
......@@ -413,7 +414,8 @@ UNITS = {
("Platform", "getSpeed") : (None, ()),
("RBTorsionForce", "getTorsionParameters")
: (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", "getForce") : (None, ()),
("System", "getVirtualSite") : (None, ()),
......
......@@ -448,7 +448,7 @@ class TestUnits(QuantityTestCase):
self.assertAlmostEqualQuantities(n, 2.05834818672e-17 * u.mole)
self.assertAlmostEqualQuantities(V, 5.2359833333333e-19 * u.meters**3)
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))
# Checks trouble with complicated unit conversion factors
p1 = 1.0 * u.atmospheres
......@@ -638,6 +638,7 @@ class TestUnits(QuantityTestCase):
self.assertEqual(str(u.meters*u.meters), 'meter**2')
self.assertEqual(str(u.meter*u.meter), 'meter**2')
@unittest.skipIf(np is None, 'Skipping numpy units tests')
class TestNumpyUnits(QuantityTestCase):
def testNumpyQuantity(self):
......@@ -686,6 +687,14 @@ class TestNumpyUnits(QuantityTestCase):
b = a.reshape((5, 2))
self.assertTrue(u.is_quantity(b))
if np is None:
# Support lack of numpy
del TestNumpyUnits
def testMultiplication(self):
""" Tests that units override numpy.ndarray multiplication """
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