#!/bin/sh # Converts XPLOR psf to CHARMM psf. # Run without command-line arguments for usage information. # Copyright (C) 2013 Kenno Vanommeslaeghe # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . if [ $# -lt 2 ] ; then bn=`basename $0` echo "Converts XPLOR psf to CHARMM psf. Usage: $bn > `echo $bn | sed 's/./ /g'` ^^^ Note: optionally, prm files in flex format may be used instead of rtf files." exit 1 fi xplor=$1 shift 1 awk -v psf=$xplor 'BEGIN {getline < psf;sub(" +$","");n=toupper($0); if (n !~ "^PSF") {print "ERROR: psf file not recognized!" > "/dev/stderr"; exit 1} } (toupper($1) == "MASS"){t=$3;m=masnum[t]; if (!m) masnum[t]=$2 else if (m != $2) { printf("ERROR: conflicting MASS entry in %s line %i !\n",FILENAME,FNR) > "/dev/stderr"; exit 1} } END{print n;if (n ~ " EXT") {attb=47;atta=54} # before, after else {attb=29;atta=34}; # ^ ^ getline < psf;sub(" +$","");print; getline < psf;sub(" +$","");print; n=$1+2;for(i=1;i<=n;i++){getline < psf;sub(" +$","");print}; n=$1;for(i=1;i<=n;i++){getline < psf;sub(" +$",""); m=masnum[$6];if (!m) { printf("ERROR: unknown atom type %s in xplor psf %s !\n",$6,psf) > "/dev/stderr"; exit 1}; printf("%s%4i%s\n",substr($0,1,attb),m,substr($0,atta))}; while (getline < psf) print}' $*