You gotta' be careful what you say in blog posts - things like, "it shouldn't be hard to make x do y" typically lead to emails asking you how to do it. Then again, I do love a challenge!
So, I received an email a few hours ago asking me how I could take the molecule viewer from my last post and realize my "it shouldn't be hard to make the this dynamiclly render molecules from mol files" comment.
In order to dynamically render a 3D molecule, we'll have to add the ability to convert a mol file to a format more easily handled by Flash. Work will involve adding a parser and making some changes to MoleculeFactory.create() to accept a parsed result.
On a side-note, another email I received pointed me to a YouTube video of Mike Lively's work at Northern Kentucky University. I watched the video... good stuff.
One comment in the video that caught my attention (~ :40 seconds) was the "1400 lines of code" needed to parse a MOL file. He then updates (~ :50 seconds) the figure to 350 lines for his most recent effort. I'm not sure exactly what his parser looks like... but I would strongly recommend using regular expressions.
I might be wrong, but the output of a CCCDBB query looks like a legacy / rigid format (I've only tested my assumptions with PM3 data - mileage may vary). So, I really don't think you're going to see fluctuation in the output; regular expressions should give you maximum bang for the buck when parsing. Take a look at the ChemParser.as class in the project - about ~50 lines is all you should need (I'll take a look at adding bond information later).
Back to the challenge of turning my first project into a dynamic mol file converter and molecule visualizer. Hit up this link...
[ Molehill Molecule Viewer ]
WARNING: You'll need to make sure you're running Flash Player 11 incubator or better... else you're going to have some issues viewing the example.
Then, take a mol file like this...
C3H4O2 2-Propenoic acid 79107
##CCCBDB 3 71102:50
Geometry Optimized at PM3
9 8 0 0 0 0 0 0 0 0 V2000
1.3371 0.3176 0.0000 O 0000000000000000000
1.7959 1.1520 0.0000 H 0000000000000000000
-0.3314 1.7138 0.0000 O 0000000000000000000
0.0000 0.5400 0.0000 C 0000000000000000000
-0.8840 -0.6430 0.0000 C 0000000000000000000
-1.9563 -0.4059 0.0000 H 0000000000000000000
-0.4503 -1.8996 0.0000 C 0000000000000000000
0.5997 -2.1818 0.0000 H 0000000000000000000
-1.1361 -2.7426 0.0000 H 0000000000000000000
1 2 1 0 0 0
1 4 1 0 0 0
3 4 2 0 0 0
4 5 1 0 0 0
5 6 1 0 0 0
5 7 2 0 0 0
7 8 1 0 0 0
7 9 1 0 0 0
Paste it into the text box, and click the convert button. Voila!
What you are looking at my friends... is a molecule of Propenoic Acid which is a naturally occurring carboxylic fatty acid found in milk, sweat, and fuel distillates. Mmmmm - sweat.
Give it a try! Hit up the CCCDBB search engine, type in a formula, and click-through to the PM3 mol output. Copy-and-paste the mol text block into the molecule viewer and the magix will happen. Just make sure that the mol file includes the coordinate block. There are a number of formulas that don't.
[ source: Molehill Molecule Viewer - Flash Builder Project ]