Skip to content

Commit

Permalink
Do atomtyping when converting from SMILES to SDF
Browse files Browse the repository at this point in the history
  • Loading branch information
goglepox committed Sep 13, 2012
1 parent c5de6ce commit 29a5289
Showing 1 changed file with 34 additions and 11 deletions.
Expand Up @@ -39,10 +39,12 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.progress.IProgressConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.smiles.DeduceBondSystemTool;
import org.openscience.cdk.smiles.FixBondOrdersTool;

import net.bioclipse.cdk.business.Activator;
import net.bioclipse.cdk.business.ICDKManager;
Expand Down Expand Up @@ -145,22 +147,39 @@ protected IStatus run(IProgressMonitor monitor) {
ui.remove(output);
}
monitor.beginTask( "Converting file", count );
FixBondOrdersTool bondOrderTool = new FixBondOrdersTool();
long timestamp = System.currentTimeMillis();
long before = timestamp;
int current = 0;
int last = 0;

int failedCount= 0;
while ( iterator.hasNext() ) {
try {
cdk.appendToSDF(newPath, iterator.next());
ICDKMolecule mol = iterator.next();
boolean filterout = false;
for(IAtom atom:mol.getAtomContainer().atoms()) {
if( atom.getAtomTypeName()==null ||
atom.getAtomTypeName().equals("X")){
filterout = true;
}
}
if(!filterout) {
IMolecule newAC =
bondOrderTool.kekuliseAromaticRings((IMolecule) mol.getAtomContainer());
mol = new CDKMolecule(newAC);
cdk.appendToSDF(output, mol);
} else{
++failedCount;
}
} catch ( BioclipseException e ) {
LogUtils.handleException( e, logger,
"net.bioclipse.cdk.ui" );
return new Status(
IStatus.ERROR,
net.bioclipse.cdk.ui.Activator.PLUGIN_ID,
"Error, failed to write to file.");
++failedCount;
logger.error(e.getMessage(),e);
}
current++;
catch (CDKException e) {
++failedCount;
logger.warn("Could not deduce bond orders");
} current++;
if (System.currentTimeMillis() - timestamp > 1000) {
monitor.subTask( "Done: " + current + "/" + count
+ " (" + TimeCalculator.generateTimeRemainEst(
Expand All @@ -175,11 +194,15 @@ protected IStatus run(IProgressMonitor monitor) {
timestamp = System.currentTimeMillis();
}
}

monitor.done();
logger.debug("Wrote file" + newPath);
return Status.OK_STATUS;
logger.debug("Wrote file" + output);
if(failedCount!=0){
setProperty(IProgressConstants.KEEP_PROPERTY, true);
}

return new Status(IStatus.OK,net.bioclipse.cdk.ui.Activator.PLUGIN_ID,
"Failed to convert "+failedCount+" molecules");
}};
job.setUser(true);
job.schedule();
Expand Down

0 comments on commit 29a5289

Please sign in to comment.