Writes a Molecule to an OutputStream in MDL sdf format.

@param container Molecule that is written to an OutputStream
173552
public void writeMolecule(IAtomContainer container) throws Exception {

        final int dim = getNumberOfDimensions(container);
        StringBuilder line = new StringBuilder();
        Map<Integer, Integer> rgroups = null;
        Map<Integer, String> aliases = null;
        // write header block
        // lines get shortened to 80 chars, that's in the spec
        String title = container.getTitle();
        if (title == null) title = "";
        if (title.length() > 80) title = title.substring(0, 80);
        writer.write(title);
        writer.write('\n');

        /*
         * From CTX spec This line has the format:
         * IIPPPPPPPPMMDDYYHHmmddSSssssssssssEEEEEEEEEEEERRRRRR (FORTRAN:
         * A2<--A8--><---A10-->A2I2<--F10.5-><---F12.5--><-I6-> ) User's first
         * and last initials (l), program name (P), date/time (M/D/Y,H:m),
         * dimensional codes (d), scaling factors (S, s), energy (E) if modeling
         * program input, internal registry number (R) if input through MDL
         * form. A blank line can be substituted for line 2.
         */
        writer.write("  ");
        writer.write(getProgName());
        writer.write(new SimpleDateFormat("MMddyyHHmm").format(System.currentTimeMillis()));
        if (dim != 0) {
            writer.write(Integer.toString(dim));
            writer.write('D');
        }
        writer.write('\n');

        String comment = (String) container.getProperty(CDKConstants.REMARK);
        if (comment == null) comment = "";
        if (comment.length() > 80) comment = comment.substring(0, 80);
        writer.write(comment);
        writer.write('\n');

        // index stereo elements for setting atom parity values
        Map<IAtom,ITetrahedralChirality> atomstereo = new HashMap<>();
        Map<IAtom,Integer> atomindex = new HashMap<>();
        for (IStereoElement element : container.stereoElements())
            if (element instanceof ITetrahedralChirality)
                atomstereo.put(((ITetrahedralChirality) element).getChiralAtom(), (ITetrahedralChirality) element);
        for (IAtom atom : container.atoms())
            atomindex.put(atom, atomindex.size());

        // write Counts line
        line.append(formatMDLInt(container.getAtomCount(), 3));
        line.append(formatMDLInt(container.getBondCount(), 3));
        line.append("  0  0");
        // we mark all stereochemistry to absolute for now
        line.append(atomstereo.isEmpty() ? "  0" : "  1");
        line.append("  0  0  0  0  0999 V2000");
        writer.write(line.toString());
        writer.write('\n');

        // write Atom block
        for (int f = 0; f < container.getAtomCount(); f++) {
            IAtom atom = container.getAtom(f);
            line.setLength(0);
            switch (dim) {
                case 0:
                    // if no coordinates available, then output a number
                    // of zeros
                    line.append("    0.0000    0.0000    0.0000 ");
                    break;
                case 2:
                    if (atom.getPoint2d() != null) {
                        line.append(formatMDLFloat((float) atom.getPoint2d().x));
                        line.append(formatMDLFloat((float) atom.getPoint2d().y));
                        line.append("    0.0000 ");
                    } else {
                        line.append("    0.0000    0.0000    0.0000 ");
                    }
                    break;
                case 3:
                    if (atom.getPoint3d() != null) {
                        line.append(formatMDLFloat((float) atom.getPoint3d().x));
                        line.append(formatMDLFloat((float) atom.getPoint3d().y));
                        line.append(formatMDLFloat((float) atom.getPoint3d().z)).append(" ");
                    } else {
                        line.append("    0.0000    0.0000    0.0000 ");
                    }
                    break;
            }
            if (container.getAtom(f) instanceof IPseudoAtom) {
                //according to http://www.google.co.uk/url?sa=t&ct=res&cd=2&url=http%3A%2F%2Fwww.mdl.com%2Fdownloads%2Fpublic%2Fctfile%2Fctfile.pdf&ei=MsJjSMbjAoyq1gbmj7zCDQ&usg=AFQjCNGaJSvH4wYy4FTXIaQ5f7hjoTdBAw&sig2=eSfruNOSsdMFdlrn7nhdAw an R group is written as R#
                IPseudoAtom pseudoAtom = (IPseudoAtom) container.getAtom(f);
                String label = pseudoAtom.getLabel();
                if (label == null) // set to empty string if null
                    label = "";

                // firstly check if it's a numbered R group
                Matcher matcher = NUMERED_R_GROUP.matcher(label);
                if (pseudoAtom.getSymbol().equals("R") && !label.isEmpty() && matcher.matches()) {

                    line.append("R# ");
                    if (rgroups == null) {
                        // we use a tree map to ensure the output order is always the same
                        rgroups = new TreeMap<Integer, Integer>();
                    }
                    rgroups.put(f + 1, Integer.parseInt(matcher.group(1)));

                }
                // not a numbered R group - note the symbol may still be R
                else {

                    // note: no distinction made between alias and pseudo atoms - normally
                    //       aliases maintain their original symbol while pseudo atoms are
                    //       written with a 'A' in the atom block

                    // if the label is longer then 3 characters we need
                    // to use an alias.
                    if (label.length() > 3) {

                        if (aliases == null) aliases = new TreeMap<Integer, String>();

                        aliases.put(f + 1, label); // atom index to alias

                        line.append(formatMDLString(atom.getSymbol(), 3));

                    } else { // label is short enough to fit in the atom block

                        // make sure it's not empty
                        if (!label.isEmpty())
                            line.append(formatMDLString(label, 3));
                        else
                            line.append(formatMDLString(atom.getSymbol(), 3));

                    }
                }

            } else {
                line.append(formatMDLString(container.getAtom(f).getSymbol(), 3));
            }

            // atom properties
            int[] atomprops = new int[12];
            atomprops[0] = determineIsotope(atom);
            atomprops[1] = determineCharge(container, atom);
            atomprops[2] = determineStereoParity(container, atomstereo, atomindex, atom);
            atomprops[5] = determineValence(container, atom);
            atomprops[9] = determineAtomMap(atom);
            line.append(formatMDLInt(atomprops[0], 2)); // dd (mass-number)
            line.append(formatMDLInt(atomprops[1], 3)); // ccc (charge)
            int last = atomprops.length-1;
            if (!writeDefaultProps.isSet())
            {
                while (last >= 0) {
                    if (atomprops[last] != 0)
                        break;
                    last--;
                }
                // matches BIOVIA syntax
                if (last >= 2 && last < 5)
                    last = 5;
            }
            for (int i = 2; i <= last; i++)
                line.append(formatMDLInt(atomprops[i], 3));
            line.append('\n');
            writer.write(line.toString());
        }

        // write Bond block
        for (IBond bond : container.bonds()) {
            line.setLength(0);
            if (bond.getAtomCount() != 2) {
                logger.warn("Skipping bond with more/less than two atoms: " + bond);
            } else {
                if (bond.getStereo() == IBond.Stereo.UP_INVERTED || bond.getStereo() == IBond.Stereo.DOWN_INVERTED
                    || bond.getStereo() == IBond.Stereo.UP_OR_DOWN_INVERTED) {
                    // turn around atom coding to correct for inv stereo
                    line.append(formatMDLInt(atomindex.get(bond.getEnd()) + 1, 3));
                    line.append(formatMDLInt(atomindex.get(bond.getBegin()) + 1, 3));
                } else {
                    line.append(formatMDLInt(atomindex.get(bond.getBegin()) + 1, 3));
                    line.append(formatMDLInt(atomindex.get(bond.getEnd()) + 1, 3));
                }

                int bondType = 0;

                if (bond instanceof QueryBond) {
                    QueryBond qbond = ((QueryBond)bond);
                    Expr e = qbond.getExpression();
                    switch (e.type()) {
                        case ALIPHATIC_ORDER:
                        case ORDER:
                            bondType = e.value();
                            break;
                        case IS_AROMATIC:
                            bondType = 4;
                            break;
                        case SINGLE_OR_DOUBLE:
                            bondType = 5;
                            break;
                        case SINGLE_OR_AROMATIC:
                            bondType = 6;
                            break;
                        case DOUBLE_OR_AROMATIC:
                            bondType = 7;
                            break;
                        case TRUE:
                            bondType = 8;
                            break;
                        case OR:
                            // SINGLE_OR_DOUBLE
                            if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 1).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 2))) ||
                                e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 2).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 1))))
                                bondType = 5;
                            // SINGLE_OR_AROMATIC
                            else if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 1).or(new Expr(Expr.Type.IS_AROMATIC))) ||
                                e.equals(new Expr(Expr.Type.IS_AROMATIC).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 1))))
                                bondType = 6;
                            // DOUBLE_OR_AROMATIC
                            else if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 2).or(new Expr(Expr.Type.IS_AROMATIC))) ||
                                     e.equals(new Expr(Expr.Type.IS_AROMATIC).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 2))))
                                bondType = 6;
                            break;
                        default:
                            throw new IllegalArgumentException("Unsupported bond type!");
                    }
                } else {
                    if (bond.getOrder() != null) {
                        switch (bond.getOrder()) {
                            case SINGLE:
                            case DOUBLE:
                            case TRIPLE:
                                if (writeAromaticBondTypes.isSet() && bond.isAromatic())
                                    bondType = 4;
                                else
                                    bondType = bond.getOrder().numeric();
                                break;
                            case UNSET:
                                if (bond.isAromatic()) {
                                    if (!writeAromaticBondTypes.isSet())
                                        throw new CDKException("Bond at idx " + container.indexOf(bond) + " was an unspecific aromatic bond which should only be used for querie in Molfiles. These can be written if desired by enabling the option 'WriteAromaticBondTypes'.");
                                    bondType = 4;
                                }
                                break;
                        }
                    }
                }

                if (bondType == 0)
                    throw new CDKException("Bond at idx=" + container.indexOf(bond) + " is not supported by Molfile, bond=" + bond.getOrder());

                line.append(formatMDLInt(bondType, 3));
                line.append("  ");
                switch (bond.getStereo()) {
                    case UP:
                        line.append("1");
                        break;
                    case UP_INVERTED:
                        line.append("1");
                        break;
                    case DOWN:
                        line.append("6");
                        break;
                    case DOWN_INVERTED:
                        line.append("6");
                        break;
                    case UP_OR_DOWN:
                        line.append("4");
                        break;
                    case UP_OR_DOWN_INVERTED:
                        line.append("4");
                        break;
                    case E_OR_Z:
                        line.append("3");
                        break;
                    default:
                        line.append("0");
                }
                if (writeDefaultProps.isSet())
                    line.append("  0  0  0 ");
                line.append('\n');
                writer.write(line.toString());
            }
        }

        // Write Atom Value
        for (int i = 0; i < container.getAtomCount(); i++) {
            IAtom atom = container.getAtom(i);
            if (atom.getProperty(CDKConstants.COMMENT) != null
                && atom.getProperty(CDKConstants.COMMENT) instanceof String
                && !((String) atom.getProperty(CDKConstants.COMMENT)).trim().equals("")) {
                writer.write("V  ");
                writer.write(formatMDLInt(i + 1, 3));
                writer.write(" ");
                writer.write((String) atom.getProperty(CDKConstants.COMMENT));
                writer.write('\n');
            }
        }

        // write formal atomic charges
        for (int i = 0; i < container.getAtomCount(); i++) {
            IAtom atom = container.getAtom(i);
            Integer charge = atom.getFormalCharge();
            if (charge != null && charge != 0) {
                writer.write("M  CHG  1 ");
                writer.write(formatMDLInt(i + 1, 3));
                writer.write(" ");
                writer.write(formatMDLInt(charge, 3));
                writer.write('\n');
            }
        }

        // write radical information
        if (container.getSingleElectronCount() > 0) {
            Map<Integer, SPIN_MULTIPLICITY> atomIndexSpinMap = new LinkedHashMap<Integer, SPIN_MULTIPLICITY>();
            for (int i = 0; i < container.getAtomCount(); i++) {
                int eCount = container.getConnectedSingleElectronsCount(container.getAtom(i));
                switch (eCount) {
                    case 0:
                        continue;
                    case 1:
                        atomIndexSpinMap.put(i, SPIN_MULTIPLICITY.Monovalent);
                        break;
                    case 2:
                        // information loss, divalent but singlet or triplet?
                        atomIndexSpinMap.put(i, SPIN_MULTIPLICITY.DivalentSinglet);
                        break;
                    default:
                        logger.debug("Invalid number of radicals found: " + eCount);
                        break;
                }
            }
            Iterator<Map.Entry<Integer, SPIN_MULTIPLICITY>> iterator = atomIndexSpinMap.entrySet().iterator();
            for (int i = 0; i < atomIndexSpinMap.size(); i += NN8) {
                if (atomIndexSpinMap.size() - i <= NN8) {
                    writer.write("M  RAD" + formatMDLInt(atomIndexSpinMap.size() - i, WIDTH));
                    writeRadicalPattern(iterator, 0);
                } else {
                    writer.write("M  RAD" + formatMDLInt(NN8, WIDTH));
                    writeRadicalPattern(iterator, 0);
                }
                writer.write('\n');
            }
        }

        // write formal isotope information
        for (int i = 0; i < container.getAtomCount(); i++) {
            IAtom atom = container.getAtom(i);
            if (!(atom instanceof IPseudoAtom)) {
                Integer atomicMass = atom.getMassNumber();
                if (!writeMajorIsotopes.isSet() &&
                    isMajorIsotope(atom))
                    atomicMass = null;
                if (atomicMass != null) {
                    writer.write("M  ISO  1 ");
                    writer.write(formatMDLInt(i + 1, 3));
                    writer.write(" ");
                    writer.write(formatMDLInt(atomicMass, 3));
                    writer.write('\n');
                }
            }
        }

        //write RGP line (max occurrence is 16 data points per line)
        if (rgroups != null) {
            StringBuilder rgpLine = new StringBuilder();
            int cnt = 0;

            // the order isn't guarantied but as we index with the atom
            // number this isn't an issue
            for (Map.Entry<Integer, Integer> e : rgroups.entrySet()) {
                rgpLine.append(formatMDLInt(e.getKey(), 4));
                rgpLine.append(formatMDLInt(e.getValue(), 4));
                cnt++;
                if (cnt == 8) {
                    rgpLine.insert(0, "M  RGP" + formatMDLInt(cnt, 3));
                    writer.write(rgpLine.toString());
                    writer.write('\n');
                    rgpLine = new StringBuilder();
                    cnt = 0;
                }
            }
            if (cnt != 0) {
                rgpLine.insert(0, "M  RGP" + formatMDLInt(cnt, 3));
                writer.write(rgpLine.toString());
                writer.write('\n');
            }

        }

        // write atom aliases
        if (aliases != null) {

            for (Map.Entry<Integer, String> e : aliases.entrySet()) {

                writer.write("A" + formatMDLInt(e.getKey(), 5));
                writer.write('\n');

                String label = e.getValue();

                // fixed width file - doubtful someone would have a label > 70 but trim if they do
                if (label.length() > 70) label = label.substring(0, 70);

                writer.write(label);
                writer.write('\n');

            }
        }

        writeSgroups(container, writer, atomindex);

        // close molecule
        writer.write("M  END");
        writer.write('\n');
        writer.flush();
    }
1339811
public static StereoElementFactory using2DCoordinates(IAtomContainer container) {
        EdgeToBondMap bondMap = EdgeToBondMap.withSpaceFor(container);
        int[][] graph = GraphUtil.toAdjList(container, bondMap);
        return new StereoElementFactory2D(container, graph, bondMap);
    }
217298
@Override
    public DescriptorValue calculate(IAtomContainer container) {
        IAtomContainer atomContainer;
        try {
            atomContainer = (IAtomContainer) container.clone();
        } catch (CloneNotSupportedException e) {
            DoubleArrayResult kierValues = new DoubleArrayResult(3);
            kierValues.add(Double.NaN);
            kierValues.add(Double.NaN);
            kierValues.add(Double.NaN);
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), kierValues,
                    getDescriptorNames());
        }
        atomContainer = AtomContainerManipulator.removeHydrogens(atomContainer);

        //org.openscience.cdk.interfaces.IAtom[] atoms = atomContainer.getAtoms();
        java.util.List firstAtomNeighboors;
        java.util.List secondAtomNeighboors;
        java.util.List thirdAtomNeighboors;
        DoubleArrayResult kierValues = new DoubleArrayResult(3);
        double bond1;
        double bond2;
        double bond3;
        double kier1;
        double kier2;
        double kier3;
        double atomsCount = atomContainer.getAtomCount();
        ArrayList<Double> singlePaths = new ArrayList<Double>();
        ArrayList<String> doublePaths = new ArrayList<String>();
        ArrayList<String> triplePaths = new ArrayList<String>();
        double[] sorterFirst = new double[2];
        double[] sorterSecond = new double[3];
        String tmpbond2;
        String tmpbond3;

        for (int a1 = 0; a1 < atomsCount; a1++) {
            bond1 = 0;
            firstAtomNeighboors = atomContainer.getConnectedAtomsList(atomContainer.getAtom(a1));
            for (int a2 = 0; a2 < firstAtomNeighboors.size(); a2++) {
                bond1 = atomContainer.indexOf(atomContainer.getBond(atomContainer.getAtom(a1), (IAtom) firstAtomNeighboors.get(a2)));
                if (!singlePaths.contains(new Double(bond1))) {
                    singlePaths.add(bond1);
                    java.util.Collections.sort(singlePaths);
                }
                secondAtomNeighboors = atomContainer.getConnectedAtomsList((IAtom) firstAtomNeighboors.get(a2));
                for (int a3 = 0; a3 < secondAtomNeighboors.size(); a3++) {
                    bond2 = atomContainer.indexOf(atomContainer.getBond((IAtom) firstAtomNeighboors.get(a2),
                            (IAtom) secondAtomNeighboors.get(a3)));
                    if (!singlePaths.contains(new Double(bond2))) {
                        singlePaths.add(bond2);
                    }
                    sorterFirst[0] = bond1;
                    sorterFirst[1] = bond2;
                    java.util.Arrays.sort(sorterFirst);

                    tmpbond2 = sorterFirst[0] + "+" + sorterFirst[1];

                    if (!doublePaths.contains(tmpbond2) && (bond1 != bond2)) {
                        doublePaths.add(tmpbond2);
                    }
                    thirdAtomNeighboors = atomContainer.getConnectedAtomsList((IAtom) secondAtomNeighboors.get(a3));
                    for (int a4 = 0; a4 < thirdAtomNeighboors.size(); a4++) {
                        bond3 = atomContainer.indexOf(atomContainer.getBond((IAtom) secondAtomNeighboors.get(a3),
                                (IAtom) thirdAtomNeighboors.get(a4)));
                        if (!singlePaths.contains(new Double(bond3))) {
                            singlePaths.add(bond3);
                        }
                        sorterSecond[0] = bond1;
                        sorterSecond[1] = bond2;
                        sorterSecond[2] = bond3;
                        java.util.Arrays.sort(sorterSecond);

                        tmpbond3 = sorterSecond[0] + "+" + sorterSecond[1] + "+" + sorterSecond[2];
                        if (!triplePaths.contains(tmpbond3)) {
                            if ((bond1 != bond2) && (bond1 != bond3) && (bond2 != bond3)) {
                                triplePaths.add(tmpbond3);
                            }
                        }
                    }
                }
            }
        }

        if (atomsCount == 1) {
            kier1 = 0;
            kier2 = 0;
            kier3 = 0;
        } else {
            kier1 = (((atomsCount) * ((atomsCount - 1) * (atomsCount - 1))) / (singlePaths.size() * singlePaths.size()));
            if (atomsCount == 2) {
                kier2 = 0;
                kier3 = 0;
            } else {
                if (doublePaths.size() == 0)
                    kier2 = Double.NaN;
                else
                    kier2 = (((atomsCount - 1) * ((atomsCount - 2) * (atomsCount - 2))) / (doublePaths.size() * doublePaths
                            .size()));
                if (atomsCount == 3) {
                    kier3 = 0;
                } else {
                    if (atomsCount % 2 != 0) {
                        if (triplePaths.size() == 0)
                            kier3 = Double.NaN;
                        else
                            kier3 = (((atomsCount - 1) * ((atomsCount - 3) * (atomsCount - 3))) / (triplePaths.size() * triplePaths
                                    .size()));
                    } else {
                        if (triplePaths.size() == 0)
                            kier3 = Double.NaN;
                        else
                            kier3 = (((atomsCount - 3) * ((atomsCount - 2) * (atomsCount - 2))) / (triplePaths.size() * triplePaths
                                    .size()));
                    }
                }
            }
        }

        kierValues.add(kier1);
        kierValues.add(kier2);
        kierValues.add(kier3);
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), kierValues,
                getDescriptorNames());
    }
768057
public static double getBondLengthMedian(final IAtomContainer container) {
        if (container.getBondCount() == 0) throw new IllegalArgumentException("Container has no bonds.");
        double[] lengths = new double[container.getBondCount()];
        for (int i = 0; i < container.getBondCount(); i++) {
            final IBond bond = container.getBond(i);
            final IAtom atom1 = bond.getBegin();
            final IAtom atom2 = bond.getEnd();
            if (atom1.getPoint2d() == null || atom2.getPoint2d() == null)
                throw new IllegalArgumentException("An atom has no 2D coordinates.");
            lengths[i] = getLength2D(bond);
        }
        Arrays.sort(lengths);
        return lengths[lengths.length / 2];
    }
163457
public void write(final ComponentDescriptor<?> componentDescriptor, final OutputStream outputStream)
            throws IOException {
        write(new ComponentDocumentationWrapper(componentDescriptor), outputStream);
    }
145882
private void writeObject(ObjectOutputStream out) throws IOException {
        if (!_peer.equals(this) && !(_peer instanceof Serializable)) {
            throw new IOException("Bean context child delegate does not support serialization!!!");
        }
        out.defaultWriteObject();
    }
751234
private void writeObject(ObjectOutputStream out) throws IOException {
        out.defaultWriteObject();
        // If the SemanticSpace that was provided is already serializable, then
        // just write it to the stream as is
        if (sspace instanceof Serializable) {
            out.writeObject(sspace);
        }
        // Otherwise, in order to serialize this instance, wrap the data in a
        // dummy SemanticSpace that contains the equivalent term-vector mapping
        else {
            verbose(LOGGER, "%s is not serializable, so writing a copy " +
                    "of the data", sspace.getSpaceName());
            Map<String,Vector> termToVector = 
                new HashMap<String,Vector>(sspace.getWords().size());
            for (String term : sspace.getWords()) 
                termToVector.put(term, sspace.getVector(term));
            SemanticSpace copy = new VectorMapSemanticSpace<Vector>(
                termToVector, "copy of " + sspace.getSpaceName(),
                sspace.getVectorLength());
            out.writeObject(copy);
        }
    }
