-
Notifications
You must be signed in to change notification settings - Fork 1
/
module_functions.f90
227 lines (159 loc) · 5.6 KB
/
module_functions.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Originally created by James McDonagh at the University of Manchester 2015, in the Popelier group !
! Components of the module are acknowledged to Dr Tanja van Mourik University of St Andrews !
! Licensed under MIT License !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Originally created by James.
! Version 1.1
! CHANGE LOG
! Version 1 : Functions for calculating strutcural parameters
! Version 1.1: Modular format and incorporation in the Hermes program.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module module_functions
use module_constants
implicit none
contains
function bond_vector(v1,v2)
!Dummy arguements
real, dimension(3) :: v1,v2
!Function argument
real, dimension(3) :: bond_vector
!local
integer :: i
do i=1,3
bond_vector(i)=v2(i)-v1(i)
end do
end function bond_vector
!************************************************************************
function dist(x1, y1, z1, x2, y2, z2) ! Calculates the distance between two coordinates given as separate values
implicit none ! Function originally created by Rob Coates Univeristy of Manchester 2015
real, dimension(3) :: vector
real :: distance2, dist, x1, y1, z1, x2, y2, z2
integer :: i
i = 0
distance2 = 0
dist = 0
vector = 0
vector(1) = x1 - x2
vector(2) = y1 - y2
vector(3) = z1 - z2
do i = 1,3,1
distance2 = distance2 + (vector(i)**2.0)
end do
dist = sqrt(distance2)
end function dist
!************************************************************************
Function norm(v)
!dummy arguments
real, dimension (3) :: v
!function result
real :: norm
norm=sqrt(v(1)*v(1) + v(2)*v(2) + v(3)*v(3))
! Print*, "norm is = ", norm ! JMcD DIAGNOSTIC PRINT
end Function norm
!************************************************************************
function normalise(vector,normal)
!Dummy arguments
real, dimension(3) :: vector
real :: normal
!fucntion argument
real, dimension(3) ::normalise
!local
integer :: inc
do inc=1,3,1
normalise(inc)=vector(inc)/normal
end do
end function normalise
!************************************************************************
function vector_cross(bvec1,bvec2)
!Dummy arguments
real, dimension(3) :: bvec1, bvec2
!Function argument
real, dimension(3) :: vector_cross
vector_cross(1)=(bvec1(2)*bvec2(3)-bvec1(3)*bvec2(2))
vector_cross(2)=(bvec1(3)*bvec2(1)-bvec1(1)*bvec2(3))
vector_cross(3)=(bvec1(1)*bvec2(2)-bvec1(2)*bvec2(1))
end function vector_cross
!************************************************************************
function vector_dot(v1,v2)
!Dummy arguments
real, dimension(3) :: v1, v2
!function argument
real :: vector_dot
vector_dot=v1(1)*v2(1)+v1(2)*v2(2)+v1(3)*v2(3)
end function vector_dot
!************************************************************************
function perdist(x1, y1, z1, x2, y2, z2, boxlen) ! Calculates the distance between two coordinates in periodic Boundary conditions
implicit none ! Function originally created by Rob Coates University of Manchester 2015
real, dimension(3) :: vector
real :: distance2, distance, x1, y1, z1, x2, y2, z2, boxlen, perdist, halfboxlen
integer :: i
i = 0
distance2 = 0
distance = 0
vector = 0
vector(1) = x1 - x2
vector(2) = y1 - y2
vector(3) = z1 - z2
halfboxlen = boxlen*0.5
do i = 1,3,1 ! R.C. takes into account periodic boundry conditions
if (vector(i).gt.halfboxlen) then
vector(i) = vector(i) - boxlen
! else if(vector(i).lt.-halfboxlen) then
! vector(i) = vector(i) + boxlen
else
cycle
end if
end do
do i = 1,3,1
distance2 = distance2 + (vector(i)**2.0)
end do
distance = sqrt(distance2)
perdist = distance
end function perdist
!************************************************************************
function distancemicro(x1, y1, z1, x2, y2, z2, bl) ! Calculates the distance between two coordinates
implicit none
real, dimension(3) :: vector
real :: distance2, distancemicro, x1, y1, z1, x2, y2, z2, bl
integer :: i
i = 0
distance2 = 0
distancemicro = 0
vector = 0
vector(1) = x1 - x2
vector(2) = y1 - y2
vector(3) = z1 - z2
do i = 1,3,1 !takes into account periodic boundry conditions
if (vector(i).GT.(bl*0.5)) then
vector(i) = vector(i) - bl
else
cycle
end if
end do
do i = 1,3,1
distance2 = distance2 + (vector(i)**2.0)
end do
distancemicro = sqrt(distance2)
end function distancemicro
!************************************************************************
function distmicro(x1, y1, z1, x2, y2, z2) ! Calculates the distance between two coordinates
implicit none
real, dimension(3) :: vector
real :: distance2, distmicro, x1, y1, z1, x2, y2, z2
integer :: i
i = 0
distance2 = 0
distmicro = 0
vector = 0
vector(1) = x1 - x2
vector(2) = y1 - y2
vector(3) = z1 - z2
do i = 1,3,1
distance2 = distance2 + (vector(i)**2.0)
end do
distmicro = sqrt(distance2)
end function distmicro
!************************************************************************
end module module_functions