Popup tips on bibtex links in org-mode

| categories: uncategorized | tags:

I want to explore using popup tips to display richer information about org-mode links. The idea is to have something like a tooltip that displays the bibtex entry when you hover over it, or click on it.

https://github.com/auto-complete/popup-el/blob/master/popup.el

Here is a canonical example of a popup.

(popup-tip "Hello, World!")
t

All I need to do is figure out a simple way to get the bibtex entry as a string, and pop it up when a link is clicked on.

(org-add-link-type
 "test"
 ;; this function is run when you click
 (lambda (link-string) 
   (popup-tip link-string))
 ;; formatting
(lambda (keyword desc format)
   (cond
    ((eq format 'html) (format "<pre>%s:%s</pre>" keyword desc)))))
lambda (link-string) (popup-tip link-string)
lambda (keyword desc format) (cond ((eq format (quote html)) (format <pre>%s:%s</pre> keyword desc)))

Now we give it a try.

test:show-me-the-popup

That looks good.

Ok, the penultimate step will be to lookup a bibtex entry, and show the entry in a popup. We will hardcode the path to the bibtex file.

(org-add-link-type
 "test"
 ;; this function is run when you click
 (lambda (bibtex-key)
   (let ((entry (with-temp-buffer
                  (insert-file-contents "~/Dropbox/bibliography/references.bib")
                  (goto-char (point-min))
                  (re-search-forward bibtex-key)
                  (bibtex-narrow-to-entry)
                  (buffer-string))))
     (popup-tip entry))))
lambda (bibtex-key) (let ((cb (current-buffer)) (entry (with-temp-buffer (insert-file-contents ~/Dropbox/bibliography/references.bib) (goto-char (point-min)) (re-search-forward bibtex-key) (bibtex-narrow-to-entry) (buffer-string)))) (popup-tip entry))

test:mehta-2014-ident-poten

And here is what appears for me:

The final step is to connect this to an idle timer . We want a popup to occur when our mouse is idle. I am setting this up to run one time, after 5 seconds of idleness.

(run-with-idle-timer 5 nil (lambda () (popup-tip "You are being idle")))
[nil 0 5 0 nil (lambda nil (popup-tip "You are being idle")) nil idle 0]

So, we need to setup an idle timer that runs on some interval. When the cursor is on the right kind of link, we want to get a popup. I adapted the following code from http://www.emacswiki.org/emacs/IdleTimers .

;; variable for the timer object
(defvar idle-timer-bibtex-timer nil)

;; callback function 
(defun idle-timer-bibtex-callback ()
  "displays a popup of the bibtex entry in a test link"
  (interactive)
  (let ((object (org-element-context)))    
    (when (and (equal (org-element-type object) 'link) 
               (equal (org-element-property :type object) "test"))
      (let* ((bibtex-key (org-element-property :path object))
             (entry (with-temp-buffer
                      (insert-file-contents "~/Dropbox/bibliography/references.bib")
                      (goto-char (point-min))
                      (re-search-forward bibtex-key)
                      (bibtex-narrow-to-entry)
                      (buffer-string))))
        (popup-tip entry)))))

;; start functions
(defun idle-timer-bibtex-start ()
  (interactive)
  (when (timerp idle-timer-bibtex-timer)
    (cancel-timer idle-timer-bibtex-timer))
  (setq idle-timer-bibtex-timer
          (run-with-timer 1 1 #'idle-timer-bibtex-callback)))

;; stop function
(defun idle-timer-bibtex-stop ()
  (interactive)
  (when (timerp idle-timer-bibtex-timer)
    (cancel-timer idle-timer-bibtex-timer))
  (setq idle-timer-bibtex-timer nil))

(idle-timer-bibtex-start)
idle-timer-bibtex-stop

test:kitchin-2008-alloy

Now, whenever the cursor is on the link, and there is an idle of about a sec, I get a popup window of the bibtex entry. It looks like this:

There are still some limitations to this code. It does not handle multiple citations in a link (like the cite links I normally use do). That will take a little work to fixup. I cannot figure out how to get mouse-over tooltips; this only works when the cursor is on the link. I do not know what the optimal timer setting is. This one runs every second. I do not see any issues in performance with that. Another issue might be making the timer a file local variable. It would be nice if the timer quit running when the file was closed. I do not know how easy that would be to implement, or if there should be one timer running for org-mode. Finally, this code is hard-coded to use my reference file. For a real module, we would probably provide some customization to choose other bibtex files. Overall though, this might be a handy way to quickly peruse the citations in an org-file.

Copyright (C) 2014 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 8.2.5h

Discuss on Twitter

Limitations?

| categories: uncategorized | tags:

JSON is flexible, and can store text and numeric data. It does not store numpy arrays, but rather it is limited to storing lists of data. You would have to convert them back to arrays if you want to do array math. You probably wouldn't want to store a 3d array of electron density in this format, although it probably isn't worse than a CUBE file format. We haven't tested these files very significantly yet at a large scale to see how fast it is to read from lots of them.

Nonetheless, this looks like a reasonable format to share data in human and machine readable form, without violating the VASP licence conditions.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

Exporting accented characters to latex from org-mode

| categories: uncategorized | tags:

I noticed recently in writing a technical paper in org-mode that I had some trouble exporting some accented characters to LaTeX.

Here are 5 words that render correctly in LaTeX

1. Jos\'{e}
2. peque\~{n}o
3. Gro\ss
4. Gr\"{u}neisen
5. N\o{}rskov

Here we wrap these words in a LaTeX block so it exports verbatim to see how they look in a PDF.

Note to see this in LaTeX, you must view the exporting-accented-characters.pdf. Now, we use the same characters in org-mode.

  1. Jos\'{e}
  2. peque\~{n}o
  3. Gro\ss
  4. Gr\"{u}neisen
  5. N\o{}rskov

The exported LaTeX code looks like:

\begin{enumerate}
\item Jos$\backslash$'\{e\}
\item peque$\backslash$\textasciitilde{}\{n\}o
\item Gro\ss
\item Gr$\backslash$"\{u\}neisen
\item N\o{}rskov
\end{enumerate}

The exporter does not handle all of them correctly. Org-mode is its own system, and it is not, and won't be a total replacement for LaTeX. Nevertheless, these are pretty common characters for me, and We need a solution! A clunky way we found to solve this is to add a LATEXHEADER line that defines a new LaTeX command like this:

#+LATEX_HEADER: \newcommand{\gruneisen}{Gr\"{u}neisen}

Then you can use the new command in org-mode. So this text:

We use \gruneisen in a sentence.

Renders like this:

We use \gruneisen in a sentence.

That is not too ideal, since some journals do not like you to define new commands. It turns out that org-mode has its own commands to solve this problem! There is a list of these commands stored in a variable called org-entities.

Here we print these entities for "the record". I add an extra star to the data in org-entities so they will all be nested in this post.

(mapcar (lambda(x)
  "print element x. If it is a heading, add an extra star"
  (interactive)
  (if (and (stringp x) (string= (substring x 0 1) "*"))
      (princ (format "*%s\n" x))
    (princ (format "%s\n" x)))) org-entities)

1 Letters

1.1 Latin

(Agrave \`{A} nil &Agrave; A À À) (agrave \`{a} nil &agrave; a à à) (Aacute \'{A} nil &Aacute; A Á Á) (aacute \'{a} nil &aacute; a á á) (Acirc \A nil &Acirc; A  Â) (acirc \a nil &acirc; a â â) (Atilde \~{A} nil &Atilde; A à Ã) (atilde \~{a} nil &atilde; a ã ã) (Auml \"{A} nil &Auml; Ae Ä Ä) (auml \"{a} nil &auml; ae ä ä) (Aring Å nil &Aring; A Å Å) (AA Å nil &Aring; A Å Å) (aring \aa{} nil &aring; a å å) (AElig \AE{} nil &AElig; AE Æ Æ) (aelig \ae{} nil &aelig; ae æ æ) (Ccedil \c{C} nil &Ccedil; C Ç Ç) (ccedil \c{c} nil &ccedil; c ç ç) (Egrave \`{E} nil &Egrave; E È È) (egrave \`{e} nil &egrave; e è è) (Eacute \'{E} nil &Eacute; E É É) (eacute \'{e} nil &eacute; e é é) (Ecirc \E nil &Ecirc; E Ê Ê) (ecirc \e nil &ecirc; e ê ê) (Euml \"{E} nil &Euml; E Ë Ë) (euml \"{e} nil &euml; e ë ë) (Igrave \`{I} nil &Igrave; I Ì Ì) (igrave \`{i} nil &igrave; i ì ì) (Iacute \'{I} nil &Iacute; I Í Í) (iacute \'{i} nil &iacute; i í í) (Icirc \I nil &Icirc; I Î Î) (icirc \i nil &icirc; i î î) (Iuml \"{I} nil &Iuml; I Ï Ï) (iuml \"{i} nil &iuml; i ï ï) (Ntilde \~{N} nil &Ntilde; N Ñ Ñ) (ntilde \~{n} nil &ntilde; n ñ ñ) (Ograve \`{O} nil &Ograve; O Ò Ò) (ograve \`{o} nil &ograve; o ò ò) (Oacute \'{O} nil &Oacute; O Ó Ó) (oacute \'{o} nil &oacute; o ó ó) (Ocirc \O nil &Ocirc; O Ô Ô) (ocirc \o nil &ocirc; o ô ô) (Otilde \~{O} nil &Otilde; O Õ Õ) (otilde \~{o} nil &otilde; o õ õ) (Ouml \"{O} nil &Ouml; Oe Ö Ö) (ouml \"{o} nil &ouml; oe ö ö) (Oslash \O nil &Oslash; O Ø Ø) (oslash \o{} nil &oslash; o ø ø) (OElig \OE{} nil &OElig; OE OE Œ) (oelig \oe{} nil &oelig; oe oe œ) (Scaron \v{S} nil &Scaron; S S Š) (scaron \v{s} nil &scaron; s s š) (szlig \ss{} nil &szlig; ss ß ß) (Ugrave \`{U} nil &Ugrave; U Ù Ù) (ugrave \`{u} nil &ugrave; u ù ù) (Uacute \'{U} nil &Uacute; U Ú Ú) (uacute \'{u} nil &uacute; u ú ú) (Ucirc \U nil &Ucirc; U Û Û) (ucirc \u nil &ucirc; u û û) (Uuml \"{U} nil &Uuml; Ue Ü Ü) (uuml \"{u} nil &uuml; ue ü ü) (Yacute \'{Y} nil &Yacute; Y Ý Ý) (yacute \'{y} nil &yacute; y ý ý) (Yuml \"{Y} nil &Yuml; Y Y Ÿ) (yuml \"{y} nil &yuml; y ÿ ÿ)

1.2 Latin (special face)

(fnof \textit{f} nil &fnof; f f ƒ) (real \Re t &real; R R ℜ) (image \Im t &image; I I ℑ) (weierp \wp t &weierp; P P ℘)

1.3 Greek

(Alpha A nil &Alpha; Alpha Alpha Α) (alpha α t &alpha; alpha alpha α) (Beta B nil &Beta; Beta Beta Β) (beta β t &beta; beta beta β) (Gamma Γ t &Gamma; Gamma Gamma Γ) (gamma γ t &gamma; gamma gamma γ) (Delta Δ t &Delta; Delta Gamma Δ) (delta δ t &delta; delta delta δ) (Epsilon E nil &Epsilon; Epsilon Epsilon Ε) (epsilon ε t &epsilon; epsilon epsilon ε) (varepsilon ε t &epsilon; varepsilon varepsilon ε) (Zeta Z nil &Zeta; Zeta Zeta Ζ) (zeta ζ t &zeta; zeta zeta ζ) (Eta H nil &Eta; Eta Eta Η) (eta η t &eta; eta eta η) (Theta Θ t &Theta; Theta Theta Θ) (theta θ t &theta; theta theta θ) (thetasym ϑ t &thetasym; theta theta ϑ) (vartheta ϑ t &thetasym; theta theta ϑ) (Iota I nil &Iota; Iota Iota Ι) (iota ι t &iota; iota iota ι) (Kappa K nil &Kappa; Kappa Kappa Κ) (kappa κ t &kappa; kappa kappa κ) (Lambda Λ t &Lambda; Lambda Lambda Λ) (lambda λ t &lambda; lambda lambda λ) (Mu M nil &Mu; Mu Mu Μ) (mu μ t &mu; mu mu μ) (nu ν t &nu; nu nu ν) (Nu N nil &Nu; Nu Nu Ν) (Xi Ξ t &Xi; Xi Xi Ξ) (xi ξ t &xi; xi xi ξ) (Omicron O nil &Omicron; Omicron Omicron Ο) (omicron \textit{o} nil &omicron; omicron omicron ο) (Pi Π t &Pi; Pi Pi Π) (pi π t &pi; pi pi π) (Rho P nil &Rho; Rho Rho Ρ) (rho ρ t &rho; rho rho ρ) (Sigma Σ t &Sigma; Sigma Sigma Σ) (sigma σ t &sigma; sigma sigma σ) (sigmaf ς t &sigmaf; sigmaf sigmaf ς) (varsigma ς t &sigmaf; varsigma varsigma ς) (Tau T nil &Tau; Tau Tau Τ) (Upsilon Υ t &Upsilon; Upsilon Upsilon Υ) (upsih Υ t &upsih; upsilon upsilon ϒ) (upsilon υ t &upsilon; upsilon upsilon υ) (Phi Φ t &Phi; Phi Phi Φ) (phi φ t &phi; phi phi φ) (Chi X nil &Chi; Chi Chi Χ) (chi χ t &chi; chi chi χ) (acutex ´ x t &acute;x 'x 'x 𝑥́) (Psi Ψ t &Psi; Psi Psi Ψ) (psi ψ t &psi; psi psi ψ) (tau τ t &tau; tau tau τ) (Omega Ω t &Omega; Omega Omega Ω) (omega ω t &omega; omega omega ω) (piv \varpi t &piv; omega-pi omega-pi ϖ) (partial ∂ t &part; [partial differential] [partial differential] ∂)

1.4 Hebrew

(alefsym \aleph t &alefsym; aleph aleph ℵ)

1.5 Dead languages

(ETH \DH{} nil &ETH; D Ð Ð) (eth \dh{} nil &eth; dh ð ð) (THORN \TH{} nil &THORN; TH Þ Þ) (thorn \th{} nil &thorn; th þ þ)

2 Punctuation

2.1 Dots and Marks

(dots … nil &hellip; … … …) (hellip … nil &hellip; … … …) (middot \textperiodcentered{} nil &middot; . · ·) (iexcl !` nil &iexcl; ! ¡ ¡) (iquest ?` nil &iquest; ? ¿ ¿)

2.2 Dash-like

(shy ­ nil &shy; ) (ndash – nil &ndash; - - –) (mdash — nil &mdash; – – —)

2.3 Quotations

(quot \textquotedbl{} nil &quot; " " ") (acute \textasciiacute{} nil &acute; ' ´ ´) (ldquo \textquotedblleft{} nil &ldquo; " " “) (rdquo \textquotedblright{} nil &rdquo; " " ”) (bdquo \quotedblbase{} nil &bdquo; " " „) (lsquo \textquoteleft{} nil &lsquo; ` ` ‘) (rsquo \textquoteright{} nil &rsquo; ' ' ’) (sbquo \quotesinglbase{} nil &sbquo; , , ‚) (laquo \guillemotleft{} nil &laquo; << « «) (raquo \guillemotright{} nil &raquo; >> » ») (lsaquo \guilsinglleft{} nil &lsaquo; < < ‹) (rsaquo \guilsinglright{} nil &rsaquo; > > ›)

3 Other

3.1 Misc. (often used)

(circ \nil nil &circ; ^ ^ ˆ) (vert | t &#124; | | |) (brvbar \textbrokenbar{} nil &brvbar; | ¦ ¦) (sect \S nil &sect; paragraph § §) (amp \& nil &amp; & & &) (lt \textless{} nil &lt; < < <) (gt \textgreater{} nil &gt; > > >) (tilde \~{} nil &tilde; ~ ~ ~) (slash / nil / / / /) (plus + nil + + + +) (under \_ nil _ _ _ _) (equal = nil = = = =) (asciicirc \textasciicircum{} nil ^ ^ ^ ^) (dagger \textdagger{} nil &dagger; [dagger] [dagger] †) (Dagger \textdaggerdbl{} nil &Dagger; [doubledagger] [doubledagger] ‡)

3.2 Whitespace

(nbsp ~ nil &nbsp; ) (ensp \hspace*{.5em} nil &ensp;  ) (emsp \hspace*{1em} nil &emsp;  ) (thinsp \hspace*{.2em} nil &thinsp;  )

3.3 Currency

(curren \textcurrency{} nil &curren; curr. ¤ ¤) (cent \textcent{} nil &cent; cent ¢ ¢) (pound \pounds{} nil &pound; pound £ £) (yen \textyen{} nil &yen; yen ¥ ¥) (euro \texteuro{} nil &euro; EUR EUR €) (EUR € nil &euro; EUR EUR €) (EURdig € nil &euro; EUR EUR €) (EURhv € nil &euro; EUR EUR €) (EURcr € nil &euro; EUR EUR €) (EURtm € nil &euro; EUR EUR €)

3.4 Property Marks

(copy \textcopyright{} nil &copy; (c) © ©) (reg \textregistered{} nil &reg; (r) ® ®) (trade \texttrademark{} nil &trade; TM TM ™)

3.5 Science et al.

(minus − t &minus; - - −) (pm \textpm{} nil &plusmn; +- ± ±) (plusmn \textpm{} nil &plusmn; +- ± ±) (times \texttimes{} nil &times; * × ×) (frasl / nil &frasl; / / ⁄) (div \textdiv{} nil &divide; / ÷ ÷) (frac12 \textonehalf{} nil &frac12; 1/2 ½ ½) (frac14 \textonequarter{} nil &frac14; 1/4 ¼ ¼) (frac34 \textthreequarters{} nil &frac34; 3/4 ¾ ¾) (permil \textperthousand{} nil &permil; per thousand per thousand ‰) (sup1 \textonesuperior{} nil &sup1; ^1 ¹ ¹) (sup2 \texttwosuperior{} nil &sup2; ^2 ² ²) (sup3 \textthreesuperior{} nil &sup3; ^3 ³ ³) (radic \sqrt{\,} t &radic; [square root] [square root] √) (sum ∑ t &sum; [sum] [sum] ∑) (prod ∏ t &prod; [product] [n-ary product] ∏) (micro \textmu{} nil &micro; micro µ µ) (macr \textasciimacron{} nil &macr; [macron] ¯ ¯) (deg \textdegree{} nil &deg; degree ° °) (prime ′ t &prime; ' ' ′) (Prime ′′ t &Prime; '' '' ″) (infin \propto t &infin; [infinity] [infinity] ∞) (infty ∞ t &infin; [infinity] [infinity] ∞) (prop \propto t &prop; [proportional to] [proportional to] ∝) (proptp \propto t &prop; [proportional to] [proportional to] ∝) (not \textlnot{} nil &not; [angled dash] ¬ ¬) (neg ¬ t &not; [angled dash] ¬ ¬) (land ∧ t &and; [logical and] [logical and] ∧) (wedge ∧ t &and; [logical and] [logical and] ∧) (lor ∨ t &or; [logical or] [logical or] ∨) (vee ∨ t &or; [logical or] [logical or] ∨) (cap ∩ t &cap; [intersection] [intersection] ∩) (cup ∪ t &cup; [union] [union] ∪) (int ∫ t &int; [integral] [integral] ∫) (there4 \therefore t &there4; [therefore] [therefore] ∴) (sim ∼ t &sim; ~ ~ ∼) (cong ≅ t &cong; [approx. equal to] [approx. equal to] ≅) (simeq ≅ t &cong; [approx. equal to] [approx. equal to] ≅) (asymp ≈ t &asymp; [almost equal to] [almost equal to] ≈) (approx ≈ t &asymp; [almost equal to] [almost equal to] ≈) (ne ≠ t &ne; [not equal to] [not equal to] ≠) (neq ≠ t &ne; [not equal to] [not equal to] ≠) (equiv ≡ t &equiv; [identical to] [identical to] ≡) (le ≤ t &le; <= <= ≤) (ge ≥ t &ge; >= >= ≥) (sub ⊂ t &sub; [subset of] [subset of] ⊂) (subset ⊂ t &sub; [subset of] [subset of] ⊂) (sup ⊃ t &sup; [superset of] [superset of] ⊃) (supset ⊃ t &sup; [superset of] [superset of] ⊃) (nsub ¬⊂ t &nsub; [not a subset of] [not a subset of ⊄) (sube \subseteq t &sube; [subset of or equal to] [subset of or equal to] ⊆) (nsup ¬⊃ t &nsup; [not a superset of] [not a superset of] ⊅) (supe \supseteq t &supe; [superset of or equal to] [superset of or equal to] ⊇) (forall ∀ t &forall; [for all] [for all] ∀) (exist ∃ t &exist; [there exists] [there exists] ∃) (exists ∃ t &exist; [there exists] [there exists] ∃) (empty ∅ t &empty; [empty set] [empty set] ∅) (emptyset ∅ t &empty; [empty set] [empty set] ∅) (isin ∈ t &isin; [element of] [element of] ∈) (in ∈ t &isin; [element of] [element of] ∈) (notin ∉ t &notin; [not an element of] [not an element of] ∉) (ni ∋ t &ni; [contains as member] [contains as member] ∋) (nabla ∇ t &nabla; [nabla] [nabla] ∇) (ang ∠ t &ang; [angle] [angle] ∠) (angle ∠ t &ang; [angle] [angle] ∠) (perp ⊥ t &perp; [up tack] [up tack] ⊥) (sdot ⋅ t &sdot; [dot] [dot] ⋅) (cdot ⋅ t &sdot; [dot] [dot] ⋅) (lceil ⌈ t &lceil; [left ceiling] [left ceiling] ⌈) (rceil ⌉ t &rceil; [right ceiling] [right ceiling] ⌉) (lfloor ⌊ t &lfloor; [left floor] [left floor] ⌊) (rfloor ⌋ t &rfloor; [right floor] [right floor] ⌋) (lang \langle t &lang; < < ⟨) (rang \rangle t &rang; > > ⟩) (hbar ℏ t &#8463; hbar hbar ℏ)

3.6 Arrows

(larr ← t &larr; <- <- ←) (leftarrow ← t &larr; <- <- ←) (gets ← t &larr; <- <- ←) (lArr ⇐ t &lArr; <= <= ⇐) (Leftarrow ⇐ t &lArr; <= <= ⇐) (uarr ↑ t &uarr; [uparrow] [uparrow] ↑) (uparrow ↑ t &uarr; [uparrow] [uparrow] ↑) (uArr ⇑ t &uArr; [dbluparrow] [dbluparrow] ⇑) (Uparrow ⇑ t &uArr; [dbluparrow] [dbluparrow] ⇑) (rarr → t &rarr; -> -> →) (to → t &rarr; -> -> →) (rightarrow → t &rarr; -> -> →) (rArr ⇒ t &rArr; => => ⇒) (Rightarrow ⇒ t &rArr; => => ⇒) (darr ↓ t &darr; [downarrow] [downarrow] ↓) (downarrow ↓ t &darr; [downarrow] [downarrow] ↓) (dArr ⇓ t &dArr; [dbldownarrow] [dbldownarrow] ⇓) (Downarrow ⇓ t &dArr; [dbldownarrow] [dbldownarrow] ⇓) (harr ↔ t &harr; <-> <-> ↔) (leftrightarrow ↔ t &harr; <-> <-> ↔) (hArr ⇔ t &hArr; <=> <=> ⇔) (Leftrightarrow ⇔ t &hArr; <=> <=> ⇔) (crarr ↵ t &crarr; <-' <-' ↵) (hookleftarrow ↵ t &crarr; <-' <-' ↵)

3.7 Function names

(arccos arccos t arccos arccos arccos arccos) (arcsin arcsin t arcsin arcsin arcsin arcsin) (arctan arctan t arctan arctan arctan arctan) (arg arg t arg arg arg arg) (cos cos t cos cos cos cos) (cosh cosh t cosh cosh cosh cosh) (cot cot t cot cot cot cot) (coth coth t coth coth coth coth) (csc csc t csc csc csc csc) (deg ° t &deg; deg deg deg) (det det t det det det det) (dim dim t dim dim dim dim) (exp exp t exp exp exp exp) (gcd gcd t gcd gcd gcd gcd) (hom hom t hom hom hom hom) (inf inf t inf inf inf inf) (ker ker t ker ker ker ker) (lg lg t lg lg lg lg) (lim lim t lim lim lim lim) (liminf liminf t liminf liminf liminf liminf) (limsup limsup t limsup limsup limsup limsup) (ln ln t ln ln ln ln) (log log t log log log log) (max max t max max max max) (min min t min min min min) (Pr Pr t Pr Pr Pr Pr) (sec sec t sec sec sec sec) (sin sin t sin sin sin sin) (sinh sinh t sinh sinh sinh sinh) (sup ⊃ t &sup; sup sup sup) (tan tan t tan tan tan tan) (tanh tanh t tanh tanh tanh tanh)

3.8 Signs & Symbols

(bull \textbullet{} nil &bull; * * •) (bullet \textbullet{} nil &bull; * * •) (star * t * * * ⋆) (lowast ∗ t &lowast; * * ∗) (ast ∗ t &lowast; * * *) (odot o t o [circled dot] [circled dot] ʘ) (oplus ⊕ t &oplus; [circled plus] [circled plus] ⊕) (otimes ⊗ t &otimes; [circled times] [circled times] ⊗) (checkmark ✓ t &#10003; [checkmark] [checkmark] ✓)

3.9 Miscellaneous (seldom used)

(para \P{} nil &para; [pilcrow] ¶ ¶) (ordf \textordfeminine{} nil &ordf; a ª ª) (ordm \textordmasculine{} nil &ordm; o º º) (cedil \c{} nil &cedil; [cedilla] ¸ ¸) (oline \overline{~} t &oline; [overline] ¯ ‾) (uml \textasciidieresis{} nil &uml; [diaeresis] ¨ ¨) (zwnj \/{} nil &zwnj; ‌) (zwj nil &zwj; ‍) (lrm nil &lrm; ‎) (rlm nil &rlm; ‏)

3.10 Smilies

(smile ☺ t &#9786; :-) :-) ⌣) (smiley ☺ nil &#9786; :-) :-) ☺) (blacksmile \blacksmiley{} nil &#9787; :-) :-) ☻) (sad \frownie{} nil &#9785; :-( :-( ☹)

3.11 Suits

(clubs ♣ t &clubs; [clubs] [clubs] ♣) (clubsuit ♣ t &clubs; [clubs] [clubs] ♣) (spades ♠ t &spades; [spades] [spades] ♠) (spadesuit ♠ t &spades; [spades] [spades] ♠) (hearts ♥ t &hearts; [hearts] [hearts] ♥) (heartsuit ♥ t &heartsuit; [hearts] [hearts] ♥) (diams ♦ t &diams; [diamonds] [diamonds] ♦) (diamondsuit ♦ t &diams; [diamonds] [diamonds] ♦) (Diamond \diamond t &diamond; [diamond] [diamond] ⋄) (loz \diamond t &loz; [lozenge] [lozenge] ◊)

4 Summary.

Wow, there are a lot of commands ☺. We just need to use them. For example, I can write Grüneisen, and it finally renders the way it should!

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

Notice anything different

| categories: uncategorized | tags:

Based on the last few posts on making links to external files work in the blog, and customizing code block export in HTML, I have rewritten blogofile.elto more cleanly support the use of images and data files in my blog posts. Now, I should be able to include a data file (like this one) in a post and you should be able to click on the link to open it after I publish the post in the usual way by pressing F10. That should process the post, construct URLs for all the links, including images, copy the relevant files to the blog directory, and generate the HTML file for blogofile to build. This is a little more robust than it used to be, as all files are stored in a directory named based on the post title, so there is less concern of using duplicate filenames for images and datafiles.

Here is a gratuitous image, just to see if it works ;)

Figure 1: test image

Hopefully, there is nothing different on the outside! URLs to images are now in a different place, but that should not be apparent unless you read source code. The real difference is that now there are working links to data files! And it is easier for me to write my posts including them, with simple publishing.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

Estimating uncertainties in equations of state

| categories: uncategorized | tags:

We often use DFT to calculate the energy of a unit cell as a function of volume. Then, we fit an equation of state to the data to estimate the volume that minimizes the total energy, and the bulk modulus of the material. 10.1016/j.comphys.2003.12.001

volume energy
324.85990899 -399.9731688470
253.43999457 -400.0172393178
234.03826687 -400.0256270548
231.12159387 -400.0265690700
228.40609504 -400.0273551120
225.86490337 -400.0280030862
223.47556626 -400.0285313450
221.21992353 -400.0289534593
219.08319566 -400.0292800709
217.05369547 -400.0295224970
215.12089909 -400.0296863867
213.27525144 -400.0297809256
211.51060823 -400.0298110000
203.66743321 -400.0291665573
197.07888649 -400.0275017142
191.39717952 -400.0250998136
186.40163591 -400.0221371852
181.94435510 -400.0187369863
177.92077043 -400.0149820198
174.25380090 -400.0109367042
170.88582166 -400.0066495100
167.76711189 -400.0021478258
164.87096104 -399.9974753449
159.62553397 -399.9876885136
154.97005460 -399.9774175487
150.78475335 -399.9667603369
146.97722201 -399.9557686286
143.49380641 -399.9445262604
import numpy as np
import matplotlib.pyplot as plt
from pycse import nlinfit

# data
V = np.array([row[0] for row in data]) 
E = np.array([row[1] for row in data])

plt.plot(V, E, '.')
plt.xlabel('Volume ($\AA^3$)')
plt.ylabel('Energy (Ha)')

def Murnaghan(vol, E0, B0, BP, V0):
    '''
    given a vector of parameters and volumes, return a vector of energies.
    equation From PRB 28,5480 (1983)
    '''
    
    E = E0 + B0*vol/BP*(((V0/vol)**BP)/(BP-1)+1) - V0*B0/(BP-1.)

    return E

guess = [-400, 0.5, 2, 210]
pars, pint, SE = nlinfit(Murnaghan, V, E, guess, alpha=0.05)
E0, B0, BP, V0 = pint

Vfit = np.linspace(V.min(), V.max())
plt.plot(Vfit, Murnaghan(Vfit, *pars))
plt.savefig('images/eos-uncertainty.png')

print '95% confidence intervals'
print 'V0 = {0} bohr**3'.format(V0)
print 'E0 = {0} Ha'.format(E0)
print 'B0 = {0} GPA'.format([x * 29421.010901602753 for x in B0])
95% confidence intervals
V0 = [212.27788154532402, 213.27897592511891] bohr**3
E0 = [-400.0297027767362, -400.02922937100408] Ha
B0 = [108.62283904402159, 111.20447706313001] GPA

You can see the fit is not perfect, and there is corresponding uncertainty in the estimated parameters. A nice feature of the Murnaghan equation of state is that the parameters are directly the quantities of interest, so the uncertainties are directly calculated here. For other models, e.g. a polynomial fit, you would have to propagate the errors in the parameters to the properties.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter
« Previous Page -- Next Page »