diff -aur amber11.orig/src/sander/bintraj.f amber11/src/sander/bintraj.f
--- amber11.orig/src/sander/bintraj.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/bintraj.f	2010-06-14 15:32:22.370558041 +0200
@@ -8,11 +8,11 @@
 module bintraj
    private
 
-   integer :: crd_ncid, vel_ncid, oldMode, cmode, atomCnt
+   integer :: crd_ncid, vel_ncid, dip_ncid, oldMode, cmode, atomCnt
    integer :: FrameDimID,SpatialDimID, AtomDimID, LabelDimID, Cell_spatialDimID, Cell_angularDimID
-   integer :: CoordVarID, Cell_lengthVarID, Cell_angleVarID, SpatialVarID, VelocVarID, TempVarID
-   integer :: Cell_spatialVarID, Cell_angularVarID, crd_TimeVarID, vel_TimeVarID
-   integer :: crd_frame, vel_frame
+   integer :: CoordVarID, Cell_lengthVarID, Cell_angleVarID, SpatialVarID, VelocVarID, DipolVarID, TempVarID
+   integer :: Cell_spatialVarID, Cell_angularVarID, crd_TimeVarID, vel_TimeVarID, dip_TimeVarID
+   integer :: crd_frame, vel_frame, dip_frame
 
    public open_binary_files, close_binary_files, write_binary_traj, end_binary_frame
 contains
@@ -35,9 +35,9 @@
 #  include "box.h"
 #  define NCLABELLEN 5
 
-   logical :: crd_file_exists = .false., vel_file_exists = .false.
+   logical :: crd_file_exists = .false., vel_file_exists = .false., dip_file_exists = .false.
 
-   if (ntwv == 0 .and. ntwx == 0) return
+   if (ntwm == 0 .and. ntwv == 0 .and. ntwx == 0) return
 
    atomCnt = natom
    if (ntwprt > 0) atomCnt = ntwprt
@@ -105,6 +105,16 @@
       vel_frame = crd_frame
    end if
 
+   ! Point dip_ncid at either a separate file or the combined (crd) traj file
+   if (ntwm > 0) then
+      call open_nc_file(dip_ncid,mddip,owrite,facc,atomCnt,title, &
+            dip_file_exists,dip_frame,dip_TimeVarID)
+   else if (ntwm == -1) then
+      dip_ncid = crd_ncid
+      dip_file_exists = crd_file_exists
+      dip_frame = crd_frame
+   end if
+
    ! Define velocity variables in file pointed to by vel_ncid
    if (ntwv /= 0 ) then
       if (vel_file_exists) then
@@ -121,6 +131,23 @@
       end if
    end if
 
+   ! Define dipole variables in file pointed to by dip_ncid
+   if (ntwm /= 0 ) then
+      if (dip_file_exists) then
+         call checkerror(nf90_inq_varid(dip_ncid, "dipoles", DipolVarID), &
+               "query dipoles")
+      else
+         call checkerror(nf90_def_var(dip_ncid, "dipoles", nf90_float, &
+               (/ SpatialDimID, AtomDimID, FrameDimID /), DipolVarID), &
+               "define dipoles")
+         call checkerror(nf90_put_att(dip_ncid, DipolVarID, "units", &
+               "electron*angstrom"), "define dipole units")
+         call checkerror(nf90_put_att(dip_ncid, DipolVarID, "scale_factor", &
+               0.05487781454591352354), "define dipole scale_factor")
+! 0.05487781454591352354  = INV_AMBER_ELECTROSTATIC as in constants.f
+      end if
+   end if
+
 
    ! Prepare files for data writing
    if (ntwx > 0 .and. .not. crd_file_exists) then 
@@ -137,6 +164,7 @@
       end if
    end if
    if (ntwv > 0 .and. .not. vel_file_exists) call end_nc_define(vel_ncid)
+   if (ntwm > 0 .and. .not. dip_file_exists) call end_nc_define(dip_ncid)
    
 #else
    write(6,*) 'No binary trajectory support in this version'
@@ -159,6 +187,7 @@
    
    if (ntwx > 0) call checkerror(nf90_close(crd_ncid),"close mdcrd")   
    if (ntwv > 0) call checkerror(nf90_close(vel_ncid),"close mdvel")
