forked from Chengcheng-Xiao/VASP_BOND_FIX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bond_length.patch
315 lines (314 loc) · 11.4 KB
/
bond_length.patch
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
diff -ruN src/constrain.F src_mod/constrain.F
--- src/constrain.F 1970-01-01 01:00:00.000000000 +0100
+++ src_mod/constrain.F 2020-04-29 16:32:36.000000000 +0100
@@ -0,0 +1,243 @@
+!*********************************************************************
+!
+! subroutine to constrain force (added in GaTech for fixing bond length)
+!
+! Original Author: UNKONW
+! Modified by: Chengcheng-Xiao
+! Email: [email protected]
+! 2020-05-22 adapted to vasp 5.4.4
+! 2020-04-23 add ability to fix multiple bonds
+!*********************************************************************
+
+ SUBROUTINE RD_CONSTRAIN(NCONST,ION1,ION2,DIST12)
+ USE lattice
+ USE poscar
+ IMPLICIT NONE
+
+
+ INTEGER ION1(99),ION2(99),NCONST
+ REAL(q) DIST12(99)
+ ION1=0
+ ION2=0
+ DIST12=0.0
+
+ NCONST=0
+ OPEN(UNIT=777,FILE='CONSTRAIN',STATUS='OLD',ERR=900)
+ DO WHILE (.TRUE.)
+ NCONST=NCONST+1
+ READ(777,*,END=999) ION1(NCONST),ION2(NCONST),DIST12(NCONST)
+ END DO
+999 CLOSE(UNIT=777)
+
+! OPEN(UNIT=777,FILE='CONSTRAIN',STATUS='OLD',ERR=900)
+! READ(777,*) ION1,ION2,DIST12
+! CLOSE(UNIT=777)
+
+! WRITE(*,*) 'ION1=',ION1,'ION2=',ION2,'d=',DIST12
+
+ 900 CONTINUE
+ END SUBROUTINE
+
+
+
+ SUBROUTINE CONSTRAIN_FORCE(T_INFO,VEL,TIFOR,POS,LATT_CUR,IO)
+ USE lattice
+ USE poscar
+ USE base
+ IMPLICIT NONE
+
+ TYPE (latt) LATT_CUR
+ TYPE (type_info) T_INFO
+ TYPE(in_struct) IO
+ REAL(q) TIFOR(3,T_INFO%NIONS),VEL(3,T_INFO%NIONS)
+ REAL(q) POS(3,T_INFO%NIONS)
+! local
+ INTEGER ION1(99),ION2(99),NCONST,I
+ REAL(q) DIST12(99)
+ REAL(q) DDIST12
+ REAL(q) POS1(3),POS2(3),TANVEC(3),TANC
+ REAL(q) TANF1,TANF2,TANAVEF
+
+ CALL RD_CONSTRAIN(NCONST,ION1,ION2,DIST12)
+! IF ((ION1 .EQ. 0) .OR. (ION2 .EQ. 0) .OR. (DIST12 .EQ. 0._q)) THEN
+! WRITE(*,*) 'Failed to read CONSTRAIN.'
+! GOTO 800
+! ENDIF
+ ! loop over all constrains
+ DO I=1,NCONST
+ ! get atomic postion in Cart coord.
+ POS1(1)=POS(1,ION1(I))
+ POS1(2)=POS(2,ION1(I))
+ POS1(3)=POS(3,ION1(I))
+ CALL DIRKAR(1, POS1, LATT_CUR%A)
+ POS2(1)=POS(1,ION2(I))
+ POS2(2)=POS(2,ION2(I))
+ POS2(3)=POS(3,ION2(I))
+ CALL DIRKAR(1, POS2, LATT_CUR%A)
+
+ ! get direction vector -> TANVEC
+ ! get distance -> DIST12
+ ! get dist difference -> DDIST12
+ TANVEC(1)=POS2(1)-POS1(1)
+ TANVEC(2)=POS2(2)-POS1(2)
+ TANVEC(3)=POS2(3)-POS1(3)
+ TANC=(TANVEC(1)**2.0+TANVEC(2)**2.0+TANVEC(3)**2.0)**0.5
+ DDIST12=TANC-DIST12(I)
+ TANVEC(1)=TANVEC(1)/TANC
+ TANVEC(2)=TANVEC(2)/TANC
+ TANVEC(3)=TANVEC(3)/TANC
+
+ ! project force on each atom to direction vector
+ ! FORCE * TANVEC
+ TANF1=TIFOR(1,ION1(I))*TANVEC(1)
+ TANF1=TANF1+TIFOR(2,ION1(I))*TANVEC(2)
+ TANF1=TANF1+TIFOR(3,ION1(I))*TANVEC(3)
+ TANF2=TIFOR(1,ION2(I))*TANVEC(1)
+ TANF2=TANF2+TIFOR(2,ION2(I))*TANVEC(2)
+ TANF2=TANF2+TIFOR(3,ION2(I))*TANVEC(3)
+
+ ! get average force on direction vector
+ TANAVEF=(TANF1+TANF2)*0.5
+
+ ! subtract average force on direction vector from atomic force
+ ! forces on atom are now orthorgonal to direction vec
+ TIFOR(1,ION1(I))=TIFOR(1,ION1(I))-TANF1*TANVEC(1)
+ TIFOR(2,ION1(I))=TIFOR(2,ION1(I))-TANF1*TANVEC(2)
+ TIFOR(3,ION1(I))=TIFOR(3,ION1(I))-TANF1*TANVEC(3)
+ TIFOR(1,ION2(I))=TIFOR(1,ION2(I))-TANF2*TANVEC(1)
+ TIFOR(2,ION2(I))=TIFOR(2,ION2(I))-TANF2*TANVEC(2)
+ TIFOR(3,ION2(I))=TIFOR(3,ION2(I))-TANF2*TANVEC(3)
+
+ ! add back average force along direction vec so that they are equal on each atom.
+ ! this makes atoms become rigid body.
+ IF ((T_INFO%LSFOR(1,ION1(I))).AND.(T_INFO%LSFOR(1,ION2(I)))) THEN
+ TIFOR(1,ION1(I))=TIFOR(1,ION1(I))+TANAVEF*TANVEC(1)
+ TIFOR(1,ION2(I))=TIFOR(1,ION2(I))+TANAVEF*TANVEC(1)
+! IF (IO%IU6>=0) WRITE(IO%IU6,'(X,A,F9.6,A,F9.6)') 'Force on Cart. X, Atom1:', TIFOR(1,ION1(I)), ' Atom2: ', TIFOR(1,ION2(I))
+ ENDIF
+ IF ((T_INFO%LSFOR(2,ION1(I))).AND.(T_INFO%LSFOR(2,ION2(I)))) THEN
+ TIFOR(2,ION1(I))=TIFOR(2,ION1(I))+TANAVEF*TANVEC(2)
+ TIFOR(2,ION2(I))=TIFOR(2,ION2(I))+TANAVEF*TANVEC(2)
+! IF (IO%IU6>=0) WRITE(IO%IU6,'(X,A,F9.6,A,F9.6)') 'Force on Cart. Y, Atom1:',TIFOR(2,ION1(I)),' Atom2: ', TIFOR(2,ION2(I))
+ ENDIF
+ IF ((T_INFO%LSFOR(3,ION1(I))).AND.(T_INFO%LSFOR(3,ION2(I)))) THEN
+ TIFOR(3,ION1(I))=TIFOR(3,ION1(I))+TANAVEF*TANVEC(3)
+ TIFOR(3,ION2(I))=TIFOR(3,ION2(I))+TANAVEF*TANVEC(3)
+! IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A,F9.6,A,F9.6)') 'Force on Cart. Z, Atom1:',TIFOR(3,ION1(I)),' Atom2: ', TIFOR(3,ION2(I))
+ ENDIF
+
+ VEL(1,ION1(I))=0._q
+ VEL(2,ION1(I))=0._q
+ VEL(3,ION1(I))=0._q
+ VEL(1,ION2(I))=0._q
+ VEL(2,ION2(I))=0._q
+ VEL(3,ION2(I))=0._q
+ END DO
+ IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A)') 'CONSTRAIN_FORCE is done.'
+! WRITE(*,*) 'CONSTRAIN_FORCE is done.'
+
+ 800 CONTINUE
+ END SUBROUTINE
+
+ SUBROUTINE CONSTRAIN_POSITION(T_INFO,POS,LATT_CUR,IO)
+ USE lattice
+ USE poscar
+ USE base
+ IMPLICIT NONE
+
+ TYPE (latt) LATT_CUR
+ TYPE (type_info) T_INFO
+ TYPE(in_struct) IO
+ REAL(q) POS(3,T_INFO%NIONS)
+! local
+ INTEGER ION1(99),ION2(99),NCONST,I
+ REAL(q) DIST12(99)
+ REAL(q) DDIST12
+ REAL(q) POS1(3),POS2(3),TANVEC(3),TANC
+ REAL(q) TANF1,TANF2,TANAVEF(3)
+
+ CALL RD_CONSTRAIN(NCONST,ION1,ION2,DIST12)
+! IF ((ION1 .EQ. 0) .OR. (ION2 .EQ. 0) .OR. (DIST12 .EQ. 0._q)) THEN
+! WRITE(*,*) 'Failed to read CONSTRAIN.'
+! GOTO 700
+! ENDIF
+
+ ! loop over all constrains
+ DO I=1,NCONST
+ ! get atomic postion in Cart coord.
+ POS1(1)=POS(1,ION1(I))
+ POS1(2)=POS(2,ION1(I))
+ POS1(3)=POS(3,ION1(I))
+ CALL DIRKAR(1, POS1, LATT_CUR%A)
+ POS2(1)=POS(1,ION2(I))
+ POS2(2)=POS(2,ION2(I))
+ POS2(3)=POS(3,ION2(I))
+ CALL DIRKAR(1, POS2, LATT_CUR%A)
+
+ ! get direction vector -> TANVEC
+ ! get distance -> DIST12
+ ! get dist difference -> DDIST12
+ TANVEC(1)=POS2(1)-POS1(1)
+ TANVEC(2)=POS2(2)-POS1(2)
+ TANVEC(3)=POS2(3)-POS1(3)
+ TANC=(TANVEC(1)**2.0+TANVEC(2)**2.0+TANVEC(3)**2.0)**0.5
+ DDIST12=TANC-DIST12(I)
+ TANVEC(1)=TANVEC(1)/TANC
+ TANVEC(2)=TANVEC(2)/TANC
+ TANVEC(3)=TANVEC(3)/TANC
+
+ ! if atoms are allowed to move, then make them equally devided along direction vector
+ ! |pos_a - pos_center| = |pos_b - pos_center| = 0.5*DIST12 along direction_vec
+ IF ((T_INFO%LSFOR(1,ION1(I))).AND.(T_INFO%LSFOR(1,ION2(I)))) THEN
+ POS1(1)=POS1(1)+0.5*DDIST12*TANVEC(1)
+ POS2(1)=POS2(1)-0.5*DDIST12*TANVEC(1)
+ ENDIF
+ IF ((T_INFO%LSFOR(2,ION1(I))).AND.(T_INFO%LSFOR(2,ION2(I)))) THEN
+ POS1(2)=POS1(2)+0.5*DDIST12*TANVEC(2)
+ POS2(2)=POS2(2)-0.5*DDIST12*TANVEC(2)
+ ENDIF
+ IF ((T_INFO%LSFOR(3,ION1(I))).AND.(T_INFO%LSFOR(3,ION2(I)))) THEN
+ POS1(3)=POS1(3)+0.5*DDIST12*TANVEC(3)
+ POS2(3)=POS2(3)-0.5*DDIST12*TANVEC(3)
+ ENDIF
+
+ ! if only one atoms (atom2) is allowed to move, then move that atom along the direction_vec so that
+ ! |pos_a - pos_b| = DIST12 along direction_vec
+ IF ((.NOT.T_INFO%LSFOR(1,ION1(I))).AND.(T_INFO%LSFOR(1,ION2(I)))) THEN
+ POS2(1)=POS2(1)-DDIST12*TANVEC(1)
+ ENDIF
+ IF ((.NOT.T_INFO%LSFOR(2,ION1(I))).AND.(T_INFO%LSFOR(2,ION2(I)))) THEN
+ POS2(2)=POS2(2)-DDIST12*TANVEC(2)
+ ENDIF
+ IF ((.NOT.T_INFO%LSFOR(3,ION1(I))).AND.(T_INFO%LSFOR(3,ION2(I)))) THEN
+ POS2(3)=POS2(3)-DDIST12*TANVEC(3)
+ ENDIF
+
+ ! if only one atoms (atom1) is allowed to move, then move that atom along the direction_vec so that
+ ! |pos_a - pos_b| = DIST12 along direction_vec
+ IF ((T_INFO%LSFOR(1,ION1(I))).AND.(.NOT.T_INFO%LSFOR(1,ION2(I)))) THEN
+ POS1(1)=POS1(1)+DDIST12*TANVEC(1)
+ ENDIF
+ IF ((T_INFO%LSFOR(2,ION1(I))).AND.(.NOT.T_INFO%LSFOR(2,ION2(I)))) THEN
+ POS1(2)=POS1(2)+DDIST12*TANVEC(2)
+ ENDIF
+ IF ((T_INFO%LSFOR(3,ION1(I))).AND.(.NOT.T_INFO%LSFOR(3,ION2(I)))) THEN
+ POS1(3)=POS1(3)+DDIST12*TANVEC(3)
+ ENDIF
+
+ CALL KARDIR(1,POS1,LATT_CUR%B)
+ CALL KARDIR(1,POS2,LATT_CUR%B)
+
+ POS(1,ION1(I))=POS1(1)
+ POS(2,ION1(I))=POS1(2)
+ POS(3,ION1(I))=POS1(3)
+ POS(1,ION2(I))=POS2(1)
+ POS(2,ION2(I))=POS2(2)
+ POS(3,ION2(I))=POS2(3)
+ END DO
+ IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A)') 'CONSTRAIN_POSITION is done.'
+
+
+ 700 CONTINUE
+ END SUBROUTINE
+
diff -ruN src/main.F src_mod/main.F
--- src/main.F 2017-04-20 10:03:58.000000000 +0100
+++ src_mod/main.F 2020-04-29 16:32:36.000000000 +0100
@@ -3125,6 +3125,32 @@
! add chain forces and constrain forces
!=======================================================================
CALL VCA_FORCE(T_INFO, TIFOR)
+! 2018-05-22 added for fixing bond length
+ CALL CONSTRAIN_FORCE(T_INFO,DYN%VEL,TIFOR,DYN%POSION,LATT_CUR,IO)
+! 2020-04-24 write constrained force
+wrtforce: IF (IO%IU6>=0 .AND. IO%NWRITE>=1) THEN
+WRITE(IO%IU6,972)
+DO J=1,T_INFO%NIONS
+ VTMP=T_INFO%POSION(1:3,J)
+ CALL DIRKAR(1,VTMP,LATT_CUR%A)
+ WRITE(IO%IU6,976) VTMP,(TIFOR (I,J),I=1,3)
+ENDDO
+
+IF (IO%INTERACTIVE) THEN
+ WRITE(IO%IU0,'(A)') 'FORCES:'
+ DO J=1,T_INFO%NIONS
+ WRITE(IO%IU0,'(3F14.7)') (TIFOR (I,J),I=1,3)
+ ENDDO
+ENDIF
+WRITE(IO%IU6,977)
+
+972 FORMAT( ' POSITION ',35X,'CONSTRAINED TOTAL-FORCE (eV/Angst)'/ &
+& ' ----------------------------------------------', &
+& '-------------------------------------')
+976 FORMAT((3F13.5,3X,3F14.6))
+977 FORMAT(' ----------------------------------------------', &
+& '-------------------------------------')
+ENDIF wrtforce
IF (DYN%IBRION /=5 .AND. DYN%IBRION /=6 .AND. DYN%IBRION /=7 ) &
CALL SET_SELECTED_FORCES_ZERO(T_INFO,DYN%VEL,TIFOR,LATT_CUR)
@@ -3676,7 +3702,11 @@
LATT_CUR%A(3,I)=SCALEQ*LATT_CUR%A(3,I)
ENDDO
ENDIF
- CALL LATTIC(LATT_CUR)
+ CALL LATTIC(LATT_CUR)
+
+! 2020-04-28 position constrain for fixing bond length
+ CALL CONSTRAIN_POSITION(T_INFO,DYN%POSION,LATT_CUR,IO)
+
!-----------------------------------------------------------------------
! reinitialize the prediction algorithm for the wavefunction if needed
!-----------------------------------------------------------------------
diff -ruN src/.objects src_mod/.objects
--- src/.objects 2017-04-20 10:04:05.000000000 +0100
+++ src_mod/.objects 2020-04-29 16:32:36.000000000 +0100
@@ -129,6 +129,7 @@
pardens.o \
optics.o \
constr_cell_relax.o \
+ constrain.o \
stm.o \
finite_diff.o \
elpol.o \
@@ -327,6 +328,7 @@
pardens.o \
optics.o \
constr_cell_relax.o \
+ constrain.o \
stm.o \
finite_diff.o \
elpol.o \