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

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer#setID() . 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: ExtAtomContainerManipulator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Copy the input container and suppress any explicit hydrogens. Only
 * hydrogens that can be represented as a hydrogen count value on the atom
 * are suppressed. If a copy is not needed please use {@link
 * #suppressHydrogens}.
 *
 * @param org the container from which to remove hydrogens
 * @return a copy of the input with suppressed hydrogens
 * @see #suppressHydrogens
 */
public static IAtomContainer copyAndSuppressedHydrogens(IAtomContainer org) {
    /*
     * Remove the CTAB_SGROUPS flag as CDK 2.2 complains
     */
    org.setProperty(CDKConstants.CTAB_SGROUPS, null);
    /*
     * @ASAD: IMP STEP to avoid unset Hydrogen arror:
     * Set implicit Hydrogen count
     */
    try {
        IAtomContainer clone = org.clone();
        clone.setID(org.getID());
        for (int i = 0; i < org.getAtomCount(); i++) {
            int implicitHydrogenCount = getImplicitHydrogenCount(clone.getAtom(i));
            clone.getAtom(i).setImplicitHydrogenCount(implicitHydrogenCount);
            clone.getAtom(i).setProperties(org.getAtom(i).getProperties());
            clone.getAtom(i).setFlags(org.getAtom(i).getFlags());
        }
        return suppressHydrogens(clone);
    } catch (CloneNotSupportedException e) {
        throw new IllegalStateException("atom container could not be cloned");
    }
}
 
Example 2
Source File: ExtAtomContainerManipulator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns deep copy of the molecule
 *
 * @param container
 * @return deep copy of the mol
 * @throws CloneNotSupportedException
 */
public static IAtomContainer newInstanceWithIDs(IAtomContainer container) throws CloneNotSupportedException {
    //setNullHCountToZero(container);
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    IAtomContainer ac = builder.newInstance(IAtomContainer.class, container);
    /*Set IDs as CDK clone doesn't*/
    for (int i = 0; i < ac.getAtomCount(); i++) {
        ac.getAtom(i).setID(container.getAtom(i).getID());
        if (ac.getAtom(i).getProperties() == null) {
            ac.getAtom(i).setProperties(new HashMap<>());
        }
    }

    for (int i = 0; i < ac.getBondCount(); i++) {
        if (ac.getBond(i).getProperties() == null) {
            ac.getBond(i).setProperties(new HashMap<>());
        }
    }
    ac.setProperties(container.getProperties());
    ac.setFlags(container.getFlags());
    ac.setID(container.getID());
    ac.notifyChanged();
    return ac;
}
 
Example 3
Source File: ExtAtomContainerManipulator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns IAtomContainer without Hydrogen. If an GraphAtomContainer has
 * atom single atom which is atom Hydrogen then its not removed.
 *
 * @param atomContainer
 * @return IAtomContainer without Hydrogen. If an GraphAtomContainer has
 * atom single atom which is atom Hydrogen then its not removed.
 */
public static IAtomContainer convertExplicitToImplicitHydrogens(IAtomContainer atomContainer) {
    IAtomContainer mol = atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);
    if (mol.getAtomCount() > 1) {
        mol = removeHydrogensExceptSingleAndPreserveAtomID(mol);
    } else if (mol.getAtomCount() == 1 && !atomContainer.atoms().iterator().next().getSymbol().equalsIgnoreCase("H")) {
        /*
         * Pseudo-atoms and unconfigured atoms safetynet
         */
        convertImplicitToExplicitHydrogens(mol);
        mol = removeHydrogensExceptSingleAndPreserveAtomID(mol);
    } else if (mol.getAtomCount() == 1 && atomContainer.atoms().iterator().next().getSymbol().equalsIgnoreCase("H")) {
        LOGGER.warn("WARNING: single hydrogen atom removal not supported!");
    }
    mol.setProperties(atomContainer.getProperties());
    mol.setFlags(atomContainer.getFlags());
    if (atomContainer.getID() != null) {
        mol.setID(atomContainer.getID());
    }
    return mol;
}
 
