Using LS_COLORS to colorize your shell by filename / filetype


Messing with LS_COLORS

Before and after

Small steps

I’ll first set LS_COLOR='' Below, you’ll see that nothing is colored, except for the directories which are blue, because of another environment variable called DIR_COLORS. We are going to learn how to tell LS_COLORS to colorize files by name.

I usually had colored by files by whether or not they were executable, a symbolic link, etc, which something like LS_COLORS='di=96:fi=0:ln=33:ex=1;92' which sets

  • directories to 96 (cyan)
  • files to 0 (default)
  • links to 33 (yellow)
  • executables to 92 (green)

and so on.

Go further

I realized recently you can set LS_COLORS to colorize files by name. This is useful in times where you know many types of files will be present in a directory and you want to see what they are right away. Or even if its not that useful, it’s still pretty cool.

Here I know I have .tex, .aux, .log, .bib, .png, .zip, and .pdf all in this directory. I do LS_COLORS='*.png=96:*.aux=90:*.bib=94:*.log=1;90:*.pdf=1;93:*.tex=93:*.zip=91:di=1;94'

Notice how you can set bold and a color with 1;COLOR.


Extreme Measures

Since you can take this to extremes, I did.  I quite like it – I use colored pens in real life, so when I discovered this, I just had to …


:) Enjoy the pretty prompts!

Posted in Computing, Programming, Stuff Tagged with: , , , , , , , , , , ,

Making your command line prompt cool – exploring PS1, PROMPT_COMMAND and other environment variables


Let’s start with an extremely basic prompt so we can see how subtle changes affect it. If you export PS1=’a string of text’, your prompt will be exactly ‘a string of text’, unless you use one of the special PS1 codes ‘\u, \h, \w’:

Other PS1 codes include:

u - the current user's username
h - the current machine's hostname
j - the number of jobs managed by this shell
@ - the current time (12 hour format)
d - the current date
w - path of the current working directory
W - just the current working directory
e - an ASCII escape character (033)
n - adds a newline character

Adding colors is the next step. Bash reads a color code and colorizes everything after that, until it reads a new one. And I mean everything. You need to end your PS1 with the color code you want to type in.

In pseudocode,
export PS1='code1 item code2 item2 coode3 item3'

This results in item having color for “colorcode”, item2 having colorcode2, item3 having colorcode3, and we exit with colorcode4 which will be the color of your commands you type.

We can combine several codes together if they are compatible. For example, 0 is default, 1 is bold. So 1;32 means bold and yellow. \033[1;36m means, to bash “beginning a color code, make it bold, and make it cyan.” You can keep adding color codes, and if they don’t override the last one, they will just add:

echo -e '\033[1m make it bold, and \033[36m make it \033[31m red \033[31;103m with a yellow background'

My usual PS1 is: export PS1='\[\033[1;33m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;96m\]\$ \[\033[0m\]', or something like this. Let’s break it down by bolding the color codes

export PS1='\[\033[1;33m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]'

export PS1='\[\033[1;33m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;96m\]\$ \[\033[0m\]'

The PROMPT_COMMAND environment variable executes a command each time your prompt returns to you. It can be used to give your PS1 some dynamic ability – the ability to update depending on the current state of the system, outside of the limited PS1 codes. The only way I’ve been able to use it meaningfully is to print the system memory available.

export PROMPT_COMMAND='echo -en "\033[m\033[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"\033[1;38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB ""'

Messing with LS_COLORS

I’ll first set LS_COLOR='' Below, you’ll see that nothing is colored, except for the directories which are blue, because of another environment variable called DIR_COLORS. We are going to learn how to tell LS_COLORS to colorize files by name.

I usually had colored by files by whether or not they were executable, a symbolic link, etc, which something like LS_COLORS='di=96:fi=0:ln=33:ex=1;92' which sets

  • directories to 96 (cyan)
  • files to 0 (default)
  • links to 33 (yellow)
  • executables to 92 (green)

and so on.

I realized recently you can set LS_COLORS to colorize files by name. This is useful in times where you know many types of files will be present in a directory and you want to see what they are right away. Or even if its not that useful, it’s still pretty cool.

Here I know I have .tex, .aux, .log, .bib, .png, .zip, and .pdf all in this directory. I do LS_COLORS='*.png=96:*.aux=90:*.bib=94:*.log=1;90:*.pdf=1;93:*.tex=93:*.zip=91:di=1;94'

Notice how you can set bold and a color with 1;COLOR.


Since you can take this to extremes, I did.  I quite like it – I use colored pens in real life, so when I discovered this, I just had to …


:) Enjoy the pretty prompts!

Posted in Computing, Programming, Uncategorized

Useful shell aliases


Redo the last command as if I had sudoed

alias please='sudo $(fc -ln -1)'

Use this all the time

(Ubuntu) Install a package I don’t have but tried to use

alias ok='eval $($(fc -ln -1) 2>&1 | sed -n 2p)'

Free up system memory

alias freemem='echo "echo 1 > /proc/sys/vm/drop_caches" | sudo sh'

For this example, I started to copy a 4 GB file so that I knew my ram would start to be used up. Here, you can see my memory available on the left is decreasing as I hit enter for purposes of demonstration. (displaying my system memory is done using the PROMPT_COMMAND environment variable). You can see when I use freemem, I get my memory back.

Colorize cat!

alias dog='pygmentize -g'

This works like cat in that it dumps the contents of a file to the screen. It does not concatenate files. But it does read the shebang and print the code with syntax highlighting, if it can. Requires python-pygmentize

Find a file or directory in working dir matching a string.

I use this one a LOT! Ignores case and prints line number.

alias lsg='ls -la| grep -ni'

I have many variants of this one, most notably to do this recursively through directories beneath you: ls -laR | grep -in

If you don’t have pygmentize for my dog alias, make installing it a breeze

(Ubuntu) obviously

alias gimme='sudo apt-get install'


Posted in Computing, Programming Tagged with: , , , , , , , , , , , ,

Bitcoin-data manipulaton and plotting in python



plot.png -

I wrote a python mini-api to manipulate and visualize the price of bitcoin historically using the coinbase version 1 api.

bitcoin-price (python module)

Get bitcoin price data from the coinbase API and parse it into an easily manipulated form.

>>> from fast_dump_v22 import *
>>> get_page(1)

Will return all the data on page 1 of coinbase’s bitcoin price API (this is the latest data).

You can almost always turn on optional debug statements

>>> get_first_N(3, show=True)
... fetching first 3

You can get all the price data that coinbase has

>>> get_all(show=True)
... getting page 1
... getting page 2
... getting page 3
... getting page 4
... getting page 5
... getting page 6
... getting page 7
... getting page 8
... getting page 9
... etc ...

All the ‘get_*’ functions return a price_data string, which is interlaced timestamps and prices littered with newlines and commas. You can print them to see what is going on more clearly:

>>> print(get_page(1))

Turn on the optional show switch for printing large vectors

>>> prices(get_page(11), show=True)
... returning 11000 prices in specified range ...

You can use prices(data)[k] and timestamps()[j] to return the kth price in data, or the jth timestamp in data.

>>> data = get_page(1)
>>> prices(data)[4]
>>> prices(data, index=4)

are two equivalent ways of returning only the 4th price in the requested range (in this case, page 1). This also works for timestamps.

>>> timestamps(get_page(1)+get_page(2))[1166] == timestamps(get_first_N(2), index=1166)

This shows the expressiveness of this module. In general:

>>> prices(get_page(2)) == parse(get_page(2))[0]

prices() and timestamps() are just functions that return a parsed() object having a specific index, or indices.

>>> parse(get_page(1)+get_page(2)+get_page(3))[0] == prices(get_first_N(3))
>>> parse(get_page(2)+get_page(3))[0] == prices(get_range(2,3))

The parse() function is there to manually control the outputs instead of just getting prices, or timestamps

>>> x = parse(get_page(1))
>>> x[0][0]
>>> x[0][1]
>>> x[1][1]

As you can see, parse(price_data)[0][k] returns the kth price in the list. Indices [1][k] return the kth timestamp.

The parse() function takes care of some weird edge cases:

>>> get_first_N(3) == get_page(1)+get_page(2)+get_page(3)
>>> parse(get_first_N(3)) == parse(get_page(1)+get_page(2)+get_page(3))
>>> x = get_page(1)
>>> y = get_range(2,7)
>>> prices(get_first_N(7)) == prices(x+y)

In general,

OPERATOR( get_page(1) + get_page(2) + ... + get_page(k) ) == OPERATOR(get_first_N(k))

where OPERATOR is parsed(), prices(), or timestamps(). We also know prices() can obviously display and return ranges of values. When returning large vectors, you can verify their length by setting show=True. The “show” parameter is optional for all get_* functions and provides some information about the operation being performed.

>>> print( prices(get_first_N(11), show=True) )
... returning 11000 prices in specified range...

since each page is a thousand pairs of values (timestamp, price).

>>> len(prices(get_page(2))
>>> prices(get_page(2)) # returns a long list

fast_dump_v1* are older versions that are somewhat different. They are designed to store the fetched data in the .data directory. This in v2*, this was abandoned in favor of stdout redirection.
// 2015

Posted in Bitcoin, bitcoin-core, btc, Computing, Electronics and Engineering, Programming, Statistics, Stuff, Uncategorized Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Getting started with Bitcoin the “right way” – encrypted wallets, bitcoin core, and linux


A brief introduction to getting started with bitcoin on a linux distribution

For the impatient: Skip to step 1

Bitcoin is one of the most interesting technologies we have seen emerge in the past ten years. And it confuses everyone who sets out to use it.  This post is my definitive guide to beginning your journey with bitcoin the right way.


To me, the right way includes, but is not limited to:

  • Running bitcoin on a linux machine.  My reasons for this are too many to really list here, but suffice it to say that since linux is widely regarded as the most secure operating system available, and the usage of bitcoin involves being your own bank, using bitcoin on linux is the best way to ensure your coins stay safe.
  • Using the bitcoin-core wallet software.  There are other wallets available.  You actually don’t even need a wallet software to own bitcoins or even spend bitcoins.  However, if you want to understand how bitcoin works under the hood – which you should, because you are going to be your own bank, you should use this software.
  • Using the command line to do bitcoin things. Actually, using both the GUI and the command line is the way to go.  This tutorial (this is part 1 of 2) will be a command-line-centric description because afterall, I’m trying to show you the right way to do things.

But that’s just, like, your opinion man.

It is. This is my blog.

You shouldn’t necessarily trust me or anyone – bitcoin isn’t about trust. But if you google “altoidnerd”, you’ll find that I have been around the bitcoin eco-system for quite some time. That’s all I can tell you.

Screen Shot 2015-09-10 at 8.31.28 PM

There are just so many wallets available – why bitcoin-core?  Because I have been using it for years, I have a very good method of keeping my coins safe, and that is what I am sharing with you today.  Use it- it is THE wallet.

But altoidnerd, I don’t want to run linux. I like windows / OSX

I am a linux and an OSX user.  So please understand the scope of my knowledge includes these operating systems. If you want to use OSX, most of this tutorial will make sense with minor changes perhaps.

Screen Shot 2015-09-10 at 8.32.59 PM

If you want to use windows, that’s ok, I’m not going to judge you. Bitcoin-core is available for windows as well. Please understand however, I am not a windows user, so I will not be able to give you “the definitive bitcoin windows guide”. You can still read on, however, since you can apply much of this tutorial to usage of bitcoin-qt’s debug window instead of the command line.

Step 1: Download and install bitcoin-core

Navigate to’s official download page and select the bitcoin-core distribution for your operating system. And do choose linux (tgz).  Do that because you should be running linux.  But if you aren’t, even though you should be, choose the distribution for your operating system. Extract and install the client.

The “right way”

To really take control of things, and understand what is happening, you’re going to want to run bitcoin software from the command line. Though it isn’t really necessary to download the thing from the command line, I’m going to describe that here because this tutorial is the first installment of a start to finish command line approach. For a sneak peak of what I mean, see an earlier post where I described how to use bitcoin-core to generate QR codes without having to trust shady ass websites.

Go to your home directory and create a new directory just for bitcoin.  This is not a necessary step, but once again, this is my “right way” tutorial and I will explain reasons for this later on.  Enter the directory, and download the tarball with the “wget” command.  The extract the tarball like so:

    cd ~

    mkdir bitcoin

    cd bitcoin

    wget ''

    tar -xzvf bitcoin-0.11.0-linux64.tar.gz



Sweet.  Now change directory to where the binaries are,

    cd bitcoin-0.11.0/bin/

and launch “bitcoin-qt” (qt means its the GUI version).


It’s going to show you the dialogue box below and ask you if you’d like to use the default directory. Do it. Click “OK”.




You’ll see a friendly startup screen if you’ve done things right!




Step 2: Encrypt your wallet, and wait a few days

Bitcoin-core is called a “full-node” implementation, which means the first time you start it on your machine, it’s going to download every single bitcoin transaction that has ever taken place.  Wait until the blockchain is synced to start making transactions.

In the mean time, you need to set a passphrase for your wallet.  This is super important.  In the upper left corner of bitcoin-qt, go to settings -> Encrypt Wallet, and set a very strong passphrase.


This will make it impossible for anyone to send bitcoins from your wallet without entering your password:


Just make sure you:

    • Make your password extremely long. I don’t know if there is a length limit in the bitcoin-core code or not. Regardless, seriously push your personal boundaries on what you think a safe password is. Make it super duper long, and impossible to guess. Wise men have discussed password strength to a great extent. Pick a strong password. 20+ characters. Go for 30. No 40. Just make it long, and keep it an absolute secret.
    • Never, ever lose or forget this password. If you lose or forgot your password, your coins will be unspendable forever. Neither you, nor anybody on earth, nor God himself will be able to spend your coins. Your coins will be effectively lost.

Picking a strong passphrase makes security so, so easy

Once you encrypt your wallet, you can copy and store wallet.dat everywhere (I explain wallet.dat in great detail in “Step 3”). I literally have copies of my main wallet.dat on 6 or 7 computers, because come hell or highwater, I will always be able to find a copy of my wallet.dat file. I suggest you do the same. Here is why strong encryption and insane redundancy works:

  • If your password is ridiculously long, you can be very lazy and downright cavelier about where you keep your wallet.dat, because even if someone finds the wallet file, they wont be able to do a damn thing with it. They won’t be able to spend your coins without your passphrase.
  • This means that you can make copies of wallet.dat and store them like literally everywhere, on all your machines, three times over. In the cloud. On your mom’s computer. Hell, theoretically speaking, you can post your encrypted wallet.dat on the internet and just about everyone will have a copy, and be unable to spend your coins, because they don’t know your password. Someone remind me to put some coins into an address, and post the encrypted wallet online to prove my point.

    Bottom Line

    If you encrypt your wallet like a boss, you never forget your password, you never tell anyone your password, and you copy the file to everywhere you possibly can imagine, you will never lose your coins. And nobody will be able to steal them from you. Seriously, nobody. It is computationally impossible.

    Step 3: Understand what you just did on your computer

    Let’s break it down this way. Here are some things that just happened when you launched bitcoin-qt for the first time:

    • A hidden directory ~/.bitcoin was created. It contains among other things the single most important thing ever: a file called wallet.dat. This file is critical. ~/.bitcoin/wallet.dat contains all of your private keys. wallet.dat is life. When you see in headlines in the news like “Frustrated gentleman quite upset having lost a usb jump drive containing 100,000 BTC“, it means he doesn’t have a copy of wallet.dat, so neither he, nor anyone on earth, nor God himself can spend his coins anymore.
    • Your computer started downloading the blockchain. The blockchain is a record of every bitcoin transaction ever to have taken place. This will take a few days. As of today, the blockchain is about 42 gigabytes. Make sure you have space for it.

    Do not delete your wallet.dat file. Just don’t. If you want to start a new wallet, instead of deleting wallet.dat, just rename it to something else, like wallet.dat.old, restart bitcoin-qt, and it will create a new wallet for you. Keep your wallets people. Keep them good.


    Notice how I have a file called wallet.dat.default? That’s because I never delete a wallet. When I installed bitcoin on this computer, I moved the wallet.dat that stores my coins into ~/.bitcoin/, but first I renamed the existing file so I can keep it. Because, why not? I’m telling you – don’t delete a file called wallet.dat, because mistakes happen, and its better to have hundreds of files named wallet.dat.* than it is to lose your coins.

In my next post, I will describe some of the features of the bitcoin-qt debug window, bitcoind and its helper bitcoin-cli.  You can do interesting things, like import new keys, or convert keys to qr-codes.

If you have ay questions, please feel free to comment or contact me.
If you liked this post, you can donate bitcoins to me here: 12gKRdrz7yy7erg5apUvSRGemypTUvBRuJ
Learn about the author here:

Posted in Bitcoin, bitcoin-core, btc, Computing, Electronics and Engineering, Programming, Stuff Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

How import a bitcoin address private key into breadwallet (iOS) with a QR code using bitcoin-core for Ubuntu / Linux


On encoding private keys from Bitcoin-core as QR codes for use in paper wallets, other wallet software, etc …

Note: Breadwallet will not import the private key upon scanning the qr code. It will offer to transfer the funds in that address to your breadwallet keyring.

Breadwallet, an awesome open source iOS bitcoin SPV client, allows you to import a private key for use within breadwallet.  So, if you’re a user of bitcoin-core, and want to be able to spend some of your funds you have there with breadwallet, you’ll need to create a QR code of your private key to scan it with breadwallet.

Install qrencode

This tutorial uses qrencode, an open source string to QR converter. The source can be found here:

Alternatively, you can install qrencode on ubuntu/debian through repositories

sudo apt-get install qrencode

Then, as of bitcoin-core version 0.11.0 you’ll need to run bitcoind rather than the GUI bitcoin-qt. If you’re using an old version of bitcoin-core that does not have the bitcoin-cli tool, you can get the latest version of bitcoin-core and extract it without having to verify the blockchain again or mess with wallet.dat – your ~/.bitcoin directory will remain unchanged.

Get the newest version of Bitcoin-core

wget ''
tar -xzvf bitcoin-0.11.0-linux64.tar.gz
cd bitcoin-0.11.0/bin

You should see the executables for the bitcoin-core suite here.

Run bitcoind and create your QR

Be sure you quit any versions of bitoin-qt or bitcoind that are already running, then start the bitcoin daemon

./bitcoind &

The & operator makes sure bitcoind detaches from your terminal so you can keep going.

Now you are ready to get a QR code for your desired address. Is your address is “addr”, you can generate a QR code of your private key without ever showing your private key on screen in plain text. Just do:

./bitcoin-cli dumpprivkey "addr" | qrencode -o ~/Desktop/Key.png

Or better yet, if you want to create a new address and QR-encode its private key,

addr=$(./bitcoin-cli getnewaddress)
./bitcoin-cli dumpprivkey $addr| qrencode -o
echo "private key dumped for: "$addr

The QR code should appear on your desktop. Below is a screen shot of me doing an example where I create a new address, and get a QR for its private key.  Enjoy!


Note that if your wallet is password protected (which it really should be), you’ll need to first do

./bitcoin-cli walletpassphrase "your_password" 100

where the argument 100 means the wallet will allow all actions (like spending, or dumping keys) for 100 seconds. That should be plenty of time.

Posted in Bitcoin, bitcoin-core, btc, Computing, Programming, Scamcoins, Stuff Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

How random is /dev/random? Visualizing the output of /dev/random using hexdump, dd, and python

Screen Shot 2015-05-30 at 8.25.23 AM

I wrote a python script that will plot the output of /dev/random in a few ways so you can see just how random it is.

Make a line plot:

Screen Shot 2015-05-30 at 9.08.52 AM

Make a histogram:

Screen Shot 2015-05-30 at 9.08.02 AM



Do be careful when using the dd command. It can wipe out your filesystem if you set the outfile incorrectly. I’d recommend not changing the option of=”./randfile”.

Edit the block size and/or block count in *.sh to change the output resolution:

Screen Shot 2015-05-30 at 8.33.37 AM

You may need root privileges to use the dd command.

Remember that on OSX, /dev/random and /dev/urandom are identical.  On linux, to get 100 blocks as I have, you may have to use /dev/urandom (unlimited random). The linux case is probably more interesting as the outputs are different.  How exactly DO they differ?

OSX is known to use Yarrow-160 a cryptographic algorithm that makes use of hash functions (specifically SHA1) to create “unlimited” seemingly-random bits from a finite entropy pool.

As far as I know, linux does not. Linux will wait for more entropy when /dev/random is used as opposed to /dev/urandom.

See personal page and github repository.

Posted in Computing, Programming, Statistics, Stuff

Do copies of Hamlet exist embedded in the digits of pi?

I know Vi Hart discussed it, but she may have not been the first to entertain the idea. Not sure. The question is do they digits of pi contain copies of hamlet?

Yes, yes they do. Not just copies of Hamlet, but actually copies of every book imaginable are contained within the digits of pi an infinite number of times.

Using software package pi and simple shell commands,

pastebin of shell commands

I found that any N digit sequence probably appears within the first 10^N digits of pi [1]; moreover, the sequence would appear about 10 times in the first 10^(N+1) digits of pi, 100 times in the first 10^(N+2) digits, etc.

For example, lets say our sequence is the last 4 digits of my phone number – 1345
That’s 4 digits, so if I scan the first 104 digits of pi, sure enough, my phone number occurs 1 time. If I scan 105 digits, it occurs 12 times. For 109 digits, it occures like 98 times. Its clockwork. See below.

altoidnerd@HADRON:~$ pi 10000|grep -o 1345|grep -c 1345
altoidnerd@HADRON:~$ pi 100000|grep -o 1345|grep -c 1345
altoidnerd@HADRON:~$ pi 1000000|grep -o 1345|grep -c 1345
altoidnerd@HADRON:~$ pi 10000000|grep -o 1345|grep -c 1345

Anyway, so the question is how many digits of pi would we need to search through to likely find about 1 or 2 copies of hamlet in the sequence?

So I got hamlet in plaintext from 2 sources. I found that hamlet when compressed from plain text to a tar.gz archive, the average size was 69 KiB. Therefore, (I think?) that means to represent hamlet as just a binary integer, it would have 69 x 8 x 1024 digits = 565248 digits.

To get the number of digits in base 10, we multiply by log_10 (2) +~ .69 so the base ten hamlet would be like a sequence of about ~390,000 digitsm (0-9).

Ok so back to pi. How many digits of pi must we scan to probably find a string of length 390,000? That would be 10^390000 digits. That’s a lot of pi, but pi has got enough digits to spare. We should see approximately 1 copy of hamlet in the first 10^390000 digits of pi.

Even cooler is that if we just increase the power by 1, we should see 10 hamlets; increase the power by 2, and we should get 100 copies of hamlet. So quickly, we end up with infinite hamlets in the digits of pi. And not only hamlet … this argument should would for any book.

[1] This is not too surprising since pi is believed to be a normal number, though this is unproven.

Posted in Computing, Electronics and Engineering, Physics and Mathematics, Stuff Tagged with: , , , , , , ,

Calculations of the EFG tensor in DTN using the GIPAW method with CASTEP and Quantum Espresso software

One important difference between NQR and NMR is that for NQR, the transition frequency is site specific and cannot be chosen by the experimenter. In NMR studies, the excitation frequency of the nucleus is just the gyromagnetic ratio times the applied field. Thus, the difficulty in NMR is controlling the uniformity of the applied static B. However, the experimenter is free to choose an operating frequency by adjusting B. For NQR, the transition frequency is proportional to the electric field gradient (EFG) at the nuclear site, which is entirely a property of the substance and a function of temperature. While it is theoretically possible to apply a prescribed EFG in the lab, it is unfeasible as the EFG’s in crystal strcutures are often on the order of many kV/m^2. Thus the particular difficulty in NQR spectroscopy is locating the resonance in the first place, which is much like combing the desert if the apparatus runs at a fixed frequency. The home made pulsed superheterodyne spectrometer used in the trial experiments has proven to have excellent resolution. However, it has essentially no ability to perform frequency sweeps as is done in continuous wave methods. The operator must choose a relatively narrow band (< 1 MHz) to target, and design a custom bridge, tank, and receiver configuration just for small band. Band switching is non-trivial with high resolution pulsed techniques.

At one time, it was not possible to calculate the EFG for all but the simplest of structures. However, DFT calculations have become very potent and accessible in the last decade. Beginning in June of 2013, Calculations of the EFG tensor in dichloro-tetrakis-thiourea-nickel NiCl_2 [SC(NH_2)_2]_4 were made using the GIPAW method with closed source CASTEP software (by then graduatre student Dr. Tim Green at Oxford University, with advisor Dr. Jonathan = Yates). Then in October of 2013, Dr. Ari Seitsonen and I repeated the calculation at ETH in Zurich using the open source DFT-GIPAW package Quantum Espresso (QE).

The two calculations show good agreement in many respects and indicate that the 35Cl resonance frequencies in DTN are likely about an order of magnitude lower than initially believed. Because chlorine NQR transitions occurred around 30 MHz in both para-dichlorobenze and NaClO_3, DTN was initally thought to be likely to show 35Cl NQR in the 29-31 MHz band. This was tested first by Robert Baker (REU Student, 2010) and then in 2012-2013 by myself to no avail.

There is no particular reason 35Cl should have to have a resonance in this 30 MHz band. 35Cl NQR measurements have been made in many materials below 18 MHz and above 60 MHz. A high degree of symmetry in a given structure can result in very low NQR frequencies, with correspondingly very poor S/N. Though all nuclei with spin S >= 1 are guaranteed to have at least one non-zero NQR transition frequency, NQR is not always found. This is likely due to poor S/N when the EFG is small and the transition frequency is very low.

Evidence for the validity of the DFT calculations is that the prediction for NaClO3 35Cl NQR matches observation remarkably well. Additionally, since both DFT packages output the full EFG tensor, the NQR transitions for 14N were also predicted by the same calculations. There are sixteen nitrogen nuclei in each unit cell of DTN (right). DTN contains 4 independent thiourea molecules in each unit cell, each having 4 nitrogen centers.

The NQR frequencies calculated by CASTEP and QE for 14N in DTN match very well with those observed in pure thiourea from literature (David H. Smith and R. M. Cotts). The paper by Smith and Cotts quotes NQR in 14N in pure thiourea NQR at 2.6 MHz and 2.0 MHz for inequivalent sites at room temperature. In the absense of any DFT calculation, the 14N resonance in pure thourea would be a best first guess as to the NQR transition for 14N in DTN.

As the NQR frequency at a given nuclear site is directly proportional to Vzz (the electric field gradient, or stretching), crystals with a high degree of symmetry will have low NQR frequencies. Inspection of the crystal structure superficially indicates a widely symmetric nuclear distribution about the chlorine sites, as the thiourea groups are distributed symmetrically and the structure parameters show each Cl is roughly equidistant to both adjacent Ni nuclei.

The quadrupole coupling constant and NQR transitions
The quadrupole coupling constant Cq is defined as

 Cq = e*Vzz*Q/h [1]

where Vzz is the largest absolute eigenvalue, e is the electron charge, Q is the quadrupole moment and h is planck's constant.

We consider a nucleus of spin S and define

 A = eVzzQ / (4S(2S-1)) [2]

where S is spin and Q is the quadrupole moment. Then the NQR frequency or (frequencies) are given by

 f_nqr = 3|A| / h (2 |m| +1) [3]

where m is the lowest of the two levels m and m+1 over which a transition has occurred. For integral spins there are S unique transitions. For half integral spins there are S – ½ unique transitions.
NQR is observed in nuclei with I=3/2, I=5/2 and I=7/2. For I=1/2., there are no transitions. The I=5/2 and I=7/2 are indeed complicated, but for I=3/2 there is a degeneracy that causes there to be one frequency of half the quadrupole coupling constant, which makes the single transition frequency in the case of I=3/2 equal to one half the quadrupole coupling constant Cq = eVzzQ/h = e^2Qq/h.

NQR Frequencies for half-integral spins
Chlorine has I = 3/2 so there is only 1 transition. Using I=3/2 in the formula above, we obtain

 f_nqr = (1/2) eVzzQ/h = (1/2) Cq [4]

for axially symmetric field gradients. For non-axially symmetryic gradients, we define the assymetry parameter η = (Vxx-Vyy)/Vzz. η=0 in the axially symmetric case, where Vzz is the only nonzero component. When η is non-zero, the transitions for I=3/2 are

 f_nqr ~ (1/2) eVzzQ/h * (1 + 1/3 η^2)^(1/2) [5]

In general for half integral spin of I = n/2 n 3, 5, 7,... use what is given in Hahn and you should find the coefficients are 3/10, and 3/20 for I=5/2

 f_nqr_[5/2 --> 3/2] = (3/10) eVzzQ/h [6]
 f_nqr_[3/2->1/2] = (3/20) eVzzQ/h [7]

NQR frequencies for integral spins
For integral spins, we use the formula [2] again. For for I=1 and an axially symmetric field gradient (η=0) , the NQR transition frequency is

 f_nqr = (3/4) eVzzQ/h = (3/4) Cq [8]


Cl 1 Cq: 8.4298 (MHz) Eta: 0.1272
Cl 2 Cq: 0.1705 (MHz) Eta: 0.5898
Cl 3 Cq: 0.1866 (MHz) Eta: 0.5340
Cl 4 Cq: 8.4513 (MHz) Eta: 0.1264
Cl 1 Cq: -15.7965 (MHz) Eta: 0.0089
Cl 2 Cq: -16.9778 (MHz) Eta: 0.0048
Cl 3 Cq: -16.9515 (MHz) Eta: 0.0048
Cl 4 Cq: -15.8271 (MHz) Eta: 0.0089

 Cl 1 Cq= 9.4969 MHz Eta=-0.00000
 Cl 2 Cq= -0.9388 MHz Eta= 0.00000
 Cl 3 Cq= 9.4869 MHz Eta= 0.00000
 Cl 4 Cq= -0.9298 MHz Eta= 0.00000

N 1 Cq: -3.7067 (MHz) Eta: 0.3400
N 2 Cq: -3.3560 (MHz) Eta: 0.4226
N 3 Cq: -3.6918 (MHz) Eta: 0.3463
N 4 Cq: -3.3621 (MHz) Eta: 0.4256
N 5 Cq: -3.6917 (MHz) Eta: 0.3468
N 6 Cq: -3.3533 (MHz) Eta: 0.4231
N 7 Cq: -3.7068 (MHz) Eta: 0.3410
N 8 Cq: -3.3535 (MHz) Eta: 0.4228
N 9 Cq: -3.6920 (MHz) Eta: 0.3466
N 10 Cq: -3.3611 (MHz) Eta: 0.4251
N 11 Cq: -3.7067 (MHz) Eta: 0.3409
N 12 Cq: -3.3524 (MHz) Eta: 0.4230
N 13 Cq: -3.7073 (MHz) Eta: 0.3399
N 14 Cq: -3.3563 (MHz) Eta: 0.4225
N 15 Cq: -3.6927 (MHz) Eta: 0.3469

N 1 Cq: 3.0165 (MHz) Eta: 0.8408
N 2 Cq: -2.6850 (MHz) Eta: 0.9198
N 3 Cq: 3.0154 (MHz) Eta: 0.8423
N 4 Cq: -2.6885 (MHz) Eta: 0.9216
N 5 Cq: 3.0164 (MHz) Eta: 0.8419
N 6 Cq: -2.6841 (MHz) Eta: 0.9213
N 7 Cq: 3.0179 (MHz) Eta: 0.8414
N 8 Cq: -2.6854 (MHz) Eta: 0.9186
N 9 Cq: 3.0188 (MHz) Eta: 0.8421
N 10 Cq: -2.6833 (MHz) Eta: 0.9207
N 11 Cq: 3.0214 (MHz) Eta: 0.8411
N 12 Cq: -2.6802 (MHz) Eta: 0.9177
N 13 Cq: 3.0199 (MHz) Eta: 0.8406
N 14 Cq: -2.6798 (MHz) Eta: 0.9189
N 15 Cq: 3.0198 (MHz) Eta: 0.8417
N 16 Cq: -2.6788 (MHz) Eta: 0.9203

 N 45 Cq= -3.5069 MHz eta= 0.36826
 N 46 Cq= -3.5084 MHz eta= 0.36870
 N 47 Cq= -3.5084 MHz eta= 0.36870
 N 48 Cq= -3.1864 MHz eta= 0.38355
 N 49 Cq= -3.1864 MHz eta= 0.38355
 N 50 Cq= -3.1880 MHz eta= 0.38408
 N 51 Cq= -3.1864 MHz eta= 0.38355
 N 52 Cq= -3.1864 MHz eta= 0.38355
 N 53 Cq= -3.1880 MHz eta= 0.38408
 N 54 Cq= -3.5069 MHz eta= 0.36826
 N 55 Cq= -3.5084 MHz eta= 0.36870
 N 56 Cq= -3.5084 MHz eta= 0.36870
 N 57 Cq= -3.5069 MHz eta= 0.36826
 N 58 Cq= -3.1880 MHz eta= 0.38408
 N 59 Cq= -3.1880 MHz eta= 0.38408
 N 60 Cq= -3.5069 MHz eta= 0.36826
Q= 2.04 1e-30 m^2

For NaClO3, CASTEP arrived at an average NQR frequency (over 4 sites) of 28.9 MHz. For chlorine in DTN, CASTEP calculated NQR at 8.5 MHz (unrelaxed) and 4.5 MHz (relaxed). For 14N in DTN, the calculation yields 2.9 MHz and 1.6 MHz for inequivalent sites in the relaxed EFG calculation. The difference between the relaxed and unrelaxed calculation lies in the structural data preparation. In the unrelaxed case, structure data from direct measurements in literature is fed directly into CASTEP and used. In the relaxed case, the structure parameters itself are adjusted using GIPAW, and then the EFG is calculated.

Posted in Stuff

Meeting – October 8, 2014 | Hashes


Posted in Stuff



Recent Posts