Perl



Features & Limitations

There are two different Perl wrappers for Daylight software.
DayPerl
  • Written by Alex Wong. Maintained and improved by Roger Critchlow, Jeremy Yang, Margaret Kamphorst and Jack Delany.
  • Doesn't require DaySWIG or SWIG.
  • The numerous example programs include applications programs, utilities and CGIs.
  • Recent improvements have made installation reasonably straight forward and reliable.
  • The wrapper and programs are widely used and very well-tested.
  • DayPerl is thin and not highly "Perl-like":
    • Illegal syntax: constants are implemented using functions (e.g. NULL_OB), not scalars, precluding the use of "use strict" for debugging.
    • Single return values (not multiple).
    • The "invalid string" (analogous to NULL in C) is awkwardly handled using the "KLUDGE_INVALID_STRING" pseudo-constant rather than "undef" (e.g. dt_alloc_string("KLUDGE_INVLID_STRING") ).
    • No garbage collection ( dt_dealloc() required to free memory) .
    • Manual error checking.
  • Uses null-terminated scalars (SvPV); length needn't be passed to functions (e.g. dt_smilin("OCC")).
  • No drawing library (stubs only).
DayPerl2
  • Written by Craig James.
  • Requires SWIG.
  • Includes several example programs.
  • Is complicated to install (at least on non-Linux Operating Systems).
  • Has many dependancies: SWIG, freetype, gnumake (required for freetype).
  • Not well-tested by Daylight
  • DayPerl2 is somewhat more "Perl-like":
    • Constants are properly implemented as scalar variables (e.g. $NULL_OB ), allowing the use of "use strict" for debugging.
    • Multiple return values are used (e.g. ($ok,$status) = dt_continue($server) ).
    • The "invalid string" is handled in the expected way, using "undef" (e.g. dt_alloc_string(undef)).
    • Uses null-terminated scalars (SvPV); length needn't be passed to functions (e.g. dt_smilin("OCC")).
  • No garbage collection ( dt_dealloc() required to free memory) .
  • Manual error checking.
  • Includes a PNG drawing library.

Download & Installation

DayPerl Acquire the dayperl-491.tar.gz or dayperl-481.tar.gz archive.
% gzip -dc dayperl-491.tar.gz | tar xf -
% cd dayperl-491/
% more _readme
% perl parse_perlv.pl
% make
% su root
    # make install
% make test
DayPerl2 Acquire the dayperl2.tar.gz archive.
% gzip -dc dayperl2.tar.gz | tar xf -
% more README
% cd dayperl2/swig
% gzip -dc swig-1.3.9.tar.gz | tar xf -
% cd SWIG-1.3.19
% ./configure
% make
% su root
    # make install
% cd ../../libgd
% ./Build.sh
% cd ../DayPerl2
% cp makefile.linux makefile
% vi makefile
<verify SWIG location> % make
% su root
    # make install

Example Code Compilation & Execution

DayPerl
cansmi.pl
#!/usr/bin/env perl

use DayPerl;

my ( $mol, $smiles, $cansmi);
 while ($smiles = <STDIN>) {
   chomp $smiles;
   if (NULL_OB == ($mol = dt_smilin($smiles))) {
     print STDERR "ERROR: (dt_smilin) Can't parse SMILES \"$_\"\n";
   } else {
     $cansmi = dt_cansmiles($mol, 1);
     if (!$cansmi) {
       print STDERR "ERROR: (dt_cansmi) \"$_\"\n";
     } else {
       print $cansmi, "\n";
     }
   } 
   dt_dealloc($mol);
 }
exit 0
% echo "OCC" | perl cansmi.pl
CCO 
DayPerl2
cansmi.pl
#!/usr/bin/env perl

use strict;
use DayPerl2;

my ( $mol, $smiles, $cansmi);
 while ($smiles = <STDIN>) {
   chomp $smiles;
   if ($NULL_OB == ($mol = dt_smilin($smiles))) {
     print STDERR "ERROR: (dt_smilin) Can't parse SMILES \"$_\"\n";
   } else {
     if (!$cansmi) {
       print STDERR "ERROR: (dt_cansmi) \"$_\"\n";
     } else {
       print $cansmi, "\n";
     }
   } 
   dt_dealloc($mol);
 }
exit 0
% echo "OCC" | perl cansmi.pl
CCO