Transpose paste

Despite python etc we still heavily rely on the tables. Sometimes it is need to transpose a vertical data-set to a horizontal representation. That is easy. In LibreOffice Calc use special paste (Shift+Ctrl+v) and tick transpose and numbers. One can do similar trick in Excel. That is it.

Omnipotent compose key

Two keyboard layouts are all you need. I have a Cyrillic and a Latin one. So I can type in Russian and many-many other languages including Estonian. For the later one, I use the omnipotent compose key. The compose key is a key to trigger the insertion of a precomposed character. Shortly, it allows me to type “äöüõ”. Moreover, it simplifies typing “š” in my family name (Ivaništšev). Believe me, this is more difficult with the Estonian layout. Also, I can type “€” sign.

On Linux (Gnome) you can activate it as: System > Preferences > Keyboard > Layouts > Layout Options > Compose key. Choose the preferred button that will turn on the composition mode. I prefer Caps Lock. On Windows one requires special software. For example, wincompose.

The life seems so beautiful when everything is set, and the UK layout is set to default.

Besides, one can enable compose for Greek alphabet by adding to ~/.XCompose file:

# GREEK CAPITAL LETTERS
<Multi_key> <G> <A> : "Α" U0391 # GREEK CAPITAL LETTER ALPHA
<Multi_key> <G> <B> : "Β" U0392 # GREEK CAPITAL LETTER BETA
<Multi_key> <G> <G> : "Γ" U0393 # GREEK CAPITAL LETTER GAMMA
<Multi_key> <G> <D> : "Δ" U0394 # GREEK CAPITAL LETTER DELTA
<Multi_key> <G> <E> : "Ε" U0395 # GREEK CAPITAL LETTER EPSILON
<Multi_key> <G> <Z> : "Ζ" U0396 # GREEK CAPITAL LETTER ZETA
<Multi_key> <G> <H> : "Η" U0397 # GREEK CAPITAL LETTER ETA
<Multi_key> <G> <I> : "Ι" U0399 # GREEK CAPITAL LETTER IOTA
<Multi_key> <G> <K> : "Κ" U039A # GREEK CAPITAL LETTER KAPPA
<Multi_key> <G> <L> : "Λ" U039B # GREEK CAPITAL LETTER LAMDA
<Multi_key> <G> <M> : "Μ" U039C # GREEK CAPITAL LETTER MU
<Multi_key> <G> <N> : "Ν" U039D # GREEK CAPITAL LETTER NU
<Multi_key> <G> <P> : "Π" U03A0 # GREEK CAPITAL LETTER PI
<Multi_key> <G> <R> : "Ρ" U03A1 # GREEK CAPITAL LETTER RHO
<Multi_key> <G> <S> : "Σ" U03A3 # GREEK CAPITAL LETTER SIGMA
<Multi_key> <G> <T> : "Τ" U03A4 # GREEK CAPITAL LETTER TAU
<Multi_key> <G> <U> : "Υ" U03A5 # GREEK CAPITAL LETTER UPSILON
<Multi_key> <G> <F> : "Φ" U03A6 # GREEK CAPITAL LETTER PHI
<Multi_key> <G> <X> : "Χ" U03A7 # GREEK CAPITAL LETTER CHI
<Multi_key> <G> <W> : "Ω" U03A9 # GREEK CAPITAL LETTER OMEGA
<Multi_key> <G> <O> : "Θ" U0398 # GREEK CAPITAL LETTER THETA
<Multi_key> <G> <Y> : "Ψ" U03A8 # GREEK CAPITAL LETTER PSI
<Multi_key> <G> <C> : "Ξ" U039E # GREEK CAPITAL LETTER XI

# greek small letters
<Multi_key> <g> <a> : "α" U03B1 # GREEK SMALL LETTER ALPHA
<Multi_key> <g> <b> : "β" U03B2 # GREEK SMALL LETTER BETA
<Multi_key> <g> <g> : "γ" U03B3 # GREEK SMALL LETTER GAMMA
<Multi_key> <g> <d> : "δ" U03B4 # GREEK SMALL LETTER DELTA
<Multi_key> <g> <e> : "ε" U03B5 # GREEK SMALL LETTER EPSILON
<Multi_key> <g> <z> : "ζ" U03B6 # GREEK SMALL LETTER ZETA
<Multi_key> <g> <h> : "η" U03B7 # GREEK SMALL LETTER ETA
<Multi_key> <g> <i> : "ι" U03B9 # GREEK SMALL LETTER IOTA
<Multi_key> <g> <k> : "κ" U03BA # GREEK SMALL LETTER KAPPA
<Multi_key> <g> <l> : "λ" U03BB # GREEK SMALL LETTER LAMDA
<Multi_key> <g> <m> : "μ" U03BC # GREEK SMALL LETTER MU
<Multi_key> <g> <n> : "ν" U03BD # GREEK SMALL LETTER NU
<Multi_key> <g> <p> : "π" U03C0 # GREEK SMALL LETTER PI
<Multi_key> <g> <r> : "ρ" U03C1 # GREEK SMALL LETTER RHO
<Multi_key> <g> <s> : "σ" U03C3 # GREEK SMALL LETTER SIGMA
<Multi_key> <g> <t> : "τ" U03C4 # GREEK SMALL LETTER TAU
<Multi_key> <g> <u> : "υ" U03C5 # GREEK SMALL LETTER UPSILON
<Multi_key> <g> <f> : "φ" U03C6 # GREEK SMALL LETTER PHI
<Multi_key> <g> <x> : "χ" U03C7 # GREEK SMALL LETTER CHI
<Multi_key> <g> <w> : "ω" U03C9 # GREEK SMALL LETTER OMEGA
<Multi_key> <g> <t> : "θ" U03B8 # GREEK SMALL LETTER THETA
<Multi_key> <g> <y> : "ψ" U03C8 # GREEK SMALL LETTER PSI
<Multi_key> <g> <c> : "ξ" U03BE # GREEK SMALL LETTER XI
# special characters
<Multi_key> <minus> <minus> </>     : "–" U2013 # NDASH
<Multi_key> <minus> <minus> <minus> : "−" U2212 # MINUS
<Multi_key> <minus> <Right>         : "→" U2192 # RIGHTWARDS ARROW
<Multi_key> <minus> <Left>          : "←" U2190 # LEFTWARDS ARROW
<Multi_key> <minus> <Up>            : "↑" U2191 # UPWARDS ARROW
<Multi_key> <minus> <Down>          : "↓" U2193 # DOWNWARDS ARROW
<Multi_key> <minus> <minus> <Right> : "⇌" U21cc # EQUILIBRIUM ARROW
<Multi_key> <minus> <minus> <Left>  : "⇄" U21c4 # BACKFORWARD ARROW
<Multi_key> <minus> <minus> <o>     : "⦵" U29B5 # Circle with Horizontal Bar

# tweak for my favourite British layout on a US keyboard
<Multi_key> <#> <#>                 : "\" U005C # BACKSLASH
 

P.S. useful links https://tuttle.github.io/python-useful/compose-key-cheat-sheet.html
https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts
https://en.wikipedia.org/wiki/Phonetic_Extensions
P.P.S. the missing signs can be inserted as Ctrl+Shift+U+XXXX+Enter, 2212 for −, 21cc for ⇌, 21c4 for ⇄, 2191 for ↑, 2193 for ↓.

Nasty PBC

In most cases the output gro files cut particles at the PBC borders. This does not look too nice to me, when visualized in VMD. Fortunately, it can be fairly easily fixed by:

gmx trjconv -f NVT.xtc -s NVT.tpr -n index.ndx -o NVT_mol.xtc -pbc mol

or, simpler, in the VMD terminal:

pbc unwrap

pdftk allmighty

For the Estonian chemistry competition I had to work a lot with pdf-s. pdftk utilite turned to be extremely useful.
To split pdf-s into peaces:
pdftk in.pdf cat N output cut.pdf
To rotate pdf-s:
pdftk in.pdf cat 1east 2east output rotated.pdf
To merge pdf-s:
pdftk in*.pdf cat output merged.pdf

Working abroad

Sometimes for some reason some VPN might not work as one expects. Then one can login to a node with a key.

First, check if you have a public key already. On your own computer in a terminal run:

cat ~/.ssh/id_rsa.pub

If this command worked, then skip the next step. If an error appeared, run this:

ssh-keygen

It will ask for a password. This is the password you give to the key. You can make one without password, in which case it will not ask for a password each time you try to use it.

You must have an access to the cluster somehow to run the following command:

ssh-copy-id -i ~/.ssh/id_rsa.pub <your-username>@cluster-address

Well, you can also just copy the string from id_rsa.pub on your machine to the id_rsa.pub on your cluster.

This trick does not work for all machines. So, you might use the established connection to connect to other machines. In my case I wanted to work with some notebooks, so I did:

ssh -N -L localhost:PORT1:localhost:PORT2 <your-username>@cluster-address

and so it worked.

Installation of LibXC 3.0.0 trunk + GPAW1.1.0 + ASE

For a long time we wanted to try SCAN functional implemented in LibXC using GPAW. However, at first, fresh LibXC 3.0.0 did not work. Then we could not compile GPAW. Unit today. Here is a recipe that works for Fedora 25.

First, let’s prepare clean Fedora 25:

sudo dnf groupinstall "Development Tools"
sudo dnf groupinstall 'C Development Tools and Libraries'
sudo dnf install gcc-gfortran python-devel zlib-devel
sudo dnf install python-pip blas-devel lapack-devel atlas-devel openblas-devel rpm-build
sudo dnf install openmpi-devel scalapack-openmpi-devel blacs-openmpi-devel
sudo pip install --upgrade pip
pip install --upgrade --user numpy scipy matplotlib
sudo dnf install nano

Nano is installed in case you don’t like vi or emacs. Some packages might not be needed, but we installed them anyway.

LibXC compilation:

svn co http://www.tddft.org/svn/libxc/trunk/ libxc
cd libxc
autoreconf -i
./configure --enable-shared --prefix=/home/USER/xc
make -j N
make install

After compiling LibXC add these lines to your .bashrc:

export C_INCLUDE_PATH=/home/USER/xc/include
export LIBRARY_PATH=/home/USER/xc/lib
export LD_LIBRARY_PATH=/home/USER/xc/lib

Let’s install ASE using pip, because it is easy.

pip install --upgrade --user ase

Get the GPAW source code and remove in libxc.c in c/xc/ line “xc_mgga_x_tb09_set_params(self->functional[0], c);”. Them compile GPAW with python setup.py install --user.  YOu might want to add the .local/bin to the path.

Don’t forget to get setups. E.g. execute gpaw install-data DIR. After that try this example:


from ase import Atom, Atoms
from gpaw import GPAW
xc = 'MGGA_X_SCAN+MGGA_C_SCAN'
bulk = Atoms([Atom('Li')], pbc=True)
k = 4
g = 8
calc = GPAW(gpts=(g, g, g), kpts=(k, k, k),
xc=xc)#, txt=None)
bulk.set_calculator(calc)
bulk.get_potential_energy()

pdf optimisation

While preparing an online report for the PUT1107 project, I encountered a limit for uploaded pdf-files as low as 3 Mb. Thus, I was forced to reduce the pdf-file size to this limit as follows:

1. I merged a set of articles into one files: pdftk 1.pdf 2.pdf 3.pdf output set.pdf

2. Then I reduced the size of the resulting file: gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf set.pdf

The size was reduced by more than 50% with almost the same visual quality.

Taming the equations in Libreoffice

Working on large documents with many equations in a word processor is a torture. In my case, booklets of chemistry problems require a lot of work. For certain reason I prefer to use LibreOffice. When is needed to reformat all equations in a document the following macro is very useful:

Sub FormulaFontSizeChanger

o = ThisComponent.getEmbeddedObjects()

fontSize = 12

fontFamily = “Arial”

For i = 0 to o.count-1

if (not IsNull(o(i))) and (not IsNull(o(i).Model)) then

o(i).Model.TopMargin = 0

o(i).Model.BottomMargin = 0

o(i).Model.LeftMargin = 0

o(i).Model.RightMargin = 0

o(i).Model.BaseFontHeight = fontSize

o(i).Model.FontNameVariables = fontFamily

o(i).Model.FontVariablesIsItalic = 1

o(i).Model.FontNameFunctions = fontFamily

o(i).Model.FontNameNumbers = fontFamily

o(i).Model.FontNameText = fontFamily

o(i).Component.BaseFontHeight = fontSize

o(i).ExtendedControlOverEmbeddedObject.update()

endif

Next i

End Sub

 

P.S. The script might be useful also when writing a thesis with a lot of chemistry inside and many Zotero references. LaTeX might not be so comfortable, and in Word one is still limited with few math fonts.

Travel tips

Summer is a great time for research visits, schools as well as vacations. Here is my check list for a safe trip from 2016.

  • Passport, ID card and driving license (and a secure place for these documents)
  • A bottle of water (stay hydrated)
  • Snacks or meal replacement bars for sustenance during the trip
  • Cough drops
  • Wet wipes and napkins
  • Something to read or listen (headphones)
  • A notebook or something to write on
  • A scarf or something to protect your neck from cold
  • A cap or something to close your face while sleeping
  • Sunglasses
  • Compression socks
  • Lightweight and water-resistant pair of shoes
  • Some coins and some cash
  • A universal adapter

Here is what I would like to add to the list in 2023 (thanks to chatGPT for ideas):

  • A portable charger or power bank to keep your devices charged
  • Hand sanitizer or disinfecting wipes to keep your hands and surfaces clean
  • An extra set of clothes or a change of underwear in case of unexpected delays or lost luggage
  • Maps or a guidebook for your destination to help you navigate and plan your trip
  • A medical mask!

size limits of email boxes

Email is an essential part of the work. Sometimes the box gets full, thus preventing the work. With gmail there is a trick how to find and delete large emails that occupy most of the space. To search for attachments greater than 5 Mb search “size:5000000”.