Class XmlChemDrawReader

All Implemented Interfaces:
javajs.api.GenericLineReader
Direct Known Subclasses:
CDXReader

public class XmlChemDrawReader extends XmlReader
A reader for ChemDraw CDXML files. See https://www.cambridgesoft.com/services/documentation/sdk/chemdraw/cdx/IntroCDXML.htm for the full, detailed specification. Here we are just looking for simple aspects that could be converted to valid 2D MOL files, SMILES, and InChI. Fragments (such as CH2CH2OH) and "Nickname"-type fragments such as Ac and Ph, are processed correctly. But their 2D representations are pretty nuts. ChemDraw does not make any attempt to place these in reasonable locations. That said, Jmol's 3D minimization does a pretty fair job, and the default is to do that minimization. If minimization and addition of H is not desired, use FILTER "NOH" or FILTER "NO3D" XmlChemDrawReader also serves as the reader for binary CDX files, as CDXReader subclasses this class. See that class for details.
Author:
hansonr
  • Field Details

    • minX

      private float minX
    • minY

      private float minY
    • minZ

      private float minZ
    • maxZ

      private float maxZ
    • maxY

      private float maxY
    • maxX

      private float maxX
    • no3D

      private boolean no3D
      ChemDraw can mess up 3D completely with octahedral stereochemistry; setting filter "no3D" ensures the raw 2D structure is returned.
    • fragments

      private Stack<String> fragments
    • thisFragment

      private String thisFragment
    • thisNode

      private XmlChemDrawReader.CDNode thisNode
    • nodes

    • nostereo

      private List<XmlChemDrawReader.CDNode> nostereo
    • textBuffer

      private String textBuffer
      temporary holder of style chunks within text objects
  • Constructor Details

    • XmlChemDrawReader

      public XmlChemDrawReader()
  • Method Details

    • processXml

      protected void processXml(XmlReader parent, Object saxReader) throws Exception
      Overrides:
      processXml in class XmlReader
      Parameters:
      parent -
      saxReader -
      Throws:
      Exception
    • processStartElement

      public void processStartElement(String localName, String nodeName)
      Overrides:
      processStartElement in class XmlReader
      Parameters:
      localName -
      nodeName - TODO
    • processEndElement

      void processEndElement(String localName)
      Overrides:
      processEndElement in class XmlReader
      Parameters:
      localName -
    • setNode

      private void setNode(String id)
      Set the atom information. Reading: NodeType, Warning. Element, Isotope, Charge, xyz, p 3D coordinates xyz is only used if there are no 2D p coordinates. This may not be possible. I don't know. These aren't real 3D coordinates, just enhanced z values.
      Parameters:
      id -
    • checkWarningOK

      private boolean checkWarningOK(String warning)
    • setBond

      private void setBond()
      Process the bond tags. We only look at the following attributes: B beginning atom (atom1) E ending atom (atom2) BeginAttach associates atom1 with a fragment EndAttach associates atom2 with a fragment Order -- the bond order Display -- wedges and such Display2 -- only important here for partial bonds bonds to multiple attachments are not actually made.
    • setAtom

      private void setAtom(String key)
      Set the 2D or pseudo-3D coordinates of the atoms. ChemDraw pseudo-3D is just a z-layering of chunks of the molecule. Nothing really useful. These coordinates are ignored if there are any atoms also with 2D coordinates or for FILTER "NO3D". So, pretty much, the z coordinates are never used.
      Parameters:
      key -
    • finalizeSubclassReader

      protected void finalizeSubclassReader() throws Exception
      Fix connections to Fragments and Nicknames, adjust stereochemistry for wavy displays, flag invalid atoms, and adjust the scale to something more molecular. Finalize the 2D/3D business.
      Overrides:
      finalizeSubclassReader in class XmlReader
      Throws:
      Exception
    • fixConnections

      private void fixConnections()
      First fix all the attachments, tying together the atoms identified as ExternalConnectionPoints with atoms of bonds indicating "BeginAttach" or "EndAttach". Then flag all unconnected atoms and also remove any wedges or hashes that are associated with bonds to atoms that also have wavy bonds.
    • centerAndScale

      private void centerAndScale()
      Adjust the scale to have an average bond length of 1.45 Angstroms. This is just to get the structure in the range of other structures rather than being huge.
    • fixInvalidAtoms

      private void fixInvalidAtoms()
      Remove fragment, external point, or invalid unconnected nodes (including unconnected carbon nodes, which can arise from deletions (in my experience) and are then not noticed because they have no associated text.