Skip to content

Commit e27a5c7

Browse files
committed
Added a method for casting Force to ExampleForce
1 parent 5c24825 commit e27a5c7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

python/exampleplugin.i

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ import simtk.unit as unit
3838
val[3] = unit.Quantity(val[3], unit.kilojoule_per_mole/unit.nanometer**4)
3939
%}
4040

41+
/*
42+
* Convert C++ exceptions to Python exceptions.
43+
*/
44+
%exception {
45+
try {
46+
$action
47+
} catch (std::exception &e) {
48+
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
49+
return NULL;
50+
}
51+
}
52+
4153

4254
namespace ExamplePlugin {
4355

@@ -66,6 +78,15 @@ public:
6678
%clear int& particle2;
6779
%clear double& length;
6880
%clear double& k;
81+
82+
/*
83+
* Add a function for casting a Force to an ExampleForce.
84+
*/
85+
%extend {
86+
static ExamplePlugin::ExampleForce& cast(OpenMM::Force& force) {
87+
return dynamic_cast<ExamplePlugin::ExampleForce&>(force);
88+
}
89+
}
6990
};
7091

7192
}

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
exampleplugin_library_dir = '@EXAMPLEPLUGIN_LIBRARY_DIR@'
1010

1111
# setup extra compile and link arguments on Mac
12-
extra_compile_args = []
12+
extra_compile_args = ['-std=c++11']
1313
extra_link_args = []
1414

1515
if platform.system() == 'Darwin':

0 commit comments

Comments
 (0)