chemomer 1.0.1.0 → 1.1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d82770ee66ecaa22f7b9f7dec9c5f76fc9362e10991196334d72b537b9197d4
4
- data.tar.gz: 7a36ce51729d55a8546ccf59ce9eb52f2fec8f31668075e1ba4c983737f459c7
3
+ metadata.gz: f0808ca500149a79e0f978bb5df5e58dd338d96a3a63f1e2aeb10741677c7b39
4
+ data.tar.gz: 78d2ead41d5172404796237da4f651d0c1ae5806aa7df46a45e32737d76d9ead
5
5
  SHA512:
6
- metadata.gz: 12044208b2087b1438200d6c782661e3415779ca51b53e9974310e9a55820112c62d74cca7e64318de688493ea444b5dfe7d03e78fb4d74b7f3c2c3744b09524
7
- data.tar.gz: dff19c9fc4d77ca883a03e98609d073a3a5ba7768513adb020eeeb70405004dae942ca39041def5e9fd1dcbc09b2e64e7eb597a8cda3e3d817d6629281816f36
6
+ metadata.gz: fe0340ea90d149b5abc1589a9b554ed22a153f8a4d5c4c499890e3ce86ed4981cbb0348c760c8952b6afb38b5efb9f89fe28552be81138c8f56a50b0b9a8944f
7
+ data.tar.gz: 5b58960925990cfb04ba8f349af346a6e4416bf6d9fb1abb84c0490e78e166176597658919bcb85c8ecf563f3662d1eb9537b52d76d57984f36f7a472072e527
@@ -9,7 +9,7 @@ env:
9
9
  # Hermetic CI: the engine ref and the oracle corpus ref are pinned,
10
10
  # never floating. Bump these lines deliberately with each engine
11
11
  # ride (the tag carries what changed).
12
- ENGINE_REF: v1.0.1
12
+ ENGINE_REF: v1.1.0
13
13
  CORPUS_REF: v0.3.41
14
14
 
15
15
  jobs:
@@ -12,6 +12,17 @@ module Chemomer
12
12
  # chemomer_string_free releases a string returned by the ABI
13
13
  # chemomer_last_error → the calling thread's last error, or null
14
14
  # chemomer_ffi_version → the ABI version (1)
15
+ #
16
+ # The reaction-identity surface (the engine's RInChI layer, in every
17
+ # engine cdylib that ships it):
18
+ #
19
+ # chemomer_rinchi_from_rxn RXNfile → RInChI string
20
+ # chemomer_rinchi_aux_from_rxn RXNfile → RAuxInfo string
21
+ # chemomer_rinchi_short_key_from_rxn RXNfile → Short-RInChIKey string
22
+ # chemomer_rinchi_long_key_from_rxn RXNfile → Long-RInChIKey string
23
+ # chemomer_rinchi_web_key_from_rxn RXNfile → Web-RInChIKey string
24
+ # chemomer_rinchi_from_rd RDfile → RInChI string
25
+ # chemomer_rinchi_decode (rinchi, rauxinfo) → component table
15
26
  module Bindings
16
27
  module_function
17
28
 
@@ -31,6 +42,14 @@ module Chemomer
31
42
  aux_bindings[names] ||= attach_aux(names)
32
43
  end
33
44
 
45
+ # The reaction-identity surface: attached on first use, same
46
+ # contract as aux — the gem lights up the moment an engine cdylib
47
+ # ships the exports; against a dylib without them, a clear
48
+ # Chemomer::Error explains the gap.
49
+ def rinchi(*names)
50
+ rinchi_bindings[names] ||= attach_rinchi(names)
51
+ end
52
+
34
53
  def bindings
35
54
  @bindings ||= {}
36
55
  end
@@ -39,6 +58,10 @@ module Chemomer
39
58
  @aux_bindings ||= {}
40
59
  end
41
60
 
61
+ def rinchi_bindings
62
+ @rinchi_bindings ||= {}
63
+ end
64
+
42
65
  def attach(names)
43
66
  guard_readable(names)
44
67
  Module.new do
@@ -88,6 +111,39 @@ module Chemomer
88
111
  raise Error, load_failure(e)
89
112
  end
90
113
 
114
+ def attach_rinchi(names)
115
+ guard_readable(names)
116
+ Module.new do
117
+ extend FFI::Library
118
+
119
+ ffi_lib(*names)
120
+ attach_function :chemomer_rinchi_from_rxn, %i[string], :pointer
121
+ attach_function :chemomer_rinchi_aux_from_rxn, %i[string], :pointer
122
+ attach_function :chemomer_rinchi_short_key_from_rxn, %i[string], :pointer
123
+ attach_function :chemomer_rinchi_long_key_from_rxn, %i[string], :pointer
124
+ attach_function :chemomer_rinchi_web_key_from_rxn, %i[string], :pointer
125
+ attach_function :chemomer_rinchi_from_rd, %i[string], :pointer
126
+ attach_function :chemomer_rinchi_decode, %i[string string], :pointer
127
+ # The call path needs the companions too — they exist in every
128
+ # engine ABI version, so attaching them here is version-safe;
129
+ # only the rinchi symbols above are the version-sensitive ones.
130
+ attach_function :chemomer_string_free, %i[pointer], :void
131
+ attach_function :chemomer_last_error, [], :pointer
132
+
133
+ def self.last_error
134
+ pointer = chemomer_last_error
135
+ pointer.null? ? nil : pointer.read_string
136
+ end
137
+ end
138
+ rescue FFI::NotFoundError
139
+ raise Error,
140
+ "chemomer: the cdylib does not export the chemomer_rinchi_* symbols — " \
141
+ "the reaction-identity surface needs an engine that ships the exports " \
142
+ "(github.com/chemomer/chemomer, src/ffi.rs)"
143
+ rescue LoadError => e
144
+ raise Error, load_failure(e)
145
+ end
146
+
91
147
  # An explicit CHEMOMER_LIB path is one candidate; a missing or
92
148
  # unreadable file deserves the direct message rather than the
93
149
  # loader's. The default soname list is searched by the loader
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chemomer
4
+ # The reaction-identity layer's decode result, parsed out of the C
5
+ # ABI's component-table wire form — the string the
6
+ # chemomer_rinchi_decode export returns (see
7
+ # RinchiReaction::component_table in the engine's src/rinchi.rs):
8
+ #
9
+ # <flag> '+' directional, '=' equilibrium
10
+ # <inchi><TAB><aux><TAB><inchikey> one line per reactant
11
+ # <> role separator (bare)
12
+ # ...
13
+ #
14
+ # InChI, AuxInfo, and InChIKey strings carry no tab and no newline,
15
+ # so the table splits unambiguously: the first line is the flag, the
16
+ # bare `<>` lines separate the three roles, every other line is one
17
+ # component's identity triple. The roles are already resolved (a
18
+ # backward-flag identifier arrives decoded into its real roles), so
19
+ # the flag line reads `+` or `=` only.
20
+ module Rinchi
21
+ DIRECTIONALITY = {
22
+ "+" => "directional",
23
+ "=" => "equilibrium"
24
+ }.freeze
25
+
26
+ module_function
27
+
28
+ # Parses the component table into the decoded reaction:
29
+ #
30
+ # { "directionality" => "directional",
31
+ # "reactants" => [{ "inchi" => ..., "aux" => ..., "inchikey" => ... }, ...],
32
+ # "products" => [...], "agents" => [...] }
33
+ def decode_table(table)
34
+ lines = table.split("\n")
35
+ lines.pop if lines.last && lines.last.empty?
36
+ flag = lines.shift
37
+ directionality = DIRECTIONALITY.fetch(flag) do
38
+ raise Error, "chemomer: unknown direction flag #{flag.inspect} in the component table"
39
+ end
40
+
41
+ roles = { "reactants" => [], "products" => [], "agents" => [] }
42
+ keys = roles.keys
43
+ index = 0
44
+ lines.each do |line|
45
+ if line == "<>"
46
+ index += 1
47
+ next
48
+ end
49
+ key = keys[index] or raise Error, "chemomer: too many role separators in the component table"
50
+ inchi, aux, inchikey = line.split("\t", -1)
51
+ unless inchikey
52
+ raise Error, "chemomer: malformed component line #{line.inspect} in the component table"
53
+ end
54
+ roles[key] << { "inchi" => inchi, "aux" => aux, "inchikey" => inchikey }
55
+ end
56
+
57
+ { "directionality" => directionality }.merge(roles)
58
+ end
59
+ end
60
+ end
@@ -5,5 +5,5 @@ module Chemomer
5
5
  # chemomer-py): the chemomer engine release this gem wraps (0.1.0)
6
6
  # plus the gem's own runtime counter (1). An engine bump resets the
7
7
  # counter (0.2.0.1); a runtime-only fix increments it (0.1.0.2).
8
- VERSION = "1.0.1.0"
8
+ VERSION = "1.1.0.0"
9
9
  end
data/lib/chemomer.rb CHANGED
@@ -13,11 +13,15 @@ require "rbconfig"
13
13
  #
14
14
  # Chemomer.from_molfile(molfile) # => [inchi, inchikey]
15
15
  # Chemomer.aux_from_molfile(molfile) # => aux line
16
+ # Chemomer.rinchi_from_rxn(rxnfile) # => [rinchi, rauxinfo, short, long, web]
17
+ # Chemomer.rinchi_from_rd(rdfile) # => rinchi line
18
+ # Chemomer.rinchi_decode(rinchi, rauxinfo) # => decoded reaction hash
16
19
  # Chemomer.ffi_version # => 1
17
20
  module Chemomer
18
21
  autoload :VERSION, "chemomer/version"
19
22
  autoload :Bindings, "chemomer/bindings"
20
23
  autoload :Error, "chemomer/error"
24
+ autoload :Rinchi, "chemomer/rinchi"
21
25
 
22
26
  # Fallback sonames tried in order when CHEMOMER_LIB is unset; the
23
27
  # OS loader resolves them from its search path (LD_LIBRARY_PATH /
@@ -43,8 +47,8 @@ module Chemomer
43
47
  # # => ["InChI=1S/H2O/h1H2", "XLYOFNOQVPJJNP-UHFFFAOYSA-N"]
44
48
  def from_molfile(molfile)
45
49
  bindings = Bindings.for(*lib)
46
- inchi = call(bindings, molfile, :chemomer_from_molfile)
47
- inchikey = call(bindings, molfile, :chemomer_inchikey)
50
+ inchi = call(bindings, :chemomer_from_molfile, molfile)
51
+ inchikey = call(bindings, :chemomer_inchikey, molfile)
48
52
  [inchi, inchikey]
49
53
  end
50
54
 
@@ -54,7 +58,47 @@ module Chemomer
54
58
  # ships it.
55
59
  def aux_from_molfile(molfile)
56
60
  bindings = Bindings.aux(*lib)
57
- call(bindings, molfile, :chemomer_aux_from_molfile)
61
+ call(bindings, :chemomer_aux_from_molfile, molfile)
62
+ end
63
+
64
+ # RXNfile → the reaction-identity five lines: [RInChI, RAuxInfo,
65
+ # Short-RInChIKey, Long-RInChIKey, Web-RInChIKey] (engine-verbatim,
66
+ # key headers included). Needs the chemomer_rinchi_* exports —
67
+ # attached on first use, so they light up the moment an engine
68
+ # cdylib ships them.
69
+ #
70
+ # Chemomer.rinchi_from_rxn(rxnfile)
71
+ # # => ["RInChI=1.00.1S/H2O/h1H2<>H2O/h1H2/d+",
72
+ # # "RAuxInfo=1.00.1/...",
73
+ # # "Short-RInChIKey=SA-FUHFF-...",
74
+ # # "Long-RInChIKey=SA-FUHFF-...",
75
+ # # "Web-RInChIKey=XLYOFNOQVPJJNPIXP-NUHFFFADPSCTJSA"]
76
+ def rinchi_from_rxn(rxnfile)
77
+ bindings = Bindings.rinchi(*lib)
78
+ [
79
+ call(bindings, :chemomer_rinchi_from_rxn, rxnfile),
80
+ call(bindings, :chemomer_rinchi_aux_from_rxn, rxnfile),
81
+ call(bindings, :chemomer_rinchi_short_key_from_rxn, rxnfile),
82
+ call(bindings, :chemomer_rinchi_long_key_from_rxn, rxnfile),
83
+ call(bindings, :chemomer_rinchi_web_key_from_rxn, rxnfile)
84
+ ]
85
+ end
86
+
87
+ # RDfile → the RInChI identifier line (the `$DATUM $MFMT` agent-scan
88
+ # input edge; the other four lines ride the RXN exports' assembly).
89
+ def rinchi_from_rd(rdfile)
90
+ bindings = Bindings.rinchi(*lib)
91
+ call(bindings, :chemomer_rinchi_from_rd, rdfile)
92
+ end
93
+
94
+ # RInChI (+ RAuxInfo companion, empty when unknown) → the decoded
95
+ # reaction: { "directionality" => "directional"|"equilibrium",
96
+ # "reactants"|"products"|"agents" => [{"inchi" =>, "aux" =>,
97
+ # "inchikey" =>}, ...] }. No structures are rebuilt — the components
98
+ # carry their identities straight from the string.
99
+ def rinchi_decode(rinchi, rauxinfo = "")
100
+ bindings = Bindings.rinchi(*lib)
101
+ Rinchi.decode_table(call(bindings, :chemomer_rinchi_decode, rinchi, rauxinfo))
58
102
  end
59
103
 
60
104
  # The C ABI version of the attached cdylib (1 today).
@@ -65,8 +109,8 @@ module Chemomer
65
109
  # The C ABI contract: null return on error (the message sits on the
66
110
  # calling thread's last_error slot), the returned string freed right
67
111
  # after reading it.
68
- def call(bindings, molfile, function)
69
- pointer = bindings.public_send(function, molfile)
112
+ def call(bindings, function, *arguments)
113
+ pointer = bindings.public_send(function, *arguments)
70
114
  # A null return arrives as a non-nil FFI::Pointer whose address is
71
115
  # 0 — the truthiness test would sail past it, so null? is the
72
116
  # guard.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chemomer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.0
4
+ version: 1.1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -44,6 +44,7 @@ files:
44
44
  - lib/chemomer.rb
45
45
  - lib/chemomer/bindings.rb
46
46
  - lib/chemomer/error.rb
47
+ - lib/chemomer/rinchi.rb
47
48
  - lib/chemomer/version.rb
48
49
  homepage: https://github.com/chemomer/chemomer-ruby
49
50
  licenses: