NamedMolecule { name: "caffeine".into(), .. } draws a molecule by its common name, like
Molecule draws a SMILES string. The name is looked up in a table of about a hundred
common molecules written for the kit. It covers small inorganic molecules, hydrocarbons,
aromatics and heterocycles, alcohols, acids, sugars, amino acids, nucleobases, and drugs
and hormones (caffeine, aspirin, glucose, cholesterol, morphine). Nothing is looked up over
the network.
Case, hyphens and underscores do not matter ("Vitamin-C" finds "vitamin c"). A name
that is not in the table draws nothing, and inspect warns about it. named_smiles(name)
gives the SMILES, and named_molecules() lists the table. Gallery scenes: MoleculeParade
(five named molecules drawn in turn into a lineup) and NamedMolecule
(caffeine, vanillin and dopamine).

MoleculeParade 6.5 s
NamedMolecule 3 suse fframes_kit::prelude::*;
fn figure<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> { ui.show(NamedMolecule { name: "glucose".into(), center: (0.0, 0.0), enter: Some(Create::default().into()), ..ui.defaults() })}Components are plain structs. Set the fields you need and fill the rest with ..ui.defaults(): the defaults below come from the current theme (theme. values are fields of Theme).
NamedMolecule
Section titled “NamedMolecule”| Field | Type | Default | Description |
|---|---|---|---|
name |
Cow<str> |
Cow::Borrowed("caffeine") |
Common name of the molecule ("caffeine", "glucose"); case, hyphens and underscores do not matter. A name not in the table draws nothing. |
center |
(f64, f64) |
m.center |
The middle of the molecule’s coordinates, in units of ui.space. |
bond_length |
f32 |
m.bond_length |
Pixels per bond length of the laid-out structure. |
show_hydrogens |
bool |
m.show_hydrogens |
Writes the hydrogens and charge after a heteroatom’s symbol (OH, NH2); false writes the symbol alone. |
color_atoms |
bool |
m.color_atoms |
Colours the labels of oxygen, nitrogen, sulfur, phosphorus and the halogens; false uses bond_color for all. |
bond_color |
Color |
m.bond_color |
Colour of the bonds, and of the labels of carbon and of every atom when color_atoms is false. |
stroke_width |
f32 |
m.stroke_width |
Width in pixels of the bond lines. |
enter |
Option<EnterAnim> |
None |
How the bonds draw on; None shows them from the start. |
exit |
Option<ExitAnim> |
None |
How the bonds leave at the end of the container; None stays. |
parts_enter |
Option<FadeIn> |
None |
Fade in of the atom labels; None for none. |
parts_exit |
Option<FadeOut> |
None |
Fade out of the atom labels before the end; None for none. |
Feature chemistry · Source