Example 4
Source File: SmilesMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    try {
        IAtomContainer clone = container.clone();
        for (IAtom a : container.atoms()) {
            if (a.getID() != null) {
                int index = container.indexOf(a);
                clone.getAtom(index).setID(a.getID());
            }
        }

        if (container.getID() != null) {
            clone.setID(container.getID());
        }

        int[] canonicalPermutation = getCanonicalPermutation(clone);
        getCanonicalPermutation(clone, canonicalPermutation);
        return clone;

    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }
    return null;
}
 
Example 5
Source File: InChiMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    int[] canonicalPermutation = getCanonicalPermutation(container);
    IAtomContainer permute = permute(
            canonicalPermutation, container);
    if (container.getID() != null) {
        permute.setID(container.getID());
    }

    for (int i : canonicalPermutation) {
        if (container.getAtom(i).getID() != null) {
            permute.getAtom(i).setID(container.getAtom(i).getID());
        }
    }
    return permute;
}
 
Example 6
Source File: AbstractReactionLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param moleculeSet
 * @param labeller
 * @param permutationMap
 * @return
 */
protected IAtomContainerSet canoniseAtomContainerSet(
        IAtomContainerSet moleculeSet,
        ICanonicalMoleculeLabeller labeller,
        Map<IAtomContainer, int[]> permutationMap) {
    IAtomContainerSet canonicalMolecules = new AtomContainerSet();
    for (IAtomContainer atomContainer : moleculeSet.atomContainers()) {
        IAtomContainer canonicalForm
                = labeller.getCanonicalMolecule(atomContainer);
        if (fixAtomMappingCastType) {
            fixAtomMapping(canonicalForm);
        }
        canonicalForm.setID(atomContainer.getID());
        permutationMap.put(
                canonicalForm,
                labeller.getCanonicalPermutation(atomContainer));
        canonicalMolecules.addAtomContainer(canonicalForm);
    }
    return canonicalMolecules;
}
 
Example 7
Source File: MCSThread.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private synchronized IAtomContainer getNewContainerWithIDs(IAtomContainer mol)
        throws CDKException, CloneNotSupportedException {
    /*
     Generating SMILES speed ups the mapping process by n-FOLDS
     May be this is CDK inherent bug, which relies on the properties set by the SMILES
     */
    IAtomContainer ac;
    ac = mol.clone();
    for (int i = 0; i < ac.getAtomCount(); i++) {
        String atomID = mol.getAtom(i).getID() == null
                ? valueOf(i) : mol.getAtom(i).getID();
        ac.getAtom(i).setID(atomID);
    }
    String containerID = mol.getID() == null ? valueOf(nanoTime()) : mol.getID();
    ac.setID(containerID);

    return ac;
}
 
Example 8
Source File: ExtAtomContainerManipulator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns deep copy of the molecule
 *
 * @param container
 * @return deep copy of the mol
 * @throws CloneNotSupportedException
 */
public static IAtomContainer cloneWithIDs(IAtomContainer container) throws CloneNotSupportedException {
    //setNullHCountToZero(container);
    IAtomContainer ac = new AtomContainer(container).clone();/*Set IDs as CDK clone doesn't*/
    for (int i = 0; i < ac.getAtomCount(); i++) {
        ac.getAtom(i).setID(container.getAtom(i).getID());
        if (ac.getAtom(i).getProperties() == null) {
            ac.getAtom(i).setProperties(new HashMap<>());
        } else {
            ac.getAtom(i).setID(container.getAtom(i).getID());
            ac.getAtom(i).setFlags(container.getAtom(i).getFlags());
            ac.getAtom(i).setProperties(container.getAtom(i).getProperties());
            ac.getAtom(i).setIsInRing(container.getAtom(i).isInRing());
            ac.getAtom(i).setIsAromatic(container.getAtom(i).isAromatic());
        }
    }

    for (int i = 0; i < ac.getBondCount(); i++) {
        if (ac.getBond(i).getProperties() == null) {
            ac.getBond(i).setProperties(new HashMap<>());
        } else {
            ac.getBond(i).setFlags(container.getBond(i).getFlags());
            ac.getBond(i).setProperties(container.getBond(i).getProperties());
        }
    }

    ac.setProperties(container.getProperties());
    ac.setFlags(container.getFlags());
    ac.setID(container.getID());
    ac.notifyChanged();
    return ac;
}
 
Example 9
Source File: SignatureMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    try {
        IAtomContainer permute = container.clone();

        if (container.getID() != null) {
            permute.setID(container.getID());
        }

        for (int i = 0; i < permute.getAtomCount(); i++) {
            if (container.getAtom(i).getID() != null) {
                permute.getAtom(i).setID(container.getAtom(i).getID());
            }
        }

        int[] canonicalPermutation = getCanonicalPermutation(permute);

        permuteWithoutClone(canonicalPermutation, permute);

        return permute;
    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }

    return null;
}
 
Example 10
Source File: MCSThread.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private synchronized IAtomContainer duplicate(IAtomContainer ac) throws CloneNotSupportedException {
    IAtomContainer a = ac.clone();
    a.setID(ac.getID());

    for (int i = 0; i < a.getAtomCount(); i++) {
        a.getAtom(i).setID(ac.getAtom(i).getID());
    }

    ac.setProperties(ac.getProperties());
    ac.setFlags(ac.getFlags());
    ac.setID(ac.getID());
    ac.notifyChanged();

    return a;
}
 
Example 11
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 12
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 13
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     *
     * @param org_mol
     * @return cloned canonicalized molecule
     * @throws CloneNotSupportedException
     * @throws CDKException
     */
    public static IAtomContainer canonicalise(IAtomContainer org_mol) throws CloneNotSupportedException, CDKException {

        IAtomContainer cloneMolecule = cloneWithIDs(org_mol);

        int[] p = new int[cloneMolecule.getAtomCount()];
//        /*
//         Signature based canonical Permutations
//         */
//        p = new uk.ac.ebi.reactionblast.tools.labelling.
//        SignatureMoleculeLabeller().getCanonicalPermutation(cloneMolecule);

        /*
        Use the Canonical labelling from the SMILES
        IMP: Suggested by John May
         */
        try {
//            unique().create(cloneMolecule, p);
            SmilesGenerator smiles = new SmilesGenerator(
                    SmiFlavor.AtomAtomMap
                    | SmiFlavor.Unique
                    //                    | SmiFlavor.UseAromaticSymbols
                    | SmiFlavor.Stereo);

            String sm = smiles.create(cloneMolecule, p);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.debug("Fragment not fit to canonicalise!");
        }

        permuteWithoutClone(p, cloneMolecule);

        /*
        Set the IDs to container
         */
        if (org_mol.getID() != null) {
            cloneMolecule.setID(org_mol.getID());
        }

        return cloneMolecule;
    }
 
