Pteros  2.0
Molecular modeling library for human beings!
periodic_box.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 <Eigen/Core>
34 #include "pteros/core/typedefs.h"
35 
36 namespace pteros {
37 
43 class PeriodicBox {
44 public:
45 
47  PeriodicBox();
48 
50  PeriodicBox(Matrix3f_const_ref m);
51 
53  PeriodicBox(Vector3f_const_ref vectors, Vector3f_const_ref angles);
54 
56  PeriodicBox(const PeriodicBox& other);
57 
59  PeriodicBox& operator=(const PeriodicBox& other);
60 
61  // Get box element
62  float get_element(int i, int j) const;
63 
64  // Set box element
65  void set_element(int i, int j, float val);
66 
68  Eigen::Vector3f get_vector(int i) const;
69 
71  void set_vector(Vector3f_const_ref vec, int i);
72 
74  Eigen::Matrix3f get_matrix() const;
75 
77  void set_matrix(Matrix3f_const_ref box);
78 
81  void scale_vectors(Vector3f_const_ref scale);
82 
84  Eigen::Matrix3f get_inv_matrix() const;
85 
87  Eigen::Vector3f lab_to_box(Vector3f_const_ref point) const;
88 
90  Eigen::Matrix3f lab_to_box_transform() const;
91 
93  Eigen::Vector3f box_to_lab(Vector3f_const_ref point) const;
94 
96  Eigen::Matrix3f box_to_lab_transform() const;
97 
99  float extent(int i) const;
100 
102  Eigen::Vector3f extents() const;
103 
105  bool is_triclinic() const {return _is_triclinic;}
106 
108  bool is_periodic() const {return _is_periodic;}
109 
117  float distance(Vector3f_const_ref point1,
118  Vector3f_const_ref point2,
119  Array3i_const_ref pbc = fullPBC) const;
120 
122  float distance_squared(Vector3f_const_ref point1,
123  Vector3f_const_ref point2,
124  Array3i_const_ref pbc = fullPBC) const;
125 
128  void wrap_point(Vector3f_ref point,
129  Array3i_const_ref pbc = fullPBC,
130  Vector3f_const_ref origin = Eigen::Vector3f::Zero()) const;
131 
134  bool in_box(Vector3f_const_ref point, Vector3f_const_ref origin = Eigen::Vector3f::Zero()) const;
135 
137  Eigen::Vector3f closest_image(Vector3f_const_ref point,
138  Vector3f_const_ref target,
139  Array3i_const_ref pbc = fullPBC) const;
140 
142  Eigen::Vector3f shortest_vector(Vector3f_const_ref point1,
143  Vector3f_const_ref point2,
144  Array3i_const_ref pbc = fullPBC) const;
145 
147  float volume();
148 
150  void from_pdb_box(const char *line);
151 
153  std::string to_pdb_box() const;
154 
156  void to_vectors_angles(Vector3f_ref vectors, Vector3f_ref angles) const;
157 
161  void from_vectors_angles(Vector3f_const_ref vectors, Vector3f_const_ref angles);
162 
163 
164 private:
165  Eigen::Matrix3f _box;
166  Eigen::Matrix3f _box_inv;
167  bool _is_triclinic;
168  bool _is_periodic;
169 
170  void recompute_internals();
171 };
172 
173 }
174 
175 
176 
177 
pteros::PeriodicBox::closest_image
Eigen::Vector3f closest_image(Vector3f_const_ref point, Vector3f_const_ref target, Array3i_const_ref pbc=fullPBC) const
Finds a periodic image of point, which is closest in space to target and returns it
Definition: periodic_box.cpp:172
pteros::PeriodicBox::lab_to_box
Eigen::Vector3f lab_to_box(Vector3f_const_ref point) const
Convert point from lab coordinates to box coordinates.
Definition: periodic_box.cpp:111
pteros::PeriodicBox::from_pdb_box
void from_pdb_box(const char *line)
Read box from CRYST string in PDB format. Overwrites current box!
Definition: periodic_box.cpp:226
pteros::PeriodicBox::to_vectors_angles
void to_vectors_angles(Vector3f_ref vectors, Vector3f_ref angles) const
Returns representation of the box as vector lengths and angles.
Definition: periodic_box.cpp:297
pteros::PeriodicBox::is_triclinic
bool is_triclinic() const
Is the box triclinic?
Definition: periodic_box.h:105
pteros::PeriodicBox::from_vectors_angles
void from_vectors_angles(Vector3f_const_ref vectors, Vector3f_const_ref angles)
Creates box from vector length and angles.
Definition: periodic_box.cpp:342
pteros::PeriodicBox::is_periodic
bool is_periodic() const
Is the box set? If false, the system is not periodic.
Definition: periodic_box.h:108
pteros::PeriodicBox::extent
float extent(int i) const
Return i-th extent of the box.
Definition: periodic_box.cpp:127
pteros::PeriodicBox::in_box
bool in_box(Vector3f_const_ref point, Vector3f_const_ref origin=Eigen::Vector3f::Zero()) const
Determine if the point is inside the box Origin of the box coordinates defaults to {0,...
Definition: periodic_box.cpp:161
pteros::PeriodicBox::get_inv_matrix
Eigen::Matrix3f get_inv_matrix() const
Get stored inverted matrix of box vectors.
Definition: periodic_box.cpp:107
pteros::PeriodicBox::operator=
PeriodicBox & operator=(const PeriodicBox &other)
Assignment operator.
Definition: periodic_box.cpp:63
pteros::PeriodicBox::box_to_lab
Eigen::Vector3f box_to_lab(Vector3f_const_ref point) const
Convert point from box coordinates to lab coordinates.
Definition: periodic_box.cpp:119
pteros::PeriodicBox::to_pdb_box
std::string to_pdb_box() const
Write box as CRYST string in PDB format.
Definition: periodic_box.cpp:318
pteros::PeriodicBox::get_matrix
Eigen::Matrix3f get_matrix() const
Get stored matrix of box vectors.
Definition: periodic_box.cpp:96
pteros::PeriodicBox::shortest_vector
Eigen::Vector3f shortest_vector(Vector3f_const_ref point1, Vector3f_const_ref point2, Array3i_const_ref pbc=fullPBC) const
Computes shortest vector from point1 to point2 between their closest images.
Definition: periodic_box.cpp:177
pteros::PeriodicBox::scale_vectors
void scale_vectors(Vector3f_const_ref scale)
Scale box vectors by specified factors.
Definition: periodic_box.cpp:100
pteros::PeriodicBox::set_vector
void set_vector(Vector3f_const_ref vec, int i)
Set i-th box vector.
Definition: periodic_box.cpp:90
pteros::PeriodicBox
Class encapsulating all operations with arbitrary triclinic periodic boxes This class stores the peri...
Definition: periodic_box.h:43
pteros::PeriodicBox::distance
float distance(Vector3f_const_ref point1, Vector3f_const_ref point2, Array3i_const_ref pbc=fullPBC) const
Compute a periodic distance between two points in the box Periodicity is only accouted for given set ...
Definition: periodic_box.cpp:140
pteros::PeriodicBox::distance_squared
float distance_squared(Vector3f_const_ref point1, Vector3f_const_ref point2, Array3i_const_ref pbc=fullPBC) const
The same as distance but returns squared distance.
Definition: periodic_box.cpp:135
pteros::PeriodicBox::get_vector
Eigen::Vector3f get_vector(int i) const
Get i-th box vector.
Definition: periodic_box.cpp:86
pteros::PeriodicBox::set_matrix
void set_matrix(Matrix3f_const_ref box)
Modify the box from 3x3 matrix.
Definition: periodic_box.cpp:80
pteros::PeriodicBox::lab_to_box_transform
Eigen::Matrix3f lab_to_box_transform() const
Return the transformation from lab coordinates to box coordinates.
Definition: periodic_box.cpp:115
pteros::PeriodicBox::wrap_point
void wrap_point(Vector3f_ref point, Array3i_const_ref pbc=fullPBC, Vector3f_const_ref origin=Eigen::Vector3f::Zero()) const
Wrap point to the box for given set of dimensions Origin of the box coordinates defaults to {0,...
Definition: periodic_box.cpp:149
pteros::PeriodicBox::extents
Eigen::Vector3f extents() const
Return the vector of box extents.
Definition: periodic_box.cpp:131
pteros::PeriodicBox::volume
float volume()
Returns box volume.
Definition: periodic_box.cpp:145
pteros::PeriodicBox::box_to_lab_transform
Eigen::Matrix3f box_to_lab_transform() const
Return the transformation from box coordinates to lab coordinates.
Definition: periodic_box.cpp:123
pteros::PeriodicBox::PeriodicBox
PeriodicBox()
Default constructor.
Definition: periodic_box.cpp:46