Author: scooter
Date: 2011-05-25 17:34:49 -0700 (Wed, 25 May 2011)
New Revision: 25544

Added:
   csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-jchempaint-19.jar
Removed:
   csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-1.3.6.jar
   csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-templates.jar
Modified:
   csplugins/trunk/ucsf/scooter/chemViz/build.xml
   csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java
   csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreatePopupTask.java
   csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/CompoundPopup.java
   
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/renderers/CompoundRenderer.java
Log:
Move to cdk-jchempaint-19 and clean up handling of images a little.


Modified: csplugins/trunk/ucsf/scooter/chemViz/build.xml
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/build.xml      2011-05-26 00:30:23 UTC 
(rev 25543)
+++ csplugins/trunk/ucsf/scooter/chemViz/build.xml      2011-05-26 00:34:49 UTC 
(rev 25544)
@@ -69,14 +69,14 @@
   <target name="compile" depends="compile-core" description="Compile with 
Cytoscape under development" />
 
   <target name="compile-core" depends="init">
-    <javac source="1.5" debug="${compile.debug}" 
deprecation="${compile.deprecation}" optimize="${compile.optimize}" 
srcdir="${src.dir}" destdir="${build.dir}/classes">
+    <javac source="1.6" debug="${compile.debug}" 
deprecation="${compile.deprecation}" optimize="${compile.optimize}" 
srcdir="${src.dir}" destdir="${build.dir}/classes">
       <classpath refid="compile.classpath" />
     </javac>
   </target>
 
   <target name="compile-test" depends="compile">
     <mkdir dir="${build.dir}/classes/test" />
-    <javac source="1.5" debug="${compile.debug}" 
deprecation="${compile.deprecation}" optimize="${compile.optimize}" 
srcdir="${src.dir}/test" destdir="${build.dir}/classes/test">
+    <javac source="1.6" debug="${compile.debug}" 
deprecation="${compile.deprecation}" optimize="${compile.optimize}" 
srcdir="${src.dir}/test" destdir="${build.dir}/classes/test">
       <classpath refid="test.classpath" />
     </javac>
   </target>

Deleted: csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-1.3.6.jar
===================================================================
(Binary files differ)

Added: csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-jchempaint-19.jar
===================================================================
(Binary files differ)


Property changes on: 
csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-jchempaint-19.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Deleted: csplugins/trunk/ucsf/scooter/chemViz/lib/cdk-templates.jar
===================================================================
(Binary files differ)

Modified: csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java        
2011-05-26 00:30:23 UTC (rev 25543)
+++ csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java        
2011-05-26 00:34:49 UTC (rev 25544)
@@ -37,9 +37,11 @@
 
 import java.awt.Color;
 import java.awt.Font;
+import java.awt.FontMetrics;
 import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.Rectangle;
+import java.awt.RenderingHints;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.AffineTransformOp;
@@ -78,6 +80,7 @@
 import org.openscience.cdk.exception.InvalidSmilesException;
 import org.openscience.cdk.fingerprint.Fingerprinter;
 import org.openscience.cdk.geometry.GeometryTools;
+import org.openscience.cdk.graph.ConnectivityChecker;
 import org.openscience.cdk.inchi.InChIGenerator;
 import org.openscience.cdk.inchi.InChIGeneratorFactory;
 import org.openscience.cdk.inchi.InChIToStructure;
@@ -414,52 +417,62 @@
                this.iMolecule = null;
                this.iMolecule3D = null;
                this.fingerPrint = null;
+               this.smilesStr = null;
+
+               List<Compound> mapList = null;
+               if (Compound.compoundMap == null) 
+                       Compound.compoundMap = new HashMap();
+
+               if (Compound.compoundMap.containsKey(source)) {
+                       mapList = Compound.compoundMap.get(source);
+               } else {
+                       mapList = new ArrayList();
+               }
+               mapList.add(this);
+               Compound.compoundMap.put(source, mapList);
+
                if (attrType == AttriType.inchi) {
                        // Convert to smiles 
                        this.smilesStr = convertInchiToSmiles(moleculeString);
                } else {
-                       this.smilesStr = mstring;
-                       // Create the CDK Molecule object
-                       SmilesParser sp = new 
SmilesParser(DefaultChemObjectBuilder
-                                                       .getInstance());
-                       try {
-                               iMolecule = sp.parseSmiles(this.smilesStr);
-                       } catch (InvalidSmilesException e) {
-                               iMolecule = null;
-                               logger.error("Unable to parse SMILES: 
"+smilesStr+": "+e.getMessage());
+                       if (mstring != null && mstring.length() > 0) {
+                               // Strip any blanks in the string
+                               this.smilesStr = mstring.replaceAll(" ", "");
                        }
                }
 
+               if (smilesStr == null)
+                       return;
+
+               logger.debug("smiles string = "+smilesStr);
+
+               // Create the CDK Molecule object
+               SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder
+                                               .getInstance());
+               try {
+                       iMolecule = sp.parseSmiles(this.smilesStr);
+               } catch (InvalidSmilesException e) {
+                       iMolecule = null;
+                       logger.warning("Unable to parse SMILES: "+smilesStr+" 
for "+source.getIdentifier()+": "+e.getMessage());
+                       return;
+               }
+
                // At this point, we should have an IMolecule
                try { 
-                       if (iMolecule != null) {
+                       
CDKHueckelAromaticityDetector.detectAromaticity(iMolecule);
 
-                               
CDKHueckelAromaticityDetector.detectAromaticity(iMolecule);
+                       // Make sure we update our implicit hydrogens
+                       CDKHydrogenAdder adder = 
CDKHydrogenAdder.getInstance(iMolecule.getBuilder());
+                       adder.addImplicitHydrogens(iMolecule);
 
-                               // Make sure we update our implicit hydrogens
-                               CDKHydrogenAdder adder = 
CDKHydrogenAdder.getInstance(iMolecule.getBuilder());
-                               adder.addImplicitHydrogens(iMolecule);
-
-                               // Get our fingerprint
-                               Fingerprinter fp = new Fingerprinter();
-                               // Do we need to do the addh here?
-                               fingerPrint = 
fp.getFingerprint(addh(iMolecule));
-                       }
+                       // Get our fingerprint
+                       Fingerprinter fp = new Fingerprinter();
+                       // Do we need to do the addh here?
+                       fingerPrint = fp.getFingerprint(addh(iMolecule));
                } catch (CDKException e1) {
                        fingerPrint = null;
                }
 
-               List<Compound> mapList = null;
-               if (Compound.compoundMap == null) 
-                       Compound.compoundMap = new HashMap();
-
-               if (Compound.compoundMap.containsKey(source)) {
-                       mapList = Compound.compoundMap.get(source);
-               } else {
-                       mapList = new ArrayList();
-               }
-               mapList.add(this);
-               Compound.compoundMap.put(source, mapList);
        }
 
        /**
@@ -730,11 +743,22 @@
                // System.out.println("depictWithCDK("+width+","+height+")");
 
                if (iMolecule == null || width == 0 || height == 0) {
-                       return null;
+                       return blankImage(iMolecule, width, height);
                }
 
                try {
                        if (!laidOut) {
+                               // Is the structure connected?
+                               if 
(!ConnectivityChecker.isConnected(iMolecule)) {
+                                       // No, for now, find the largest 
component and use that exclusively
+                                       IMoleculeSet molSet = 
ConnectivityChecker.partitionIntoMolecules(iMolecule);
+                                       IMolecule largest = 
molSet.getMolecule(0);
+                                       for (int i = 0; i < 
molSet.getMoleculeCount(); i++) {
+                                               if 
(molSet.getMolecule(i).getAtomCount() > largest.getAtomCount())
+                                                       largest = 
molSet.getMolecule(i);
+                                       }
+                                       iMolecule = largest;
+                               }
                                StructureDiagramGenerator sdg = new 
StructureDiagramGenerator();
                                sdg.setUseTemplates(false);
                                sdg.setMolecule(iMolecule);
@@ -777,6 +801,7 @@
                        graphics.setColor(background);
                        graphics.setBackground(background);
                        graphics.fillRect(0,0,renderWidth,renderHeight);
+                       
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
RenderingHints.VALUE_ANTIALIAS_ON);
 
                        renderer.paint(iMolecule, new AWTDrawVisitor(graphics), 
bbox, true);
 
@@ -794,7 +819,7 @@
                                bufferedImage = op.filter(bufferedImage, null);
                        }
                } catch (Exception e) {
-                       logger.warning("Unable to depict molecule with CDK 
depiction: "+e.getMessage(), e);
+                       logger.warning("Unable to depict molecule for 
"+source.getIdentifier()+" with CDK depiction: "+e.getMessage(), e);
                }
 
                return bufferedImage;
@@ -826,6 +851,11 @@
                try {
                        // Get the factory      
                        InChIGeneratorFactory factory = 
InChIGeneratorFactory.getInstance();
+                       if (!inchi.startsWith("InChI="))
+                               inchi = "InChI="+inchi;
+
+                       logger.debug("Getting structure for: "+inchi);
+
                        InChIToStructure intostruct = 
factory.getInChIToStructure(inchi, DefaultChemObjectBuilder.getInstance());
 
                        // Get the structure
@@ -833,7 +863,7 @@
                        if (ret == INCHI_RET.WARNING) {
                                logger.warning("InChI warning: " + 
intostruct.getMessage());
                        } else if (ret != INCHI_RET.OKAY) {
-                               logger.error("Structure generation failed 
failed: " + ret.toString()
+                               logger.warning("Structure generation failed: " 
+ ret.toString()
                       + " [" + intostruct.getMessage() + "]");
                                return null;
                        }
@@ -843,10 +873,45 @@
                        SmilesGenerator sg = new SmilesGenerator();
                        return sg.createSMILES(iMolecule);
                } catch (Exception e) {
-                       logger.error("Structure generation failed failed: " + 
e.getMessage());
+                       logger.warning("Structure generation failed: " + 
e.getMessage(), e);
                        return null;
                }
 
        }
 
+       private Image blankImage(IMolecule mol, int width, int height) {
+               final String noImage = "Image Unavailable";
+
+               if (width == 0 || height == 0)
+                       return null;
+
+               BufferedImage bufferedImage = new BufferedImage(width, height, 
BufferedImage.TYPE_INT_ARGB);
+               Graphics2D graphics = bufferedImage.createGraphics();
+               graphics.setBackground(Color.WHITE);
+
+               graphics.setColor(Color.WHITE);
+               graphics.fillRect(0,0,width,height);
+               graphics.setColor(Color.BLACK);
+
+               // Create our font
+               Font font = new Font("SansSerif", Font.PLAIN, 18);
+               graphics.setFont(font);
+               FontMetrics metrics = graphics.getFontMetrics();
+
+               int length = metrics.stringWidth(noImage);
+               while (length+6 >= width) {
+                       font = font.deriveFont((float)(font.getSize2D() * 
0.9)); // Scale our font
+                       graphics.setFont(font);
+                       metrics = graphics.getFontMetrics();
+                       length = metrics.stringWidth(noImage);
+               }
+
+               int lineHeight = metrics.getHeight();
+
+               graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
RenderingHints.VALUE_ANTIALIAS_ON);
+               graphics.drawString(noImage, (width-length)/2, 
(height+lineHeight)/2);
+
+               return bufferedImage;
+       }
+
 }

Modified: 
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreatePopupTask.java
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreatePopupTask.java 
2011-05-26 00:30:23 UTC (rev 25543)
+++ csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreatePopupTask.java 
2011-05-26 00:34:49 UTC (rev 25544)
@@ -128,7 +128,10 @@
                        if (objectList.size() == 1) {
                                CompoundPopup popup = new CompoundPopup(cList, 
objectList, null);
                        } else {
-                               CompoundPopup popup = new CompoundPopup(cList, 
objectList, labelAttribute);
+                               if (labelAttribute.equals("ID"))
+                                       new CompoundPopup(cList, objectList, 
type+".ID");
+                               else
+                                       new CompoundPopup(cList, objectList, 
labelAttribute);
                        }
                }
        }

Modified: csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/CompoundPopup.java
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/CompoundPopup.java      
2011-05-26 00:30:23 UTC (rev 25543)
+++ csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/CompoundPopup.java      
2011-05-26 00:34:49 UTC (rev 25544)
@@ -50,6 +50,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.BorderFactory;
 import javax.swing.ImageIcon;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
@@ -115,7 +116,8 @@
                // Is it in our map?
                if (imageMap.containsKey(labelComponent)) {
                        Image img = 
imageMap.get(labelComponent).getImage(width,height, Color.WHITE);
-                       labelComponent.setIcon(new ImageIcon(img));
+                       if (img != null)
+                               labelComponent.setIcon(new ImageIcon(img));
                }
        }
 
@@ -131,11 +133,13 @@
                setLayout(layout);
 
                // Get the right attributes
-               if (labelAttribute != null && 
labelAttribute.startsWith("node."))
+               if (labelAttribute != null && 
labelAttribute.startsWith("node.")) {
                        attributes = Cytoscape.getNodeAttributes();
-               else if (labelAttribute != null && 
labelAttribute.startsWith("edge."))
+                       labelAttribute = labelAttribute.substring(5);
+               } else if (labelAttribute != null && 
labelAttribute.startsWith("edge.")) {
                        attributes = Cytoscape.getEdgeAttributes();
-               else
+                       labelAttribute = labelAttribute.substring(5);
+               } else
                        labelAttribute = null;
 
                for (Compound compound: compoundList) {
@@ -145,12 +149,16 @@
                        if (labelAttribute == null) {
                                label = new JLabel(new ImageIcon(img));
                        } else {
-                               String textLabel = 
attributes.getAttribute(compound.getSource().getIdentifier(),labelAttribute.substring(5)).toString();
-                               label = new JLabel(textLabel, new 
ImageIcon(img), JLabel.CENTER);
+                               Object textLabel = 
attributes.getAttribute(compound.getSource().getIdentifier(),labelAttribute);
+                               if (textLabel == null)
+                                       textLabel = 
compound.getSource().getIdentifier();
+                               label = new JLabel(textLabel.toString(), new 
ImageIcon(img), JLabel.CENTER);
                                label.setVerticalTextPosition(JLabel.BOTTOM);
                                label.setHorizontalTextPosition(JLabel.CENTER);
                        }
                        label.setBackground(Color.WHITE);
+                       label.setOpaque(true);
+                       label.setBorder(BorderFactory.createEtchedBorder());
                        label.addComponentListener(this);
                        imageMap.put(label, compound);
                        add (label);

Modified: 
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/renderers/CompoundRenderer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/renderers/CompoundRenderer.java
 2011-05-26 00:30:23 UTC (rev 25543)
+++ 
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ui/renderers/CompoundRenderer.java
 2011-05-26 00:34:49 UTC (rev 25544)
@@ -94,8 +94,11 @@
                if (width != table.getRowHeight())
                        table.setRowHeight(width); // Note, this will trigger a 
repaint!
                Image resizedImage = c.getImage(width,width);
-               if (resizedImage == null) return null;
-               JLabel l = new JLabel(new ImageIcon(resizedImage));
+               JLabel l;
+               if (resizedImage != null)
+                       l = new JLabel(new ImageIcon(resizedImage));
+               else
+                       l = new JLabel("No Image Available", JLabel.CENTER);
                if (!rowMap.containsKey(c.getSource())) {
                        rowMap.put(c.getSource(), new ArrayList());
                }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to