forked from bioclipse/bioclipse.cheminformatics
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added support for SmartsMatching on MolTable.
* Added checkbox for SmartsMatchingView * Rewrote models to support SmartsFiles * Added import SMARTS from file * Running SmartsMatching with MolTable open highlights hits in chemical structures. Smartsmatching in MolTable is very slow, mainly because results are not persisted among redraws (see bug 1676). Solves bug 1675.
- Loading branch information
Showing
14 changed files
with
946 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...oclipse.cdk.smartsmatching/src/net/bioclipse/cdk/smartsmatching/SmartsMatchGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009 Ola Spjuth. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Ola Spjuth - initial API and implementation | ||
******************************************************************************/ | ||
package net.bioclipse.cdk.smartsmatching; | ||
|
||
import java.awt.Color; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jface.preference.IPreferenceStore; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
import org.openscience.cdk.interfaces.IAtomContainer; | ||
import org.openscience.cdk.renderer.RendererModel; | ||
import org.openscience.cdk.renderer.elements.ElementGroup; | ||
import org.openscience.cdk.renderer.elements.IRenderingElement; | ||
import org.openscience.cdk.renderer.elements.OvalElement; | ||
import org.openscience.cdk.renderer.generators.IGenerator; | ||
import org.openscience.cdk.renderer.generators.IGeneratorParameter; | ||
|
||
|
||
public class SmartsMatchGenerator implements IGenerator { | ||
|
||
public SmartsMatchGenerator() { | ||
|
||
} | ||
|
||
/** | ||
* Set up the colored circles based on calculated properties = matches | ||
*/ | ||
public IRenderingElement generate( IAtomContainer ac, | ||
RendererModel model ) { | ||
|
||
// System.out.println("Generator found AC: " + ac); | ||
|
||
ElementGroup group = new ElementGroup(); | ||
Object o = ac.getProperty( SmartsMatchingConstants.SMARTS_MATCH_PROPERTY ); | ||
if (o==null) return group; | ||
|
||
//Need to parse the property into something which we can highlight | ||
List<Integer> highlightList=SmartsMatchingHelper.parseProperty(o); | ||
|
||
for(int i = 0;i<ac.getAtomCount();i++) { //Loop over all atoms | ||
for (Integer ii : highlightList){ //Loop over list of atom indices with M2D results | ||
if (ii.intValue()==i){ | ||
IAtom atom = ac.getAtom( i ); | ||
|
||
Color drawColor=SmartsMatchingConstants.SMARTS_HIGHLIGHT_COLOR; | ||
double radius=SmartsMatchingConstants.SMARTS_HIGHLIGHT_RADIUS; | ||
|
||
group.add( new OvalElement( atom.getPoint2d().x, | ||
atom.getPoint2d().y, | ||
radius,true, drawColor )); | ||
} | ||
} | ||
} | ||
|
||
return group; | ||
} | ||
|
||
public List<IGeneratorParameter> getParameters() { | ||
return Collections.emptyList(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ipse.cdk.smartsmatching/src/net/bioclipse/cdk/smartsmatching/SmartsMatchingConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.bioclipse.cdk.smartsmatching; | ||
|
||
import java.awt.Color; | ||
|
||
/** | ||
* | ||
* @author ola | ||
* | ||
*/ | ||
public class SmartsMatchingConstants { | ||
|
||
public static final Object SMARTS_MATCH_PROPERTY = "SMARTS_PROPERTY"; | ||
public static final Color SMARTS_HIGHLIGHT_COLOR = Color.YELLOW; | ||
public static final double SMARTS_HIGHLIGHT_RADIUS = 0.4; | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...oclipse.cdk.smartsmatching/src/net/bioclipse/cdk/smartsmatching/SmartsMatchingHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package net.bioclipse.cdk.smartsmatching; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.StringTokenizer; | ||
|
||
import net.bioclipse.cdk.business.CDKManager; | ||
import net.bioclipse.cdk.domain.ICDKMolecule; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
|
||
|
||
public class SmartsMatchingHelper { | ||
|
||
private static final Logger logger = Logger.getLogger(CDKManager.class); | ||
|
||
/** | ||
* Deliver a list of integers to highlight | ||
* @param o | ||
* @return | ||
*/ | ||
public static List<Integer> parseProperty( Object o ) { | ||
|
||
if (!( o instanceof String )) | ||
return Collections.emptyList(); | ||
|
||
String prop=(String)o; | ||
|
||
List<Integer> ret=new ArrayList<Integer>(); | ||
|
||
logger.debug( "Parsing property: " + prop ); | ||
|
||
//Parse 1,2,3,8 into list of Integers | ||
//split up entire string by , | ||
StringTokenizer tk=new StringTokenizer(prop, ","); | ||
while ( tk.hasMoreElements() ) { | ||
String token = tk.nextToken(); | ||
Integer atomno=Integer.parseInt( token ); | ||
ret.add( atomno ); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
/** | ||
* Save the atoms to property | ||
* @param cdkmol | ||
* @param hitAtoms | ||
*/ | ||
public static void serializeToProperty( ICDKMolecule cdkmol, | ||
Set<IAtom> hitAtoms ) { | ||
|
||
String prop=""; | ||
for (IAtom atom : hitAtoms){ | ||
int atomno=cdkmol.getAtomContainer().getAtomNumber( atom ); | ||
if (atomno>0) | ||
prop=prop+atomno+","; | ||
} | ||
|
||
if (prop.length()<=0) return; | ||
|
||
prop=prop.substring( 0,prop.length()-1 ); | ||
|
||
cdkmol.getAtomContainer().getProperties().put( | ||
SmartsMatchingConstants.SMARTS_MATCH_PROPERTY, prop ); | ||
|
||
logger.debug("Serialized ac prop: " + prop); | ||
|
||
} | ||
|
||
} |
126 changes: 126 additions & 0 deletions
126
...artsmatching/src/net/bioclipse/cdk/smartsmatching/SmartsMatchingRendererConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009 Ola Spjuth. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Ola Spjuth - initial API and implementation | ||
******************************************************************************/ | ||
package net.bioclipse.cdk.smartsmatching; | ||
|
||
import java.awt.Color; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.core.runtime.jobs.Job; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
import org.openscience.cdk.interfaces.IAtomContainer; | ||
import org.openscience.cdk.renderer.RendererModel; | ||
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; | ||
|
||
import net.bioclipse.cdk.business.Activator; | ||
import net.bioclipse.cdk.business.CDKManager; | ||
import net.bioclipse.cdk.business.ICDKManager; | ||
import net.bioclipse.cdk.domain.CDKMolecule; | ||
import net.bioclipse.cdk.domain.ICDKMolecule; | ||
import net.bioclipse.cdk.smartsmatching.views.SmartsMatchingView; | ||
import net.bioclipse.cdk.ui.sdfeditor.editor.IRenderer2DConfigurator; | ||
import net.bioclipse.core.business.BioclipseException; | ||
|
||
public class SmartsMatchingRendererConfigurator | ||
implements IRenderer2DConfigurator{ | ||
|
||
private static final Logger logger = Logger.getLogger( | ||
SmartsMatchingRendererConfigurator.class); | ||
|
||
//The bondcolor in M2d results | ||
Color bondcolor=new Color(33,33,33); | ||
|
||
/** | ||
* Add tooltip read from M2D property | ||
*/ | ||
public void configure(final RendererModel model, final IAtomContainer ac) { | ||
|
||
// Job job=new Job("") { | ||
// | ||
// @Override | ||
// protected IStatus run( IProgressMonitor monitor ) { | ||
|
||
ICDKManager cdk = Activator.getDefault().getJavaCDKManager(); | ||
|
||
//Get the SMARTS from the SmartsView | ||
List<String> allSmarts=SmartsMatchingView.getActiveSmarts(); | ||
if (allSmarts==null || allSmarts.size()<=0) | ||
return; | ||
// return Status.OK_STATUS; | ||
|
||
//Read from prefs for AC to see if we need to calculate again | ||
String smartsProp=(String) ac.getProperty( | ||
SmartsMatchingConstants.SMARTS_MATCH_PROPERTY ); | ||
|
||
//The below does not work since properties are lost. | ||
//Filed as Bug 1676 | ||
if (smartsProp!=null){ | ||
//Check if we have calculated, if so, do not repeat it | ||
return; | ||
} | ||
|
||
//Calculate smarts matches and store as property | ||
ICDKMolecule cdkmol=new CDKMolecule(ac); | ||
|
||
//Store atoms for highlighting in a set, no duplicates | ||
Set<IAtom> hitAtoms=new HashSet<IAtom>(); | ||
|
||
for (String activeSmarts : allSmarts ){ | ||
List<IAtomContainer> hitACs; | ||
try { | ||
hitACs = cdk.getSmartsMatches( cdkmol, activeSmarts ); | ||
if (hitACs!=null){ | ||
|
||
for (IAtomContainer hitAC : hitACs){ | ||
for (IAtom atom : hitAC.atoms()){ | ||
hitAtoms.add( atom ); | ||
} | ||
} | ||
} | ||
} catch ( BioclipseException e ) { | ||
logger.error( "SMARST matching failed for smarts: " | ||
+ activeSmarts + " due to: " + e.getMessage()); | ||
} | ||
} | ||
|
||
if (hitAtoms.size()>0) | ||
//Serialize to property | ||
SmartsMatchingHelper.serializeToProperty(cdkmol, hitAtoms); | ||
|
||
model.setIsCompact( true ); | ||
model.setShowAtomTypeNames( false ); | ||
model.setShowImplicitHydrogens( false ); | ||
model.setShowExplicitHydrogens( false ); | ||
model.setAtomRadius( 0 ); | ||
|
||
|
||
//Update drawing | ||
//TODO: is this really needed here? | ||
model.fireChange(); | ||
|
||
// TODO Auto-generated method stub | ||
return; | ||
// return Status.OK_STATUS; | ||
// } | ||
// }; | ||
// | ||
// job.setUser( false ); | ||
// job.schedule(); | ||
|
||
|
||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...t.bioclipse.cdk.smartsmatching/src/net/bioclipse/cdk/smartsmatching/model/SmartsFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.bioclipse.cdk.smartsmatching.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.bioclipse.core.domain.BioObject; | ||
|
||
|
||
public class SmartsFile extends BioObject{ | ||
|
||
List<SmartsWrapper> smarts; | ||
String name; | ||
|
||
public List<SmartsWrapper> getSmarts() { | ||
|
||
return smarts; | ||
} | ||
|
||
public void setSmarts( List<SmartsWrapper> smarts ) { | ||
|
||
this.smarts = smarts; | ||
} | ||
|
||
public String getName() { | ||
|
||
return name; | ||
} | ||
|
||
public void setName( String name ) { | ||
|
||
this.name = name; | ||
} | ||
|
||
public void addSmartsWrapper( SmartsWrapper sw ) { | ||
if (smarts==null) smarts= new ArrayList<SmartsWrapper>(); | ||
smarts.add( sw ); | ||
} | ||
|
||
} |
Oops, something went wrong.