| 1 | package HackaMol::Roles::ReadXyzRole; | ||||||||||||||
| 2 | 11 | $HackaMol::Roles::ReadXyzRole::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 FileHandle; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 13 | ▶ | sub read_xyz_atoms { | ||||||||||||
|
Subroutine
read_xyz_atoms: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | #read xyz file and generate list of Atom objects | ||||||||||||||
| 12 | 13 | my $self = shift; | |||||||||||||
| 13 | 13 | my $fh = shift; | |||||||||||||
| 14 | # my $file = shift; | ||||||||||||||
| 15 | # my $fh = FileHandle->new("<$file") or croak "unable to open $file"; | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 13 | my @atoms; | |||||||||||||
| 18 | 13 | my ( $n, $t ) = ( 0, 0 ); | |||||||||||||
| 19 | |||||||||||||||
| 20 | 13 | my $nat = undef; | |||||||||||||
| 21 | 13 | ▶ | while (<$fh>) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | 669 | ▶ | if (/^(\s*\d+\s*)$/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 24 | 16 | $n = (split)[0]; | |||||||||||||
| 25 | 16 | ▶ | if ( defined($nat) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 5 | ▶ | croak "number of atoms has changed\n" unless ( $nat == $n ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 4 | $t++; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | 15 | $nat = $n; | |||||||||||||
| 30 | 15 | $n = 0; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | elsif (/(\w+|\d+)(\s+-*\d+\.\d+){3}/) { | ||||||||||||||
| 33 | 638 | my @stuff = split; | |||||||||||||
| 34 | 638 | my $sym = $stuff[0]; | |||||||||||||
| 35 | 638 | my $xyz = V( @stuff[ 1, 2, 3 ] ); | |||||||||||||
| 36 | 638 | ▶ | if ( $t == 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 624 | ▶ | if ( $sym =~ /\d/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 12 | $atoms[$n] = HackaMol::Atom->new( | |||||||||||||
| 39 | name => "at$n", | ||||||||||||||
| 40 | Z => $sym, | ||||||||||||||
| 41 | coords => [$xyz] | ||||||||||||||
| 42 | ); | ||||||||||||||
| 43 | } | ||||||||||||||
| 44 | else { | ||||||||||||||
| 45 | 612 | $atoms[$n] = HackaMol::Atom->new( | |||||||||||||
| 46 | name => "at$n", | ||||||||||||||
| 47 | symbol => $sym, | ||||||||||||||
| 48 | coords => [$xyz] | ||||||||||||||
| 49 | ); | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | } | ||||||||||||||
| 52 | else { | ||||||||||||||
| 53 | 14 | ▶ | if ( $sym =~ /\d/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 10 | ▶ | croak "atoms have changed from last model to current: $t\n" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | if ( $sym != $atoms[$n]->Z ); | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | else { | ||||||||||||||
| 58 | 4 | ▶ | croak "atoms have changed from last model to current: $t\n" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | if ( $sym ne $atoms[$n]->symbol ); | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | 12 | $atoms[$n]->set_coords( $t, $xyz ); | |||||||||||||
| 62 | |||||||||||||||
| 63 | } | ||||||||||||||
| 64 | 636 | $n++; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | # set iatom to track the array. diff from serial which refers to pdb | ||||||||||||||
| 69 | 10 | $atoms[$_]->iatom($_) foreach ( 0 .. $#atoms ); | |||||||||||||
| 70 | 10 | return (\@atoms); | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 11 | ▶ | no Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 74 | |||||||||||||||
| 75 | 11 | 1; | |||||||||||||
| 76 | |||||||||||||||
| 77 | __END__ | ||||||||||||||