blib/lib/Chemistry/File/InChI.pm

filter: Statementstmt 84.0% 21 / 25 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 3 / 3 totaltotal 83.7% 31 / 37 CC 2 SCAR 4.1
CC
2
Cov
85%
read_mol
2.0
name_is
2.0
file_is
2.0
CRAP 1.5
« lib/Chemistry/File/InChI/Parser.yp ↑ Summary blib/lib/Chemistry/File/InChI/Parser.pm »
1 package Chemistry::File::InChI;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use base 'Chemistry::File';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Chemistry::File::InChI::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: InChI identifier reader
11 2 our $VERSION = '0.10'; # VERSION
12  
13 =head1 NAME
14  
15 Chemistry::File::InChI - InChI identifier reader
16  
17 =head1 SYNOPSIS
18  
19 use Chemistry::File::InChI;
20  
21 # read a molecule
22 my $mol = Chemistry::Mol->parse('InChI=1S/H2N2/c1-2/h1-2H', format => 'inchi');
23  
24 =head1 DESCRIPTION
25  
26 InChI identifier reader written according to L<Richard L. Apodaca's InChI grammar|https://github.com/metamolecular/inchi-grammar>.
27 Only formula, C</c>, C</h>, C</t>, C</s> and C</q> layers are supported at the moment.
28 Certain InChI concepts do not map into the concepts of C<Chemistry::Mol>, thus they are stored as molecule and atom attributes.
29  
30 Count multiplier of a molecule is stored in molecule attribute C<inchi/counts>.
31 Stereochemistry setting of C<1> or C<2> is stored in molecule attribute C<inchi/stereochemistry>.
32 Charges are stored in molecule attribute C<inchi/charges>.
33  
34 Tetrahedral center setting C<+> or C<-> is stored in atom attribute C<inchi/chirality>.
35  
36 =cut
37  
38 2 Chemistry::Mol->register_format(inchi => __PACKAGE__);
39  
40 sub read_mol
41 60 ▶{
Subroutine read_mol: called CC=2 SCAR=6.9
Pod documented
42 60 my ($self, $fh, %opts) = @_;
43  
44 60 my $line = <$fh>;
45 60 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 30 30 60
46 30 $line =~ s/\r\n//g;
47  
48 30 my $parser = Chemistry::File::InChI::Parser->new;
49 30 return $parser->parse( $line );
50 }
51  
52 0 ▶sub name_is {
Subroutine name_is: not called CC=1 SCAR=6.9
Pod documented
53 0 my ($self, $fname) = @_;
54 0 $fname =~ /\.inchi$/i;
55 }
56  
57 0 ▶sub file_is {
Subroutine file_is: not called CC=1 SCAR=6.9
Pod documented
58 0 my ($self, $fname) = @_;
59 0 $fname =~ /\.inchi$/i;
60 }
61  
62 =head1 SOURCE CODE REPOSITORY
63  
64 L<https://github.com/perlmol/Chemistry-File-InChI>
65  
66 =head1 SEE ALSO
67  
68 L<Chemistry::Mol>, L<Chemistry::File>
69  
70 InChI grammar L<https://github.com/metamolecular/inchi-grammar>
71  
72 =head1 AUTHOR
73  
74 Andrius Merkys <merkys@cpan.org>
75  
76 =head1 COPYRIGHT
77  
78 Copyright (c) 2022-2026 Andrius Merkys. All rights reserved. This program is
79 free software; you can redistribute it and/or modify it under the same terms as
80 Perl itself.
81  
82 =cut
83  
84 2 1;
« lib/Chemistry/File/InChI/Parser.yp ↑ Summary blib/lib/Chemistry/File/InChI/Parser.pm »