📄 smilesgeneratortest.java
字号:
hydroxyl.setHydrogenCount(1); hydroxyl.setFormalCharge(-1); molecule.addAtom(sodium); molecule.addAtom(hydroxyl); smiles = sg.createSMILES(molecule); assertTrue(smiles.indexOf(".") != -1); } /** * @cdk.bug 791091 */ public void testBug791091() { String smiles = ""; Molecule molecule = new Molecule(); 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, 1.0); molecule.addBond(1, 2, 1.0); molecule.addBond(2, 4, 1.0); molecule.addBond(4, 0, 1.0); molecule.addBond(4, 3, 1.0); fixCarbonHCount(molecule); smiles = sg.createSMILES(molecule); assertEquals("N1(C)CCC1", smiles); } /** * @cdk.bug 590236 */ public void testBug590236() { String smiles = ""; Molecule molecule = new Molecule(); SmilesGenerator sg = new SmilesGenerator(); molecule.addAtom(new Atom("C")); Atom carbon2 = new Atom("C"); carbon2.setMassNumber(13); molecule.addAtom(carbon2); molecule.addBond(0, 1, 1.0); fixCarbonHCount(molecule); smiles = sg.createSMILES(molecule); assertEquals("C[13C]", smiles); } /** * A bug reported for JChemPaint. * * @cdk.bug 956923 */ public void testSFBug956923() throws Exception { String smiles = ""; Molecule molecule = new Molecule(); SmilesGenerator sg = new SmilesGenerator(); Atom sp2CarbonWithOneHydrogen = new Atom("C"); sp2CarbonWithOneHydrogen.setHybridization(CDKConstants.HYBRIDIZATION_SP2); sp2CarbonWithOneHydrogen.setHydrogenCount(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, 1.0); molecule.addBond(1, 2, 1.0); molecule.addBond(2, 3, 1.0); molecule.addBond(3, 4, 1.0); molecule.addBond(4, 5, 1.0); molecule.addBond(5, 0, 1.0); smiles = sg.createSMILES(molecule); assertEquals("c1ccccc1", smiles); } /** * A unit test for JUnit */ public void testAtomPermutation() { Molecule mol = new Molecule(); mol.addAtom(new Atom("S")); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, 2.0); mol.addBond(0, 2, 2.0); mol.addBond(0, 3, 1.0); mol.addBond(0, 4, 1.0); mol.getAtom(3).setHydrogenCount(1); mol.getAtom(4).setHydrogenCount(1); AtomContainerAtomPermutor acap = new AtomContainerAtomPermutor(mol); SmilesGenerator sg = new SmilesGenerator(); String smiles = ""; String oldSmiles = sg.createSMILES(mol); while (acap.hasNext()) { smiles = sg.createSMILES(new Molecule((AtomContainer) acap.next())); //logger.debug(smiles); assertEquals(oldSmiles, smiles); } } /** * A unit test for JUnit */ public void testBondPermutation() { Molecule mol = new Molecule(); mol.addAtom(new Atom("S")); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, 2.0); mol.addBond(0, 2, 2.0); mol.addBond(0, 3, 1.0); mol.addBond(0, 4, 1.0); mol.getAtom(3).setHydrogenCount(1); mol.getAtom(4).setHydrogenCount(1); AtomContainerBondPermutor acbp = new AtomContainerBondPermutor(mol); SmilesGenerator sg = new SmilesGenerator(); String smiles = ""; String oldSmiles = sg.createSMILES(mol); while (acbp.hasNext()) { smiles = sg.createSMILES(new Molecule((AtomContainer) acbp.next())); //logger.debug(smiles); assertEquals(oldSmiles, smiles); } } private void fixCarbonHCount(Molecule mol) { /* * the following line are just a quick fix for this * particluar carbon-only molecule until we have a proper * hydrogen count configurator */ double bondCount = 0; org.openscience.cdk.interfaces.IAtom atom; for (int f = 0; f < mol.getAtomCount(); f++) { atom = mol.getAtom(f); bondCount = mol.getBondOrderSum(atom); if (atom.getSymbol().equals("C")) { atom.setHydrogenCount(4 - (int) bondCount - (int) atom.getCharge()); } if (atom.getSymbol().equals("N")) { atom.setHydrogenCount(3 - (int) bondCount - (int) atom.getCharge()); } } } /** * A unit test for JUnit */ public void testPseudoAtom() { Atom atom = new PseudoAtom("Star"); SmilesGenerator sg = new SmilesGenerator(); String smiles = ""; Molecule molecule = new Molecule(); molecule.addAtom(atom); smiles = sg.createSMILES(molecule); assertEquals("[*]", smiles); } /** * Test generation of a reaction SMILES. I know, it's a stupid alchemic * reaction, but it serves its purpose. */ public void testReactionSMILES() throws Exception { Reaction reaction = new Reaction(); Molecule methane = new Molecule(); methane.addAtom(new Atom("C")); reaction.addReactant(methane); Molecule magic = new Molecule(); magic.addAtom(new PseudoAtom("magic")); reaction.addAgent(magic); Molecule gold = new Molecule(); gold.addAtom(new Atom("Au")); reaction.addProduct(gold); SmilesGenerator sg = new SmilesGenerator(); String smiles = sg.createSMILES(reaction); //logger.debug("Generated SMILES: " + smiles); assertEquals("C>[*]>[Au]", smiles); } /** * Test generation of a D and L alanin. */ public void testAlaSMILES() throws Exception { String filename = "data/mdl/l-ala.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); new HydrogenAdder().addExplicitHydrogensToSatisfyValency(mol1); new HydrogenPlacer().placeHydrogens2D(mol1, 1.0); filename = "data/mdl/d-ala.mol"; ins = this.getClass().getClassLoader().getResourceAsStream(filename); reader = new MDLReader(ins); Molecule mol2 = (Molecule) reader.read(new Molecule()); new HydrogenAdder().addExplicitHydrogensToSatisfyValency(mol2); new HydrogenPlacer().placeHydrogens2D(mol2, 1.0); SmilesGenerator sg = new SmilesGenerator(); String smiles1 = sg.createChiralSMILES(mol1, new boolean[20]); String smiles2 = sg.createChiralSMILES(mol2, new boolean[20]); assertNotSame(smiles1, smiles2); } /** * Test some sugars */ public void testSugarSMILES() throws Exception { String filename = "data/mdl/D-mannose.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); new HydrogenPlacer().placeHydrogens2D(mol1, 1.0); filename = "data/mdl/D+-glucose.mol"; ins = this.getClass().getClassLoader().getResourceAsStream(filename); reader = new MDLReader(ins); Molecule mol2 = (Molecule) reader.read(new Molecule()); new HydrogenPlacer().placeHydrogens2D(mol2, 1.0); SmilesGenerator sg = new SmilesGenerator(); String smiles1 = sg.createChiralSMILES(mol1, new boolean[20]); String smiles2 = sg.createChiralSMILES(mol2, new boolean[20]); assertNotSame(smiles1, smiles2); } /** * Test for some rings where the double bond is broken */ public void testCycloOctan() throws Exception { String filename = "data/mdl/cyclooctan.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.createSMILES(mol1); assertEquals(moleculeSmile, "C1=CCCCCCC1"); } /** * A unit test for JUnit */ public void testCycloOcten() throws Exception { String filename = "data/mdl/cycloocten.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.createSMILES(mol1); assertEquals(moleculeSmile, "C1C=CCCCCC1"); } /** * A unit test for JUnit */ public void testCycloOctadien() throws Exception { String filename = "data/mdl/cyclooctadien.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.createSMILES(mol1); assertEquals(moleculeSmile, "C=1CCC=CCCC=1"); } /** * @cdk.bug 1089770 */ public void testSFBug1089770_1() throws Exception { String filename = "data/mdl/bug1089770-1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.createSMILES(mol1); //logger.debug(filename + " -> " + moleculeSmile); assertEquals(moleculeSmile, "C1CCC=2CCCC=2(C1)"); } /** * @cdk.bug 1089770 */ public void testSFBug1089770_2() throws Exception { String filename = "data/mdl/bug1089770-2.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile = sg.createSMILES(mol1); //logger.debug(filename + " -> " + moleculeSmile); assertEquals(moleculeSmile, "C=1CCC=CCCC=1"); } /** * @cdk.bug 1014344 */ public void testSFBug1014344() throws Exception { String filename = "data/mdl/bug1014344-1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); Molecule mol1 = (Molecule) reader.read(new Molecule()); new HydrogenAdder().addImplicitHydrogensToSatisfyValency(mol1); SmilesGenerator sg = new SmilesGenerator(); String molSmiles = sg.createSMILES(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); new HydrogenAdder().addImplicitHydrogensToSatisfyValency(mol2); String cmlSmiles = sg.createSMILES(new Molecule(mol2)); assertEquals(molSmiles,cmlSmiles); } /** * @cdk.bug 1014344 */ public void testTest() throws Exception { String filename_cml = "data/mdl/9554.mol"; String filename_mol = "data/mdl/9553.mol"; InputStream ins1 = this.getClass().getClassLoader().getResourceAsStream(filename_cml); InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename_mol); MDLReader reader1 = new MDLReader(ins1); Molecule mol1 = (Molecule) reader1.read(new Molecule()); new HydrogenAdder().addExplicitHydrogensToSatisfyValency(mol1); StructureDiagramGenerator sdg=new StructureDiagramGenerator(mol1); sdg.generateCoordinates(); MDLReader reader2 = new MDLReader(ins2); Molecule mol2 = (Molecule) reader2.read(new Molecule()); new HydrogenAdder().addExplicitHydrogensToSatisfyValency(mol2); sdg=new StructureDiagramGenerator(mol2); sdg.generateCoordinates(); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile1 = sg.createChiralSMILES(mol1, new boolean[mol1.getBondCount()]); String moleculeSmile2 = sg.createChiralSMILES(mol2, new boolean[mol2.getBondCount()]); assertFalse(moleculeSmile1.equals(moleculeSmile2)); } /** * @cdk.bug 1014344 */ 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); IMolecule mol1 = model.getMoleculeSet().getMolecule(0); MDLReader reader2 = new MDLReader(ins2); Molecule mol2 = (Molecule) reader2.read(new Molecule()); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile1 = sg.createSMILES(mol1);// logger.debug(filename_cml + " -> " + moleculeSmile1); String moleculeSmile2 = sg.createSMILES(mol2);// logger.debug(filename_mol + " -> " + moleculeSmile2); assertEquals(moleculeSmile1, moleculeSmile2); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -