Macs in Chemistry

Insanely great science


Using PTHPasteboard Pro 4

I recently reviewed Clipboard managers and decided PTPPasteboard best met my need.

PTHPasteboard is comprehensive clipboard manager that supports multiple text and image clipboards, these can then be accessed via a customisable icon in the menu bar or from a floating window, clicking on an item in the clipboard history displays the application that the data was copied from and for text items shows the number of lines/words/characters and for images the size. PTHPasteboard also supports filtering of clipboard text allowing you to convert to unformatted text, convert to lower/upper case, change to Mac/Unix/Windows line endings. There is also a custom filter dialog that allows you to build your own filters for example to convert a list from a text document into an html list. It also allows the creation of custom clipboards. PTHPasteboard PRO's Syncing support takes advantage of Mac OS X's Bonjour technology to seamlessly sync your pasteboard items across multiple machines.

I’ve been using it for a couple of weeks now and I thought I’d share few tips.

Multiple clipboards

Whilst PTHPasteboard can share the clipboard contents you might not want to share every item on the clipboard, I created a new clipboard and called it “Shared” and then in the “sync” panel clicked the “Publish” button. Now when I want to share an item on the main clipboard I select it in drop down menu and choose “Add to Shared”, it then gets magically copied to my desktop computer clipboard. I’ve also created a clipboard called “Keep” to this clipboard I’ve added items that I regular need to paste into documents such as my address and a selection of the markdown items I regularly use on the website.


Text Filtering

One really nice feature is the ability to modify the contents of the clipboard on the fly, the applications comes with a number of ready made filters that allow you to convert to unformatted text, convert to lower/upper case, change to Mac/Unix/Windows line endings. One option I’ve been using is the ability to call shell scripts. Simply copy some text to the clipboard then choose “Show Custom Filter Window” from the drop down clipboard menu, in the window that opens choose “Shell Script” from the drop down window. Type the shell script command in the lower panel, in this case “wc -w” and hit the “Update” the button. The Output box will now show the word count for the copied text.


Perhaps a rather more useful option would be the ability to sort a list of text items, the shell command “sort” allows you to do this. Copy some text to the clipboard and open the custom filter window, select Shell script and type “sort” into the left hand box and you should see an alphabetically sorted list in the output box. If you use “sort -r” the sort order will be reversed. If you want to keep this filter then click the “Save Filter” button and give it a recognisable name. I found I sometimes had to go to the control panel and stop/start PTHPasteboard to have the new filter appear in the top menu bar drop down menu.


With a sorted list on the clipboard it is now possible to convert this to an HTML encoded list with a couple of simple filters. Add a second filter and choose "Quote Text" from the "Replace" menu and type “<li>” into the "Start Quote" box and “</li>” into the "End Quote" box.


Now add a third filter adding “<ul>” and “</ul>,” remember to uncheck the “Quote each line” checkbox since we only want to be adding to the start and end of the list.


Copy this into a web page and you should see it displayed as shown below in your web browser.

Along similar lines it is easy to construct a sequential filter that will convert comma separated text to a HTML table. First use a Search and Replace filter to change all “,” to “</td> <td>”, then use a Quote filer to add <td> and </td> to the start and end of each line, then use another quote filter to add <tr> and </tr> to the start and end of each line, then another quote filter to add <table> and </table> to the start and end of the entire block of text (uncheck the “Quote each line” checkbox).

Name Age Birthday Address
Harper 86 June Monte Vista Avenue
Avila 09 September Altavista Avenue
Church 13 May Wayne Avenue
Cervantes 12 May Church Street
Solomon 88 January Altamont Circle
Harvey 73 September Concord Avenue

Using OpenBabel

The above examples are fairly trivial examples but the ability to call shell scripts allows for much more interesting options. I use SMILES strings as a very compact line notation for representing molecular structures, however these are not the easiest way to visualise a chemical structure so I need to convert them to alternative formats for display, particularly in web pages.

For example the SMILES string “CCCc1nn(C)c2c1N=C(NC2=O)c1cc(ccc1OCC)S(=O)(=O)N1CCN(C)CC1” is difficult to visualise but the open source cheminformatics tool OpenBabel can be used to convert to a format that can be rendered using a suitable tool. Openbabel will take the SMILES string via stdin and return the structure in mol format to stdout. So with the SMILES string copied to the clipboard again open the custom filter window, this time type /usr/local/bin/babel -ismi -omol --gen2D into the left hand box (note you need to give the full unix path to the application). Click “Update and you should have the structure pasted in mol format appear in the Output box. For use with ChemDoodle we need to remove the line endings and replace them with \n. To do this add a second filter (click the + button) and choose “Search and Replace” from the “Replace” menu and then just press return in the “Search” box and type “\n” in the “Replace” box.

smi2mol custom

This can then be pasted into a HTML page to render the structure using the ChemDoodle web components.

Alternatively you can just turn the SMILES string into svg (ScalableVector Graphics, not supported by all browsers) format using an OpenBabel shell script again “/usr/local/bin/babel -ismi -osvg --gen2D” converts a SMILES string on the clip board to the code needed to display as shown below.

CH 3 N N CH 3 N NH O O CH 3 S O O N N CH 3 - OBDepict

There are more hints and tutorials here

Updated 17 January 2012