/** * Write a char number to the output, wrapping if needed. * * @param c char * @return self-reference for chaining. * @throws IOException low-level IO error */ V30LineWriter write(char c) throws IOException { if (c == '\n' && currLength == PREFIX.length()) return this; if (c != '\n') newLineIfNeeded(); writePrefixIfNeeded(); this.writer.write(c); currLength++; if (c == '\n') currLength = 0; return this; }
/** * Write chemobject index list, mainly useful for Sgroup output. * * @param chemObjects collection of chemobjects * @param idxs index map * @return self-reference for chaining. * @throws IOException low-level IO error */ V30LineWriter write(Collection<? extends IChemObject> chemObjects, Map<IChemObject, Integer> idxs) throws IOException { this.write(chemObjects.size()); List<Integer> integers = new ArrayList<>(); for (IChemObject chemObject : chemObjects) integers.add(idxs.get(chemObject)); Collections.sort(integers); for (Integer integer : integers) this.write(' ').write(integer); return this; }
final String title = mol.getTitle(); if (title != null) writer.writeDirect(title.substring(0, Math.min(80, title.length()))); writer.writeDirect('\n'); writer.writeDirect(" CDK "); writer.writeDirect(HEADER_DATE_FORMAT.format(System.currentTimeMillis())); final int dim = getNumberOfDimensions(mol); if (dim != 0) { writer.writeDirect(Integer.toString(dim)); writer.writeDirect('D'); writer.writeDirect('\n'); writer.writeDirect(comment.substring(0, Math.min(80, comment.length()))); writer.writeDirect('\n'); writer.writeDirect(" 0 0 0 0 0 999 V3000\n");
writer.write("BEGIN SGROUP\n"); for (Sgroup sgroup : sgroups) { final SgroupType type = sgroup.getType(); writer.write(++sgroupIdx).write(' ').write(type.getKey()).write(" 0"); writer.write(" ATOMS=(") .write(sgroup.getAtoms(), idxs) .write(")"); writer.write(" CBONDS=("); // containment bonds } else { writer.write(" XBONDS=("); // crossing bonds writer.write(sgroup.getBonds(), idxs); writer.write(")"); if (parents.size() > 1) throw new CDKException("Cannot write Sgroup with multiple parents"); writer.write(" PARENT=").write(1+sgroups.indexOf(parents.iterator().next())); switch (key) { case CtabSubType: writer.write(" SUBTYPE=").write(sgroup.getValue(key).toString()); break; case CtabConnectivity: writer.write(" CONNECT=").write(sgroup.getValue(key).toString().toUpperCase(Locale.ROOT)); break; case CtabSubScript:
return; final int dim = getNumberOfDimensions(mol); writer.write("BEGIN ATOM\n"); int atomIdx = 0; for (IAtom atom : atoms) { writer.write(++atomIdx) .write(' ') .write(symbol) .write(' '); switch (dim) { case 0: writer.write("0 0 0 "); break; case 2: if (p2d != null) { writer.write(p2d.x).writeDirect(' ') .write(p2d.y).writeDirect(' ') .write("0 "); } else { writer.write("0 0 0 "); writer.write(p3d.x).writeDirect(' ') .write(p3d.y).writeDirect(' ') .write(p3d.z).writeDirect(' '); } else { writer.write("0 0 0 ");
writer.write("BEGIN BOND\n"); int bondIdx = 0; for (IBond bond : mol.bonds()) { writer.write(++bondIdx) .write(' ') .write(order) .write(' ') .write(begIdx) .write(' ') .write(endIdx); case UP: case UP_INVERTED: writer.write(" CFG=1"); break; case UP_OR_DOWN: case UP_OR_DOWN_INVERTED: writer.write(" CFG=2"); break; case DOWN: case DOWN_INVERTED: writer.write(" CFG=3"); break; case NONE: atoms.remove(bond.getBegin()); atoms.remove(bond.getEnd()); writer.write(" ATTACH=ANY ENDPTS=(").write(atoms, idxs).write(')');
/** * Write a string to the output, wrapping if needed. * * @param str value * @return self-reference for chaining. * @throws IOException low-level IO error */ V30LineWriter write(String str) throws IOException { int i = str.indexOf('\n'); if (i < 0) { writeUnbroken(str); } else if (i == str.length() - 1) { writeUnbroken(str); currLength = 0; } else { throw new UnsupportedOperationException(); } return this; }
private void writeUnbroken(String str) throws IOException { newLineIfNeeded(); writePrefixIfNeeded(); final int len = str.length(); if (currLength + len < LIMIT) { this.writer.write(str); currLength += len; } else { // could be more efficient but sufficient for (int i = 0; i < len; i++) write(str.charAt(i)); } }
/** * Write a int number to the output, wrapping if needed. * * @param num value * @return self-reference for chaining. * @throws IOException low-level IO error */ V30LineWriter write(int num) throws IOException { return write(Integer.toString(num)); }
/** * {@inheritDoc} */ @Override public void close() throws IOException { if (writer != null) writer.close(); }
/** * Write a floating point number to the output, wrapping * if needed. * * @param num value * @return self-reference for chaining. * @throws IOException low-level IO error */ V30LineWriter write(double num) throws IOException { return write(DECIMAL_FORMAT.format(num)); }
/** * {@inheritDoc} */ @Override public void setWriter(Writer writer) throws CDKException { this.writer = new V30LineWriter(writer); }
/** * Create a new V3000 writer, output to the provided JDK writer. * * @param writer output location */ public MDLV3000Writer(Writer writer) { this.writer = new V30LineWriter(writer); }