+   if (ntwm > 0) call checkerror(nf90_close(dip_ncid),"close mddip")
 
 #else
    write(6,*) 'No binary trajectory support in this version'
@@ -209,6 +238,10 @@
          call checkerror(nf90_put_var(vel_ncid,VelocVarID, r(istart:n), &
                start = (/ 1, 1, vel_frame /), count = (/ 3, (n-istart+1)/3, 1 /)), &
                'write velocities')
+      case (MDDIP_UNIT)
+         call checkerror(nf90_put_var(dip_ncid,DipolVarID, r(istart:n), &
+               start = (/ 1, 1, dip_frame /), count = (/ 3, (n-istart+1)/3, 1 /)), &
+               'write dipoles')
       case default
          write (6,*) 'Error: unhandled unit ',unit,' selected for output in bintraj'
    end select
@@ -246,6 +279,7 @@
          crd_frame = crd_frame + 1
          ! Sync frame counters if combined trajectory
          if (ntwv == -1) vel_frame = vel_frame + 1
+         if (ntwm == -1) dip_frame = dip_frame + 1
       case (MDVEL_UNIT)
          call checkerror(nf90_put_var(vel_ncid, vel_TimeVarID, &
                (/ t /), start = (/ vel_frame /), count = (/ 1 /)), 'write time')
@@ -253,6 +287,13 @@
          call checkerror(nf90_sync(vel_ncid))
          
          vel_frame = vel_frame +1
+      case (MDDIP_UNIT)
+         call checkerror(nf90_put_var(dip_ncid, dip_TimeVarID, &
+               (/ t /), start = (/ dip_frame /), count = (/ 1 /)), 'write time')
+         
+         call checkerror(nf90_sync(dip_ncid))
+         
+         dip_frame = dip_frame +1
       case default
          write (6,*) 'Error: unhandled unit ',unit,' selected for end frame in bintraj'
    end select
diff -aur amber11.orig/src/sander/dynlib.f amber11/src/sander/dynlib.f
--- amber11.orig/src/sander/dynlib.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/dynlib.f	2010-06-14 11:29:52.634568966 +0200
@@ -172,6 +172,10 @@
             call amopen(MDVEL_UNIT,mdvel,owrite,'F','W')
             write(MDVEL_UNIT,1000) title
          end if
+         if (ntwm > 0) then
+            call amopen(MDDIP_UNIT,mddip,owrite,'F','W')
+            write(MDDIP_UNIT,1000) title
+         end if
       else
          call open_binary_files
       end if  ! (ioutfm <= 0)
@@ -204,6 +208,7 @@
       else
          if ( ntwx > 0 ) close( MDCRD_UNIT )
          if ( ntwv > 0 ) close( MDVEL_UNIT )
+         if ( ntwm > 0 ) close( MDDIP_UNIT )
       end if
       if ( ntwe > 0 ) close( MDEN_UNIT )
       if ( imin == 5 ) close( INPTRAJ_UNIT )
diff -aur amber11.orig/src/sander/files.h amber11/src/sander/files.h
--- amber11.orig/src/sander/files.h	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/files.h	2010-06-14 11:29:19.430566337 +0200
@@ -27,11 +27,13 @@
 integer     MDEN_UNIT
 integer     MDINFO_UNIT
 integer     MDVEL_UNIT
+integer     MDDIP_UNIT
 parameter ( MDINFO_UNIT =  7 )
 parameter ( MDCRD_UNIT  = 12 )
 parameter ( INPTRAJ_UNIT = 24 )
 parameter ( MDEN_UNIT   = 15 )
 parameter ( MDVEL_UNIT  = 13 )
+parameter ( MDDIP_UNIT  = 14 )
 integer, parameter :: CNSTPH_UNIT = 18, CPOUT_UNIT = 19
 
 ! 18 was picked because CNSTPH uses it; conflicts are not expected.
@@ -76,9 +78,9 @@
 integer BC_HULP  ! size in integers of common HULP
 parameter ( BC_HULP = 10 )
 
-integer     ntpr,ntwr,ntwx,ntwv,ntwe,ntpp,ioutfm,ntwprt,&
+integer     ntpr,ntwr,ntwx,ntwv,ntwm,ntwe,ntpp,ioutfm,ntwprt,&
             ntave
-common/hulp/ntpr,ntwr,ntwx,ntwv,ntwe,ntpp,ioutfm,ntwprt,&
+common/hulp/ntpr,ntwr,ntwx,ntwv,ntwm,ntwe,ntpp,ioutfm,ntwprt,&
             ntave
 
 !      NMRRDR : Contains information about input/output file redirection
diff -aur amber11.orig/src/sander/mdread.f amber11/src/sander/mdread.f
--- amber11.orig/src/sander/mdread.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/mdread.f	2010-06-14 11:24:12.302562096 +0200
@@ -92,7 +92,7 @@
          nscm,nstlim,t,dt, &
          ntc,ntcc,nconp,tol,ntf,ntn,nsnb, &
          cut,dielc, &
-         ntpr,ntwx,ntwv,ntwe,ntave,ntpp,ioutfm, &
+         ntpr,ntwx,ntwv,ntwm,ntwe,ntave,ntpp,ioutfm, &
          ntr,nrc,ntrx,taur,nmropt, &
          ivcap,cutcap,xcap,ycap,zcap,fcap, &
          xlorth,ylorth,zlorth,xorth,yorth,zorth,forth, &
@@ -157,6 +157,7 @@
          'INPCRD' ,inpcrd(1:70), 'PARM'  ,parm(1:70)  , &
          'RESTRT',restrt(1:70) , 'REFC'  ,refc(1:70)  , &
          'MDVEL' ,mdvel(1:70)  , 'MDEN'   ,mden(1:70) , &
+         'MDDIP' ,mddip(1:70)  , &
          'MDCRD' ,mdcrd(1:70)  , 'MDINFO' ,mdinfo(1:70), &
          'MTMD'  ,mtmd(1:70)   , 'INPDIP', inpdip(1:70), &
          'RSTDIP', rstdip(1:70), 'INPTRAJ', inptraj(1:70)
@@ -213,6 +214,7 @@
    ntwr = 500
    ntwx = 0
    ntwv = 0
+   ntwm = 0
    ntwe = 0
    ipb = 0
    inp = 1!for backward compatibility
@@ -1061,6 +1063,7 @@
          ', ntrx    =',ntrx,', ntwr    =',ntwr
    write(6,'(5x,4(a,i8))') 'iwrap   =',iwrap,', ntwx    =',ntwx, &
          ', ntwv    =',ntwv,', ntwe    =',ntwe
+   write(6,'(5x,1(a,i8))') 'ntwm    =',ntwm
    write(6,'(5x,3(a,i8),a,i7)') 'ioutfm  =',ioutfm, &
          ', ntwprt  =',ntwprt, &
          ', idecomp =',idecomp,', rbornstat=',rbornstat
@@ -2112,6 +2115,18 @@
       write (6, '(/2x,a)') 'NTWX must be > 0 for NTWV == -1.'
       inerr = 1
    end if
+   if (ntwm < -1) then
+      write(6,'(/2x,a,i3,a)') 'NTWM (',ntwm,') must be >= -1.'
+      inerr = 1
+   end if
+   if (ntwm == -1 .and. ioutfm /= 1) then
+      write (6, '(/2x,a)') 'IOUTFM must be 1 for NTWM == -1.'
+      inerr = 1
+   end if
+   if (ntwm == -1 .and. ntwx == 0) then
+      write (6, '(/2x,a)') 'NTWX must be > 0 for NTWM == -1.'
+      inerr = 1
+   end if
    if (ntwe < 0) then
       write(6,'(/2x,a,i3,a)') 'NTWE (',ntwe,') must be >= 0.'
       inerr = 1
diff -aur amber11.orig/src/sander/ncsu-bbmd-ctxt.f amber11/src/sander/ncsu-bbmd-ctxt.f
--- amber11.orig/src/sander/ncsu-bbmd-ctxt.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/ncsu-bbmd-ctxt.f	2010-06-14 14:12:09.754562231 +0200
@@ -39,6 +39,7 @@
    character(SL) :: mdout ! master only
    character(SL) :: restrt ! master only
    character(SL) :: mdvel ! master only
+   character(SL) :: mddip ! master only
    character(SL) :: mden ! master only
    character(SL) :: mdcrd ! master only
    character(SL) :: mdinfo ! master only
@@ -150,6 +151,7 @@
    self%mdout  = mdout
    self%restrt = restrt
    self%mdvel  = mdvel
+   self%mddip  = mddip
    self%mden   = mden
    self%mdcrd  = mdcrd
    self%mdinfo = mdinfo
@@ -686,6 +688,10 @@
                      masterroot, commmaster, error)
       ncsu_assert(error.eq.0)
 
+      call mpi_bcast(self%mddip, len(self%mddip), MPI_CHARACTER, &
+                     masterroot, commmaster, error)
+      ncsu_assert(error.eq.0)
+
       call mpi_bcast(self%mden, len(self%mden), MPI_CHARACTER, &
                      masterroot, commmaster, error)
       ncsu_assert(error.eq.0)
@@ -1272,6 +1278,7 @@
    mdinfo = self%mdinfo
    restrt = self%restrt
    mdvel = self%mdvel
+   mddip = self%mddip
    mden = self%mden
    mdcrd = self%mdcrd
 
diff -aur amber11.orig/src/sander/pimd_init.f amber11/src/sander/pimd_init.f
--- amber11.orig/src/sander/pimd_init.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/pimd_init.f	2010-06-14 12:41:44.454562020 +0200
@@ -6,7 +6,7 @@
    use pimd_vars, only: nbead, natomCL, nbead_inv, tempbuf,  &
                         PRIPIMD, NMPIMD, CMD, RPMD,  &
                         equal_part, x_centroid, real_mass, nrg_all, &
-                        cartpos, cartvel
+                        cartpos, cartvel, cartdip
    use cmd_vars,  only: file_nrg_cmd, file_pos_cmd, file_vel_cmd &
                       , cart_to_nmode, nmode_to_cart, fcart_to_fnmode &
                       , lambda_nmode, omega_nmode, adiab_param
@@ -169,6 +169,9 @@
       allocate( cartvel(3,natom),stat=ierr)
       REQUIRE(ierr.eq.0)
 
+      allocate( cartdip(3,natom),stat=ierr)
+      REQUIRE(ierr.eq.0)
+
       call transformation_matrix( nbead )
      
 #ifdef LES
@@ -244,7 +247,7 @@
 
 subroutine pimd_finalize( pimdtype )
    use pimd_vars, only: nbead, nbead_inv,tempbuf,NMPIMD,CMD,equal_part, &
-              x_centroid,real_mass,nrg_all,cartpos,cartvel,dmdlm, itimass
+              x_centroid,real_mass,nrg_all,cartpos,cartvel,cartdip,dmdlm, itimass
    use cmd_vars, only: file_nrg_cmd, file_pos_cmd, file_vel_cmd,cart_to_nmode,nmode_to_cart,fcart_to_fnmode, &
                        lambda_nmode, omega_nmode, adiab_param
 
@@ -285,6 +288,8 @@
       REQUIRE(ierr==0)
       deallocate(cartvel,stat=ierr)
       REQUIRE(ierr==0)
+      deallocate(cartdip,stat=ierr)
+      REQUIRE(ierr==0)
    end if
 
 end subroutine
diff -aur amber11.orig/src/sander/pimd_vars.f amber11/src/sander/pimd_vars.f
--- amber11.orig/src/sander/pimd_vars.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/pimd_vars.f	2010-06-14 12:42:11.050562072 +0200
@@ -28,7 +28,7 @@
   ! dmdlm = d mass / d lambda / mass (for TI w.r.t. mass)
   _REAL_, allocatable :: dmdlm(:)
   _REAL_, allocatable :: x_centroid(:,:), real_mass(:), nrg_all(:) &
-                       , tempbuf(:,:), cartpos(:,:), cartvel(:,:)
+                       , tempbuf(:,:), cartpos(:,:), cartvel(:,:), cartdip(:,:)
 end module
 
 module full_pimd_vars
