49 Commits

Author SHA1 Message Date
Peter Eastman
e53bdc5eab Top level Python module is now "openmm" (#3000)
* Top level Python module is now "openmm"

* Updated module names in examples

* Updated module names in documentation

* Updated module in CI scripts

* Added deprecation warning
2021-02-01 09:40:37 -08:00
Peter Eastman
9008050c9e Reduce numerical error in computing conversion factors between units (#2968) 2021-01-14 16:31:40 -08:00
peastman
b4543a4633 Updated to latest values for physical constants (#2802)
* Updated to latest values for physical constants

* Updated documentation on physical constants

* Updated Python unit definitions

* Fixed constants in test case

* Added a comment
2020-08-18 10:53:24 -07:00
Rasmus Wriedt Larsen
c8bd639278 Prefer not self == other when defining __ne__ in Python
Apparently it is the slightly more correct way of doing thigns, as explained in
https://stackoverflow.com/a/30676267/538973
2020-03-30 10:45:23 +02:00
David Dotson
ad50ced2e8 Switched hartree ScaledUnit basis to joule
From @peastman:

> Test cases are failing. I believe it's because the parent for a ScaledUnit needs to be a Unit, not another ScaledUnit. So in the line
>
> ```
>  hartree_base_unit = ScaledUnit(4.3597447222071e-18, joule_base_unit, "hartree", "Ha")
> ```
>
> replace joule_base_unit with joule.
2019-10-08 01:08:48 +02:00
David Dotson
ce85b7f73e Added hartree unit.
This is of immediate need to QCEngine, in particular MolSSI/QCEngine#151
2019-10-08 00:18:49 +02:00
Andrea Rizzi
6220775ca6 Fix #1940: Bug in Quantity.__setitem__ when assigning slices 2017-12-04 15:32:04 -05:00
Robert T. McGibbon
04e61cd90c Update unit_definitions.py
Change bohr unit to value from CODATA (http://physics.nist.gov/cgi-bin/cuu/Value?bohrrada0)
2016-11-01 22:35:49 -04:00
Robert T. McGibbon
3281347810 Add Bohrs to units 2016-11-01 18:59:07 -04:00
Robert McGibbon
98d053d490 Improve docstrings
Swigged python docstrings now include documented return values and type
information or their arguments. They are generated in numpydoc format.
Furthermore, all of the Python app layer docstrings have been changed
to numpydoc format. The filterPythonFiles.py script which helps to
generate the Doxygen Python API docs has been updated to reflect these
changes.
2015-11-02 16:41:22 -08:00
peastman
b7088b7401 Python 2/3 compatibility in single code base, plus python 3 testing on travis. 2015-08-27 16:26:03 -07:00
Jason Swails
24f6585e49 Remove superfluous import. 2015-06-23 08:29:24 -04:00
Jason Swails
10daac8774 Better fix. 2015-06-23 08:18:49 -04:00
Jason Swails
8e346de8e1 Fix Python 3 support in unit package. 2015-06-22 21:42:46 -04:00
Jason Swails
ba1af1ee90 Delete now out-of-date docs as well as adding __array_priority__ to Quantity.
This should be *lower* than that of Unit (and ScaledUnit/BaseUnit), since we
still want Units to take priority over Quantities (but Quantity to take
precedence over regular ndarrays) for reasons like this:

>>> a = np.array([1]) * u.angstroms
>>> b = a * u.angstroms # should be np.array([1])*u.angstroms**2
>>> np.arange(10) * a # utilize broadcasting
[1 2 3 4 5 6 7 8 9 10] A**2
2015-06-19 12:41:28 -04:00
Jason Swails
4ae687498b A large number of unit cleanups and fix numpy wart
The main thing that's done here is that numpy arrays can be given units via the
* operator, rather than relying on the Quantity constructor

e.g.,

>>> import numpy as np
>>> np.zeros(10) * u.angstroms
Quantity(value=array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]), unit=angstrom)

yay!
2015-06-18 19:13:56 -06:00
Jason Swails
f7a7f4ea12 Fix the mean() and std() methods on container Quantities when those containers
are NOT numpy arrays.
2014-12-07 20:17:19 -05:00
Jason Swails
b9a19a0c01 Fix small bug in unit related to mutable sequences. 2014-12-06 18:21:10 -05:00
Jason Swails
5b4abbb5d3 Oops... Forgot unit on the reshape command.
Add a test for the various numpy attributes (and the arguments they take) for
the unit module.
2014-11-04 11:41:01 -05:00
Jason Swails
a5c00fa550 Fix another small bug for unit handling with numpy arrays. Fixes the exception:
Traceback (most recent call last):
  File ".../python/tests/TestNumpyCompatibility.py", line 87, in testNumpyAttributes
    d = self.data.reshape((100, 3))
  File ".../simtk/unit/quantity.py", line 575, in reshape
    return Quantity(self._value.reshape(shape, order=order))
  File ".../simtk/unit/quantity.py", line 142, in __init__
    if value == first_item:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Also add a test for new unit numpy capabilities.
2014-11-04 11:17:13 -05:00
Jason Swails
019f502642 Add missing arg check. Implement "reshape" in Quantity that passes down to the
underlying numpy array. This function would be used in instances where, for
instance, a certain API would send a flattened array of coordinates or
velocities with units attached, and you wanted to reshape the array into
(natom, 3) to be consistent with OpenMM's Context object.
2014-11-03 14:42:25 -05:00
Jason Swails
dc8b4038cf Allow Quantity.sum (and other attributes, like mean, max, min, and std) to take
arguments and pass them to the numpy function if applicable. That way, users get
the full flexibility of the numpy API on those particular methods AND get the
added benefit that the result has the correct units (and it all runs fast).
2014-11-03 13:42:02 -05:00
Peter Eastman
9184c3722e Fixed bug in Quantity.sum() 2014-10-15 12:51:29 -07:00
Jason Swails
f6d9006666 Possible speedup for unit_math.sum function. 2014-10-06 19:49:12 -04:00
Jason Swails
9c38d980cb Stop using "== None" and "!= None". "is" and "is not" is the preferred way to do
it.  Not only that, I got this FutureWarning:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/simtk/unit/quantity.py:170:
FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if value == None:
2014-10-06 18:36:27 -04:00
Jason Swails
8faeeb4d05 More stable std calc. 2014-10-06 18:29:01 -04:00
Jason Swails
5c029ede95 Add functions to Quantity to compute the max, min, standard deviation (as the
sqrt of the variance), and average, returning a Quantity with the proper units.

This should be reasonably efficient, as it takes advantage of numpy-accelerated
methods if they're present.
2014-10-06 17:56:58 -04:00
peastman
b7b4742fea Fixed a bug in unit conversion for sequences 2014-07-16 10:54:47 -07:00
peastman
48498b10c9 Fixed bug in pull request #227 2013-12-09 10:57:32 -08:00
Patrick Grinaway
8d6d55217a Check type in __eq__() and __ne__(), simplify code 2013-12-05 21:22:48 -05:00
Patrick Grinaway
1f1a28b5e5 Added implementation for equality __eq__() and inequality __ne__() operators 2013-12-05 16:53:13 -05:00
Justin MacCallum
4941cc7d4b Removed trailing whitespace 2013-07-12 13:33:34 -06:00
Lee-Ping Wang
83bc16c889 Added GROMACS coordinate reader and Debye in units. 2012-05-20 05:43:21 +00:00
Peter Eastman
c2e05fe86e Defined a sum() function that works with Quantities. Also fixed a doctest. 2012-05-07 18:15:26 +00:00
Peter Eastman
b3f88f6fcd Added license notice to Python files 2012-03-27 17:43:36 +00:00
Peter Eastman
639092999f Fixed bug where tuples would sometimes turn into lists when changing their units 2012-03-13 21:12:31 +00:00
Peter Eastman
c3ca5fc050 Finished implementing addHydrogens() 2012-02-11 01:09:04 +00:00
Peter Eastman
15c272fdb0 Implemented addSolvent() 2012-02-08 18:32:05 +00:00
Peter Eastman
bfc1b5299d Define both __div__ and __truediv__ to work on all Python versions 2012-01-23 23:38:37 +00:00
Peter Eastman
d648613ba6 Changes to support Python 3 2012-01-23 21:24:33 +00:00
Peter Eastman
f6c08a067b Name for Coulomb unit was defined incorrectly 2011-11-15 18:47:36 +00:00
Peter Eastman
5b1faed965 Fixed incorrect abbreviations for charge units 2011-05-18 17:41:23 +00:00
Peter Eastman
1db8640dd9 Further optimizations to units code 2011-03-12 00:22:50 +00:00
Peter Eastman
c3c84a28ef Further optimizations to unit code 2011-03-09 01:05:20 +00:00
Peter Eastman
47ab0a622f Optimizations to unit conversion 2011-03-08 01:25:41 +00:00
Christopher Bruns
1ef16124ea Use Peter's modified quantity.py
Change doctests to reflect better preservation of tuples in collections of collections.
Note that outer container is still converted to list...
2011-03-03 23:53:25 +00:00
Christopher Bruns
09f5cb4c26 Cache some units results for better performance. 2011-03-03 01:39:22 +00:00
Christopher Bruns
5a6ece03cb Add optimization to possibly speed up units code. 2011-03-03 00:53:51 +00:00
Peter Eastman
65b9d0b623 Python API wrappers are now part of OpenMM 2011-02-26 00:03:42 +00:00