Skip to main content

Crate crabwurcs

Crate crabwurcs 

Source
Expand description

crabWURCS: a pure-Rust toolkit for glycan notation conversion, chemical-structure interop, and SNFG rendering.

This crate is a thin facade — it does no work itself, it just re-exports the workspace’s other crates under one name so a consumer can use crabwurcs::... instead of depending on each sub-crate individually. All real logic lives in:

  • core — the WURCS grammar and the shared core::ResidueGraph model
  • iupac — IUPAC condensed/extended notation
  • mol — MOL/SDF/SMILES chemical structure interop (MolWURCS equivalent)
  • pdb — glycan extraction from PDB/mmCIF structures
  • snfg — SNFG SVG rendering (seq2snfg equivalent)

The facade also contains compact source-WURCS and notation-derived lookup tables for all 943 GlycoShape records (938 molecularly specified structures plus four notation-only edge cases, with duplicate records sharing rows). Equivalent SMILES serializations are resolved by the pure-Rust molecular backend, with de-novo molecular extraction and an authoritative registry-derived index for every concrete monosaccharide.

The sections below — generated from the renderer’s own output — document every supported monosaccharide symbol, the SNFG rendering rules, and motif highlighting.

§Supported monosaccharides

crabWURCS renders the complete SNFG 2.0.4 symbol table. Every residue resolves to a shape + colour pair — together they encode the monosaccharide identity following the official Symbol Nomenclature for Glycans (the symbol alone is the label; residue abbreviations are optional).

The 87 entries below are the authoritative list returned by ResidueKind::ALL. Generic classes (marked generic) preserve unspecified stereochemistry: they keep their family colour but draw in white, match any member of their family in motif queries, and cannot be exported to GLYCAM (which would require assigning stereochemistry that is not present).

Each symbol image on this page is generated by render_symbol_svg from the same renderer that draws full glycan figures, so the legend can never drift from the library’s actual output.

§Hexoses — circle

SymbolNameWURCS UniqueRESAliasesGeneric
HexHexaxxxxh-1x_1-5Hexose
GlcGlca2122h-1x_1-5Glucose
ManMana1122h-1x_1-5Mannose
GalGala2112h-1x_1-5Galactose
GulGula2212h-1x_1-5Gulose
AltAlta1222h-1x_1-5Altrose
AllAlla1111h-1x_1-5Allose
TalTala1112h-1x_1-5Talose
IdoIdoa2121h-1x_1-5Idose

§N-Acetylhexosamines — square

SymbolNameWURCS UniqueRESAliasesGeneric
HexNAcHexNAcaxxxxh-1x_1-5_2*NCC/3=ON-Acetylhexosamine
GlcNAcGlcNAca2122h-1x_1-5_2*NCC/3=ON-Acetylglucosamine
ManNAcManNAca1122h-1x_1-5_2*NCC/3=ON-Acetylmannosamine
GalNAcGalNAca2112h-1x_1-5_2*NCC/3=ON-Acetylgalactosamine
GulNAcGulNAca2212h-1x_1-5_2*NCC/3=ON-Acetylgulosamine
AltNAcAltNAca1222h-1x_1-5_2*NCC/3=ON-Acetylaltrosamine
AllNAcAllNAca1111h-1x_1-5_2*NCC/3=ON-Acetylallosamine
TalNAcTalNAca1112h-1x_1-5_2*NCC/3=ON-Acetyltalosamine
IdoNAcIdoNAca2121h-1x_1-5_2*NCC/3=ON-Acetylidosamine

§Hexosamines — notched square

A white square with a coloured corner triangle indicates an amino (non-acetylated) sugar.

SymbolNameWURCS UniqueRESAliasesGeneric
HexNHexNaxxxxh-1x_1-5_2*NHexosamine
GlcNGlcNa2122h-1x_1-5_2*NGlucosamine
ManNManNa1122h-1x_1-5_2*NMannosamine
GalNGalNa2112h-1x_1-5_2*NGalactosamine
GulNGulNa2212h-1x_1-5_2*NGulosamine
AltNAltNa1222h-1x_1-5_2*NAltrosamine
AllNAllNa1111h-1x_1-5_2*NAllosamine
TalNTalNa1112h-1x_1-5_2*NTalosamine
IdoNIdoNa2121h-1x_1-5_2*NIdosamine

§Hexuronates — divided diamond

The coloured half of the diamond denotes a uronic acid. Most uronates colour the top half; IdoA is drawn with the bottom half coloured (brown), matching the official table.

SymbolNameWURCS UniqueRESAliasesGeneric
HexAHexAaxxxxA-1x_1-5Hexuronate, HexuronicAcid
GlcAGlcAa2122A-1x_1-5GlucuronicAcid
ManAManAa1122A-1x_1-5MannuronicAcid
GalAGalAa2112A-1x_1-5GalacturonicAcid
GulAGulAa2212A-1x_1-5GuluronicAcid
AltAAltAa1222A-1x_1-5AltruronicAcid
AllAAllAa1111A-1x_1-5AlluronicAcid
TalATalAa1112A-1x_1-5TaluronicAcid
IdoAIdoAa2121A-1x_1-5IduronicAcid

§6-Deoxyhexoses — triangle

SymbolNameWURCS UniqueRESAliasesGeneric
dHexdHexaxxxxm-1x_1-5Deoxyhexose
QuiQuia2122m-1x_1-5Quinovose
RhaRhaa2211m-1x_1-5Rhamnose
6dGul6dGula2212m-1x_1-56-DeoxyGulose
6dAlt6dAlta2111m-1x_1-56-DeoxyAltrose
6dTal6dTala1112m-1x_1-56-DeoxyTalose
FucFuca1221m-1x_1-5Fucose

§6-Deoxyhexosamines — divided triangle

SymbolNameWURCS UniqueRESAliasesGeneric
dHexNAcdHexNAcaxxxxm-1x_1-5_2*NCC/3=ODeoxyhexNAc
QuiNAcQuiNAca2122m-1x_1-5_2*NCC/3=ON-Acetylquinovosamine
RhaNAcRhaNAca2211m-1x_1-5_2*NCC/3=ON-Acetylrhamnosamine
6dAltNAc6dAltNAca2111m-1x_1-5_2*NCC/3=ON-Acetyl6-DeoxyAltrosamine
6dTalNAc6dTalNAca1112m-1x_1-5_2*NCC/3=ON-Acetyl6-DeoxyTalosamine
FucNAcFucNAca1221m-1x_1-5_2*NCC/3=ON-Acetylfucosamine

§2,6-Dideoxyhexoses — flat rectangle

SymbolNameWURCS UniqueRESAliasesGeneric
ddHexddHexadxxxm-1x_1-5Di-deoxyhexose, Dideoxyhexose
OliOliad122m-1x_1-5Olivose
TyvTyva1d22m-1x_1-5Tyvelose
AbeAbea2d12m-1x_1-5Abequose
ParPara2d22m-1x_1-5Paratose
DigDigad222m-1x_1-5Digitoxose
ColCola1d21m-1x_1-5Colitose

§Pentoses — star

SymbolNameWURCS UniqueRESAliasesGeneric
PenPenaxxxh-1x_1-5Pentose
AraAraa211h-1x_1-5Arabinose
LyxLyxa112h-1x_1-5Lyxose
XylXyla212h-1x_1-5Xylose
RibRiba222h-1x_1-5Ribose

§Nonulosonic acids (sialic acids) — diamond

SymbolNameWURCS UniqueRESAliasesGeneric
NulONulOAadxxxxxh-2x_2-63-deoxy-nonulosonicAcid, Nonulosonate
KdnKdnAad21122h-2x_2-6KDN
Neu5AcNeu5AcAad21122h-2x_2-6_5*NCC/3=ONeuAc, Neup5Ac
Neu5GcNeu5GcAad21122h-2x_2-6_5*NCCO/3=ONeuGc, Neup5Gc
NeuNeuAad21122h-2x_2-6_5*NNeuraminicAcid
SiaSia(no UniqueRES — display class only)SialicAcid

§3,9-Dideoxy-nonulosonic acids — flat diamond

SymbolNameWURCS UniqueRESAliasesGeneric
ddNulOddNulOAadxxxxxm-2x_2-6_5*N_7*N3,9-dideoxy-nonulosonicAcid
PsePseAad22111m-2x_2-6_5*N_7*NPseudaminicAcid
LegLegAad21122m-2x_2-6_5*N_7*NLegionaminicAcid
AciAciAad21111m-2x_2-6_5*N_7*NAcinetaminicAcid
4eLeg4eLegAad11122m-2x_2-6_5*N_7*N4-epi-Leg

