Pteros  2.0
Molecular modeling library for human beings!
compiled_plugin.h
1 /*
2  * This file is a part of
3  *
4  * ============================================
5  * ### Pteros molecular modeling library ###
6  * ============================================
7  *
8  * https://github.com/yesint/pteros
9  *
10  * (C) 2009-2021, Semen Yesylevskyy
11  *
12  * All works, which use Pteros, should cite the following papers:
13  *
14  * 1. Semen O. Yesylevskyy, "Pteros 2.0: Evolution of the fast parallel
15  * molecular analysis library for C++ and python",
16  * Journal of Computational Chemistry, 2015, 36(19), 1480–1488.
17  * doi: 10.1002/jcc.23943.
18  *
19  * 2. Semen O. Yesylevskyy, "Pteros: Fast and easy to use open-source C++
20  * library for molecular analysis",
21  * Journal of Computational Chemistry, 2012, 33(19), 1632–1636.
22  * doi: 10.1002/jcc.22989.
23  *
24  * This is free software distributed under Artistic License:
25  * http://www.opensource.org/licenses/artistic-license-2.0.php
26  *
27 */
28 
29 #pragma once
30 
31 #include "pteros/analysis/task_plugin.h"
32 
33 #ifndef STANDALONE_PLUGINS
34 
35 // Make a Python extension module from this plugin
36 
37 #include <pybind11/pybind11.h>
38 #include <pybind11/functional.h>
39 #include <pybind11/operators.h>
40 #include <pybind11/stl.h>
41 #include <pybind11/eigen.h>
42 #include <pybind11/operators.h>
43 
44 namespace py = pybind11;
45 
46 #define _EVAL(arg) #arg
47 #define CREATE_COMPILED_PLUGIN(_name) \
48 PYBIND11_MODULE(_name, m) {\
49  py::class_<_name,TaskPlugin,std::shared_ptr<_name>>(m, _EVAL(_name))\
50  .def(py::init<const Options&>())\
51  .def("help",&_name::help)\
52  ;\
53 }
54 
55 #else //STANDALONE_PLUGINS
56 
57 // Make a stand-alone executable from this plugin
58 
59 #include "pteros/analysis/trajectory_reader.h"
60 #include "pteros/core/pteros_error.h"
61 #include "pteros/core/logging.h"
62 
63 using namespace pteros;
64 using namespace std;
65 
66 // Skeleton of the driver program
67 
68 #define CREATE_COMPILED_PLUGIN(_name)\
69 int main(int argc, char** argv){\
70  try {\
71  Options options;\
72  parse_command_line(argc,argv,options);\
73  Trajectory_reader engine(options);\
74  auto task = new _name(options);\
75  engine.add_task(task);\
76  cout << "-------------------------------------------------------------" << endl;\
77  cout << " This is stand-alone Pteros analysis plugin '" #_name "'" << endl;\
78  cout << "-------------------------------------------------------------" << endl;\
79  if(!options.has("f") && !options.has("help")){\
80  cout << "Usage:" << endl;\
81  cout << "\tpteros_" #_name " -f <files> <task options>" << endl;\
82  cout << "\n\tFor specific task options use '-help task'" << endl;\
83  cout << "\tFor trajectory processing options use '-help traj'" << endl;\
84  cout << "\tFor all available options use '-help all' or just '-help'" << endl;\
85  return 1;\
86  }\
87  if(options.has("help")){\
88  string help = options("help","").as_string();\
89  if(help=="traj"){\
90  cout << engine.help() << endl;\
91  } else if(help=="task"){\
92  cout << task->help() << endl;\
93  } else {\
94  cout << task->help() << endl << endl;\
95  cout << engine.help() << endl;\
96  }\
97  return 1;\
98  }\
99  engine.run();\
100  } catch (const std::exception& e) { \
101  LOG()->error(e.what()); \
102  } catch(...) { \
103  LOG()->error("Unknown error"); \
104  }\
105 }
106 
107 
108 #endif //STANDALONE_PLUGINS
109 
110 
111 
112