| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Chemistry::File::QChemOut; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | $VERSION = '0.10'; | 
| 4 |  |  |  |  |  |  | # $Id: QChemOut.pm,v 1.1.1.1 2006/10/04 16:13:50 itubert Exp $ | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 22306 | use base qw(Chemistry::File); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 3180 |  | 
| 7 | 1 |  |  | 1 |  | 41384 | use Chemistry::Mol; | 
|  | 1 |  |  |  |  | 61890 |  | 
|  | 1 |  |  |  |  | 58 |  | 
| 8 | 1 |  |  | 1 |  | 11 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 64 |  | 
| 9 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 10 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 481 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 NAME | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | Chemistry::File::QChemOut - Q-Chem ouput molecule format reader | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | use Chemistry::File::QChemOut; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # read an QChemOut file | 
| 21 |  |  |  |  |  |  | my $mol = Chemistry::Mol->read("myfile.out", format => 'qchemout'); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | # read all the intermediate structures (e.g., optimization steps) | 
| 24 |  |  |  |  |  |  | my $mol = Chemistry::Mol->read("myfile.out", | 
| 25 |  |  |  |  |  |  | format => 'chemout', all => 1); | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =cut | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | This module reads Q-Chem output files. It automatically registers the | 
| 32 |  |  |  |  |  |  | 'qchemout' format with Chemistry::Mol, so that Q-Chem outuput files may be | 
| 33 |  |  |  |  |  |  | identified and read using Chemistry::Mol->read(). | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | The current version of this reader simply extracts the cartesian coordinates | 
| 36 |  |  |  |  |  |  | and symbols from the Q-Chem outuput file. All other information is ignored. | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head1 INPUT OPTIONS | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =over | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =item all | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | If true, read all the intermediate structures, as in a structure optimization. | 
| 45 |  |  |  |  |  |  | This causes $mol->read to return an array instead of a single molecule. | 
| 46 |  |  |  |  |  |  | Default: false. | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =back | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =cut | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | Chemistry::Mol->register_format(qchemout => __PACKAGE__); | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub parse_string { | 
| 55 | 2 |  |  | 2 | 1 | 43694 | my ($class, $s, %opts) = @_; | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 2 |  | 50 |  |  | 11 | my $mol_class  = $opts{mol_class}  || 'Chemistry::Mol'; | 
| 58 | 2 |  | 33 |  |  | 22 | my $atom_class = $opts{atom_class} || $mol_class->atom_class; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 2 |  |  |  |  | 219 | my @coord_blocks = $s =~ m{ | 
| 61 |  |  |  |  |  |  | Standard\ Nuclear\ Orientation | 
| 62 |  |  |  |  |  |  | .*? | 
| 63 |  |  |  |  |  |  | ---- | 
| 64 |  |  |  |  |  |  | (?:\n|\r\n?) | 
| 65 |  |  |  |  |  |  | (.*?)           # coordinate block | 
| 66 |  |  |  |  |  |  | \ ---- | 
| 67 |  |  |  |  |  |  | }smxg; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 2 | 50 |  |  |  | 11 | croak "no coordinates found" unless @coord_blocks; | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 2 | 100 |  |  |  | 10 | unless ($opts{all}) { | 
| 72 |  |  |  |  |  |  | # keep only the last block | 
| 73 | 1 |  |  |  |  | 4 | splice @coord_blocks, 0, @coord_blocks - 1; | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 2 |  |  |  |  | 5 | my @mols; | 
| 77 | 2 |  |  |  |  | 6 | for my $block (@coord_blocks) { | 
| 78 | 5 |  |  |  |  | 22 | my $mol = $mol_class->new(); | 
| 79 | 5 |  |  |  |  | 176 | my @lines = split /(?:\n|\r\n?)/, $block; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 5 |  |  |  |  | 9 | my $i = 0; | 
| 82 | 5 |  |  |  |  | 9 | for my $line (@lines) { | 
| 83 | 40 |  |  |  |  | 3295 | $i++; | 
| 84 | 40 |  |  |  |  | 156 | $line =~ s/^\s+//; | 
| 85 | 40 |  |  |  |  | 152 | my ($n, $symbol, $x, $y, $z) = split ' ', $line; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 40 |  |  |  |  | 149 | my $atom = $mol->new_atom( | 
| 88 |  |  |  |  |  |  | symbol => $symbol, | 
| 89 |  |  |  |  |  |  | coords => [$x, $y, $z], | 
| 90 |  |  |  |  |  |  | ); | 
| 91 |  |  |  |  |  |  | } | 
| 92 | 5 |  |  |  |  | 415 | push @mols, $mol; | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 2 | 100 |  |  |  | 21 | return $opts{all} ? @mols : $mols[0]; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | sub name_is { | 
| 99 | 0 |  |  | 0 | 1 |  | my ($class, $fname) = @_; | 
| 100 | 0 |  |  |  |  |  | return; | 
| 101 | 0 |  |  |  |  |  | $fname =~ /\.xyz$/i; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | sub file_is { | 
| 105 | 0 |  |  | 0 | 1 |  | my ($class, $fname) = @_; | 
| 106 | 0 |  |  |  |  |  | return; | 
| 107 | 0 |  |  |  |  |  | $fname =~ /\.xyz$/i; | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | sub write_string { | 
| 111 | 0 |  |  | 0 | 1 |  | my ($class, $mol, %opts) = @_; | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 0 |  |  |  |  |  | croak "QChemOut writing not implemented"; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | 1; | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =head1 VERSION | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | 0.10 | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | L, L. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head1 AUTHOR | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | Ivan Tubert-Brohman | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =cut | 
| 131 |  |  |  |  |  |  |  |