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

Add exception PDBQT_PARSE_ERROR for python #100

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions build/python/vina/autodock_vina.i
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "tree.h"
#include "triangular_matrix_index.h"
#include "utils.h"
SWIGRUNTIME PyObject* pPDBQT_PARSE_ERROR;
%}

// Set and reset dlopenflags so that plugin loading works fine for "import _openbabel"
Expand All @@ -75,17 +76,41 @@ if sys.platform.find("linux") != -1:
sys.setdlopenflags(dlflags | ctypes.RTLD_GLOBAL)
%}
%pythoncode %{
PDBQT_PARSE_ERROR = _vina_wrapper.PDBQT_PARSE_ERROR
if sys.platform.find("linux") != -1:
sys.setdlopenflags(dlflags)
%}

%init %{
pPDBQT_PARSE_ERROR = PyErr_NewException("_vina_wrapper.PDBQT_PARSE_ERROR", NULL, NULL);
Py_INCREF(pPDBQT_PARSE_ERROR);
PyModule_AddObject(m, "PDBQT_PARSE_ERROR", pPDBQT_PARSE_ERROR);
%}
// Add standard C++ library
%include "std_array.i"
%include "std_list.i"
%include "std_map.i"
%include "std_vector.i"
%include "std_string.i"

%include "stl.i"
%include "exception.i"
%exception set_ligand_from_string{
try {
$action
}
catch (const pdbqt_parse_error & e) {
PyErr_SetString(pPDBQT_PARSE_ERROR, e.what());
SWIG_fail;
}
}
%exception set_ligand_from_file{
try {
$action
}
catch (const pdbqt_parse_error & e) {
PyErr_SetString(pPDBQT_PARSE_ERROR, e.what());
SWIG_fail;
}
}
// Help SWIG to understand some special types, like list of strings
namespace std {
%template(IntVector) vector<int>;
Expand Down
24 changes: 12 additions & 12 deletions src/lib/parse_pdbqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,13 @@ model parse_ligand_pdbqt_from_file(const std::string& name, atom_type::t atype)
non_rigid_parsed nrp;
context c;

try {
// try {
parse_pdbqt_ligand(make_path(name), nrp, c);
}
catch(pdbqt_parse_error& e) {
std::cerr << e.what();
exit(EXIT_FAILURE);
}
// }
// catch(pdbqt_parse_error& e) {
// std::cerr << e.what();
// exit(EXIT_FAILURE);
// }

pdbqt_initializer tmp(atype);
tmp.initialize_from_nrp(nrp, c, true);
Expand All @@ -643,14 +643,14 @@ model parse_ligand_pdbqt_from_string(const std::string& string_name, atom_type::
non_rigid_parsed nrp;
context c;

try {
// try {
std::stringstream molstream(string_name);
parse_pdbqt_ligand(molstream, nrp, c);
}
catch(pdbqt_parse_error& e) {
std::cerr << e.what() << '\n';
exit(EXIT_FAILURE);
}
// }
// catch(pdbqt_parse_error& e) {
// std::cerr << e.what() << '\n';
// exit(EXIT_FAILURE);
// }

pdbqt_initializer tmp(atype);
tmp.initialize_from_nrp(nrp, c, true);
Expand Down