Pteros  2.0
Molecular modeling library for human beings!
periodic_box.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 PERIODIC_BOX_H
24 #define PERIODIC_BOX_H
25 
26 #include <string>
27 #include <Eigen/Core>
28 #include "pteros/core/typedefs.h"
29 
30 namespace pteros {
31 
47 class Periodic_box {
48 public:
49 
51  Periodic_box();
52 
54  Periodic_box(Matrix3f_const_ref box);
55 
57  Periodic_box(Vector3f_const_ref vectors, Vector3f_const_ref angles);
58 
61 
63  void modify(Matrix3f_const_ref box);
64 
66  Eigen::Vector3f get_vector(int i);
67 
69  Eigen::Matrix3f get_matrix() const;
70 
73  void scale_vectors(Vector3f_const_ref scale);
74 
76  Eigen::Matrix3f get_inv_matrix() const;
77 
79  Eigen::Vector3f lab_to_box(Vector3f_const_ref point) const;
80 
82  Eigen::Matrix3f lab_to_box_transform() const;
83 
85  Eigen::Vector3f box_to_lab(Vector3f_const_ref point) const;
86 
88  Eigen::Matrix3f box_to_lab_transform() const;
89 
91  float extent(int i) const;
92 
94  Eigen::Vector3f extents() const;
95 
97  bool is_triclinic() const {return _is_triclinic;}
98 
100  bool is_periodic() const {return _is_periodic;}
101 
109  float distance(Vector3f_const_ref point1,
110  Vector3f_const_ref point2,
111  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
112 
114  float distance_squared(Vector3f_const_ref point1,
115  Vector3f_const_ref point2,
116  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
117 
120  void wrap_point(Vector3f_ref point,
121  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
122 
125  bool in_box(Vector3f_const_ref point, Vector3f_const_ref origin = Eigen::Vector3f::Zero()) const;
126 
128  Eigen::Vector3f get_closest_image(Vector3f_const_ref point,
129  Vector3f_const_ref target,
130  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
131 
133  Eigen::Vector3f shortest_vector(Vector3f_const_ref point1,
134  Vector3f_const_ref point2,
135  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
136 
138  float volume();
139 
141  void read_pdb_box(const char *line);
142 
144  std::string write_pdb_box() const;
145 
147  void to_vectors_angles(Vector3f_ref vectors, Vector3f_ref angles) const;
148 
152  void from_vectors_angles(Vector3f_const_ref vectors, Vector3f_const_ref angles);
153 
154 
155 private:
156  Eigen::Matrix3f _box;
157  Eigen::Matrix3f _box_inv;
158  bool _is_triclinic;
159  bool _is_periodic;
160 };
161 
162 }
163 
164 #endif /* ATOM_H */
bool is_periodic() const
Is the box set? If false, the system is not periodic.
Definition: periodic_box.h:100
Eigen::Matrix3f box_to_lab_transform() const
Return the transformation from box coordinates to lab coordinates.
Definition: periodic_box.cpp:92
float distance(Vector3f_const_ref point1, Vector3f_const_ref point2, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Compute a periodic distance between two points in the box Periodicity is only accouted for given set ...
Definition: periodic_box.cpp:109
Eigen::Vector3f lab_to_box(Vector3f_const_ref point) const
Convert point from lab coordinates to box coordinates.
Definition: periodic_box.cpp:80
void read_pdb_box(const char *line)
Read box from CRYST string in PDB format. Overwrites current box!
Definition: periodic_box.cpp:195
Pteros namespace.
Definition: options.cpp:32
Periodic_box & operator=(Periodic_box other)
Copy constructor.
Definition: periodic_box.cpp:47
void modify(Matrix3f_const_ref box)
Modify the box from 3x3 matrix.
Definition: periodic_box.cpp:52
std::string write_pdb_box() const
Write box as CRYST string in PDB format.
Definition: periodic_box.cpp:287
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:130
float extent(int i) const
Return i-th extent of the box.
Definition: periodic_box.cpp:96
Eigen::Vector3f box_to_lab(Vector3f_const_ref point) const
Convert point from box coordinates to lab coordinates.
Definition: periodic_box.cpp:88
Eigen::Vector3f extents() const
Return the vector of box extents.
Definition: periodic_box.cpp:100
float distance_squared(Vector3f_const_ref point1, Vector3f_const_ref point2, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
The same as distance but returns squared distance.
Definition: periodic_box.cpp:104
Eigen::Vector3f shortest_vector(Vector3f_const_ref point1, Vector3f_const_ref point2, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Computes shortest vector from point1 to point2 between their closest images.
Definition: periodic_box.cpp:146
Eigen::Matrix3f get_inv_matrix() const
Get stored inverted matrix of box vectors.
Definition: periodic_box.cpp:76
Periodic_box()
Default constructor.
Definition: periodic_box.cpp:36
Eigen::Vector3f get_closest_image(Vector3f_const_ref point, Vector3f_const_ref target, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Finds a periodic image of point, which is closest in space to target and returns it.
Definition: periodic_box.cpp:141
void scale_vectors(Vector3f_const_ref scale)
Scale box vectors by specified factors.
Definition: periodic_box.cpp:69
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:266
Eigen::Matrix3f lab_to_box_transform() const
Return the transformation from lab coordinates to box coordinates.
Definition: periodic_box.cpp:84
Eigen::Vector3f get_vector(int i)
Get i-th box vector.
Definition: periodic_box.cpp:61
bool is_triclinic() const
Is the box triclinic?
Definition: periodic_box.h:97
void wrap_point(Vector3f_ref point, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Wrap point to the box for given set of dimensions Origin of the box coordinates is assumed to be {0...
Definition: periodic_box.cpp:118
float volume()
Returns box volume.
Definition: periodic_box.cpp:114
Eigen::Matrix3f get_matrix() const
Get stored matrix of box vectors.
Definition: periodic_box.cpp:65
void from_vectors_angles(Vector3f_const_ref vectors, Vector3f_const_ref angles)
Creates box from vector length and angles.
Definition: periodic_box.cpp:311
Class encapsulating all operations with arbitrary triclinic periodic boxes This class stores the peri...
Definition: periodic_box.h:47