Class MDocument

  • All Implemented Interfaces:
    chemaxon.core.structure.DocumentForBuilder, MTransformable, Serializable
    Direct Known Subclasses:
    MSelectionDocument

    @PublicAPI
    public class MDocument
    extends Object
    implements MTransformable, Serializable, chemaxon.core.structure.DocumentForBuilder
    Marvin document. Stores molecules and graphics objects. There are two main groups of graphic objects. One of them contains simple objects without chemical meaning, these are stored directly in this document. The other group, called extra objects, has chemical meaning and belongs to a chemical structure. Extra object are:
    • reaction arrow
    • S-group bracket
    Extra objects are stored in the related chemical structure, but they are available from this class.
    Since:
    Marvin 3.1.4
    See Also:
    Serialized Form
    • Constructor Detail

      • MDocument

        public MDocument​(MoleculeGraph m)
        Creates a document for the specified molecule graph.
        Parameters:
        m - the main molecule graph
        Throws:
        IllegalArgumentException - if the given molecule has a parent (root, rgroup, component)
      • MDocument

        public MDocument​(Molecule[] mols)
        Creates a document for the specified molecule animation.
        Parameters:
        mols - the molecule animation
        Since:
        Marvin 4.0, 06/30/2005
      • MDocument

        public MDocument​(MDocument doc)
        Copy constructor.
        Parameters:
        doc - the source
      • MDocument

        protected MDocument​(MDocument doc,
                            boolean cloneobjs)
        Copy constructor.
        Parameters:
        doc - the source
        cloneobjs - whether to clone objects
        Since:
        Marvin 3.5, 11/06/2004
    • Method Detail

      • cloneTemporraryObjects

        protected void cloneTemporraryObjects​(MDocument doc)
      • cloneSets

        public void cloneSets​(MDocument doc)
        Clones the atom/bond sets from doc.
        Parameters:
        doc - the document to clone from.
      • cloneDocument

        public MDocument cloneDocument()
        Creates a clone.
        Returns:
        the clone
        Since:
        Marvin 3.5.1, 11/20/2004
      • cloneMainMolecule

        public final Molecule cloneMainMolecule()
        Creates a clone.
        Returns:
        the main molecule of the clone
        Throws:
        ClassCastException - if the main molecule graph is not a Molecule instance
        Since:
        Marvin 3.5.1, 11/20/2004
      • cloneMainMoleculeGraph

        public final MoleculeGraph cloneMainMoleculeGraph()
        Creates a clone.
        Returns:
        the main molecule graph of the clone
        Since:
        Marvin 3.5.1, 11/20/2004
      • clone

        public final Object clone()
        Creates a clone.
        Overrides:
        clone in class Object
        Returns:
        the clone
      • removeAtomFromGraphs

        public void removeAtomFromGraphs​(MolAtom node)
        Removes the specified node from all molecule graphs.
        Parameters:
        node - the node to remove
      • selectAllObjects

        public void selectAllObjects​(boolean s)
        Selects or unselects all objects.
      • selectAllConnectedObjects

        public void selectAllConnectedObjects​(boolean s)
        Selects or unselects all objects in this document and objects that belong to the chemical structure of this document.
      • getObjectContainingSelection

        public MObject getObjectContainingSelection()
        Gets the object that contains the selection.
        Returns:
        the object or null
      • setObjectContainingSelection

        public void setObjectContainingSelection​(MObject o)
        Sets the object that contains the selection. All other objects's contents are unselected.
        Parameters:
        o - the object or null
      • isHighlighted

        public boolean isHighlighted​(MObject o)
        Is the specified object currently highlighted?
        Returns:
        true if it is highlighted, false otherwise
      • highlight

        public void highlight​(MObject o)
        Highlight an object.
        Parameters:
        o - the object to highlight
      • unhighlight

        public void unhighlight​(MObject o)
        Unhighlights an object.
        Parameters:
        o - the object to unhighlight
      • unhighlightAll

        public void unhighlightAll()
        Unhighlights all objects.
      • getDraggedObject

        public MObject getDraggedObject()
        Gets the dragged object
        Returns:
        the dragged object or null
      • setDraggedObject

        public void setDraggedObject​(MObject o)
        Sets the dragged object.
        Parameters:
        o - the object
      • getFocus

        public MObject getFocus()
        Gets the focused object
        Returns:
        the focused object or null
      • setFocus

        public void setFocus​(MObject o)
        Focus to the specified object.
        Parameters:
        o - the object
      • getMainMoleculeGraph

        public MoleculeGraph getMainMoleculeGraph()
        Gets the main molecule graph.
        Returns:
        the molecule graph
      • setMainMoleculeGraph

        public void setMainMoleculeGraph​(MoleculeGraph m)
        Sets the main molecule graph.
        Parameters:
        m - the molecule graph
      • getMoleculeMovie

        public chemaxon.struc.graphics.MMoleculeMovie getMoleculeMovie()
        Gets the molecule movie.
        Returns:
        the molecule movie or null
        Since:
        Marvin 4.0, 06/30/2005
      • getPrimaryMolecule

        public Molecule getPrimaryMolecule()
        Gets the primary molecule object. The main molecule graph is returned if it is a molecule, unless it is empty and a molecule movie is also present. In that case, the current molecule of the movie is returned. WARNING! Do not change the returned molecule object! The document may become corrupted.
        Returns:
        the array of molecules
        Since:
        Marvin 4.0, 06/30/2005
      • getPrimaryMolecules

        public Molecule[] getPrimaryMolecules()
        Gets an array containing the primary molecule objects. The main molecule graph is returned if it is a molecule, unless it is empty and a molecule movie is also present. In that case, the molecules of the movie are returned. WARNING! Do not change the returned molecule objects! The document may become corrupted.
        Returns:
        the array of molecules
        Since:
        Marvin 4.0, 06/30/2005
      • getAllMolecules

        public Molecule[] getAllMolecules()
        Gets an array containing all molecule objects. WARNING! Do not change the returned molecule objects! The document may become corrupted.
        Returns:
        the array of molecules
        Since:
        Marvin 4.0, 06/30/2005
      • getAllNonEmptyMolecules

        public Molecule[] getAllNonEmptyMolecules()
        Gets an array containing all non-empty molecule objects. WARNING! Do not change the returned molecule objects! The document may become corrupted.
        Returns:
        the array of molecules
        Since:
        Marvin 4.0, 06/30/2005
      • setMoleculeMovie

        public void setMoleculeMovie​(chemaxon.struc.graphics.MMoleculeMovie mmm)
        Sets the molecule movie.
        Parameters:
        mmm - the molecule movie
        Since:
        Marvin 4.0, 06/30/2005
      • indexOf

        public int indexOf​(MObject o)
        Searches for an object in the document or in the chemical structure that belongs to the document.
        Parameters:
        o - the object
        Returns:
        the object's index if found, -1 otherwise
      • moveObject

        public void moveObject​(MObject o,
                               int i)
        Move an object to another place in the stack.
        Parameters:
        o - the object
        i - the new position
      • moveMainMoleculeGraphToFront

        public void moveMainMoleculeGraphToFront()
        Move the main molecule graph to the top of stack.
      • moveMoleculeMovieToFront

        public void moveMoleculeMovieToFront()
        Move the molecule movie (if exists) to the top of stack.
        Since:
        Marvin 4.0, 06/30/2005
      • contains

        public boolean contains​(MObject o)
        Searches an object in the document.
        Parameters:
        o - the object
        Returns:
        true if the document contains the object, false otherwise
      • contains

        public boolean contains​(MDocument doc)
        Tests whether the document contains all objects of another document.
        Parameters:
        doc - the other document
        Returns:
        true if the document contains the objects of the other document, false otherwise
        Since:
        Marvin 3.4
      • containsOnlyOne

        public boolean containsOnlyOne​(Class cl)
        Tests whether the document contains only one object of the specified class.
        Parameters:
        cl - MObject.class or a derived class
        Returns:
        true if no more and not less than one non-empty object is instance of the specified class
        Since:
        Marvin 3.5, 07/12/2004
      • addObject

        public void addObject​(MObject o)
        Adds an object to the document.
        Parameters:
        o - the object
      • isExtraObject

        public boolean isExtraObject​(MObject o)
        Decides whether a graphic object belongs to the main chemical structure of the document.
        Parameters:
        o - the graphic object
        Returns:
        true if the graphic object belongs to the main chemical structure, false otherwise.
      • removeObject

        public void removeObject​(MObject o)
        Removes an object from the document or from the chemical structure of the document.
        Parameters:
        o - the object
      • removeObject

        public void removeObject​(int i)
        Removes an object from the document.
        Parameters:
        i - the object index
      • getObjectCount

        public int getObjectCount()
        Gets the number of objects in this document.
        Returns:
        the number of objects
      • getConnectedObjectCount

        public int getConnectedObjectCount()
        Gets the number of objects in this document and in the chemical structure of this document.
        Returns:
        the number of objects
      • getObject

        public MObject getObject​(int i)
        Gets an object from the document.
        Parameters:
        i - the index of the object
        Returns:
        the object at the specified index.
      • getConnectedObject

        public MObject getConnectedObject​(int i)
        Gets an object from the document or from the chemical structure of the document.
        Parameters:
        i - the index of the object
        Returns:
        the object at the specified index.
      • getAllObjects

        public List<MObject> getAllObjects()
        Gets all objects stored in this document and from the chemical structure of the document.
        Returns:
        the list of objects
      • setObject

        public void setObject​(MObject o,
                              int i)
        Sets an object
        Parameters:
        o - the object
        i - the index
      • removeAtom

        public void removeAtom​(MolAtom a)
        Removes an atom from all the chemical graphs and removes all graphics objects that contain its reference.
        Parameters:
        a - the atom to remove
        Since:
        Marvin 3.5, 07/05/2004
      • removeAtom

        public void removeAtom​(MolAtom a,
                               int cleanupFlags)
        Removes an atom from all the chemical graphs and removes all graphics objects that contain its reference.
        Parameters:
        a - the atom to remove
        cleanupFlags - cleanup options
        Since:
        Marvin 4.1, 03/07/2006
      • clear

        public void clear()
        Clears the document. Removes all objects except the main molecule graph, from which all atoms, bonds and other objects are removed.
      • clearSets

        public void clearSets()
        Clears the atomSets and the bondSets.
      • isEmpty

        public boolean isEmpty()
        Tests whether the document is empty:
        • the main molecule object in the document is empty
        • no graphic object is included (neither simple nor extra)
        Returns:
        true if the document is empty, false otherwise
      • isSimpleMolecule

        public boolean isSimpleMolecule()
        Tests whether the document is equivalent to a simple molecule.
        Returns:
        true if the document does not have extra properties, false otherwise
        Since:
        Marvin 4.1, 11/19/2005
      • simplifyMolecule

        public void simplifyMolecule()
        Simplifies the main molecule object if possible. Note that it makes the original molecule object invalid.
        Since:
        Marvin 4.1.13, 09/20/2007
        See Also:
        Molecule.getSimplifiedMolecule()
      • transform

        public void transform​(CTransform3D t)
        Transforms all object's coordinates.
        Specified by:
        transform in interface MTransformable
        Parameters:
        t - the transformation matrix
      • calcCenter

        public DPoint3 calcCenter()
        Calculates the geometrical center.
        Returns:
        the center in `absolute' coordinates
      • calcCenter

        public DPoint3 calcCenter​(CTransform3D t)
        Calculates the geometrical center.
        Parameters:
        t - the viewing transformation or null
        Returns:
        the center in transformed coordinates
        Since:
        Marvin 4.1, 04/28/2006
      • getStartPosition

        public long getStartPosition()
        Gets the starting position of this document in the input file.
        Returns:
        the starting position
      • setStartPosition

        public void setStartPosition​(long off)
        Sets the starting position of this document in the input file.
        Parameters:
        off - the starting position
      • getEndPosition

        public long getEndPosition()
        Gets the end position of this document in the input file.
        Returns:
        the end position
      • setEndPosition

        public void setEndPosition​(long off)
        Sets the end position of this document in the input file.
        Parameters:
        off - the end position
      • getInputFormat

        public final String getInputFormat()
        Gets the input file format. Set by the import module if the molecule is from a file.
        Returns:
        the input file format for the document
      • setInputFormat

        public void setInputFormat​(String format)
        Sets the input file format.
        Parameters:
        format - the input format
      • exportToObject

        @Deprecated
        public Object exportToObject​(String fmt)
                              throws IOException
        Deprecated.
        As of release 5.7, replaced by MolExporter.exportToObject(MDocument, String)
        Creates a String, byte[] array or Image representation of the molecule. When creating an image, display options can also be specified in the format descriptor string. Format and options are separated by a colon, multiple options can be separated by commas. See the possible formats and their options on the File Formats in Marvin page. Examples:
         import java.awt.Image;
         ...
         String s1 = (String)doc.exportToObject("mol");
         String s2 = (String)doc.exportToObject("smiles:a-H"); // aromatize, remove H
         Image img = (Image)doc.exportToObject("image:w300,h300,#ffff00");
         byte[] d3 = (byte[])doc.exportToObject("png:w300,h300,b32,#00ffff00");
         byte[] d4 = (byte[])doc.exportToObject("jpeg:w300,h300,Q95,#ffff00,spacefill");
         
        Parameters:
        fmt - the format descriptor string
        Returns:
        a String, a byte[] array or an Image
        Throws:
        MolExportException - Export error.
        IllegalArgumentException - Invalid format string.
        SecurityException - Export module cannot be loaded because of security reasons (firewall).
        IOException
        Since:
        Marvin 4.0, 07/01/2005
        See Also:
        exportToFormat(java.lang.String), exportToBinFormat(java.lang.String), Molecule.exportToObject(java.lang.String)
      • getMProp

        public MProp getMProp()
        Gets the document as a property.
        Since:
        Marvin 4.1, 08/01/2006
      • properties

        public MPropertyContainer properties()
        Gets the property container.
        Since:
        Marvin 4.0, 06/18/2005
      • getAtomSetFont

        public MFont getAtomSetFont​(int seq)
        Gets an atom set font.
        Parameters:
        seq - the atom set sequence number
        Returns:
        the font
        Since:
        Marvin 4.0.3, 06/10/2005
      • setAtomSetFont

        public void setAtomSetFont​(int seq,
                                   MFont font)
        Sets the font of an atom set.
        Parameters:
        seq - atom set sequence number (0, ..., MolAtom.SETSEQ_MAX)
        font -
        Since:
        Marvin 4.0.3, 06/10/2005
      • getAtomSetColorMode

        public int getAtomSetColorMode​(int seq)
        Gets the atom set coloring mode.
        Parameters:
        seq - the atom set sequence number
        Returns:
        the mode
        Since:
        Marvin 4.1, 05/31/2006
        See Also:
        SETCOLOR_DEFAULT, SETCOLOR_SPECIFIED, SETCOLOR_COLORLESS
      • setAtomSetColorMode

        public void setAtomSetColorMode​(int seq,
                                        int m)
        Sets the atom set coloring mode.
        Parameters:
        seq - the atom set sequence number
        m - the mode
        Since:
        Marvin 4.1, 05/31/2006
        See Also:
        SETCOLOR_DEFAULT, SETCOLOR_SPECIFIED, SETCOLOR_COLORLESS
      • isAtomSetColorModeSet

        public boolean isAtomSetColorModeSet()
        Decides whether the atomset coloring mode is set.
        Returns:
        true if the coloring mode is set for at lease one atomset false otherwise.
      • setExtraLabelSetColorMode

        public void setExtraLabelSetColorMode​(int seq,
                                              int mode)
      • getAtomSetSize

        public int getAtomSetSize()
        Gets the size of the atom set.
        Returns:
        the atom set size
      • getExtraLabelSetSize

        public int getExtraLabelSetSize()
      • getAtomSetRGB

        public int getAtomSetRGB​(int seq)
        Gets an atom set color.
        Parameters:
        seq - the atom set sequence number
        Returns:
        the RGB values or -1 if unset or default atom coloring is used
        Since:
        Marvin 4.0, 03/02/2005
      • getExtraLabelSetRGBs

        public long getExtraLabelSetRGBs​(int seq)
      • getExtraLabelSetColorMode

        public int getExtraLabelSetColorMode​(int seq)
        Gets the coloring mode of extra label set sequences.
        Parameters:
        seq - the atom sequence number
        Returns:
        the coloring mode
        Since:
        Marvin 4.1, 07/06/2006
        See Also:
        SETCOLOR_DEFAULT, SETCOLOR_SPECIFIED, SETCOLOR_COLORLESS
      • getExtraLabelSetFont

        public MFont getExtraLabelSetFont​(int seq)
      • setExtraLabelColorsForDocument

        public void setExtraLabelColorsForDocument​(Molecule mol)
        Sets the coloring mode sets and colors of extra labels
        Parameters:
        mol - the graph union in the document
      • setAtomSetRGB

        public void setAtomSetRGB​(int seq,
                                  int rgb)
        Sets the color of an atom set. It also sets the color mode of the set to SETCOLOR_SPECIFIED.
        Parameters:
        seq - atom set sequence number (0, ..., MolAtom.SETSEQ_MAX)
        rgb - the RGB values
        Since:
        Marvin 4.0, 03/02/2005
      • setExtraLabelSetRGBs

        public void setExtraLabelSetRGBs​(int seq,
                                         int rgb)
      • setExtraLabelSetRGBs

        public void setExtraLabelSetRGBs​(int seq,
                                         int rgb1,
                                         int rgb2)
      • getAtomSetColor

        public Color getAtomSetColor​(int seq)
        Gets an atom set color.
        Parameters:
        seq - the atom set sequence number
        Returns:
        the color or null if unset or default bond coloring is used
        Since:
        Marvin 4.0, 03/02/2005
      • getBondSetSize

        public int getBondSetSize()
        Gets the bond set size.
        Returns:
        the bond set size
      • getBondSetThickness

        public double getBondSetThickness​(int seq)
        Gets a bond set thickness.
        Parameters:
        seq - the atom set sequence number
        Returns:
        the thickness
        Since:
        Marvin 4.0.3, 10/14/2005
      • setBondSetThickness

        public void setBondSetThickness​(int seq,
                                        double thickness)
        Sets the thickness of a bond set.
        Parameters:
        seq - bond set sequence number (0, ..., MolAtom.SETSEQ_MAX)
        thickness -
        Since:
        Marvin 4.0.3, 10/14/2005
      • getBondSetColorMode

        public int getBondSetColorMode​(int seq)
        Gets the bond set coloring mode.
        Parameters:
        seq - the bond set sequence number
        Returns:
        the mode
        Since:
        Marvin 4.1, 05/31/2006
        See Also:
        SETCOLOR_DEFAULT, SETCOLOR_SPECIFIED, SETCOLOR_COLORLESS
      • setBondSetColorMode

        public void setBondSetColorMode​(int seq,
                                        int m)
        Sets the bond set coloring mode.
        Parameters:
        seq - the bond set sequence number
        m - the mode
        Since:
        Marvin 4.1, 05/31/2006
        See Also:
        SETCOLOR_DEFAULT, SETCOLOR_SPECIFIED, SETCOLOR_COLORLESS
      • getBondSetRGB

        public int getBondSetRGB​(int seq)
        Gets a bond set color.
        Parameters:
        seq - the bond set sequence number
        Returns:
        the RGB values or -1 if unset or default coloring is used
        Since:
        Marvin 4.0, 03/02/2005
      • setBondSetRGB

        public void setBondSetRGB​(int seq,
                                  int rgb)
        Sets the color of a bond set. It also sets the color mode of the set to SETCOLOR_SPECIFIED.
        Parameters:
        seq - bond set sequence number (1, ..., MolBond.SETSEQ_MAX)
        rgb - the RGB values
        Since:
        Marvin 4.0, 03/02/2005
      • getBondSetColor

        public Color getBondSetColor​(int seq)
        Gets a bond set color.
        Parameters:
        seq - the bond set sequence number
        Returns:
        the color or null if unset or default bond coloring is used
        Since:
        Marvin 4.0, 03/02/2005
      • addCheckerMark

        public void addCheckerMark​(MDocument.CheckerMark mark)
        Adds a checker mark to the document. The checker mark containts atom indexes, bond indexes, and a color NOTE: checker marks will be reset on any molecule change
        Parameters:
        mark - is the checker mark information
        Since:
        Marvin 5.3
      • getCheckerMarks

        public MDocument.CheckerMark[] getCheckerMarks()
        Returns the array of checker marks NOTE: checker marks will be reset on any molecule change
        Returns:
        atom indexes or null
        Since:
        Marvin 5.3
        See Also:
        addCheckerMark(CheckerMark)
      • toString

        public String toString()
        Overrides Object.toString() to ease debugging. Returns a string consisting of the classname (without the package name!), the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. If the main molecule graph is not empty, then the string also contains the number of nodes and edges in "[Na,Mb]" form.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object
        Since:
        Marvin 4.1, 04/18/2006
      • getPageSettings

        public chemaxon.struc.PageSettings getPageSettings()
        Gets the page settings of multipage molecular document.
        Returns:
        the page settings
        Since:
        Marvin 4.1, 01/09/2006
      • setPageSettings

        public void setPageSettings​(chemaxon.struc.PageSettings pageSettings)
        Sets the page settings of multipage molecular document.
        Parameters:
        pageSettings - the page settings
        Since:
        Marvin 4.1, 01/09/2006
      • setGUIPropertyContainer

        public void setGUIPropertyContainer​(MPropertyContainer gpc)
        Sets the property container storing MarvinPane settings
        Parameters:
        gpc -
        Since:
        5.2.2 11/05/2009
      • getGUIPropertyContainer

        public MPropertyContainer getGUIPropertyContainer()
        Returns:
        the property container storing GUI settings or null
        Since:
        4.1 11/04/2006
      • getFreeAtomSetIndex

        public int getFreeAtomSetIndex()
        Returns the first unused atomset index.
        Returns:
        the atomset index
      • getFreeBondSetIndex

        public int getFreeBondSetIndex()
        Returns the first unused bondset index.
        Returns:
        the bondset index
      • removeColorsFromMolecules

        public void removeColorsFromMolecules()
        Removes coloring from all molecular objects in the document. Removes coloring of atoms, bonds and extra labels. Removes all color sets from the document.
      • removeElectronsOf

        public void removeElectronsOf​(MolAtom targetAtom)
        Removes the Electron containers belongs to targetAtom,
        Parameters:
        targetAtom -
      • fixElectronContainers

        public static void fixElectronContainers​(MDocument doc,
                                                 boolean lonePairsAutoCalc,
                                                 boolean lonePairsVisible)
        Removes unnecesarry MElectronContainers from the give MDocument corresponding to lone pair display options, if an electron of a MEFlow arrow has been removed the arrow is removed as well.
        Parameters:
        doc -
        lonePairsAutoCalc -
        lonePairsVisible -
      • hasExplicitLonePairs

        public boolean hasExplicitLonePairs()
        Returns true if the MDocument has any electrons drawn by the user.
        Returns:
        true if any electrons if set by the user.
        Since:
        Marvin 15.9.21
      • getExplicitLonePairCount

        public int getExplicitLonePairCount()
        Returns the number of Lone Pair electrons set by the user.
        Returns:
        number of user drawn lone pairs.
        Since:
        Marvin 15.9.21
      • getLonePairCount

        public int getLonePairCount()
        Returns the number of Lone Pair electrons.
        Returns:
        number of user lone pairs.
        Since:
        Marvin 15.9.21
      • hasRadicals

        public boolean hasRadicals()
        Returns true if the MDocument has any Radical Electrons.
        Returns:
        true if MDocument has any radical electrons.
        Since:
        Marvin 15.9.21
      • getRadicalCount

        public int getRadicalCount()
        Returns the number of Radical electrons.
        Returns:
        number of Radical electrons.
        Since:
        Marvin 15.9.21
      • hasElectrons

        public boolean hasElectrons()
        Returns whether MDocument contains any electrons.
        Returns:
        true if the MDocument contains any electrons.
        Since:
        Marvin 15.9.21
      • getElectronCount

        public int getElectronCount()
        Returns the number of electrons.
        Returns:
        number of electrons.
        Since:
        Marvin 15.9.21