Example 14
Source File: GameTheoryMixture.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private synchronized void UpdateMapping() throws Exception {
        boolean[][] FlagMatrix = winner.getFlagMatrix();

        ReactionContainer reactionStructureInformationContainer = mh.getReactionContainer();

        for (int iIndex = 0; iIndex < reactionStructureInformationContainer.getEductCount(); iIndex++) {
            for (int jIndex = 0; jIndex < reactionStructureInformationContainer.getProductCount(); jIndex++) {
                int substrateIndex = iIndex;
                int productIndex = jIndex;
                IAtomContainer ac1 = reactionStructureInformationContainer.getEduct(substrateIndex);
                IAtomContainer ac2 = reactionStructureInformationContainer.getProduct(productIndex);

                if (FlagMatrix[substrateIndex][productIndex]) {

                    // updateFlag=true;
                    BitSet A = reactionStructureInformationContainer.getFingerPrintofEduct(substrateIndex);    // A=EDUCT
                    BitSet B = reactionStructureInformationContainer.getFingerPrintofProduct(productIndex);    // B=PRODUCT

                    /*
                     * Choose this function if you want JMCS to run
                     */
                    ac1.setID(this.eductList.get(substrateIndex));
                    ac2.setID(this.productList.get(productIndex));

                    AbstractGraphMatching GM = new GraphMatching(RID, ac1, ac2, _dirSuffix, removeHydrogen);
                    boolean mcsMatch = GM.mcsMatch(mh, removeHydrogen, substrateIndex, productIndex, A, B);
//                    System.out.println("Mol Size E: " + ac1.getAtomCount() + " , Mol Size P: " + ac2.getAtomCount());
                    if (mcsMatch) {
//                        System.out.println(eductList.get(substrateIndex) + " <=> " + productList.get(productIndex));
                        delta += GM.removeMatchedAtomsAndUpdateAAM(reaction);
                        List<MolMapping> rMap = getReactionMolMapping().
                                getMapping(RID, this.eductList.get(substrateIndex), this.productList.get(productIndex));
                        for (MolMapping map : rMap) {
                            map.setReactionMapping(true);
                            IAtomContainer mol = GM.getMatchedPart();
                            mol = canonLabeler.getCanonicalMolecule(mol);
                            CDKSMILES cdkSmiles = new CDKSMILES(mol, true, false);
                            map.setMatchedSMILES(cdkSmiles.getCanonicalSMILES(), ++stepIndex);
                        }
                    }
                    IAtomContainer RemainingEduct = GM.getRemainingEduct();
                    IAtomContainer RemainingProduct = GM.getRemainingProduct();

                    reactionStructureInformationContainer.putEduct(substrateIndex, RemainingEduct);
                    reactionStructureInformationContainer.putProduct(productIndex, RemainingProduct);
                    reactionStructureInformationContainer.setEductModified(substrateIndex, true);
                    reactionStructureInformationContainer.setProductModified(productIndex, true);
                }
            }
        }
    }
 
Example 15
Source File: GameTheoryMax.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private synchronized void UpdateMapping() throws Exception {
        boolean[][] FlagMatrix = winner.getFlagMatrix();

        ReactionContainer reactionStructureInformation = mh.getReactionContainer();

        for (int iIndex = 0; iIndex < reactionStructureInformation.getEductCount(); iIndex++) {
            for (int jIndex = 0; jIndex < reactionStructureInformation.getProductCount(); jIndex++) {
                int substrateIndex = iIndex;
                int productIndex = jIndex;
                IAtomContainer ac1 = reactionStructureInformation.getEduct(substrateIndex);
                IAtomContainer ac2 = reactionStructureInformation.getProduct(productIndex);

                if (FlagMatrix[substrateIndex][productIndex]) {

                    // updateFlag=true;
                    BitSet A = reactionStructureInformation.getFingerPrintofEduct(substrateIndex);    // A=EDUCT
                    BitSet B = reactionStructureInformation.getFingerPrintofProduct(productIndex);    // B=PRODUCT

                    /*
                     * Choose this function if you want JMCS to run
                     */
                    ac1.setID(this.eductList.get(substrateIndex));
                    ac2.setID(this.productList.get(productIndex));

                    AbstractGraphMatching GM = new GraphMatching(rid, ac1, ac2, dirSuffix, removeHydrogen);
//                    System.out.println("Mol Size E: " + ac1.getAtomCount() + " , Mol Size P: " + ac2.getAtomCount());
                    boolean mcsMatch = GM.mcsMatch(mh, removeHydrogen, substrateIndex, productIndex, A, B);
                    if (mcsMatch) {
                        delta += GM.removeMatchedAtomsAndUpdateAAM(reaction);
                        List<MolMapping> rMap = getReactionMolMapping().
                                getMapping(rid, this.eductList.get(substrateIndex), this.productList.get(productIndex));
                        rMap.stream().map((map) -> {
                            map.setReactionMapping(true);
                            return map;
                        }).forEach((map) -> {
                            try {
                                IAtomContainer mol = GM.getMatchedPart();
                                mol = canonLabeler.getCanonicalMolecule(mol);
                                CDKSMILES cdkSmiles = new CDKSMILES(mol, true, false);
                                map.setMatchedSMILES(cdkSmiles.getCanonicalSMILES(), ++stepIndex);
                            } catch (CloneNotSupportedException e) {
                            }
                        });
                    }
                    IAtomContainer remainingEduct = GM.getRemainingEduct();
                    IAtomContainer remainingProduct = GM.getRemainingProduct();

//                    System.out.println("Rem Mol Size E: " + remainingEduct.getAtomCount() 
//                            + " , Rem Mol Size P: " + remainingProduct.getAtomCount());
                    reactionStructureInformation.putEduct(substrateIndex, remainingEduct);
                    reactionStructureInformation.putProduct(productIndex, remainingProduct);
                    reactionStructureInformation.setEductModified(substrateIndex, true);
                    reactionStructureInformation.setProductModified(productIndex, true);
                }
            }
        }
    }
 
Example 16
Source File: GameTheoryRings.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private synchronized void UpdateMapping() throws Exception {
    boolean[][] FlagMatrix = winner.getFlagMatrix();

    ReactionContainer reactionStructureInformationContainer = mh.getReactionContainer();

    for (int iIndex = 0; iIndex < reactionStructureInformationContainer.getEductCount(); iIndex++) {
        for (int jIndex = 0; jIndex < reactionStructureInformationContainer.getProductCount(); jIndex++) {
            int substrateIndex = iIndex;
            int productIndex = jIndex;
            IAtomContainer ac1 = reactionStructureInformationContainer.getEduct(substrateIndex);
            IAtomContainer ac2 = reactionStructureInformationContainer.getProduct(productIndex);

            if (FlagMatrix[substrateIndex][productIndex]) {

                // updateFlag=true;
                BitSet A = reactionStructureInformationContainer.getFingerPrintofEduct(substrateIndex);    // A=EDUCT
                BitSet B = reactionStructureInformationContainer.getFingerPrintofProduct(productIndex);    // B=PRODUCT

                /*
                 * Choose this function if you want JMCS to run
                 */
                ac1.setID(this.eductList.get(substrateIndex));
                ac2.setID(this.productList.get(productIndex));

                AbstractGraphMatching GM = new GraphMatching(RID, ac1, ac2, _dirSuffix, removeHydrogen);
                boolean mcsMatch = GM.mcsMatch(mh, removeHydrogen, substrateIndex, productIndex, A, B);
                if (DEBUG) {
                    System.out.println("Mol Size E: " + ac1.getAtomCount() + " , Mol Size P: " + ac2.getAtomCount());
                }
                if (mcsMatch) {
                    if (DEBUG) {
                        System.out.println(eductList.get(substrateIndex) + " <=> " + productList.get(productIndex));
                    }
                    delta += GM.removeMatchedAtomsAndUpdateAAM(reaction);
                    List<MolMapping> rMap = getReactionMolMapping().
                            getMapping(RID, this.eductList.get(substrateIndex), this.productList.get(productIndex));
                    for (MolMapping map : rMap) {
                        map.setReactionMapping(true);
                        IAtomContainer mol = GM.getMatchedPart();
                        mol = canonLabeler.getCanonicalMolecule(mol);
                        CDKSMILES cdkSmiles = new CDKSMILES(mol, true, false);
                        map.setMatchedSMILES(cdkSmiles.getCanonicalSMILES(), ++stepIndex);
                    }
                }
                IAtomContainer remainingEduct = GM.getRemainingEduct();
                IAtomContainer remainingProduct = GM.getRemainingProduct();
                if (DEBUG) {
                    System.out.println("Remaining Mol Size E: " + remainingEduct.getAtomCount() + " , Remaining Mol Size P: " + remainingProduct.getAtomCount());
                }
                reactionStructureInformationContainer.putEduct(substrateIndex, remainingEduct);
                reactionStructureInformationContainer.putProduct(productIndex, remainingProduct);
                reactionStructureInformationContainer.setEductModified(substrateIndex, true);
                reactionStructureInformationContainer.setProductModified(productIndex, true);
            }
        }
    }
}
 
