correction of gamsc
[unres4.git] / source / unres / MD.f90
index 36124aa..82ecbe8 100644 (file)
 
       nbond=nct-nnt
       do i=nnt,nct
-        if (itype(i).ne.10) nbond=nbond+1
+        if (itype(i,1).ne.10) nbond=nbond+1
       enddo
 !
       if (lprn1) then
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind1=ind1+1
           do j=1,3
             Bmat(ind+j,ind1)=dC_norm(j,i+nres)
           Td(i)=Td(i)+vbl*Tmat(i,ind)
         enddo
         do k=nnt,nct
-          if (itype(k).ne.10) then
+          if (itype(k,1).ne.10) then
             ind=ind+1
-            Td(i)=Td(i)+vbldsc0(1,itype(k))*Tmat(i,ind)
+            Td(i)=Td(i)+vbldsc0(1,itype(k,1))*Tmat(i,ind)
           endif
         enddo
       enddo 
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           do j=1,3
             ind=ind+1
             zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
               i,(dC(j,i),j=1,3),xx
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          if (itype(i,1).ne.10) then
             ind=ind+1
-            xx=vbld(i+nres)-vbldsc0(1,itype(i))
+            xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
             write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
              i,(dC(j,i+nres),j=1,3),xx
           endif
         endif
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind=ind+1
           blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
-          ppvec(ind)=2*vbldsc0(1,itype(i))**2-blen2
-          diffbond=dabs(vbldsc0(1,itype(i))-dsqrt(blen2))
+          ppvec(ind)=2*vbldsc0(1,itype(i,1))**2-blen2
+          diffbond=dabs(vbldsc0(1,itype(i,1))-dsqrt(blen2))
           if (diffbond.gt.diffmax) diffmax=diffbond
           if (ppvec(ind).gt.0.0d0) then
             ppvec(ind)=dsqrt(ppvec(ind))
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           do j=1,3
             dc(j,i+nres)=zapas(ind+j)
             dc_work(ind+j)=zapas(ind+j)
               i,(dC(j,i),j=1,3),xx
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          if (itype(i,1).ne.10) then
             ind=ind+1
-            xx=vbld(i+nres)-vbldsc0(1,itype(i))
+            xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
             write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
              i,(dC(j,i+nres),j=1,3),xx
           endif
       potE=potEcomp(0)-potEcomp(20)
       call cartgrad
       totT=totT+d_time
+      totTafm=totT
 !  Calculate the kinetic and total energy and the kinetic temperature
       call kinetic(EK)
 #ifdef MPI
 !      include 'COMMON.IOUNITS'
       real(kind=8) :: KE_total
                                                              
-      integer :: i,j,k,iti
+      integer :: i,j,k,iti,mnum
       real(kind=8) :: KEt_p,KEt_sc,KEr_p,KEr_sc,incr(3),&
        mag1,mag2,v(3) 
 #ifdef DEBUG
 #endif       
       KEt_p=0.0d0
       KEt_sc=0.0d0
-!      write (iout,*) "ISC",(isc(itype(i)),i=1,nres)
+!      write (iout,*) "ISC",(isc(itype(i,1)),i=1,nres)
 !   The translational part for peptide virtual bonds      
       do j=1,3
         incr(j)=d_t(j,0)
       enddo
       do i=nnt,nct-1
+       mnum=molnum(i)
 !        write (iout,*) "Kinetic trp:",i,(incr(j),j=1,3) 
         do j=1,3
           v(j)=incr(j)+0.5d0*d_t(j,i)
        enddo
         vtot(i)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
-        KEt_p=KEt_p+(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))            
+        KEt_p=KEt_p+mp(mnum)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))           
         do j=1,3
           incr(j)=incr(j)+d_t(j,i)
         enddo
         incr(j)=d_t(j,0)
       enddo
       do i=nnt,nct
-        iti=iabs(itype(i))
-        if (itype(i).eq.10) then
+         mnum=molnum(i)
+        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
+          .or.(mnum.eq.5)) then
           do j=1,3
             v(j)=incr(j)
          enddo   
         endif
 !        write (iout,*) "Kinetic trsc:",i,(incr(j),j=1,3) 
 !        write (iout,*) "i",i," msc",msc(iti)," v",(v(j),j=1,3) 
-        KEt_sc=KEt_sc+msc(iti)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))         
+        KEt_sc=KEt_sc+msc(iti,mnum)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))            
         vtot(i+nres)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
         do j=1,3
           incr(j)=incr(j)+d_t(j,i)
 !  The part due to stretching and rotation of the peptide groups
        KEr_p=0.0D0
        do i=nnt,nct-1
