Separating the spectra of different targets into individual molly files

If you have reduced the spectra of different objects together, then these spectra will now all be in one file, opt.mol. You can separate out the spectra of different targets using the select command inside molly. This ignores spectra which do not match certain criteria, so you can work only on those which have a certain character string in the Object keyword in their headers.

This shell script splits the opt.mol file into a file for each unique target (using the Object keyword in the headers). It loads in the file to molly and outputs the object for each one. It then extracts unique values of the Object keyword from the resulting text file and, for each object, loads in the opt.mol file to molly and writes a file called by the object keyword and containing only the spectra of that object.

#!/bin/tcsh

if ( $#argv != 1 ) then
  echo "Usage: objsep [mollyfile]"
  exit
endif

molly << EOF
load $argv[1] 1 600 1
flis 1 600 zzz_select.tmp.1 1 Object
quit
y
EOF

awk '{print $2}' zzz_select.tmp.1 > zzz_select.tmp.2
sort zzz_select.tmp.2 > zzz_select.tmp.3
uniq zzz_select.tmp.3 > zzz_select.tmp.4

foreach object (`cat zzz_select.tmp.4`)
molly << EOF
load $argv[1] 1 600 1
select C Object $object
write $object.mol 1 600 N
quit
y
EOF
end

rm zzz_select.tmp.?

exit