File: suv.f

package info (click to toggle)
raster3d 3.0-2-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,988 kB
  • sloc: fortran: 10,785; ansic: 1,057; makefile: 317; sh: 252; csh: 15
file content (188 lines) | stat: -rw-r--r-- 4,024 bytes parent folder | download | duplicates (6)
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
	FUNCTION CCuij(UU,VV)
C       ===============================================================
C	Correlation coefficient between two (3x3) anisotropic 
C	displacement matrices Uij and Vij.
C	See Merritt (1999) Acta Crystallographica D55, 1997-2004.
C	Return 0 if any of the tensors involved are NPD
C       ===============================================================
	REAL CCuij V3VINV
	REAL UU(3,3), VV(3,3), WW(3,3), UI(3,3), VI(3,3), WI(3,3)
	REAL DUI, DVI, DWI
	DUI = 1. / V3INV(UI,UU)
	DVI = 1. / V3INV(VI,VV)
C	Sylvester's criterion for NPD tensor
	IF (DUI.LE.0 .OR. UU(1,1).LE.0 
     &   .OR. (UU(1,1)*UU(2,2)-UU(1,2)*UU(2,1)).LE.0) THEN
		CCuij = 0
		RETURN
	ENDIF
	IF (DVI.LE.0 .OR. VV(1,1).LE.0 
     &   .OR. (VV(1,1)*VV(2,2)-VV(1,2)*VV(2,1)).LE.0) THEN
		CCuij = 0
		RETURN
	ENDIF
	CALL M3ADD(WI,UI,VI)
	DWI = V3INV(WW,WI)
	IF (DWI.LE.0 .OR. WW(1,1).LE.0
     &   .OR. (WW(1,1)*WW(2,2)-WW(1,2)*WW(2,1)).LE.0) THEN
		CCuij = 0
		RETURN
	ENDIF
	CCuij 	= sqrt(sqrt(DUI*DVI))
     &		/ sqrt(0.125*DWI)
	RETURN
	END


	FUNCTION CCuv(U,V)
C       ===============================================================
C	Wrapper for CCuij()
C       ===============================================================
	REAL CCuv, CCuij
	REAL U(6), V(6)
	REAL UU(3,3), VV(3,3)
	UU(1,1) = U(1)
	UU(2,2) = U(2)
	UU(3,3) = U(3)
	UU(1,2) = U(4)
	UU(2,1) = U(4)
	UU(1,3) = U(5)
	UU(3,1) = U(5)
	UU(2,3) = U(6)
	UU(3,2) = U(6)
	VV(1,1) = V(1)
	VV(2,2) = V(2)
	VV(3,3) = V(3)
	VV(1,2) = V(4)
	VV(2,1) = V(4)
	VV(1,3) = V(5)
	VV(3,1) = V(5)
	VV(2,3) = V(6)
	VV(3,2) = V(6)
	CCuv = CCuij(UU,VV)
	RETURN
	END

	FUNCTION Suv(U,V)
C       ===============================================================
C	Normalized correlation coefficient ("similarity") between two
C	anisotropic displacement vectors Uij and Vij.
C	See Merritt (1999) Acta Crystallographica D55, 1997-2004.
C       ===============================================================
	REAL Suv, CCuij
	REAL U(6), V(6)
	REAL UU(3,3), VV(3,3), Uiso(3,3), Viso(3,3), WW(3,3)
	REAL Ueq, Veq
	UU(1,1) = U(1)
	UU(2,2) = U(2)
	UU(3,3) = U(3)
	UU(1,2) = U(4)
	UU(2,1) = U(4)
	UU(1,3) = U(5)
	UU(3,1) = U(5)
	UU(2,3) = U(6)
	UU(3,2) = U(6)
	VV(1,1) = V(1)
	VV(2,2) = V(2)
	VV(3,3) = V(3)
	VV(1,2) = V(4)
	VV(2,1) = V(4)
	VV(1,3) = V(5)
	VV(3,1) = V(5)
	VV(2,3) = V(6)
	VV(3,2) = V(6)
	Ueq = (UU(1,1) + UU(2,2) + UU(3,3)) / 3.
	Veq = (VV(1,1) + VV(2,2) + VV(3,3)) / 3.
	DO I = 1,3
	DO J = 1,3
		WW(I,J) = VV(I,J) * Ueq / Veq
		Uiso(I,J) = 0
		Viso(I,J) = 0
	ENDDO
	ENDDO
	DO I = 1,3
		Uiso(I,I) = Ueq
		Viso(I,I) = Veq
	ENDDO
	Suv_top = CCuij(UU,WW)
	Suv_bot = (CCuij(UU,Uiso) * CCuij(VV,Viso))
	if (Suv_top.eq.0 .or. Suv_bot.eq.0) then
		Suv = 0
	else
		Suv = Suv_top / Suv_bot
	endif
	RETURN
	END

C	=======================================================
C	The rest of the file is just generic 3x3 matrix algebra
C	=======================================================

	SUBROUTINE V3CROSS(B,C,A)
C	CROSS PRODUCT OF TWO VECTORS
C	=======================
	REAL A(3),B(3),C(3)
	A(1)=B(2)*C(3)-C(2)*B(3)
	A(2)=B(3)*C(1)-C(3)*B(1)
	A(3)=B(1)*C(2)-C(1)*B(2)
	RETURN
	END
C
	FUNCTION V3DOT(A,B)
C	DOT PRODUCT OF TWO VECTORS
C	================
	REAL A(3),B(3)
	V3DOT=A(1)*B(1)+A(2)*B(2)+A(3)*B(3)
	RETURN
	END
C
	SUBROUTINE M3ADD(A,B,C)
C	A=B+C
C	========================
	REAL A(3,3),B(3,3),C(3,3)
	DO I=1,3
	DO J=1,3
	  A(I,J) = B(I,J) + C(I,J)
	ENDDO
	ENDDO
	RETURN
	END
C
	SUBROUTINE M3MUL(A,B,C)
C	A=B*C
C	========================
	REAL A(3,3),B(3,3),C(3,3),S
	DO I=1,3
	DO J=1,3
	  S=0
	  DO K=1,3
	    S=S+B(I,K)*C(K,J)
	  ENDDO
	  A(I,J)=S
	ENDDO
	ENDDO
	RETURN
	END
C
	FUNCTION V3INV(A,B)
C	INVERT A GENERAL 3X3 MATRIX AND RETURN DETERMINANT
C	A=(B)-1
C	======================
	REAL A(3,3),B(3,3),C(3,3),D
	CALL V3CROSS(B(1,2),B(1,3),C(1,1))
	CALL V3CROSS(B(1,3),B(1,1),C(1,2))
	CALL V3CROSS(B(1,1),B(1,2),C(1,3))
	D=V3DOT(B(1,1),C(1,1))
	IF (ABS(D).LE.1.E-30) THEN
	    V3INV=0.0
	    RETURN
	ENDIF
	DO I=1,3
	DO J=1,3
	    A(I,J)=C(J,I)/D
	ENDDO
	ENDDO
	V3INV=D
	RETURN
	END
C