+       mnum=molnum(i)
 !        write (iout,*) "i",i 
 !        write (iout,*) "i",i," mag1",mag1," mag2",mag2 
         do j=1,3
          incr(j)=d_t(j,i)
        enddo
 !        write (iout,*) "Kinetic rotp:",i,(incr(j),j=1,3) 
-         KEr_p=KEr_p+(incr(1)*incr(1)+incr(2)*incr(2) &
+         KEr_p=KEr_p+Ip(mnum)*(incr(1)*incr(1)+incr(2)*incr(2) &
          +incr(3)*incr(3))
        enddo  
 !      goto 111
 !  The rotational part of the side chain virtual bond
        KEr_sc=0.0D0
        do i=nnt,nct
-        iti=iabs(itype(i))
-        if (itype(i).ne.10) then
+       mnum=molnum(i)
+        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
         do j=1,3
          incr(j)=d_t(j,nres+i)
        enddo
 !        write (iout,*) "Kinetic rotsc:",i,(incr(j),j=1,3) 
-       KEr_sc=KEr_sc+Isc(iti)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
+       KEr_sc=KEr_sc+Isc(iti,mnum)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
          incr(3)*incr(3))
         endif
        enddo
 ! The total kinetic energy     
   111  continue
 !       write(iout,*) 'KEr_sc', KEr_sc 
-       KE_total=0.5d0*(mp*KEt_p+KEt_sc+0.25d0*Ip*KEr_p+KEr_sc)         
+       KE_total=0.5d0*(KEt_p+KEt_sc+0.25d0*KEr_p+KEr_sc)               
 !       write (iout,*) "KE_total",KE_total 
       return
       end subroutine kinetic
           enddo
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+          if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
             do j=1,3
               ind=ind+1
               v_work(ind)=d_t(j,i+nres)
         if (rstcount.eq.1000.or.itime.eq.n_timestep) then
            open(irest2,file=rest2name,status='unknown')
            write(irest2,*) totT,EK,potE,totE,t_bath
+        totTafm=totT 
 ! AL 4/17/17: Now writing d_t(0,:) too
            do i=0,2*nres
             write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
           endif                    
           if (rattle) call rattle2
           totT=totT+d_time
+        totTafm=totT
           if (d_time.ne.d_time0) then
             d_time=d_time0
 #ifndef   LANG0
       potE=potEcomp(0)-potEcomp(20)
 !      potE=energia_short(0)+energia_long(0)
       totT=totT+d_time
+        totTafm=totT
 ! Calculate the kinetic and the total energy and the kinetic temperature
       call kinetic(EK)
       totE=EK+potE
 !      include 'COMMON.INTERACT'
 !      include 'COMMON.IOUNITS'
 !      include 'COMMON.NAMES'
-      integer :: i,j,inres
+      integer :: i,j,inres,mnum
 
       do j=1,3
         d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
 !      include 'COMMON.IOUNITS'
 !      include 'COMMON.NAMES'
       real(kind=8) :: adt,adt2
-      integer :: i,j,inres
+      integer :: i,j,inres,mnum
         
 #ifdef DEBUG
       write (iout,*) "VELVERLET1 START: DC"
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3    
             adt=d_a_old(j,inres)*d_time
 !      include 'COMMON.INTERACT'
 !      include 'COMMON.IOUNITS'
 !      include 'COMMON.NAMES'
-      integer :: i,j,inres
+      integer :: i,j,inres,mnum
 
       do j=1,3
         d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
 ! position and velocity increments included.
       real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
       real(kind=8) :: adt,adt2
-      integer :: i,j,ind,inres
+      integer :: i,j,ind,inres,mnum
 !
 ! Add the contribution from BOTH friction and stochastic force to the
 ! coordinates, but ONLY the contribution from the friction forces to velocities
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3    
             adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
 !      include 'COMMON.NAMES'
       real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1        !(MAXRES6) maxres6=6*maxres
       real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
-      integer :: i,j,ind,inres
+      integer :: i,j,ind,inres,mnum
 ! Revised 3/31/05 AL: correlation between random contributions to 
 ! position and velocity increments included.
 ! The correlation coefficients are calculated at low-friction limit.
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
 !      include 'COMMON.IOUNITS'
       real(kind=8),dimension(3) :: aux,accel,accel_old
       real(kind=8) :: dacc
-      integer :: i,j
+      integer :: i,j,mnum
 
       do j=1,3
 !        aux(j)=d_a(j,0)-d_a_old(j,0)
         enddo
       endif
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           do j=1,3 
 !            accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
             accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
           enddo
         endif
 ! Side chains
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
           do j=1,3 
             epdriftij= &
              dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
 !      include 'COMMON.IOUNITS'
 !      include 'COMMON.NAMES'
       real(kind=8) :: T_half,fact
