At the start of 2020 I decided that I'd try learning to program in Swift using Xcode, I've never had any formal programming training and I've always regarded myself as a cut-and-paste programmer. I've dabbled with various languages from AppleScript and shell scripting through ApplescriptObjC to Python and become fairy proficient with Python. After reading how Xcode was supposed to greatly simplify the process I thought I'd give it a try. After going through a couple of tutorials and reading this excellent introduction to Swift I set about writing my first app.
I had a pretty good idea of what I wanted the app to do but I spent a little times sketching out the interface and checking the external web services I wanted to access. Most could be accessed by simple GET urls and I spent a little time testing with various queries working out how to break them. It was clear that some of the potential query text strings would need to be URL encoded.
URL encoding, also known as percent encoding, is a way to encode or escape reserved, unprintable, or non-ASCII characters in URLs to a safe and secure format that can be transmitted over the internet
One thing I did not do which I would really recommend is spending some time checking that the proposed name for your app is not already taken somewhere. I did not and it turns out to be a bit of a pain changing the name at a later date, whilst Xcode helps in many ways one of the consequences is the chosen name is propagated through-out the code and file names.
Building the interface
Building the interface in Xcode is very straight-forward and mainly consists of dragging and dropping various interface elements into position, guidelines appear automatically to aid getting things lined up. The attributes inspector allows you alter the appearance of each element. The large white box is a Webkit view and is used to embed web content, in this case images of the molecular structures.
Linking to the code
Interface elements like buttons, text fields and dropdown menus can be linked to the code by control clicking on the interface element and the dragging and dropping to the appropriate position in the code. Once all the interface elements have been linked you can then start writing the code.
Much of the code is fairly uneventful, setting the query as the text from the input field, url encoding to make it url safe, getting the choice of search engine.
The code to display the structure is shown below, we construct the URL from three variables, the search engine (engineLink), query string url encoded (escapedString) and how we want the structure displayed (molRepresentation). We then send the request to the web service and load the response into the web view (molView).
Creating the icon
I experimented with various applications trying to create the application icon and ended up using Sketch this seemed to offer the best compromise between vector editing capabilities and ease of use. The interface in particular was very Mac-like and seemed comfortingly familiar. Well worth a look at and you can try it out for free.
The default is to build the code targeting the version of the Mac OS on the host machine but there is the option for building for other versions. Looking at the Macs in Chem website over the last month it looks like it might be better to aim for Mac OS 10.13 or later to support the majority of the potential users.
Most people will have downloaded software from the internet and come across this warning message, I wanted to avoid this so decided to go through the notarisation process.
Full details are in the developer documentation.
Notarization gives users more confidence that the Developer ID-signed software you distribute has been checked by Apple for malicious components. Notarization is not App Review. The Apple notary service is an automated system that scans your software for malicious content, checks for code-signing issues, and returns the results to you quickly. If there are no issues, the notary service generates a ticket for you to staple to your software; the notary service also publishes that ticket online where Gatekeeper can find it.
This seemed rather convoluted but if you follow the details on the above webpage it all works fine. First time through I misunderstood the
Create an archive of your app
This means create an archive using the "Archive" option in the "Product" menu from the main Xcode toolbar.
The notarisation actually took only a couple of minutes, and I got an email back when it was completed.
You then need to export your archive again to receive a distributable version of your software that includes the notary ticket!
How to use molSeeker
You can download molSeeker here.
The interface is shown below, simply type the name of the molecule/drug/chemical you are interested in into the test field, then choose a search engine. Two search engines are implemented CIR the Chemical Identifier Resolver from the NCI/NIH,
This service works as a resolver for different chemical structure identifiers and allows one to convert a given structure identifier into another representation or structure identifier. It can help you identify and find the chemical structure if you have an identifier such as an InChIKey.
and PubChem from NCBI.
Contains unique, validated chemical structures (small molecules) that can be searched using names, synonyms or keywords. The compound records may link to more than one PubChem Substance record if different depositors supplied the same structure. These Compound records reflect validated chemical depiction information provided to describe substances in PubChem Substance. Structures stored within PubChem Compounds are pre-clustered and cross-referenced by identity and similarity groups. Additionally, calculated properties and descriptors are available for searching and filtering of chemical structures.
The condensed, 27 character InChIKey is a hashed version of the full InChI (using the SHA-256 algorithm), designed to allow for easy web searches of chemical compounds.
Many open source databases now include the InChiKey as one of the identifiers far molecular records.
UniChem efficiently produces cross-references between chemical structure identifiers from 39 different databases, it can very rapidly search using the InChikey as the query term, the output is displayed as a web page with links to the appropriate data sources. Clicking on the hyperlink then opens the record in the source database.
If you want an image of the structure you can simply drag and drop the image onto you desktop, or you can copy the SMILES string and paste it into you favourite Chemical drawing package.
You can download molSeeker here. It has been tested on Mac OS X 10.13 and above.
Last updated 16 Feb 2020