This is a read-only mirror of pymolwiki.org

Difference between revisions of "Label font id"

From PyMOL Wiki
Jump to navigation Jump to search
m (1 revision)
m (6 revisions)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Overview ==
+
The [[label_font_id]] setting sets the typeface (font family) for atom [[label|labels]].
Set which fonts PyMol uses to render labels.  Font IDs 5—14 are normal fonts, while 15 and 16 are for unicode fonts (and can support many more characters).
 
  
 
== Syntax ==
 
== Syntax ==
 +
 
<source lang="python">
 
<source lang="python">
set label_font_id, 10 # use font no. 10
+
# use "Serif Bold" font family
set label_font_id, 11 # use font no. 11
+
set label_font_id, 10
set label_font_id, 12 # use font no. 12
 
 
</source>
 
</source>
  
== UTF-8 Fonts ==
+
== Available Font Families ==
[[Image:New_fonts.jpeg|thumb|New fonts in PyMol. Notice the alpha and beta characters.]]
+
 
 +
''Font IDs 0-4 were fixed size GLUT fonts, their support was dropped in PyMOL 1.6.''
 +
 
 +
{| class="wikitable"
 +
!Name!!label_font_id
 +
|-
 +
|Sans||5
 +
|-
 +
|Sans Oblique||6
 +
|-
 +
|Sans Bold||7
 +
|-
 +
|Sans Bold Oblique||8
 +
|-
 +
|Serif||9
 +
|-
 +
|Serif Oblique||17
 +
|-
 +
|Serif Bold||10
 +
|-
 +
|Serif Bold Oblique||18
 +
|-
 +
|Mono||11
 +
|-
 +
|Mono Oblique||12
 +
|-
 +
|Mono Bold||13
 +
|-
 +
|Mono Bold Oblique||14
 +
|-
 +
|Gentium Roman||15
 +
|-
 +
|Gentium Italic||16
 +
|}
 +
 
 +
== Special Characters ==
 +
 
 +
Several [http://www.unicode.org/ Unicode] characters are supported.
 +
They can be entered with [https://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code unicode literals] as 4-digit hexadecimal escape sequences.
 +
 
 +
'''Example characters''' (find the code for your character at [http://www.unicode.org/charts Unicode Charts]):
 +
 
 +
{| class="wikitable"
 +
!Code!!Character!!Name
 +
|-
 +
|<code>u"\u03b1"</code>||α||Alpha
 +
|-
 +
|<code>u"\u03b2"</code>||β||Beta
 +
|-
 +
|<code>u"\u00c5"</code>||Å||Ångström
 +
|-
 +
|<code>u"\u00b1"</code>||±||plus/minus
 +
|-
 +
|<code>u"\u00b2"</code>||²||superscript 2
 +
|}
 +
 
 +
== Example 1 ==
  
Newer versions support UTF8 fonts; use '''label_font_id''' from above to 15 or 16. The good news about the UTF8 fonts is that they support the alpha and beta characters. (See image.)
+
[[Image:New_fonts.jpeg|thumb|The alpha and beta are Unicode characters.]]
  
Here's some example code for the image at right:
 
 
<source lang="python">
 
<source lang="python">
# roman
+
# if Python is configured with utf-8 default encoding (all incentive builds)
set label_font_id, 15
+
label  5/CA, u"\u03b1-Helix"
set label_shadow_mode, 3
+
label 10/CA, u"\u03b2-Sheet"
label 5/CA, "\316\261-Helix"
+
 
label 10/CA, "\316\262-Sheet"
+
# if Python is configured differently, explicit utf-8 encoding is necessary
 +
label 5/CA, u"\u03b1-Helix".encode("utf-8")
 +
label 10/CA, u"\u03b2-Sheet".encode("utf-8")
  
 
# italic
 
# italic
Line 27: Line 83:
 
# make bigger
 
# make bigger
 
set label_size, 50
 
set label_size, 50
 +
 +
# cast shadows in ray tracing
 +
set label_shadow_mode, 3
 
</source>
 
</source>
  
==Unicode Fonts==
+
== Example 2 ==
 +
 
 
[[Image:Font_ex.png|300px|thumb|right|Notice the Angstrom and superscript 2 characters.  You can add other characters as well.]]
 
[[Image:Font_ex.png|300px|thumb|right|Notice the Angstrom and superscript 2 characters.  You can add other characters as well.]]
  
PyMOL gives you the flexibility to use encoded unicode fonts.  This allows us to insert various symbols, like the symbol used for Angstrom.  Here are the steps to insert a character from the unicode character set.
 
 
* Find the code for your character at [http://www.unicode.org/charts Unicode Charts].  The Angstrom character, <math>\textrm{\AA}</math> is u"\u00c5" and <math>\pm</math> is u"\u00b1".
 
* Label the selection.  For simple strings, just type the string in double quote, -- "like this" -- and append to the end of that .encode('utf-8') -- "like this".encode('utf-8').  A working example is shown here,
 
 
<source lang="python">
 
<source lang="python">
# label residue 30 with "4.1 Ang^2 +/- 0.65 Ang^2; see the image at right
+
# label residue 30 with "4.1 Ang^2 +/- 0.65 Ang^2
label i. 30, "4.1" + u"\u00c5\u00b2  \u00b1 0.65 \u00c5\u00b2 ".encode('utf-8')
+
label i. 30, "4.1" + u"\u00c5\u00b2  \u00b1 0.65 \u00c5\u00b2 "
 
</source>
 
</source>
  
 +
== See Also ==
  
 +
* [[label]]
 +
* [[label_size]]
 +
* [[label_shadow_mode]]
  
 
[[Category:Settings|Label font id]]
 
[[Category:Settings|Label font id]]
 
[[Category:Labeling|Label font id]]
 
[[Category:Labeling|Label font id]]

Latest revision as of 01:14, 28 August 2017

The label_font_id setting sets the typeface (font family) for atom labels.

Syntax

# use "Serif Bold" font family
set label_font_id, 10

Available Font Families

Font IDs 0-4 were fixed size GLUT fonts, their support was dropped in PyMOL 1.6.

Name label_font_id
Sans 5
Sans Oblique 6
Sans Bold 7
Sans Bold Oblique 8
Serif 9
Serif Oblique 17
Serif Bold 10
Serif Bold Oblique 18
Mono 11
Mono Oblique 12
Mono Bold 13
Mono Bold Oblique 14
Gentium Roman 15
Gentium Italic 16

Special Characters

Several Unicode characters are supported. They can be entered with unicode literals as 4-digit hexadecimal escape sequences.

Example characters (find the code for your character at Unicode Charts):

Code Character Name
u"\u03b1" α Alpha
u"\u03b2" β Beta
u"\u00c5" Å Ångström
u"\u00b1" ± plus/minus
u"\u00b2" ² superscript 2

Example 1

The alpha and beta are Unicode characters.
# if Python is configured with utf-8 default encoding (all incentive builds)
label  5/CA, u"\u03b1-Helix"
label 10/CA, u"\u03b2-Sheet"

# if Python is configured differently, explicit utf-8 encoding is necessary
label  5/CA, u"\u03b1-Helix".encode("utf-8")
label 10/CA, u"\u03b2-Sheet".encode("utf-8")

# italic
set label_font_id, 16

# make bigger
set label_size, 50

# cast shadows in ray tracing
set label_shadow_mode, 3

Example 2

Notice the Angstrom and superscript 2 characters. You can add other characters as well.
# label residue 30 with "4.1 Ang^2 +/- 0.65 Ang^2
label i. 30, "4.1" + u"\u00c5\u00b2  \u00b1 0.65 \u00c5\u00b2 "

See Also