AvogadroLibs 2.1.0-20261111
Loading...
Searching...
No Matches
SmilesWriter Class Reference

Serialize a molecule to a SMILES string. More...

#include <avogadro/io/smileswriter.h>

Public Types

enum class  HydrogenMode {
  Implicit ,
  Bracket ,
  Explicit
}

Public Member Functions

void setHydrogenMode (HydrogenMode mode)
HydrogenMode hydrogenMode () const
void setAtomMaps (bool enable)
bool atomMaps () const
void setAromatic (bool enable)
bool aromatic () const
HydrogenMode effectiveHydrogenMode () const
bool write (const Core::Molecule &molecule, std::string &smiles)
const std::string & error () const

Detailed Description

Tetrahedral chirality and double bond direction markers are read out of the molecule's coordinates, so they are written only for a molecule that has them; a structure without 3D positions is written without stereochemistry rather than with a guess. Which centres count as stereogenic is decided constitutionally, within the limits documented in atomequivalence_p.h.

Where a source marked a configuration undefined – see Core::stereo.h – that is honoured and no descriptor is written, since the coordinates in that case are a placement rather than a claim.

Member Enumeration Documentation

◆ HydrogenMode

enum class HydrogenMode
strong

How hydrogens are represented in the output.

Enumerator
Implicit 

Inferred from the valence model, so methane is written "C".

Bracket 

A count inside the bracket, so methane is written "[CH4]".

Explicit 

Separate atoms, so methane is written "[H][C]([H])([H])[H]".

Member Function Documentation

◆ setHydrogenMode()

void setHydrogenMode ( HydrogenMode mode)

Set how hydrogens are represented. Note that atomMaps() overrides this, see setAtomMaps().

◆ setAtomMaps()

void setAtomMaps ( bool enable)

Emit each atom's index as a Daylight atom map class, so that the string can be correlated back to the molecule it came from.

Classes are written one-based, because Daylight assigns class zero the meaning "unmapped"; a consumer reading the classes back must subtract one to recover the Avogadro atom index.

This implies HydrogenMode::Explicit. A hydrogen folded into a bracket count has nowhere to carry a class, and in Avogadro that hydrogen is a real atom with a real index, so folding it would silently produce a partial mapping.

◆ setAromatic()

void setAromatic ( bool enable)

Write perceived aromatic rings in the lowercase form, so benzene is "c1ccccc1" rather than "C1=CC=CC=C1". Both describe the same molecule; the lowercase form is what most toolkits produce and expect, so it is enabled by default and callers wanting Kekule output must ask for it.

Perception is Core::AromaticityPerceiver; anything it does not recognise is written with its bond orders as stored.

◆ effectiveHydrogenMode()

HydrogenMode effectiveHydrogenMode ( ) const
Returns
The hydrogen mode that will actually be used, after applying the implication described in setAtomMaps().

◆ write()

bool write ( const Core::Molecule & molecule,
std::string & smiles )

Write molecule to smiles.

Returns
True on success, false on failure, in which case error() gives more detail and smiles is left empty.

◆ error()

const std::string & error ( ) const
Returns
A description of the last failure, or an empty string.

The documentation for this class was generated from the following file: