Skip to content

Chemistry support for Obsidian. Rendering SMILES strings into chemistry structures.

License

Notifications You must be signed in to change notification settings

Acylation/obsidian-chem

Repository files navigation

Obsidian Chem

Obsidian Downloads Powered by RDKit

简体中文 | English

Chem is a plugin for Obsidian.md providing chemistry support. It allows you to insert chemical structures into your notes through code blocks containing SMILES strings (powered by Smiles Drawer & RDKit.js).

Note

Latest release: 0.4.1
Document version: 0.4.1

Features & Usage

Render SMILES Strings as Chemical Structures

Render via Code Block

You can use this plugin to render chemical structures from SMILES strings. Just type the SMILES strings in a code block with smiles as the language. Each line should contain only one string.

The data is stored as plain text, so you won’t lose it. The renderer will always work, even if the plugin changes its cheminfo core.

Render SMILES strings into structures

Inline Render

You can enable inline render feature in plugin settings. Code lines with specified prefix would be recognized. The default syntax is $smiles=C1=CC=CC=C1 and the prefix is configurable.

Global Sizing and Theming

You can adjust the structure scale or the image size and configure light/dark themes of the structure images in the plugin’s settings page. The structures in open notes will be automatically updated when the plugin settings or Obsidian color scheme are changed.

Configure size and theme

Copy & Export

The copy feature is accessible through the right-click menu on images. Images are copied in png format. Despite common applications, you can also paste the copied image into your note, which will then save the image as a file to your attachment folder. The scale of the export, transparency, and theme can be configured to suit your needs.

Utilizing Dataview

Inline Dataview queries and DataviewJS rendering can be enabled in the settings tab. Once enabled, lines within the smiles block will be checked and parsed. The return values from this process will be used to render chemical structures, providing greater flexibility. The prefix and strategy are fetched directly from the corresponding Dataview plugin settings.

Dataview lines in smiles block

Warning

This feature is dependent on the Dataview plugin. Please ensure that you have installed and enabled it.

The execution of DataviewJS is implemented by calling eval() at the bottom, which is known to have security issues. To avoid unintended execution, only trusted code lines should be passed.

If you wish to keep inline Dataview queries rendering and only disable DataviewJS, you can toggle off the Enable JavaScript Queries or Enable Inline JavaScript Queries options through the Dataview plugin settings.

Introduction on SMILES

What is SMILES?

SMILES stands for Simplified Molecular-Input Line-Entry System. It is a specification to describe chemical structures using linear ASCII strings. You can learn more about it from the official website or Wikipedia.

Why Using SMILES?

Using SMILES strings to represent molecules is easier and more widely supported by chemistry drawing tools than using LaTeX packages like mhchem and chemfig.

How to Generate SMILES Strings?

For simple structures, you can type them in manually. However, for more complex ones, you may want to use structure editors, such as ChemDraw, ChemDrawJS, MarvinJS and Ketcher. There's a Ketcher editor integration plugin Obsidian Ketcher available right in Obsidian.

Also, you can use translators like Open Babel, JOELib and the Chemical Translation Service to convert chemical names, CAS numbers and *.mol files into SMILES strings.

Installation

Note

Make sure that you are not in the Restricted Mode.

The plugin is available in the official plugin market. You can go to Settings → Community plugins → Browse, and search for the Chem plugin by Acylation. After installing, you need to enable the plugin to use it.

You can also follow the steps below to install the plugin manually.

  1. Go to the repo's latest release page, and download the main.js, style.css, and manifest.json. Alternatively, you can download the latest zip file and then unzip it to get the three files.
  2. Copy these files to your local path [yourvault]/.obsidian/plugins/chem/. You may need to create the folder chem by yourself.
  3. Launch/restart Obsidian, or refresh the plugin list, you will see this plugin.
  4. In the plugin list, enable Chem and enjoy!

Note

If you want to utilize RDKit.js, Chem plugin would try to fetch RDKit_minimal and RDKit_minimal.wasm files from release. If you have problem connecting GitHub, please download them manully and put them in the directory [yourvault]/.obsidian/plugins/chem/rdkit/ for recognization and loading.

Plugin Scope

I have a lot of ideas for this plugin, but my coding skills and resources are limited. I want to make it useful for anyone who needs to take notes on chemistry (such as research records, organic chemistry anki cards, etc.). As examples, here are some of the features I have in mind.

  • Displaying chemical formulas and structures.
  • Importing structures from the clipboard, .cdxml files, etc.
  • Appending chemical info (e.g. exact mass) next to the structures. This can help MS users and beginners in chemistry.
  • Supporting internal coordinates like .mol files. Would be useful in computational chemistry.
  • Shortcuts for physicochemical formulas in LaTeX.
  • ......

I'd love to hear your feedback and suggestions. Actually, the first feature of the plugin, to render SMILES strings, was suggested by community users! I’m very grateful for their input. (See the acknowledgment section for details)

Contributing

Thank you for your interest in contributing to this project! We welcome bug reports, feature requests, and pull requests from anyone. For more information on how to contribute to Chem, check out CONTRIBUTING.md.

Roadmap

Check out the roadmap to see what's been working on.

Companion Plugins

Chem plugin is now primarily focused on rendering texts into structures. If you want to create complex structures from scratch, the Ketcher plugin has integrated a powerful opensource editor.

Chemical Structure Renderer is a similar plugin of Chem, which uses Ketcher, Indigo online service for parsing and rendering, while Chem plugin integrates standalone packages and runs locally.

Credits

The plugin relies on Smiles Drawer and RDKit.js as the parsing and drawing cores, and takes Mathpix as a good example on integrating Smiles Drawer and use codeblock to decorate the note. Thank you very much!

During the whole process of development, I found the developer documentation super helpful. Massive thanks to @marcusolsson for leading this project!

The plugin is motivated by forum requests for including chemical structures in Obsidian. Thank you for the inspiring discussions and the great ideas!