Pteros  2.0
Molecular modeling library for human beings!
compiled_plugin.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2013, Semen Yesylevskyy
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of Artistic License:
13  *
14  * Please note, that Artistic License is slightly more restrictive
15  * then GPL license in terms of distributing the modified versions
16  * of this software (they should be approved first).
17  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
18  * for details. Such license fits scientific software better then
19  * GPL because it prevents the distribution of bugged derivatives.
20  *
21 */
22 
23 #ifndef COMPILED_PLUGIN_H
24 #define COMPILED_PLUGIN_H
25 
26 // this header is needed anyway
27 #include "pteros/python/compiled_plugin_base.h"
28 
29 #ifndef STANDALONE_PLUGINS
30 
31 // Make a Python extension module from this plugin
32 
33 #include "pteros/python/bindings_util.h"
34 
35 using namespace boost::python;
36 
37 #define CREATE_COMPILED_PLUGIN(_name) \
38 void Pteros_error_translator(const pteros::Pteros_error& e) { \
39  PyErr_SetString(PyExc_UserWarning, const_cast<pteros::Pteros_error&>(e).what().c_str()); \
40 } \
41 BOOST_PYTHON_MODULE(_name) \
42 { \
43  import_array(); \
44  boost::python::numeric::array::set_module_and_type("numpy", "ndarray"); \
45  register_exception_translator<pteros::Pteros_error>(&Pteros_error_translator); \
46  class_<_name,boost::noncopyable>("Task", init<pteros::Trajectory_processor*,const pteros::Options&>()) \
47  .def_readwrite("label",&_name::label) \
48  .def("help",&_name::help) \
49  ; \
50 }
51 
52 #else //STANDALONE_PLUGINS
53 
54 // Make a stand-alone executable from this plugin
55 
56 #include "pteros/core/pteros_error.h"
57 
58 using namespace pteros;
59 using namespace std;
60 
61 #define CREATE_COMPILED_PLUGIN(_name) \
62 int main(int argc, char** argv){\
63  try {\
64  Options options;\
65  parse_command_line(argc,argv,options);\
66  Trajectory_processor engine(options);\
67  _name task(&engine,options);\
68  task.label = #_name;\
69  cout << "-------------------------------------------------------------" << endl;\
70  cout << " This is stand-alone Pteros analysis plugin '" #_name "'" << endl;\
71  cout << "-------------------------------------------------------------" << endl;\
72  if(!options.has("f") && !options.has("help")){\
73  cout << "Usage:" << endl;\
74  cout << "\tpteros_" #_name " -f <files> <task options>" << endl;\
75  cout << "\n\tFor specific task options use '-help task'" << endl;\
76  cout << "\tFor trajectory processing options use '-help traj'" << endl;\
77  cout << "\tFor all available options use '-help all' or just '-help'" << endl;\
78  return 1;\
79  }\
80  if(options.has("help")){\
81  string help = options("help","").as_string();\
82  if(help=="traj"){\
83  cout << engine.help() << endl;\
84  } else if(help=="task"){\
85  cout << task.help() << endl;\
86  } else {\
87  cout << task.help() << endl << endl;\
88  cout << engine.help() << endl;\
89  }\
90  return 1;\
91  }\
92  engine.run();\
93  } catch(const Pteros_error& e) {\
94  cout << e.what() << endl;\
95  }\
96 }
97 
98 
99 #endif //STANDALONE_PLUGINS
100 
101 #endif //COMPILED_PLUGIN_H
Pteros namespace.
Definition: options.cpp:32
STL namespace.