#!/usr/bin/perl # -------------------------------------------------------------- # Convert a CHARMM card file into PDB file for use with MOLMOL # # March 4 2003 # Modified December 10 2004 # -------------------------------------------------------------- # # Usage : crd2pdb.prl file1.crd file2.crd file3.crd ... # foreach $file (@ARGV) { ($output_name=$file) =~ s/\.crd/\.pdb/g; open(IN,"$file"); @line=; $end=@line-1; close(IN); open(OUT,">$output_name"); # Gets title from crd file and writes it as REMARK for $i (0..$end) { if ($line[$i] !~ /\*/) { $begin=$i+1; last; } $l = "REMARK ".substr($line[$i],1,80); print OUT "$l"; } # $begin : number of first line containing an atom # $end : number of last line containing an atom # Prevents writing a "TER" before the first segment $firstseg=1; $preseg=""; # Main loop for $i ($begin..$end) { $num=substr($line[$i],0,5); $resid=substr($line[$i],5,5); $resname=substr($line[$i],11,4); $atomname=substr($line[$i],16,4); $x=substr($line[$i],20,10); $y=substr($line[$i],30,10); $z=substr($line[$i],40,10); $segname=substr($line[$i],51,4); $resnum=substr($line[$i],56,5); $w=substr($line[$i],61,9); # Writes a "TER" between segments if ( ($segname ne $preseg) and ($firstseg==1) ) { $firstseg=0; $preseg=$segname; } elsif ( $segname ne $preseg ) { print OUT "TER \n"; $preseg=$segname; } # Writes an ATOM line in PDB format, with "weight" in B-factor column printf OUT ("ATOM%7d %-5s%4s%5d %8.3f%8.3f%8.3f 1.00%6.2f %4s \n", $num,$atomname,$resname,$resnum,$x,$y,$z,$w,$segname); } print OUT "TER\n"; close(OUT); }