#!/usr/bin/perl
#@author: Chris Schmidt
#@date: March 2010
#@purpous: Creats a Dihedral restraints file for Xplor from a file containing
#three columns, the residue number the PHI angle and the PSI angle
#This script takes in tow arguments <dihedral-constraints> <output-file>

if ($#ARGV < 1){
	print "Usage <dihedral-constraints> <output file>\nThis script takes in two arguments <dihedral-constraints> <output-file>";
	exit;

}#end if
$dihFile = $ARGV[0];
$outFile = $ARGV[1];

open(INPUT, "<".$dihFile);
open(OUTPUT, ">".$outFile);
while(<INPUT>){
	chomp;
	$line= $_;
	@lines = split(" ", $line);
	#i= resNumber (read from file)
	$i= $lines[0];
	$i2= $i-1;
        $i3 = $i+1;
	#a= energy (1.0)
	$a= 1.0;
	#b= angle (read from file)
	$b1= $lines[1];
	$b2= $lines[2];
	#c= range in Hz (var)
	$c= 5.0;
	#d= exponent (2)(int)
	$d= 2;
	
	print OUTPUT "!PHI for residue $i\n";
	print OUTPUT "assign ( resid $i2 and name c )\n";
	print OUTPUT "       ( resid $i and name n )\n";
	print OUTPUT "       ( resid $i and name ca )\n";
	print OUTPUT "       ( resid $i and name c )   $a $b1 $c $d\n";
	print OUTPUT "\n!PSI for residue $i \n";
	print OUTPUT "assign ( resid $i and name n )\n";
	print OUTPUT "       ( resid $i and name ca )\n";
	print OUTPUT "       ( resid $i and name c )\n";
	print OUTPUT "       ( resid $i3 and name n )   $a $b2 $c $d\n";
	print OUTPUT "\n";

}#end while
close(INPUT);
close(OUTPUT);