Example 17
Source File: GameTheoryMin.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private synchronized void UpdateMapping() throws Exception {
    boolean[][] FlagMatrix = winner.getFlagMatrix();

    ReactionContainer reactionStructureInformationContainer = mh.getReactionContainer();

    for (int iIndex = 0; iIndex < reactionStructureInformationContainer.getEductCount(); iIndex++) {
        for (int jIndex = 0; jIndex < reactionStructureInformationContainer.getProductCount(); jIndex++) {
            int substrateIndex = iIndex;
            int productIndex = jIndex;
            IAtomContainer ac1 = reactionStructureInformationContainer.getEduct(substrateIndex);
            IAtomContainer ac2 = reactionStructureInformationContainer.getProduct(productIndex);

            if (FlagMatrix[substrateIndex][productIndex]) {

                // updateFlag=true;
                BitSet a_BitSet = reactionStructureInformationContainer.getFingerPrintofEduct(substrateIndex);    // a_BitSet=EDUCT
                BitSet b_BitSet = reactionStructureInformationContainer.getFingerPrintofProduct(productIndex);    // b_BitSet=PRODUCT

                /*
                 * Choose this function if you want JMCS to run
                 */
                ac1.setID(this.eductList.get(substrateIndex));
                ac2.setID(this.productList.get(productIndex));

                AbstractGraphMatching graphMatching = new GraphMatching(reactionName, ac1, ac2, _dirSuffix, removeHydrogen);
                boolean mcsMatch = graphMatching.mcsMatch(mh, removeHydrogen, substrateIndex, productIndex, a_BitSet, b_BitSet);
                if (DEBUG) {
                    out.println("Mol Size E: " + ac1.getAtomCount() + " , Mol Size P: " + ac2.getAtomCount());
                }
                if (mcsMatch) {
                    if (DEBUG) {
                        out.println(eductList.get(substrateIndex) + " <=> " + productList.get(productIndex));
                    }
                    delta += graphMatching.removeMatchedAtomsAndUpdateAAM(reaction);
                    List<MolMapping> rMap = getReactionMolMapping().
                            getMapping(reactionName, this.eductList.get(substrateIndex), this.productList.get(productIndex));
                    for (MolMapping map : rMap) {
                        map.setReactionMapping(true);
                        IAtomContainer mol = graphMatching.getMatchedPart();
                        mol = canonLabeler.getCanonicalMolecule(mol);
                        CDKSMILES cdkSmiles = new CDKSMILES(mol, true, false);
                        map.setMatchedSMILES(cdkSmiles.getCanonicalSMILES(), ++stepIndex);
                    }
                }
                IAtomContainer remainingEduct = graphMatching.getRemainingEduct();
                IAtomContainer remainingProduct = graphMatching.getRemainingProduct();

                reactionStructureInformationContainer.putEduct(substrateIndex, remainingEduct);
                reactionStructureInformationContainer.putProduct(productIndex, remainingProduct);
                reactionStructureInformationContainer.setEductModified(substrateIndex, true);
                reactionStructureInformationContainer.setProductModified(productIndex, true);
            }
        }
    }
}
 
Example 18
Source File: MappingUtility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 *
 * @param name
 * @param dir
 * @return
 * @throws FileNotFoundException
 * @throws CDKException
 */
public IAtomContainer readMDLMolecule(String name, String dir) throws FileNotFoundException, CDKException {
    String filepath = dir + name + ".mol";
    MDLV2000Reader reader = new MDLV2000Reader(new FileReader(filepath));
    IAtomContainer AtomContainer = reader.read(new AtomContainer());
    AtomContainer.setID(name);
    return AtomContainer;
}