asciichem 1.2.16.1 → 1.2.16.2

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: da480d371edab3ef3dd767137a9334a80f53205f6d654fb6388d6f3d945aeec7
4
- data.tar.gz: 336c0c6166e6f6e2774cd1720b903dad52cec2f71e9f10bd21abae19942b3e88
3
+ metadata.gz: 6534f58f77de9f78e8d37bdd2bfe51db24520a2c9982ad0a472a3a28dfacf2fe
4
+ data.tar.gz: da8015482d975d9a320321a4fdea64fd99e1dd24e003b00262adba301b67309b
5
5
  SHA512:
6
- metadata.gz: 18beb1e3590bb16689fd0e4c7b21e8f7b443813485d50ba8cf31dd44295c0fca002044a7d56a387b3efe7f9693c4b0cf5ee467890095f169f1bf7892636467cd
7
- data.tar.gz: 04a3b62ed4ece2bf0d528b439028bb8aa4cf4f8e0ec5ee9e3aa96a6fd687d7f6f58265bc104a00344047a42cec6a41282422c21885c53d21918164401afb71a3
6
+ metadata.gz: 75736b6a32c392bb17cb1bae45889b5cf0f510453018a7b6acc8569a4f6e9ca7e690925861f439f5f082cbac37b94868c72b656aeb971b166b1010f6ef184f13
7
+ data.tar.gz: 0c79f4134f1f9f2b3bcc64a0b155260415b64a0613588670689ff701dff9c944f0780a20a343916807499ab0a290135a10f8717152d8f54c9b7e6f12bd21ca5b
@@ -9,7 +9,7 @@ env:
9
9
  # Hermetic CI: the corpus ref is pinned, never floating. Bump this
10
10
  # one line deliberately with each corpus release (the tag carries
11
11
  # what changed).
12
- CORPUS_REF: v0.24.0
12
+ CORPUS_REF: v0.30.0
13
13
 
14
14
  jobs:
15
15
  test:
data/asciichem.gemspec CHANGED
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency "moxml", "~> 0.6.1"
43
43
  spec.add_dependency "parsanol", "~> 1.5.0", ">= 1.5.3.1"
44
44
  spec.add_dependency "relaton-bib", "~> 2.1"
45
- spec.add_dependency "plurimath", "~> 0.11"
45
+ spec.add_dependency "plurimath", "~> 0.12"
46
46
  spec.add_dependency "thor", "~> 1.3"
47
47
 
48
48
  spec.add_development_dependency "json_schemer", "~> 2.4"
@@ -52,14 +52,54 @@ module AsciiChem
52
52
  # numbers only: a fractional remainder means the Hückel arithmetic
53
53
  # cannot decide (fused aromatic-schematic atoms), and perception
54
54
  # declines rather than invents.
55
- def hydrogen_valence_sum(atom_index, edges)
55
+ #
56
+ # When a detected aromatic five-membered ring is supplied, its
57
+ # lone-pair donation donor counts its ring bonds as the kekulized
58
+ # singles the donation model implies (pyrrole N: two singles + one
59
+ # H = valence 3 → one implicit hydrogen; furan O: two singles =
60
+ # valence 2 → none) — the blanket 1.5 sum over-values a donor
61
+ # (3.0 against valence 2 or 3) and would decline exactly the
62
+ # heteroatoms the donation rule exists to answer.
63
+ def hydrogen_valence_sum(atom_index, edges, ring = nil, atoms = nil)
64
+ donor = ring && atoms && donation_donor?(atoms[atom_index], atoms, atom_index, edges, ring)
56
65
  edges.sum do |edge|
57
66
  next 0 unless edge.from == atom_index || edge.to == atom_index
58
67
 
59
- edge.kind == :aromatic ? 1.5 : BOND_ORDER.fetch(edge.kind, 1)
68
+ if edge.kind == :aromatic
69
+ donor ? 1.0 : 1.5
70
+ else
71
+ BOND_ORDER.fetch(edge.kind, 1)
72
+ end
60
73
  end
61
74
  end
62
75
 
76
+ # The donation donor of an aromatic five-membered ring: a
77
+ # lone-pair-donating element with no in-system double bond of its
78
+ # own (its 2π come from the lone pair), uncharged, with no stated
79
+ # hydrogens (a stated count is the source's word — never
80
+ # re-derived), and **unique among nitrogens** — the donation is
81
+ # one lone pair per ring, so a plain `n` beside another donor
82
+ # element (imidazole's `n` beside an `[nH]`, oxazole's `n` beside
83
+ # the `o`) is pyridine-type: it keeps the blanket Hückel sum and
84
+ # answers zero. O and S are the preferred donors and do not defer
85
+ # (oxazole's `o` stays the donor beside its `n`).
86
+ def donation_donor?(atom, atoms, atom_index, edges, ring)
87
+ return false unless ring.length == 5
88
+ return false unless ring.include?(atom_index)
89
+ return false if atom.charge || atom.hydrogens
90
+ return false unless LONE_PAIR_DONORS.include?(atom.element)
91
+ return false if in_system_double?(atom_index, edges, ring)
92
+ if atom.element == 'N'
93
+ return false if ring.any? do |other_index|
94
+ next false if other_index == atom_index
95
+
96
+ LONE_PAIR_DONORS.include?(atoms[other_index].element)
97
+ end
98
+ end
99
+
100
+ true
101
+ end
102
+
63
103
  # Implicit hydrogens for an atom: the smallest default valence
64
104
  # that the hydrogen-valence sum fits, minus that sum. The sum must
65
105
  # come from #hydrogen_valence_sum (aromatic-aware).
@@ -93,7 +93,7 @@ module AsciiChem
93
93
 
94
94
  @perceived_hydrogens[index] = AsciiChem::Perception.implicit_hydrogens(
95
95
  atoms[index],
96
- AsciiChem::Perception.hydrogen_valence_sum(index, edges)
96
+ AsciiChem::Perception.hydrogen_valence_sum(index, edges, ring, atoms)
97
97
  )
98
98
  end
99
99
  ring.each_with_index do |atom, i|
@@ -105,10 +105,11 @@ module AsciiChem
105
105
 
106
106
  # Hydrogens the written token must state: the source's own count
107
107
  # wins; otherwise only a ring PERCEIVED from Kekulé bond orders
108
- # gets perception's implicit count. A source-aromatic atom
109
- # already states its hydrogens the way SMILES does (`[nH]`), and
110
- # aromatic 1.5 bond orders do not map onto heteroatom valences
111
- # (thiophene's S would otherwise acquire a phantom H).
108
+ # gets perception's implicit count. Source-aromatic heteroatoms
109
+ # need no stated H in the token: the donation-donor rule
110
+ # (perception.rb) re-derives the count deterministically on the
111
+ # next read — pyrrole round-trips as `c1ccnc1` and still
112
+ # perceives its N hydrogen.
112
113
  def writing_hydrogens(index)
113
114
  stated = @atoms[index].hydrogens
114
115
  return stated unless stated.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsciiChem
4
- VERSION = "1.2.16.1"
4
+ VERSION = "1.2.16.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciichem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.16.1
4
+ version: 1.2.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -119,14 +119,14 @@ dependencies:
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '0.11'
122
+ version: '0.12'
123
123
  type: :runtime
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '0.11'
129
+ version: '0.12'
130
130
  - !ruby/object:Gem::Dependency
131
131
  name: thor
132
132
  requirement: !ruby/object:Gem::Requirement