Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
4941cc7d
Commit
4941cc7d
authored
Jul 12, 2013
by
Justin MacCallum
Browse files
Removed trailing whitespace
parent
3862202e
Changes
31
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
216 additions
and
216 deletions
+216
-216
wrappers/python/simtk/unit/baseunit.py
wrappers/python/simtk/unit/baseunit.py
+19
-19
wrappers/python/simtk/unit/constants.py
wrappers/python/simtk/unit/constants.py
+1
-1
wrappers/python/simtk/unit/doctests.py
wrappers/python/simtk/unit/doctests.py
+58
-58
wrappers/python/simtk/unit/mymatrix.py
wrappers/python/simtk/unit/mymatrix.py
+22
-22
wrappers/python/simtk/unit/prefix.py
wrappers/python/simtk/unit/prefix.py
+5
-5
wrappers/python/simtk/unit/quantity.py
wrappers/python/simtk/unit/quantity.py
+59
-59
wrappers/python/simtk/unit/standard_dimensions.py
wrappers/python/simtk/unit/standard_dimensions.py
+1
-1
wrappers/python/simtk/unit/unit.py
wrappers/python/simtk/unit/unit.py
+34
-34
wrappers/python/simtk/unit/unit_definitions.py
wrappers/python/simtk/unit/unit_definitions.py
+1
-1
wrappers/python/simtk/unit/unit_math.py
wrappers/python/simtk/unit/unit_math.py
+7
-7
wrappers/python/simtk/unit/unit_operators.py
wrappers/python/simtk/unit/unit_operators.py
+9
-9
No files found.
wrappers/python/simtk/unit/baseunit.py
View file @
4941cc7d
...
...
@@ -15,7 +15,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
@@ -40,14 +40,14 @@ __version__ = "0.6"
class
BaseUnit
(
object
):
'''
Physical unit expressed in exactly one BaseDimension.
For example, meter_base_unit could be a BaseUnit for the length dimension.
The BaseUnit class is used internally in the more general Unit class.
'''
def
__init__
(
self
,
base_dim
,
name
,
symbol
):
"""Creates a new BaseUnit.
Parameters
- self: The newly created BaseUnit.
- base_dim: (BaseDimension) The dimension of the new unit, e.g. 'mass'
...
...
@@ -62,7 +62,7 @@ class BaseUnit(object):
self
.
_conversion_factor_to
[
self
]
=
1.0
self
.
_conversion_factor_to_by_name
=
{}
self
.
_conversion_factor_to_by_name
[
self
.
name
]
=
1.0
def
__lt__
(
self
,
other
):
"""
Comparison function that sorts BaseUnits by BaseDimension
...
...
@@ -78,10 +78,10 @@ class BaseUnit(object):
Returns a dictionary of BaseDimension:exponent pairs, describing the dimension of this unit.
"""
yield
(
self
.
dimension
,
1
)
def
iter_base_units
(
self
):
yield
(
self
,
1
)
def
get_dimension_tuple
(
self
):
"""
Returns a sorted tuple of (BaseDimension, exponent) pairs, that can be used as a dictionary key.
...
...
@@ -89,7 +89,7 @@ class BaseUnit(object):
l
=
list
(
self
.
iter_base_dimensions
())
l
.
sort
()
return
tuple
(
l
)
def
__str__
(
self
):
"""Returns a string with the name of this BaseUnit
"""
...
...
@@ -97,40 +97,40 @@ class BaseUnit(object):
def
__repr__
(
self
):
return
'BaseUnit(base_dim=%s, name="%s", symbol="%s")'
%
(
self
.
dimension
,
self
.
name
,
self
.
symbol
)
def
define_conversion_factor_to
(
self
,
other
,
factor
):
"""
Defines a conversion factor between two BaseUnits.
self * factor = other
Parameters:
- self: (BaseUnit) 'From' unit in conversion.
- other: (BaseUnit) 'To' unit in conversion.
- factor: (float) Conversion factor.
After calling this method, both self and other will have stored
conversion factors for one another, plus all other BaseUnits which
self and other have previously defined.
Both self and other must have the same dimension, otherwise a TypeError
will be raised.
Returns None.
"""
if
self
.
dimension
!=
other
.
dimension
:
raise
TypeError
(
'Cannot define conversion for BaseUnits with different dimensions.'
)
assert
(
factor
!=
0
)
assert
(
not
self
is
other
)
assert
(
not
self
is
other
)
# import all transitive conversions
self
.
_conversion_factor_to
[
other
]
=
factor
self
.
_conversion_factor_to_by_name
[
other
.
name
]
=
factor
for
(
unit
,
cfac
)
in
other
.
_conversion_factor_to
.
items
():
if
unit
is
self
:
continue
if
self
.
_conversion_factor_to
.
has_key
(
unit
):
continue
self
.
_conversion_factor_to
[
unit
]
=
factor
*
cfac
self
.
_conversion_factor_to
[
unit
]
=
factor
*
cfac
unit
.
_conversion_factor_to
[
self
]
=
pow
(
factor
*
cfac
,
-
1
)
self
.
_conversion_factor_to_by_name
[
unit
.
name
]
=
factor
*
cfac
self
.
_conversion_factor_to_by_name
[
unit
.
name
]
=
factor
*
cfac
unit
.
_conversion_factor_to_by_name
[
self
.
name
]
=
pow
(
factor
*
cfac
,
-
1
)
# and for the other guy
invFac
=
pow
(
factor
,
-
1.0
)
...
...
@@ -146,13 +146,13 @@ class BaseUnit(object):
def
conversion_factor_to
(
self
,
other
):
"""Returns a conversion factor from this BaseUnit to another BaseUnit.
It does not matter which existing BaseUnit you define the conversion factor to.
Conversions for all other known BaseUnits will be computed at the same time.
Raises TypeError if dimension does not match.
Raises LookupError if no conversion has been defined. (see define_conversion_factor_to).
"""
if
self
is
other
:
return
1.0
if
self
.
dimension
!=
other
.
dimension
:
...
...
wrappers/python/simtk/unit/constants.py
View file @
4941cc7d
...
...
@@ -11,7 +11,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
wrappers/python/simtk/unit/doctests.py
View file @
4941cc7d
This diff is collapsed.
Click to expand it.
wrappers/python/simtk/unit/mymatrix.py
View file @
4941cc7d
...
...
@@ -10,7 +10,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
@@ -34,7 +34,7 @@ import sys
def
eye
(
size
):
"""
Returns identity matrix.
>>> print(eye(3))
[[1, 0, 0]
[0, 1, 0]
...
...
@@ -50,11 +50,11 @@ def eye(size):
r
.
append
(
0
)
result
.
append
(
r
)
return
MyMatrix
(
result
)
def
zeros
(
m
,
n
=
None
):
"""
Returns matrix of zeroes
>>> print(zeros(3))
[[0, 0, 0]
[0, 0, 0]
...
...
@@ -82,7 +82,7 @@ class MyVector(object):
def
__str__
(
self
):
return
str
(
self
.
data
)
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
"("
+
repr
(
self
.
data
)
+
")"
...
...
@@ -91,20 +91,20 @@ class MyVector(object):
def
__contains__
(
self
,
item
):
return
item
in
self
.
data
def
__delitem__
(
self
,
key
):
del
self
.
data
[
key
]
def
__iter__
(
self
):
for
item
in
self
.
data
:
yield
item
def
__len__
(
self
):
return
len
(
self
.
data
)
def
__setitem__
(
self
,
key
,
value
):
self
.
data
[
key
]
=
value
def
__rmul__
(
self
,
lhs
):
try
:
len
(
lhs
)
...
...
@@ -119,7 +119,7 @@ class MyVector(object):
class
MyMatrix
(
MyVector
):
"""
Pure python linear algebra matrix for internal matrix inversion in UnitSystem.
>>> m = MyMatrix([[1,0,],[0,1,]])
>>> print(m)
[[1, 0]
...
...
@@ -158,7 +158,7 @@ class MyMatrix(MyVector):
"""
def
numRows
(
self
):
return
len
(
self
.
data
)
def
numCols
(
self
):
if
len
(
self
.
data
)
==
0
:
return
0
...
...
@@ -179,13 +179,13 @@ class MyMatrix(MyVector):
start_char
=
" "
result
+=
"]"
return
result
def
__repr__
(
self
):
return
'MyMatrix('
+
MyVector
.
__repr__
(
self
)
+
')'
def
is_square
(
self
):
return
self
.
numRows
()
==
self
.
numCols
()
def
__iter__
(
self
):
for
item
in
self
.
data
:
yield
MyVector
(
item
)
...
...
@@ -206,7 +206,7 @@ class MyMatrix(MyVector):
def
__mul__
(
self
,
rhs
):
"""
Matrix multiplication.
>>> a = MyMatrix([[1,2],[3,4]])
>>> b = MyMatrix([[5,6],[7,8]])
>>> print(a)
...
...
@@ -218,7 +218,7 @@ class MyMatrix(MyVector):
>>> print(a*b)
[[19, 22]
[43, 50]]
"""
m
=
self
.
numRows
()
n
=
len
(
rhs
[
0
])
...
...
@@ -235,7 +235,7 @@ class MyMatrix(MyVector):
def
__add__
(
self
,
rhs
):
"""
Matrix addition.
>>> print(MyMatrix([[1, 2],[3, 4]]) + MyMatrix([[5, 6],[7, 8]]))
[[6, 8]
[10, 12]]
...
...
@@ -253,7 +253,7 @@ class MyMatrix(MyVector):
def
__sub__
(
self
,
rhs
):
"""
Matrix subtraction.
>>> print(MyMatrix([[1, 2],[3, 4]]) - MyMatrix([[5, 6],[7, 8]]))
[[-4, -4]
[-4, -4]]
...
...
@@ -270,7 +270,7 @@ class MyMatrix(MyVector):
def
__pos__
(
self
):
return
self
def
__neg__
(
self
):
m
=
self
.
numRows
()
n
=
self
.
numCols
()
...
...
@@ -384,7 +384,7 @@ class MyMatrix(MyVector):
for
k
in
range
(
0
,
n
):
temp
=
a
[
k
][
indxr
[
l
]]
a
[
k
][
indxr
[
l
]]
=
a
[
k
][
indxc
[
l
]]
a
[
k
][
indxc
[
l
]]
=
temp
a
[
k
][
indxc
[
l
]]
=
temp
return
a
def
transpose
(
self
):
...
...
@@ -395,13 +395,13 @@ class MyMatrixTranspose(MyMatrix):
def
transpose
(
self
):
return
MyMatrix
(
self
.
data
)
def
numRows
(
self
):
if
len
(
self
.
data
)
==
0
:
return
0
else
:
return
len
(
self
.
data
[
0
])
def
numCols
(
self
):
return
len
(
self
.
data
)
...
...
@@ -461,7 +461,7 @@ class MyMatrixTranspose(MyMatrix):
# run module directly for testing
if
__name__
==
'__main__'
:
# Test the examples in the docstrings
import
doctest
,
sys
doctest
.
testmod
(
sys
.
modules
[
__name__
])
wrappers/python/simtk/unit/prefix.py
View file @
4941cc7d
...
...
@@ -11,7 +11,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
@@ -44,14 +44,14 @@ import sys
class
SiPrefix
(
object
):
"""
Unit prefix that can be multiplied by a unit to yield a new unit.
e.g. millimeter = milli*meter
"""
def
__init__
(
self
,
prefix
,
factor
,
symbol
):
self
.
prefix
=
prefix
self
.
factor
=
factor
self
.
symbol
=
symbol
def
__mul__
(
self
,
unit
):
"""
SiPrefix * BaseUnit yields new BaseUnit
...
...
@@ -136,7 +136,7 @@ si_prefixes = ( yotto
def
define_prefixed_units
(
base_unit
,
module
=
sys
.
modules
[
__name__
]):
"""
Create attributes for prefixed units derived from a particular BaseUnit, e.g. "kilometer" from "meter_base_unit"
Parameters
- base_unit (BaseUnit) existing base unit to use as a basis for prefixed units
- module (Module) module which will contain the new attributes. Defaults to simtk.unit module.
...
...
@@ -146,7 +146,7 @@ def define_prefixed_units(base_unit, module = sys.modules[__name__]):
name
=
new_base_unit
.
name
new_unit
=
Unit
({
new_base_unit
:
1.0
})
# Create base_unit attribute, needed for creating UnitSystems
module
.
__dict__
[
name
+
'_base_unit'
]
=
new_base_unit
# e.g. "kilometer_base_unit"
module
.
__dict__
[
name
+
'_base_unit'
]
=
new_base_unit
# e.g. "kilometer_base_unit"
# Create attribue in this module
module
.
__dict__
[
name
]
=
new_unit
# e.g. "kilometer"
# And plural version
...
...
wrappers/python/simtk/unit/quantity.py
View file @
4941cc7d
This diff is collapsed.
Click to expand it.
wrappers/python/simtk/unit/standard_dimensions.py
View file @
4941cc7d
...
...
@@ -13,7 +13,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
wrappers/python/simtk/unit/unit.py
View file @
4941cc7d
This diff is collapsed.
Click to expand it.
wrappers/python/simtk/unit/unit_definitions.py
View file @
4941cc7d
...
...
@@ -11,7 +11,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
wrappers/python/simtk/unit/unit_math.py
View file @
4941cc7d
...
...
@@ -13,7 +13,7 @@ Portions copyright (c) 2012 Stanford University and the Authors.
Authors: Christopher M. Bruns
Contributors: Peter Eastman
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
...
@@ -49,7 +49,7 @@ from unit_definitions import *
def
sin
(
angle
):
"""
Examples
>>> sin(90*degrees)
1.0
"""
...
...
@@ -67,7 +67,7 @@ def sinh(angle):
def
cos
(
angle
):
"""
Examples
>>> cos(180*degrees)
-1.0
"""
...
...
@@ -102,10 +102,10 @@ def acos(x):
0.0 rad
"""
return
math
.
acos
(
x
)
*
radians
def
acosh
(
x
):
return
math
.
acosh
(
x
)
*
radians
def
asin
(
x
):
return
math
.
asin
(
x
)
*
radians
...
...
@@ -114,10 +114,10 @@ def asinh(x):
def
atan
(
x
):
return
math
.
atan
(
x
)
*
radians
def
atanh
(
x
):
return
math
.
atanh
(
x
)
*
radians
def
atan2
(
x
,
y
):
return
math
.
atan2
(
x
,
y
)
*
radians
...
...
wrappers/python/simtk/unit/unit_operators.py
View file @
4941cc7d
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment