SmilesGenerator { public String create(IAtomContainer molecule) throws CDKException { return create(molecule, new int[molecule.getAtomCount()]); } @Deprecated  SmilesGenerator();  SmilesGenerator(int flavour); SmilesGenerator aromatic(); @Deprecated SmilesGenerator withAtomClasses(); static SmilesGenerator generic(); static SmilesGenerator isomeric(); static SmilesGenerator unique(); static SmilesGenerator absolute(); @Deprecated String createSMILES(IAtomContainer molecule); @Deprecated String createSMILES(IReaction reaction); String create(IAtomContainer molecule); String create(IAtomContainer molecule, int[] order); static String create(IAtomContainer molecule, int flavour, int[] order); @Deprecated String createReactionSMILES(IReaction reaction); String create(IReaction reaction); String create(IReaction reaction, int[] ordering); @Deprecated void setUseAromaticityFlag(boolean useAromaticityFlag); static Comparator<IAtom> createComparator(final IAtomContainer mol,
                                                     final int flavor);  }
@Test public void testEthylPropylPhenantren() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.makeEthylPropylPhenantren(); SmilesGenerator sg = new SmilesGenerator(); fixCarbonHCount(mol1); String smiles1 = sg.create(mol1); Assert.assertNotNull(smiles1); Assert.assertEquals("C=1C=CC(=C2C=CC3=C(C12)C=CC(=C3)CCC)CC", smiles1); }
@Test public void testPropylCycloPropane() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.makePropylCycloPropane(); SmilesGenerator sg = new SmilesGenerator(); fixCarbonHCount(mol1); String smiles1 = sg.create(mol1); Assert.assertNotNull(smiles1); Assert.assertEquals("C1CC1CCC", smiles1); }
@Test public void testPartitioning() throws Exception { String smiles = ""; IAtomContainer molecule = new AtomContainer(); SmilesGenerator sg = new SmilesGenerator(); Atom sodium = new Atom("Na"); sodium.setFormalCharge(+1); Atom hydroxyl = new Atom("O"); hydroxyl.setImplicitHydrogenCount(1); hydroxyl.setFormalCharge(-1); molecule.addAtom(sodium); molecule.addAtom(hydroxyl); addImplicitHydrogens(molecule); smiles = sg.create(molecule); Assert.assertTrue(smiles.indexOf(".") != -1); }
@Test public void testBug791091() throws Exception { String smiles = ""; IAtomContainer molecule = new AtomContainer(); SmilesGenerator sg = new SmilesGenerator(); molecule.addAtom(new Atom("C")); molecule.addAtom(new Atom("C")); molecule.addAtom(new Atom("C")); molecule.addAtom(new Atom("C")); molecule.addAtom(new Atom("N")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(2, 4, IBond.Order.SINGLE); molecule.addBond(4, 0, IBond.Order.SINGLE); molecule.addBond(4, 3, IBond.Order.SINGLE); fixCarbonHCount(molecule); smiles = sg.create(molecule); Assert.assertEquals("C1CCN1C", smiles); }
@Test public void testSFBug956923_nonAromatic() throws Exception { String smiles = ""; IAtomContainer molecule = new AtomContainer(); SmilesGenerator sg = new SmilesGenerator(); Atom sp2CarbonWithOneHydrogen = new Atom("C"); sp2CarbonWithOneHydrogen.setHybridization(IAtomType.Hybridization.SP2); sp2CarbonWithOneHydrogen.setImplicitHydrogenCount(1); molecule.addAtom(sp2CarbonWithOneHydrogen); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addBond(5, 0, IBond.Order.SINGLE); smiles = sg.create(molecule); Assert.assertEquals("[CH]1[CH][CH][CH][CH][CH]1", smiles); }
@Test public void testPseudoAtom() throws Exception { IAtom atom = new PseudoAtom("Star"); SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smiles = ""; IAtomContainer molecule = new AtomContainer(); molecule.addAtom(atom); addImplicitHydrogens(molecule); smiles = sg.create(molecule); Assert.assertEquals("*", smiles); }
@Test public void testReactionSMILES() throws Exception { Reaction reaction = new Reaction(); AtomContainer methane = new AtomContainer(); methane.addAtom(new Atom("C")); reaction.addReactant(methane); IAtomContainer magic = new AtomContainer(); magic.addAtom(new PseudoAtom("magic")); reaction.addAgent(magic); IAtomContainer gold = new AtomContainer(); gold.addAtom(new Atom("Au")); reaction.addProduct(gold); methane.getAtom(0).setImplicitHydrogenCount(4); gold.getAtom(0).setImplicitHydrogenCount(0); SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smiles = sg.create(reaction); Assert.assertEquals("C>*>[Au]", smiles); }
@Test public void testCycloOctan() throws Exception { String filename = "data/mdl/cyclooctan.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(new AtomContainer()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.create(mol1); Assert.assertEquals("C\\1=C\\CCCCCC1", moleculeSmile); }
@Test public void testCycloOcten() throws Exception { String filename = "data/mdl/cycloocten.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(new AtomContainer()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.create(mol1); Assert.assertEquals("C1/C=C\\CCCCC1", moleculeSmile); }
@Test public void testCycloOctadien() throws Exception { String filename = "data/mdl/cyclooctadien.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class)); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.create(mol1); Assert.assertEquals("C=1\\CC/C=C\\CC/C1", moleculeSmile); }
@Test public void testSFBug1089770_1() throws Exception { String filename = "data/mdl/bug1089770-1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(new AtomContainer()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.create(mol1); Assert.assertEquals("C1CCC2=C(C1)CCC2", moleculeSmile); }
@Test public void testSFBug1089770_2() throws Exception { String filename = "data/mdl/bug1089770-2.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(new AtomContainer()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.create(mol1); Assert.assertEquals("C=1\\CC/C=C\\CC/C1", moleculeSmile); }
@Category(SlowTest.class) @Test public void testSFBug1014344() throws Exception { String filename = "data/mdl/bug1014344-1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(new AtomContainer()); addImplicitHydrogens(mol1); SmilesGenerator sg = new SmilesGenerator(); String molSmiles = sg.create(mol1); StringWriter output = new StringWriter(); CMLWriter cmlWriter = new CMLWriter(output); cmlWriter.write(mol1); CMLReader cmlreader = new CMLReader(new ByteArrayInputStream(output.toString().getBytes())); IAtomContainer mol2 = ((IChemFile) cmlreader.read(new ChemFile())).getChemSequence(0).getChemModel(0) .getMoleculeSet().getAtomContainer(0); addImplicitHydrogens(mol2); String cmlSmiles = sg.create(new AtomContainer(mol2)); Assert.assertEquals(molSmiles, cmlSmiles); }
@Test public void testSFBug1014344_1() throws Exception { String filename_cml = "data/cml/bug1014344-1.cml"; String filename_mol = "data/mdl/bug1014344-1.mol"; InputStream ins1 = this.getClass().getClassLoader().getResourceAsStream(filename_cml); InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename_mol); CMLReader reader1 = new CMLReader(ins1); IChemFile chemFile = (IChemFile) reader1.read(new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer mol1 = model.getMoleculeSet().getAtomContainer(0); MDLReader reader2 = new MDLReader(ins2); IAtomContainer mol2 = reader2.read(new AtomContainer()); addImplicitHydrogens(mol1); addImplicitHydrogens(mol2); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile1 = sg.create(mol1); String moleculeSmile2 = sg.create(mol2); Assert.assertEquals(moleculeSmile1, moleculeSmile2); }
@Test public void testPreservingFormalCharge() throws Exception { AtomContainer mol = new AtomContainer(); mol.addAtom(new Atom(Elements.OXYGEN)); mol.getAtom(0).setFormalCharge(-1); mol.addAtom(new Atom(Elements.CARBON)); mol.addBond(0, 1, IBond.Order.SINGLE); addImplicitHydrogens(mol); SmilesGenerator generator = new SmilesGenerator(); generator.create(new AtomContainer(mol)); Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().intValue()); }
@Test public void testTimeOut() throws Exception { String filename = "data/mdl/24763.sdf"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); ChemFile chemFile = reader.read(new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(1, containersList.size()); IAtomContainer container = containersList.get(0); SmilesGenerator smilesGenerator = new SmilesGenerator(); Assert.assertNotNull(smilesGenerator.create(container)); }
@Test public void testSFBug2051597() throws Exception { String smiles = "c1(c2ccc(c8ccccc8)cc2)" + "c(c3ccc(c9ccccc9)cc3)" + "c(c4ccc(c%10ccccc%10)cc4)" + "c(c5ccc(c%11ccccc%11)cc5)" + "c(c6ccc(c%12ccccc%12)cc6)" + "c1(c7ccc(c%13ccccc%13)cc7)"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer cdkMol = smilesParser.parseSmiles(smiles); SmilesGenerator smilesGenerator = new SmilesGenerator(); String genSmiles = smilesGenerator.create(cdkMol); Assert.assertTrue("There were'nt any % ring closures in the output", genSmiles.indexOf("%") >= 0); Assert.assertTrue(genSmiles.indexOf("%10") >= 0); Assert.assertTrue(genSmiles.indexOf("%11") >= 0); Assert.assertTrue(genSmiles.indexOf("%12") >= 0); Assert.assertTrue(genSmiles.indexOf("%13") >= 0); IAtomContainer cdkRoundTripMol = smilesParser.parseSmiles(genSmiles); Assert.assertNotNull(cdkRoundTripMol); }
@Test public void testBug3040273() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); String testSmiles = "C1(C(C(C(C(C1Br)Br)Br)Br)Br)Br"; IAtomContainer mol = sp.parseSmiles(testSmiles); IsotopeFactory fact = Isotopes.getInstance(); fact.configureAtoms(mol); SmilesGenerator sg = new SmilesGenerator(); String smiles = sg.create((IAtomContainer) mol); IAtomContainer mol2 = sp.parseSmiles(smiles); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(mol, mol2)); }
@Test public void testCreateSMILESWithoutCheckForMultipleMolecules_withDetectAromaticity() throws Exception { IAtomContainer benzene = TestMoleculeFactory.makeBenzene(); addImplicitHydrogens(benzene); SmilesGenerator sg = new SmilesGenerator(); String smileswithoutaromaticity = sg.create(benzene); Assert.assertEquals("C=1C=CC=CC1", smileswithoutaromaticity); }
@Test public void canonicalReactions() throws Exception { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IReaction r1 = smipar.parseReactionSmiles("CC(C)C1=CC=CC=C1.C(CC(=O)Cl)CCl>[Al+3].[Cl-].[Cl-].[Cl-].C(Cl)Cl>CC(C)C1=CC=C(C=C1)C(=O)CCCCl"); IReaction r2 = smipar.parseReactionSmiles("C(CC(=O)Cl)CCl.CC(C)C1=CC=CC=C1>[Al+3].[Cl-].[Cl-].[Cl-].C(Cl)Cl>CC(C)C1=CC=C(C=C1)C(=O)CCCCl"); IReaction r3 = smipar.parseReactionSmiles("CC(C)C1=CC=CC=C1.C(CC(=O)Cl)CCl>C(Cl)Cl.[Al+3].[Cl-].[Cl-].[Cl-]>CC(C)C1=CC=C(C=C1)C(=O)CCCCl"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavor.Canonical); assertThat(smigen.create(r1), is(smigen.create(r2))); assertThat(smigen.create(r2), is(smigen.create(r3))); }
@Test(expected = IllegalStateException.class) public void inconsistentAromaticState() throws Exception { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("c1ccccc1"); for (IAtom atom : mol.atoms()) atom.setIsAromatic(false); SmilesGenerator smigen = new SmilesGenerator(SmiFlavor.UseAromaticSymbols); smigen.create(mol); }
@Test public void strictIsotopes() throws CDKException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("[12CH3]C"); assertThat(new SmilesGenerator(SmiFlavor.AtomicMassStrict).create(mol), is("[12CH3]C")); }
@Test public void isotopes() throws CDKException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("[12CH3]C"); assertThat(new SmilesGenerator(SmiFlavor.AtomicMass).create(mol), is("[12CH3]C")); }
@Test public void cyclobutene() throws CDKException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("C1(C)=C(c2ccccc2)C=C1.C1(C)C(c2ccccc2)=CC=1"); assertThat(new SmilesGenerator(SmiFlavor.Canonical).create(mol), is("C=1C=CC(=CC1)C=2C=CC2C.C=1C=CC(=CC1)C=2C=CC2C")); assertThat(new SmilesGenerator(SmiFlavor.Canonical + SmiFlavor.UseAromaticSymbols).create(mol), is("c1ccc(cc1)C=2C=CC2C.c1ccc(cc1)C2=CC=C2C")); }
@Test public void roundTripExtendedCisTrans() throws CDKException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("C/C=C=C=C/C"); assertThat(new SmilesGenerator(SmiFlavor.Stereo).create(mol), is("C/C=C=C=C/C")); for (IStereoElement se : mol.stereoElements()) { se.setConfigOrder(se.getConfigOrder() ^ 0x3); } assertThat(new SmilesGenerator(SmiFlavor.Stereo).create(mol), is("C/C=C=C=C\\C")); }
@Test public void canonAtomMaps() throws CDKException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("[*:2]C(CC[*:3])[*:1]"); assertThat(new SmilesGenerator(SmiFlavor.Canonical|SmiFlavor.AtomAtomMap).create(mol), is("[*:1]C([*:2])CC[*:3]")); IAtomContainer mol2 = smipar.parseSmiles("[*:2]C(CC[*:1])[*:2]"); assertThat(new SmilesGenerator(SmiFlavor.Canonical|SmiFlavor.AtomAtomMap).create(mol2), is("[*:1]CCC([*:2])[*:2]")); }
@Test public void canonAtomMapsRenumber() throws CDKException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("[*:2]C(CC[*:3])[*:1]"); assertThat(new SmilesGenerator(SmiFlavor.Canonical|SmiFlavor.AtomAtomMapRenumber).create(mol), is("[*:1]CCC([*:2])[*:3]")); IAtomContainer mol2 = smipar.parseSmiles("[*:3]C(CC[*:1])[*:2]"); assertThat(new SmilesGenerator(SmiFlavor.Canonical|SmiFlavor.AtomAtomMapRenumber).create(mol2), is("[*:1]CCC([*:2])[*:3]")); }