# Tag: Software

## Science via email

One thing scientists and engineers have to do daily is discuss collaborative work via email exchanges. This often includes the need to share and discuss mathematical equations and to represent variables with subscripts and superscripts or special characters; something that is tricky when you are emailing in plain text.

WikiImages / Pixabay

Of course it is possible to work around this problem! Email was invented by scientists, and for decades they have been communicating in this manner, using various conventions to convey the correct information using plaintext. However, if you are a Gmail user there is a nice extension that will make your equations look proper good.

## Tex for Gmail

TeX for Gmail is a Chrome browser extension that checks a Gmail email that you are writing for LaTeX markup and converts the markup to a visually prettier equation, using one of two modes. In Simple Math mode, subscripts and superscripts are correctly formatted but the current font is maintained and text remains ediatble. In Rich Math mode, the equation is rendered into TeX and replaced by an embedded image.  The email recipient doesn’t need the extension installed on their browser in order to read your nice equations!

### Example

Original markup:

\$E = mc^{2}\$

Simple Math mode:

E = mc2

Rich Math mode:
$\dpi{300}\inline E = mc^{2}$

## Issues

One problem; once the extension has converted my markup to formatted text, I cannot get the markup back. So editing a small mistake usually means re-doing all the curly brackets and other stuff that a TeX equation requires. The only workaround seems to be to stay vigilant and use Undo (Ctrl-z), but this doesn’t work when you notice a mistake in an equation that you wrote a while ago. One improvement could be the option to restore any equation to the original markup.

## Conclusions

Overall, a great little tool to improve the clarity of science and maths communications over email. With a few small improvements it could be even better but it is already very usable.

### 5 Tips for making finite element models with Salome

Salome is an open source software package used to create geometric models and finite element meshes for use in numerical simulations. It is also able to perform its own numerical simulations and has post-processing capabilities built in.

Here are my 5 tips for anyone who is interested in using Salome for model and mesh creation.

## 1. Practice manually first

This goes without saying. Although Salome has a powerful Python-based scripting capability, it is worth practicing with manual model generation. By that I mean, clicking with your mouse in the GUI. Manual practice lets you get familiar with the quirks of the Salome workflow, which has a different mentality to many other model generator programs.

## 2. Use the Notebook

In Salome the Notebook is a useful tool that allows you to set size parameters in the beginning as model variables. This means that later on you can edit the notebook variable values and re-build the model using different sizes; something that cannot be done normally, while typing size values in to construct geometric objects. The Notebook is like having some of the power of scripting while still making the model manually in the GUI. A great halfway step up to full scripting.

## 3. Learn to use scripting

Once you are familiar with Salome’s way of thinking, automation through scripting can become a critical component of being productive. Often it is necessary to compare many similar models where just one specific parameter (say the size of some part) is being changed.

In this recent paper we had to compare the effects of different soft magnetic defect thicknesses in a permanent magnetic grain.  By scripting the model generation I was able to rapidly generate similar models from one template script.

## 4. Small size adjustments can get you out of a rut

Sometimes with Salome (and actually with other modelling software too) you find an annoying problem that makes no sense. For example, you made the model with no problems but now you increased the size of part A and it doesn’t want to build anymore. These kind of problems can occur because designing such a powerful piece of software to work universally is hard. You might be attempting something that the software designers did not anticipate.

One trick that often works for me goes like this. Change the parameter again by a small, arbitrary amount. If size A is 100 nm large, try changing it to 100.001. The simulation result will be virtually identical but you might find the model generation can now function without problems.

I remember in an earlier version of GiD, doing a boolean volume operation on two objects would fail if the edges of the objects overlapped perfectly. So I always had to make sure to translate one of the objects by a tiny amount. Then the Boolean operation would usually work. The makers of GiD fixed this in later versions and most good model software can handle such things.

The same problem often occurs with meshing algorithms. Depending on the type, an algorithm may be trying to fill a certain volume with elements but is being constrained for element size. This can cause the algorithm to fail, but a small change in the specified mesh size can get it to work again.

## 5. Check your dumped scripts

When making a model using the GUI it is really cool to be able to dump the model as a Python script, which can then be edited and run using the script mode. As I highlighted in another post, it helps to take care that Explode functions do not reorder the exploded entities. The default behaviour is to reorder, and it is easy to forget this when using the script, leading to confusion when the wrong objects are subject to later operations.

### Cool code: plotting columns from many data files with Grace

Grace a.k.a. xmgrace is a really useful tool for plotting histograms from tabular data files. Its power comes from the command line control and being scriptable. Yes, there are other options which are sometimes more suitable for specific situations (e.g. GNUplot, Matplotlib/PyLab), but for quick, basic plotting I usually find myself relying on xmgrace.

Here is an example of a single line command to plot two columns from each of a large number of data files:

`for i in ./a*/field.log; do echo -n " -block \$i -bxy 10:44" ; done | xargs xmgrace`

The command searches all current subdirectories with names beginning “a” for files called field.log. For each field.log file found it uses an echo command to generate a commandline argument string that we normally use to make a 2D plot with the 10th (x axis) and 44th (y axis) columns using xmgrace. The -n option for echo makes sure there is no newline after each echo, generating one long collection of commands. We next want to pass this on to xmgrace…

xmgrace does not take input from stdin so we first pipe the total echo output to xargs, which is a tool used to construct command line parameters from stdin. xargs then passes these command line arguments to xmgrace.

This little code snippet saves a lot of typing, which grows of the order N for N data files. Now I need to work out how to name each data set on the fly too.

I use Zotero to manage my literature collection, including all the associated PDF attachments. It really made my life easier when I set up the WebDAV file sync on Box. However, until now the only way to sync files to my Onyx Boox M96 eReader (image) was by connecting a USB cable and copying them manually to the device. Since Zotero stores the files in cryptically-named individual folders it is hard to do this manually in an organised manner and involves lots of clicking. Today I am going to find a better way.

This is what we want! Our technical documents on a large-screen eInk device that allows annotation. Great for proofreading!

I searched for an Android version of Zotero, hoping that I could just sync to the extra device. Aside from the fact that the article files would take up too much of my internal flash storage space there is actually no official Zotero for Android; only some discontinued third-party project called Zotero Reader and a paid-option called Zandy, which had mixed reviews on the Play Store.

But then there is ZotFile, which can be installed on your PC as a Firefox add-on or as an extension to the stand-alone Zotero, and gives additional functionality. Zotfile is able to copy the article attachment (PDF) to a location on your PC or Mac, for example a Dropbox folder, that is set up to sync with an external device. It can also extract any annotationsto the PDF that you create on the device. My eReader runs Android so I have a number of options for the software that does the syncing, including DropBox, Google Drive or even BitTorrent Sync. I am jumping between Windows and Ubuntu on my main PC and I had issues doing this with BTSync in a single shared folder before, but as long as the collection of files does not grow too big I can keep separate sync folders in Win7 and Ubuntu to avoid any issues. Using BTSync means that you have a collection of devices syncing to each other but your files are not stored in the cloud on someone else’s servers. All transfers are encrypted so in principle it is secure.

OK, here are the steps I took.

1. Install ZotFile as a Firefox Add-on (to work with the Zotero Firefox Add-on).

2. Create a new folder somewhere on the PC that will be the sync folder. In Ubuntu I chose “/home/username/Documents/ZotFileSync” and in Windows I chose “C:/Users/Documents/ZotFileSync” (or whatever). The important thing is that it is not the same folder on a shared drive, something that caused problems for me in the past.

3. In Firefox, find the ZotFile preferences. In the second tab, check the box to “Use Zotfile to send and get files form tablet”. Give it the sync “Base” folder path. I also chose to create subfolders and save a copy of annotated files with the suffix “_annotated”.

The ZotFile preferences can be found inside Zotero by going to Tools > Add-ons > ZotFile > Options.

4. Use BTSync or dropbox or whatever you like to sync this folder to the cloud.

5. Set up BTSync or dropbox or whatever on your tablet/eReader to sync the files to/from the cloud. You might need to install a file manager app in order to create a new sync folder on your device. I used ES File Explorer, which incidentally seems to work quite well on an eInk screen.

BitTorrent sync in the Play store on my Onyx Boox M96 eReader.

Now, in Zotero (on your PC) you can right-click an item, Manage Attachments and Send to Tablet (see image below). It should shortly appear on your device, as long as it is connected to the internet and syncing with the cloud. Just like magic!

Sending an article to your handheld device from Zotero is easy with ZotFile, even though it is simply copying it to a folder that is synced by separate software.

UPDATE:

There are a few (device-specific) issues with this solution.

1) BitTorrent Sync is not running when I boot the eReader. I have to manually start it. It also forgets to sync my shared folder automatically so I have to remind it every time I run the app. I hope that the option to run apps on startup will be included on a later firmware update.

2) The Onyx Boox M96 (Booxtor edition) only scans the internal storage for new books when you boot the device, with no option to manually scan from inside the OS. That means that once the synced files appear in the btsync shared folder the device library doesn’t show them until the next reboot. Again, I hope a manual “scan for new books” will be added to the library app on a later OS update. You could alternatively use a 3rd party reading app that manages its own database of books on the device.

These two issues combined make the process of transferring documents to the eReader a little less automatic than I would like. However, I have eliminated the need to attach the eReader to my PC via USB cables. Let’s see if the arbiters of the device will tweak the software for us in the future.

At the moment I don’t seem to be able to export my annotated PDF files, so I have not tested the annotation extraction feature of ZotFile yet.

### Syncing Zotero files with WebDAV from Box

It’s hard to stay organized when you work on multiple computers, with multiple operating systems. My main notebook is a dual boot Ubuntu/Win7 machine where I have a shared partition for work files. I sync my work folder with my Ubuntu tower PC via BitTorrent Sync. This has now been working well for some time (the syncing happens under Ubuntu only, which is a drawback, but if BTSync under Windows also tries to sync the same shared folder it causes problems, thus I avoided doing so) although if you start with two identical copies of the folder on the two PCs it still wants to sync all of the files one way over the network. Not good when the folder is 100 GB large! (Update: this may have been solved in the latest version of the software).

Anyway, for the last half year I have been back using Zotero for my bibliography manager. It makes importing citations and the associated fulltext PDFs from a journal website relatively easy although there are some difficulties with importing PDFs from a local drive, particularly when an old file has no OCR layer. Then I sometimes have to input the metadata manually.

So my Zotero folder (data and files) went over the 300 MB free size limit for the online Zotero storage. That means that my library on Windows and my library on Ubuntu (I cannot share it locally, it seems, due to formatting and access rights issues – need two copies for now!) are no longer synced. I managed to get access to some papers under Windows and now I want to use them in Ubuntu and they are not there. It could easily turn into a big mess of files and folders and I want to keep it somehow automagically synced using Zotero.

So finally I turned to the WebDAV option in Zotero. This lets you keep the data (i.e. library metadata and collections) synced on the Zotero server and the files (i.e. PDF and other attachments) on a separate server. So, how can you get a WebDAV server?

I got a free personal storage account with Box (10 GB) and in the Zotero preferences I am able to setup a server, that is, https://dav.box.com/dav/zotero/

Don’t forget to create a folder named “zotero” in your Box account first! Also, you can now purge your files from storage using the Zotero web interface under storage preferences. This frees up all of that space that was previously clogged up with attachments.

There you go, you now have 10GB of free storage for your Zotero library!