Search in sources :

Example 1 with LittleEndianDataOutputStream

use of com.actelion.research.util.LittleEndianDataOutputStream in project openchemlib by Actelion.

the class ChemDrawCDX method getChemDrawBuffer.

public byte[] getChemDrawBuffer(StereoMolecule mol) {
    CDXDocument doc = new CDXDocument();
    doc.add(new CDPShowEnhAtomStereo(true));
    doc.add(new CDPShowAtomStereo(true));
    doc.add(new CDPShowBondStereo(true));
    CDXNode page = new CDXPage();
    CDXNode frag = new CDXFragment();
    doc.add(page);
    page.add(frag);
    MolGeom g = getTransform(mol);
    writeMolecule(mol, frag, g);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LittleEndianDataOutputStream l = new LittleEndianDataOutputStream(bos);
    write(l, doc);
    try {
        bos.close();
    } catch (IOException ex) {
        System.err.println("ChemDrawCDX::getChemDrawBuffer(): Error closing stream : " + ex);
    }
    return bos.toByteArray();
}
Also used : LittleEndianDataOutputStream(com.actelion.research.util.LittleEndianDataOutputStream)

Example 2 with LittleEndianDataOutputStream

use of com.actelion.research.util.LittleEndianDataOutputStream in project openchemlib by Actelion.

the class ChemDrawCDX method getChemDrawBuffer.

public byte[] getChemDrawBuffer(Reaction rxn) {
    CDXDocument doc = new CDXDocument();
    int r = rxn.getReactants();
    int p = rxn.getProducts();
    int mn = rxn.getMolecules();
    doc.add(new CDPShowEnhAtomStereo(true));
    doc.add(new CDPShowAtomStereo(true));
    doc.add(new CDPShowBondStereo(true));
    CDXNode page = new CDXPage();
    doc.add(page);
    MolGeom g = getTransform(rxn);
    int[] rids = new int[r];
    for (int i = 0; i < r; i++) {
        StereoMolecule m = rxn.getReactant(i);
        CDXNode frag = new CDXFragment();
        writeMolecule(m, frag, g);
        rids[i] = frag.getID();
        page.add(frag);
    }
    int[] pids = new int[p];
    for (int i = 0; i < p; i++) {
        StereoMolecule m = rxn.getProduct(i);
        CDXNode frag = new CDXFragment();
        writeMolecule(m, frag, g);
        pids[i] = frag.getID();
        page.add(frag);
    }
    CDXReactionStep step = new CDXReactionStep(rids, pids);
    page.add(step);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LittleEndianDataOutputStream l = new LittleEndianDataOutputStream(bos);
    write(l, doc);
    try {
        bos.close();
    } catch (IOException ex) {
        System.err.println("ChemDrawCDX::getChemDrawBuffer(): Error closing stream : " + ex);
    }
    return bos.toByteArray();
}
Also used : LittleEndianDataOutputStream(com.actelion.research.util.LittleEndianDataOutputStream) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 3 with LittleEndianDataOutputStream

use of com.actelion.research.util.LittleEndianDataOutputStream in project openchemlib by Actelion.

the class ChemDrawCDX method test.

public void test() {
    CDXDocument doc = new CDXDocument();
    CDXNode page = new CDXPage();
    CDXNode frag = new CDXFragment();
    // CDXAtom at1 = new CDXAtom((short)7, 0x00948000, 0x00A44000);
    // CDXAtom at2 = new CDXAtom((short)8, 0x00B17A4E, 0x00AC03BA);
    CDXAtom at1 = new CDXAtom((short) 7, 0x00, 0x00);
    CDXAtom at2 = new CDXAtom((short) 8, 0x02000000, 0x00AC03BA);
    CDXBond b1 = new CDXBond(at1.getID(), at2.getID());
    doc.add(page);
    page.add(frag);
    frag.add(at1);
    frag.add(at2);
    frag.add(b1);
    dump(doc);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LittleEndianDataOutputStream l = new LittleEndianDataOutputStream(bos);
    write(l, doc);
    try {
        bos.close();
    } catch (IOException e) {
    }
    byte[] buffer = bos.toByteArray();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < buffer.length; i++) {
        byte b = buffer[i];
        if (i != 0) {
            sb.append(" ");
        }
        if (i > 0 && (i % 16) == 0) {
            sb.append("\n");
        }
        sb.append(String.format("%02X", (int) (b & 0xFF)));
    }
    System.out.println("\nByte Dump:\n" + sb);
    NativeClipboardAccessor.setClipBoardData("ChemDraw Interchange Format", buffer);
    try {
        BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream("d:\\dev\\console\\test.cdx"));
        l = new LittleEndianDataOutputStream(os);
        write(l, doc);
        os.close();
    } catch (IOException e) {
    }
}
Also used : LittleEndianDataOutputStream(com.actelion.research.util.LittleEndianDataOutputStream)

Aggregations

LittleEndianDataOutputStream (com.actelion.research.util.LittleEndianDataOutputStream)3 StereoMolecule (com.actelion.research.chem.StereoMolecule)1