vibesketch.render.chemfig¶
chemfig source for LaTeX: structures as a walk with angles, schemes with arrows.
chemfig (Christian Tellechea, CTAN) draws a molecule from a walk over its
atoms: every bond carries an absolute angle and a length coefficient,
branches are parenthesised, and a bond that closes a ring is a hook,
?[a] at the first atom and ?[a,{=}] at the second. This module
reproduces the drawing rather than idealising it: a spanning tree by
depth-first search from the leftmost terminal atom, the bond angles and
relative lengths read off the 2D coordinates, and the remaining bonds as
hooks. Fused and bridged rings therefore come out exactly as drawn, which is
why chemfig’s ring macros (*6(...)) are not used.
Atom labels follow chemfig’s rule that a new atom starts at every capital
letter: carbon is implicit, a heteroatom carries its hydrogens on the side
away from its bonds (HO- and -OH) and its charge as a superscript,
and every bond names the atom it leaves and arrives at (-[:30,,2,1]) so a
label such as H_2N attaches at the nitrogen. A heteroatom with bonds on
both sides draws its hydrogens as atoms of their own in the free direction.
Stereo bonds are chemfig’s Cram bonds, > and >: widening towards the
atom in front, with the direction taken from the walk. Aromatic rings are
written in a Kekulé form.
Reactions become \schemestart ... \schemestop with \+ between
species, reagents above and conditions and the yield below the arrow, and
compound numbers under their structures with \chemname. The arrow kinds
map to ->, <=> and <->; a retrosynthetic arrow is drawn with
TikZ’s double -Implies tip, which chemfig loads. The result is a
fragment for \input in a document that loads the chemfig package.
Functions
|
|
|
The document's structures and reactions as a chemfig fragment. |
Exceptions
The structure or scheme cannot be expressed in chemfig. |
- exception vibesketch.render.chemfig.ChemfigRefused[source]¶
Bases:
ValueErrorThe structure or scheme cannot be expressed in chemfig.
- vibesketch.render.chemfig.chemfig_molecule(mol)[source]¶
\chemfig{...}for an RDKit molecule with 2D coordinates.Hydrogens are implicit unless the molecule keeps them as atoms. Raises
ChemfigRefusedfor a bond chemfig cannot draw or a structure with no coordinates.
- vibesketch.render.chemfig.chemfig_source(document)[source]¶
The document’s structures and reactions as a chemfig fragment.
Every reaction is a scheme; species in no reaction follow as structures of their own. Raises
ChemfigRefusedwhen there is nothing to draw or a species a reaction needs has no structure.