MarvinSketch / Property Change Listener / Aromatise

User 7b0ee04e66

13-08-2007 12:08:54

Good afternoon,





I am trying to display a Reaction Smarts on the fly listening to the Change Event from Marvin Sketch and displaying it into a Text Area in a JPanel.





Code:
package marvin;





import chemaxon.marvin.beans.MSketchPane;





import chemaxon.struc.Molecule;





import java.awt.GridBagConstraints;


import java.awt.GridBagLayout;


import java.awt.Insets;





import java.beans.PropertyChangeEvent;


import java.beans.PropertyChangeListener;





import javax.swing.JFrame;


import javax.swing.JLabel;


import javax.swing.JPanel;


import javax.swing.JScrollPane;


import javax.swing.JTextArea;





public class MSketchListenerExample extends JPanel implements PropertyChangeListener {





    private JLabel lblSmirks;


    private JScrollPane m_ScrollSmirks;


    private JTextArea txtSmirks;


    private MSketchPane m_MarvinSketch;








    public MSketchListenerExample() {


        initialize();


    }





    public static void main(String[] args) {


        MSketchListenerExample mSketchListenerExample =


            new MSketchListenerExample();


        JFrame test = new JFrame();


        test.add(mSketchListenerExample);


        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        test.pack();


        test.setVisible(true);


    }








    private void initialize() {





        createSketchPanelLabels();


        createSketchPanelTextAreas();


        setUpLayout();





    }








    /**


     * Method to create all the Labels on the form


     */


    private





    void createSketchPanelLabels() {


        lblSmirks = new JLabel("SMIRKS", JLabel.RIGHT);


    }





    /**


     * Method to create all the text objects on the form


     */


    private





    void createSketchPanelTextAreas() {


        txtSmirks = new JTextArea(3, 100);


        txtSmirks.setWrapStyleWord(true);


        m_ScrollSmirks = new JScrollPane(txtSmirks);





        m_MarvinSketch = new MSketchPane();


        m_MarvinSketch.addPropertyChangeListener(this);





    }





    /**


     * This methods lays out all the form's components


     */


    private





    void setUpLayout() {


        // set Layout to GridBagLayout


        GridBagConstraints c = new GridBagConstraints();


        GridBagLayout gridbag = new GridBagLayout();


        this.setLayout(gridbag);





        // first row


        // marvin


        c.fill = GridBagConstraints.BOTH;


        c.insets = new Insets(5, 5, 5, 5);


        c.anchor = GridBagConstraints.FIRST_LINE_START;





        c.gridx = 0;


        c.gridy = 0;


        c.weightx = 1;


        c.gridheight = 5;


        c.gridwidth = 4;


        gridbag.setConstraints(m_MarvinSketch, c);


        add(m_MarvinSketch);








        c.gridx = 0;


        c.gridy = 5;


        c.gridheight = 3;


        c.weightx = 1.0;


        c.gridwidth = GridBagConstraints.REMAINDER;


        gridbag.setConstraints(m_ScrollSmirks, c);


        add(m_ScrollSmirks);








    }





    public void propertyChange(PropertyChangeEvent evt) {


        String name = evt.getPropertyName();


        if (name.equals("file") || name.equals("mol")) {


            Molecule mol = m_MarvinSketch.getMol();


            mol.expandSgroups();


                            mol.aromatize();


            System.out.println(mol.toFormat("smarts"));


            String smarts = mol.toFormat("smarts");


            txtSmirks.setText(smarts);


        }


    }


}






I then try to draw the reaction attached. As soon as I draw the reaction arrow, I get the following exception.





c1ccccc1


[#6]-c1ccccc1


[#6]Cc1ccccc1


[#6]C([#6])c1ccccc1


[#6]C(O)c1ccccc1


Exception breakpoint occurred at line 144 of EventDispatchThread.java.


java.lang.ArrayIndexOutOfBoundsException: -1


Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1


at chemaxon.marvin.modules.SSSR.fillRingIdx(Unknown Source)


at chemaxon.marvin.modules.SSSR.getRings(Unknown Source)


at chemaxon.marvin.modules.SSSR.callback(Unknown Source)


at chemaxon.struc.CGraph.getSSSR(Unknown Source)


at chemaxon.marvin.modules.Aromata.aromatize(Unknown Source)


at chemaxon.marvin.modules.Aromata.callback(Unknown Source)


at chemaxon.struc.MoleculeGraph.aromatize(Unknown Source)


at chemaxon.struc.Molecule.aromatize(Unknown Source)


at chemaxon.struc.RgMolecule.aromatize(Unknown Source)


at chemaxon.struc.MoleculeGraph.aromatize(Unknown Source)


at marvin.MSketchListenerExample.propertyChange(MSketchListenerExample.java:118)


at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)


at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)


at java.awt.Component.firePropertyChange(Component.java:7172)


at chemaxon.marvin.beans.MarvinPane.propertyChange(Unknown Source)


at chemaxon.marvin.beans.MSketchPane.propertyChange(Unknown Source)


at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)


at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)


at chemaxon.marvin.sketch.swing.SketchCanvas.callback(Unknown Source)


at chemaxon.marvin.sketch.MolEditor.historize(Unknown Source)


at chemaxon.marvin.sketch.modules.LineSM.buttonUp(Unknown Source)


at chemaxon.marvin.sketch.modules.ArrowSM$Reaction.buttonUp(Unknown Source)


at chemaxon.marvin.sketch.MolEditor.command0(Unknown Source)


at chemaxon.marvin.sketch.MolEditor.command(Unknown Source)


at chemaxon.marvin.sketch.swing.SketchCanvas.mouseReleased(Unknown Source)


at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)


at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)


at java.awt.Component.processMouseEvent(Component.java:5501)


at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)


at java.awt.Component.processEvent(Component.java:5266)


at java.awt.Container.processEvent(Container.java:1966)


at java.awt.Component.dispatchEventImpl(Component.java:3968)


at java.awt.Container.dispatchEventImpl(Container.java:2024)


at java.awt.Component.dispatchEvent(Component.java:3803)


at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)


at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)


at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)


at java.awt.Container.dispatchEventImpl(Container.java:2010)


at java.awt.Window.dispatchEventImpl(Window.java:1778)


at java.awt.Component.dispatchEvent(Component.java:3803)


at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)


at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)


at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)


at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)


at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)


at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)





If I open the file from Marvin Sketch File > Open, this does not happen.


What am I doing wrong? Is there a way around the problem?





I have been tring to use the method "isReactionErrorVisible()" in MSketchPane, but there nearly always seems to be a Reaction error highlighted even when the Reaction is correct and can succesfully be used for Library Enumeration. What is it checking for exactly?





Regards


Catherine

User 7b0ee04e66

13-08-2007 13:10:56

I am now trying to check that it is a valid reaction by using the method


isValenceErrorVisible() in the method below (the rest of the class has not changed).





Code:
    public void propertyChange(PropertyChangeEvent evt) {


        System.out.println("Valency Error = " + m_MarvinSketch.isValenceErrorVisible());


        System.out.println("Reaction Error = " + m_MarvinSketch.isReactionErrorVisible());


       


        String name = evt.getPropertyName();


        if (name.equals("file") || name.equals("mol")) {


            Molecule mol = m_MarvinSketch.getMol();


            mol.expandSgroups();


                            mol.aromatize();


            System.out.println(mol.toFormat("smarts"));


            String smarts = mol.toFormat("smarts");


            txtSmirks.setText(smarts);


        }


    }









But this always return true even when the SketchPane is empty.


Is there an alternative method to check for pentavalent C, etc?





Thanks in advance for your help


Catherine

ChemAxon 7c2d26e5cf

13-08-2007 14:18:48

valenceErrorVisible and reactionErrorVisible are display properties.


With the help of these properties, you can highlight valence errors and unbalanced reactions or not. The state of these properties do not indicate that the current structure is valid or not.


Valence errors are highlighted with red underline by the atom label. By unbalanced reactions, there is a red rectangle around the reaction arrow.

User 7b0ee04e66

13-08-2007 14:53:58

OK Thanks, I will need to think of an alternative way to check for reaction or valence errors.





Did you find out what was wrong with the first post?





Thanks


Catherine

ChemAxon 7c2d26e5cf

17-08-2007 12:31:23

In first view, The problem seems to be in the aromatization by uncompleted reactions. We will investigate it deeply.


Until then, I can suggest the following workaround: draw the reaction arrow in the last step (after the reactant and products are already existing).

ChemAxon a3d59b832c

21-08-2007 13:36:30

Catherine,





You will need the following methods to check for errors:





http://www.chemaxon.com/marvin/doc/api/chemaxon/struc/MoleculeGraph.html#valenceCheck()


http://www.chemaxon.com/marvin/doc/api/chemaxon/struc/MoleculeGraph.html#hasValenceError()


http://www.chemaxon.com/marvin/doc/api/chemaxon/struc/RxnMolecule.html#isIncompleteReaction()





You may also find this forum topic useful:





Forbidding wedge bonds off of planar (aromatic) atoms





Best regards,





Szabolcs

User 7b0ee04e66

21-08-2007 13:46:56

Thanks


I had found some of the methods by browsing through the API, but not all of them.


Is there a version of Marvin 4.2 that I could use for testing the new features your suggest?


Catherine

ChemAxon a3d59b832c

21-08-2007 14:22:54

Yes, there is a Marvin alpha version available here:





http://www.chemaxon.com/shared/alpha/marvin/index.html





Or if you need the JChem package:





http://www.chemaxon.com/download.php?dl=&d=/data/download/jchem/test/jchem_5.0.0alpha8.zip





(The next major Marvin and JChem releases have been renamed to 5.0 in the meantime.)

User 7b0ee04e66

28-08-2007 14:59:29

Hello


I am still using the Java class included above.


I have trying to map some atoms in the reagents and products of the reaction and noticed that if I use





- Right-Click / Map and M1 the changes are updated automatically to the


Text Box which displays the Smirks





- Same happens if I use Select All, Add > Atom Maps





- But not If I click on the arrow and draw an arrow between the 2 atoms which should be mapped together. The first time, Marvin is refreshed and displays the atom maps but the Text Area is unchanged. When we map further atoms, Marvin displays atoms maps for 1 and 2, and the Text area which displays the Smarts is updated with atom maps for 1.


It is as if it is one step behind





To reproduce try the reaction below


[#8-][N+](=O)C1=CC=CC=C1>>[#7]C1=CC=CC=C1


map the aromatic carbon next to N first and nothing changes


map the Nitrogen atom and the map for the carbon appears


[#8-][N+](=O)[C:1]1=CC=CC=C1>>[#7][C:1]1=CC=CC=C1





Is this likely to be fixed in the next version?


Thanks


Catherine

User f359e526a1

29-08-2007 06:53:12

Hello, seems the mapping actually works - if you check the molecule by Edit/Source it will give you the correct string - it is the text field updating that is flaky somewhere. Thank you for the report, we will investigate it.