Created
February 16, 2011 12:08
-
-
Save hariaimar/829277 to your computer and use it in GitHub Desktop.
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
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.util.Iterator; | |
import java.util.Map; | |
import jxl.Workbook; | |
import jxl.write.Label; | |
import jxl.write.WritableSheet; | |
import jxl.write.WritableWorkbook; | |
import jxl.write.WriteException; | |
import org.openscience.cdk.DefaultChemObjectBuilder; | |
import org.openscience.cdk.Molecule; | |
import org.openscience.cdk.exception.CDKException; | |
import org.openscience.cdk.interfaces.IMolecule; | |
import org.openscience.cdk.io.iterator.IteratingMDLReader; | |
import org.openscience.cdk.qsar.DescriptorEngine; | |
import org.openscience.cdk.qsar.DescriptorSpecification; | |
import org.openscience.cdk.qsar.DescriptorValue; | |
import org.openscience.cdk.qsar.descriptors.molecular.BCUTDescriptor; | |
import org.openscience.cdk.smiles.SmilesGenerator; | |
import org.openscience.cdk.smiles.SmilesParser; | |
/** | |
* | |
* @author Hari | |
*acknowledgement CDK team,Ramachandran T.C | |
*/ | |
public class Main { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) throws FileNotFoundException, CDKException, IOException, WriteException { | |
// TODO code application logic here | |
File sdfFile = new File("/hari/home/Downloads/CID_241.sdf"); | |
WritableWorkbook workbook = Workbook.createWorkbook(new File("output.xls")); | |
WritableSheet sheet = workbook.createSheet("Sheet1",0); | |
IteratingMDLReader reader = new IteratingMDLReader(new FileInputStream(sdfFile), DefaultChemObjectBuilder.getInstance()); | |
SmilesGenerator sg = new SmilesGenerator(); | |
String smile = ""; | |
int k = 0; | |
while (reader.hasNext()) { | |
IMolecule mol = (IMolecule)reader.next(); | |
smile = sg.createSMILES(mol); | |
System.out.print(smile+"\n"); | |
BCUTDescriptor descriptor = new BCUTDescriptor(); | |
// Molecule molecule = (Molecule) new SmilesParser(DefaultChemObjectBuilder.getInstance()).parseSmiles("NC(CO)C(=O)O"); | |
Molecule molecule = (Molecule) new SmilesParser(DefaultChemObjectBuilder.getInstance()).parseSmiles(smile); | |
// Second program | |
DescriptorEngine engine = new DescriptorEngine(DescriptorEngine.MOLECULAR); | |
engine.process(molecule); | |
/** | |
* The function getProperties returns a Map value. Map represents a Key Value set. | |
* It is retrieved using an iterator. Since the key is of DescriptorSpecification class and the | |
* value is of type DescriptorValue we have to typecast the key and value with the same while retrieving. | |
* since they have not override the same to String. | |
*/ | |
Map i = molecule.getProperties(); | |
Iterator iterator = i.keySet().iterator(); | |
/** | |
* The following prints the key and Value set. | |
*/ | |
Label label0 = new Label(1, k, smile); | |
sheet.addCell(label0); | |
k++;k++; | |
while (iterator.hasNext()) { | |
Object l = iterator.next(); | |
String key = ((DescriptorSpecification) l).getSpecificationReference().toString(); | |
Label label1 = new Label(1,k,key.substring(key.lastIndexOf("#") + 1)); | |
sheet.addCell(label1); | |
Label label2 = new Label(2,k,((DescriptorValue) i.get((DescriptorSpecification)l)).getValue().toString()); | |
sheet.addCell(label2); | |
k++; | |
} | |
k++;k++; | |
} | |
workbook.write(); | |
workbook.close(); | |
System.out.print(k+"\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment