I assume that the existing water residues have consecutive RESIDs, i.e. the RESID of the last water molecule is the same as the number of water molecules; previous water deletions can cause gaps. If the numbers are not the same, after reading the initial PSF and COOR files, use the command (see struct.doc)

JOIN water_segid RENUM

Starting from an equilibrated model,

* read PSF and COOR from equilibration
* use JOIN if needed (see above); save the revised PSF and COOR to new files
* use RENAME (struct.doc) to change SEGID, RESN, and ATOM names to D2O compatible for the last half of water residues
* use DELETE to remove all atoms except those renamed to be D2O
* use JOIN d2o_segid RENUM to make RESIDs start from 1
* save the D2O coords to a COOR CARD file
* DELETE the remaining atoms
* read PSF and COOR from equilibration, or the revised files if waters were renumbered
* DELETE the last half of water residues
* use GENERate to create a new D2O segment
* read the saved D2O coords from the file; use the RESID option
* save the resulting PSF and COOR data structures

To select the last half of the water for the renames and deletion, a range selection is useful; e.g. for 5000 water molecules

rename resn D2O sele segid WAT .and. resid 2501:5000 end

Rick Venable
computational chemist