Skip to content

Instantly share code, notes, and snippets.

@hariaimar
Created January 14, 2011 15:49
Show Gist options
  • Save hariaimar/779764 to your computer and use it in GitHub Desktop.
Save hariaimar/779764 to your computer and use it in GitHub Desktop.
import java.util.Iterator;
import java.util.Map;
import org.openscience.cdk.*;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.qsar.descriptors.molecular.*;
import org.openscience.cdk.smiles.*;
import org.openscience.cdk.qsar.*;
import org.openscience.cdk.qsar.result.IDescriptorResult;
/**
*
* @author Hari
* @since 19-12-2010
* @version 1.0
*/
public class descr {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws CDKException {
// TODO code application logic here
BCUTDescriptor descriptor = new BCUTDescriptor();
Molecule molecule = (Molecule) new SmilesParser(DefaultChemObjectBuilder.getInstance()).parseSmiles("NC(CO)C(=O)O");
// The first program in wiki link for Descriptor Calculator
DescriptorValue value = descriptor.calculate(molecule);
IDescriptorResult theNumbers = value.getValue();
System.out.print(theNumbers.toString()+"\n\n");
// 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.
*/
while(iterator. hasNext()){
String key = ((DescriptorSpecification)iterator.next()).getSpecificationReference().toString();
System.out.print(key.substring(key.lastIndexOf("#")+1)+" : ");
System.out.print(((DescriptorValue)i.get((DescriptorSpecification)iterator.next())).getValue().toString()+"\n\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment