Class MDLV2000Writer

  • All Implemented Interfaces:
    Closeable, AutoCloseable, IChemObjectIO, IChemObjectWriter

    public class MDLV2000Writer
    extends DefaultChemObjectWriter
    Writes MDL molfiles, which contains a single molecule (see [Dalby, A. et. al.. Journal of Chemical Information and Computer Sciences. 1992. 32]). For writing a MDL molfile you can this code:
     MDLV2000Writer writer = new MDLV2000Writer(
       new FileWriter(new File("output.mol"))
     );
     writer.write((IAtomContainer)molecule);
     writer.close();
     

    The writer has two IO settings: one for writing 2D coordinates, even if 3D coordinates are given for the written data; the second writes aromatic bonds as bond type 4, which is, strictly speaking, a query bond type, but my many tools used to reflect aromaticity. The full IO setting API is explained in CDK News [Willighagen, E.L.. CDK News. 2004. 1]. One programmatic option to set the option for writing 2D coordinates looks like:

     Properties customSettings = new Properties();
     customSettings.setProperty(
      "ForceWriteAs2DCoordinates", "true"
     );
     PropertiesListener listener =
       new PropertiesListener(customSettings);
     writer.addChemObjectIOListener(listener);
     
    Source code:
    main
    IO options:
    NameQuestionDefault
    ProgramNameProgram name to write at the top of the molfile header, should be exactly 8 characters longCDK
    ForceWriteAs2DCoordinatesShould coordinates always be written as 2D?false
    WriteAromaticBondTypesShould aromatic bonds be written as bond type 4?false
    WriteMajorIsotopesWrite atomic mass of any non-null atomic mass including major isotopes (e.g. [12]C)true
    WriteDefaultPropertiesWrite trailing zero's on atom/bond property blocks even if they're not used.true
    WriteQueryFormatValenciesShould valencies be written in the MDL Query format? (deprecated)false
    Belongs to CDK module:
    io
    Keywords:
    file format, MDL molfile
    • Constructor Detail

      • MDLV2000Writer

        public MDLV2000Writer​(Writer out)
        Constructs a new MDLWriter that can write an IAtomContainer to the MDL molfile format.
        Parameters:
        out - The Writer to write to
      • MDLV2000Writer

        public MDLV2000Writer​(OutputStream output)
        Constructs a new MDLWriter that can write an IAtomContainer to a given OutputStream.
        Parameters:
        output - The OutputStream to write to
      • MDLV2000Writer

        public MDLV2000Writer()
    • Method Detail

      • close

        public void close()
                   throws IOException
        Flushes the output and closes this object.
        Throws:
        IOException - when the wrapper IO class cannot be closed.
      • accepts

        public boolean accepts​(Class<? extends IChemObject> classObject)
        Description copied from interface: IChemObjectIO
        Returns whether the given IChemObject can be read or written.
        Parameters:
        classObject - IChemObject of which is tested if it can be handled.
        Returns:
        true, if the IChemObject can be handled.
      • writeMolecule

        public void writeMolecule​(IAtomContainer container)
                           throws Exception
        Writes a Molecule to an OutputStream in MDL sdf format.
        Parameters:
        container - Molecule that is written to an OutputStream
        Throws:
        Exception
      • formatMDLInt

        protected static String formatMDLInt​(int x,
                                             int n)
        Formats an integer to fit into the connection table and changes it to a String.
        Parameters:
        x - The int to be formated
        n - Length of the String
        Returns:
        The String to be written into the connectiontable
      • formatMDLFloat

        protected static String formatMDLFloat​(float fl)
        Formats a float to fit into the connectiontable and changes it to a String.
        Parameters:
        fl - The float to be formated
        Returns:
        The String to be written into the connectiontable
      • formatMDLString

        protected static String formatMDLString​(String s,
                                                int le)
        Formats a String to fit into the connectiontable.
        Parameters:
        s - The String to be formated
        le - The length of the String
        Returns:
        The String to be written in the connectiontable
      • setWriteAromaticBondTypes

        public void setWriteAromaticBondTypes​(boolean val)
        Convenience method to set the option for writing aromatic bond types.
        Parameters:
        val - the value.
      • customizeJob

        public void customizeJob()