Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Parsing Guassian '03 Log Files

by GrandFather (Saint)
on Jan 31, 2008 at 01:43 UTC ( [id://665253]=note: print w/replies, xml ) Need Help??


in reply to Parsing Guassian '03 Log Files

Something like:

use strict; use warnings; my $file = <<FILE; ---------------------------- ! Optimized Parameters ! ! (Angstroms and Degrees) ! ---------------------- ------------------- +----------------------------------------------------- ! Name Value Derivative information (Atomic Units) + ! --------------------------------------------------------------------- +--- ! hc2 1.1136 -DE/DX = 0.0 + ! ! nc3 1.3392 -DE/DX = 0.0 + ! ! nch3 117.4979 -DE/DX = 0.0 + ! ! hn4 0.9929 -DE/DX = 0.0 + ! ---------------------------------------------------------------------- +-- GradGradGradGradGradGradGradGradGradGradGradGradGradGradGradGradGradGr +adGrad FILE open my $inFile, '<', \$file; my $valueStart; my $valueLength; my $min = 1.0; my $max = 2.0; while (<$inFile>) { next unless m/Optimized Parameters/ .. m/GradGradGrad/; next unless $valueLength or /^(.*?Name)(\s*Value)/; if (! $valueLength) { $valueStart = length $1; $valueLength = length $2; next; } my $value = substr $_, $valueStart, $valueLength; next unless $value =~ /^\s*[+-]?\d+(\.\d*)?\s*$/; next if $value < $min or $value > $max; print $_; } close $inFile;

Prints:

! hc2 1.1136 -DE/DX = 0.0 + ! ! nc3 1.3392 -DE/DX = 0.0 + !

Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: Parsing Guassian '03 Log Files
by Andrew_Levenson (Hermit) on Jan 31, 2008 at 02:15 UTC
    Thank you very much, but unfortunately, I need it to work in such a way that I call the script/program, feed it an input filename and an output filename, and have it work its magic. Each file is of an undetermined length, with sections that need to be parsed f undetermined length, as each file represents a different chain-length of the molecule.

    Sorry that I didn't specify that earlier.
    C(qw/74 97 104 112/);sub C{while(@_){$c**=$C;print (map{chr($C!=$c?shift:pop)}$_),$C+=@_%2!=1?1:0}}

      Well, I couldn't do it all for you - what would you do with all the time you saved?

      You may find help in dealing with the file issues in replies to the thread File read and strip ;).


      Perl is environmentally friendly - it saves trees
        Thanks, GF.
        You've been a great help time and again. :)
        C(qw/74 97 104 112/);sub C{while(@_){$c**=$C;print (map{chr($C!=$c?shift:pop)}$_),$C+=@_%2!=1?1:0}}
        I ended up hacking this together when I got into the lab this afternoon. It's ugly, and probably inefficient, but it is entirely within my skillset and it works beautifully for what I need it to do (save for one file, which for some reason gets printed in triplicate, but that is just one case).
        #!/usr/bin/perl use strict; use warnings; # Parse Gaussian '03 output files # for the lengths of the bonds # in Diaminopolymethine Dyes # strictly between Carbon and Nitrogen # or Carbon and Carbon my $infile, my $outfile; my @inlog, my @inlog_n, my @logged; chomp($infile = <>); chomp($outfile = <>); open FILE, "<$infile"; while(<FILE>) { push @inlog, $_; } close FILE; for(@inlog) { push @inlog_n, grep( /^\s?!{1}?\s*(c|n)/, $_); } @inlog = grep( !/h|c{3}?|nc{2}?|(estimate)|c{2}?n{1}?/, @inlog_n ); pop @inlog_n for @inlog_n; @inlog_n = map{ split( /\s/, $_) } @inlog; pop @inlog for @inlog; for(@inlog_n) { push @logged, $_ if $_=~/\d/ && $_!~/[a-zA-Z]/; } open LOG, ">$outfile"; for(@logged) { print LOG "$_\n" if $_>=1; } close LOG;

        Thanks again for the help!
        C(qw/74 97 104 112/);sub C{while(@_){$c**=$C;print (map{chr($C!=$c?shift:pop)}$_),$C+=@_%2!=1?1:0}}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://665253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-23 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found