Hi all,

I wanted to contribute sth (instead of just sending bugs and feature
requests): here is how I used UniversalIsomorphismTester.getOverlaps to
compute the MCS for more than just 2 Molecules (runtime is of course
O(n^2)).
(I hope its not yet included in CDK, havent found it, though).

Best regards,
Martin

org.openscience.cdk.isomorphism.MultiMCSComputer
[[[
package org.openscience.cdk.isomorphism;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;

public class MultiMCSComputer
{
    public static IAtomContainer computeMCS(IAtomContainer mols[]) throws
CDKException
    {
        // sort according to number of atoms in ascending order to reduce
computational effort
        Arrays.sort(mols, new Comparator<IAtomContainer>()
        {
            @Override
            public int compare(IAtomContainer o1, IAtomContainer o2)
            {
                return new Integer(o1.getAtomCount()).compareTo(new
Integer(o2.getAtomCount()));
            }
        });

        List<IAtomContainer> candidates = new ArrayList<IAtomContainer>();
        // iterate over compounds
        for (IAtomContainer mol : mols)
        {
            mol = new
Molecule(AtomContainerManipulator.removeHydrogens(mol));
            if (candidates.size() == 0)
            {
                // if == first compound, add compound to candidates
                candidates.add(mol);
            }
            else
            {
                // else compute mcs of all candidates with this compound,
use results as new candidates
                List<IAtomContainer> newCandiates = new
ArrayList<IAtomContainer>();
                for (IAtomContainer can : candidates)
                {
                    List<IAtomContainer> canMCS =
UniversalIsomorphismTester.getOverlaps(can, mol);
                    for (IAtomContainer m : canMCS)
                        if (m.getAtomCount() > 0)
                            newCandiates.add(m);
                }
                candidates = newCandiates;
                if (candidates.size() == 0)
                    return null;
            }
        }
        IAtomContainer max = null;
        for (IAtomContainer mol : candidates)
            if (max == null || mol.getAtomCount() > max.getAtomCount())
                max = mol;
        return max;
    }
}
]]]



-- 
Dipl-Inf. Martin Gütlein
Phone:
+49 (0)761 203 7633 (office)
+49 (0)177 623 9499 (mobile)
Email:
[email protected]
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to