sub _read_PDB_coordinate_section
{ my ($self, $buffer, $struc) = @_;
my ($model_num, $chain_name, $residue_name, $atom_name); $model_num = "";
$chain_name = "";
$residue_name = "";
$atom_name = "";
my $atom_unpack = "x6 a5 x1 a4 a1 a3 x1 a1 a4 a1 x3 a8 a8 a8 a6 a6 x6 a4 a2 a2";
my $anisou_unpack = "x6 a5 x1 a4 a1 a3 x1 a1 a4 a1 x1 a7 a7 a7 a7 a7 a7 a4 a2 a2";
my $model = Bio::Structure::Model->new;
$model->id('default');
my $noatom = $self->_noatom;
my ($chain, $residue, $atom, $old);
my (%_ch_in_model);
$_ = $$buffer;
while (defined( $_ ||= $self->_readline )) {
if (/^MODEL\s+(\d+)/) {
$model_num = $1;
$self->debug("_read_PDB_coor: parsing model $model_num\n");
$model->id($model_num);
if (/^MODEL\s+\d+\s+\S+/) { $old = 1;
}
}
if (/^(ATOM |HETATM|SIGATM)/) {
my @line_elements = unpack $atom_unpack, $_;
my $pdb_atomname = $line_elements[1]; for my $k (0 .. $#line_elements) {
$line_elements[$k] =~ s/^\s+//; $line_elements[$k] =~ s/\s+$//; $line_elements[$k] = undef if ($line_elements[$k] =~ /^\s*$/);
}
my ($serial, $atomname, $altloc, $resname, $chainID, $resseq, $icode, $x, $y, $z,
$occupancy, $tempfactor, $segID, $element, $charge) = @line_elements;
$chainID = 'default' if ( !defined $chainID );
if ($chainID ne $chain_name) {
if (exists $_ch_in_model{$chainID} ) { $chain = $_ch_in_model{$chainID};
} else { $chain = Bio::Structure::Chain->new;
$struc->add_chain($model,$chain);
$chain->id($chainID);
$_ch_in_model{$chainID} = $chain;
}
$chain_name = $chain->id;
}
if( !defined $icode ) {
$icode = "";
}
my $res_name_num = $resname."-".$resseq.$icode;
if ($res_name_num ne $residue_name) { $residue = Bio::Structure::Residue->new;
$struc->add_residue($chain,$residue);
$residue->id($res_name_num);
$residue_name = $res_name_num;
$atom_name = ""; }
if ($noatom) {
$_ = undef;
next;
}
if ( $altloc && ($altloc =~ /\S+/) && ($atomname eq $atom_name) ) {
$_ = undef; next;
}
if (/^(ATOM |HETATM)/) { $atom_name = $atomname;
$atom = Bio::Structure::Atom->new;
$struc->add_atom($residue,$atom);
$atom->id($atomname);
$atom->pdb_atomname($pdb_atomname); $atom->serial($serial);
$atom->icode($icode);
$atom->x($x);
$atom->y($y);
$atom->z($z);
$atom->occupancy($occupancy);
$atom->tempfactor($tempfactor);
$atom->segID($segID); if (! $old ) {
$atom->element($element);
$atom->charge($charge);
}
}
else { my $sigx = $x;
my $sigy = $y;
my $sigz = $z;
my $sigocc = $occupancy;
my $sigtemp = $tempfactor;
if ($atom_name ne $atomname) { $self->throw("A SIGATM record should have the same $atomname as the previous record $atom_name\n");
}
$atom->sigx($sigx);
$atom->sigy($sigy);
$atom->sigz($sigz);
$atom->sigocc($sigocc);
$atom->sigtemp($sigtemp);
}
}
if (/^(ANISOU|SIGUIJ)/) {
if ($noatom) {
$_ = undef;
next;
}
my @line_elements = unpack $anisou_unpack, $_;
for my $k (0 .. $#line_elements) {
$line_elements[$k] =~ s/^\s+//; $line_elements[$k] =~ s/\s+$//; $line_elements[$k] = undef if ($line_elements[$k] =~ /^\s*$/);
}
my ($serial, $atomname, $altloc, $resname, $chainID, $resseq, $icode,
$u11,$u22, $u33, $u12, $u13, $u23, $segID, $element, $charge) = @line_elements;
$self->debug("read_PDB_coor: parsing ANISOU record: $serial $atomname\n");
if ( $altloc && ($altloc =~ /\S+/) && ($atomname eq $atom_name) ) {
$_ = undef;
next;
}
if (/^ANISOU/) {
if ($atom_name ne $atomname) { $self->throw("A ANISOU record should have the same $atomname as the previous record $atom_name\n");
}
$atom->aniso("u11",$u11);
$atom->aniso("u22",$u22);
$atom->aniso("u33",$u33);
$atom->aniso("u12",$u12);
$atom->aniso("u13",$u13);
$atom->aniso("u23",$u23);
}
else { if ($atom_name ne $atomname) { $self->throw("A SIGUIJ record should have the same $atomname as the previous record $atom_name\n");
}
$atom->aniso("sigu11",$u11);
$atom->aniso("sigu22",$u22);
$atom->aniso("sigu33",$u33);
$atom->aniso("sigu12",$u12);
$atom->aniso("sigu13",$u13);
$atom->aniso("sigu23",$u23);
}
}
if (/^TER /) {
$_ = undef;
next;
}
if (/^ENDMDL/) {
$_ = $self->_readline;
last;
}
if (/^(CONECT|MASTER)/) { last;
}
$_ = undef;
}
$$buffer = $_;
return $model;
}
} |
sub next_structure
{ my ($self,@args) = @_;
my ($line);
my ($obslte, $title, $caveat, $compnd, $source, $keywds,
$expdta, $author, %revdat, $revdat, $sprsde, $jrnl, %remark, $dbref,
$seqadv, $seqres, $modres, $het, $hetnam, $hetsyn, $formul, $helix,
$sheet, $turn, $ssbond, $link, $hydbnd, $sltbrg, $cispep,
$site, $cryst1, $tvect,);
my $struc = Bio::Structure::Entry->new(-id => 'created from pdb.pm');
my $all_headers = ( !$self->_noheader ); my %header;
$line = $self->_readline;
if( !defined $line ) {
return undef; }
if( $line =~ /^\s+$/ ) {
while( defined ($line = $self->_readline) ) {
$line =~/\S/ && last;
}
}
if( !defined $line ) {
return undef; }
$line =~ /^HEADER\s+\S+/ || $self->throw("PDB stream with no HEADER. Not pdb in my book");
my($header_line) = unpack "x10 a56", $line;
$header{'header'} = $header_line;
my($class, $depdate, $idcode) = unpack "x10 a40 a9 x3 a4", $line;
$idcode =~ s/^\s*(\S+)\s*$/$1/;
$struc->id($idcode);
$self->debug("PBD c $class d $depdate id $idcode\n");
my $buffer = $line;
BEFORE_COORDINATES :
until( !defined $buffer ) {
$_ = $buffer;
last if /^(MODEL|ATOM|HETATM)/;
if (/^OBSLTE / && $all_headers) {
$obslte = $self->_read_PDB_singlecontline("OBSLTE","12-70",\$buffer);
$header{'obslte'} = $obslte;
}
if (/^TITLE / && $all_headers) {
$title = $self->_read_PDB_singlecontline("TITLE","11-70",\$buffer);
$header{'title'} = $title;
}
if (/^CAVEAT / && $all_headers) {
$caveat = $self->_read_PDB_singlecontline("CAVEAT","12-70",\$buffer);
$header{'caveat'} = $caveat;
}
if (/^COMPND / && $all_headers) {
$compnd = $self->_read_PDB_singlecontline("COMPND","11-70",\$buffer);
$header{'compnd'} = $compnd;
$self->debug("get COMPND $compnd\n");
}
if (/^SOURCE / && $all_headers) {
$source = $self->_read_PDB_singlecontline("SOURCE","11-70",\$buffer);
$header{'source'} = $source;
}
if (/^KEYWDS / && $all_headers) {
$keywds = $self->_read_PDB_singlecontline("KEYWDS","11-70",\$buffer);
$header{'keywds'} = $keywds;
}
if (/^EXPDTA / && $all_headers) {
$expdta = $self->_read_PDB_singlecontline("EXPDTA","11-70",\$buffer);
$header{'expdta'} = $expdta;
}
if (/^AUTHOR / && $all_headers) {
$author = $self->_read_PDB_singlecontline("AUTHOR","11-70",\$buffer);
$header{'author'} = $author;
}
if (/^REVDAT / && $all_headers) {
my ($rol) = unpack "x7 a59", $_;
$revdat .= $rol;
$header{'revdat'} = $revdat;
}
if (/^SPRSDE / && $all_headers) {
$sprsde = $self->_read_PDB_singlecontline("SPRSDE","12-70",\$buffer);
$header{'sprsde'} = $sprsde;
}
if (/^JRNL / && $all_headers) {
$jrnl = $self->_read_PDB_jrnl(\$buffer);
$struc->annotation->add_Annotation('reference',$jrnl);
$header{'jrnl'} = 1; }
if (/^REMARK\s+(\d+)\s*/ && $all_headers) {
my $remark_num = $1;
if ($remark_num == 1) {
my @refs = $self->_read_PDB_remark_1(\$buffer);
foreach my $ref (@refs) {
$struc->annotation->add_Annotation('reference', $ref);
}
$_ = $buffer;
}
if (/^REMARK\s+(\d+)\s*/) {
my $r_num = $1;
if ($r_num != 1) { my ($rol) = unpack "x11 a59", $_;
$remark{$r_num} .= $rol;
}
}
}
if (/^DBREF / && $all_headers) {
my ($rol) = unpack "x7 a61", $_;
$dbref .= $rol;
$header{'dbref'} = $dbref;
my ($db, $acc) = unpack "x26 a6 x1 a8", $_;
$db =~ s/\s*$//;
$acc =~ s/\s*$//;
my $link = Bio::Annotation::DBLink->new;
$link->database($db);
$link->primary_id($acc);
$struc->annotation->add_Annotation('dblink', $link);
}
if (/^SEQADV / && $all_headers) {
my ($rol) = unpack "x7 a63", $_;
$seqadv .= $rol;
$header{'seqadv'} = $seqadv;
}
if (/^SEQRES / && $all_headers) {
my ($rol) = unpack "x8 a62", $_;
$seqres .= $rol;
$header{'seqres'} = $seqres;
}
if (/^MODRES / && $all_headers) {
my ($rol) = unpack "x7 a63", $_;
$modres .= $rol;
$header{'modres'} = $modres;
}
if (/^HET / && $all_headers) {
my ($rol) = unpack "x7 a63", $_;
$het .= $rol;
$header{'het'} = $het;
}
if (/^HETNAM / && $all_headers) {
my ($rol) = unpack "x8 a62", $_;
$hetnam .= $rol;
$header{'hetnam'} = $hetnam;
}
if (/^HETSYN / && $all_headers) {
my ($rol) = unpack "x8 a62", $_;
$hetsyn .= $rol;
$header{'hetsyn'} = $hetsyn;
}
if (/^FORMUL / && $all_headers) {
my ($rol) = unpack "x8 a62", $_;
$formul .= $rol;
$header{'formul'} = $formul;
}
if (/^HELIX / && $all_headers) {
my ($rol) = unpack "x7 a69", $_;
$helix .= $rol;
$header{'helix'} = $helix;
}
if (/^SHEET / && $all_headers) {
my ($rol) = unpack "x7 a63", $_;
$sheet .= $rol;
$header{'sheet'} = $sheet;
}
if (/^TURN / && $all_headers) {
my ($rol) = unpack "x7 a63", $_;
$turn .= $rol;
$header{'turn'} = $turn;
}
if (/^SSBOND / && $all_headers) {
my ($rol) = unpack "x7 a65", $_;
$ssbond .= $rol;
$header{'ssbond'} = $ssbond;
}
if (/^LINK / && $all_headers) {
my ($rol) = unpack "x12 a60", $_;
$link .= $rol;
$header{'link'} = $link;
}
if (/^HYDBND / && $all_headers) {
my ($rol) = unpack "x12 a60", $_;
$hydbnd .= $rol;
$header{'hydbnd'} = $hydbnd;
}
if (/^SLTBRG / && $all_headers) {
my ($rol) = unpack "x12 a60",$_;
$sltbrg .= $rol;
$header{'sltbrg'} = $sltbrg;
}
if (/^CISPEP / && $all_headers) {
my ($rol) = unpack "x7 a52", $_;
$cispep .= $rol;
$header{'cispep'} = $cispep;
}
if (/^SITE / && $all_headers) {
my ($rol) = unpack "x7 a54", $_;
$site .= $rol;
$header{'site'} = $site;
}
if (/^CRYST1/ && $all_headers) {
my ($rol) = unpack "x6 a64", $_;
$cryst1 .= $rol;
$header{'cryst1'} = $cryst1;
}
if (/^(ORIGX\d) / && $all_headers) {
my $origxn = lc($1);
my ($rol) = unpack "x10 a45", $_;
$header{$origxn} .= $rol;
}
if (/^(SCALE\d) / && $all_headers) {
my $scalen = lc($1);
my ($rol) = unpack "x10 a45", $_;
$header{$scalen} .= $rol;
}
if (/^(MTRIX\d) / && $all_headers) {
my $mtrixn = lc($1);
my ($rol) = unpack "x7 a53", $_;
$header{$mtrixn} .= $rol;
}
if (/^TVECT / && $all_headers) {
my ($rol) = unpack "x7 a63", $_;
$tvect .= $rol;
$header{'tvect'} = $tvect;
}
$buffer = $self->_readline;
}
if (%header) {
for my $record (keys %header) {
my $sim = Bio::Annotation::SimpleValue->new();
$sim->value($header{$record});
$struc->annotation->add_Annotation($record, $sim);
}
}
if (%remark) {
for my $remark_num (keys %remark) {
my $sim = Bio::Annotation::SimpleValue->new();
$sim->value($remark{$remark_num});
$struc->annotation->add_Annotation("remark_$remark_num", $sim);
}
}
$buffer = $_;
if (defined($buffer) && $buffer =~ /^(ATOM |MODEL |HETATM)/ ) { until( !defined ($buffer) ) { my $model = $self->_read_PDB_coordinate_section(\$buffer, $struc);
$struc->add_model($struc, $model);
if ($buffer !~ /^MODEL /) { last;
}
}
}
else {
$self->throw("Could not find a coordinate section in this record\n");
}
until( !defined $buffer ) {
$_ = $buffer;
if (/^CONECT/) {
my $conect_unpack = "x6 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5";
my (@conect) = unpack $conect_unpack, $_;
for my $k (0 .. $#conect) {
$conect[$k] =~ s/\s//g;
}
my $source = shift @conect;
my $type;
for my $k (0 .. 9) {
next unless ($conect[$k] =~ /^\d+$/);
if( $k <= 3 ) {
$type = "bond";
}
elsif( ($k >= 4 && $k <= 5) || ($k >= 7 && $k <= 8) ) {
$type = "hydrogen";
}
elsif( $k == 6 || $k == 9 ) {
$type = "saltbridged";
} else {
$self->throw("k has impossible value ($k), check brain");
}
$struc->conect($source, $conect[$k], $type);
}
}
if (/^MASTER /) {
my ($rol) = unpack "x10 a60", $_;
$struc->master($rol);
}
if (/^END/) {
}
$buffer = $self->_readline;
}
return $struc; } |
sub write_structure
{ my ($self, $struc) = @_;
if( !defined $struc ) {
$self->throw("Attempting to write with no structure!");
}
if( ! ref $struc || ! $struc->isa('Bio::Structure::StructureI') ) {
$self->throw(" $struc is not a StructureI compliant module.");
}
my ($ann, $string, $output_string, $key);
($ann) = $struc->annotation->get_Annotations("header");
if ($ann) {
$string = $ann->as_text;
$string =~ s/^Value: //;
$output_string = pack ("A10 A56", "HEADER", $string);
} else { my $id = $struc->id;
if (!$id) {
$id = "UNK1";
}
if (length($id) > 4) {
$id = substr($id,0,4);
}
my $classification = "DEFAULT CLASSIFICATION";
my $dep_date = "24-JAN-70";
$output_string = pack ("A10 A40 A12 A4", "HEADER", $classification, $dep_date, $id);
}
$output_string .= " " x (80 - length($output_string) );
$self->_print("$output_string\n");
my (%header);
for $key ($struc->annotation->get_all_annotation_keys) {
$header{$key} = 1;;
}
exists $header{'obslte'} && $self->_write_PDB_simple_record(-name => "OBSLTE ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("obslte"), -rol => "11-70");
exists $header{'title'} && $self->_write_PDB_simple_record(-name => "TITLE ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("title"), -rol => "11-70");
exists $header{'caveat'} && $self->_write_PDB_simple_record(-name => "CAVEAT ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("caveat"), -rol => "12-70");
exists $header{'compnd'} && $self->_write_PDB_simple_record(-name => "COMPND ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("compnd"), -rol => "11-70");
exists $header{'source'} && $self->_write_PDB_simple_record(-name => "SOURCE ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("source"), -rol => "11-70");
exists $header{'keywds'} && $self->_write_PDB_simple_record(-name => "KEYWDS ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("keywds"), -rol => "11-70");
exists $header{'expdta'} && $self->_write_PDB_simple_record(-name => "EXPDTA ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("expdta"), -rol => "11-70");
exists $header{'author'} && $self->_write_PDB_simple_record(-name => "AUTHOR ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("author"), -rol => "11-70");
exists $header{'revdat'} && $self->_write_PDB_simple_record(-name => "REVDAT ",
-annotation => $struc->annotation->get_Annotations("revdat"), -rol => "8-66");
exists $header{'sprsde'} && $self->_write_PDB_simple_record(-name => "SPRSDE ", -cont => "9-10",
-annotation => $struc->annotation->get_Annotations("sprsde"), -rol => "12-70");
my ($jrnl_done, $remark_1_counter);
if ( !exists $header{'jrnl'} ) {
$jrnl_done = 1;
}
foreach my $ref ($struc->annotation->get_Annotations('reference') ) {
if( !$jrnl_done ) { $ref->authors && $self->_write_PDB_simple_record(-name => "JRNL AUTH",
-cont => "17-18", -rol => "20-70", -string => $ref->authors );
$ref->title && $self->_write_PDB_simple_record(-name => "JRNL TITL",
-cont => "17-18", -rol => "20-70", -string => $ref->title );
$ref->editors && $self->_write_PDB_simple_record(-name => "JRNL EDIT",
-cont => "17-18", -rol => "20-70", -string => $ref->editors );
$ref->location && $self->_write_PDB_simple_record(-name => "JRNL REF ",
-cont => "17-18", -rol => "20-70", -string => $ref->location );
$ref->editors && $self->_write_PDB_simple_record(-name => "JRNL EDIT",
-cont => "17-18", -rol => "20-70", -string => $ref->editors );
$ref->encoded_ref && $self->_write_PDB_simple_record(-name => "JRNL REFN",
-cont => "17-18", -rol => "20-70", -string => $ref->encoded_ref );
$jrnl_done = 1;
} else { if (!$remark_1_counter) { my $remark_1_header_line = "REMARK 1" . " " x 70;
$self->_print("$remark_1_header_line\n");
$remark_1_counter = 1;
}
my $rem_line = "REMARK 1 REFERENCE " . $remark_1_counter;
$rem_line .= " " x (80 - length($rem_line) );
$self->_print($rem_line,"\n");
$ref->authors && $self->_write_PDB_simple_record(-name => "REMARK 1 AUTH",
-cont => "17-18", -rol => "20-70", -string => $ref->authors );
$ref->title && $self->_write_PDB_simple_record(-name => "REMARK 1 TITL",
-cont => "17-18", -rol => "20-70", -string => $ref->title );
$ref->editors && $self->_write_PDB_simple_record(-name => "REMARK 1 EDIT",
-cont => "17-18", -rol => "20-70", -string => $ref->editors );
$ref->location && $self->_write_PDB_simple_record(-name => "REMARK 1 REF ",
-cont => "17-18", -rol => "20-70", -string => $ref->location );
$ref->editors && $self->_write_PDB_simple_record(-name => "REMARK 1 EDIT",
-cont => "17-18", -rol => "20-70", -string => $ref->editors );
$ref->encoded_ref && $self->_write_PDB_simple_record(-name => "REMARK 1 REFN",
-cont => "17-18", -rol => "20-70", -string => $ref->encoded_ref );
$remark_1_counter++;
}
}
if (! defined $remark_1_counter ) { my $remark_1_header_line = "REMARK 1" . " " x 70;
$self->_print("$remark_1_header_line\n"); }
my (%remarks, $remark_num);
for $key (keys %header) {
next unless ($key =~ /^remark_(\d+)$/);
next if ($1 == 1);
$remarks{$1} = 1;
}
for $remark_num (sort {$a <=> $b} keys %remarks) {
$self->_write_PDB_remark_record($struc, $remark_num);
}
exists $header{'dbref'} && $self->_write_PDB_simple_record(-name => "DBREF ",
-annotation => $struc->annotation->get_Annotations("dbref"), -rol => "8-68");
exists $header{'seqadv'} && $self->_write_PDB_simple_record(-name => "SEQADV ",
-annotation => $struc->annotation->get_Annotations("seqadv"), -rol => "8-70");
exists $header{'seqres'} && $self->_write_PDB_simple_record(-name => "SEQRES ",
-annotation => $struc->annotation->get_Annotations("seqres"), -rol => "9-70");
exists $header{'modres'} && $self->_write_PDB_simple_record(-name => "MODRES ",
-annotation => $struc->annotation->get_Annotations("modres"), -rol => "8-70");
exists $header{'het'} && $self->_write_PDB_simple_record(-name => "HET ",
-annotation => $struc->annotation->get_Annotations("het"), -rol => "8-70");
exists $header{'hetnam'} && $self->_write_PDB_simple_record(-name => "HETNAM ",
-annotation => $struc->annotation->get_Annotations("hetnam"), -rol => "9-70");
exists $header{'hetsyn'} && $self->_write_PDB_simple_record(-name => "HETSYN ",
-annotation => $struc->annotation->get_Annotations("hetsyn"), -rol => "9-70");
exists $header{'formul'} && $self->_write_PDB_simple_record(-name => "FORMUL ",
-annotation => $struc->annotation->get_Annotations("formul"), -rol => "9-70");
exists $header{'helix'} && $self->_write_PDB_simple_record(-name => "HELIX ",
-annotation => $struc->annotation->get_Annotations("helix"), -rol => "8-76");
exists $header{'sheet'} && $self->_write_PDB_simple_record(-name => "SHEET ",
-annotation => $struc->annotation->get_Annotations("sheet"), -rol => "8-70");
exists $header{'turn'} && $self->_write_PDB_simple_record(-name => "TURN ",
-annotation => $struc->annotation->get_Annotations("turn"), -rol => "8-70");
exists $header{'ssbond'} && $self->_write_PDB_simple_record(-name => "SSBOND ",
-annotation => $struc->annotation->get_Annotations("ssbond"), -rol => "8-72");
exists $header{'link'} && $self->_write_PDB_simple_record(-name => "LINK ",
-annotation => $struc->annotation->get_Annotations("link"), -rol => "13-72");
exists $header{'hydbnd'} && $self->_write_PDB_simple_record(-name => "HYDBND ",
-annotation => $struc->annotation->get_Annotations("hydbnd"), -rol => "13-72");
exists $header{'sltbrg'} && $self->_write_PDB_simple_record(-name => "SLTBRG ",
-annotation => $struc->annotation->get_Annotations("sltbrg"), -rol => "13-72");
exists $header{'cispep'} && $self->_write_PDB_simple_record(-name => "CISPEP ",
-annotation => $struc->annotation->get_Annotations("cispep"), -rol => "8-59");
exists $header{'site'} && $self->_write_PDB_simple_record(-name => "SITE ",
-annotation => $struc->annotation->get_Annotations("site"), -rol => "8-61");
exists $header{'cryst1'} && $self->_write_PDB_simple_record(-name => "CRYST1",
-annotation => $struc->annotation->get_Annotations("cryst1"), -rol => "7-70");
for my $k (1..3) {
my $origxn = "origx".$k;
my $ORIGXN = uc($origxn)." ";
exists $header{$origxn} && $self->_write_PDB_simple_record(-name => $ORIGXN,
-annotation => $struc->annotation->get_Annotations($origxn), -rol => "11-55");
}
for my $k (1..3) {
my $scalen = "scale".$k;
my $SCALEN = uc($scalen)." ";
exists $header{$scalen} && $self->_write_PDB_simple_record(-name => $SCALEN,
-annotation => $struc->annotation->get_Annotations($scalen), -rol => "11-55");
}
for my $k (1..3) {
my $mtrixn = "mtrix".$k;
my $MTRIXN = uc($mtrixn)." ";
exists $header{$mtrixn} && $self->_write_PDB_simple_record(-name => $MTRIXN,
-annotation => $struc->annotation->get_Annotations($mtrixn), -rol => "8-60");
}
exists $header{'tvect'} && $self->_write_PDB_simple_record(-name => "TVECT ",
-annotation => $struc->annotation->get_Annotations("tvect"), -rol => "8-70");
my %het_res; $het_res{'HOH'} = 1; if (exists $header{'het'}) {
my ($het_line) = ($struc->annotation->get_Annotations("het"))[0]->as_text;
$het_line =~ s/^Value: //;
for ( my $k = 0; $k <= length $het_line ; $k += 63) {
my $l = substr $het_line, $k, 63;
$l =~ s/^\s*(\S+)\s+.*$/$1/;
$het_res{$l} = 1;
}
}
for my $model ($struc->get_models) {
if ($struc->get_models > 1) {
my $model_line = sprintf("MODEL %4d", $model->id);
$model_line .= " " x (80 - length($model_line) );
$self->_print($model_line, "\n");
}
for my $chain ($struc->get_chains($model)) {
my ($residue, $atom, $resname, $resnum, $atom_line, $atom_serial, $atom_icode, $chain_id);
my ($prev_resname, $prev_resnum, $prev_atomicode); my $wr_ter = 0; $chain_id = $chain->id;
if ( $chain_id eq "default" ) {
$chain_id = " ";
}
$self->debug("model_id: $model->id chain_id: $chain_id\n");
for $residue ($struc->get_residues($chain)) {
($resname, $resnum) = split /-/, $residue->id;
for $atom ($struc->get_atoms($residue)) {
if ($het_res{$resname}) { if ( ! $wr_ter && $resname ne "HOH" ) { my $ter_line = "TER ";
$ter_line .= sprintf("%5d", $atom_serial + 1);
$ter_line .= " ";
$ter_line .= sprintf("%3s ", $prev_resname);
$ter_line .= $chain_id;
$ter_line .= sprintf("%4d", $prev_resnum);
$ter_line .= $atom_icode ? $prev_atomicode : " "; $ter_line .= " " x (80 - length $ter_line); $self->_print($ter_line,"\n");
$wr_ter = 1;
}
$atom_line = "HETATM";
} else {
$atom_line = "ATOM ";
}
$atom_line .= sprintf("%5d ", $atom->serial);
$atom_serial = $atom->serial; $atom_icode = $atom->icode;
$prev_resname = $resname;
$prev_resnum = $resnum;
$prev_atomicode = $atom_icode;
my $atom_id = $atom->id;
my $pdb_atomname = $atom->pdb_atomname;
if( defined $pdb_atomname ) {
$atom_line .= sprintf("%-4s", $pdb_atomname);
} else {
my $element = $atom->element;
if( defined $element && $element ne "H") {
if( length($element) == 2 ) {
$atom_line .= sprintf("%-4s", $atom->id);
} else {
$atom_line .= sprintf(" %-3s", $atom->id);
}
} else { if ($atom->id =~ /^\dH/) { $atom_line .= sprintf("%-4s", $atom->id);
} elsif (length($atom_id) == 4) {
if ($atom_id =~ /^(H\d\d)(\d)$/) { $atom_line .= $2.$1;
} else { $atom_line .= $atom_id;
}
} else { $atom_line .= sprintf(" %-3s", $atom->id);
}
}
}
$atom_line .= " "; $atom_line .= sprintf("%3s",$resname); $atom_line .= " ".$chain_id; $atom_line .= sprintf("%4d", $resnum); $atom_line .= $atom->icode ? $atom->icode : " "; $atom_line .= " "; $atom_line .= sprintf("%8.3f", $atom->x); $atom_line .= sprintf("%8.3f", $atom->y); $atom_line .= sprintf("%8.3f", $atom->z); $atom_line .= sprintf("%6.2f", $atom->occupancy); $atom_line .= sprintf("%6.2f", $atom->tempfactor); $atom_line .= " "; $atom_line .= $atom->segID ? sprintf("%-4s", $atom->segID) :
" ";
$atom_line .= $atom->element ?
sprintf("%2s", $atom->element) :
" ";
$atom_line .= $atom->charge ?
sprintf("%2s", $atom->charge) :
" ";
$self->_print($atom_line,"\n");
}
}
if ( $resname ne "HOH" && ! $wr_ter ) {
my $ter_line = "TER ";
$ter_line .= sprintf("%5d", $atom_serial + 1);
$ter_line .= " ";
$ter_line .= sprintf("%3s ", $resname);
$ter_line .= $chain_id;
$ter_line .= sprintf("%4d", $resnum);
$ter_line .= $atom_icode ? $atom_icode : " "; $ter_line .= " " x (80 - length $ter_line); $self->_print($ter_line,"\n");
$wr_ter = 1;
}
}
if ($struc->get_models > 1) { my $endmdl_line = "ENDMDL" . " " x 74;
$self->_print($endmdl_line, "\n");
}
}
my @sources = $struc->get_all_conect_source;
my ($conect_line,@conect, @bond, @hydbond, @saltbridge, $to, $type);
for my $source (@sources) {
my @conect = $struc->conect($source);
for my $con (@conect) {
($to, $type) = split /_/, $con;
if($type eq "bond") {
push @bond, $to;
} elsif($type eq "hydrogenbonded") {
push @hydbond, $to;
} elsif($type eq "saltbridged") {
push @saltbridge, $to;
} else {
$self->throw("type $type is unknown for conect");
}
}
while ( @bond || @hydbond || @saltbridge) {
my ($b, $hb, $sb);
$conect_line = "CONECT". sprintf("%5d", $source);
for my $k (0..3) {
$b = shift @bond;
$conect_line .= $b ? sprintf("%5d", $b) : " ";
}
for my $k (4..5) {
$hb = shift @hydbond;
$conect_line .= $hb ? sprintf("%5d", $hb) : " ";
}
$sb = shift @saltbridge;
$conect_line .= $sb ? sprintf("%5d", $sb) : " ";
for my $k (7..8) {
$hb = shift @hydbond;
$conect_line .= $hb ? sprintf("%5d", $hb) : " ";
}
$sb = shift @saltbridge;
$conect_line .= $sb ? sprintf("%5d", $sb) : " ";
$conect_line .= " " x (80 - length($conect_line) );
$self->_print($conect_line, "\n");
}
}
my $master_line = "MASTER " . $struc->master;
$master_line .= " " x (80 - length($master_line) );
$self->_print($master_line, "\n");
my $end_line = "END" . " " x 77;
$self->_print($end_line,"\n");
} |
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _