HackaMol/Roles/ReadPdbqtRole.pm

filter: Statementstmt 88.5% 54 / 61 Branchbran 75.0% 18 / 24 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 80.2% 81 / 101 CC 17 SCAR 27.8
CC
17
Cov
81%
read_pdbqt_atoms
20.5
BEGIN
1.0
BEGIN
1.0
CRAP 16.1
« HackaMol/Roles/ReadPdbRole.pm ↑ Summary HackaMol/Roles/FileFetchRole.pm »
1 package HackaMol::Roles::ReadPdbqtRole;
2 11 $HackaMol::Roles::ReadPdbqtRole::VERSION = '0.053';
3 # ABSTRACT: Read files with molecular information
4 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use HackaMol::PeriodicTable qw(_element_name _trim _qstring_num);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Math::Vector::Real;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub read_pdbqt_atoms {
Subroutine read_pdbqt_atoms: called CC=17 SCAR=30.2
Pod documented
10  
11 # this is too similar to reading pdb for it too exist separately... think about
12 1 my $self = shift;
13 1 my $fh = shift;
14 #my $file = shift;
15 #my $fh = FileHandle->new("<$file") or croak "unable to open $file";
16  
17 # $RtBrnch{ROOT}{iatoms} = LIST integers of atoms in root
18 # $RtBrnch{BRNCH1}{iatoms} = LIST integers of atoms in BRNCH1
19 # $RtBrnch{BRNCH1}{ROOT} = LIST two integers of rotable bond for BRNCH1
20 # $RtBrnch{BRNCH2}{iatoms} = LIST integers of atoms in BRNCH2
21 # $RtBrnch{BRNCH2}{SBRNCH1} iatoms} = LIST integers of atoms in BRNCH2
22 # each branch is rigid block of atoms
23 # NONONONONO!!!! for now, just read in atoms. We'll figure out how to save the tree later
24 1 my %RtBrnch;
25  
26 my @atoms;
27 1 my ( $n, $t ) = ( 0, 0 );
28 1 my $q_tbad = 0;
29 1 my $something_dirty = 0;
30  
31 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 378 1 379
32  
33 378 ▶ if (/^(?:MODEL\s+(\d+))/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^(?:MODEL\s+(\d+))/) { } 9 369 378
elsif (/^(?:ENDMDL)/) { } 9 360 369
elsif (/^(?:HETATM|ATOM)/) { } 252 108 360
34 9 $n = 0;
35 9 $q_tbad = 0; # flag a bad model and never read again!
36 }
37 elsif (/^(?:ENDMDL)/) {
38 9 $t++;
39 }
40 elsif (/^(?:HETATM|ATOM)/) {
41 252 ▶ next if $q_tbad;
Branch: 1 branch
BranchTrueFalseTotal
if $q_tbad 0 252 252
42 my (
43 252 $record_name, $serial, $name, $altloc, $resName,
44 $chainID, $resSeq, $icod, $x, $y,
45 $z, $occ, $B, $charge, $ADTtype
46 ) = unpack "A6A5x1A4A1A3x1A1A4A1x3A8A8A8A6A6x4A6x1A2", $_;
47  
48 #ATOM 1 O LIG d 1 8.299 4.799 79.371 0.00 0.00 -0.292 OA
49 #-----|----|x---||--|x|---||xxx-------|-------|-------|-----|-----|xxxx-----|x-|
50  
51 252 ▶ if ( $chainID =~ m/\w/ ) { $chainID = uc( _trim($chainID) ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($chainID =~ /\w/) { } 252 0 252
52 0 else { $chainID = ' ' }
53  
54 252 $name = _trim($name);
55 252 $resName = _trim($resName);
56 252 $resSeq = _trim($resSeq);
57  
58 #$resSeq = 0 if ( $resSeq < 0 );
59 252 $serial = _trim($serial);
60 252 $charge = _trim($charge);
61 252 $ADTtype = _trim($ADTtype);
62  
63 252 my ( $element, $qdirt ) = _element_name($ADTtype);
64 252 ▶ $something_dirty++ if ($qdirt);
Branch: 1 branch
BranchTrueFalseTotal
if $qdirt 27 225 252
65 252 my $xyz = V( $x, $y, $z );
66  
67 252 ▶ if ( $t == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t == 0) { } 28 224 252
68 28 $atoms[$n] = HackaMol::Atom->new(
69 name => $name,
70 record_name => $record_name,
71 serial => $serial,
72 chain => $chainID,
73 symbol => $element,
74 charges => [$charge],
75 coords => [$xyz],
76 occ => $occ * 1,
77 bfact => $B * 1,
78 resname => $resName,
79 resid => $resSeq,
80 segid => $ADTtype,
81 altloc => $altloc,
82 );
83 28 ▶ $atoms[$n]->is_dirty($qdirt) unless $atoms[$n]->is_dirty;
Branch: 1 branch
BranchTrueFalseTotal
unless $atoms[$n]->is_dirty 28 0 28
84 }
85 else {
86 #croak condition if atom changes between models
87 224 ▶ if ( $n > $#atoms or $name ne $atoms[$n]->name
Branch: 1 branch
BranchTrueFalseTotal
if ($n > $#atoms or $name ne $atoms[$n]->name or $element ne $atoms[$n]->symbol) 0 224 224
Condition33%2/6
$n > $#atoms or $name ne $atoms[$n]->name or $element ne $atoms[$n]->symbol
l!l&&r!l&&!r
00224
$n > $#atoms or $name ne $atoms[$n]->name
l!l&&r!l&&!r
00224
MC/DC0%0/3
$n > $#atoms or $name ne $atoms[$n]->name or $element ne $atoms[$n]->symbol
$n > $#atoms $name ne $atoms[$n]->name $element ne $atoms[$n]->symbol
Truth table25%1/4
A or B or C
A= $n > $#atomsB= $name ne $atoms[$n]->nameC= $element ne $atoms[$n]->symbol
ABCresult
1XX1
01X1
0011
0000
88 or $element ne $atoms[$n]->symbol )
89 {
90 0 my $carp_message =
91 "BAD t->$t PDB Atom $n "
92 . "serial $serial resname $resName "
93 . "has changed";
94 0 carp $carp_message;
95 0 $q_tbad = $t; # this is a bad model!
96 #wipe out all the coords prior
97 0 $atoms[$_]->delete_coords($t) foreach 0 .. $n - 1;
98 0 $t--;
99 0 next;
100 }
101 224 $atoms[$n]->set_coords( $t, $xyz );
102 }
103 252 $n++;
104 }
105 }
106  
107 # set iatom to track the array. diff from serial which refers to pdb
108 1 $atoms[$_]->iatom($_) foreach ( 0 .. $#atoms );
109 1 ▶ if ($something_dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($something_dirty) 1 0 1
110 1 ▶ unless ( $self->hush_read ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hush_read) 1 0 1
111 1 my $message = "MolReadRole> found $something_dirty dirty atoms. ";
112 1 $message .= "Check symbols and lookup names";
113 1 carp $message;
114 }
115 }
116 1 return (\@atoms);
117 }
118  
119 11 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121 11 1;
122  
123 __END__
« HackaMol/Roles/ReadPdbRole.pm ↑ Summary HackaMol/Roles/FileFetchRole.pm »