<commit_before>#!/usr/bin/env perl 

use strict; 
use warnings; 

use Getopt::Long; 
use Pod::Usage; 

use Math::Linalg qw(length); 
use VASP qw(read_force); 

my @usages = qw(NAME SYSNOPSIS OPTIONS); 

# POD 
=head1 NAME 
 
wtf.pl: what the (Hellmann-Feynman) forces (VASP 5) 

=head1 SYNOPSIS

vforce.pl [-h] [-s]

=head1 OPTIONS

=over 8 

=item B<-h> 

Print the help message and exit.

=item B<-n> 

Number of column in force table 

=back 

=cut

# default optional arguments 
my $help = 0; 
my $ncol = 5; 

GetOptions(
    'h'   => \$help, 
    'n=i' => \$ncol,
) or pod2usage(-verbose => 1); 

# help message 
if ($help) { pod2usage(-verbose => 99, -section => \@usages) }

# collect forces 
my @forces = read_force('OUTCAR');

# table format
my $nrow = @forces % $ncol ? int(@forces/$ncol)+1 : @forces/$ncol; 

# sort force indices based on modulus 
my @indices = sort { $a % $nrow <=> $b % $nrow } 0..$#forces; 

# print forces
my $digit   = length(scalar(@forces)); 

for my $i (0..$#indices) { 
    printf "%${digit}d: f = %.2e    ", $indices[$i]+1, $forces[$indices[$i]]; 
    
    # the last of us 
    if ($i == $#indices) { last  }  
    
    # break new line due to index wrap around
    if ($indices[$i] > $indices[$i+1] or $ncol == 1) { print "\n" }  
}

# trailing newline <commit_msg>Allow wtf.pl to read forces from input<commit_after>#!/usr/bin/env perl 

use strict; 
use warnings; 

use Getopt::Long; 
use Pod::Usage; 

use Math::Linalg qw(length); 
use VASP qw(read_force); 

my @usages = qw(NAME SYSNOPSIS OPTIONS); 

# POD 
=head1 NAME 
 
wtf.pl: what the (Hellmann-Feynman) forces (VASP 5) 

=head1 SYNOPSIS

wtf.pl [-h] [-s]

=head1 OPTIONS

=over 8 

=item B<-h> 

Print the help message and exit.

=item B<-n> 

Number of column in force table 

=item B<-i>

Input file (default: OUTCAR) 

=back 

=cut

# default optional arguments 
my $help = 0; 
my $ncol = 5; 
my $input = 'OUTCAR'; 

GetOptions(
    'h'   => \$help, 
    'n=i' => \$ncol,
    'i=s' => \$input,
) or pod2usage(-verbose => 1); 

# help message 
if ($help) { pod2usage(-verbose => 99, -section => \@usages) }

# collect forces 
my @forces = read_force($input);

# table format
my $nrow = @forces % $ncol ? int(@forces/$ncol)+1 : @forces/$ncol; 

# sort force indices based on modulus 
my @indices = sort { $a % $nrow <=> $b % $nrow } 0..$#forces; 

# print forces
my $digit   = length(scalar(@forces)); 

for my $i (0..$#indices) { 
    printf "%${digit}d: f = %.2e    ", $indices[$i]+1, $forces[$indices[$i]]; 
    
    # the last of us 
    if ($i == $#indices) { last  }  
    
    # break new line due to index wrap around
    if ($indices[$i] > $indices[$i+1] or $ncol == 1) { print "\n" }  
}

# trailing newline 
{'fraction_non_alphanumeric': 0.17359323280617875, 'fraction_numerical': 0.013975726369988967, 'mean_word_length': 2.9824304538799415, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2377964', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1066, 'n_words': 319}