Recently I had to figure out if two residues are bonded together or not. This is not as straightforward as you might think. Here is a subroutine to do the job.
if ( ResiduesAreBonded(\\\$document, \\\$r1, \\\$r2) ) {
...
}
sub ResiduesAreBonded(\\\$\\\$\\\$) {
my \\\$debug = 0;
my (\\\$doc,\\\$res1,\\\$res2) = @_;
my \\\$regex1 = "^" . \\\$res1->Name . "[^0-9].*";
my \\\$regex2 = \\\$res2->Name . "[^0-9].*";
my \\\$filter = "Bond Name=\\"" . \\\$regex1 . " - " . \\\$regex2 . "\\"";
my \\\$bonds = \\\$doc->FilterByProperty(\\\$filter);
my \\\$bondcount = \\\$bonds->Count;
if (\\\$bondcount && \\\$debug) {
printf "FILTER:%s\\n", \\\$filter;
printf "Bonds %d\\n", \\\$bonds->Count;
foreach (@\\\$bonds) {
printf "Bond %s\\n", \\\$_->Name;
}
}
my \\\$filter = "Bond Name=\\"" . \\\$regex2 . " - " . \\\$regex1 . "\\"";
my \\\$bonds = \\\$doc->FilterByProperty(\\\$filter);
if (\\\$bondcount && \\\$debug) {
printf "FILTER:%s\\n", \\\$filter;
printf "Bonds %d\\n", \\\$bonds->Count;
foreach (@\\\$bonds) {
printf "Bond %s\\n", \\\$_->Name;
}
}
\\\$bondcount += \\\$bonds->Count;
return \\\$bondcount;
}
