An Object-Oriented Framework for Molecular Representation: Getting Started with Octet
If applications are hard to design and toolkits are harder, then frameworks are hardest of all. A framework designer gambles that one architecture will work for all applications in the domain. Any substantive change to the framework's design would reduce its benefits considerably, since the framework's main contribution to an application is the architecture it defines. Therefore it's imperative to design the framework to be as flexible and extensible as possible.
-Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides- Design Patterns
One of the most important considerations when building an application is the choice of framework. As the quote from the Gang of Four implies, there's much more to frameworks than just a collection of re-usable code. At their best, frameworks provide a foundation for thinking about a problem domain and a language for communicating with other developers about it. In this article, I'll introduce Octet, an object-oriented framework for molecular representation.
The Molecular Representation Problem
Isn't molecular representation a solved problem? After all, don't SMILES, Molfile, InChI, and CML adequately represent any molecule the average software developer is likely to see?
As previously discussed, molecular representation technologies have stagnated while the molecules chemists themselves now routinely make and use have continued to become more and more "exotic." Developers are now faced with the thorny problem that a variety of common structural motifs in chemistry can't be adequately represented with industry-standard cheminformatics tools.
This point is so important, I'll repeat it: cheminformatics has fallen behind chemistry in the kinds of molecules it can work with. Quick fixes only allow the problem to fester; what's needed is a comprehensive solution. This is Octet's problem domain.
Every framework is bounded by a specific problem domain. Although the size of the domain can vary, a framework provides a comprehensive solution within it. For complex and poorly standardized domains (such as molecular representation), a good framework can greatly accelerate application development.
A good frameworks stays within its problem domain. One of the most important reasons is to prevent featuritis, the root of much software evil. Keeping a framework focused on its core mission makes it much more likely that it can remain documented, tested, extensible, and efficient.
By intention, a variety of features fall outside Octet's problem domain and so will never be directly supported. For example, rendering 2-D structure diagrams is a common problem in cheminformatics that has nothing to do with solving the molecular representation problem. Similarly, reading and writing SMILES strings and Molfiles are supported by many toolkits, but not by Octet directly. After all, it's the inherent limitations of these languages that Octet is trying to overcome.
Higher-level functionality such as legacy language support and 2-D rendering, although not part of Octet itself, can be developed with Octet as a foundation. For example, two Octet add-on frameworks specifically address these problems. They are called Rosetta and Structure, respectively.
About This Series
This article is the first in a series discussing Octet. Future articles will describe in detail Octet's design, implementation, and use. Although Octet has come a long way, it's far from finished. My motivation for writing these articles is to hear what you have to say about Octet, so please feel free to contact me.
Although Octet is written in Java, code examples discussed here will be written in Ruby. I've taken the same approach in discussing the Chemistry Development Kit (CDK) and Structure-CDK. Ruby's brevity and comfortable syntax make it ideal for both writing and discussing code.
Ruby Java Bridge (RJB) is the magic technology that makes this possible. Previous articles have discussed the installation and use of RJB on Windows and Linux.
A Simple Test
Assuming you've installed Ruby, RubyGems and Ruby Java Bridge, you can perform a simple demonstration of Octet in Ruby:
require 'rubygems'
require_gem 'rjb'
require 'rjb'
BasicMoleculeBuilder = Rjb::import('net.sf.octet.builder.BasicMoleculeBuilder')
RepresentationKit = Rjb::import('net.sf.octet.util.RepresentationKit')
MoleculeKit = Rjb::import('net.sf.octet.util.MoleculeKit')
System = Rjb::import('java.lang.System')
builder = BasicMoleculeBuilder.new
RepresentationKit.buildHexane(builder)
molecule = builder.releaseMolecule
MoleculeKit.printMolecule(molecule, System.out)$ export CLASSPATH=./octet-0.8.2.jar $ ruby test.rb **Molecule Properties** Atom Count: 6, Bonding System Count: 5 Atoms: atom: C[0] (2nu 0e, 0or, 0.0fc, 1bs, 1n, 4.0val, 3ih ) atom: C[1] (2nu 0e, 0or, 0.0fc, 2bs, 2n, 4.0val, 2ih ) atom: C[2] (2nu 0e, 0or, 0.0fc, 2bs, 2n, 4.0val, 2ih ) atom: C[3] (2nu 0e, 0or, 0.0fc, 2bs, 2n, 4.0val, 2ih ) atom: C[4] (2nu 0e, 0or, 0.0fc, 2bs, 2n, 4.0val, 2ih ) atom: C[5] (2nu 0e, 0or, 0.0fc, 1bs, 1n, 4.0val, 3ih ) No non-natural isotopic distributions specified. No Orbitals specified. Bonding Systems: bonding system: ( 2be, 0abe, 2a, 1ap ) [ (0, 1) ] bonding system: ( 2be, 0abe, 2a, 1ap ) [ (1, 2) ] bonding system: ( 2be, 0abe, 2a, 1ap ) [ (2, 3) ] bonding system: ( 2be, 0abe, 2a, 1ap ) [ (3, 4) ] bonding system: ( 2be, 0abe, 2a, 1ap ) [ (4, 5) ] Atom Pairs: atom pair: (0, 1) (1.0 bo) atom pair: (1, 2) (1.0 bo) atom pair: (2, 3) (1.0 bo) atom pair: (3, 4) (1.0 bo) atom pair: (4, 5) (1.0 bo) No Atomic Configurations specified. No Conformation specified.
As you can see, Octet shares the same concepts and vocabulary as FlexMol. We'll drill down into the meaning of the output in later articles. The important thing to remember is that we can print out a report like the one above for any Molecule, no matter how complex.
Conclusions
Octet is an object-oriented framework designed to solve the molecular representation problem and serve as a solid foundation for a variety of cheminformatics applications. Of course, there's much more to Octet than the simple example shown here. Future articles will describe in greater detail the design and use of Octet through illustrative examples.
A Molecular Language for Modern Chemistry: FlexMol, Tetrahedral Chirality, and Monolaterol
Models of structure and bonding play a critical role in guiding chemical research. These models also define the scope and limitations of any cheminformatics system. Within the last several years, the gap between the structure and bonding models used by chemical information systems and by the chemists who use them has been widening. On this front, chemistry is moving much faster than cheminformatics. Sooner or later the difference must be reconciled.
A Looming Problem
Models of structure and bonding in cheminformatics, although adequate for organic chemistry in the 1970s, are outdated today. As recently discussed, some of the most interesting molecules in organic chemistry can't be adequately represented by 99% of the available cheminformatics tools. This may not be a problem if your clients never work with these molecules (but they probably are already). It may not be a problem if your system never interacts with the outside world where these molecules are prevalent (but it will eventually). A quick fix is likely to produce even bigger problems down the road. What's needed is a comprehensive solution.
FlexMol is a molecular language designed to solve this problem. For example, recent articles have demonstrated how FlexMol is capable of representing some of today's most difficult structural motifs: metallocenes; biaryl axial chirality; non-biaryl axial chirality; planar chirality; and non-tetrahedral stereochemical configuration.
Although FlexMol handles these tough cases, it's not merely a specialty language for "weird" molecules. Rather, FlexMol provides a basic set of elements and principles that can be applied to any molecule, regardless of its peculiarities or lack thereof. For example, FlexMol defines a clean system for the representation for alkene geometry. This basic level of functionality is not even provided by the industry-standard Molfile format, which requires 2-D atom coordinates.
In this demonstration, we'll turn our attention to one of the most basic problems in cheminformatics - the representation of tetrahedral chirality. Using an example molecule from the recent literature, we'll see how the principles outlined in previous FlexMol examples also apply to stereogenic carbons.
Conformation or Configuration?
We need to answer a basic question before we can represent tetrahedral chirality: should we use configuration or conformation? Following the simple principle that isomers interconvertible by bond rotation are conformational isomers and all others are configurational isomers, it's clear that we'll be using configuration. More rigorous definitions are offered by Dietz.
An Example

A recent paper describes the isolation of the plant natural product Monolaterol and the assignment of its absolute configuration. Using the structure and atom numbering system shown above, we can construct a complete FlexMol representation of Monolaterol. Rather than reproduce it here, let's just consider the stereochemically-relevant part:
<!-- snip -->
<configuration>
<configurationWheel>
<atomPair source="15" target="16"></atomPair>
<halfPlane>
<lower atom="14"></lower>
</halfPlane>
<halfPlane></halfPlane>
<halfPlane></halfPlane>
<halfPlane>
<lower atom="12"></lower>
</halfPlane>
</configurationWheel>
<configurationWheel>
<atomPair source="15" target="12"></atomPair>
<halfPlane>
<lower atom="16"></lower>
</halfPlane>
<halfPlane></halfPlane>
<halfPlane></halfPlane>
<halfPlane>
<lower atom="14"></lower>
</halfPlane>
</configurationWheel>
<configurationWheel>
<atomPair source="15" target="14"></atomPair>
<halfPlane>
<lower atom="12"></lower>
</halfPlane>
<halfPlane></halfPlane>
<halfPlane></halfPlane>
<halfPlane>
<lower atom="16"></lower>
</halfPlane>
</configurationWheel>
</configuration>
<!-- snip -->Notice that three configurationWheels are defined. As in the case of representing the configuration of square-planar species, each substituent of the chiral center is in turn placed along a wheel's axis, giving three wheels in total for Monolaterol. The relationships among atoms, planes, and axes is represented in the following cartoon:

Notice also that there are two empty half-planes in each conformationWheel. Half-planes occur in pairs spaced 180 degrees apart. Given that there are two neighboring atoms to place into half-planes, two half-planes will be empty. We nevertheless must include them as placeholders. Notice that virtual hydrogens (those hydrogens not explicitly defined as part of the atoms element) are not placed into half-planes.
It should be clear that the FlexMol representation of Monolaterol's (R)-enantiomer is distinguishable by visual inspection or by software. Each configurationWheel would be enantiomeric. As a result, the ordering of half-planes about their respective axes would be inverted.
So What?
Most cheminformatics tools can represent tetrahedral chirality. In nearly every case, this is accomplished with stereodescriptors, atom parities, or chiral flags. Extending these systems to non-tetrahedral chirality requires more templates - a difficult, if not impossible, task in most cases. Worse still, such systems are often based on poorly-documented conventions, resulting in a great deal of confusion when writing software implementations.
FlexMol takes a completely different approach by actually describing the chiral environment around an atom in terms of a simple system of axes and planes. The rules governing these elements are applied regardless of the kind of chirality being represented. This results in a system that works consistently for known forms of chirality, and which can be extended as new forms of chirality are encountered.
A Software Implementation
Any new molecular language requires a software implementation. For FlexMol, that implementation is provided by the Octet Framework. Octet is open source software written in Java that provides a FlexMol reader, a FlexMol writer, and many tools for working with molecular representations.
Conclusions
Although not often discussed, models of bonding and structure figure prominently in the ability of cheminformatics software to solve relevant problems. This is especially true in the increasingly important area of molecular chirality. In this area, FlexMol offers a system with unprecedented flexibility; it works just as well with stereogenic carbon as with numerous, less common forms of chirality.
Ferrocene and Beyond: A Solution to the Molecular Representation Problem
The representation of molecular structure decisively determines the scope of a chemical computer program. Our goal is to provide a versatile computer-oriented molecular structure representation for chemical information storage and retrieval as well as for computer-assisted synthesis design. Structural formulas describe molecular structure on the proper level of abstraction for these applications. ... It is therefore desirable that the computer-oriented representation of molecular structure be as expressive as the structural formulas.
-Andreas Dietz, J. Chem. Inf. Comput. Sci. 1995, 35, 787-802
A recent Depth-First article highlighted the difficulty that existing molecular languages have in communicating the generalized, multi-atom bonding present in metallocenes such a ferrocene. For software and Web services that do not interact with the outside world, the Ferrocene Problem may not be a big deal. But for the growing number that do, the Ferrocene Problem is but the tip of a very large iceberg.
Today's Weird-Looking Molecule is Tomorrow's Molecule of the Month
Consider the problem of axial chirality, such as that present in certain biaryls. None of the molecular languages currently in widespread use (InChI, SMILES, Molfile, or CML) provide a mechanism to faithfully represent and communicate this structural motif. In the 1980s, axial chirality was a novelty. Today it is ubiquitous. Consider this graphical abstract from the current issue of Organic Letters:

If you were asked to create an application capable of distinguishing substituted (R) and (S) binol enantiomers, could you do it? If your system needed to reliably interact with the outside world, could it do so? If you're working with any of the cheminformatics tools currently in widespread use, chances are good that the answers to these questions would be "no".
Do you still think of metallocenes as curiosities studied by a handful of organometallic chemists? Consider this J. Org. Chem. ASAP contents article describing one of the most fundamental transformations in organic chemistry:

The problem only gets worse as concepts like axial and planar chirality are increasingly co-mingled with multi-atom bonding. For example, consider the following graphical abstract, taken from J. Org. Chem. ASAP contents:

These molecules, and many others like them, were used in the context of organic chemistry. Moreover, the papers describing their use were published in widely-respected journals specializing in organic chemistry. Yet dozens of popular cheminformatics tools specifically designed for use with organic chemisty are incapable of faithfully representing the most interesting features of these molecules. In other words, the problem is both real and immediate.
Chemistry relentlessly marches forward, revealing even greater molecular information problems on the horizon. For software to remain relevant, it must be based on tools that are up to the challenge.
A Solution
The system proposed by Dietz offers a solution to nearly all of the bonding and stereochemistry problems of existing molecular languages. As a tradeoff, Dietz's system is significantly more complicated to implement. This places an increased burden on software to make the system as simple and understandable as possible.
Java and XML Implementations
Any specification, if it is to become more than just an academic exercise, requires a software implementation. Fortunately, for Dietz's system both a software implementation and an XML Schema have been developed and are freely-available.
The software implementation can be found in the Java framework Octet. In addition to fully-implementing Dietz's specification, Octet enables ring perception, substructure and query structure matching, breadth-first traversal, and of course, depth-first traversal. Add-on libraries are available for 2-D structure depiction, and Molfile and SMILES input and output. A CDK News article discusses CDKTools, a bridge to the Chemistry Development Kit. Octet remains, to my knowledge, the first and only implementation of the Dietz system.
The first, and to my knowledge only, XML implementation of the Dietz molecular representation system is FlexMol (Flexible Molecular Object Language). A commented W3C schema is distributed with Octet. Browser-ready HTML documentation can be found here, or from the sidebar links under "APIs and Schema Documentation." Octet is able to read and write FlexMol documents, providing an open, end-to-end solution to the problem of representing and transmitting molecules containing "nonstandard" bonding and stereochemistry.
Conclusions
Both FlexMol and Octet are convenient tools for working with the Dietz molecular representation system. Future articles in this series will show how they can be used to solve current, real-world molecular representation problems.
Scripting Octet with JRuby
JRuby is a Java implementation of the Ruby language. It lets developers manipulate Java classes and objects using Ruby syntax. Why would anybody want to do this? One reason is to enable Ruby developers to work with “legacy” Java code. Another less obvious reason it that Java classes and objects can manipulated interactively with the JRuby version of Interactive Ruby, or irb. Still another is to provide new avenues for application development and deployment. In this article, I'll show how Octet can be scripted with JRuby.
Older posts: 1 2


