Hello, I am an undergraduate trying to write some code to generate some molecules from random smiles strings. I want to use the VicinitySampler or other constitutional isomer generator, but I tried to input some code based on the VicinitySamplertest and it isn't working. I am using the CDK by importing the jar files into Eclipse. I'm not sure if I need to add hydrogens after creating the molecule. I also tried using a simple smiles string from the test rather than the one created below but the molecule seems to be built. Thanks for any help. Here is my code:
import org.openscience.cdk.exception.InvalidSmilesException; import org.openscience.cdk.graph.ConnectivityChecker; import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.smiles.*; import org.openscience.cdk.structgen.*; import org.openscience.cdk.DefaultChemObjectBuilder; import java.util.List; import java.util.Random; public class RandomString { static final char[] _chars = { 'C','C','C','O','O','N','N','C', }; static Random _r = new Random(); static void randomStr(char[] buf, int len) { for (int i = 0; i < len; i++) { buf[i] = _chars[_r.nextInt(8)]; } } public static void main(String[] args) throws InvalidSmilesException { char[] buf = new char[5]; String s; randomStr(buf, 5); s = new String(buf); SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IMolecule mol = sp.parseSmiles(s); List structures = VicinitySampler.sample(mol); System.out.print(structures.size() + "\n"); System.out.print(mol.getAtomCount()+ "\n"); System.out.print(mol.getFirstAtom() + " \n"); System.out.print(ConnectivityChecker.isConnected(mol)); } } ## And here is the output 5 4 Atom(9532399, C, H:3, SP:0, 2D:[null], 3D:[null], Fract3D:[null], C:0.0, FC:0, AtomType(null, MBO:0.0, BOS:0.0, FC:0, H:0, NC:0, CR:0.0, VDWR:0.0, EV:0, Isotope(0, EM:-1.0, AB:-1.0, Element(C, ID:null, AN:0)))) true ------------------------------------------------------------------------------ Check out the new SourceForge.net Marketplace. It is the best place to buy or sell services for just about anything Open Source. http://p.sf.net/sfu/Xq1LFB _______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user