Pteros  2.0
Molecular modeling library for human beings!
utilities.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 "pteros/core/typedefs.h"
33 #include "pteros/core/selection.h"
34 #include <vector>
35 
36 #ifndef M_PI
37  #define M_PI 3.14159265358979323846
38 #endif
39 
40 #ifndef M_PI_2
41  #define M_PI_2 9.86960440108935712052951
42 #endif
43 
44 namespace pteros {
45 
46  float angle_between_vectors(Vector3f_const_ref vec1, Vector3f_const_ref vec2);
47 
48  Eigen::Vector3f project_vector(Vector3f_const_ref vec1, Vector3f_const_ref vec2);
49 
50  float rad_to_deg(float ang);
51  float deg_to_rad(float ang);
52 
53  constexpr long double operator"" _deg (long double ang) {
54  return ang*3.141592/180.0;
55  }
56 
57  constexpr long double operator"" _rad (long double ang) {
58  return ang*180.0/3.141592;
59  }
60 
61  std::string get_element_name(int elnum);
62 
63  int get_element_number(const std::string& name);
64 
65  float get_vdw_radius(int elnum, const std::string& name);
66 
67  // Guess element using VMD logic
68  void guess_element(const std::string& name, int& anum, float& mass);
69 
70  // Guess element using our own simplified logic
71  void get_element_from_atom_name(const std::string& name, int& anum, float& mass);
72 
74  Eigen::Affine3f rotation_transform(Vector3f_const_ref pivot, Vector3f_const_ref axis, float angle);
75 
77  char resname_1char(const std::string& code);
79  std::string resname_3char(char code);
80 
81  // Conversions
82  int str_to_int(const std::string& str);
83  float str_to_float(const std::string& str);
84  void str_to_lower_in_place(std::string& str);
85  void str_to_upper_in_place(std::string& str);
86  std::string str_to_lower_copy(const std::string& str);
87  void str_trim_in_place(std::string &s);
88 
89  std::string time_pretty_print(float t);
90 
92  class Histogram {
93  public:
94  Histogram(){}
95  Histogram(float minval, float maxval, int n);
96  void create(float minval, float maxval, int n);
97  int get_bin(float v);
98  void add(float v, float weight=1.0);
99  void add(const std::vector<float> &v);
100  void add(const std::vector<float> &v, const std::vector<float> &w);
101  void add_cylindrical(float r, float w, float sector, float cyl_h);
103  void add_sel_cylindrical(const Selection &sel, Vector3f_const_ref pivot, Array3i_const_ref dims, float sector, float cyl_h);
104  void normalize(float norm=0);
105  float value(int i) const;
106  float position(int i) const;
107  float delta() const {return d;}
108  Eigen::VectorXd &values();
109  Eigen::VectorXd& positions();
110  int num_bins() const;
111  void save_to_file(const std::string& fname, float x_shift=0);
112  private:
113  int nbins;
114  float minv,maxv,d;
115  Eigen::VectorXd val;
116  Eigen::VectorXd pos;
117  bool normalized;
118  };
119 
121  class Histogram2D {
122  public:
123  Histogram2D(){}
124  Histogram2D(float minval1, float maxval1, int n1, float minval2, float maxval2, int n2);
125  void create(float minval1, float maxval1, int n1, float minval2, float maxval2, int n2);
126  void add(float v1, float v2, float weight=1.0);
127  void normalize(float norm=0);
128  Eigen::Vector2f delta() const {return d;}
129  float value(int i,int j) const;
130 
131  void save_to_file(const std::string& fname);
132  private:
133  Eigen::Vector2i nbins;
134  Eigen::Vector2f minv,maxv,d;
135  Eigen::MatrixXd val;
136 
137  bool normalized;
138  };
139 
140  void greeting(std::string tool_name="");
141 
142 } // namespace
143 
144 
145 
146 
147 
pteros::Selection
Selection class.
Definition: selection.h:65
pteros::Histogram2D
Simple 2D histogram class.
Definition: utilities.h:121
pteros::Histogram
Simple histogram class.
Definition: utilities.h:92
pteros::Histogram::add_sel_cylindrical
void add_sel_cylindrical(const Selection &sel, Vector3f_const_ref pivot, Array3i_const_ref dims, float sector, float cyl_h)
Add whole selection to cylindrical histogram.
Definition: utilities.cpp:301