934142
private void writeObject (ObjectOutputStream out)
        throws IOException
    {
        out.writeInt(size());

        for (IntEntry<TileSet> entry : intEntrySet()) {
            out.writeInt(entry.getIntKey());
            out.writeObject(entry.getValue());
        }
    }
347434
Entry<String, Point2d[]> createEntry(final IAtomContainer container) {
        try {

            final int n = container.getAtomCount();
            final int[] ordering = new int[n];
            final String smiles = cansmi(container, ordering);

            // build point array that is in the canonical output order
            final Point2d[] points = new Point2d[n];
            for (int i = 0; i < n; i++) {
                Point2d point = container.getAtom(i).getPoint2d();

                if (point == null) {
                    logger.warn("Atom at index ", i, " did not have coordinates.");
                    return null;
                }

                points[ordering[i]] = point;
            }

            return new SimpleEntry<String, Point2d[]>(smiles, points);

        } catch (CDKException e) {
            logger.warn("Could not encode container as SMILES: ", e);
        }

        return null;
    }
798678
public static void write(ObjectOutput out, Class<?> cl) throws IOException {
        int dim;

        if (cl == null) {
            out.writeByte(-1);
        } else {
            dim = 0;
            while (cl.isArray()) {
                dim++;
                cl = cl.getComponentType();
            }

            if (dim > Byte.MAX_VALUE) {
                throw new RuntimeException("to many dimensions");
            }

            out.writeByte((byte) dim);
            out.writeUTF(cl.getName());
        }
    }
