4 # This script reads an XPLOR input file with distance restraint data
5 # as sometimes is found in the pdb database (http://www.pdb.org).
6 # From this input file dihedral restrints should be removed, such that
7 # only distance restraints are left. The script can handle ambiguous restraints.
8 # It converts the distance restraints to GROMACS format.
9 # A typical command line would be
10 # ./xplor2gmx.pl 33 conf.pdb < restraints.dat > disre.itp
11 # You can turn off debugging info, but please do verify your output is correct!
13 # David van der Spoel (spoel@gromacs.org), July 2002
16 # Turn debugging off (0), or on ( > 0).
18 # Turn atom name translation on and off
21 #$res0 = shift;# || die "I need the residue offset\n";
22 $pdb = shift || die "I need the name of the pdb file with correct atom numbers\n";
23 $core = shift || "core.ndx";
24 $tbl = "$ENV{GMXDATA}/top/atom_nom.tbl";
26 printf "[ distance_restraints ]\n";
27 printf "; Read an xplor distance restraint file, and output GROMACS distance restraints.\n";
28 printf "; This also needs a pdb file with correct GROMACS atom numbering.\n";
29 printf "; I used $pdb for the atom numbers\n";
30 printf "; This also needs the offset in residues.\n";
31 #printf "; I used $res0 for the residue offset\n";
34 # If things go wrong, check whether your pdb file is read correctly.
38 open(PDB
,$pdb) || die "Can not open file $pdb\n";
39 while ($line = <PDB
>) {
40 if (index($line,"ATOM") >= 0) {
41 @tmp = split(' ',$line);
42 $aname[$natom] = $tmp[2];
43 $resnr[$natom] = $tmp[4];
44 if (!defined $resname[$tmp[4]]) {
45 $resname[$tmp[4]] = $tmp[3];
52 printf "; I found $natom atoms in the pdb file $pdb\n";
53 printf "; I found $nres residues in the pdb file $pdb\n";
55 for ($i = 0; ($i < $natom); $i ++) {
56 printf("; %5d %5s %5s %5d\n",$i+1,$aname[$i],
57 $resname[$resnr[$i]],$resnr[$i]);
62 # Read the name translation table.
63 # Source for this comes from: http://www.bmrb.wisc.edu/ref_info/atom_nom.tbl
64 # It was adapted slightly for GROMACS use, but only as regards formatting,
67 open(TBL
,$tbl) || die "Can not open atom-name translation table $tbl\n";
69 while ($line = <TBL
>) {
70 @ttt = split('#',$line);
71 @tmp = split(' ',$ttt[0]);
74 $tblres[$ntbl] = $tmp[0];
75 $tblxplor[$ntbl] = $tmp[1];
76 $tblgmx[$ntbl] = $tmp[3];
81 printf "; Read $ntbl entries from $tbl\n";
84 [ "HA#", "HA1", "HA2" ],
85 [ "HA*", "HA1", "HA2" ],
86 [ "HB#", "HB", "HB1", "HB2" ],
87 [ "HB*", "HB", "HB1", "HB2" ],
88 [ "HG#", "HG", "HG1", "HG2", "HG11", "HG12", "HG13", "HG21", "HG22", "HG23" ],
89 [ "HG*", "HG", "HG1", "HG2", "HG11", "HG12", "HG13", "HG21", "HG22", "HG23" ],
90 [ "HG1#", "HG11", "HG12", "HG13" ],
91 [ "HG1*", "HG11", "HG12", "HG13" ],
92 [ "HG2#", "HG21", "HG22", "HG23" ],
93 [ "HG2*", "HG21", "HG22", "HG23" ],
94 [ "HD#", "HD1", "HD2", "HD11", "HD12", "HD13", "HD21", "HD22", "HD23" ],
95 [ "HD*", "HD1", "HD2", "HD11", "HD12", "HD13", "HD21", "HD22", "HD23" ],
96 [ "HD1#", "HD11", "HD12" ],
97 [ "HD1*", "HD11", "HD12" ],
98 [ "HD2#", "HD21", "HD22" ],
99 [ "HD2*", "HD21", "HD22" ],
100 [ "HE#", "HE", "HE1", "HE2" ],
101 [ "HE*", "HE", "HE1", "HE2" ],
102 [ "HH#", "HH11", "HH12", "HH21", "HH22" ],
103 [ "HH*", "HH11", "HH12", "HH21", "HH22" ],
104 [ "HZ#", "HZ", "HZ1", "HZ2", "HZ3" ],
105 [ "HZ*", "HZ", "HZ1", "HZ2", "HZ3" ],
116 for(my $i = 0; ($i < $ntbl); $i ++) {
117 if ($tblres[$i] eq $resnm) {
118 if ($tblxplor[$i] eq $atom) {
127 printf "; No name change for $resname[$resnr] $atom\n";
132 sub expand_template
{
133 my $atom = shift(@_);
134 my $rnum = shift(@_);
139 die("No residue name for residue $rnum") if (!defined ($resname[$rnum]));
140 for (my $tt=0; (($tt <= $#templates) && ($bdone == 0)); $tt++) {
141 $templ = $templates[$tt];
142 if ($atom eq $templ->[0]) {
143 for ($jj = 1; ($jj <= $#{$templ}); $jj++) {
144 push @atoms, transl_aname
($resname[$rnum],$templ->[$jj]);
150 push @atoms, transl_aname
($resname[$rnum],$atom);
153 my $natom = $#atoms+1;
154 printf("; Found $natom elements for atom $resname[$rnum] %d $atom:",
165 printf "; There are $#templates template entries\n";
166 for ($tt=0; ($tt <= $#templates); $tt++) {
167 $templ = $templates[$tt];
168 $ntempl = $#{$templ};
169 printf "; Item $tt ($templates[$tt][0]) has $ntempl entries\n";
173 # This index file holds numbers of restraints involving core atoms
174 @protcore = ( "H", "HN", "HA", "HA1", "HA2", "HB", "HB1", "HB2", "HB3", "HG", "HG1", "HG2", "HG3", "N", "O" );
175 open(CORE
,">$core") || die "Can not open $core\n";
176 print CORE
"[ core-restraints ]\n";
183 while ($line = <STDIN
>) {
184 @ttt = split('!',$line);
185 if ((index($ttt[0],"assign") >= 0) && (index($ttt[0],"!assign") < 0)) {
186 @tmp = split('\(',$ttt[0]);
187 # Find first argument
188 if (($rhaak = index($tmp[1],')')) < 0) {
189 printf "No ) in '$tmp[1]'\n";
191 $atres1 = substr($tmp[1],0,$rhaak);
192 @at1 = split('or',$atres1);
194 # Find second argument
195 if (($rhaak = index($tmp[2],')')) < 0) {
196 printf "No ) in '$tmp[2]'\n";
198 $atres2 = substr($tmp[2],0,$rhaak);
199 @at2 = split('or',$atres2);
201 @expdata = split('\)',$tmp[2]);
202 @dist = split(' ',$expdata[1]);
206 foreach $a1 ( @at1 ) {
207 @info1 = split(' ',$a1);
209 @atoms1 = expand_template
($info1[4],$r1);
211 foreach $a2 ( @at2 ) {
212 @info2 = split(' ',$a2);
214 @atoms2 = expand_template
($info2[4],$r2);
216 for ($i = 0; ($i < $natom) && ($resnr[$i] < $r1); $i++) { ; }
217 for ( ; ($i < $natom) && ($resnr[$i] == $r1); $i++) {
218 foreach $ii ( @atoms1 ) {
219 if ($ii eq $aname[$i]) {
221 for $pp ( @protcore ) {
227 for ($j = 0; ($j < $natom) && ($resnr[$j] < $r2); $j++) { ; }
228 for ( ; ($j < $natom) && ($resnr[$j] == $r2); $j++) {
229 foreach $jj ( @atoms2 ) {
230 if ($jj eq $aname[$j]) {
232 $dminus = 0.1*$dist[1];
233 $dplus = 0.1*$dist[2];
237 printf("%5d %5d %5d %5d %5d %7.3f %7.3f %7.3f 1.0; res $r1 $ii - res $r2 $jj\n",$i+1,$j+1,1,$myindex,1,$low,$up1,$up2);
241 for $pp ( @protcore ) {
246 if (($bCoreI == 0) || ($bCoreJ == 0)) {
248 printf "; No core $ii ($bCoreI) $jj ($bCoreJ)\n";
262 printf CORE
"$myindex\n";
266 printf "; UNRESOLVED: $ttt[0]\n";
277 printf "; A total of $myindex lines with distance restraints were read from $linec input lines\n";
278 printf "; From this, $npair actual restraints were generated.\n";
279 printf "; A total of $nunresolved lines could not be interpreted\n";
280 printf "; In the process $ntranslated atoms had a name change\n";
281 printf "; However for $nuntransltd no name change could be found\n";
282 printf "; usually these are either HN->H renamings or not-existing atoms\n";
283 printf "; generated by the template expansion (e.g. HG#)\n";
284 printf "; A total of $ncore restraints were classified as core restraints\n";