HackaMol/Roles/MolReadRole.pm

filter: Statementstmt 72.6% 53 / 73 Branchbran 52.9% 18 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 50.0% 2 / 4 totaltotal 68.2% 84 / 123 CC 18 SCAR 21.4
CC
18
Cov
66%
read_string_atoms
14.0
read_file_atoms
12.1
read_file_cif_parts
6.0
CRAP 8.5
« HackaMol/Roles/ReadXyzRole.pm ↑ Summary HackaMol/Roles/AtomGroupRole.pm »
1 package HackaMol::Roles::MolReadRole;
2 11 $HackaMol::Roles::MolReadRole::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 Carp;
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 HackaMol::PeriodicTable qw(%KNOWN_NAMES);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use YAML::XS qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use HackaMol::Atom; #add the code,the Role may better to understand
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 with qw(
13 HackaMol::Roles::ReadYAMLRole
14 HackaMol::Roles::ReadZmatRole
15 HackaMol::Roles::ReadPdbRole
16 HackaMol::Roles::ReadPdbxRole
17 HackaMol::Roles::ReadPdbqtRole
18 HackaMol::Roles::ReadXyzRole
19 );
20  
21 11 has 'hush_read' => (
22 is => 'rw',
23 isa => 'Int',
24 lazy => 1,
25 default => 0,
26 );
27  
28  
29 6 ▶sub read_string_atoms {
Subroutine read_string_atoms: called CC=9 SCAR=26.4
Pod documented
30 6 my $self = shift;
31 6 my $string = shift;
32 6 ▶ my $type = shift or croak "must pass format: xyz, pdb, cif, pdbqt, zmat, yaml";
Branch: 1 branch
BranchTrueFalseTotal
my $type = shift() or croak("must pass format: xyz, pdb, cif, pdbqt, zmat, yaml") 6 0 6
33  
34 6 ▶ open (my $fh, '<', \$string) or croak "unable to open string";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", \$string or croak("unable to open string") 6 0 6
35  
36 6 my $atoms;
37  
38 6 ▶ if ( $type eq 'pdb' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'pdb') { } 3 3 6
elsif ($type eq 'pdbqt') { } 0 3 3
elsif ($type eq 'xyz') { } 2 1 3
elsif ($type eq 'zmat') { } 0 1 1
elsif ($type eq 'cif') { } 1 0 1
elsif ($type eq 'yaml') { } 0 0 0
39 3 ($atoms) = $self->read_pdb_atoms($fh);
40 }
41 elsif ( $type eq 'pdbqt') {
42 0 $atoms = $self->read_pdbqt_atoms($fh);
43 }
44 elsif ( $type eq 'xyz') {
45 2 $atoms = $self->read_xyz_atoms($fh);
46 }
47 elsif ( $type eq 'zmat') {
48 0 $atoms = $self->read_zmat_atoms($fh);
49 }
50 elsif ( $type eq 'cif') {
51 1 $atoms = $self->read_cif_atoms($fh);
52 }
53 elsif ( $type eq 'yaml') {
54 0 $fh->close;
55 0 $fh = Loadtype($type);
56 0 $atoms = $self->read_yaml_atoms($fh);
57 }
58 else {
59 0 croak "$type format not supported";
60 }
61 6 return (@{$atoms});
62 }
63  
64 1 ▶sub read_file_pdb_parts{
Subroutine read_file_pdb_parts: called CC=2 SCAR=7.0
Pod undocumented
65 1 my $self = shift;
66 1 my $file = shift;
67  
68 1 ▶ my $fh = FileHandle->new("<$file") or croak "unable to open $file";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "FileHandle"->new("<$file") or croak("unable to open $file") 1 0 1
69 1 return $self->read_pdb_parts($fh);
70 }
71  
72 0 ▶sub read_file_cif_parts {
Subroutine read_file_cif_parts: not called CC=2 SCAR=17.9
Pod undocumented
73 # temporary, this is getting out of hand!
74 0 my $self = shift;
75 0 my $file = shift;
76  
77 0 ▶ my $fh = FileHandle->new("<$file") or croak "unable to open $file";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "FileHandle"->new("<$file") or croak("unable to open $file") 0 0 0
78 0 my $info = $self->read_cif_info($fh);
79 0 my @models = $self->read_cif_atoms($fh);
80 #$info = $self->read_cif_info($fh,$info);
81 my @mols = map {
82 0 HackaMol::Molecule->new(
83 name => "model." . $_->[0]->model_num,
84 atoms => $_
85 ) } @models;
86 0 return ($info, \@mols);
87 }
88  
89 24 ▶sub read_file_atoms {
Subroutine read_file_atoms: called CC=8 SCAR=24.9
Pod documented
90 24 my $self = shift;
91 24 my $file = shift;
92
93 24 ▶ my $fh = FileHandle->new("<$file") or croak "unable to open $file";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "FileHandle"->new("<$file") or croak("unable to open $file") 23 1 24
94  
95 23 my $atoms;
96  
97 23 ▶ if ( $file =~ m/\.pdb$/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($file =~ /\.pdb$/) { } 11 12 23
elsif ($file =~ /\.pdbqt$/) { } 1 11 12
elsif ($file =~ /\.cif$/) { } 0 11 11
elsif ($file =~ /\.xyz$/) { } 11 0 11
elsif ($file =~ /\.zmat$/) { } 0 0 0
elsif ($file =~ /\.yaml$/) { } 0 0 0
98 11 ($atoms) = $self->read_pdb_atoms($fh);
99 }
100 elsif ( $file =~ m/\.pdbqt$/ ) {
101 1 $atoms = $self->read_pdbqt_atoms($fh);
102 }
103 elsif ( $file =~ m/\.cif$/ ) {
104 0 $atoms = $self->read_cif_atoms($fh);
105 }
106 elsif ( $file =~ m/\.xyz$/ ) {
107 11 $atoms = $self->read_xyz_atoms($fh);
108 }
109 elsif ( $file =~ m/\.zmat$/ ) {
110 0 $atoms = $self->read_zmat_atoms($fh);
111 }
112 elsif ( $file =~ m/\.yaml$/) {
113 0 $fh->close;
114 0 $fh = LoadFile($file);
115 0 $atoms = $self->read_yaml_atoms($fh);
116 }
117 else {
118 0 croak "$file format not supported";
119 }
120 20 return (@{$atoms});
121 }
122  
123 11 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
124  
125 11 1;
126  
127 __END__
« HackaMol/Roles/ReadXyzRole.pm ↑ Summary HackaMol/Roles/AtomGroupRole.pm »