Package moss

Class MoleculeNtn

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Ctab, SLN, SMILES

public abstract class MoleculeNtn extends Notation
Class for (linear) notations for molecules.

A molecule is represented as a graph with atoms as nodes and bonds as edges.

General grammar for (linear) molecule descriptions:

  Molecule ::= Atom Branch
  Branch   ::= \epsilon
             | Bond Atom  Branch
             | Bond Label Branch
             | "(" Branch ")" Branch
  Atom     ::= Element LabelDef
  LabelDef ::= \epsilon
             | Label LabelDef

The definitions of the terms "Element", "Bond", and "Label" depend on the chosen description language. For the SMILES language it is:

  Element  ::= "[H]" | "[He]" | "[Li]" | "[Be]" | ...
             | "B" | "C" | "N" | "O" | "F" | ...
  Bond     ::= \epsilon | "-" | "=" | "#" | ":"
  Label    ::= [0-9] | "%" [0-9] [0-9]
Since:
2006.08.12
See Also:
  • Field Details

    • desc

      protected StringBuilder desc
      the buffer for creating molecule descriptions
  • Constructor Details

    • MoleculeNtn

      public MoleculeNtn()
      Create a molecule notation.
      Since:
      2023.07.31 (Christian Borgelt)
  • Method Details

    • hasFixedTypes

      public boolean hasFixedTypes()
      Whether this notation has a fixed set of (node and edge) types.
      Specified by:
      hasFixedTypes in class Notation
      Returns:
      true, because types are atoms and bonds
      Since:
      2007.06.29 (Christian Borgelt)
    • setNodeMgr

      public void setNodeMgr(TypeMgr nodemgr)
      Set the node type manager.

      This function has no effect, because node types are fixed.

      Overrides:
      setNodeMgr in class Notation
      Parameters:
      nodemgr - the new node type manager
      Since:
      2007.06.29 (Christian Borgelt)
      See Also:
    • setEdgeMgr

      public void setEdgeMgr(TypeMgr edgemgr)
      Set the edge type manager.

      This function has no effect, because edge types are fixed.

      Overrides:
      setEdgeMgr in class Notation
      Parameters:
      edgemgr - the new edge type manager
      Since:
      2007.06.29 (Christian Borgelt)
      See Also:
    • getHydros

      protected int getHydros() throws IOException
      Read shorthand hydrogen atoms.
      Returns:
      the number of shorthand hydrogen atoms
      Throws:
      IOException - if a read error occurred
      Since:
      2006.08.12 (Christian Borgelt)
    • getHydros

      protected static int getHydros(Node atom, Recoder coder)
      Get the number of adjacent hydrogen atoms (and mark them).
      Parameters:
      atom - the atom for which to get the adjacent hydrogens
      coder - the recoder for the atom types (if any)
      Returns:
      the number of shorthand hydrogen atoms
      Since:
      2006.08.12 (Christian Borgelt)
    • write

      public void write(Graph graph, Writer writer) throws IOException
      Write a description of a molecule.
      Specified by:
      write in class Notation
      Parameters:
      graph - the molecule to write
      writer - the writer to write to
      Throws:
      IOException - if a read error occurred
      Since:
      2007.06.22 (Christian Borgelt)