diff -aur amber11.orig/src/sander/runmd.f amber11/src/sander/runmd.f
--- amber11.orig/src/sander/runmd.f	2010-04-26 14:21:23.000000000 +0200
+++ amber11/src/sander/runmd.f	2010-06-14 14:56:29.146553957 +0200
@@ -27,7 +27,7 @@
 
    use pimd_vars, only: ipimd, nbead, natomCL, &
                         bnd_vir, Eimp_virial, equal_part, Epot_deriv,  &
-                        tau_vol, Epot_spring, NMPIMD, CMD, cartpos, cartvel, &
+                        tau_vol, Epot_spring, NMPIMD, CMD, cartpos, cartvel, cartdip, &
                         itimass, real_mass
 
    use neb_vars, only: ineb, neb_nbead
@@ -211,7 +211,7 @@
    integer i,j,im,i3,nitp,nits
    integer nstep,nrep,nrek,nren,iend,istart3,iend3
    integer nrx,nr,nr3,ntcmt,izero,istart
-   logical ixdump,ivdump,itdump
+   logical ixdump,ivdump,imdump,itdump
    logical qsetup
 #ifdef RISM
    logical irismdump
@@ -2110,6 +2110,7 @@
    
    itdump = .false.             ! Write coordinates this step?
    ivdump = .false.             ! Write velocities this step?
+   imdump = .false.             ! Write dipoles this step?
    ixdump = .false.             ! Write restart this step?
    ivscm  = .false.             ! Do com removal this step?
 #ifdef RISM
@@ -2141,6 +2142,7 @@
 #endif
    if (ntwx>0) itdump = mod(total_nstep,ntwx) == 0 ! Trajectory coords
    if (ntwv>0) ivdump = mod(total_nstep,ntwv) == 0 ! Velocity
+   if (ntwm>0) imdump = mod(total_nstep,ntwm) == 0 ! Dipoles
    if( ntwr /= 0 ) then
       if ( mod(total_nstep, ntwr ) == 0 ) ixdump = .true. ! Restart
    endif
@@ -2149,6 +2151,7 @@
       if( mod(total_nstep,nscm) == 0 ) ivscm =.true. ! C.o.M. removal
    end if
    if (ntwv == -1 .and. itdump) ivdump = .true. !Combined crdvel file
+   if (ntwm == -1 .and. itdump) imdump = .true. !Combined crddip file
 
 #ifdef RISM
    if(rismprm%ntwrism > 0 .and. rismprm%irism ==1)then
@@ -2811,6 +2814,32 @@
              call corpac(v,1,nrx,MDVEL_UNIT,loutfm)
           endif
       end if
+
+      !     Dipoles archive:
+      if (imdump) then
+
+         ! NOTE - This assumes that if numextra > 0, then dipoles are
+         !        found in the array linddip...
+         if (numextra > 0) call zero_extra_pnts_vec(xx(linddip),ix)
+
+#ifdef MPI
+         ! Write out current replica#, exchange#, step#, and mytargettemp
+         ! If mdloop==0 this is a normal md run (since REMD never calls corpac
+         !  when mdloop==0) and we don't want the REMD header.
+         if (mdloop>0.and.loutfm) &
+            write (MDDIP_UNIT,'(a,3(1x,i8),1x,f8.3)') "REMD ", repnum, mdloop, &
+                              total_nstep, mytargettemp
+#endif
+
+!          if(ipimd.eq.NMPIMD.or.ipimd.eq.CMD) then
+!              call trans_dip_nmode_to_cart(xx(linddip),cartdip)
+!              call corpac(cartdip,1,nrx,MDDIP_UNIT,loutfm)
+!             call corpac(xx(linddip),1,nrx,MDDIP_UNIT,loutfm)
+!          else
+             call corpac(xx(linddip),1,nrx,MDDIP_UNIT,loutfm)
+!          endif
+      end if
+
       !     Energy archive:
       !      (total_nstep set in Step 5.)
       if (ntwe > 0) then
@@ -2821,6 +2850,7 @@
       if (ioutfm > 0) then
          if (itdump) call end_binary_frame(MDCRD_UNIT)
          if (ivdump .and. ntwv>0 ) call end_binary_frame(MDVEL_UNIT)
+         if (imdump .and. ntwm>0 ) call end_binary_frame(MDDIP_UNIT)
       end if
 
 #ifdef MPI