-      integer :: i,j,inres
+      integer :: i,j,inres,mnum
 ! 
       T_half=2.0d0/(dimen3*Rb)*EK
       fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             d_t(j,inres)=fact*d_t(j,inres)
       character(len=50) :: tytul
       logical :: file_exist
 !el      common /gucio/ cm
-      integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr
+      integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr,mnum
       real(kind=8) :: etot,tt0
       logical :: fail
 
 ! if the friction coefficients do not depend on surface area
       if (lang.gt.0 .and. .not.surfarea) then
         do i=nnt,nct-1
-          stdforcp(i)=stdfp*dsqrt(gamp)
+          mnum=molnum(i)
+          stdforcp(i)=stdfp(mnum)*dsqrt(gamp(mnum))
         enddo
         do i=nnt,nct
-          stdforcsc(i)=stdfsc(iabs(itype(i))) &
-                      *dsqrt(gamsc(iabs(itype(i))))
+          mnum=molnum(i)
+          stdforcsc(i)=stdfsc(iabs(itype(i,mnum)),mnum) &
+                      *dsqrt(gamsc(iabs(itype(i,mnum)),mnum))
         enddo
       endif
 ! Open the pdb file for snapshotshots
         endif
         call random_vel
         totT=0.0d0
+        totTafm=totT
        endif
       else
 ! Generate initial velocities
          write(iout,*) "Initial velocities randomly generated"
         call random_vel
         totT=0.0d0
+        totTafm=totT
       endif
 !      rest2name = prefix(:ilen(prefix))//'.rst'
       if(me.eq.king.or..not.out1file)then
        write (iout,*) "vcm right after adjustment:"
        write (iout,*) (vcm(j),j=1,3) 
       endif
-      if (.not.rest) then              
+      if ((.not.rest).and.(indpdb.eq.0)) then          
          call chainbuild
          if(iranconf.ne.0) then
           if (overlapsc) then 
        real (kind=8),allocatable,dimension(:,:) :: matold
 #endif
 #endif
-      integer :: i,j,ii,k,ind,mark,imark
+      integer :: i,j,ii,k,ind,mark,imark,mnum
 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m 
 ! First generate velocities in the eigenspace of the G matrix
 !      write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
       Ek1=0.0d0
       ii=0
       do i=nnt,nct
-        if (itype(i).eq.10) then
+!        if (itype(i,1).eq.10) then
+         mnum=molnum(i)
+        iti=iabs(itype(i,mnum))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
+          .or.(mnum.eq.5)) then
           j=ii+3
         else
           j=ii+6
         if (i.lt.nct) then
           do k=1,3
 !            write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
-            Ek1=Ek1+0.5d0*mp*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
-            0.5d0*0.25d0*IP*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
+            Ek1=Ek1+0.5d0*mp(mnum)*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
+            0.5d0*0.25d0*IP(mnum)*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
           enddo
         endif
-        if (itype(i).ne.10) ii=ii+3
-        write (iout,*) "i",i," itype",itype(i)," mass",msc(itype(i))
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) ii=ii+3
+        write (iout,*) "i",i," itype",itype(i,mnum)," mass",msc(itype(i,mnum),mnum)
         write (iout,*) "ii",ii
         do k=1,3
           ii=ii+1
           write (iout,*) "k",k," ii",ii,"EK1",EK1
-          if (iabs(itype(i)).ne.10) Ek1=Ek1+0.5d0*Isc(iabs(itype(i)))*(d_t_work(ii)-d_t_work(ii-3))**2
-          Ek1=Ek1+0.5d0*msc(iabs(itype(i)))*d_t_work(ii)**2
+          if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5))&
+           Ek1=Ek1+0.5d0*Isc(iabs(itype(i,mnum),mnum))*(d_t_work(ii)-d_t_work(ii-3))**2
+          Ek1=Ek1+0.5d0*msc(iabs(itype(i,mnum)),mnum)*d_t_work(ii)**2
         enddo
         write (iout,*) "i",i," ii",ii
       enddo
           d_t(k,j)=d_t_work(ind)
           ind=ind+1
         enddo
-        if (itype(j).ne.10 .and. itype(j).ne.ntyp1) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5))
           do k=1,3
             d_t(k,j+nres)=d_t_work(ind)
             ind=ind+1
         d_t(j,0)=d_t(j,nnt)
       enddo
       do i=nnt,nct
