fortran有关文件的试题求救

文件propene.mol是ACD/ChemSketch所生成的丙烯分子的mol格式文件,读出其中的坐标数据,求出所有的任意两原子之间的距离,写入文件data.txt中(... 文件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
展开
 我来答
xmenlab
推荐于2016-11-27 · TA获得超过180个赞
知道小有建树答主
回答量:96
采纳率:0%
帮助的人:137万
展开全部

代码如下,供参考

      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)

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式