All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Pbc.h
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #ifndef __PLUMED_tools_Pbc_h
23 #define __PLUMED_tools_Pbc_h
24 
25 #include "Vector.h"
26 #include "Tensor.h"
27 #include <vector>
28 #include <cstddef>
29 
30 namespace PLMD{
31 
32 /*
33 Tool to deal with periodic boundary conditions.
34 
35 This class is useful to apply periodic boundary conditions on interatomic
36 distances. It stores privately information about reduced lattice vectors
37 */
38 class Pbc{
39 /// Type of box
40  enum {unset,orthorombic,generic} type;
41 /// Box
43 /// Inverse box
45 /// Reduced box.
46 /// This is a set of lattice vectors generating the same lattice
47 /// but "minimally skewed". Useful to optimize image search.
49 /// Inverse of the reduced box
51 /// List of shifts that should be attempted.
52 /// Depending on the sign of the scaled coordinates representing
53 /// a distance vector, a different set of shifts must be tried.
54  std::vector<Vector> shifts[2][2][2];
55 /// Alternative representation for orthorombic cells.
56 /// Not really used, but could be used to optimize search in
57 /// orthorombic cells.
59 /// Build list of shifts.
60 /// This is expensive, and must be called only when box is
61 /// reset. It allows building a minimal set of shifts
62 /// depending on the sign of the scaled coordinates representing
63 /// a distance vector.
64  void buildShifts(std::vector<Vector> shifts[2][2][2])const;
65 /// Full search (for testing)
66  void fullSearch(Vector&)const;
67 /// internal version of distance, also returns the number
68 /// of attempted shifts (used in Pbc::test()).
69  Vector distance(const Vector&,const Vector&,int*nshifts)const;
70 public:
71 /// Perform some check. Useful for debugging.
72  static void test();
73 /// Constructor
74  Pbc();
75 /// Compute modulo of (v2-v1), using or not pbc depending on bool pbc.
76  double distance( const bool pbc, const Vector& v1, const Vector& v2 ) const;
77 /// Computes v2-v1, using minimal image convention
78  Vector distance(const Vector& v1,const Vector& v2)const;
79 /// Set the lattice vectors.
80 /// b[i][j] is the j-th component of the i-th vector
81  void setBox(const Tensor&b);
82 /// Returns the box
83  const Tensor& getBox()const;
84 /// Returns the inverse matrix of box.
85 /// Thus: pbc.getInvBox() == inverse(pbc.getBox()).
86  const Tensor& getInvBox()const;
87 /// Transform a vector in real space to a vector in scaled coordinates.
88 /// Thus:pbc.realToScaled(v) == matmul(transpose(inverse(pbc.getBox(),v)));
89  Vector realToScaled(const Vector&)const;
90 /// Transform a vector in scaled coordinates to a vector in real space.
91 /// Thus:pbc.scaledToRead(v) == matmul(transpose(pbc.getBox()),v);
92  Vector scaledToReal(const Vector&)const;
93 /// Returns true if the box vectors are orthogonal
94  bool isOrthorombic()const;
95 };
96 
97 inline
98 Vector Pbc::distance(const Vector& v1,const Vector& v2)const{
99  return distance(v1,v2,NULL);
100 }
101 
102 }
103 
104 #endif
Tensor invBox
Inverse box.
Definition: Pbc.h:44
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
enum PLMD::Pbc::@6 type
Type of box.
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
Tensor box
Box.
Definition: Pbc.h:42
Vector scaledToReal(const Vector &) const
Transform a vector in scaled coordinates to a vector in real space.
Definition: Pbc.cpp:206
Tensor reduced
Reduced box.
Definition: Pbc.h:48
Vector mdiag
Definition: Pbc.h:58
Vector diag
Alternative representation for orthorombic cells.
Definition: Pbc.h:58
Tensor invReduced
Inverse of the reduced box.
Definition: Pbc.h:50
Definition: Pbc.h:38
Vector distance(const Vector &, const Vector &, int *nshifts) const
internal version of distance, also returns the number of attempted shifts (used in Pbc::test())...
Definition: Pbc.cpp:158
std::vector< Vector > shifts[2][2][2]
List of shifts that should be attempted.
Definition: Pbc.h:54
const Tensor & getInvBox() const
Returns the inverse matrix of box.
Definition: Pbc.cpp:218
static void test()
Perform some check. Useful for debugging.
Definition: Pbc.cpp:222
void buildShifts(std::vector< Vector > shifts[2][2][2]) const
Build list of shifts.
Definition: Pbc.cpp:39
void fullSearch(Vector &) const
Full search (for testing)
Definition: Pbc.cpp:93
bool isOrthorombic() const
Returns true if the box vectors are orthogonal.
Definition: Pbc.cpp:210
Pbc()
Constructor.
Definition: Pbc.cpp:32
Vector hdiag
Definition: Pbc.h:58
Vector realToScaled(const Vector &) const
Transform a vector in real space to a vector in scaled coordinates.
Definition: Pbc.cpp:202
const Tensor & getBox() const
Returns the box.
Definition: Pbc.cpp:214
void setBox(const Tensor &b)
Set the lattice vectors.
Definition: Pbc.cpp:115