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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
| Program nonorthoSA
!
! This program calculates the accessible surface area by using a simple Monte
! Carlo integration for both orthorhombic and non-orthorhombic unit cells.
! To run the program the following files are needed:
! 1) an input file containing the name of the file containing the diameters of
! the atoms, the name of the file containing the coordinates of the
! framework atoms, the diameter of the probe, the number of random trials
! around each framework atom, the lenghts of the unit cells (a, b, c), the
! cell angles (alpha, beta and gamma) and the crystal density.
! 2) A file containing the diameters of the framework atoms. The program is
! written to read in an xyz file. Please note that the coordinates of all
! framework atoms need to be specified (P1) as the program does not handle
! symmetry operations.
!
! Things that you might have to change:
! - The maximum number of framework atoms 5000 at the moment. Change the value
! of max_no if your unit cells contains more atoms.
!
! Changes to the code
!
! 9/3/2009 Tina Duren
! fixed a bug that wrote the error message to a file rather than
! the screen if an atom type was not specified in the diameter list
! Thanks to Kenji Sumida from the University of Berkeley for
! pointing this out.
!
Use matrix
Use defaults
Implicit None
!
! Maximum number of atoms in your unit cell. Increase if your unit cell
! contains more atoms.
!
Integer, Parameter :: max_no = 5000
Character(len = 3) :: atom
Character(len = 2) :: symbol
Character(len = 10) :: atomname(1:max_no), atomtype(1:100)
Character(len = 100) :: atom_file, coord_file, output_file
Type(MatrixType) :: lij, lijinv
Real(kind=RDbl) :: sigmatype(1:100), atomsigma(1:4000)
Real(kind=RDbl) :: x(1:max_no), y(1:max_no), z(1:max_no)
Real(kind=RDbl) :: xnew(1:max_no), ynew(1:max_no), znew(1:max_no)
Real(kind=RDbl) :: alpha, beta, gamma, alpha_r, beta_r, gamma_r
Real(kind=RDbl) :: a, b, c, ai, bi, ci, aj, bj, cj, ak, bk, ck
Real(kind=RDbl) :: xpoint, ypoint, zpoint, xpointnew, ypointnew, zpointnew
Real(kind=RDbl) :: phi, costheta, theta
Real(kind=RDbl) :: rho_crys, dprobe, Nsample
Real(kind=RDbl) :: dx, dy, dz, dx_trans, dy_trans, dz_trans, dist2
Real(kind=RDbl) :: sjreal, stotal, sfrac, uc_volume, stotalreduced
Real(kind=RDbl) :: ran_num1, ran_num2, trash
Real(kind=RDBL) :: ran0
Integer :: seed, N, ntypes, i, j, k, ncount
Integer :: ierror
Logical :: match, deny
!
! Seed for the random number generator, change if you want to start from a
! different random number
!
seed = -52907
!
! to properly initialise the random number generator, a negative seed is
! needed
!
If (seed> 0) seed = -1 * seed
!
! Read the data from the input file
!
Read(*,('(A)')) atom_file ! file containing the diameters of atoms
Read(*,('(A)')) coord_file ! file containing the cartesian coordinates
Read(*,*) dprobe ! diameter of probe in A
Read(*,*) Nsample ! Number of trials per framework atom
Read(*,*) a, b, c ! Cell parameters in A
Read(*,*) alpha, beta, gamma ! cell angles
Read(*,*) rho_crys ! density of crystal in g / cm3
alpha_r = alpha*degtorad
beta_r = beta*degtorad
gamma_r = gamma*degtorad
ai = a
aj = 0
ak = 0
bi = b*cos(gamma_r)
bj = b*sin(gamma_r)
bk = 0
ci = c*cos(beta_r)
cj = (b*c*cos(alpha_r)-bi*ci)/bj
ck = sqrt(c**2-ci**2-cj**2)
lij%comp = 0
lij%comp(1,1) = ai
lij%comp(1,2) = bi
lij%comp(1,3) = ci
lij%comp(2,1) = aj
lij%comp(2,2) = bj
lij%comp(2,3) = cj
lij%comp(3,1) = ak
lij%comp(3,2) = bk
lij%comp(3,3) = ck
lijinv=matrix_inverse(lij)
!
! Open the files and read the data
!
Open(10, file=atom_file, status='old', IOSTAT = ierror)
If (ierror /= 0) Then
Write(*,*) 'Error opening file: ',atom_file
Write(*,*) 'Make sure it exists or check the spelling of the filename'
END IF
ntypes = 0
Do
Read(10,*) atom
IF(Trim(atom) == 'EOF') EXIT
ntypes = ntypes + 1
END DO
Rewind(10)
Do i = 1, ntypes
Read(10,*) atomtype(i), sigmatype(i)
End do
!
! Openeing and reading the coord file
!
Open(20, file=coord_file, status='old', IOSTAT = ierror)
If (ierror /= 0) Then
Write(*,*) 'Error opening file: ',coord_file
Write(*,*) 'Make sure it exists or check the spelling of the filename'
END IF
!
! The first line contains the number of framework atoms
!
Read(20,*) N
!
! Skip the blank line of the xyz file
!
Read(20,*)
Do i=1, N
!
! The format of the coordinate file corresponds to an xyz file as exported
! from Diamond.
! x(i), y(i), z(i): x,y,z coordinates in Angstrom
! symbol: chemical symbol of framework atom.
!
! Change the following read statement if you want to use a different
! file format. But ensure that you end up with the coordinates in A and
! the name of the framework atoms!
Read(20,*) symbol, x(i), y(i), z(i)
!
! The diameters of the framework atoms are stored together with the atom
! name. So assign atom name according to chemical symbol.
!
symbol = Trim(symbol)
SELECT CASE(symbol)
CASE('H')
atomname(i) = 'Hydrogen'
CASE('C')
atomname(i) = 'Carbon'
CASE('O')
atomname(i) = 'Oxygen'
CASE('Zn')
atomname(i) = 'Zinc'
CASE('Cr')
atomname(i) = 'Chromium'
CASE('Cd')
atomname(i) = 'Cadmium'
CASE default
Write(*,*) symbol ,' not in list'
Write(*,*) 'List can be found in nonorthoSA.F90'
END SELECT
! Transform molecules coordinates
xnew(i) = x(i)*lijinv%comp(1,1) + y(i)*lijinv%comp(1,2) + &
z(i)*lijinv%comp(1,3)
ynew(i) = x(i)*lijinv%comp(2,1) + y(i)*lijinv%comp(2,2) + &
z(i)*lijinv%comp(2,3)
znew(i) = x(i)*lijinv%comp(3,1) + y(i)*lijinv%comp(3,2) + &
z(i)*lijinv%comp(3,3)
xnew(i) = a*xnew(i)
ynew(i) = b*ynew(i)
znew(i) = c*znew(i)
! Translate the transformed coordinates so they lie in the box a,b,c
If(xnew(i)<0.0) xnew(i) = xnew(i) + a
If(xnew(i)>=a) xnew(i) = xnew(i) - a
If(ynew(i)<0.0) ynew(i) = ynew(i) + b
If(ynew(i)>=b) ynew(i) = ynew(i) - b
If(znew(i)<0.0) znew(i) = znew(i) + c
If(znew(i)>=c) znew(i) = znew(i) - c
! Match sigmas with coordinates
atomname(i)=Trim(atomname(i))
match=.False.
Do j=1, ntypes
If(atomname(i)==atomtype(j)) Then
atomsigma(i)=sigmatype(j)+dprobe
match=.True.
Exit
End If
End Do
If(.Not.match) Then
Write(*,*) 'Could not find match for atom: ', i, ' ', atomname(i)
Write(*,*) 'The name is either read in incorrectly or does not exist'
Write(*,*) 'in the list of available atoms in ',atom_file
Stop
End If
End Do
Write(*,*)
Write(*,*) 'Calculating the accessible surface area for the following input parameters'
Write(*,*) '-------------------------------------------------------------------------'
Write(*,*) 'File with framework coordinates: ',TRIM(coord_file)
Write(*,*) 'File with atom diameters: ', TRIM(atom_file)
Write(*,'(A,F12.3)') ' Probe diameter in A: ',dprobe
! Main sampling cycle
stotal=0.0
Do i=1, N ! Loop over all framework atoms
ncount=0
Do j=1, Nsample ! Number of trial positions around each framework atom
!
! Generate random vector of length 1
! First generate phi 0:+2pi
!
phi = ran0(seed)*twopi
!
!
! Generate cosTheta -1:1 to allow for even distribution of random vectors
! on the unit sphere.See <a href="http://mathworld.wolfram.com/SpherePointPicking.html" target="_blank">http://mathworld.wolfram.com/SpherePointPicking.html</a>
! for further explanations
!
costheta = 1 - ran0(seed) * 2.0
theta = Acos(costheta)
xpoint = sin(theta)*cos(phi)
ypoint = sin(theta)*sin(phi)
zpoint = costheta
! Make this vector of (sigma+probe_diameter)/2.0 length
xpoint=xpoint*atomsigma(i)/2.0
ypoint=ypoint*atomsigma(i)/2.0
zpoint=zpoint*atomsigma(i)/2.0
! Transform random vector
xpointnew = xpoint*lijinv%comp(1,1) + ypoint*lijinv%comp(1,2) &
+ zpoint*lijinv%comp(1,3)
ypointnew = xpoint*lijinv%comp(2,1) + ypoint*lijinv%comp(2,2) &
+ zpoint*lijinv%comp(2,3)
zpointnew = xpoint*lijinv%comp(3,1) + ypoint*lijinv%comp(3,2) &
+ zpoint*lijinv%comp(3,3)
xpointnew = a*xpointnew
ypointnew = b*ypointnew
zpointnew = c*zpointnew
! Translate the center of coordinate to the particle i center and apply PBC
xpointnew = xpointnew + xnew(i)
ypointnew = ypointnew + ynew(i)
zpointnew = zpointnew + znew(i)
If(xpointnew < 0.0) xpointnew = xpointnew + a
If(xpointnew >= a) xpointnew = xpointnew - a
If(ypointnew < 0.0) ypointnew = ypointnew + b
If(ypointnew >= b) ypointnew = ypointnew - b
If(zpointnew < 0.0) zpointnew = zpointnew + c
If(zpointnew >= c) zpointnew = zpointnew - c
! Now we check for overlap
deny=.False.
Do k=1,N
if(k==i) cycle
dx = xpointnew - xnew(k)
dx = dx - a*int(2.0*dx/a)
dy = ypointnew - ynew(k)
dy = dy - b*int(2.0*dy/b)
dz = zpointnew-znew(k)
dz = dz-c*int(2.0*dz/c)
dx = dx / a
dy = dy / b
dz = dz / c
dx_trans = dx*lij%comp(1,1) + dy*lij%comp(1,2) + dz*lij%comp(1,3)
dy_trans = dx*lij%comp(2,1) + dy*lij%comp(2,2) + dz*lij%comp(2,3)
dz_trans = dx*lij%comp(3,1) + dy*lij%comp(3,2) + dz*lij%comp(3,3)
dist2=dx_trans*dx_trans+dy_trans*dy_trans+dz_trans*dz_trans
If(sqrt(dist2)<0.999*atomsigma(k)/2.0) then
deny=.True.
Exit
End If
End Do
If(deny) Cycle
ncount=ncount+1
End Do
! Fraction of the accessible surface area for sphere i
sfrac=Real(ncount)/Real(Nsample)
! Surface area for sphere i in real units (A^2)
sjreal=pi*atomsigma(i)*atomsigma(i)*sfrac
stotal=stotal+sjreal
End Do
! Converting stotal on Surface per Volume
! Unit volume calculated from the absolute value of the determinate of the 3x3
! matrix containing the vectors defining the unit cell.
! See e.g. Marsden, et al. "Basic Multivariable Calculus" 1993 pg. 53
uc_volume=abs(ai*(bj*ck-bk*cj)-aj*(bi*ck-bk*ci)+ak*(bi*cj-bj*ci))
stotalreduced=stotal/uc_volume*1.E4
! Report results
Write(*,'(A,F12.2)') ' Total surface area in Angstroms^2: ', stotal
Write(*,'(A,F12.2)') ' Total surface area per volume in m^2/cm^3: ', &
stotalreduced
Write(*,'(A,F12.2)') ' Total surface area per volume in m^2/g: ', &
stotalreduced / rho_crys
End Program NonorthoSA
!----------------FUNCTIONS-------------------------------------
FUNCTION ran0(idum)
!
! Random number generator from W.H. Press et al, Numerical Recipes in
! FORTRAN, Cambridge University Press, 1992
!
INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV
REAL(kind = 8) ran0,AM,EPS,RNMX
PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836, &
NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
INTEGER j,k,iv(NTAB),iy
SAVE iv,iy
DATA iv /NTAB*0/, iy /0/
if (idum.le.0.or.iy.eq.0) then
idum=max(-idum,1)
do 11 j=NTAB+8,1,-1
k=idum/IQ
idum=IA*(idum-k*IQ)-IR*k
if (idum.lt.0) idum=idum+IM
if (j.le.NTAB) iv(j)=idum
11 continue
iy=iv(1)
endif
k=idum/IQ
idum=IA*(idum-k*IQ)-IR*k
if (idum.lt.0) idum=idum+IM
j=1+iy/NDIV
iy=iv(j)
iv(j)=idum
ran0=min(AM*iy,RNMX)
return
END FUNCTION ran0 |
Partager