-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlattice.f90
executable file
·310 lines (276 loc) · 8.06 KB
/
lattice.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
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
module lattice
use apk
use openfort
use spinc
CHARACTER(3),allocatable:: AT(:)
character*10 sitetitle
character*3 chRE
character*2 chLig
integer ksub, nrel
integer,save :: hlocalInst
type(T_RECT) rectan
contains
integer*4 function latdialog( hDlg, message, wParam, lParam )
!MS$ ATTRIBUTES STDCALL, ALIAS : '_latdialog@16' :: latdialog
integer*4 hDlg, message, wParam, lParam
integer ret,i, iindex
character*4 chtemp
character*3 chtempL
character*11 titletemp
character*4 chgpar
character*5 chpartemp
LPARAM = LPARAM
write(chgpar,'(f4.1)') Gs
select case (message)
case (WM_INITDIALOG)
do i=1,ksub
ret=SendDlgItemMessage(hDlg,IDL_SITE,LB_ADDSTRING,0,LOC(at(i)//CHAR(0)))
end do
ret=SendDlgItemMessage(hDlg,IDL_SITE,LB_SETCURSEL,1,0)
ret=SetDlgItemText(hDlg,ID_SELECTTITLE,sitetitle//char(0))
ret=SetDlgItemText(hDlg,ID_SELECTRE,chRE//char(0))
ret=SetDlgItemText(hDlg,ID_LIGAND,chLig//char(0))
ret=SetDlgItemText(hDlg,ID_GPAR,chgpar//char(0))
! case(WM_PAINT)
! ret=UpdateWindow(hDlg)
! ret=UpdateWindow(hMWindow)
case (WM_COMMAND)
!ret=InvalidateRgn(hMWindow,NULL,.TRUE.)
! ret=InvalidateRgn(hDlg,NULL,.TRUE.)
iindex=SendDlgItemMessage(hDlg,IDL_SITE,LB_GETCURSEL,0,0)
nrel=iindex+1
select case(INT4(LoWord(wparam)))
case(IDOK)
ret=GetDlgItemText(hDlg,ID_SELECTTITLE,titletemp,11)
sitetitle=titletemp(1:ret)
ret=GetDlgItemText(hDlg,ID_SELECTRE,chtemp,4)
chRE=chtemp(1:3)
ret=GetDlgItemText(hDlg,ID_LIGAND,chtempL,3)
chLig=chtempL(1:2)
ret=GetDlgItemText(hDlg,ID_GPAR,chpartemp,5)
read(chpartemp(1:4),*) Gs
ret = EndDialog(hDlg, TRUE)
latdialog = 1;return
case(IDCANCEL)
ret = EndDialog(hDlg, FALSE)
latdialog =-1;return
end select
end select
latdialog = 1
return
end function latdialog
integer function makelat()
IMPLICIT REAL*8(A-H,O-Z)
integer i,i1,i2,i3,l
DIMENSION T1(3),T2(3),T3(3),Y(3)
allocatable DEC(:,:),RR(:,:),X(:,:,:),IND(:,:),chr(:)
integer ret
character*14 temptitle
hlocalInst=hInst
sitetitle="defaultnam"
chRE="Nd3"
chLig="O2"
Gs=8
ret=Initoflat()
IF (ret.eq.1) THEN
ret = UpdateWindow(hMWindow)
FileStatus=1
open(1,file=ofbuffer, mode='read')
READ(1,5) KSUB
5 FORMAT(24X,I3)
ALLOCATE (AT(KSUB),DEC(KSUB,3),chr(KSUB))
READ(1,*)
READ(1,'(3f7.4)') T1,T2,T3
READ(1,10) (AT(I),(DEC(I,J),J=1,3),chr(I),I=1,KSUB)
10 FORMAT(A3,3F10.6,f6.2)
close(1)
! WRITE(*,*) 'Enter site for field calculation(I4)'
! READ(*,15) NREL
nrel=1
ret=DialogBox(hlocalInst,LOC("SITESELECT"C),hMWindow,LOC(latdialog))
if(ret.eq.TRUE) then
!******************the number of translations ****************************
ktr=13
!********************************************************************
KCELL=ktr*ktr*ktr
KSUM=KCELL*KSUB
ALLOCATE (RR(KSUB,3),X(KSUB,KCELL,3),IND(KSUM,2))
do I=1,KSUM; IND(I,1)=0; IND(I,2)=0; end do
do I=1,KSUB;do L=1,3;RR(I,L)=DEC(NREL,L)-DEC(I,L);end do; end do
ktt=(ktr+1)/2
DO 100 I=1,KSUB
IS=0
DO 100 I1=1,ktr
II1=I1-ktt
DO 100 I2=1,ktr
II2=I2-ktt
DO 100 I3=1,ktr
IS=IS+1;II3=I3-ktt
do L=1,3
Y(L)=T1(L)*II1+T2(L)*II2+T3(L)*II3
X(I,IS,L)=DEC(NREL,L)-DEC(I,L)-Y(L)
end do
100 continue
CALL SORT(KSUB,KCELL,X,IND,IS)
i=lstrlen(curdirpath)
ret=SetCurrentDirectory(curdirpath(1:i)//"\\Lat"C)
temptitle=TRIM(sitetitle)//".xyz"
i=LEN_TRIM(temptitle)
open(3,file=temptitle(1:i))
write(3,'(a10)') sitetitle
write(3,'(i2)') is
write(3,'(a3)') chRE
write(3,'(x,a2)') chLig
write(3,'(f4.1)') Gs
do I=1,IS
write(3,101) AT(IND(I,1)),(X(IND(I,1),IND(I,2),L),L=1,3),&
chr(IND(I,1)),&
SQRT(X(IND(I,1),IND(I,2),1)**2+X(IND(I,1),IND(I,2),2)**2+&
X(IND(I,1),IND(I,2),3)**2)
101 FORMAT(a3,f10.6,f10.6,f10.6,f6.2,f10.6)
end do
close(3)
i=lstrlen(curdirpath)
ret=SetCurrentDirectory(curdirpath(1:i))
deallocate(RR,X,IND)
deallocate(AT,DEC,chr)
makelat=1
return
else
deallocate(AT,DEC,chr)
makelat=-1
return
end if
else
ret=MessageBox(NULL,"You didn't opened any file"C,""C,MB_ICONSTOP)
makelat=-1
return
endif
end function makelat
!***** subroutine to sort lattice atoms position*********************
subroutine SORT(KSUB,KCELL,X,IND,IS)
IMPLICIT REAL*8(A-H,O-Z)
! CHARACTER*4 AT(KSUB)
DIMENSION X(KSUB,KCELL,3)
integer i,j
allocatable XN(:,:)
DIMENSION IND(KSUB*KCELL,2)
ALLOCATE (XN(KSUB,KCELL))
DO I=1,KSUB
DO J=1,KCELL
XN(I,J)=0.0D00
do L=1,3
XN(I,J)=XN(I,J)+X(I,J,L)*X(I,J,L)
end do
XN(I,J)=DSQRT(XN(I,J))
end do
end do
AM=1.D30
!*********building coordination spheres up to RMAX************************
RMAX=3.1D00
!******************************************************************
IS=0
where(xn.gt.rmax)
xn=-1
end where
do i=1,ksub
do j=1,kcell
if(xn(i,j).gt.0) then
is=is+1
ind(is,1)=i;ind(is,2)=j
end if
end do
end do
deallocate(XN)
end subroutine sort
integer function getLigands()
integer ret,i
character*3, allocatable :: tmpid(:)
real r
ret=Initoflat()
IF (ret.eq.1) THEN
FileStatus=1
open(1,file=ofbuffer)
read(1,'(a40)') envname
read(1,'(i2)') numat
allocate(tmpid(numat),xLig(numat,3),qLig(numat))
tmpid=' ';xLig=0.;qLig=0.
read(1,'(a3)') idRE; read(1,'(a3)') idLig
read(1,'(f4.1)') Gs
do i=1,numat
read(1,10) tmpid(i),xLig(i,1), xLig(i,2), xLig(i,3),qLig(i),r
10 format(a3,f10.6,f10.6,f10.6,f6.2,f10.6)
end do
! open(2,file='debug.txt'); ! write(2,'(i2)') numat;! write(2,'(a3)') idRE
! do i=1,numat;! write(2, 10) idLig,xLig(i,1), xLig(i,2), xLig(i,3);! end do; ! close(2)
deallocate(tmpid)
close(1)
getLigands=1
else
ret=MessageBox(NULL,"You didn't opened any file"C,""C,MB_ICONSTOP)
getLigands=-1
return
endif
end function getLigands
integer function doAnalysis()
integer iostat, ret,i,j,icount
character*3 id1,id2
character*80 chtemp
character*6 coeftemp
integer itwasfound
!open(11, file='debug.txt')
!write(11,*) "enter the module doAnalysis"
open(10,file='overlap.txt', ACTION='READ',IOSTAT=iostat)
if(iostat.ne.0) then
ret=MessageBox(NULL,"Problems with file overlap.txt\nIt should be in your Spectra directory\n"C,""C,MB_ICONSTOP)
return
end if
!write(11,*) "file overlap.txt is opened successfully"
read(10,*);read(10,*)
!write(11,*) "begin reading"
do while (.not. EOF(10))
read(10,'(a80)') chtemp
icount=scan(chtemp,'$')
id1=chtemp(icount-3:icount-1)
chtemp=chtemp(icount+1:)
icount=scan(chtemp,'$')
id2=chtemp(icount-3:icount-1)
chtemp=chtemp(icount+1:)
if(idRE.eq.id1.and.idLig.eq.id2) then
do i=1,2
do j=1,3
icount=scan(chtemp,'$')
coeftemp=chtemp(icount-6:icount-1)
read(coeftemp,'(f6.3)') SS(i,j)
chtemp=chtemp(icount+1:)
end do
end do
do i=1,2
icount=scan(chtemp,'$')
coeftemp=chtemp(icount-4:icount-1)
read(coeftemp,'(f4.1)') rlimits(i)
chtemp=chtemp(icount+1:)
end do
itwasfound=1
exit
else
end if
end do
! write(11,*) id1, id2, ((SS(i,j),j=1,3),i=1,2),(rlimits(i),i=1,2)
close(10)
! close(11)
if(itwasfound.ne.1) then
ret=MessageBox(NULL,"SPECTRA is unable to find built-in values for the case you specified! "//idRE//" -"//idLig//" pair is not in the database"C,"BAD CASE"C,MB_ICONSTOP)
deallocate(xLig,qLig)
doAnalysis=-1;return
else
doAnalysis=1;return
endif
end function doAnalysis
integer function calculateCFP()
integer ret
ret=parex()
calculateCFP=1
deallocate(xLig,qLig)
end function calculateCFP
end module lattice