Java Code Examples for org.openscience.cdk.interfaces.IAtomContainer#setAtoms()

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer#setAtoms() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtomContainerAtomPermutor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static IAtomContainer permuteB(int[] p, IAtomContainer atomContainer) {
        IAtomContainer permutedContainer = null;
//        System.out.println("permuting " + java.util.Arrays.toString(p));
        try {
            permutedContainer = atomContainer.clone();
            int n = atomContainer.getAtomCount();
            IAtom[] permutedAtoms = new IAtom[n];
            for (int originalIndex = 0; originalIndex < n; originalIndex++) {
                // get the newly cloned atom 
                IAtom atom = permutedContainer.getAtom(originalIndex);

                // permute the index
                int newIndex = p[originalIndex];

                // put the atom in the new place
                permutedAtoms[newIndex] = atom;
            }
            permutedContainer.setAtoms(permutedAtoms);
        } catch (CloneNotSupportedException cne) {
            //?
            out.println(cne);
        }
        return permutedContainer;
    }
 
Example 2
Source File: Reactor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private synchronized void permuteWithoutClone(int[] p, IAtomContainer atomContainer) {
    int n = atomContainer.getAtomCount();
    if (DEBUG) {
        LOGGER.debug("permuting " + java.util.Arrays.toString(p));
    }
    IAtom[] permutedAtoms = new IAtom[n];

    for (int i = 0; i < n; i++) {
        IAtom atom = atomContainer.getAtom(i);
        permutedAtoms[p[i]] = atom;
        atom.setProperty("label", p[i]);
    }
    atomContainer.setAtoms(permutedAtoms);

    IBond[] bonds = getBondArray(atomContainer);
    sort(bonds, (IBond o1, IBond o2) -> {
        int u = o1.getAtom(0).getProperty("label");
        int v = o1.getAtom(1).getProperty("label");
        int x = o2.getAtom(0).getProperty("label");
        int y = o2.getAtom(1).getProperty("label");
        int min1 = min(u, v);
        int min2 = min(x, y);
        int max1 = max(u, v);
        int max2 = max(x, y);

        int minCmp = Integer.compare(min1, min2);
        if (minCmp != 0) {
            return minCmp;
        }
        int maxCmp = Integer.compare(max1, max2);
        if (maxCmp != 0) {
            return maxCmp;
        }
        LOGGER.debug("pokemon!");
        throw new InternalError();
    });
    atomContainer.setBonds(bonds);
}
 
Example 3
Source File: Block.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @return
 */
public Rectangle2D getBounds() {
    if (bounds == null) {
        IAtomContainer tmp
                = atomContainer.getBuilder().newInstance(IAtomContainer.class);
        tmp.setAtoms(getAtoms().toArray(new IAtom[0]));
        bounds = calculateBounds(tmp);
    }
    return bounds;
}
 
Example 4
Source File: BlockReactionCanoniser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private IAtomContainerSet permuteR(IAtomContainerSet original, BlockMapping mapping) {
    int[] reactantPermutation = mapping.getPermutationOfReactants();
    IAtomContainerSet permutedContainers = builder.newInstance(IAtomContainerSet.class);
    // System.out.println("REACTANTS --------------------");

    List<IAtomContainer> unusedContainers = new ArrayList<>();
    for (IAtomContainer ac : original.atomContainers()) {
        unusedContainers.add(ac);
    }
    for (int i = 0; i < original.getAtomContainerCount(); i++) {
        int pi = reactantPermutation[i];
        IAtomContainer container = original.getAtomContainer(pi);
        BlockList blockList = mapping.getBlockListForReactant(container);

        if (blockList == null) {
            out.println("blocklist null for " + i
                    + new AtomContainerPrinter().toString(container)
                    + " in " + java.util.Arrays.toString(reactantPermutation));
            continue;
        }

        unusedContainers.remove(container);

        IAtomContainer permutedContainer = builder.newInstance(IAtomContainer.class);
        permutedContainer.setID(container.getID());
        // System.out.println("AC " + i + " " + blockList);

        IAtom[] atoms = getPermutedAtomsForReactant(blockList, container);
        // System.out.println("AC " + i + " " + blockList);
        permutedContainer.setAtoms(atoms);
        for (IBond bond : container.bonds()) {
            permutedContainer.addBond(bond);
        }
        permutedContainers.addAtomContainer(permutedContainer);
    }
    unusedContainers.stream().forEach((unusedContainer) -> {
        permutedContainers.addAtomContainer(unusedContainer);
    });
    return permutedContainers;
}
 
Example 5
Source File: BlockReactionCanoniser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private IAtomContainerSet permuteP(IAtomContainerSet original, BlockMapping mapping) {
    IAtomContainerSet permutedContainers = builder.newInstance(IAtomContainerSet.class);
    int[] productPermutation = mapping.getPermutationOfProducts();
    // System.out.println("PRODUCTS --------------------");

    List<IAtomContainer> unusedContainers = new ArrayList<>();
    for (IAtomContainer ac : original.atomContainers()) {
        unusedContainers.add(ac);
    }
    for (int i = 0; i < original.getAtomContainerCount(); i++) {
        int pi = productPermutation[i];
        IAtomContainer container = original.getAtomContainer(pi);
        BlockList blockList = mapping.getBlockListForProduct(container);
        if (blockList == null) {
            out.println("blocklist null for " + i
                    + new AtomContainerPrinter().toString(container)
                    + " in " + java.util.Arrays.toString(productPermutation));
            continue;
        }
        unusedContainers.remove(container);

        IAtomContainer permutedContainer = builder.newInstance(IAtomContainer.class);
        permutedContainer.setID(container.getID());
        // System.out.println("AC " + i + " " + blockList);
        IAtom[] atoms = getPermutedAtomsForProduct(blockList, container);
        permutedContainer.setAtoms(atoms);
        for (IBond bond : container.bonds()) {
            permutedContainer.addBond(bond);
        }
        permutedContainers.addAtomContainer(permutedContainer);
    }
    unusedContainers.stream().forEach((unusedContainer) -> {
        permutedContainers.addAtomContainer(unusedContainer);
    });
    return permutedContainers;
}
 
Example 6
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void permuteWithoutClone(int[] p, IAtomContainer atomContainer) {
    int n = atomContainer.getAtomCount();
    IAtom[] permutedAtoms = new IAtom[n];

    for (int i = 0; i < n; i++) {
        IAtom atom = atomContainer.getAtom(i);
        permutedAtoms[p[i]] = atom;
        atom.setProperty("label", p[i]);
    }
    atomContainer.setAtoms(permutedAtoms);

    IBond[] bonds = getBondArray(atomContainer);
    sort(bonds, (IBond o1, IBond o2) -> {
        int u = o1.getAtom(0).getProperty("label");
        int v = o1.getAtom(1).getProperty("label");
        int x = o2.getAtom(0).getProperty("label");
        int y = o2.getAtom(1).getProperty("label");
        int min1 = min(u, v);
        int min2 = min(x, y);
        int max1 = max(u, v);
        int max2 = max(x, y);

        int minCmp = Integer.compare(min1, min2);
        if (minCmp != 0) {
            return minCmp;
        }
        int maxCmp = Integer.compare(max1, max2);
        if (maxCmp != 0) {
            return maxCmp;
        }
        LOGGER.debug("pokemon!");
        throw new InternalError();
    });
    atomContainer.setBonds(bonds);
}
 
Example 7
Source File: AtomContainerAtomPermutor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void permuteWithoutClone(int[] p, IAtomContainer atomContainer) {
    int n = atomContainer.getAtomCount();
    IAtom[] permutedAtoms = new IAtom[n];
    for (int originalIndex = 0; originalIndex < n; originalIndex++) {
        // get the newly cloned atom 
        IAtom atom = atomContainer.getAtom(originalIndex);

        // permute the index
        int newIndex = p[originalIndex];

        // put the atom in the new place
        permutedAtoms[newIndex] = atom;
    }
    atomContainer.setAtoms(permutedAtoms);
}
 
Example 8
Source File: SignatureMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void permuteWithoutClone(int[] p, IAtomContainer atomContainer) {
    int n = atomContainer.getAtomCount();
    IAtom[] permutedAtoms = new IAtom[n];

    for (int i = 0; i < n; i++) {
        IAtom atom = atomContainer.getAtom(i);
        permutedAtoms[p[i]] = atom;
        atom.setProperty("label", p[i]);
    }
    atomContainer.setAtoms(permutedAtoms);

    IBond[] bonds = getBondArray(atomContainer);
    sort(bonds, (IBond o1, IBond o2) -> {
        int u = o1.getAtom(0).getProperty("label");
        int v = o1.getAtom(1).getProperty("label");
        int x = o2.getAtom(0).getProperty("label");
        int y = o2.getAtom(1).getProperty("label");
        int min1 = min(u, v);
        int min2 = min(x, y);
        int max1 = max(u, v);
        int max2 = max(x, y);

        int minCmp = Integer.compare(min1, min2);
        if (minCmp != 0) {
            return minCmp;
        }
        int maxCmp = Integer.compare(max1, max2);
        if (maxCmp != 0) {
            return maxCmp;
        }
        LOGGER.debug("pokemon!");
        throw new InternalError();
    });
    atomContainer.setBonds(bonds);
}
 
Example 9
Source File: SmilesMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Given a molecule (possibly disconnected) compute the labels which would
 * order the atoms and bonds by increasing canonical labeling.
 *
 * @param atomContainer
 * @param p
 */
public void getCanonicalPermutation(IAtomContainer atomContainer, int p[]) {
    int n = atomContainer.getAtomCount();

    IAtom[] permutedAtoms = new IAtom[n];

    for (int i = 0; i < n; i++) {
        IAtom atom = atomContainer.getAtom(i);
        permutedAtoms[p[i]] = atom;
        atom.setProperty("label", p[i]);
    }
    atomContainer.setAtoms(permutedAtoms);

    IBond[] bonds = getBondArray(atomContainer);
    sort(bonds, (IBond o1, IBond o2) -> {
        int u = o1.getAtom(0).getProperty("label");
        int v = o1.getAtom(1).getProperty("label");
        int x = o2.getAtom(0).getProperty("label");
        int y = o2.getAtom(1).getProperty("label");
        int min1 = min(u, v);
        int min2 = min(x, y);
        int max1 = max(u, v);
        int max2 = max(x, y);

        int minCmp = Integer.compare(min1, min2);
        if (minCmp != 0) {
            return minCmp;
        }
        int maxCmp = Integer.compare(max1, max2);
        if (maxCmp != 0) {
            return maxCmp;
        }
        LOGGER.debug("pokemon!");
        throw new InternalError();
    });

    atomContainer.setBonds(bonds);
}