We’ve been busy, working hard to bring you some of the features that you have asked us for.
This will be a major change to what you can use the Chemistry Add-In for Microsoft Word for.
We’re keen to see your reaction!
Chemistry Add-In for Microsoft Word
CML is Cool
by Andy Wright
We’ve been busy, working hard to bring you some of the features that you have asked us for.
This will be a major change to what you can use the Chemistry Add-In for Microsoft Word for.
We’re keen to see your reaction!
by Clyde Davies
This is the first in (what I hope will be) a series of occasional postings. Targeted at developers mainly, these will cover some of the problems we come across, and how we solve them.
Chem4Word is about ten years old. It started out as a research project. Such projects typically explore new ways of solving problems. They don’t set out to optimize established approaches. When you keep adding new functions at the expense of making existing ones work better, you end up with cruft.
The cruftiest portion of Chem4Word was its in-memory chemistry handling. Chem4Word’s standard file format is Chemical Markup Language, an XML dialect. There was no logical differentiation between the file containing the information and its in-memory representation. The code simply loaded the CML as-is into an XDocument. It then manipulated the XML directly. This was very wasteful as it required the XML parsed every time we needed to manipulate something. XDocuments are fine for limited XML editing, but when you’re constantly hitting the document then the conversion overhead becomes huge.

So, we wrote a completely new, in-memory Model class in C#. The Model in essence represents a chemical drawing. A Model contains Molecules, which can contain other Molecule objects or Atom and Bond collections.
Atoms obviously are the building blocks of Molecules. We store these in Molecules as dictionaries. These allow us to quickly retrieve an Atom by its label, such as ‘a1’. Bonds are simple collections, which reference a StartAtom and EndAtom as a text label. So Bond ‘b1’ would link Atoms ‘a1’ and ‘a2’, for example.
Atoms obviously have to reference a specific Element. There are obviously a limited number of these, stored in a single global PeriodicTable.
Each Molecule also contains what we term as emergent objects. So, a Molecule has a collection of Rings, and each Ring collects several Atoms. Atoms can be shared by more than one ring.
This simple approach allows us to create compact in-memory representations of quite complex molecules. The XML representation, instead of being central, is now relegated purely to persistence roles. Previewing, in-document rendering, editing and many other functions now work on the Model. A dedicated CMLConverter class handles conversion to and from the CML format, typically when storing this in a Custom XML Part.
No doubt some purists will take issue with this rather literal implementation but we (and you) are already reaping the benefits. The improved performance is by far the most dramatic effect. Even on a relatively fast machine, rendering insulin in the document used to take six or seven minutes. Now it takes a few seconds. We have seen performance improvements of 400-500% on small molecules and 12,000% on large ones!
One final benefit comes from exposing the atoms and bonds as objects in their own right, and organizing them as collections. We can now data-bind to them. Windows Presentation Foundation makes heavy use of data binding. So, we could theoretically data-bind various visual elements to their corresponding logical ones. And this is precisely what we do in the FlexDisplay component, which we will cover in a later post.
by Clyde Davies
2021 was a challenging year for many of us. We are still glad that we managed to produce a new release of Chem4Word. The most effort went into improving ACME, our new molecule sketcher.
ACME opens new horizons for Chem4Word. And I’d like to talk about some of those now.
Chemistry is the study of change, as Walter White memorably points out.
Chem4Word up to now has been more concerned with static molecules. We think it presents these as well as any paid-for package.
But molecules are boring, yeah? You got enthused when you saw some chemistry happening! You have been demanding change. And we’re going to deliver it!
We’ve been working on basic reaction functionality. What’s that? Well, it’s drawing different kinds of chemical reactions and specifying reactants, products, reaction type with reagents and conditions. Here’s a sneak preview:

But Chemical Markup Language, which underpins Chem4Word, is capable of much, much more. CML describes reactions in great detail using CML-React. You can fully specify the reaction type, reagents and conditions. You can also set reactants and products for a reaction.
We want to treat reagents and solvents as first-class chemical objects in their own right. So, we will add custom dictionaries of these, both from libraries and from online sources like Wikipedia.
We also plan to fully support reaction mechanisms with electron pushers (‘curly arrows’). Chem4Word will be the best free chemistry tool for teaching and understanding chemistry!
We are now beta-testing this new version, so get involved if you can. Download the beta and tell us what you think. All your feedback is valuable!
Clyde Davies
Project Leader.
by Clyde Davies

You often ask us, ‘why doesn’t Chem4Word work in Office Online apps?’ After all, you would be able to use it on any platform that supported them. Such as Apple Mac, used by many chemists in preference to Windows.
The answer is complicated and lies in the history of Chem4Word. It started collaborative project between Microsoft Research and Cambridge University more than ten years ago. If you wanted to develop a Word add-in at that time, you had two options.
First, you could write it in Visual Basic for Applications. This is great for quick, relatively unsophisticated customisations, such as custom templates or dialog boxes.
But Chem4Word demanded a lot more from the platform. So it used Visual Studio Tools for Office (VSTO). VSTO, pronounced ‘visto’, ties Word and other Office apps into the .NET Framework using the C# programming language. This unleashes the full power of Windows, including sophisticated graphics and XML handling. This is just what was needed to power Chem4Word.
A lot has changed since it was first written. Microsoft sank more resources into developing the cloud-based versions of Office and now embraces JavaScript as a development language. It’s bringing its online APIs into line with the VSTO-supported APIs. There will soon be little to choose from them.
But, and this is a very big ‘but’: JavaScript is a very different language to C#. Despite being ‘the programming language of the Web’, it is arguably a poor relation and does things very differently. Translating our tens of thousands of lines of code from C# to JavaScript is a huge task! JavaScript’s graphics capabilities come second to the native Windows platform. For instance, ACME would be difficult to reproduce using the HTML canvas:

The Office Online development platform is also limited. We can’t easily access compound libraries downloaded to the computer. The security restrictions of running in a web browser put paid to that, and other features! Office Online add-ins can only interact with the user through task panes. It’s difficult to shoehorn all our functionality into those.

Microsoft have pledged continued support for VSTO-based applications. So, for now we will dedicate our development resources to enhancing Chem4Word on this platform. Our new ACME editor will allow us to add exciting new features, like reactions and structural templates, while maintaining the full Chem4Word experience that you know and value.
We will still be closely watching how the new Office Developer story unfolds. When we are happy that we can take what we have done to the new online platform, with minimal effort, hassle and degradation of functionality, then we will provide a Chem4Word that’s as fully-featured and easy to use online as it is on your desktop!
As a final comment, with the web version of Word, you can open, read and edit documents containing Chemistry that were created with the desktop version of Word without losing the Chemistry components.
This post shows you how to merge your existing structure V3 library into V2020 essential oils library.
1. Export your existing structures to a folder by clicking on the Chem4Word “Options” button.

2. Select the library tab and click on the “Export” button.

3. Chose a folder to export them to. Here I have created a folder called “C:\Users\Mike\Library”.

4. When “Select Folder” is clicked you should see a progress bar at the bottom of the form as shown below.

5. Once the export is completed you will see a dialog similar to the following.

6. Select the “Maintenance” Tab and click on the “Open” button for the library.

7. Once the folder has opened you can backup the file “Library.db”, then delete it.

8. Close all running copies of Microsoft Word. If in doubt re-boot your PC after the above step.
9. Start Microsoft Word, Select the Chemistry Tab, then click on the “Open” Library button and you should see that the new Essential Oils database has been installed. In the image below the button’s caption has been changed to close as the library is open.

10. You can now import and merge the structures from your previous library by clicking on the “Options” button. Select the “Library” tab, then click on the “Import” button.

11. Select the folder you previously exported your library to.

12. You will be required to confirm the import operation.

13. While working you will see a progress bar at the bottom of the form as shown below.

14. Congratulations, you have now merged the two libraries.
