{ "cells": [ { "cell_type": "markdown", "id": "5394a3ef", "metadata": {}, "source": [ "# Compound properties and structured records\n", "\n", "This notebook shows the live compound-loading workflow and the structured record helpers added for NistChemPy 2.x." ] }, { "cell_type": "code", "execution_count": 1, "id": "6ff79a18", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:37:59.815722Z", "iopub.status.busy": "2026-05-20T17:37:59.815600Z", "iopub.status.idle": "2026-05-20T17:38:00.809099Z", "shell.execute_reply": "2026-05-20T17:38:00.808500Z" } }, "outputs": [ { "data": { "text/plain": [ "NistCompound(ID=C71432)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import nistchempy as nist\n", "\n", "compound = nist.get_compound('C71432') # benzene\n", "compound" ] }, { "cell_type": "code", "execution_count": 2, "id": "38a52e40", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:38:00.810864Z", "iopub.status.busy": "2026-05-20T17:38:00.810582Z", "iopub.status.idle": "2026-05-20T17:38:00.814964Z", "shell.execute_reply": "2026-05-20T17:38:00.814400Z" } }, "outputs": [ { "data": { "text/plain": [ "{'record_type': 'compound',\n", " 'compound_id': 'C71432',\n", " 'source_url': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432',\n", " 'retrieved_at': '',\n", " 'ID': 'C71432',\n", " 'name': 'Benzene',\n", " 'synonyms': ['[6]Annulene',\n", " 'Benzol',\n", " 'Benzole',\n", " 'Coal naphtha',\n", " 'Cyclohexatriene',\n", " 'Phenyl hydride',\n", " 'Pyrobenzol',\n", " 'Pyrobenzole',\n", " 'Benzolene',\n", " 'Bicarburet of hydrogen',\n", " 'Carbon oil',\n", " 'Mineral naphtha',\n", " 'Motor benzol',\n", " 'Benzeen',\n", " 'Benzen',\n", " 'Benzin',\n", " 'Benzine',\n", " 'Benzolo',\n", " 'Fenzen',\n", " 'NCI-C55276',\n", " 'Phene',\n", " 'Rcra waste number U019',\n", " 'UN 1114',\n", " 'NSC 67315',\n", " '1,3,5-Cyclohexatriene'],\n", " 'formula': 'C 6 H 6',\n", " 'mol_weight': 78.1118,\n", " 'inchi': 'InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H',\n", " 'inchi_key': 'UHOVQNZJYSORNB-UHFFFAOYSA-N',\n", " 'cas_rn': '71-43-2',\n", " 'mol_refs': {'mol2D': 'https://webbook.nist.gov/cgi/cbook.cgi?Str2File=C71432',\n", " 'mol3D': 'https://webbook.nist.gov/cgi/cbook.cgi?Str3File=C71432'},\n", " 'data_refs': {'cTG': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=1#Thermo-Gas',\n", " 'cTC': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=2#Thermo-Condensed',\n", " 'cTP': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=4#Thermo-Phase',\n", " 'cTR': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=8#Thermo-React',\n", " 'cSO': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=10#Solubility',\n", " 'cIE': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=20#Ion-Energetics',\n", " 'cIC': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=40#Ion-Cluster',\n", " 'cIR': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=80#IR-Spec',\n", " 'cMS': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=200#Mass-Spec',\n", " 'cUV': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=400#UV-Vis-Spec',\n", " 'cES': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=800#Electronic-Spec',\n", " 'cGC': 'https://webbook.nist.gov/cgi/cbook.cgi?ID=C71432&Mask=2000#Gas-Chrom',\n", " 'Fluid Properties': 'https://webbook.nist.gov/cgi/fluid.cgi?ID=C71432&Action=Page'},\n", " 'nist_public_refs': {'Electron-Impact Ionization Cross Sections (on physics web site)': 'https://physics.nist.gov/cgi-bin/Ionization/table.pl?ionization=C6H6xx0',\n", " 'Gas Phase Kinetics Database': 'https://kinetics.nist.gov/kinetics/rpSearch?cas=71432',\n", " 'X-ray Photoelectron Spectroscopy Database, version 5.0': 'https://srdata.nist.gov/xps/SpectralByCompdDd/2349',\n", " 'NIST Polycyclic Aromatic Hydrocarbon Structure Index': 'https://pah.nist.gov/?q=pah001'},\n", " 'nist_subscription_refs': {'NIST / TRC Web Thermo Tables, \"lite\" edition (thermophysical and thermochemical data)': 'https://wtt-lite.nist.gov/wtt-lite/index.html?cmp=benzene',\n", " 'NIST / TRC Web Thermo Tables, professional edition (thermophysical and thermochemical data)': 'https://wtt-pro.nist.gov/wtt-pro/index.html?cmp=benzene'}}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "compound.to_dict()" ] }, { "cell_type": "markdown", "id": "5492dc63", "metadata": {}, "source": [ "Property loaders still use WebBook pages. They now return the loaded objects and also store them on the compound object." ] }, { "cell_type": "code", "execution_count": 3, "id": "583322ec", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:38:00.816251Z", "iopub.status.busy": "2026-05-20T17:38:00.816064Z", "iopub.status.idle": "2026-05-20T17:38:02.134171Z", "shell.execute_reply": "2026-05-20T17:38:02.133697Z" } }, "outputs": [ { "data": { "text/plain": [ "(1, Spectrum(C71432, Mass spectrum #0))" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ms_spectra = compound.get_ms_spectra()\n", "len(ms_spectra), ms_spectra[0] if ms_spectra else None" ] }, { "cell_type": "code", "execution_count": 4, "id": "22402c59", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:38:02.135361Z", "iopub.status.busy": "2026-05-20T17:38:02.135169Z", "iopub.status.idle": "2026-05-20T17:38:02.138064Z", "shell.execute_reply": "2026-05-20T17:38:02.137695Z" } }, "outputs": [ { "data": { "text/plain": [ "{'record_type': 'spectrum',\n", " 'compound_id': 'C71432',\n", " 'source_url': 'https://webbook.nist.gov/cgi/cbook.cgi?JCAMP=C71432&Index=0&Type=Mass',\n", " 'retrieved_at': '',\n", " 'spectrum_type': 'MS',\n", " 'spectrum_index': '0',\n", " 'parsed': {}}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ms_spectra[0].to_dict(include_raw=False) if ms_spectra else None" ] }, { "cell_type": "code", "execution_count": 5, "id": "2823befb", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:38:02.139106Z", "iopub.status.busy": "2026-05-20T17:38:02.138940Z", "iopub.status.idle": "2026-05-20T17:38:14.363156Z", "shell.execute_reply": "2026-05-20T17:38:14.362495Z" } }, "outputs": [ { "data": { "text/plain": [ "(16,\n", " Chromatogram(C71432, Kovats' RI, non-polar column, isothermal: 276 data points))" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chromatograms = compound.get_gas_chromatography()\n", "len(chromatograms), chromatograms[0] if chromatograms else None" ] }, { "cell_type": "code", "execution_count": 6, "id": "53a9bad2", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:38:14.364406Z", "iopub.status.busy": "2026-05-20T17:38:14.364283Z", "iopub.status.idle": "2026-05-20T17:38:14.370732Z", "shell.execute_reply": "2026-05-20T17:38:14.370229Z" } }, "outputs": [ { "data": { "text/plain": [ "[{'Column type': 'Capillary',\n", " 'Active phase': 'RTX-5',\n", " 'Column length (m)': '30.',\n", " 'Carrier gas': 'N2',\n", " 'Substrate': '',\n", " 'Column diameter (mm)': '0.25',\n", " 'Phase thickness (μm)': '0.25',\n", " 'Temperature (C)': '100.',\n", " 'I': '685.',\n", " 'Reference': 'Ádámová, M.; Orinák, A.; Halás, L., Retention indices as identification tool in pyrolysis-capillary gas chromatography, J. Chromatogr. A, 2005, 1087, 1-2, 131-141, https://doi.org/10.1016/j.chroma.2005.01.003',\n", " 'Comment': 'MSDC-RI'},\n", " {'Column type': 'Capillary',\n", " 'Active phase': 'RTX-5',\n", " 'Column length (m)': '30.',\n", " 'Carrier gas': 'N2',\n", " 'Substrate': '',\n", " 'Column diameter (mm)': '0.25',\n", " 'Phase thickness (μm)': '0.25',\n", " 'Temperature (C)': '120.',\n", " 'I': '694.74',\n", " 'Reference': 'Ádámová, M.; Orinák, A.; Halás, L., Retention indices as identification tool in pyrolysis-capillary gas chromatography, J. Chromatogr. A, 2005, 1087, 1-2, 131-141, https://doi.org/10.1016/j.chroma.2005.01.003',\n", " 'Comment': 'MSDC-RI'},\n", " {'Column type': 'Capillary',\n", " 'Active phase': 'RTX-5',\n", " 'Column length (m)': '30.',\n", " 'Carrier gas': 'N2',\n", " 'Substrate': '',\n", " 'Column diameter (mm)': '0.25',\n", " 'Phase thickness (μm)': '0.25',\n", " 'Temperature (C)': '60.',\n", " 'I': '672.74',\n", " 'Reference': 'Ádámová, M.; Orinák, A.; Halás, L., Retention indices as identification tool in pyrolysis-capillary gas chromatography, J. Chromatogr. A, 2005, 1087, 1-2, 131-141, https://doi.org/10.1016/j.chroma.2005.01.003',\n", " 'Comment': 'MSDC-RI'}]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chromatograms[0].to_dict()['data'][:3] if chromatograms else []" ] }, { "cell_type": "code", "execution_count": 7, "id": "29c0a4d3", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:38:14.371821Z", "iopub.status.busy": "2026-05-20T17:38:14.371702Z", "iopub.status.idle": "2026-05-20T17:38:14.375746Z", "shell.execute_reply": "2026-05-20T17:38:14.375239Z" } }, "outputs": [ { "data": { "text/plain": [ "[('compound', 'CompoundRecord'),\n", " ('spectrum', 'SpectrumRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord'),\n", " ('gas_chromatography', 'ChromatogramRecord')]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[(record.record_type, type(record).__name__) for record in compound.to_records()]" ] }, { "cell_type": "markdown", "id": "e8da03b2", "metadata": {}, "source": [ "Spectrum records intentionally keep raw JCAMP-DX text. Numeric digitization/parsing can be added later without changing the basic record interface." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.13" } }, "nbformat": 4, "nbformat_minor": 5 }