📄 smilesparsertest.java
字号:
apinene.addBond(0, 6, 1.0); // 7 apinene.addBond(3, 7, 1.0); // 8 apinene.addBond(5, 7, 1.0); // 9 apinene.addBond(7, 8, 1.0); // 10 apinene.addBond(7, 9, 1.0); // 11 IsomorphismTester it = new IsomorphismTester(apinene); assertTrue(it.isIsomorphic(mol)); } /** * A unit test for JUnit */ public void testReadingOfTwoCharElements() throws Exception { String smiles = "[Na]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); assertEquals("Na", mol.getAtom(0).getSymbol()); } public void testReadingOfOneCharElements() throws Exception { String smiles = "[K]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); assertEquals("K", mol.getAtom(0).getSymbol()); } /** * A unit test for JUnit */ public void testOrganicSubsetUnderstanding() throws Exception { String smiles = "[Ni]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); assertEquals("Ni", mol.getAtom(0).getSymbol()); smiles = "Ni"; mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals("N", mol.getAtom(0).getSymbol()); assertEquals("I", mol.getAtom(1).getSymbol()); } /** * A unit test for JUnit */ public void testMassNumberReading() throws Exception { String smiles = "[13C]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); assertEquals("C", mol.getAtom(0).getSymbol()); assertEquals(13, mol.getAtom(0).getMassNumber()); } /** * A unit test for JUnit */ public void testFormalChargeReading() throws Exception { String smiles = "[OH-]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); assertEquals("O", mol.getAtom(0).getSymbol()); assertEquals(-1, mol.getAtom(0).getFormalCharge()); } /** * A unit test for JUnit */ public void testReadingPartionedMolecules() throws Exception { String smiles = "[Na+].[OH-]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals(0, mol.getBondCount()); } /** * A unit test for JUnit */ public void testExplicitSingleBond() throws Exception { String smiles = "C-C"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); assertEquals(1.0, mol.getBond(0).getOrder(), 0.0001); } /** * @cdk.bug 1175478 */ public void testSFBug1175478() throws Exception { String smiles = "c1cc-2c(cc1)C(c3c4c2onc4c(cc3N5CCCC5)N6CCCC6)=O"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(27, mol.getAtomCount()); assertEquals(32, mol.getBondCount()); } /** * A unit test for JUnit */ public void testUnkownAtomType() throws Exception { String smiles = "*C"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); assertTrue(mol.getAtom(0) instanceof IPseudoAtom); assertFalse(mol.getAtom(1) instanceof IPseudoAtom); smiles = "[*]C"; mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); assertTrue(mol.getAtom(0) instanceof IPseudoAtom); assertFalse(mol.getAtom(1) instanceof IPseudoAtom); } /** * A unit test for JUnit */ public void testBondCreation() throws Exception { String smiles = "CC"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); smiles = "cc"; mol = sp.parseSmiles(smiles); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); } /** * @cdk.bug 784433 */ public void testSFBug784433() throws Exception { String smiles = "c1cScc1"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(5, mol.getAtomCount()); assertEquals(5, mol.getBondCount()); } /** * @cdk.bug 873783. */ public void testProton() throws Exception { String smiles = "[H+]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); assertEquals(1, mol.getAtom(0).getFormalCharge()); } /** * @cdk.bug 881330. */ public void testSMILESFromXYZ() throws Exception { String smiles = "C.C.N.[Co].C.C.C.[H].[He].[H].[H].[H].[H].C.C.[H].[H].[H].[H].[H]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(20, mol.getAtomCount()); } /** * A unit test for JUnit */ public void testSingleBracketH() throws Exception { String smiles = "[H]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(1, mol.getAtomCount()); } /** * A unit test for JUnit */ public void testSingleH() { try { String smiles = "H"; sp.parseSmiles(smiles); fail("The SMILES string 'H' is not valid: H is not in the organic element subset"); } catch (Exception e) { // yes! it should fail } } /** * @cdk.bug 862930. */ public void testHydroxonium() throws Exception { String smiles = "[H][O+]([H])[H]"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(4, mol.getAtomCount()); } /** * @cdk.bug 809412 */ public void testSFBug809412() throws Exception { String smiles = "Nc4cc3[n+](c2c(c1c(cccc1)cc2)nc3c5c4cccc5)c6c7c(ccc6)cccc7"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(33, mol.getAtomCount()); } /** * A bug found with JCP. * * @cdk.bug 956926 */ public void testSFBug956926() throws Exception { String smiles = "[c+]1ccccc1"; // C6H5+, phenyl cation IMolecule mol = sp.parseSmiles(smiles); assertEquals(6, mol.getAtomCount()); // it's a bit hard to detect three double bonds in the phenyl ring // but I do can check the total order in the whole molecule double totalBondOrder = 0.0; Iterator bonds = mol.bonds(); while (bonds.hasNext()) totalBondOrder += ((IBond)bonds.next()).getOrder(); assertEquals(9.0, totalBondOrder, 0.001); // I can also check wether all carbons have exact two neighbors for (int i = 0; i < mol.getAtomCount(); i++) { assertEquals(2, mol.getConnectedAtomsCount(mol.getAtom(i))); } // and the number of implicit hydrogens int hCount = 0; for (int i = 0; i < mol.getAtomCount(); i++) { hCount += mol.getAtom(i).getHydrogenCount(); } assertEquals(5, hCount); } /** * A bug found with JCP. * * @cdk.bug 956929 */ public void testPyrole() throws Exception { String smiles = "c1cccn1"; IMolecule mol = sp.parseSmiles(smiles); StructureDiagramGenerator sdg=new StructureDiagramGenerator(mol); sdg.generateCoordinates(); /*MoleculeViewer2D v2d=new MoleculeViewer2D(mol); v2d.display(); Thread.sleep(100000);*/ for(int i=0;i<mol.getAtomCount();i++){ if(mol.getAtom(i).getSymbol().equals("N")){ assertEquals(1,((IBond)mol.getConnectedBondsList(mol.getAtom(i)).get(0)).getOrder(),.1); assertEquals(1,((IBond)mol.getConnectedBondsList(mol.getAtom(i)).get(1)).getOrder(),.1); } } } /** * A bug found with JCP. * * @cdk.bug 956929 */ public void testSFBug956929() throws Exception { String smiles = "Cn1cccc1"; IMolecule mol = sp.parseSmiles(smiles); StructureDiagramGenerator sdg=new StructureDiagramGenerator(mol); sdg.generateCoordinates(); assertEquals(6, mol.getAtomCount()); // it's a bit hard to detect two double bonds in the pyrrole ring // but I do can check the total order in the whole molecule double totalBondOrder = 0.0; Iterator bonds = mol.bonds(); while (bonds.hasNext()) totalBondOrder += ((IBond)bonds.next()).getOrder(); assertEquals(8.0, totalBondOrder, 0.001); // I can also check wether the total neighbor count around the // nitrogen is 3, all single bonded org.openscience.cdk.interfaces.IAtom nitrogen = mol.getAtom(1); // the second atom assertEquals("N", nitrogen.getSymbol()); totalBondOrder = 0.0; List bondsList = mol.getConnectedBondsList(nitrogen); assertEquals(3, bondsList.size()); for (int i = 0; i < bondsList.size(); i++) { totalBondOrder += ((IBond)bondsList.get(i)).getOrder(); } assertEquals(3.0, totalBondOrder, 0.001); } /** * A bug found with JCP. * * @cdk.bug 956921 */ public void testSFBug956921() throws Exception { String smiles = "[cH-]1cccc1"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(5, mol.getAtomCount()); // each atom should have 1 implicit hydrogen, and two neighbors java.util.Iterator atoms = mol.atoms(); while (atoms.hasNext()) { IAtom atomi = (IAtom)atoms.next(); assertEquals(1, atomi.getHydrogenCount()); assertEquals(2, mol.getConnectedAtomsCount(atomi)); } // and the first atom should have a negative charge assertEquals(-1, mol.getAtom(0).getFormalCharge()); } /** * @cdk.bug 1095696 */ public void testSFBug1095696() throws Exception { String smiles = "Nc1ncnc2[nH]cnc12"; IMolecule mol = sp.parseSmiles(smiles); assertEquals(10, mol.getAtomCount()); assertEquals("N", mol.getAtom(6).getSymbol()); assertEquals(1, mol.getAtom(6).getHydrogenCount()); } /** * Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 89 * (Part I). */ public void testNonBond() throws Exception { String sodiumPhenoxide = "c1cc([O-].[Na+])ccc1";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -