1
"""Contains the classes which deal with the system box.
3
Copyright (C) 2013, Joshua More and Michele Ceriotti
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http.//www.gnu.org/licenses/>.
19
Used for implementing the minimum image convention.
22
Cell: Base cell class with the generic methods and attributes.
28
from ipi.utils.depend import *
29
from ipi.utils.mathtools import *
30
from ipi.utils import units
34
"""Base class to represent the simulation cell in a periodic system.
36
This class has the base attributes required for either flexible or
37
isotropic cell dynamics. Uses an upper triangular lattice vector matrix to
41
h: An array giving the lattice vector matrix.
42
ih: An array giving the inverse of the lattice vector matrix.
43
V: The volume of the cell.
46
def __init__(self, h=None):
47
"""Initialises base cell class.
50
h: Optional array giving the initial lattice vector matrix. The
51
reference cell matrix is set equal to this. Must be an upper
52
triangular 3*3 matrix. Defaults to a 3*3 zeroes matrix.
56
#h = np.identity(3,float)
57
h = np.zeros((3,3), float)
58
dset(self,"h",depend_array(name = 'h', value = h) )
61
depend_array(name = "ih", value = np.zeros((3,3),float),
62
func=self.get_ih, dependencies=[dget(self,"h")]) )
64
depend_value(name = 'V', func=self.get_volume,
65
dependencies=[dget(self,"h")]) )
68
"""Inverts the lattice vector matrix."""
70
return invert_ut3x3(self.h)
73
"""Calculates the volume of the system box."""
75
return det_ut3x3(self.h)
77
def apply_pbc(self, atom):
78
"""Uses the minimum image convention to return a particle to the
85
An array giving the position of the image that is inside the
89
s = np.dot(self.ih,atom.q)
93
s[i] = s[i] - round(s[i])
95
return np.dot(self.h,s)
97
def array_pbc(self, pos):
98
"""Uses the minimum image convention to return a list of particles to the
102
atom: An Atom object.
105
An array giving the position of the image that is inside the
109
s = depstrip(pos).copy()
110
s.shape = (len(pos)/3,3)
112
s = np.dot(depstrip(self.ih),s.T)
115
s = np.dot(depstrip(self.h),s).T
117
pos[:] = s.reshape((len(s)*3))
119
def minimum_distance(self, atom1, atom2):
120
"""Takes two atoms and tries to find the smallest vector between two
123
This is only rigorously accurate in the case of a cubic cell,
124
but gives the correct results as long as the cut-off radius is defined
125
as smaller than the smallest width between parallel faces even for
129
atom1: An Atom object.
130
atom2: An Atom object.
133
An array giving the minimum distance between the positions of atoms
134
atom1 and atom2 in the minimum image convention.
137
s = np.dot(self.ih,atom1.q-atom2.q)
140
return np.dot(self.h, s)