Commit 4087eae3 authored by Jason Swails's avatar Jason Swails
Browse files

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

parents 6d339632 71d91890
...@@ -13,6 +13,6 @@ Getting Help ...@@ -13,6 +13,6 @@ Getting Help
Need Help? Check out the [documentation](https://simtk.org/docman/?group_id=161) and [discussion forums](https://simtk.org/forums/viewforum.php?f=161). Need Help? Check out the [documentation](https://simtk.org/docman/?group_id=161) and [discussion forums](https://simtk.org/forums/viewforum.php?f=161).
[C++ API Reference](https://simtk.org/api_docs/openmm/api5_0/c++/) [C++ API Reference](https://simtk.org/api_docs/openmm/api6_0/c++/)
[Python API Reference](https://simtk.org/api_docs/openmm/api5_0/python/) [Python API Reference](https://simtk.org/api_docs/openmm/api6_0/python/)
...@@ -48,6 +48,7 @@ public: ...@@ -48,6 +48,7 @@ public:
} }
double getSpeed() const; double getSpeed() const;
bool supportsDoublePrecision() const; bool supportsDoublePrecision() const;
static bool isPlatformSupported();
const std::string& getPropertyValue(const Context& context, const std::string& property) const; const std::string& getPropertyValue(const Context& context, const std::string& property) const;
void setPropertyValue(Context& context, const std::string& property, const std::string& value) const; void setPropertyValue(Context& context, const std::string& property, const std::string& value) const;
void contextCreated(ContextImpl& context, const std::map<std::string, std::string>& properties) const; void contextCreated(ContextImpl& context, const std::map<std::string, std::string>& properties) const;
......
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
#include "openmm/System.h" #include "openmm/System.h"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#ifdef __APPLE__
#include "sys/sysctl.h"
#endif
using namespace OpenMM; using namespace OpenMM;
using std::map; using std::map;
...@@ -42,10 +46,12 @@ using std::vector; ...@@ -42,10 +46,12 @@ using std::vector;
#ifdef OPENMM_OPENCL_BUILDING_STATIC_LIBRARY #ifdef OPENMM_OPENCL_BUILDING_STATIC_LIBRARY
extern "C" void registerOpenCLPlatform() { extern "C" void registerOpenCLPlatform() {
if (OpenCLPlatform::isPlatformSupported())
Platform::registerPlatform(new OpenCLPlatform()); Platform::registerPlatform(new OpenCLPlatform());
} }
#else #else
extern "C" OPENMM_EXPORT_OPENCL void registerPlatforms() { extern "C" OPENMM_EXPORT_OPENCL void registerPlatforms() {
if (OpenCLPlatform::isPlatformSupported())
Platform::registerPlatform(new OpenCLPlatform()); Platform::registerPlatform(new OpenCLPlatform());
} }
#endif #endif
...@@ -102,6 +108,33 @@ bool OpenCLPlatform::supportsDoublePrecision() const { ...@@ -102,6 +108,33 @@ bool OpenCLPlatform::supportsDoublePrecision() const {
return true; return true;
} }
bool OpenCLPlatform::isPlatformSupported() {
// Return false for OpenCL implementations that are known
// to be buggy (Apple OSX since 10.7.5)
#ifdef __APPLE__
char str[256];
size_t size = sizeof(str);
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
if (ret != 0)
return false;
int major, minor, micro;
if (sscanf(str, "%d.%d.%d", &major, &minor, &micro) != 3)
return false;
if ((major > 11) || (major == 11 && minor > 4) || (major == 11 && minor == 4 && micro >= 2))
// 11.4.2 is the darwin release corresponding to OSX 10.7.5, which is the
// point at which a number of serious bugs were introduced into the
// Apple OpenCL libraries, resulting in catistrophically incorrect MD simulations
// (see https://github.com/SimTk/openmm/issues/395 for example). Once a fix is released,
// this version check should be updated.
return false;
#endif
return true;
}
const string& OpenCLPlatform::getPropertyValue(const Context& context, const string& property) const { const string& OpenCLPlatform::getPropertyValue(const Context& context, const string& property) const {
const ContextImpl& impl = getContextImpl(context); const ContextImpl& impl = getContextImpl(context);
const PlatformData* data = reinterpret_cast<const PlatformData*>(impl.getPlatformData()); const PlatformData* data = reinterpret_cast<const PlatformData*>(impl.getPlatformData());
......
...@@ -42,22 +42,34 @@ class Element(object): ...@@ -42,22 +42,34 @@ class Element(object):
The simtk.openmm.app.element module contains objects for all the standard chemical elements, The simtk.openmm.app.element module contains objects for all the standard chemical elements,
such as element.hydrogen or element.carbon. You can also call the static method Element.getBySymbol() to such as element.hydrogen or element.carbon. You can also call the static method Element.getBySymbol() to
look up the Element with a particular chemical symbol.""" look up the Element with a particular chemical symbol.
Element objects should be considered immutable
"""
_elements_by_symbol = {} _elements_by_symbol = {}
_elements_by_atomic_number = {} _elements_by_atomic_number = {}
def __init__(self, number, name, symbol, mass): def __init__(self, number, name, symbol, mass):
"""Create a new element
Parameters:
number (int) The atomic number of the element
name (string) The name of the element
symbol (string) The chemical symbol of the element
mass (float) The atomic mass of the element
"""
## The atomic number of the element ## The atomic number of the element
self.atomic_number = number self._atomic_number = number
## The name of the element ## The name of the element
self.name = name self._name = name
## The chemical symbol of the element ## The chemical symbol of the element
self.symbol = symbol self._symbol = symbol
## The atomic mass of the element ## The atomic mass of the element
self.mass = mass self._mass = mass
# Index this element in a global table # Index this element in a global table
s = symbol.strip().upper() s = symbol.strip().upper()
assert s not in Element._elements_by_symbol assert s not in Element._elements_by_symbol
Element._elements_by_symbol[s] = self Element._elements_by_symbol[s] = self
if number in Element._elements_by_atomic_number: if number in Element._elements_by_atomic_number:
...@@ -81,6 +93,28 @@ class Element(object): ...@@ -81,6 +93,28 @@ class Element(object):
def getByAtomicNumber(atomic_number): def getByAtomicNumber(atomic_number):
return Element._elements_by_atomic_number[atomic_number] return Element._elements_by_atomic_number[atomic_number]
@property
def atomic_number(self):
return self._atomic_number
@property
def name(self):
return self._name
@property
def symbol(self):
return self._symbol
@property
def mass(self):
return self._mass
def __str__(self):
return '<Element %s>' % self.name
def __repr__(self):
return '<Element %s>' % self.name
# This is for backward compatibility. # This is for backward compatibility.
def get_by_symbol(symbol): def get_by_symbol(symbol):
s = symbol.strip().upper() s = symbol.strip().upper()
......
...@@ -399,6 +399,7 @@ UNITS = { ...@@ -399,6 +399,7 @@ UNITS = {
'unit.kilojoule_per_mole/(unit.nanometer*unit.nanometer)')), 'unit.kilojoule_per_mole/(unit.nanometer*unit.nanometer)')),
("MonteCarloBarostat", "getFrequency") : (None, ()), ("MonteCarloBarostat", "getFrequency") : (None, ()),
("MonteCarloAnisotropicBarostat", "getFrequency") : (None, ()), ("MonteCarloAnisotropicBarostat", "getFrequency") : (None, ()),
("NonbondedForce", "getPMEParameters") : (None, ('1/unit.nanometer', None, None, None)),
("NonbondedForce", "getExceptionParameters") ("NonbondedForce", "getExceptionParameters")
: (None, (None, None, : (None, (None, None,
'unit.elementary_charge*unit.elementary_charge', 'unit.elementary_charge*unit.elementary_charge',
......
import pickle
import unittest
from simtk.unit import dalton
from simtk.openmm.app import element
class TestElement(unittest.TestCase):
def test_immutable(self):
def modifyElement():
# this should not be allowed
element.sulfur.mass = 100*dalton
self.assertRaises(AttributeError, modifyElement)
def test_pickleable(self):
newsulfur = pickle.loads(pickle.dumps(element.sulfur))
# make sure that a new object is not created during the pickle/unpickle
# cycle
assert element.sulfur == newsulfur
assert element.sulfur is newsulfur
assert id(element.sulfur) == id(newsulfur)
def test_attributes(self):
assert element.hydrogen.atomic_number == 1
assert element.hydrogen.symbol == 'H'
assert element.hydrogen.name == 'hydrogen'
assert element.hydrogen.mass == 1.007947 * dalton
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
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