§Unknown & bacterial — flat hexagon

SymbolNameWURCS UniqueRESAliasesGeneric
UnknownUnknown(no UniqueRES — display class only)UnknownSaccharide
BacBaca2122m-1x_1-5_2*N_4*NBacillosamine
LDmanHepLDmanHepa11221h-1x_1-5L-glycero-D-manno-Heptose
KdoKdoAad1122h-2x_2-6KDO
DhaDhaAad112A-2x_2-6
DDmanHepDDmanHepa11222h-1x_1-5D-glycero-D-manno-Heptose
MurNAcMurNAca2122h-1x_1-5_2*NCC/3=O_3*OC^RCO/4=O/3C
MurNGcMurNGca2122h-1x_1-5_2*NCCO/3=O_3*OC^RCO/4=O/3C
MurMura2122h-1x_1-5_2*N_3*OC^RCO/4=O/3CMuramicAcid

§Assigned & ketoses — pentagon

The white Assigned pentagon stands in for any user-named residue whose chemistry is not in the registry; its in-shape label is the uppercased first letter of the assigned name. The remaining pentagons are ketoses.

SymbolNameWURCS UniqueRESAliasesGeneric
AssignedAssigned(no UniqueRES — display class only)
ApiApia15h-1x_1-4_3*COApiose
FruFruha122h-2x_2-6Fructose
TagTagha112h-2x_2-6Tagatose
SorSorha121h-2x_2-6Sorbose
PsiPsiha222h-2x_2-6Psicose

§Programmatic access

Resolve a residue’s symbol at runtime with classify_residue and render_symbol_svg:

use crabwurcs::{RenderOptions, render_symbol_svg, residue_from_kind, ResidueKind};

let residue = residue_from_kind(ResidueKind::Glc).unwrap();
let svg = render_symbol_svg(&residue, &RenderOptions::default()).unwrap();
assert!(svg.contains("fill=\"#0072BC\"")); // official SNFG blue

Residues that arrive from a parsed notation (not the registry) are classified automatically — render_svg calls the same classifier, so any WURCS or IUPAC input resolves to the correct symbol without an explicit ResidueKind.

§SNFG rendering

render_svg and friends turn a ResidueGraph into an SNFG (Symbol Nomenclature for Glycans) figure. The output follows SNFG 2.0.4: shape encodes the chemical class, colour encodes the stereochemical family, and the layout places the reducing end on the right with children extending to the left.

§Shapes

Each monosaccharide family maps to a distinct geometric primitive. The gallery below shows one representative per shape; see Supported monosaccharides for the full table.

ShapeFamilyExample
CircleHexosesGlc
SquareN-AcetylhexosaminesGlcNAc
Notched squareHexosamines (amino, non-acetylated)GlcN
Divided diamond (top)HexuronatesGlcA
Divided diamond (bottom)Iduronic acidIdoA
Triangle6-DeoxyhexosesFuc
Divided triangle6-DeoxyhexosaminesFucNAc
Flat rectangle2,6-DideoxyhexosesOli
StarPentosesXyl
DiamondNonulosonic acids (sialic acids)Neu5Ac
Flat diamond3,9-Dideoxy-nonulosonic acidsLeg
Flat hexagonUnknown / bacterial / muramic acid familyKdo
PentagonAssigned & ketosesFru

§Colour palette

The official SNFG RGB palette. Generic classes (unspecified stereochemistry) draw in white while keeping their family shape.

NameHexSwatch
White#FFFFFFwhite
Blue#0072BCblue
Green#00A651green
Yellow#FFD400yellow
Orange#F47920orange
Pink#F69EA1pink
Purple#A54399purple
Light blue#8FCCE9light blue
Brown#A17A4Dbrown
Red#ED1C24red

Family → colour assignment follows the standard mapping: Glc blue, Gal yellow, Man green, Fuc red, sialic acids purple/light-blue, iduronic brown, and so on. Generic classes (e.g. Hex, HexNAc) keep the family shape but fill white.

§Layout

The renderer lays the glycan out as a rooted tree:

  • Root on the right. The reducing-end residue sits at the right edge of the canvas; every child extends one step (100 px) to the left.
  • Post-order vertical packing. A parent is centred vertically between its children; leaf residues are stacked at 100 px vertical spacing.
  • Branch order follows the acceptor position. Higher acceptor positions sit above lower ones — for example the N-glycan α1-6 arm is drawn above α1-3, and β1-4 above β1-2.
  • Terminal deoxy-sugar lanes. Terminal fucose and rhamnose residues are drawn vertically aligned with their parent. When a parent carries both a α1-3 and α1-6 fucose (or α1-2 and α1-4 rhamnose), they are split above and below the parent instead of overlapping; a single such branch and the core α6-fucose default to one side so no residue is overprinted.
  • Disconnected components (compositions, undefined antennae) are all laid out rather than silently dropped.

Linkage labels (α3, β4, etc.) are placed beside each bond, rotated to the bond angle. Repeat/cyclic and undefined bonds draw as dashed grey lines; an unknown position renders as ?.

§Composition layout

WURCS compositions (a multiset of residues with no linkage information) render as a single row of grouped symbols, each with a ×N count.

composition

§Render options

RenderOptions controls the figure:

FieldDefaultEffect
colourtrueFill shapes with the SNFG palette; false draws outlines only.
show_labelsfalseDraw residue abbreviations inside shapes. Off by default — SNFG convention is that shape + colour is the label.
show_linkagestrueDraw anomeric and position labels on each bond.
font_familyArial, Helvetica, sans-serifFont stack for all text.
scale1.0Uniform scale of the whole figure.
source_notationNoneRecords the exact input notation in the SVG metadata.

Assigned pentagons always show their first-letter label regardless of show_labels, because their identity is not recoverable from shape or colour.

§Output formats

use crabwurcs::{render_svg_with_options, render_png, RenderOptions};

let graph = crabwurcs::iupac::parse_iupac_condensed("Gal(b1-4)GlcNAc").unwrap();

let svg = render_svg_with_options(&graph, &RenderOptions::default()).unwrap();
let png = render_png(&graph).unwrap(); // transparent 2× RGBA

§Embedded metadata

Every SVG carries an invisible <metadata> block (crabwurcs:notations) with:

  • the canonical IUPAC condensed form,
  • the canonical WURCS form, and
  • the original source notation and detected format (when available).

Each field is marked available="true|false" so a downstream tool knows when a canonical form could not be produced (for example an Assigned residue that cannot be represented in WURCS) without failing the render.

§Motif highlighting

render_svg_with_motifs de-emphasises every residue outside a motif of interest, so a specific substructure stands out against the rest of the glycan. This is the same GlycoDraw-compatible look used by the crabwurcs render --highlight-motif CLI flag.

§At a glance

Target: Neu5Ac(a2-3)Gal(b1-4)[Fuc(a1-3)]GlcNAc. Highlighted motif: Gal(b1-4)[Fuc(a1-3)]GlcNAc.

Without highlightWith motif highlighted
plainhighlighted

Matched residues and the motif-internal bonds keep their full SNFG colour; the non-matching Neu5Ac branch and its bond drop to the muted palette below.

§How matching works

Matching is structural and wildcard-aware, implemented by find_motif_matches. The motif is an ordinary ResidueGraph parsed from WURCS, IUPAC (condensed or extended), or GLYCAM.

  • Injective, directed, non-induced. Each motif node maps to one target node; extra branches and extra residue modifications on the target are allowed and do not block a match.
  • Unknown anomers and positions are wildcards. Fuc(a1-?)GlcNAc matches Fuc(a1-3)GlcNAc, Fuc(a1-4)GlcNAc, etc.
  • Generic classes match their whole family. A motif residue Hex matches Glc, Man, Gal, and every other hexose; HexNAc matches every N-acetylhexosamine; Sia matches Neu5Ac, Neu5Gc, Kdn, Neu. This follows ResidueKind::matches_family, so a single generic motif captures every stereochemical variant in its row of the SNFG table.
  • Union over motifs and occurrences. Every occurrence of every supplied motif is highlighted; passing several motifs builds up the union of their matches. An empty motif list is identical to a plain render.

Boundary edges — the bonds between a matched region and the rest of the target — are treated as outside the motif and dimmed with their target-side residue.

§The muted palette

Dimmed residues stay fully opaque (they must occlude the bonds drawn behind them) but drop to desaturated versions of the SNFG colours:

SNFG colourMuted
Blue #0072BC#CDE7EF
Green #00A651#CDE9DF
Yellow #FFD400#FFF6DE
Orange #F47920#FDE7E0
Pink #F69EA1#FDF0F1
Purple #A54399#F1E6ED
Light blue #8FCCE9#EEF8FB
Brown #A17A4D#F1E9E5
Red #ED1C24#F7E0E0

Bonds and text outside a match draw in light grey #D9D9D9.

§Usage

use crabwurcs::{render_svg_with_motifs, RenderOptions};

let target = crabwurcs::iupac::parse_iupac_condensed(
    "Neu5Ac(a2-3)Gal(b1-4)[Fuc(a1-3)]GlcNAc",
).unwrap();

// Wildcard linkage position — matches α3 or α4 fucose.
let motif = crabwurcs::iupac::parse_iupac_condensed("Gal(b1-4)[Fuc(a1-?)]GlcNAc").unwrap();

let svg = render_svg_with_motifs(&target, &[motif], &RenderOptions::default()).unwrap();

Repeat the call with several motifs to highlight a union of substructures. PNG output is available through render_png_with_motifs.

§Motif constraints

A motif must describe a connected, directed tree of known residues. The matcher returns MotifError otherwise:

VariantMeaning
EmptyThe motif graph has no residues.
CompositionCompositions cannot be used as motifs.
DisconnectedThe motif is not a single connected graph.
NotTreeThe motif is not a directed tree rooted at its reducing end.
CycleOrRepeatThe motif contains a cycle or a repeat-closing edge.
UndefinedLinkageThe motif contains an undefined (candidate-parent) linkage.
UndefinedModificationThe motif contains an undefined (candidate-parent) modification.

Re-exports§

pub use crabwurcs_core as core;
pub use crabwurcs_iupac as iupac;
pub use crabwurcs_mol as mol;
pub use crabwurcs_pdb as pdb;
pub use crabwurcs_snfg as snfg;

Structs§

ExtractedGlycan
ExtractedGlycanWithProvenance
An extracted glycan together with the source residue identity for every graph node. The legacy ExtractedGlycan API remains available for callers that only need the graph.
HighlightSelection
Exact graph elements to keep vivid in a highlighted SNFG rendering. Indices are the stable petgraph node/edge indices exposed by the source ResidueGraph; elements not listed here are rendered with the muted SNFG palette.
MotifMatch
PdbResidueReference
A graph-node provenance record retained from the source PDB/mmCIF file.
RenderOptions
ResidueGraph
SourceNotation

Enums§

ConversionError
CoreError
Format
MotifError
ResidueKind
SnfgError

Functions§

classify_residue
Classify a WURCS residue as an official SNFG 2.0.4 residue.
convert
detect_format
extract_glycans_from_file
extract_glycans_from_str
extract_glycans_with_provenance_from_file
Extract glycans from a PDB/mmCIF file while retaining source residue identities for every graph node.
extract_glycans_with_provenance_from_str
Extract glycans from a PDB or mmCIF string while retaining source residue identities for every graph node.
find_motif_matches
Find every injective, directed, non-induced occurrence of motif in target.
normalize_wurcs
parse_notation
render_png
Render an SNFG diagram as a transparent PNG at twice the SVG dimensions.
render_png_with_motifs
Render a motif-highlighted SNFG diagram as a transparent PNG at twice the SVG dimensions.
render_png_with_options
Render an SNFG diagram as a transparent PNG using the supplied SVG rendering options.
render_png_with_selection
Render an exact-selection SNFG diagram as a transparent PNG at twice the SVG dimensions.
render_svg
render_svg_with_motifs
Render an SNFG SVG while highlighting the union of every occurrence of every supplied motif.
render_svg_with_options
render_svg_with_selection
Render an SNFG SVG with exactly the supplied graph nodes and edges highlighted. This is intended for callers that have already resolved a specific occurrence and must not highlight every matching motif.
render_symbol_svg
Render a single SNFG symbol as a tightly-cropped, transparent-background SVG.
residue_from_kind
standardize_wurcs
Backward-compatible name for normalize_wurcs.
write_iupac_condensed_canonical
Serialize a graph to canonical IUPAC condensed without reusing a preserved source string from parsing.
write_notation
write_wurcs_canonical
Serialize a graph to canonical WURCS without reusing a preserved source string from parsing.

Type Aliases§

ConversionResult
CoreResult
SnfgResult