188373
private void writeObject(ObjectOutputStream s) throws IOException {
        ObjectOutputStream.PutField putField = s.putFields();
        putField.put("version", version);
        putField.put("resourceAdapterKey", resourceAdapterKey);
        s.writeFields();
    }
198434
public static void writeToOutputStream(Structure structure, OutputStream outputStream) throws IOException{
		// Set up this writer
		AdapterToStructureData writerToEncoder = new AdapterToStructureData();
		// Get the writer - this is what people implement
		new MmtfStructureWriter(structure, writerToEncoder);
		// Now write this data to file
		byte[] outputBytes = WriterUtils.getDataAsByteArr(writerToEncoder);
		outputStream.write(outputBytes,0,outputBytes.length);
	}
1040242
@Override
    public StereoEncoder create(IAtomContainer container, int[][] graph) {

        int n = container.getAtomCount();
        BondMap map = new BondMap(n);

        List<StereoEncoder> encoders = new ArrayList<StereoEncoder>(1);

        // index double bonds by their atoms
        for (IBond bond : container.bonds()) {
            if (isDoubleBond(bond)) map.add(bond);
        }

        Set<IAtom> visited = new HashSet<IAtom>(n);

        // find atoms which are connected between two double bonds
        for (IAtom a : map.atoms()) {

            List<IBond> bonds = map.bonds(a);
            if (bonds.size() == 2) {

                // (s)tart/(e)nd of cumulated system: -s=a=e-
                IAtom s = bonds.get(0).getOther(a);
                IAtom e = bonds.get(1).getOther(a);
                // need the parents to re-use the double bond encoder
                IAtom sParent = a;
                IAtom eParent = a;

                visited.add(a);
                visited.add(s);
                visited.add(e);

                int size = 2;

                // expand out from 'l'
                while (s != null && map.cumulated(s)) {
                    IAtom p = map.bonds(s).get(0).getOther(s);
                    IAtom q = map.bonds(s).get(1).getOther(s);
                    sParent = s;
                    s = visited.add(p) ? p : visited.add(q) ? q : null;
                    size++;
                }

                // expand from 'r'
                while (e != null && map.cumulated(e)) {
                    IAtom p = map.bonds(e).get(0).getOther(e);
                    IAtom q = map.bonds(e).get(1).getOther(e);
                    eParent = e;
                    e = visited.add(p) ? p : visited.add(q) ? q : null;
                    size++;
                }

                // s and e are null if we had a cumulative cycle...
                if (s != null && e != null) {

                    // system has now be expanded, size is the number of double
                    // bonds. For odd numbers we use E/Z whilst for even are
                    // axial M/P.
                    //  \           /
                    //   s = = = = e
                    //  /           \
                    if (isOdd(size)) {
                        StereoEncoder encoder = GeometricDoubleBondEncoderFactory.newEncoder(container, s, sParent, e,
                                eParent, graph);
                        if (encoder != null) {
                            encoders.add(encoder);
                        }
                    } else {
                        StereoEncoder encoder = axialEncoder(container, s, e);
                        if (encoder != null) {
                            encoders.add(encoder);
                        }
                    }
                }
            }
        }

        return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders);
    }
861921
@Override
    public DescriptorValue calculate(IAtomContainer container) {
        try {
            IAtomContainer clone = (IAtomContainer) container.clone();
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(clone);
            int nsp2 = 0;
            int nsp3 = 0;
            for (IAtom atom : clone.atoms()) {
                if (!atom.getSymbol().equals("C")) continue;
                if (atom.getHybridization() == Hybridization.SP2)
                    nsp2++;
                else if (atom.getHybridization() == Hybridization.SP3) nsp3++;
            }
            double ratio = nsp3 / (double) (nsp2 + nsp3);
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
                    new DoubleResult(ratio), getDescriptorNames());
        } catch (CloneNotSupportedException e) {
            return getDummyDescriptorValue(e);
        } catch (CDKException e) {
            return getDummyDescriptorValue(e);
        }
    }
55861
public void cacheDescriptorValue(IBond bond, IAtomContainer container, IDescriptorResult doubleResult) {
        if (cachedDescriptorValues == null) {
            cachedDescriptorValues = new HashMap();
            cachedDescriptorValues.put(PREVIOUS_ATOMCONTAINER, container);
        } else if (cachedDescriptorValues.get(PREVIOUS_ATOMCONTAINER) != container) {
            cachedDescriptorValues.clear();
            cachedDescriptorValues.put(PREVIOUS_ATOMCONTAINER, container);
        }
        cachedDescriptorValues.put(bond, doubleResult);
    }
1119390
public void rebond(IAtomContainer container) throws CDKException {
        container.removeAllBonds();
        maxCovalentRadius = 0.0;
        // construct a new binary space partition tree
        bspt = new Bspt(3);
        Iterator<IAtom> atoms = container.atoms().iterator();
        while (atoms.hasNext()) {
            IAtom atom = atoms.next();
            double myCovalentRadius = atom.getCovalentRadius();
            if (myCovalentRadius == 0.0) {
                throw new CDKException("Atom(s) does not have covalentRadius defined.");
            }
            if (myCovalentRadius > maxCovalentRadius) maxCovalentRadius = myCovalentRadius;
            TupleAtom tupleAtom = new TupleAtom(atom);
            bspt.addTuple(tupleAtom);
        }
        // rebond all atoms
        atoms = container.atoms().iterator();
        while (atoms.hasNext()) {
            bondAtom(container, (IAtom) atoms.next());
        }
    }
1356208
public static void writeObject(Object object, OutputStream outputStream) {
        try {
            if (object instanceof Compactable) {
                ((Compactable) object).compact();
            }
            defaultObjectMapper.writeValue(outputStream, object);
        } catch (IOException exp) {
            throw new RuntimeException("Failed to write object to outputstream", exp);
        }
    }