-        if (itype(i).eq.10) then
+!        if (itype(i,1).eq.10) then
+         mnum=molnum(i)
+         if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
+          .or.(mnum.eq.5))
           do j=1,3
             d_t(j,i)=d_t(j,i+1)-d_t(j,i)
           enddo
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           do j=1,3
             ind=ind+1
             d_t(j,i+nres)=d_t_work(ind)
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           do j=1,3
             dc_work(ind+j)=dc_old(j,i+nres)
             d_t_work(ind+j)=d_t_old(j,i+nres)
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             dc(j,inres)=dc_work(ind+j)
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             d_t(j,inres)=d_t_work(ind+j)
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
           do j=1,3
             dc_work(ind+j)=dc_old(j,i+nres)
             d_t_work(ind+j)=d_t_old(j,i+nres)
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           inres=i+nres
           do j=1,3
             dc(j,inres)=dc_work(ind+j)
         ind=ind+3
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5))
+!        if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
           inres=i+nres
           do j=1,3
             d_t(j,inres)=d_t_work(ind+j)
       
       real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
       real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
-      real(kind=8) :: M_SC,mag,mag2 
+      real(kind=8) :: M_SC,mag,mag2,M_PEP
       real(kind=8),dimension(3,0:nres) :: vpp  !(3,0:MAXRES)
       real(kind=8),dimension(3) :: vs_p,pp,incr,v
       real(kind=8),dimension(3,3) :: pr1,pr2
 
 !el      common /gucio/ cm
-      integer :: iti,inres,i,j,k
+      integer :: iti,inres,i,j,k,mnum
         do i=1,3
           do j=1,3
              Im(i,j)=0.0d0
            vrot(i)=0.0d0                  
         enddo
 !   calculating the center of the mass of the protein                                  
+        M_PEP=0.0d0
         do i=nnt,nct-1
+          mnum=molnum(i)
+          if (itype(i,mnum).eq.ntyp1_molec(mnum)) cycle
+          M_PEP=M_PEP+mp(mnum)
           do j=1,3
-            cm(j)=cm(j)+c(j,i)+0.5d0*dc(j,i)
+            cm(j)=cm(j)+(c(j,i)+0.5d0*dc(j,i))*mp(mnum)
           enddo
         enddo
-        do j=1,3
-         cm(j)=mp*cm(j)
-        enddo
+!        do j=1,3
+!         cm(j)=mp(1)*cm(j)
+!        enddo
         M_SC=0.0d0                             
         do i=nnt,nct
-           iti=iabs(itype(i))           
-          M_SC=M_SC+msc(iabs(iti))
+           mnum=molnum(i)
+           iti=iabs(itype(i,mnum))              
+          M_SC=M_SC+msc(iabs(iti),mnum)
            inres=i+nres
            do j=1,3
-            cm(j)=cm(j)+msc(iabs(iti))*c(j,inres)          
+            cm(j)=cm(j)+msc(iabs(iti),mnum)*c(j,inres)     
            enddo
         enddo
         do j=1,3
-          cm(j)=cm(j)/(M_SC+(nct-nnt)*mp)
+          cm(j)=cm(j)/(M_SC+M_PEP)
         enddo
        
         do i=nnt,nct-1
+           mnum=molnum(i)
           do j=1,3
             pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
           enddo
-          Im(1,1)=Im(1,1)+mp*(pr(2)*pr(2)+pr(3)*pr(3))
-          Im(1,2)=Im(1,2)-mp*pr(1)*pr(2)
-          Im(1,3)=Im(1,3)-mp*pr(1)*pr(3)
-          Im(2,3)=Im(2,3)-mp*pr(2)*pr(3)       
-          Im(2,2)=Im(2,2)+mp*(pr(3)*pr(3)+pr(1)*pr(1))
-          Im(3,3)=Im(3,3)+mp*(pr(1)*pr(1)+pr(2)*pr(2))
+          Im(1,1)=Im(1,1)+mp(mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
+          Im(1,2)=Im(1,2)-mp(mnum)*pr(1)*pr(2)
+          Im(1,3)=Im(1,3)-mp(mnum)*pr(1)*pr(3)
+          Im(2,3)=Im(2,3)-mp(mnum)*pr(2)*pr(3) 
+          Im(2,2)=Im(2,2)+mp(mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
+          Im(3,3)=Im(3,3)+mp(mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
         enddo                  
         
        do i=nnt,nct    
-           iti=iabs(itype(i))
+           mnum=molnum(i)
+           iti=iabs(itype(i,mnum))
            inres=i+nres
            do j=1,3
              pr(j)=c(j,inres)-cm(j)        
            enddo
-          Im(1,1)=Im(1,1)+msc(iabs(iti))*(pr(2)*pr(2)+pr(3)*pr(3))
-          Im(1,2)=Im(1,2)-msc(iabs(iti))*pr(1)*pr(2)
-          Im(1,3)=Im(1,3)-msc(iabs(iti))*pr(1)*pr(3)
-          Im(2,3)=Im(2,3)-msc(iabs(iti))*pr(2)*pr(3)   
-          Im(2,2)=Im(2,2)+msc(iabs(iti))*(pr(3)*pr(3)+pr(1)*pr(1))
-          Im(3,3)=Im(3,3)+msc(iabs(iti))*(pr(1)*pr(1)+pr(2)*pr(2))                
+          Im(1,1)=Im(1,1)+msc(iabs(iti),mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
+          Im(1,2)=Im(1,2)-msc(iabs(iti),mnum)*pr(1)*pr(2)
+          Im(1,3)=Im(1,3)-msc(iabs(iti),mnum)*pr(1)*pr(3)
+          Im(2,3)=Im(2,3)-msc(iabs(iti),mnum)*pr(2)*pr(3)      
+          Im(2,2)=Im(2,2)+msc(iabs(iti),mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
+          Im(3,3)=Im(3,3)+msc(iabs(iti),mnum)*(pr(1)*pr(1)+pr(2)*pr(2))           
         enddo
           
         do i=nnt,nct-1
-          Im(1,1)=Im(1,1)+Ip*(1-dc_norm(1,i)*dc_norm(1,i))* &    
+           mnum=molnum(i)
+          Im(1,1)=Im(1,1)+Ip(mnum)*(1-dc_norm(1,i)*dc_norm(1,i))* &      
           vbld(i+1)*vbld(i+1)*0.25d0
-         Im(1,2)=Im(1,2)+Ip*(-dc_norm(1,i)*dc_norm(2,i))* &
+         Im(1,2)=Im(1,2)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(2,i))* &
           vbld(i+1)*vbld(i+1)*0.25d0             
-          Im(1,3)=Im(1,3)+Ip*(-dc_norm(1,i)*dc_norm(3,i))* &
+          Im(1,3)=Im(1,3)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(3,i))* &
           vbld(i+1)*vbld(i+1)*0.25d0     
-          Im(2,3)=Im(2,3)+Ip*(-dc_norm(2,i)*dc_norm(3,i))* &
+          Im(2,3)=Im(2,3)+Ip(mnum)*(-dc_norm(2,i)*dc_norm(3,i))* &
           vbld(i+1)*vbld(i+1)*0.25d0           
-          Im(2,2)=Im(2,2)+Ip*(1-dc_norm(2,i)*dc_norm(2,i))* &
+          Im(2,2)=Im(2,2)+Ip(mnum)*(1-dc_norm(2,i)*dc_norm(2,i))* &
           vbld(i+1)*vbld(i+1)*0.25d0     
-          Im(3,3)=Im(3,3)+Ip*(1-dc_norm(3,i)*dc_norm(3,i))* &
+          Im(3,3)=Im(3,3)+Ip(mnum)*(1-dc_norm(3,i)*dc_norm(3,i))* &
           vbld(i+1)*vbld(i+1)*0.25d0
         enddo
         
                                
         do i=nnt,nct
-         if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
-           iti=iabs(itype(i))           
+              mnum=molnum(i)
+!         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
+           iti=iabs(itype(i,mnum))              
            inres=i+nres
-          Im(1,1)=Im(1,1)+Isc(iti)*(1-dc_norm(1,inres)* &
+          Im(1,1)=Im(1,1)+Isc(iti,mnum)*(1-dc_norm(1,inres)* &
          dc_norm(1,inres))*vbld(inres)*vbld(inres)
-          Im(1,2)=Im(1,2)-Isc(iti)*(dc_norm(1,inres)* &
+          Im(1,2)=Im(1,2)-Isc(iti,mnum)*(dc_norm(1,inres)* &
          dc_norm(2,inres))*vbld(inres)*vbld(inres)
-          Im(1,3)=Im(1,3)-Isc(iti)*(dc_norm(1,inres)* &
+          Im(1,3)=Im(1,3)-Isc(iti,mnum)*(dc_norm(1,inres)* &
          dc_norm(3,inres))*vbld(inres)*vbld(inres)
-          Im(2,3)=Im(2,3)-Isc(iti)*(dc_norm(2,inres)* &
+          Im(2,3)=Im(2,3)-Isc(iti,mnum)*(dc_norm(2,inres)* &
          dc_norm(3,inres))*vbld(inres)*vbld(inres)     
-          Im(2,2)=Im(2,2)+Isc(iti)*(1-dc_norm(2,inres)* &
+          Im(2,2)=Im(2,2)+Isc(iti,mnum)*(1-dc_norm(2,inres)* &
          dc_norm(2,inres))*vbld(inres)*vbld(inres)
-          Im(3,3)=Im(3,3)+Isc(iti)*(1-dc_norm(3,inres)* &
+          Im(3,3)=Im(3,3)+Isc(iti,mnum)*(1-dc_norm(3,inres)* &
                  dc_norm(3,inres))*vbld(inres)*vbld(inres)
          endif
         enddo
           enddo
         enddo
         do i=nnt,nct 
-        if(itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+              mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
+!         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
+!       if(itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
            inres=i+nres
            call vecpr(vrot(1),dc(1,inres),vp)                   
           do j=1,3
 !       include 'COMMON.NAMES'
       
       real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
-      integer :: iti,inres,i,j
+      integer :: iti,inres,i,j,mnum
 !  Calculate the angular momentum
        do j=1,3
           L(j)=0.0d0
           incr(j)=d_t(j,0)
        enddo                  
        do i=nnt,nct-1
+          mnum=molnum(i)
           do j=1,3
             pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
           enddo
           enddo                
           call vecpr(pr(1),v(1),vp)
           do j=1,3
-            L(j)=L(j)+mp*vp(j)
+            L(j)=L(j)+mp(mnum)*vp(j)
           enddo
           do j=1,3
              pr(j)=0.5d0*dc(j,i)
           enddo
          call vecpr(pr(1),pp(1),vp)
          do j=1,3               
-             L(j)=L(j)+Ip*vp(j)         
+             L(j)=L(j)+Ip(mnum)*vp(j)   
           enddo
         enddo
         do j=1,3
           incr(j)=d_t(j,0)
         enddo  
         do i=nnt,nct
-         iti=iabs(itype(i))
+          mnum=molnum(i)
+         iti=iabs(itype(i,mnum))
          inres=i+nres
          do j=1,3
            pr(j)=c(j,inres)-cm(j)          
          enddo
-         if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
            do j=1,3
              v(j)=incr(j)+d_t(j,inres)
            enddo
 !         write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),
 !     &     " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
          do j=1,3
-            L(j)=L(j)+msc(iabs(iti))*vp(j)
+            L(j)=L(j)+msc(iabs(iti),mnum)*vp(j)
          enddo
 !         write (iout,*) "L",(l(j),j=1,3)
-         if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           do j=1,3
             v(j)=incr(j)+d_t(j,inres)
            enddo
            call vecpr(dc(1,inres),d_t(1,inres),vp)
            do j=1,3                               
-             L(j)=L(j)+Isc(iti)*vp(j)   
+             L(j)=L(j)+Isc(iti,mnum)*vp(j)      
           enddo                           
          endif
         do j=1,3
 !       include 'COMMON.IOUNITS'
        real(kind=8),dimension(3) :: vcm,vv
        real(kind=8) :: summas,amas
-       integer :: i,j
+       integer :: i,j,mnum
 
        do j=1,3
          vcm(j)=0.0d0
        enddo
        summas=0.0d0
        do i=nnt,nct
+         mnum=molnum(i)
          if (i.lt.nct) then
-           summas=summas+mp
+           summas=summas+mp(mnum)
            do j=1,3
-             vcm(j)=vcm(j)+mp*(vv(j)+0.5d0*d_t(j,i))
+             vcm(j)=vcm(j)+mp(mnum)*(vv(j)+0.5d0*d_t(j,i))
            enddo
          endif
-         amas=msc(iabs(itype(i)))
+         amas=msc(iabs(itype(i,mnum)),mnum)
          summas=summas+amas                     
-         if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
+         if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
            do j=1,3
              vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
            enddo
       if (lprn) write (iout,*) "RATTLE1"
       nbond=nct-nnt
       do i=nnt,nct
-        if (itype(i).ne.10) nbond=nbond+1
+       mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) nbond=nbond+1
       enddo
 ! Make a folded form of the Ginv-matrix
       ind=0
             enddo
           enddo
           do k=nnt,nct
-            if (itype(k).ne.10) then
+          mnum=molnum(k)
+         if (itype(k,1).ne.10 .and. itype(k,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
               jj=jj+1
               do l=1,3
                 ind1=ind1+1
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5))
           ii=ii+1
           do j=1,3
             ind=ind+1
               enddo
             enddo
             do k=nnt,nct
-              if (itype(k).ne.10) then
+              if (itype(k,1).ne.10) then
                 jj=jj+1
                 do l=1,3
                   ind1=ind1+1
         enddo
       enddo 
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind1=ind1+1
           do j=1,3
             dC_uncor(j,ind1)=dC(j,i+nres)
           enddo
         enddo
         do k=nnt,nct
-          if (itype(k).ne.10) then
+          if (itype(k,1).ne.10) then
             ind=ind+1
             do j=1,3
               gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
         x(ind)=vbld(i+1)**2-vbl**2
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind=ind+1
-          x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
+          x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
         endif
       enddo
       if (lprn) then
            i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
+
             ind=ind+1
             write (iout,'(2i5,3f10.5,5x,e15.5)') &
              i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind=ind+1
           do j=1,3
             xx=0.0d0
               i,(dC(j,i),j=1,3),x(ind),xx
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5))
             ind=ind+1
-            xx=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
+            xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
             write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
              i,(dC(j,i+nres),j=1,3),x(ind),xx
           endif
            i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          if (itype(i,1).ne.10) then
             ind=ind+1
             write (iout,'(2i5,3f10.5,5x,e15.5)') &
              i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
           enddo
         enddo
         do k=nnt,nct
-          if (itype(k).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
             ind=ind+1
             do j=1,3
               gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           ind=ind+1
           do j=1,nbond
             Cmat(ind,j)=0.0d0
         x(ind)=scalar(d_t(1,i),dC(1,i))
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           ind=ind+1
           x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
         endif
            i,ind,(d_t(j,i),j=1,3),x(ind)
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
             ind=ind+1
             write (iout,'(2i5,3f10.5,5x,e15.5)') &
              i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5)) then
           ind=ind+1
           do j=1,3
             xx=0.0d0
              i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+         mnum=molnum(i)
+         if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
+          .and.(mnum.ne.5))
             ind=ind+1
             write (iout,'(2i5,3f10.5,5x,2e15.5)') &
               i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
 !el      common /przechowalnia/ GGinv,gdc,Cmat,nbond
 !el      common /przechowalnia/ nbond
       integer :: max_rattle = 5
-      logical :: lprn = .true., lprn1 = .true., not_done
+      logical :: lprn = .false., lprn1 = .false., not_done
       real(kind=8) :: tol_rattle = 1.0d-5
       integer :: nres2
       nres2=2*nres
       if (lprn) write (iout,*) "RATTLE_BROWN"
       nbond=nct-nnt
       do i=nnt,nct
-        if (itype(i).ne.10) nbond=nbond+1
+        if (itype(i,1).ne.10) nbond=nbond+1
       enddo
 ! Make a folded form of the Ginv-matrix
       ind=0
             enddo
           enddo
           do k=nnt,nct
-            if (itype(k).ne.10) then
+            if (itype(k,1).ne.10) then
               jj=jj+1
               do l=1,3
                 ind1=ind1+1
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ii=ii+1
           do j=1,3
             ind=ind+1
               enddo
             enddo
             do k=nnt,nct
-              if (itype(k).ne.10) then
+              if (itype(k,1).ne.10) then
                 jj=jj+1
                 do l=1,3
                   ind1=ind1+1
         enddo
       enddo 
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind1=ind1+1
           do j=1,3
             dC_uncor(j,ind1)=dC(j,i+nres)
           enddo
         enddo
         do k=nnt,nct
-          if (itype(k).ne.10) then
+          if (itype(k,1).ne.10) then
             ind=ind+1
             do j=1,3
               gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
         x(ind)=vbld(i+1)**2-vbl**2
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind=ind+1
-          x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
+          x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
         endif
       enddo
       if (lprn) then
            i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          if (itype(i,1).ne.10) then
             ind=ind+1
             write (iout,'(2i5,3f10.5,5x,e15.5)') &
              i+nres,ind,(d_t(j,i+nres),j=1,3),&
         enddo
       enddo
       do i=nnt,nct
-        if (itype(i).ne.10) then
+        if (itype(i,1).ne.10) then
           ind=ind+1
           do j=1,3
             xx=0.0d0
               i,(dC(j,i),j=1,3),x(ind),xx
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          if (itype(i,1).ne.10) then
             ind=ind+1
-            xx=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
+            xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
             write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
              i,(dC(j,i+nres),j=1,3),x(ind),xx
           endif
            i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
         enddo
         do i=nnt,nct
-          if (itype(i).ne.10) then
+          if (itype(i,1).ne.10) then
             ind=ind+1
             write (iout,'(2i5,3f10.5,5x,e15.5)') &
              i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
 !el      common /przechowalnia/ ginvfric
       
       logical :: lprn = .false., checkmode = .false.
-      integer :: i,j,ind,k,nres2,nres6
+      integer :: i,j,ind,k,nres2,nres6,mnum
       nres2=2*nres
       nres6=6*nres
 
         ind=ind+3
       enddo
       do i=nnt,nct
-        if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
+        mnum=molnum(i)
+        if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
+        .and.(mnum.ne.5)) then
           do j=1,3
             d_t_work(ind+j)=d_t(j,i+nres)
           enddo
         ind=ind+3
       enddo
       do i=nnt,nct
-        if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
+        mnum=molnum(i)
+        if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
+        .and.(mnum.ne.5)) then
+!        if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
           do j=1,3
             friction(j,i+nres)=fric_work(ind+j)
           enddo
       real(kind=8) :: work(8*2*nres)
       integer :: iwork(2*nres)
 !el      common /przechowalnia/ ginvfric,Ghalf,fcopy
-      integer :: ii,iti,k,l,nzero,nres2,nres6,ierr
+      integer :: ii,iti,k,l,nzero,nres2,nres6,ierr,mnum
 #ifdef MPI
       if (fg_rank.ne.king) goto 10
 #endif
 !  Load the friction coefficients corresponding to peptide groups
       ind1=0
       do i=nnt,nct-1
+        mnum=molnum(i)
         ind1=ind1+1
-        gamvec(ind1)=gamp
+        gamvec(ind1)=gamp(mnum)
       enddo
 !  Load the friction coefficients corresponding to side chains
       m=nct-nnt
       ind=0
-      gamsc(ntyp1)=1.0d0
+      do j=1,2
+      gamsc(ntyp1_molec(j),j)=1.0d0
+      enddo
       do i=nnt,nct
+        mnum=molnum(i)
         ind=ind+1
         ii = ind+m
-        iti=itype(i)
-        gamvec(ii)=gamsc(iabs(iti))
+        iti=itype(i,mnum)
+        gamvec(ii)=gamsc(iabs(iti),mnum)
       enddo
       if (surfarea) call sdarea(gamvec)
 !      if (lprn) then
       real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
       real(kind=8) :: time00
       logical :: lprn = .false.
-      integer :: i,j,ind
+      integer :: i,j,ind,mnum
 
       do i=0,2*nres
         do j=1,3
         do j=1,3
           ff(j)=ff(j)+force(j,i)
         enddo
-        if (itype(i+1).ne.ntyp1) then
+!        if (itype(i+1,1).ne.ntyp1) then
+         mnum=molnum(i)
+         if (itype(i+1,mnum).ne.ntyp1_molec(mnum)) then
           do j=1,3
             stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
             ff(j)=ff(j)+force(j,i+nres+1)
         stochforc(j,0)=ff(j)+force(j,nnt+nres)
       enddo
       do i=nnt,nct
-        if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
+        mnum=molnum(i)
+        if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
+        .and.(mnum.ne.5)) then
+!        if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
           do j=1,3
             stochforc(j,i+nres)=force(j,i+nres)
           enddo
         ind=ind+3
       enddo
       do i=nnt,nct
-        if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
+        mnum=molnum(i)
+        if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
+        .and.(mnum.ne.5)) then
+!        if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
           do j=1,3
             stochforcvec(ind+j)=stochforc(j,i+nres)
           enddo
       real(kind=8),parameter :: twosix = 1.122462048309372981d0
       logical :: lprn = .false.
       real(kind=8) :: probe,area,ratio
-      integer :: i,j,ind,iti
+      integer :: i,j,ind,iti,mnum
 !
 !     determine new friction coefficients every few SD steps
 !
       enddo
 !  Load peptide group radii
       do i=nnt,nct-1
-        radius(i)=pstok
+        mnum=molnum(i)
+        radius(i)=pstok(mnum)
       enddo
 !  Load side chain radii
       do i=nnt,nct
-        iti=itype(i)
-        radius(i+nres)=restok(iti)
+        mnum=molnum(i)
+        iti=itype(i,mnum)
+        radius(i+nres)=restok(iti,mnum)
       enddo
 !      do i=1,2*nres
 !        write (iout,*) "i",i," radius",radius(i) 
             ind=ind+1
             gamvec(ind) = ratio * gamvec(ind)
           enddo
-          stdforcp(i)=stdfp*dsqrt(gamvec(ind))
+          mnum=molnum(i)
+          stdforcp(i)=stdfp(mnum)*dsqrt(gamvec(ind))
           if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
         endif
       enddo
             ind=ind+1 
             gamvec(ind) = ratio * gamvec(ind)
           enddo
-          stdforcsc(i)=stdfsc(itype(i))*dsqrt(gamvec(ind))
+          mnum=molnum(i)
+          stdforcsc(i)=stdfsc(itype(i,mnum),mnum)*dsqrt(gamvec(ind))
           if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
         endif
       enddo