Subject: [bug#58261] [PATCH v3 13/15] gnu: Add avalon-toolkit.

From: David Elsing <[email-masked]>
Date: Thu, 13 Oct 2022 21:04:22 +0000

* gnu/packages/chemistry.scm (avalon-toolkit): New variable.
---
 gnu/packages/chemistry.scm | 96 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/gnu/packages/chemistry.scm b/gnu/packages/chemistry.scm
index a1c1dbfa1b..82bc3ae29e 100644
--- a/gnu/packages/chemistry.scm
+++ b/gnu/packages/chemistry.scm
@@ -926,3 +926,99 @@ (define-public yaehmop
 Orbital Package} contains a program and library for performing extended Hückel
 calculations and analyzing the results.")
     (license license:bsd-2)))
+
+(define-public avalon-toolkit
+  (package
+    (name "avalon-toolkit")
+    (version "1.2.0")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append
+             "mirror://sourceforge/avalontoolkit/"
+             "AvalonToolkit_" (substring version 0 3) "/AvalonToolkit_"
+             version ".source.tar"))
+       (sha256
+        (base32
+         "0rnnyy6axs2da7aa4q6l30ldavbk49v6l22llj1adn74h1i67bpv"))
+       (modules '((guix build utils) (ice-9 ftw)))
+       (snippet
+        #~(begin
+            (delete-file-recursively "../SourceDistribution/java")))))
+    (build-system gnu-build-system)
+    (arguments
+     (list
+      ;; There are no intended tests
+      #:tests? #f
+      #:phases
+      #~(let ((programs '("canonizer" "matchtest" "sketch" "smi2mol" "struchk")))
+          (modify-phases %standard-phases
+            (delete 'configure)
+            (add-before 'build 'remove-free
+              (lambda _
+                ;; Remove incorrect free of getenv result (patch also in rdkit)
+                (substitute* "common/reaccsio.c"
+                  (("MyFree.*tempdir.*") ""))))
+            ;; The makefile has incorrect compiler flags and is missing some
+            ;; object files, so we build it ourselves.
+            (replace 'build
+              (lambda _
+                (chdir "common")
+                (let* ((parts
+                        (list
+                         "aacheck" "casutils" "denormal" "depictutil" "didepict"
+                         "fixcharges" "forio" "geometry" "graph" "hashcode"
+                         "layout" "local" "pattern" "perceive" "reaccsio"
+                         "rtutils" "set" "shortcut" "sketch" "ssmatch" "stereo"
+                         "symbol_lists" "symboltable" "utilities"))
+                       (objects (map (lambda (name) (string-append name ".o"))
+                                     parts)))
+                  (for-each
+                   (lambda (name)
+                     (display (string-append "Compiling " name ".c\n"))
+                     (invoke "gcc" "-c" "-fPIC" "-O2"
+                             (string-append name ".c")
+                             "-o" (string-append name ".o")))
+                   parts)
+                  (display "Building shared library\n")
+                  (apply invoke "gcc" "-fPIC" "-shared" "-lm"
+                         "-o" "libavalontoolkit.so" "canonizer.c" "smi2mol.c"
+                         "struchk.c" "patclean.c" objects)
+                  ;; patclean is not built here as there is an undeclared
+                  ;; variable in main().
+                  (for-each
+                   (lambda (program)
+                     (display (string-append "Building " program "\n"))
+                     (invoke "gcc" "-L." "-lavalontoolkit" "-lm" "-O2"
+                             (string-append "-Wl,-rpath=" #$output "/lib")
+                             "-DMAIN" (string-append program ".c") "-o" program))
+                   programs))))
+            (replace 'install
+              (lambda _
+                ;; Executables
+                (for-each
+                 (lambda (program)
+                   (install-file program (string-append #$output "/bin")))
+                 programs)
+                (for-each
+                 (lambda (name)
+                   (symlink (string-append #$output "/bin/smi2mol")
+                            (string-append #$output "/bin/" name)))
+                 '("mol2smi" "rdf2smi" "mol2tbl" "mol2sma" "smi2rdf"))
+                ;; Library
+                (install-file "libavalontoolkit.so"
+                              (string-append #$output "/lib"))
+                (for-each
+                 (lambda (file)
+                   (install-file file (string-append #$output
+                                                    "/include/avalontoolkit")))
+                 (find-files "." "\\.h$"))
+                (install-file "../license.txt"
+                              (string-append #$output "/share/doc/"
+                                             #$name "-" #$version "/"))))))))
+    (home-page "https://sourceforge.net/projects/avalontoolkit/")
+    (synopsis "Tools for SMILES and MOL files and for structure fingerprinting")
+    (description "This package contains a library and programs for
+canonicalization of SMILES and MOL files, molecular structure fingerprinting
+and rendering molecules.")
+    (license license:bsd-3)))
-- 
2.37.0