Mopac7Writer extends DefaultChemObjectWriter { @Override public synchronized void write(IChemObject arg0) throws CDKException { customizeJob(); if (arg0 instanceof IAtomContainer) try { IAtomContainer container = (IAtomContainer) arg0; writer.write(mopacCommands.getSetting()); int formalCharge = AtomContainerManipulator.getTotalFormalCharge(container); if (formalCharge != 0) writer.write(" CHARGE=" + formalCharge); writer.write('\n'); if (container.getProperty("Names") != null) writer.write(container.getProperty("Names").toString()); writer.write('\n'); writer.write(getTitle()); writer.write('\n'); for (int i = 0; i < container.getAtomCount(); i++) { IAtom atom = container.getAtom(i); if (atom.getPoint3d() != null) { Point3d point = atom.getPoint3d(); writeAtom(atom, point.x, point.y, point.z, optimize.isSet() ? 1 : 0); } else if (atom.getPoint2d() != null) { Point2d point = atom.getPoint2d(); writeAtom(atom, point.x, point.y, 0, optimize.isSet() ? 1 : 0); } else writeAtom(atom, 0, 0, 0, 1); } writer.write("0"); writer.write('\n'); } catch (IOException ioException) { logger.error(ioException); throw new CDKException(ioException.getMessage(), ioException); } else throw new CDKException("Unsupported object!\t" + arg0.getClass().getName()); } Mopac7Writer();  Mopac7Writer(OutputStream out);  Mopac7Writer(Writer out); @Override synchronized void write(IChemObject arg0); @Override /** {@inheritDoc} */ void close(); @Override /** {@inheritDoc} */ boolean accepts(Class<? extends IChemObject> classObject); @Override /** {@inheritDoc} */ IResourceFormat getFormat(); @Override /** {@inheritDoc} */ void setWriter(OutputStream writer); @Override /** {@inheritDoc} */ void setWriter(Writer writer);  }
@Test public void testWrite() throws Exception { StringWriter strWriter = new StringWriter(); Mopac7Writer writer = new Mopac7Writer(strWriter); IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("Cr")); writer.write(mol); writer.close(); Assert.assertTrue(strWriter.toString().contains("PM3")); Assert.assertTrue(strWriter.toString().contains("Cr ")); Assert.assertTrue(strWriter.toString().contains("Generated by")); }