Class MoleculeComponent

  • All Implemented Interfaces:
    MacroMoleculeComponent.MoleculeVisualizer, chemaxon.marvin.space.UsableObject, chemaxon.struc.MoleculeIterators.MoleculeInterface

    @PublicAPI
    public class MoleculeComponent
    extends GraphicComponent
    implements chemaxon.struc.MoleculeIterators.MoleculeInterface, MacroMoleculeComponent.MoleculeVisualizer, chemaxon.marvin.space.UsableObject
    MoleculeComponent is the basic visualizer of simple molecules in MarvinSpace. Displays atoms and bonds in classic drawing modes: wire, ball, stick, ball&stick, ball&wire, spacefill.
    Atoms of the molecule can be individually selected.
    Ligands of a complex structure can be visualized by MoleculeComponent, but in this case the MoleculeComponent is not directly added to the GraphicScene but is handled by the MacroMoleculeComponent as a MoleculeVisualizer.
    Example of typical usage:
     ArrayList moleculeList = graphicScene.getEventHandler().readMolecule("molecule1.mol");
     MoleculeComponent mc = moleculeList.get(0);
     
    Since:
    Marvin 4.0.2
    • Field Detail

      • DRAW_TYPE_BALL_AND_WIRE

        protected static final int DRAW_TYPE_BALL_AND_WIRE
        See Also:
        Constant Field Values
      • DRAW_TYPE_BALL_AND_STICK

        protected static final int DRAW_TYPE_BALL_AND_STICK
        See Also:
        Constant Field Values
      • DEFAULT_STICK_RADIUS

        protected static final double DEFAULT_STICK_RADIUS
        See Also:
        Constant Field Values
      • DEFAULT_BOND_DISTANCE

        protected static final int DEFAULT_BOND_DISTANCE
        See Also:
        Constant Field Values
      • DEFAULT_H_BALL_PRECISION

        protected static final int DEFAULT_H_BALL_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_H_SPACEFILL_PRECISION

        protected static final int DEFAULT_H_SPACEFILL_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_H_JOINT_PRECISION

        protected static final int DEFAULT_H_JOINT_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_H_BOND_SLICE_PRECISION

        protected static final int DEFAULT_H_BOND_SLICE_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_H_STICK_SLICE_PRECISION

        protected static final int DEFAULT_H_STICK_SLICE_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_M_BALL_PRECISION

        protected static final int DEFAULT_M_BALL_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_M_SPACEFILL_PRECISION

        protected static final int DEFAULT_M_SPACEFILL_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_M_JOINT_PRECISION

        protected static final int DEFAULT_M_JOINT_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_M_BOND_SLICE_PRECISION

        protected static final int DEFAULT_M_BOND_SLICE_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_M_STICK_SLICE_PRECISION

        protected static final int DEFAULT_M_STICK_SLICE_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_L_BALL_PRECISION

        protected static final int DEFAULT_L_BALL_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_L_SPACEFILL_PRECISION

        protected static final int DEFAULT_L_SPACEFILL_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_L_JOINT_PRECISION

        protected static final int DEFAULT_L_JOINT_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_L_BOND_SLICE_PRECISION

        protected static final int DEFAULT_L_BOND_SLICE_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_L_STICK_SLICE_PRECISION

        protected static final int DEFAULT_L_STICK_SLICE_PRECISION
        See Also:
        Constant Field Values
      • COMPONENT_TYPE_MOLECULE

        protected static final int COMPONENT_TYPE_MOLECULE
        See Also:
        Constant Field Values
      • DEFAULT_COLOR

        protected static final float[] DEFAULT_COLOR
      • elementList

        public static final int[] elementList
      • drawTypes

        protected static HashMap drawTypes
      • hc

        protected chemaxon.struc.MacroMolecule.HeteroComponent hc
      • drawType

        protected int drawType
      • drawHydrogens

        protected boolean drawHydrogens
      • ballRadius

        protected double ballRadius
      • bondRadius

        protected double bondRadius
      • stickRadius

        protected double stickRadius
      • lineWidth

        protected double lineWidth
      • bondDistance

        protected int bondDistance
      • bondWidth

        protected int bondWidth
      • smoothStickColoring

        protected boolean smoothStickColoring
      • bondFacing

        protected boolean bondFacing
      • scaledBalls

        protected boolean scaledBalls
      • displayBondOrder

        protected boolean displayBondOrder
      • ballPrecision

        protected int ballPrecision
      • spacefillPrecision

        protected int spacefillPrecision
      • bondSlicePrecision

        protected int bondSlicePrecision
      • stickSlicePrecision

        protected int stickSlicePrecision
      • jointPrecision

        protected int jointPrecision
      • colorType

        protected int colorType
      • selectedAtoms

        protected boolean[] selectedAtoms
      • selectionBeforeInit

        protected boolean selectionBeforeInit
      • color

        protected float[] color
    • Constructor Detail

      • MoleculeComponent

        protected MoleculeComponent()
        Creates a new instance of MoleculeComponent. Molecule have to be set by #setMolecule()
      • MoleculeComponent

        public MoleculeComponent​(Molecule mol)
        Creates a new instance of MoleculeComponent from the given molecule.
      • MoleculeComponent

        public MoleculeComponent​(chemaxon.struc.MacroMolecule.HeteroComponent hc,
                                 MacroMoleculeComponent mmc)
        Creates a new instance of MoleculeComponent from the given HeteroComponent and MacroMoleculeComponent; this class can be used as a visualizer of a ligand.
    • Method Detail

      • isGraphicComponent

        public boolean isGraphicComponent()
        Specified by:
        isGraphicComponent in interface chemaxon.marvin.space.UsableObject
        Overrides:
        isGraphicComponent in class GraphicComponent
      • getId

        public chemaxon.marvin.space.UOID getId()
        Description copied from class: GraphicComponent
        Returns the id of the component. This id contains internal cell and component indices. The id can be changed by client and internal mechanisms in GraphicCell may also alter its value. Thus to preserve a component for later use, store the component itself rather than its Id.
        Specified by:
        getId in interface chemaxon.marvin.space.UsableObject
        Overrides:
        getId in class GraphicComponent
        Returns:
        id of the component
      • setMacroMoleculeComponent

        public void setMacroMoleculeComponent​(MacroMoleculeComponent mmc)
        A MacroMoleculeComponent can be set and in this case this will be a visualizer of a ligand in the macromolecule.
      • isMacromoleculePart

        public boolean isMacromoleculePart()
        Tells whether this MoleculeComponent is a visualizer of a ligand in a complex or an independent small molecule.
      • setColor

        public void setColor​(Color color)
        Sets the constant color of the component.
        Specified by:
        setColor in interface chemaxon.marvin.space.UsableObject
        Overrides:
        setColor in class GraphicComponent
      • setColor

        public void setColor​(float[] color)
        Sets the constant color of the component.
        Overrides:
        setColor in class GraphicComponent
      • setColor

        public void setColor​(float r,
                             float g,
                             float b)
        Sets the constant color of the component.
        Overrides:
        setColor in class GraphicComponent
      • setMolecule

        public void setMolecule​(Molecule mol)
        Sets the Molecule of the MoleculeComponent to mol, sets proper atomIterators, and computes the bounding box.
      • getAtomIterator

        public chemaxon.struc.MoleculeIterators.AtomIteratorInterface getAtomIterator​(boolean enumerateHydrogens)
        Returns the iterator of the atoms of the molecule. See MoleculeIterators.AtomIteratorInterface for details.
        Specified by:
        getAtomIterator in interface chemaxon.struc.MoleculeIterators.MoleculeInterface
        Parameters:
        enumerateHydrogens - enable/disable enumeration of hydrogens
      • getAtomProperty

        public chemaxon.struc.MoleculeIterators.AtomPropertyInterface getAtomProperty()
        See MoleculeIterators.AtomPropertyInterface for details.
        Specified by:
        getAtomProperty in interface chemaxon.struc.MoleculeIterators.MoleculeInterface
      • getBondIterator

        public chemaxon.struc.MoleculeIterators.BondIteratorInterface getBondIterator​(boolean enumerateHydrogens)
        Returns the iterator of the atoms of the molecule. See MoleculeIterators.BondIteratorInterface for details.
        Specified by:
        getBondIterator in interface chemaxon.struc.MoleculeIterators.MoleculeInterface
        Parameters:
        enumerateHydrogens - enable/disable enumeration of hydrogens
      • getAtomCount

        public int getAtomCount​(boolean enumerateHydrogens)
        Returns the number of atoms in the molecule with arbitrarily enumerating hydrogens.
        Specified by:
        getAtomCount in interface chemaxon.struc.MoleculeIterators.MoleculeInterface
      • getBondCount

        public int getBondCount​(boolean enumerateHydrogens)
        Returns the number of bonds in the molecule with arbitrarily enumerating hydrogens.
        Specified by:
        getBondCount in interface chemaxon.struc.MoleculeIterators.MoleculeInterface
      • translate

        public void translate​(float[] v)
        Translates the molecule with the parameter as a vector.
        Overrides:
        translate in class GraphicComponent
        Parameters:
        v - translation vector
      • rotate

        public void rotate​(float[] v,
                           float[] center)
        Rotates the molecule with parameter center as an origin. Rotates around x axis with the x argument of vector as angle, and so on.
        Overrides:
        rotate in class GraphicComponent
        Parameters:
        v - measure of rotation around the 3 axes
        center - Center of the rotation.
      • torsion

        public void torsion​(double angle,
                            float[] axis,
                            float[] center,
                            int[] atomArray)
        Changes torsion angle. Atoms being in the atom array will be rotated by given angle around the given axis. Center means the origin, so first there is a translation to center, rotation follows, and finally translation back.
      • isControllable

        public boolean isControllable​(String type)
        Returns whether controling by the given type of controller is allowed to the component. This component is allowed to be translated and rotated.
        Overrides:
        isControllable in class GraphicComponent
        Parameters:
        type - "Shift", "Rotate", "Resize"
        Returns:
        is the component aloowed to be controlled or not
      • setBoundingBox

        protected void setBoundingBox()
        Computes the bounding box of the visible atoms of the molecule, and adds 2 angstroms to each side.
      • initDraw

        public void initDraw()
        Initializes gl related drawing variables, for example display lists. Called by MacroMoleculeComponent, because GraphicComponents would get GL2 from the GraphicCell during initialization, but MacroMoleculeComponent has to pass it to its visualizers.
        Specified by:
        initDraw in interface MacroMoleculeComponent.MoleculeVisualizer
      • getComponentElement

        public ComponentElement getComponentElement()
        Returns the previously picked but unprocessed ComponentElement or the whole component as a ComponentElement, if no picking happened.
        Overrides:
        getComponentElement in class GraphicComponent
        Returns:
        picked part of the component
      • getCoordinates

        public void getCoordinates​(ComponentElement element,
                                   float[] c)
        Sets the coordinates of the given element in the given preallocated array.
        Overrides:
        getCoordinates in class GraphicComponent
        Parameters:
        element - specific part of the component
        c - allocated array where coordinates will be put
      • isLigand

        public boolean isLigand()
      • getLabelInformation

        public ComponentElement[] getLabelInformation​(String labeltype,
                                                      boolean onlyOnHeavyAtoms)
        Labels will be created associated to this MoleculeComponent if the labeltype is "atom", "extraatomlabel" or "molecule".
        Overrides:
        getLabelInformation in class GraphicComponent
        Parameters:
        labeltype -
        onlyOnHeavyAtoms - label info needed only for heavy atoms.
        Returns:
        array of ComponentElements to create labels to
      • getSelectedAtom

        public MolAtom getSelectedAtom​(int i)
      • getAtomSelections

        public boolean[] getAtomSelections()
      • selectAllAtoms

        public void selectAllAtoms()
        Sets all atoms to be selected.
      • unSelectAllAtoms

        public void unSelectAllAtoms()
        Sets all atoms to be unselected.
      • setVisible

        public void setVisible​(boolean v)
        Sets the component to be visible/invisible. It is slighly different from the method of GraphicComponent, because in case of visualizing a ligand of a macromolecule, the BoundingBox should be refreshed.
        Specified by:
        setVisible in interface MacroMoleculeComponent.MoleculeVisualizer
        Specified by:
        setVisible in interface chemaxon.marvin.space.UsableObject
        Overrides:
        setVisible in class GraphicComponent
        Parameters:
        v - of visibility
      • isVisible

        public boolean isVisible​(ComponentElement item)
        Returns true if the given item is visible.
        Overrides:
        isVisible in class GraphicComponent
        Parameters:
        item - part of the component
        Returns:
        visibility of the part of the component
      • isAtomVisible

        public boolean isAtomVisible​(int i)
        Returns if the atom is visible or hidden.
        Specified by:
        isAtomVisible in interface MacroMoleculeComponent.MoleculeVisualizer
        Parameters:
        i - atom index given by MoleculeIterators.AtomIteratorInterface.current() }
        Returns:
        false if the component is hidden or the atom is H atom but is not displayed or if the atom is explicitly hidden
      • isAtomFaded

        public boolean isAtomFaded​(int i)
        Tells whether the atom is faded or not.
        Specified by:
        isAtomFaded in interface MacroMoleculeComponent.MoleculeVisualizer
        Parameters:
        i - atom index given by MoleculeIterators.AtomIteratorInterface.current() }
        Returns:
        true if the atom is explicitly set faded
      • isSelected

        public boolean isSelected​(ComponentElement item)
        Returns true if the given item is selected.
        Overrides:
        isSelected in class GraphicComponent
        Parameters:
        item - specific part of the component
        Returns:
        selection state of the element
      • hasSelectedElements

        public boolean hasSelectedElements()
        Returns true if the component has any selected part.
        Overrides:
        hasSelectedElements in class GraphicComponent
        Returns:
        is any part of the component selected
      • exclusiveSelection

        public void exclusiveSelection()
        Sets the previously picked but unprocessed element to be selected, and sets every other parts not to be selected.
        Overrides:
        exclusiveSelection in class GraphicComponent
      • extendSelection

        public void extendSelection()
        Sets the previously picked but unprocessed element to be selected, and leaves other parts as they are.
        Overrides:
        extendSelection in class GraphicComponent
      • invertSelection

        public void invertSelection()
        Sets the the given part of the component to be selected if it was not set and vice versa.
        Overrides:
        invertSelection in class GraphicComponent
      • drawSelection

        protected void drawSelection​(int mode)
        Description copied from class: GraphicComponent
        Draws the component in the given mode (usually in selection mode), the rendering mode is for checking.
        Overrides:
        drawSelection in class GraphicComponent
        Parameters:
        mode - GL_RENDER or GL_SELECT
      • drawAtomSelection

        public void drawAtomSelection​(int mode)
        To make selection faster we don't draw the atoms themself into the selection buffer, but we draw simple polygons instead. Each polygon has 8 vertices, and approximates spheres well. To display these polygons, call drawAtomSelection(GL2.GL_RENDER) in the display method. You may not see the polygons though, because they have the same "radius" as the spheres. To achive that the polygons do not rotate from the viewing plane, we translate them to the origin, rotate them with the inverse rotation, and translate them back to the previous location.
        Specified by:
        drawAtomSelection in interface MacroMoleculeComponent.MoleculeVisualizer
      • pickObject

        protected void pickObject​(int offset,
                                  double[] maxZ,
                                  float[] modelview)
        Description copied from class: GraphicComponent
        Sets GraphicComponent.pickedItem to be the picked part of the component.
        Overrides:
        pickObject in class GraphicComponent
        Parameters:
        offset - Integer used in the name stack to identify the part of the component.
        maxZ - Stores the z coordinate of the part with maximum z coordinate in the actual picking. It has to be set if the part with the current offset has greater z coordinate than the stored one. Example to compute: int aIdx = GeomCalc.newVector( picked.x(), picked.y(), picked.z() ); GeomCalc.multVectorWithMatrix(aIdx, modelview); z coordinate: maxZ[0] = GeomCalc.getZ(aIdx)
        modelview - Is to compute the proper z coordinate.
      • setDrawProperty

        public void setDrawProperty​(String propertyName,
                                    String propertyValue)
        Sets a draw property.
        Accepts the PropertyName -- PropertyValue (Meaning) pairs below:
        • "DrawType", "Ligand.DrawType" -- "Wire", "Stick", "Ball", "BallAndStick", "StickAndBall", "BallAndWire", "WireAndBall", "Spacefill"
        • "Quality", "Ligand.Quality" -- "High", "Medium", "Low"
        • "ColorType", "Ligand.ColorType" -- "Constant", "CPK"
        • "Ligand.Hydrogens" -- Boolean value as String
        • "Ligand.BallRadius" -- Double value as String
          (Radius of displayed balls in angstroms)
        • "Ligand.BondRadius" -- Double value as String
          (Radius of bond cylinders in ball&stick mode in angstroms)
        • "Ligand.StickRadius" -- Double value as String
          (Radius of bond cylinders in stick mode in angstroms)
        • "Ligand.LineWidth" -- Double value as String
          (Width of displayed lines in wire mode in pixels)
        • "Ligand.BondDistance" -- Integer value as String
          (Gap between two lines/sticks representing a double bond. It is determined as a percentage of Bond radius.)
        • "Ligand.BondWidth" -- Integer value as String
          (Thickness of line/stick representing a double bond. It is expressed relative to the thcikness of a single bond.)
        • "Ligand.SmoothStickStyle" -- Boolean value as String
          (Smooth, shaded display of two colored bonds)
        • "Ligand.ScaledBalls" -- Boolean value as String
          (Are balls scaled according to vdW radius or have uniform size in ball mode or not)
        • "Ligand.DisplayBondOrder" -- Boolean value as String
          (Double, aromatic bonds are displayed or not)
        • "Ligand.Color" -- java.awt.Color value as String
        • "CarbonColorStyle" -- Integer value as String
          (Carbon color is 0: lightgray, 1: darkgray, 2: green, 3:cyan)
        Specified by:
        setDrawProperty in interface MacroMoleculeComponent.MoleculeVisualizer
        Specified by:
        setDrawProperty in interface chemaxon.marvin.space.UsableObject
        Overrides:
        setDrawProperty in class GraphicComponent
        Parameters:
        propertyName - identifier of the draw property
        propertyValue - value of the draw property as a String