chemparseplot 1.13.0__py3-none-any.whl → 1.13.2__py3-none-any.whl

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.
_version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '1.13.0'
22
- __version_tuple__ = version_tuple = (1, 13, 0)
21
+ __version__ = version = '1.13.2'
22
+ __version_tuple__ = version_tuple = (1, 13, 2)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -89,12 +89,18 @@ def changed_bonds(reactant, product, limit=3):
89
89
  return [(i, j) for _, i, j in sorted(pairs, reverse=True)[:limit]]
90
90
 
91
91
 
92
- def apply_wbo_style(molecule, bond_orders, *, minimum=0.1, weak=0.5, vmax=3.0):
92
+ def apply_wbo_style(
93
+ molecule, bond_orders, *, minimum=0.1, weak=0.5, vmax=3.0, max_contact=2.5
94
+ ):
93
95
  """Replace geometric connectivity with measured Wiberg bond orders.
94
96
 
95
97
  Atom numbering follows the source file. Dotted edges encode WBO below
96
98
  ``weak``; colour and width use a common scale across all structures.
99
+ A pair farther apart than ``max_contact`` times its covalent-radius sum
100
+ gets no edge: a closed-shell density at a near-degenerate geometry can
101
+ assign bond order to separated radical centres, which is not a bond.
97
102
  """
103
+ from ase.data import covalent_radii # noqa: PLC0415
98
104
  from matplotlib import colormaps # noqa: PLC0415
99
105
  from matplotlib.colors import to_hex # noqa: PLC0415
100
106
 
@@ -117,6 +123,13 @@ def apply_wbo_style(molecule, bond_orders, *, minimum=0.1, weak=0.5, vmax=3.0):
117
123
  for (i, j), value in bond_orders.items():
118
124
  if value < minimum:
119
125
  continue
126
+ a, b = graph.nodes[nodes[i - 1]], graph.nodes[nodes[j - 1]]
127
+ if "position" in a and "position" in b:
128
+ reach = max_contact * (
129
+ covalent_radii[a["atomic_number"]] + covalent_radii[b["atomic_number"]]
130
+ )
131
+ if np.linalg.norm(np.subtract(a["position"], b["position"])) > reach:
132
+ continue
120
133
  graph.add_edge(
121
134
  nodes[i - 1],
122
135
  nodes[j - 1],
@@ -182,13 +195,18 @@ def plot_reaction_atlas(cases, *, density=False, width=7.2):
182
195
 
183
196
  from chemparseplot.plot.neb import _crop_transparent_rgba # noqa: PLC0415
184
197
 
185
- row_height = 2.65
186
- height = row_height * len(cases) + 0.7
198
+ line_height = 0.13
199
+ row_heights = [
200
+ 2.4 + line_height * max(len(s["bonds"]) for s in case["states"]) for case in cases
201
+ ]
202
+ margin = 0.75
203
+ height = sum(row_heights) + margin
187
204
  fig = plt.figure(figsize=(width, height))
188
205
  left, right, gap = 0.025, 0.985, 0.02
189
206
  column_width = (right - left - 3 * gap) / 4
207
+ offsets = np.concatenate([[0.0], np.cumsum(row_heights)[:-1]])
190
208
  for row, case in enumerate(cases):
191
- top = 1 - (0.08 + row * row_height) / height
209
+ top = 1 - (0.08 + offsets[row]) / height
192
210
  fig.text(
193
211
  left,
194
212
  top,
@@ -236,7 +254,7 @@ def plot_reaction_atlas(cases, *, density=False, width=7.2):
236
254
  from matplotlib.cm import ScalarMappable # noqa: PLC0415
237
255
  from matplotlib.colors import Normalize # noqa: PLC0415
238
256
 
239
- cax = fig.add_axes([0.30, 0.065, 0.40, 0.025])
257
+ cax = fig.add_axes([0.30, 0.3 / height, 0.40, 0.12 / height])
240
258
  cbar = fig.colorbar(
241
259
  ScalarMappable(norm=Normalize(0, 3), cmap="viridis"),
242
260
  cax=cax,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: chemparseplot
3
- Version: 1.13.0
3
+ Version: 1.13.2
4
4
  Summary: Parsers and plotting tools for computational chemistry
5
5
  Project-URL: Documentation, https://chemparseplot.rgoswami.me
6
6
  Project-URL: Issues, https://github.com/HaoZeke/chemparseplot/issues
@@ -1,4 +1,4 @@
1
- _version.py,sha256=PztwlbaFJ2teB-Wz7qziMyzjSLljNFc1D6_B0UWBtcU,522
1
+ _version.py,sha256=2Cr_dqkSDP62wnSopFyLr49JJJmZ3fep3K8gp7qTWlk,522
2
2
  chemparseplot/__init__.py,sha256=8M1TQDLxtr2EvjQbG6EiIyiIu149VwGMBdLfoL1LsDc,890
3
3
  chemparseplot/api.py,sha256=vQz2CCbxdwV0BBmHs4hH-HK4y0T-MwBFMoKwaW2NUYU,4942
4
4
  chemparseplot/units.py,sha256=oWRy5OnGH4bAELtlzrAwxZQvliFDCWOtInj_itpC2rc,3688
@@ -60,7 +60,7 @@ chemparseplot/plot/neb.py,sha256=lD9UOA45IeF-DVoalzgfKOfF5YZNX_hjmM9Hvdu62KE,722
60
60
  chemparseplot/plot/optimization.py,sha256=yOLCXz-nw4Jj1O8C2u7szf2EJhiwk8mWGaE0h6V_LDk,24195
61
61
  chemparseplot/plot/plumed.py,sha256=lp3rNeZjwfDbYF92RkVc75sfhF_cFIeD2PyUBIKvB7Y,3943
62
62
  chemparseplot/plot/provenance.py,sha256=5RVEEKQzSssYIuLyezPFcr-TZwlP8gwzZ89Iu_wC_C8,3626
63
- chemparseplot/plot/reaction.py,sha256=q7YrIoYPmaS3haoJHTMFV3371b2Cxl86BhfBxP48CTA,11260
63
+ chemparseplot/plot/reaction.py,sha256=MwvJtSeFa2wIyjPSnjx3vyjH0KrvT_F7oj0yRdAI5hM,12135
64
64
  chemparseplot/plot/rings.py,sha256=XBfsTOlZ8eSZYtqnXwM-XIlxWejLWC2brHr9sF0Stio,32658
65
65
  chemparseplot/plot/structs.py,sha256=0CfxamdciGg6fcru7jL_6hLwM2hAMk-cRmK6E7UXaY8,6466
66
66
  chemparseplot/plot/surrogate.py,sha256=i-bbR7x_8xsW2cgqo9GZ_D8e5i7ZPIwp2UMjFH9QiUQ,98030
@@ -145,7 +145,7 @@ tests/plot/test_orca_neb_payload.py,sha256=Z6as2snM2fvW1n6HcjL9anj9jVh4baU2jZGxx
145
145
  tests/plot/test_primitive_rings.py,sha256=MTCkY7yOlKawJAmB3uQe8ufIVehcxMjJIyk_iLW00GM,3568
146
146
  tests/plot/test_projection_refactor.py,sha256=O0iydKG4qfVfIv7cLsTYkZOjKLOZrlGCkIe7yVJ7QJw,4954
147
147
  tests/plot/test_provenance.py,sha256=yl-W_V4-3WQWfrWw9HOySvXTi2liHFTnJncxEq55aGg,1853
148
- tests/plot/test_reaction.py,sha256=ADXNOyJ3EwpeW8PNNa_bfdgo_4macIP8bfDHE54zbk0,3830
148
+ tests/plot/test_reaction.py,sha256=YKnhMqAveQ0VYBPVAqmNhv_X4HmTWdXxMlT9m0-EWOw,5834
149
149
  tests/plot/test_ring_track.py,sha256=TVQZU2b5ESeFwJEyGbbysBXKl-F1evkSRkxueBGQYg8,7066
150
150
  tests/plot/test_ring_updater.py,sha256=bUufHVfXhixqMgw1p7F0V9FiecxWLnTxndGWaTj5_yo,930
151
151
  tests/plot/test_strip_rendering.py,sha256=wgqoCQR6MVQ0y4Dq2QATTVgIf-Ilizriavk5TfWwiYA,8495
@@ -154,7 +154,7 @@ tests/plot/test_surface_auto_thin.py,sha256=-hteZRi3sK5CAZp0rvZnFSunV_AnP8AdiGHq
154
154
  tests/plot/test_surrogate_plots.py,sha256=XeqV3KLu6fVgfCAMGdFRRMvzyaPSWAVYfG3QkduPZyA,39356
155
155
  tests/plot/data/sexithiophene.sdf,sha256=MlX6h2eeaXTOXm9iSoienT8qS2xvcR4B-iYK6jAAnEI,8335
156
156
  tests/tutorials/test_chemparseplot.py,sha256=RDZcMRrg5yPHguNZIdOAdaG0GuVLO73rXjjuNSef7K0,3550
157
- chemparseplot-1.13.0.dist-info/METADATA,sha256=Zh8PPf6DNit5IInDiCMmmo5VGCky4q1qcMQ6nx15B-E,9841
158
- chemparseplot-1.13.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
159
- chemparseplot-1.13.0.dist-info/licenses/LICENSE,sha256=WpBevJdirrfildX-iO61fdIm4hJ0EQniBoxNJJPlFl0,1127
160
- chemparseplot-1.13.0.dist-info/RECORD,,
157
+ chemparseplot-1.13.2.dist-info/METADATA,sha256=p-hSMpe2bxIzofg0qg9YqEWhreFrlu2XgkxMFR3D3EI,9841
158
+ chemparseplot-1.13.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
159
+ chemparseplot-1.13.2.dist-info/licenses/LICENSE,sha256=WpBevJdirrfildX-iO61fdIm4hJ0EQniBoxNJJPlFl0,1127
160
+ chemparseplot-1.13.2.dist-info/RECORD,,
@@ -102,3 +102,60 @@ def test_gallery_places_one_titled_tile_per_reaction(tmp_path):
102
102
  plt.close(fig)
103
103
  with pytest.raises(ValueError, match="one column"):
104
104
  plot_reaction_gallery(tiles, columns=0)
105
+
106
+
107
+ def test_bond_order_between_separated_atoms_draws_no_edge(tmp_path):
108
+ import xyzrender as xr
109
+
110
+ from chemparseplot.plot.reaction import apply_wbo_style
111
+
112
+ path = tmp_path / "radicals.xyz"
113
+ path.write_text("3\nradicals\nC 0 0 0\nH 1.09 0 0\nH -3.85 0 0\n")
114
+ graph = apply_wbo_style(
115
+ xr.load(str(path), quick=True), {(1, 2): 0.98, (1, 3): 0.75}
116
+ ).graph
117
+ a, b, c = sorted(graph.nodes)
118
+ assert graph.has_edge(a, b)
119
+ assert not graph.has_edge(a, c)
120
+ # a forming H-H contact of a dissociation saddle keeps its edge
121
+ hh = tmp_path / "hh.xyz"
122
+ hh.write_text("3\nhh\nC 0 0 0\nH 1.1 0 0\nH 1.1 1.29 0\n")
123
+ graph_hh = apply_wbo_style(xr.load(str(hh), quick=True), {(2, 3): 0.15}).graph
124
+ p, r, s = sorted(graph_hh.nodes)
125
+ assert graph_hh.has_edge(r, s)
126
+ # a stretched transition-state contact within the reach keeps its edge
127
+ graph = apply_wbo_style(
128
+ xr.load(str(path), quick=True), {(1, 3): 0.75}, max_contact=4.0
129
+ ).graph
130
+ assert graph.has_edge(a, c)
131
+
132
+
133
+ def test_atlas_rows_make_room_for_every_bond_line(tmp_path):
134
+ import matplotlib as mpl
135
+
136
+ mpl.use("Agg")
137
+ import matplotlib.pyplot as plt
138
+
139
+ from chemparseplot.plot.reaction import plot_reaction_atlas
140
+
141
+ image = tmp_path / "state.png"
142
+ plt.imsave(image, np.ones((8, 8, 4)))
143
+ bond = {"label": "C1\u2013C2", "distance_A": 2.2, "wbo": 0.3}
144
+
145
+ def case(n):
146
+ return {
147
+ "title": "row",
148
+ "states": [
149
+ {"title": "s", "image": str(image), "bonds": [bond] * n} for _ in range(4)
150
+ ],
151
+ }
152
+
153
+ short = plot_reaction_atlas([case(1)] * 4)
154
+ tall = plot_reaction_atlas([case(3)] * 4)
155
+ assert tall.get_figheight() > short.get_figheight()
156
+ # the colour bar sits below the lowest bond annotation
157
+ tall.canvas.draw()
158
+ bar = tall.axes[-1].get_position()
159
+ lowest = min(t.get_window_extent().y0 for t in tall.texts if "\u2013" in t.get_text())
160
+ assert bar.y1 * tall.bbox.height < lowest
161
+ plt.close("all")