| 1 | package HackaMol::Roles::MolReadRole; | ||||||||||||||||||||||||||||||
| 2 | 11 | $HackaMol::Roles::MolReadRole::VERSION = '0.051'; | |||||||||||||||||||||||||||||
| 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 | sub read_string_atoms { | ||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
read_string_atoms: called CC=9 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 31 | 6 | my $string = shift; | |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | my $type = shift or croak "must pass format: xyz, pdb, cif, pdbqt, zmat, yaml"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | open (my $fh, '<', \$string) or croak "unable to open string"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 6 | my $atoms; | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | if ( $type eq 'pdb' ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 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 | sub read_file_pdb_parts{ | ||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
read_file_pdb_parts: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 66 | 1 | my $file = shift; | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | my $fh = FileHandle->new("<$file") or croak "unable to open $file"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | 1 | return $self->read_pdb_parts($fh); | |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | sub read_file_cif_parts { | ||||||||||||||||||||||||||||||
| 73 | # temporary, this is getting out of hand! | ||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
read_file_cif_parts: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 75 | 0 | my $file = shift; | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $fh = FileHandle->new("<$file") or croak "unable to open $file"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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 | sub read_file_atoms { | ||||||||||||||||||||||||||||||
| 90 | 24 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
read_file_atoms: called CC=8 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 91 | 24 | my $file = shift; | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | 24 | ▶ | my $fh = FileHandle->new("<$file") or croak "unable to open $file"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 23 | my $atoms; | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | 23 | ▶ | if ( $file =~ m/\.pdb$/ ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | =pod | ||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | =head1 NAME | ||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | HackaMol::Roles::MolReadRole - Read files with molecular information | ||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | =head1 VERSION | ||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | version 0.051 | ||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | use HackaMol; | ||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | my $hack = HackaMol->new( name => "hackitup" ); | ||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | # build array of carbon atoms from pdb [xyz,pdbqt] file | ||||||||||||||||||||||||||||||
| 146 | my @carbons = grep { | ||||||||||||||||||||||||||||||
| 147 | $_->symbol eq "C" | ||||||||||||||||||||||||||||||
| 148 | } $hack->read_file_atoms("t/lib/1L2Y.pdb"); | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | my $Cmol = HackaMol::Molecule->new( | ||||||||||||||||||||||||||||||
| 151 | name => "carbonprotein", | ||||||||||||||||||||||||||||||
| 152 | atoms => [ @carbons ] | ||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | $Cmol->print_pdb; | ||||||||||||||||||||||||||||||
| 156 | $Cmol->print_xyz; | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | # build molecule from xyz [pdb,pdbqt] file | ||||||||||||||||||||||||||||||
| 159 | my $mol = $hack->read_file_mol("some.xyz"); | ||||||||||||||||||||||||||||||
| 160 | $mol->print_pdb; # | ||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | The HackaMol::Role::MolReadRole role provides methods for reading common structural files. Currently, | ||||||||||||||||||||||||||||||
| 165 | pdb, pdbqt, Z-matrix, and xyz are provided. The methods are all provided in separate roles. Adding | ||||||||||||||||||||||||||||||
| 166 | additional formats is straightforward: | ||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||
| 168 | 1. Add a Role that parses the file and returns a list of HackaMol::Atoms. | ||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||
| 170 | 2. Add the code here to consume the role and call the method based on the file ending. | ||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | =head1 METHODS | ||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||
| 174 | =head2 read_file_atoms | ||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | one argument: the name of a file (.xyz, .pdb, .pdbqt, .zmat) | ||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||
| 178 | returns a list of HackaMol::Atom objects | ||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||
| 180 | =head2 read_string_atoms | ||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||
| 182 | two arguments: 1. a string with coordinates properly formatted; 2. format (xyz, pdb, pdbqt, zmat, yaml) | ||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | returns a list of HackaMol::Atom objects | ||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | =head2 hush_read | ||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | isa Int that is lazy (default 0). $hack->hush_read(1) will quiet some warnings that may be ignored under some instances. | ||||||||||||||||||||||||||||||
| 191 | $hack->hush_read(-1) will increase info printed out for some warnings. | ||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||
| 193 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | =over 4 | ||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | =item * | ||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||
| 199 | L<HackaMol> | ||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | =item * | ||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||
| 203 | L<HackaMol::Roles::ReadXyzRole> | ||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||
| 205 | =item * | ||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | L<HackaMol::Roles::ReadPdbRole> | ||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | =item * | ||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||
| 211 | L<HackaMol::Roles::ReadPdbqtRole> | ||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||
| 213 | =item * | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | L<HackaMol::Roles::ReadZmatRole> | ||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||
| 217 | =item * | ||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | L<HackaMol::Atom> | ||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||
| 221 | =item * | ||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||
| 223 | L<HackaMol::Molecule> | ||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||
| 225 | =back | ||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||
| 227 | =head1 CONSUMES | ||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | =over 4 | ||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||
| 231 | =item * L<HackaMol::Roles::NERFRole> | ||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | =item * L<HackaMol::Roles::ReadPdbRole> | ||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||
| 235 | =item * L<HackaMol::Roles::ReadPdbqtRole> | ||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||
| 237 | =item * L<HackaMol::Roles::ReadPdbxRole> | ||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||
| 239 | =item * L<HackaMol::Roles::ReadXyzRole> | ||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||
| 241 | =item * L<HackaMol::Roles::ReadYAMLRole> | ||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||
| 243 | =item * L<HackaMol::Roles::ReadYAMLRole|HackaMol::Roles::ReadZmatRole|HackaMol::Roles::ReadPdbRole|HackaMol::Roles::ReadPdbxRole|HackaMol::Roles::ReadPdbqtRole|HackaMol::Roles::ReadXyzRole> | ||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||
| 245 | =item * L<HackaMol::Roles::ReadZmatRole> | ||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | =back | ||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||
| 249 | =head1 AUTHOR | ||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | Demian Riccardi <demianriccardi@gmail.com> | ||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||
| 253 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||
| 255 | This software is copyright (c) 2017 by Demian Riccardi. | ||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||
| 257 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||
| 258 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||
| 260 | =cut | ||||||||||||||||||||||||||||||