Files
CoolProp/Web/scripts/CPWeb
Ian Bell c649586e8c feat(docs): add interactive 3D molecule viewers to fluid pages (#2707)
* feat(docs): add interactive 3D molecule viewers to fluid pages

Use py3Dmol + PubChem SDF data to embed a rotate-and-drag 3D (or 2D
fallback) molecule viewer on each pure fluid documentation page.

- fetch_pubchem_sdf(): downloads 3D conformer SDF from PubChem REST API
  (falls back to 2D), caching results in molecule_sdf/ to avoid repeated
  network calls on doc rebuilds
- generate_3dmol_rst(): inlines the SDF as a JS template literal inside a
  .. raw:: html block — no extra static files needed at Sphinx build time
- FluidGenerator.write(): validates InChIKey with regex before fetching;
  pseudo-pure fluids (Air, R404A, etc.) without InChIKeys are silently skipped
- conf.py: loads 3Dmol.js from CDN via html_js_files
- .gitignore: excludes the generated molecule_sdf/ cache directory

Restores molecule visualisation that was removed in April 2025 (the old
approach tried to embed an image directive inside a CSV table, which is
invalid RST; this implementation places the viewer in the RST template).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(docs): serve 3Dmol.js locally to eliminate CORS errors

Download 3Dmol-min.js to _static/ at Sphinx build time (same pattern
as MathJax) instead of loading it from the CDN via html_js_files.
Serving the script same-origin removes the cross-origin restriction
that caused CORS errors when docs were opened from file:// or a local
dev server.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(docs): correct 3Dmol viewer positioning and initialization timing

3Dmol.js sets its canvas to position:absolute;top:0;left:0 and only
auto-sets the container to position:relative when the container's
inline style.position === "static". An unstyled div has style.position
=== "" so the check fails, and the canvas escapes the container and
anchors to the nearest positioned ancestor in the Sphinx page layout.

Fix: add position:relative explicitly to the viewer container div.

Also defer viewer init via DOMContentLoaded so layout is finalized
before createViewer reads the container dimensions, and call v.resize()
before v.render() to sync the WebGL canvas to the container size.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(docs): disable MathJax SRE to prevent CORS errors on file:// URLs

MathJax 4.0's Speech Rule Engine fetches sre/mathmaps/base.json at
runtime via fetch(). Chrome blocks this when docs are opened from a
local file:// URL (null origin). Disabling enableExplorer and
enableAssistiveMml prevents SRE from initialising entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(docs): load 3Dmol before require.js to fix AMD conflict

sphinx.ext.mathjax injects require.js at priority 500. When 3Dmol
loads after it, AMD detection fires and calls define([], factory)
instead of setting window.$3Dmol directly. Since nothing ever calls
require(['3Dmol-min']), the factory never runs and the viewer silently
fails (infinite setTimeout retry, no console errors).

Setting priority 450 ensures 3Dmol loads before require.js.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(docs): add retry logic to downloads in conf.py using requests

Replace urllib.request.urlretrieve with a requests-based _download()
helper that retries up to 5 times (exponential backoff, factor=2) on
transient HTTP errors and timeouts. Fixes CI build failures when
the MathJax or 3Dmol.js downloads time out.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 10:41:10 -04:00
..
2019-01-12 20:45:25 -07:00
2019-01-12 20:45:25 -07:00
2018-08-14 23:06:49 -06:00