From: <sh...@us...> - 2010-02-04 18:18:01
|
Revision: 15371 http://cdk.svn.sourceforge.net/cdk/?rev=15371&view=rev Author: shk3 Date: 2010-02-04 18:17:54 +0000 (Thu, 04 Feb 2010) Log Message: ----------- generation can now start from fragments Modified Paths: -------------- detgen/trunk/lib/cdk-extra.jar detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministcGeneratorTest.java detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministicGenerator.java detgen/trunk/src/org/openscience/cdk/structgen/deterministic/Fragment.java Modified: detgen/trunk/lib/cdk-extra.jar =================================================================== (Binary files differ) Modified: detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministcGeneratorTest.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministcGeneratorTest.java 2010-02-04 10:31:33 UTC (rev 15370) +++ detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministcGeneratorTest.java 2010-02-04 18:17:54 UTC (rev 15371) @@ -2,14 +2,18 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; import org.junit.Assert; import org.junit.Test; import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IBond; import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.io.iterator.IteratingMDLReader; +import org.openscience.cdk.templates.MoleculeFactory; public class DeterministcGeneratorTest { @@ -31,10 +35,48 @@ } + @Test public void testWithStartFragments() throws CloneNotSupportedException, CDKException, IOException, ClassNotFoundException { + DeterministicGenerator dg = new DeterministicGenerator(true); + List<IMolecule> input = new ArrayList<IMolecule>(); + IMolecule benzene = MoleculeFactory.makeBenzene(); + benzene.getAtom(1).setHydrogenCount(0); + benzene.getAtom(1).setHydrogenCount(1); + benzene.getAtom(1).setHydrogenCount(2); + benzene.getAtom(1).setHydrogenCount(3); + benzene.getAtom(1).setHydrogenCount(4); + benzene.getAtom(0).setHydrogenCount(5); + input.add(benzene); + IMolecule secondFragment = MoleculeFactory.makeCyclopentane(); + secondFragment.getAtom(0).setSymbol("N"); + secondFragment.getAtom(1).setSymbol("O"); + secondFragment.getAtom(2).setHydrogenCount(1); + secondFragment.getAtom(3).setHydrogenCount(2); + secondFragment.getAtom(0).setHydrogenCount(0); + secondFragment.getAtom(1).setHydrogenCount(0); + secondFragment.getAtom(4).setHydrogenCount(0); + secondFragment.getBond(secondFragment.getAtom(0),secondFragment.getAtom(4)).setOrder(IBond.Order.DOUBLE); + input.add(secondFragment); + IMolecule mol = DefaultChemObjectBuilder.getInstance().newMolecule(); + mol.addAtom(DefaultChemObjectBuilder.getInstance().newAtom("C")); + input.add(mol); + mol = DefaultChemObjectBuilder.getInstance().newMolecule(); + mol.addAtom(DefaultChemObjectBuilder.getInstance().newAtom("C")); + input.add(mol); + mol = DefaultChemObjectBuilder.getInstance().newMolecule(); + mol.addAtom(DefaultChemObjectBuilder.getInstance().newAtom("O")); + input.add(mol); + mol = DefaultChemObjectBuilder.getInstance().newMolecule(); + mol.addAtom(DefaultChemObjectBuilder.getInstance().newAtom("N")); + input.add(mol); + FragmentList result = dg.generateIsomers(input); + //TODO: insert real value + Assert.assertEquals(15, result.size()); + } + public static void main(String[] args) throws CloneNotSupportedException, CDKException, IOException, ClassNotFoundException{ long start = System.currentTimeMillis(); DeterministicGenerator dg = new DeterministicGenerator(true); - FragmentList result = dg.generateIsomers("C4O1H4"); + FragmentList result = dg.generateIsomers("C2O1H1"); long end = System.currentTimeMillis(); System.out.println("Results "+result.size()+", time "+(end-start)/1000+" s, hit Enter to finish!"); Scanner sc = new Scanner(System.in); Modified: detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministicGenerator.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministicGenerator.java 2010-02-04 10:31:33 UTC (rev 15370) +++ detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministicGenerator.java 2010-02-04 18:17:54 UTC (rev 15371) @@ -22,6 +22,7 @@ import org.openscience.cdk.interfaces.IBond; import org.openscience.cdk.interfaces.IIsotope; import org.openscience.cdk.interfaces.IMolecularFormula; +import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.tools.manipulator.MolecularFormulaManipulator; public class DeterministicGenerator { @@ -187,4 +188,35 @@ level--; alreadyExploredGenerations.add(input); } + + + public FragmentList generateIsomers(List<IMolecule> fragments) throws CloneNotSupportedException, CDKException, IOException, ClassNotFoundException { + DefaultMutableTreeNode rootNode = null; + if(debug){ + JFrame frame = new JFrame("Deterministic Generator"); + frame.setLayout(new GridLayout(1, 0)); + rootNode = new DefaultMutableTreeNode("Root Node"); + treeModel = new DefaultTreeModel(rootNode); + tree = new JTree(treeModel); + tree.setEditable(true); + tree.getSelectionModel().setSelectionMode + (TreeSelectionModel.SINGLE_TREE_SELECTION); + tree.setShowsRootHandles(true); + + JScrollPane treepane = new JScrollPane(tree); + frame.add(treepane); + frame.setSize(500,500); + frame.setPreferredSize(new Dimension(500,500)); + frame.setMinimumSize(new Dimension(500,500)); + frame.pack(); + frame.setVisible(true); + } + FragmentList solutions=new FragmentList(); + Map<Fragment, Integer> input=new HashMap<Fragment, Integer>(); + for(int i=0;i<fragments.size();i++){ + input.put(new Fragment(fragments.get(i)),1); + } + makeNextGeneration(input, solutions, rootNode); + return solutions; + } } Modified: detgen/trunk/src/org/openscience/cdk/structgen/deterministic/Fragment.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/structgen/deterministic/Fragment.java 2010-02-04 10:31:33 UTC (rev 15370) +++ detgen/trunk/src/org/openscience/cdk/structgen/deterministic/Fragment.java 2010-02-04 18:17:54 UTC (rev 15371) @@ -86,13 +86,17 @@ } attachmentPoints = new HashMap<String,Map<IAtom,Integer>>(); for(int i=0;i<this.getAtomCount();i++){ - if(this.getAtom(i).getSymbol().equals("C") || this.getAtom(i).getSymbol().equals("H") || this.getAtom(i).getSymbol().equals("O")){ + if(this.getAtom(i).getSymbol().equals("C") || this.getAtom(i).getSymbol().equals("H") || this.getAtom(i).getSymbol().equals("O") || this.getAtom(i).getSymbol().equals("N")){ int sum = (int) this.getBondOrderSum(this.getAtom(i)); int desired = 1; if(this.getAtom(i).getSymbol().equals("C")) desired = 4; if(this.getAtom(i).getSymbol().equals("O")) desired=2; + if(this.getAtom(i).getSymbol().equals("N")) + desired=3; + if(this.getAtom(i).getHydrogenCount()!=null) + desired -= this.getAtom(i).getHydrogenCount(); for(int k=sum;k<desired;k++){ if(attachmentPoints.get(morganNumbers[i])==null){ Map<IAtom, Integer> map = new HashMap<IAtom, Integer>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |