@Override public IChemObject newTestObject() { return new AtomContainerSet(); } });
@Override public void startDocument() { chemFile = new ChemFile(); chemSequence = new ChemSequence(); chemModel = new ChemModel(); setOfMolecules = new AtomContainerSet(); }
@BeforeClass public static void setUp() { setTestObjectBuilder(new ITestObjectBuilder() { @Override public IChemObject newTestObject() { return new AtomContainerSet(); } }); }
@Test public void testExampleFile_SupportColumns() throws Exception { String filename = "data/moss/TKO.mossoutput"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MoSSOutputReader reader = new MoSSOutputReader(ins); IAtomContainerSet moleculeSet = new AtomContainerSet(); moleculeSet = reader.read(moleculeSet); Assert.assertEquals(5.06, Double .valueOf(moleculeSet.getAtomContainer(0).getProperty("focusSupport").toString()).doubleValue(), 0.01); Assert.assertEquals(1.74, Double.valueOf(moleculeSet.getAtomContainer(0).getProperty("complementSupport").toString()) .doubleValue(), 0.01); }
@Test public void testReadingSmiFile_1() throws Exception { String filename = "data/smiles/smiles.smi"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); SMILESReader reader = new SMILESReader(ins); IAtomContainerSet som = reader.read(new AtomContainerSet()); String name = null; IAtomContainer thisMol = som.getAtomContainer(0); name = ((String) thisMol.getProperty("SMIdbNAME")).toString(); Assert.assertEquals("benzene", name); }
@Test public void testReading() throws Exception { String filename = "data/smiles/smiles.smi"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); SMILESReader reader = new SMILESReader(ins); IAtomContainerSet som = reader.read(new AtomContainerSet()); Assert.assertEquals(8, som.getAtomContainerCount()); }
@Test public void testReadingSmiFile_3() throws Exception { String filename = "data/smiles/test3.smi"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); SMILESReader reader = new SMILESReader(ins); IAtomContainerSet som = reader.read(new AtomContainerSet()); Assert.assertEquals(5, som.getAtomContainerCount()); }
@Test public void testExampleFile_MolReading() throws Exception { String filename = "data/moss/TKO.mossoutput"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MoSSOutputReader reader = new MoSSOutputReader(ins); IAtomContainerSet moleculeSet = new AtomContainerSet(); moleculeSet = reader.read(moleculeSet); Assert.assertEquals(19, moleculeSet.getAtomContainerCount()); for (IAtomContainer mol : moleculeSet.atomContainers()) { Assert.assertEquals(Integer.valueOf(mol.getProperty("atomCount").toString()).intValue(), mol.getAtomCount()); Assert.assertEquals(Integer.valueOf(mol.getProperty("bondCount").toString()).intValue(), mol.getBondCount()); } }
@Test public void testReadingSmiFile_2() throws Exception { String filename = "data/smiles/smiles.smi"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); SMILESReader reader = new SMILESReader(ins); IAtomContainerSet som = reader.read(new AtomContainerSet()); IAtomContainer thisMol = som.getAtomContainer(1); Assert.assertNull(thisMol.getProperty("SMIdbNAME")); }
@Test public void testAtomContainerSet() { IAtomContainerSet som = new AtomContainerSet(); Assert.assertNotNull(som); Assert.assertEquals(0, som.getAtomContainerCount()); }
@Test public void testWrite_IAtomContainerSet_SingleMolecule() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.write(molSet); sdfWriter.close(); Assert.assertTrue(writer.toString().indexOf("$$$$") != -1); }
@Test public void testWrite_IAtomContainerSet_Properties() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molecule.setProperty("foo", "bar"); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.write(molSet); sdfWriter.close(); Assert.assertTrue(writer.toString().indexOf("<foo>") != -1); Assert.assertTrue(writer.toString().indexOf("bar") != -1); }
@Test public void testWrite_IAtomContainerSet_CDKProperties() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molecule.setProperty(InvPair.CANONICAL_LABEL, "bar"); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.write(molSet); sdfWriter.close(); Assert.assertTrue(writer.toString().indexOf(InvPair.CANONICAL_LABEL) == -1); }
@Test public void testWrite_IAtomContainerSet_Properties_Off() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molecule.setProperty("foo", "bar"); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); Properties sdfWriterProps = new Properties(); sdfWriterProps.put("writeProperties", "false"); sdfWriter.addChemObjectIOListener(new PropertiesListener(sdfWriterProps)); sdfWriter.customizeJob(); sdfWriter.write(molSet); sdfWriter.close(); String result = writer.toString(); Assert.assertFalse(result.contains("<foo>")); }
@Test public void testWrite_IAtomContainerSet_MultIAtomContainer() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molSet.addAtomContainer(molecule); molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.write(molSet); sdfWriter.close(); Assert.assertTrue(writer.toString().indexOf("$$$$") != -1); }
@Test public void testMoleculeSet() throws Exception { IAtomContainerSet list = new AtomContainerSet(); list.addAtomContainer(new AtomContainer()); list.addAtomContainer(new AtomContainer()); IChemModel model = new ChemModel(); model.setMoleculeSet(list); IChemModel roundTripped = CMLRoundTripTool.roundTripChemModel(convertor, model); IAtomContainerSet newList = roundTripped.getMoleculeSet(); Assert.assertNotNull(newList); Assert.assertEquals(2, newList.getAtomContainerCount()); Assert.assertNotNull(newList.getAtomContainer(0)); Assert.assertNotNull(newList.getAtomContainer(1)); }
@Test public void testRemoveElectronContainer_IAtomContainerSet_IElectronContainer() { IAtomContainerSet ms = new AtomContainerSet(); IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, IBond.Order.DOUBLE); IBond bond = mol.getBond(0); ms.addAtomContainer(mol); IBond otherBond = new Bond(new Atom(), new Atom()); AtomContainerSetManipulator.removeElectronContainer(ms, otherBond); Assert.assertEquals(1, AtomContainerSetManipulator.getBondCount(ms)); AtomContainerSetManipulator.removeElectronContainer(ms, bond); Assert.assertEquals(0, AtomContainerSetManipulator.getBondCount(ms)); }
@Test public void testRemoveElectronContainer_IAtomContainerSet_IElectronContainer() { IAtomContainerSet ms = new AtomContainerSet(); IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, IBond.Order.DOUBLE); IBond bond = mol.getBond(0); ms.addAtomContainer(mol); IBond otherBond = new Bond(new Atom(), new Atom()); MoleculeSetManipulator.removeElectronContainer(ms, otherBond); Assert.assertEquals(1, MoleculeSetManipulator.getBondCount(ms)); MoleculeSetManipulator.removeElectronContainer(ms, bond); Assert.assertEquals(0, MoleculeSetManipulator.getBondCount(ms)); }
@Test public void testRemoveAtomAndConnectedElectronContainers_IAtomContainerSet_IAtom() { IAtomContainerSet ms = new AtomContainerSet(); IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, IBond.Order.DOUBLE); IAtom atom = mol.getAtom(0); ms.addAtomContainer(mol); IAtom otherAtom = new Atom("O"); MoleculeSetManipulator.removeAtomAndConnectedElectronContainers(ms, otherAtom); Assert.assertEquals(1, MoleculeSetManipulator.getBondCount(ms)); Assert.assertEquals(2, MoleculeSetManipulator.getAtomCount(ms)); MoleculeSetManipulator.removeAtomAndConnectedElectronContainers(ms, atom); Assert.assertEquals(0, MoleculeSetManipulator.getBondCount(ms)); Assert.assertEquals(1, MoleculeSetManipulator.getAtomCount(ms)); }
@Test public void testRemoveAtomAndConnectedElectronContainers_IAtomContainerSet_IAtom() { IAtomContainerSet ms = new AtomContainerSet(); IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("O")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, IBond.Order.DOUBLE); IAtom atom = mol.getAtom(0); ms.addAtomContainer(mol); IAtom otherAtom = new Atom("O"); AtomContainerSetManipulator.removeAtomAndConnectedElectronContainers(ms, otherAtom); Assert.assertEquals(1, AtomContainerSetManipulator.getBondCount(ms)); Assert.assertEquals(2, AtomContainerSetManipulator.getAtomCount(ms)); AtomContainerSetManipulator.removeAtomAndConnectedElectronContainers(ms, atom); Assert.assertEquals(0, AtomContainerSetManipulator.getBondCount(ms)); Assert.assertEquals(1, AtomContainerSetManipulator.getAtomCount(ms)); }