This is a description of the conversion process for importing molecular structures into Layar: converting the PDB files into the format Layar uses, importing these files into Hoppala and placing them within a layer.
Most molecular structures which are freely available exist as PDB files; these files define atoms (with types and coordinates) and bonds between the atoms. In order to visualise these, they are typically converted into a 3d mesh - for example using pymol. Unfortunately, Layar is very picky about the 3D formats it understands - it will only accept it's own format (l3d), which is based on a Wavefront .obj file and its associated material file (.mat).
It is hard to find a good process for converting PDB files into l3d. The following is a hack, which works OK for small molecules (and small numbers of them).
Get the PDB 
First stop, PubChem. Because it is the middle of winter in Scotland, I'm low on Vitamin D, so we will work with that. It seems that PDBs aren't as freely available as I thought, but we can get hold of an XML file from the PubChem page. OpenBabel to the rescue, and we can create a PDB from the XML file:
babel -isdf CID_5280795.sdf -opdb VitaminD.pdb
Create the Mesh 
This is the trickest part; pymol would seem like the obvious tool to use, as it creates beautiful 3D pictures of molecules. Unfortunately, although it can export .obj files, it doesn't export a materials file to go with it. This means that none of the atom colours are represented, which is a great shame. Instead, we use Blender, an open source 3D modelling package.
Blender cannot import PDB files directly, but there are some scripts to do it. This seems quite polished, but lacks options about the style of molecule to display. I've been using this, which gives a bit more control.
If you open the script in blender and run it, you'll get a box like this:
Because this is going to be displayed on low powered mobile devices, we need a low polygon count. So I've reduced the quality of both the connections and the spheres, and turned off hydrogens. This gives a molecule like this:
(it looks a bit dull because I've deleted the lights from my scene).
You need to perform adjustments at this stage as well. The molecule should be oriented as you would like it to appear, especially in terms of the vertical axis. Also, the scaling in Hoppala is a bit problematic at the moment, and values lower that 1:1 don't seem to work. So, the model wants to be shrunk by approximately 100-fold.
Now we can use File -> Export -> Wavefront to export the .obj file. It is *essential* to export as triangles, as the Layar software doesn't deal with anything else. Apparently, exporting as material groups can speed up rendering too:
You should now have a .obj file, and an associated .mat file.
Convert to Layar format 
Layar uses its own format for representing 3D models. Called l3d, it is essentially a binary version of a .obj file and its associate materials (.mat) file. Fortunately, they also provide a tool for converting files into this format, the Layar Model Converter.
If all has gone well, when you open the .obj file with this tool, you'll see:
- on the overview page, the number of faces should be reasonable (<5k), and the model dimensions should be <1
- the materials page should have materials reflecting the colours in the model
- the preview should look sensible...
Finally, you should be able to try positioning the molecule on the open streetmap view in the tool. This is worth doing, since Hoppala doesn't give you much of a preview for scale or rotation. Also, if you were using an alternative setup, you could directly use the .json file which is generated.
You can now select Save As..., and it will create a .l3d file, which is the model and its materials, and a .json file which describes the positioning carried out.
Import into Hoppala 
Now, these files can be imported into Hoppala. Go into your layer in Hoppala, and click on "Add an Augment". This sets up a POI, which you can position on the map:
Now, you can setup the basic properties of the POI - title, name etc. I've added a picture to represent the molecule in general browsing, which might also be displayed if the user is far away from the molecule.
The more detailed model properties are where the l3d file can be uploaded; set the model type to 3D and add the model using the boxes provided. Here is where the .json file comes in useful: the Hoppala software allows for the lat/long coordinates of the POI to be set using the Google maps view, but the scale and rotation need to be set by hand. These values can be copied from the .json file if the model was set up as desired in the conversion tool.
Press save, and the model is ready for display!