⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smilesgeneratortest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		try		{			smiles1 = sg.createSMILES(mol1, true, bool);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		if (standAlone)		{			System.err.println("SMILES 1: " + smiles1);		}		assertNotNull(smiles1);		assertTrue(smiles1.equals("F/C(=C/(F)S)S"));		mol1.getAtom(4).setPoint2d(new Point2d(0, 3));		mol1.getAtom(5).setPoint2d(new Point2d(2, 3));		try		{			smiles1 = sg.createSMILES(mol1, true, bool);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		if (standAlone)		{			System.err.println("SMILES 1: " + smiles1);		}		assertNotNull(smiles1);		assertTrue(smiles1.equals("F/C(=C\\(F)S)S"));		try		{			new HydrogenAdder().addHydrogensToSatisfyValency(mol1);			hydrogenPlacer.placeHydrogens2D(mol1, 1.0);		} catch (IOException ex)		{		} catch (ClassNotFoundException ex)		{		}		bool = new boolean[mol1.getBondCount()];		bool[2] = true;		try		{			smiles1 = sg.createSMILES(mol1, true, bool);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		assertTrue(smiles1.equals("[H]S/C(F)=C/(F)S[H]"));		mol1.getAtom(5).setPoint2d(new Point2d(0, 3));		mol1.getAtom(4).setPoint2d(new Point2d(2, 3));		try		{			smiles1 = sg.createSMILES(mol1, true, bool);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		assertTrue(smiles1.equals("[H]S/C(F)=C\\(F)S[H]"));	}	/**	 *  A unit test for JUnit	 */	public void testPartitioning()	{		String smiles = "";		Molecule molecule = new Molecule();        SmilesGenerator sg = new SmilesGenerator();		Atom sodium = new Atom("Na");		sodium.setFormalCharge(+1);		Atom hydroxyl = new Atom("O");		hydroxyl.setHydrogenCount(1);		hydroxyl.setFormalCharge(-1);		molecule.addAtom(sodium);		molecule.addAtom(hydroxyl);		try		{			smiles = sg.createSMILES(molecule);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		if (standAlone)		{			System.err.println("SMILES: " + smiles);		}		assertTrue(smiles.indexOf(".") != -1);	}	/**	 *  A unit test for JUnit	 */	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);		try		{			smiles = sg.createSMILES(molecule);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		if (standAlone)		{			System.err.println("SMILES: " + smiles);		}		assertEquals("N1(C)CCC1", smiles);	}	/**	 *  A bug reported for JChemPaint.	 */	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);		try		{			smiles = sg.createSMILES(molecule);		} catch (Exception exc)		{			fail(exc.getMessage());		}		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());			}			if (standAlone)			{				System.out.println("Hydrogen count for atom " + f + ": " + atom.getHydrogenCount());			}		}	}	/**	 *  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);		try		{			smiles = sg.createSMILES(molecule);		} catch (Exception exc)		{			System.out.println(exc);			if (!standAlone)			{				fail();			}		}		if (standAlone)		{			System.err.println("SMILES: " + smiles);		}		assertEquals("[*]", smiles);	}	/**	 *  Test generation of a reaction SMILES. I know, it's a stupid alchemic	 *  reaction, but it serves its purpose.	 */	public void testReactionSMILES()	{		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();		try		{			String smiles = sg.createSMILES(reaction);			//logger.debug("Generated SMILES: " + smiles);			assertEquals("C>[*]>[Au]", smiles);		} catch (Exception exc)		{			System.out.println(exc);		}	}	/**	 *  Test generation of a d and l alanin	 */	public void testAlaSMILES()	{		try		{			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]);			assertFalse(smiles1.equals(smiles2));		} catch (Exception exc)		{			System.out.println(exc);		}	}	/**	 *  Test some sugars	 */	public void testSugarSMILES()	{		try		{			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 HydrogenAdder().addExplicitHydrogensToSatisfyValency(mol1);			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 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]);			assertFalse(smiles1.equals(smiles2));		} catch (Exception exc)		{			System.out.println(exc);		}	}	private void display(Molecule molecule)	{		StructureDiagramGenerator sdg = new StructureDiagramGenerator();		MoleculeViewer2D mv = new MoleculeViewer2D();		Renderer2DModel r2dm = mv.getRenderer2DModel();		r2dm.setDrawNumbers(true);		try		{			sdg.setMolecule((Molecule) molecule.clone());			sdg.generateCoordinates(new Vector2d(0, 1));			mv.setAtomContainer(sdg.getMolecule());			mv.display();		} catch (Exception exc)		{			System.out.println("*** Exit due to an unexpected error during coordinate generation ***");			exc.printStackTrace();		}	}	/**	 *  Test for some rings where the double bond is broken	 */	public void testCycloOctan()	{		try		{			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");		} catch (Exception exc)		{			exc.printStackTrace();			System.out.println(exc);			fail(exc.getMessage());		}	}	/**	 *  A unit test for JUnit	 */	public void testCycloOcten()	{		try		{			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");		} catch (Exception exc)		{			exc.printStackTrace();			System.out.println(exc);			fail(exc.getMessage());		}	}	/**	 *  A unit test for JUnit	 */	public void testCycloOctadien()	{		try		{			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");		} catch (Exception exc)		{			exc.printStackTrace();			System.out.println(exc);			fail(exc.getMessage());		}	}	/**	 *  A unit test for JUnit	 */	public void testSFBug1089770_1()	{		try		{			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)");		} catch (Exception exc)		{			exc.printStackTrace();			System.out.println(exc);			fail(exc.getMessage());		}	}	/**	 *  A unit test for JUnit	 */	public void testSFBug1089770_2()	{		try		{			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");		} catch (Exception exc)		{			exc.printStackTrace();			System.out.println(exc);			fail(exc.getMessage());		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -