Exporting accented characters to latex from org-mode

| categories: uncategorized | tags: | View Comments

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:

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

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

1.2 Latin (special face)

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

1.3 Greek

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

1.4 Hebrew

(alefsym \aleph t ℵ aleph aleph ℵ)

1.5 Dead languages

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

2 Punctuation

2.1 Dots and Marks

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

2.2 Dash-like

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

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

Read and Post Comments

Notice anything different

| categories: uncategorized | tags: | View Comments

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

Read and Post Comments

Estimating uncertainties in equations of state

| categories: uncategorized | tags: | View Comments

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))

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

Read and Post Comments

Finding the volume of a unit cell at a fixed pressure

| categories: uncategorized | tags: | View Comments

A typical unit cell optimization in DFT is performed by minimizing the total energy with respect to variations in the unit cell parameters and atomic positions. In this approach, a pressure of 0 GPa is implied, as well as a temperature of 0K. For non-zero pressures, the volume that minimizes the total energy is not the same as the volume at P=0.

Let \(x\) be the unit cell parameters that can be varied. For P ≠ 0, and T = 0, we have the following

\(G(x; p) = E(x) + p V(x)\)

and we need to minimize this function to find the groundstate volume. We will do this for fcc Cu at 5 GPa of pressure. We will assume there is only one degree of freedom in the unit cell, the lattice constant. First we get the \(E(x)\) function, and then add the analytical correction.

from jasp import *
from ase import Atom, Atoms
from ase.utils.eos import EquationOfState

LC = [3.5, 3.55, 3.6, 3.65, 3.7, 3.75]
volumes, energies = [], []
ready = True

P = 5.0 / 160.2176487  # pressure in eV/ang**3

for a in LC:
    atoms = Atoms([Atom('Cu',(0, 0, 0))],
              cell=0.5 * a*np.array([[1.0, 1.0, 0.0],
                                     [0.0, 1.0, 1.0],
                                     [1.0, 0.0, 1.0]]))

    with jasp('../bulk/Cu-{0}'.format(a),
              atoms=atoms) as calc:

            e = atoms.get_potential_energy()
        except (VaspSubmitted, VaspQueued):
            ready = False

if not ready:
    import sys; sys.exit()

import numpy as np
energies = np.array(energies)
volumes = np.array(volumes)

eos = EquationOfState(volumes, energies)
v0, e0, B = eos.fit()
print 'V0 at 0 GPa = {0:1.2f} ang^3'.format(v0)

eos5 = EquationOfState(volumes, energies + P * volumes)
v0_5, e0, B = eos5.fit()
print 'V0 at 5 GPa = {0:1.2f} ang^3'.format(v0_5)
V0 at 0 GPa = 12.02 ang^3
V0 at 5 GPa = 11.62 ang^3

You can see here that apply pressure decreases the equilibrium volume, and increases the total energy.

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

org-mode source

Read and Post Comments

Meet the steam tables

| categories: uncategorized | tags: thermodynamics, steam | View Comments

Matlab post

We will use the iapws module. Install it like this:

pip install iapws

Problem statement: A Rankine cycle operates using steam with the condenser at 100 degC, a pressure of 3.0 MPa and temperature of 600 degC in the boiler. Assuming the compressor and turbine operate reversibly, estimate the efficiency of the cycle.

Starting point in the Rankine cycle in condenser.

we have saturated liquid here, and we get the thermodynamic properties for the given temperature. In this python module, these properties are all in attributes of an IAPWS object created at a set of conditions.

1 Starting point in the Rankine cycle in condenser.

We have saturated liquid here, and we get the thermodynamic properties for the given temperature.

from iapws import IAPWS97

T1 = 100 + 273.15 #in K

sat_liquid1  = IAPWS97(T=T1, x=0) # x is the steam quality. 0 = liquid

P1 = sat_liquid1.P
s1 = sat_liquid1.s
h1 = sat_liquid1.h
v1 = sat_liquid1.v

2 Isentropic compression of liquid to point 2

The final pressure is given, and we need to compute the new temperatures, and enthalpy.

P2 = 3.0 # MPa
s2 = s1 # this is what isentropic means

sat_liquid2 = IAPWS97(P=P2, s=s1)
T2, = sat_liquid2.T
h2 = sat_liquid2.h

# work done to compress liquid. This is an approximation, since the
# volume does change a little with pressure, but the overall work here
# is pretty small so we neglect the volume change.
WdotP = v1*(P2 - P1);
print('The compressor work is: {0:1.4f} kJ/kg'.format(WdotP))
>>> >>> >>> >>> >>> >>> ... ... ... >>>
The compressor work is: 0.0030 kJ/kg

The compression work is almost negligible. This number is 1000 times smaller than we computed with Xsteam. I wonder what the units of v1 actually are.

3 Isobaric heating to T3 in boiler where we make steam

T3 = 600 + 273.15 # K
P3 = P2 # definition of isobaric
steam = IAPWS97(P=P3, T=T3)

h3 = steam.h
s3 = steam.s

Qb, = h3 - h2 # heat required to make the steam

print 'The boiler heat duty is: {0:1.2f} kJ/kg'.format(Qb)
>>> >>> >>> >>> >>> >>> >>> >>>
The boiler heat duty is: 3260.69 kJ/kg

4 Isentropic expansion through turbine to point 4

steam =  IAPWS97(P=P1, s=s3)
T4, = steam.T
h4 = steam.h
s4 = s3 # isentropic
Qc, = h4 - h1 # work required to cool from T4 to T1
print 'The condenser heat duty is {0:1.2f} kJ/kg'.format(Qc)
>>> >>> >>> >>>
The condenser heat duty is 2317.00 kJ/kg

5 To get from point 4 to point 1

WdotTurbine, = h4 - h3 # work extracted from the expansion
print('The turbine work is: {0:1.2f} kJ/kg'.format(WdotTurbine))
The turbine work is: -946.71 kJ/kg

6 Efficiency

This is a ratio of the work put in to make the steam, and the net work obtained from the turbine. The answer here agrees with the efficiency calculated in Sandler on page 135.

eta = -(WdotTurbine - WdotP) / Qb
print('The overall efficiency is {0:1.2%}.'.format(eta))
The overall efficiency is 29.03%.

7 Entropy-temperature chart

The IAPWS module makes it pretty easy to generate figures of the steam tables. Here we generate an entropy-Temperature graph. We do this to illustrate the path of the Rankine cycle. We need to compute the values of steam entropy for a range of pressures and temperatures.

import numpy as np
import matplotlib.pyplot as plt

T = np.linspace(300, 372+273, 200) # range of temperatures
for P in [0.1, 1, 2, 5, 10, 20]: #MPa
    steam = [IAPWS97(T=t, P=P) for t in T]
    S = [s.s for s in steam]
    plt.plot(S, T, 'k-')

# saturated vapor and liquid entropy lines
svap = [s.s for s in [IAPWS97(T=t, x=1) for t in T]]
sliq = [s.s for s in [IAPWS97(T=t, x=0) for t in T]]

plt.plot(svap, T, 'r-')
plt.plot(sliq, T, 'b-')

plt.xlabel('Entropy (kJ/(kg K)')
plt.ylabel('Temperature (K)')
>>> >>> <matplotlib.figure.Figure object at 0x000000000638BC18>
>>> >>> ... ... ... ... [<matplotlib.lines.Line2D object at 0x0000000007F9C208>]
[<matplotlib.lines.Line2D object at 0x0000000007F9C400>]
[<matplotlib.lines.Line2D object at 0x0000000007F9C8D0>]
[<matplotlib.lines.Line2D object at 0x0000000007F9CD30>]
[<matplotlib.lines.Line2D object at 0x0000000007F9E1D0>]
[<matplotlib.lines.Line2D object at 0x0000000007F9E630>]
... >>> >>> >>> [<matplotlib.lines.Line2D object at 0x0000000001FDCEB8>]
[<matplotlib.lines.Line2D object at 0x0000000007F9EA90>]
>>> <matplotlib.text.Text object at 0x0000000007F7BE48>
<matplotlib.text.Text object at 0x0000000007F855F8>

We can plot our Rankine cycle path like this. We compute the entropies along the non-isentropic paths.

T23 = np.linspace(T2, T3)
S23 = [s.s for s in [IAPWS97(P=P2, T=t) for t in T23]]

T41 = np.linspace(T4, T1 - 0.01) # subtract a tiny bit to make sure we get a liquid
S41 = [s.s for s in [IAPWS97(P=P1, T=t) for t in T41]]

And then we plot the paths.

plt.plot([s1, s2], [T1, T2], 'r-', lw=4) # Path 1 to 2
plt.plot(S23, T23, 'b-', lw=4) # path from 2 to 3 is isobaric
plt.plot([s3, s4], [T3, T4], 'g-', lw=4) # path from 3 to 4 is isentropic
plt.plot(S41, T41, 'k-', lw=4) # and from 4 to 1 is isobaric
[<matplotlib.lines.Line2D object at 0x0000000008350908>]
[<matplotlib.lines.Line2D object at 0x00000000083358D0>]
[<matplotlib.lines.Line2D object at 0x000000000835BEB8>]
[<matplotlib.lines.Line2D object at 0x0000000008357160>]

8 Summary

This was an interesting exercise. On one hand, the tedium of interpolating the steam tables is gone. On the other hand, you still have to know exactly what to ask for to get an answer that is correct. The iapws interface is a little clunky, and takes some getting used to. It does not seem as robust as the Xsteam module I used in Matlab.

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

org-mode source

Read and Post Comments

« Previous Page -- Next Page »