line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HackaMol::Roles::MolReadRole; |
2
|
|
|
|
|
|
|
$HackaMol::Roles::MolReadRole::VERSION = '0.051'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Read files with molecular information |
4
|
11
|
|
|
11
|
|
10740
|
use Moose::Role; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
107
|
|
5
|
11
|
|
|
11
|
|
64110
|
use Carp; |
|
11
|
|
|
|
|
41
|
|
|
11
|
|
|
|
|
762
|
|
6
|
11
|
|
|
11
|
|
83
|
use Math::Vector::Real; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
597
|
|
7
|
11
|
|
|
11
|
|
85
|
use HackaMol::PeriodicTable qw(%KNOWN_NAMES); |
|
11
|
|
|
|
|
37
|
|
|
11
|
|
|
|
|
1431
|
|
8
|
11
|
|
|
11
|
|
95
|
use FileHandle; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
121
|
|
9
|
11
|
|
|
11
|
|
9424
|
use YAML::XS qw(LoadFile); |
|
11
|
|
|
|
|
33630
|
|
|
11
|
|
|
|
|
720
|
|
10
|
11
|
|
|
11
|
|
96
|
use HackaMol::Atom; #add the code,the Role may better to understand |
|
11
|
|
|
|
|
32
|
|
|
11
|
|
|
|
|
7852
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
6
|
1
|
13
|
my $self = shift; |
31
|
6
|
|
|
|
|
14
|
my $string = shift; |
32
|
6
|
50
|
|
|
|
24
|
my $type = shift or croak "must pass format: xyz, pdb, cif, pdbqt, zmat, yaml"; |
33
|
|
|
|
|
|
|
|
34
|
6
|
50
|
|
3
|
|
436
|
open (my $fh, '<', \$string) or croak "unable to open string"; |
|
3
|
|
|
|
|
34
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
33
|
|
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
2898
|
my $atoms; |
37
|
|
|
|
|
|
|
|
38
|
6
|
100
|
|
|
|
46
|
if ( $type eq 'pdb' ) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
39
|
3
|
|
|
|
|
23
|
($atoms) = $self->read_pdb_atoms($fh); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ( $type eq 'pdbqt') { |
42
|
0
|
|
|
|
|
0
|
$atoms = $self->read_pdbqt_atoms($fh); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ( $type eq 'xyz') { |
45
|
2
|
|
|
|
|
19
|
$atoms = $self->read_xyz_atoms($fh); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ( $type eq 'zmat') { |
48
|
0
|
|
|
|
|
0
|
$atoms = $self->read_zmat_atoms($fh); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ( $type eq 'cif') { |
51
|
1
|
|
|
|
|
9
|
$atoms = $self->read_cif_atoms($fh); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( $type eq 'yaml') { |
54
|
0
|
|
|
|
|
0
|
$fh->close; |
55
|
0
|
|
|
|
|
0
|
$fh = Loadtype($type); |
56
|
0
|
|
|
|
|
0
|
$atoms = $self->read_yaml_atoms($fh); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
0
|
|
|
|
|
0
|
croak "$type format not supported"; |
60
|
|
|
|
|
|
|
} |
61
|
6
|
|
|
|
|
18
|
return (@{$atoms}); |
|
6
|
|
|
|
|
108
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub read_file_pdb_parts{ |
65
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
66
|
1
|
|
|
|
|
3
|
my $file = shift; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
28
|
my $fh = FileHandle->new("<$file") or croak "unable to open $file"; |
69
|
1
|
|
|
|
|
189
|
return $self->read_pdb_parts($fh); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub read_file_cif_parts { |
73
|
|
|
|
|
|
|
# temporary, this is getting out of hand! |
74
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
75
|
0
|
|
|
|
|
0
|
my $file = shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
0
|
my $fh = FileHandle->new("<$file") or croak "unable to open $file"; |
78
|
0
|
|
|
|
|
0
|
my $info = $self->read_cif_info($fh); |
79
|
0
|
|
|
|
|
0
|
my @models = $self->read_cif_atoms($fh); |
80
|
|
|
|
|
|
|
#$info = $self->read_cif_info($fh,$info); |
81
|
|
|
|
|
|
|
my @mols = map { |
82
|
0
|
|
|
|
|
0
|
HackaMol::Molecule->new( |
|
0
|
|
|
|
|
0
|
|
83
|
|
|
|
|
|
|
name => "model." . $_->[0]->model_num, |
84
|
|
|
|
|
|
|
atoms => $_ |
85
|
|
|
|
|
|
|
) } @models; |
86
|
0
|
|
|
|
|
0
|
return ($info, \@mols); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub read_file_atoms { |
90
|
24
|
|
|
24
|
1
|
4504
|
my $self = shift; |
91
|
24
|
|
|
|
|
66
|
my $file = shift; |
92
|
|
|
|
|
|
|
|
93
|
24
|
100
|
|
|
|
306
|
my $fh = FileHandle->new("<$file") or croak "unable to open $file"; |
94
|
|
|
|
|
|
|
|
95
|
23
|
|
|
|
|
3214
|
my $atoms; |
96
|
|
|
|
|
|
|
|
97
|
23
|
100
|
|
|
|
268
|
if ( $file =~ m/\.pdb$/ ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
98
|
11
|
|
|
|
|
87
|
($atoms) = $self->read_pdb_atoms($fh); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
elsif ( $file =~ m/\.pdbqt$/ ) { |
101
|
1
|
|
|
|
|
11
|
$atoms = $self->read_pdbqt_atoms($fh); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
elsif ( $file =~ m/\.cif$/ ) { |
104
|
0
|
|
|
|
|
0
|
$atoms = $self->read_cif_atoms($fh); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ( $file =~ m/\.xyz$/ ) { |
107
|
11
|
|
|
|
|
80
|
$atoms = $self->read_xyz_atoms($fh); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ( $file =~ m/\.zmat$/ ) { |
110
|
0
|
|
|
|
|
0
|
$atoms = $self->read_zmat_atoms($fh); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif ( $file =~ m/\.yaml$/) { |
113
|
0
|
|
|
|
|
0
|
$fh->close; |
114
|
0
|
|
|
|
|
0
|
$fh = LoadFile($file); |
115
|
0
|
|
|
|
|
0
|
$atoms = $self->read_yaml_atoms($fh); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
0
|
|
|
|
|
0
|
croak "$file format not supported"; |
119
|
|
|
|
|
|
|
} |
120
|
20
|
|
|
|
|
68
|
return (@{$atoms}); |
|
20
|
|
|
|
|
2139
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
11
|
|
|
11
|
|
102
|
no Moose::Role; |
|
11
|
|
|
|
|
35
|
|
|
11
|
|
|
|
|
118
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
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 |