fortran有关文件的试题求救

文件propene.mol是ACD/ChemSketch所生成的丙烯分子的mol格式文件,读出其中的坐标数据,求出所有的任意两原子之间的距离,写入文件data.txt中(提示需要对原子按顺序进行编号)。

图片中框起来的是原子坐标。
文件内容用记事本打开后如下:
ACD/Labs06161409443D
9 8 0 0 0 0 0 0 0 0 1 V2000 -1.3862 0.2568 0.3311 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.0048 -0.4184 0.2913 C 0 0 0 0 0 0 0 0 0 0 0 0 1.1277 0.3436 0.3051 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.7416 0.4506 -0.7259 H 0 0 0 0 0 0 0 0 0 0 0 0 -2.1226 -0.4224 0.8580 H 0 0 0 0 0 0 0 0 0 0 0 0 -1.3099 1.2385 0.8893 H 0 0 0 0 0 0 0 0 0 0 0 0 0.1882 -1.5328 0.2496 H 0 0 0 0 0 0 0 0 0 0 0 0 2.1443 -0.1529 0.2758 H 0 0 0 0 0 0 0 0 0 0 0 0 1.0501 1.4720 0.3460 H 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 1 4 1 0 0 0 0 1 5 1 0 0 0 0 1 6 1 0 0 0 0 2 3 2 0 0 0 0 2 7 1 0 0 0 0 3 8 1 0 0 0 0 3 9 1 0 0 0 0M END

代码如下,供参考

      program test
      implicit none
      character(len=200) :: string
      real(8),allocatable :: xyz(:,:)
      real(8) :: rij
      integer :: natoms,nbonds
      integer :: i,j
       
      open(10,file='propene.mol',action='read')
      read(10,*)
      read(10,*)
      read(10,*)
      read(10,'(a200)') string
      read(string(1:3),*) natoms
      read(string(4:6),*) nbonds
      allocate(xyz(natoms,3))
      do i = 1,natoms
          read(10,*) xyz(i,1:3)
          ! print '(3f14.8,x)', xyz(i,:)
      end do
      close(10)
      
      open(11,file='data.txt',action='write')
      do i = 1,natoms-1
          do j = i+1,natoms
              rij = dsqrt( sum( (xyz(i,:) - xyz(j,:))**2 ) )
              write(11,*) i,j,rij
              write(*,*) i,j,rij
          end do
      end do
      close(11)
       
      stop
      end program

运行结果,同时保存文件data.txt中

           1           2   1.53809786424662     
           1           3   2.51553243866979     
           1           4   1.13186421447098     
           1           5   1.13191042490119     
           1           6   1.13187623881765     
           1           7   2.38496242528053     
           1           8   3.55462268461788     
           1           9   2.72258897742572     
           2           3   1.36506069095846     
           2           4   2.19233461862007     
           2           5   2.19231424070547     
           2           6   2.19230646124122     
           2           7   1.13175759330344     
           2           8   2.16549331793012     
           2           9   2.16550646731890     
           3           4   3.05078555293551     
           3           5   3.38480494268134     
           3           6   2.66158400393450     
           3           7   2.09919447884182     
           3           8   1.13174480338988     
           3           9   1.13180436913806     
           4           5   1.84825031042876     
           4           6   1.84824845191332     
           4           7   2.93421264566834     
           4           8   4.05805790372685     
           4           9   3.16003424981439     
           5           6   1.84933766251596     
           5           7   2.63494503927501     
           5           8   4.31486068141255     
           5           9   3.73053892219341     
           6           7   3.21459536956053     
           6           8   3.77410570201737     
           6           9   2.43296057099165     
           7           8   2.39397946106478     
           7           9   3.12745705166354     
           8           9   1.96023000946318

其中

           4           5   1.84825031042876

表示第4个原子和第5个原子间的距离为1.84825031042876 (Angstrom)

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网