private String writeToStr(IAtomContainer mol) throws IOException, CDKException { StringWriter sw = new StringWriter(); try (MDLV3000Writer mdlw = new MDLV3000Writer(sw)) { mdlw.write(mol); } return sw.toString(); }
/** * Create a new V3000 writer, output to the provided JDK output stream. * * @param out output location */ public MDLV3000Writer(OutputStream out) throws CDKException { this.setWriter(out); }
writeHeader(mol); List<Sgroup> sgroups = getSgroups(mol); IAtom[] atoms = pushHydrogensToBack(mol, idxs); writeAtomBlock(mol, atoms, idxs, atomToStereo); writeBondBlock(mol, idxs); writeSgroupBlock(sgroups, idxs);
if (mol.getAtomCount() == 0) return; final int dim = getNumberOfDimensions(mol); writer.write("BEGIN ATOM\n"); int atomIdx = 0; for (IAtom atom : atoms) { final int elem = nullAsZero(atom.getAtomicNumber()); final int chg = nullAsZero(atom.getFormalCharge()); final int mass = nullAsZero(atom.getMassNumber()); final int hcnt = nullAsZero(atom.getImplicitHydrogenCount()); final int elec = mol.getConnectedSingleElectronsCount(atom); int rad = 0; String symbol = getSymbol(atom, elem); writer.write(nullAsZero(atom.getProperty(ATOM_ATOM_MAPPING, Integer.class))); switch (getLocalParity(idxs, stereo)) { case CLOCKWISE: writer.write(" CFG=1");
private void initIOSettings() { paramWriteData = addSetting(new BooleanIOSetting("writeProperties", IOSetting.Importance.LOW, "Should molecule properties be written as non-structural data", "true")); paramWriteV3000 = addSetting(new BooleanIOSetting("writeV3000", IOSetting.Importance.LOW, "Write all records as V3000", "false")); addSettings(new MDLV2000Writer().getSettings()); addSettings(new MDLV3000Writer().getSettings()); }
mdlWriter = new MDLV3000Writer(stringWriter); else mdlWriter = new MDLV2000Writer(stringWriter);
final int dim = getNumberOfDimensions(mol); if (dim != 0) { writer.writeDirect(Integer.toString(dim));
if (beg == null || end == null) throw new IllegalStateException("Bond " + bondIdx + " had one or more atoms."); int begIdx = findIdx(idxs, beg); int endIdx = findIdx(idxs, end); if (begIdx < 0 || endIdx < 0) throw new IllegalStateException("Bond " + bondIdx + " had atoms not present in the molecule.");
@Test public void writeDimensionField() throws Exception { IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance(); IAtomContainer mol = builder.newAtomContainer(); IAtom atom = builder.newAtom(); atom.setSymbol("C"); atom.setImplicitHydrogenCount(4); atom.setPoint2d(new Point2d(0.5, 0.5)); mol.addAtom(atom); StringWriter sw = new StringWriter(); try (MDLV3000Writer mdlw = new MDLV3000Writer(sw)) { mdlw.write(mol); } assertThat(sw.toString(), containsString("2D")); }
/** * {@inheritDoc} */ @Override public void setWriter(OutputStream writer) throws CDKException { setWriter(new OutputStreamWriter(writer, StandardCharsets.UTF_8)); }
@Test public void writeDimensionField3D() throws Exception { IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance(); IAtomContainer mol = builder.newAtomContainer(); IAtom atom = builder.newAtom(); atom.setSymbol("C"); atom.setImplicitHydrogenCount(4); atom.setPoint3d(new Point3d(0.5, 0.5, 0.1)); mol.addAtom(atom); StringWriter sw = new StringWriter(); try (MDLV3000Writer mdlw = new MDLV3000Writer(sw)) { mdlw.write(mol); } assertThat(sw.toString(), containsString("3D")); }