Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about vector<Vec3> in swig interface file #21

Open
ajsilveira opened this issue Sep 16, 2020 · 5 comments
Open

Question about vector<Vec3> in swig interface file #21

ajsilveira opened this issue Sep 16, 2020 · 5 comments

Comments

@ajsilveira
Copy link

I am planning to write a new force that uses the RMSD between molecules and I will use the OpenMM RMSDForce as a base.
The first thing I did was to include in the plugin the OpenMM RMSDForce, which I named MyRMSDForce for now.
I am getting the following error when creating MyRMSDForce:

File "/home/silveira/miniconda3/lib/python3.6/site-packages/exampleplugin.py", line 394, in __init__
_exampleplugin.MyRMSDForce_swiginit(self, _exampleplugin.new_MyRMSDForce(*args))
TypeError: Wrong number or type of arguments for overloaded function 'new_MyRMSDForce'.
Possible C/C++ prototypes are:
ExamplePlugin::MyRMSDForce::MyRMSDForce(std::vector< OpenMM::Vec3,std::allocator< OpenMM::Vec3 > > const &,std::vector< int,std::allocator< int > > const &)
ExamplePlugin::MyRMSDForce::MyRMSDForce(std::vector< OpenMM::Vec3,std::allocator< OpenMM::Vec3 > > const &)

I think that the issue is related to the swig interface file
Should I add something in exampleplugin.i to handle <vector>Vec3? Thanks!

@peastman
Copy link
Member

That's correct, you need to provide a typemap for it. if you %include the typemaps.i file from the OpenMM source it should have everything you need: https://github.com/openmm/openmm/blob/master/wrappers/python/src/swig_doxygen/swig_lib/python/typemaps.i

@ajsilveira
Copy link
Author

It already has the line %include "swig/typemaps.i" as I included MyRMSDForce in the old exampleplugin.i file. I thought that Vec3 would require something similar to:


/*
 * The following lines are needed to handle std::vector.
 * Similar lines may be needed for vectors of vectors or
 * for other STL types like maps.
 */

%include "std_vector.i"
namespace std {
  %template(vectord) vector<double>;
  %template(vectori) vector<int>;

Do you think the error could be somewhere else? This is the repo: https://github.com/ajsilveira/openmm_rocsalt_plugin
Thanks!

@peastman
Copy link
Member

That's a different file. swig/typemaps.i is a file that comes with SWIG. I'm talking about a file that's included in the OpenMM source code, and defines typemaps for OpenMM classes like Vec3.

@ajsilveira
Copy link
Author

I copied the file wrappers/python/src/swig_doxygen/swig_lib/python/typemaps.i to the python directory in openmmexampleplugin and added the %include line as follows:

%module exampleplugin
%include "typemaps.i"
%import(module="simtk.openmm") "swig/OpenMMSwigHeaders.i"
%include "swig/typemaps.i"

I am still getting the same error.

@ndonyapour
Copy link

I got RMSDForce working as plugin and codes can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants