From 040d6022a42c9e5fab97a42cded77fd20d3def3f Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 22 Jul 2010 17:12:51 +0200 Subject: CONFIG reverted to @@config --- application.rb | 22 +++++++-- public/java/Display.java | 124 ----------------------------------------------- public/java/Makefile | 9 ++-- 3 files changed, 20 insertions(+), 135 deletions(-) delete mode 100644 public/java/Display.java diff --git a/application.rb b/application.rb index e1c6214..b8b1d04 100644 --- a/application.rb +++ b/application.rb @@ -1,25 +1,37 @@ # Java environment -=begin ENV["JAVA_HOME"] = "/usr/lib/jvm/java-6-sun" unless ENV["JAVA_HOME"] java_dir = File.join File.expand_path(File.dirname(__FILE__)),"public/java" cdk = File.join java_dir, "cdk-1.3.5.jar" jchempaint = File.join java_dir, "cdk-jchempaint-15.jar" ENV["CLASSPATH"] = "#{ENV["CLASSPATH"]}:#{java_dir}:#{cdk}:#{jchempaint}" -=end require 'rubygems' -#require 'rjb' +require 'rjb' gem "opentox-ruby-api-wrapper", "= 1.6.0" require 'opentox-ruby-api-wrapper' -#set :lock, true +get %r{/smiles/(.+)/smarts/(.*)} do |smiles,smarts| + content_type "image/png" + attachment "#{smiles}.png" + #LOGGER.debug "SMILES: #{smiles}, SMARTS: #{smarts}" + s = Rjb::import('Structure').new(smiles,200) + s.match(smarts) + s.show +end + + +get %r{/smiles/(.+)} do |smiles| + content_type "image/png" + attachment "#{smiles}.png" + Rjb::import('Structure').new(smiles,200).show +end get %r{/(.+)/image} do |inchi| # catches all remaining get requests smiles = OpenTox::Compound.new(:inchi => inchi).smiles content_type "image/png" attachment "#{smiles}.png" - Rjb::import('Display').new(smiles,600).image + Rjb::import('Structure').new(smiles,200).show end diff --git a/public/java/Display.java b/public/java/Display.java deleted file mode 100644 index 2950ca7..0000000 --- a/public/java/Display.java +++ /dev/null @@ -1,124 +0,0 @@ -import java.util.List; -import java.util.Arrays; -import java.util.*; -import java.io.*; - -import java.awt.*; -import java.awt.image.*; -import java.awt.geom.*; - -import javax.imageio.*; - -import org.openscience.cdk.*; -import org.openscience.cdk.interfaces.*; -import org.openscience.cdk.layout.*; -import org.openscience.cdk.renderer.*; -import org.openscience.cdk.renderer.font.*; -import org.openscience.cdk.renderer.generators.*; -import org.openscience.cdk.renderer.visitor.*; -import org.openscience.cdk.templates.*; -import org.openscience.cdk.smiles.*; -import org.openscience.cdk.smiles.smarts.*; -import org.openscience.cdk.graph.*; -import org.openscience.cdk.geometry.*; - -public class Display{ - - int size; - Rectangle drawArea; - IMolecule molecule = new Molecule(); - IMoleculeSet moleculeSet; - IMolecule[] coordinated_mols; - StructureDiagramGenerator sdg = new StructureDiagramGenerator(); - SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); - AtomContainer matches = new AtomContainer(); - Vector idlist = new Vector(); - List generators = new ArrayList(); - Renderer renderer; - BufferedImage image; - Graphics2D g2; - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - public Display (String smiles, int s) { - - size = s; - // generators make the image elements - generators.add(new BasicSceneGenerator()); - generators.add(new BasicBondGenerator()); - generators.add(new RingGenerator()); - generators.add(new BasicAtomGenerator()); - renderer = new Renderer(generators, new AWTFontManager()); - try { molecule = sp.parseSmiles(smiles); } - catch (Exception ex) { ex.printStackTrace(); } - moleculeSet = ConnectivityChecker.partitionIntoMolecules(molecule); - coordinated_mols = new IMolecule[moleculeSet.getMoleculeCount()]; - drawArea = new Rectangle(size, size); - image = new BufferedImage(size, size , BufferedImage.TYPE_INT_RGB); - g2 = (Graphics2D)image.getGraphics(); - g2.setColor(Color.WHITE); - g2.fillRect(0, 0, size, size); - } - - public byte[] image() { - try { - Rectangle2D last = new Rectangle(0,0); - for (int i = 0; i < moleculeSet.getMoleculeCount(); i++) { - IAtomContainer mol = moleculeSet.getMolecule(i); - sdg.setMolecule((IMolecule) mol); - sdg.generateCoordinates(); - mol = sdg.getMolecule(); - GeometryTools.translateAllPositive(mol); - // get size of previous mol and shift - last = GeometryTools.shiftContainer(mol, GeometryTools.getRectangle2D(mol), last,2); - coordinated_mols[i] = (IMolecule) mol; - } - moleculeSet.setMolecules(coordinated_mols); - renderer.paintMoleculeSet(moleculeSet, new AWTDrawVisitor(g2), drawArea, true); - matchSmarts("NN",Color.green); - ImageIO.write(image, "png", out); - } catch (Exception ex) { - ex.printStackTrace(); - } - return out.toByteArray(); - } - -// public Image match(String smiles, String smarts) { -// } - private void matchSmarts(String smarts, Color color) { - try { - // map smarts - SMARTSQueryTool querytool = new SMARTSQueryTool(smarts); - boolean status = querytool.matches(molecule); - if (status) { - List> mappings = querytool.getMatchingAtoms(); - int nmatch = querytool.countMatches(); - for (int i = 0; i < nmatch; i++) { - List atomIndices = (List) mappings.get(i); - for (int n = 0; n < atomIndices.size(); n++) { - Integer atomID = (Integer) atomIndices.get(n); - idlist.add(atomID); - } - } - } - - // get a unique list of bond ID's and add them to an AtomContainer - HashSet hs = new HashSet(idlist); - for (Integer h : hs) { - IAtom a = molecule.getAtom(h); - List bond_list = molecule.getConnectedBondsList(a); - for (int i = 0; i < bond_list.size(); i++) { - IBond b = (IBond) bond_list.get(i); - Integer connectedNr = molecule.getAtomNumber(b.getConnectedAtom(a)); - //if (hs.contains(connectedNr)) renderer.getRenderer2DModel().getColorHash().put(b, color); - } - } - - } catch (Exception exc) { - exc.printStackTrace(); - } - - } - -} - diff --git a/public/java/Makefile b/public/java/Makefile index bcae6ec..bffc3d8 100644 --- a/public/java/Makefile +++ b/public/java/Makefile @@ -1,9 +1,6 @@ -#all: DisplayStructure.class -all: Display.class - -#%.class: %.java -# javac -Xlint:deprecation -Xlint:unchecked -classpath ./:./cdk-1.0.1.jar $< +all: Structure.class %.class: %.java - javac -classpath ./:./cdk-1.3.5.jar:./cdk-jchempaint-15.jar $< + javac -classpath ./:./cdk-1.3.5.jar:./cdk-jchempaint-15.jar $< + #javac -classpath ./:./cdk-1.2.5.jar $< #javac -Xlint:deprecation -Xlint:unchecked -classpath ./:./cdk-1.3.5.jar:./cdk-jchempaint-15.jar $< -- cgit v1.2.3