首先我是一个完整的新手,FORTRAN,和一般的大多数形式的节目。 随着中说,我试图建立一个框,然后随机产生X,Y,Z为100个原子的坐标。 从那里,目标是计算各原子之间的距离,所述距离结果执行一些数学。 下面是我的代码。 即便N定义为100,并将打印“100”,当我打印CX我只得到20个结果。
program energytot
implicit none
integer :: i, n, j, seed(12), k, m
double precision:: sigma, r, epsilon, lx, ly, lz
double precision, dimension(:), allocatable :: cx, cy, cz, dx, dy, dz, x, y, z, LJx, LJy, LJz
allocate(x(n), y(n), z(n), LJx(n), LJy(n), LJz(n), dx(n), dy(n), dz(n))
n = 100 !Number of molecules inside the box
sigma = 4.1
epsilon = 1.7
!Box length with respect to the axis
lx = 15
ly = 15
lz = 15
do i=1,12
seed(i)=1+3
end do
!generate n random numbers for x, y, z
call RANDOM_SEED(PUT = seed)
call random_number(x)
call random_number(y)
call random_number(z)
!convert random numbers into x, y, z coordinates with (0,0,0) as the central point
cx = ((2*x)-1)*(lx*0.5)
cy = ((2*y)-1)*(lx*0.5)
cz = ((2*z)-1)*(lz*0.5)
do j=1,n-1
do k=j+1,n
dx = ABS((cx(j) - cx(j+1)))
LJx = 4 * epsilon * ((sigma/dx(j))**12 - (sigma/dx(j))**6)
dy = ABS((cy(j) - cy(j+1)))
LJy = 4 * epsilon * ((sigma/dy(j))**12 - (sigma/dy(j))**6)
dz = ABS((cz(j) - cz(j+1)))
LJz = 4 * epsilon * ((sigma/dz(j))**12 - (sigma/dz(j))**6)
end do
end do
print*,cx
print*,x
end program energytot