Pteros  2.0
Molecular modeling library for human beings!
selection_parser.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 
30 #pragma once
31 
32 #include <string>
33 #include <vector>
34 #include <memory>
35 
36 #include "pteros/core/system.h"
37 #include "peglib.h"
38 
39 namespace pteros {
40 
41 // Custom annoation for peglib ast structure
42 struct MyAstAnnotation {
43  bool is_coord_dependent;
44  std::vector<int> precomputed;
45  float numeric_value;
46 };
47 
48 typedef peg::AstBase<MyAstAnnotation> MyAst;
49 typedef std::function<void(std::vector<int>&)> result_func_t;
50 
60 public:
67  bool has_coord; //There are coordinates in selection
69  SelectionParser(std::vector<int>* subset = nullptr);
71  virtual ~SelectionParser();
73  void create_ast(std::string& sel_str, System *system);
76  void apply_ast(std::size_t fr, std::vector<int>& result);
77 
78 private:
80  std::shared_ptr<MyAst> tree;
81 
82  // AST evaluation stuff
83  System* sys;
84  int Natoms;
85  int frame;
86 
87  void eval_node(const std::shared_ptr<MyAst> &node, std::vector<int>& result);
88  std::function<float(int)> get_numeric(const std::shared_ptr<MyAst>& node);
89  Eigen::Vector3f get_vector(const std::shared_ptr<MyAst> &node);
90 
91  std::vector<int>* starting_subset;
92  std::vector<int>* current_subset;
93 
94  void precompute(std::shared_ptr<MyAst> &node);
95  void optimize_numeric(std::shared_ptr<MyAst> &node);
96 };
97 
98 }
99 
100 
101 
102 
103 
pteros::SelectionParser::create_ast
void create_ast(std::string &sel_str, System *system)
Generates AST from selection string.
Definition: selection_parser.cpp:157
pteros::System
The system of atoms.
Definition: system.h:93
pteros::SelectionParser::SelectionParser
SelectionParser(std::vector< int > *subset=nullptr)
Constructor.
Definition: selection_parser.cpp:89
pteros::SelectionParser::~SelectionParser
virtual ~SelectionParser()
Destructor.
Definition: selection_parser.cpp:97
pteros::SelectionParser
Selection parser class.
Definition: selection_parser.h:59
pteros::SelectionParser::apply_ast
void apply_ast(std::size_t fr, std::vector< int > &result)
Apply ast to the given frame.
Definition: selection_parser.cpp:182
pteros::SelectionParser::has_coord
bool has_coord
True if there are coordinate keywords in selection.
Definition: selection_parser.h:67