File: sdf.t

package info (click to toggle)
libchemistry-file-mdlmol-perl 0.24-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 352; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,941 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use Test::More tests => 15;
BEGIN { use_ok('Chemistry::File::SDF') };

use strict;
use warnings;

# Read all at once

my @mols = Chemistry::Mol->read("t/sdf/1.sdf");

ok(@mols == 8, "read 8");
my $i;
for my $mol(@mols) {
    $i++ if $mol->isa('Chemistry::Mol');
}

ok($i == @mols, "isa Chemistry::Mol");
is($mols[1]->name, "[2-(4-Bromo-phenoxy)-ethyl]-(4-dimethylamino-6-methoxy-[1,3,5]triazin-2-yl)-cyan", "name");
ok($mols[1]->attr("sdf/data")->{'PKA'} == 4.65, "attr");


# sequential read

my $reader = Chemistry::Mol->file('t/sdf/1.sdf');
isa_ok( $reader, 'Chemistry::File' );

$reader->open;
$reader->read_header;

$reader->skip_mol($reader->fh);
my $mol = $reader->read_mol($reader->fh);
isa_ok( $mol, "Chemistry::Mol" );
is($mol->name, "[2-(4-Bromo-phenoxy)-ethyl]-(4-dimethylamino-6-methoxy-[1,3,5]triazin-2-yl)-cyan", "name");
ok($mol->attr("sdf/data")->{'PKA'} == 4.65, "attr");
$i = 2;
$i++ while ($reader->skip_mol($reader->fh));
is($i, 8, "sequential read 8");


# read/write test

my $fname = "t/sdf/rw.sdf";
open F, "<", "$fname" or die "couldn't open $fname; $!\n";
my $sdf_str;
{ local $/; $sdf_str = <F> }
@mols = Chemistry::Mol->parse($sdf_str, format => 'sdf');
my $sdf_out = Chemistry::Mol->print(format => 'sdf', mols => \@mols);
ok($sdf_str eq $sdf_out, "read-write test");


# test isotopes

my $C13_ISO = 13;
my $C13_atom_block = 12.0107;
my $M_ISO_out = 'M  ISO  1   2  13';
if( eval { require Chemistry::Isotope } ) {
    $C13_ISO = $C13_atom_block = Chemistry::Isotope::isotope_mass(13, 6);
    $M_ISO_out = 'M  ISO  2   2  13   3  13';
}
@mols = Chemistry::Mol->read("t/sdf/C.sdf");
my @atoms = $mols[0]->atoms;
is($atoms[0]->mass, 12.0107);
is($atoms[1]->mass, $C13_ISO);
is($atoms[2]->mass, $C13_atom_block);
my( $M_ISO ) = grep { /^M  ISO/ }
                    split "\n", Chemistry::Mol->print(format => 'sdf',
                                                      mols => \@mols);
is($M_ISO, $M_ISO_out);