#!/bin/csh ############## SETUP ########################################################## ######### MAKE SURE THE TOPOLOGY FILES TO MERGE ARE OK ######################## # #USAGE: GRO_MERGE_TOP .top/itp .top/itp > .top/itp # set TOP1 = $1 # .top or .itp set TOP2 = $2 # .top or .itp set FF = "ffoplsaa.itp" set MOLTYPE = "Protein" set NREXCL = 3 ############# GENERATE SCRIPTS TO MERGE TOP1 AND TOP2 ######################### cat << EOF > extract_atoms.awk /\[ atoms ]/{ getline while(\$1&&\$1!="["){ if(\$1!~/\;/){ print } getline } } EOF cat << EOF > extract_types.awk BEGIN{ if (type == "bond" || type == "bonds"){ match_string = "[ bonds ]" } else if (type == "pair" || type == "pairs"){ match_string = "[ pairs ]" } else if (type == "angle" || type == "angles"){ match_string = "[ angles ]" } else if (type == "dihedral" || type == "dihedrals"){ match_string = "[ dihedrals ]" } else { print "\nYOU MUST PROVIDE A VALID TYPE\n" exit 5 } if(flag>0){flag=1} } /\[ atoms ]/{ getline while(\$1&&\$1!="["){ if(\$1!~/\;/){ natoms=\$1 } getline } } \$0 == match_string { if(flag==0){ getline while(\$1&&\$1!="["){ if(\$1!~/\;/){ print } getline } } flag-- } END{ print "NATOMS\t" natoms } EOF cat << EOF > merge_atoms.awk BEGIN{ print "[ atoms ]" } { if(\$1==1){ ++mol xat = at xres = res xchgg = chgg xtotchg = totchg } at = \$1 + xat res = \$3 + xres chgg = \$6 + xchgg chgchk = \$11 + xtotchg printf("%6d%11s%7d%7s%7s%7d%11.5f%11.5f ; qtot %9.5f\n",at,\$2,res,\$4,\$5,chgg,\$7,\$8,\$11) } END{printf("\n")} EOF cat << EOF > merge_types.awk BEGIN{ if (type == "bond" || type == "bonds"){ def = 3 print "[ bonds ]" } else if (type == "pair" || type == "pairs"){ def = 3 print "[ pairs ]" } else if (type == "angle" || type == "angles"){ def = 4 print "[ angles ]" } else if (type == "dihedral" || type == "dihedrals"){ def = 5 print "[ dihedrals ]" } } { if(\$1=="NATOMS"){ xat = \$2 } else{ nfields = split(\$0,field) printf("%5d",field[1]+xat) for(i=2;i def){ printf(" "field[def+1]) for(i=def+2;i<=nfields;i++){ printf("%10.5f",field[i]) } } printf("\n") } } END{ printf("\n") } EOF #################### NOW DO THE WORK ################################### awk -f extract_atoms.awk $TOP1 > at1.tmp awk -f extract_atoms.awk $TOP2 >> at1.tmp awk -v type="bond" -f extract_types.awk $TOP1 > bd1.tmp awk -v type="bond" -f extract_types.awk $TOP2 >> bd1.tmp awk -v type="pairs" -f extract_types.awk $TOP1 > pa1.tmp awk -v type="pairs" -f extract_types.awk $TOP2 >> pa1.tmp awk -v type="angles" -f extract_types.awk $TOP1 > an1.tmp awk -v type="angles" -f extract_types.awk $TOP2 >> an1.tmp awk -v type="dihedral" -f extract_types.awk $TOP1 > di1.tmp awk -v type="dihedral" -f extract_types.awk $TOP2 >> di1.tmp awk -v type="dihedral" -v flag=1 -f extract_types.awk $TOP1 > di2.tmp awk -v type="dihedral" -v flag=1 -f extract_types.awk $TOP2 >> di2.tmp awk -f merge_atoms.awk at1.tmp > at1_merged.tmp awk -v type="bond" -f merge_types.awk bd1.tmp > bd1_merged.tmp awk -v type="pair" -f merge_types.awk pa1.tmp > pa1_merged.tmp awk -v type="angle" -f merge_types.awk an1.tmp > an1_merged.tmp awk -v type="dihedral" -f merge_types.awk di1.tmp > di1_merged.tmp awk -v type="dihedral" -f merge_types.awk di2.tmp > di2_merged.tmp # MOST OF THE WORK IS DONE echo '#include "'$FF'"'"\n" echo "[ moleculetype ]" echo "$MOLTYPE $NREXCL\n" cat at1_merged.tmp cat bd1_merged.tmp cat pa1_merged.tmp cat an1_merged.tmp cat di1_merged.tmp cat di2_merged.tmp echo "[ system ]" echo "UNNAMED\n" echo "[ molecules ]" echo "Protein 1" # CLEANING UP /bin/rm *.tmp /bin/rm extract_atoms.awk extract_types.awk /bin/rm merge_atoms.awk merge_types.awk # DONE exit