Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LongestAliphaticChainDescriptor doesn't work #362

Closed
johnmay opened this issue Sep 1, 2017 · 2 comments
Closed

LongestAliphaticChainDescriptor doesn't work #362

johnmay opened this issue Sep 1, 2017 · 2 comments

Comments

@johnmay
Copy link
Member

johnmay commented Sep 1, 2017

Personal communication from Nichola McCann

I am relatively new to using the cdk, but I have a question about the descriptor generation. When I calculate the Longest Aliphatic Chain (nAtomLAC) for ethanol, I get different answers, depending on how I enter the molecule. If I use CCO, I get a value of 2, but if I use OCC (the canonical version from cdk), I get 0.
I have attached below the R code that I used to generate these results – could you please explain the discrepancy?

    @Test
    public void debug() throws ClassNotFoundException, CDKException, java.lang.Exception {
        SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
        IAtomContainer mol1 = sp.parseSmiles("CCO");
        IAtomContainer mol2 = sp.parseSmiles("OCC");
        System.out.println(descriptor.calculate(mol1).getValue());
        System.out.println(descriptor.calculate(mol2).getValue());
    }
@steinbeck
Copy link
Member

steinbeck commented Sep 1, 2017 via email

@johnmay
Copy link
Member Author

johnmay commented Sep 1, 2017

Here's a correct non-optimal way of doing it but mirrors what is done ATM :-)

    private boolean isAcyclicCarbon(IAtom atom) {
        return atom.getAtomicNumber() == 6 && !atom.isInRing();
    }
    private int longestAliphaticChain(IAtomContainer mol) {
        IAtomContainer part = mol.getBuilder().newAtomContainer();
        Cycles.markRingAtomsAndBonds(mol); // ensure ring flags are set
        for (IAtom atom : mol.atoms())
            if (isAcyclicCarbon(atom))
                part.addAtom(atom);
        for (IBond bond : mol.bonds())
            if (isAcyclicCarbon(bond.getBegin()) && isAcyclicCarbon(bond.getEnd()))
                part.addBond(bond);
        AllPairsShortestPaths apsp = new AllPairsShortestPaths(part);
        int max = 0;
         // NxN can be avoided, apsp internally knows longest path
        for (int beg = 0; beg < part.getAtomCount(); beg++) {
            for (int end = 0; end < part.getAtomCount(); end++) {
                int dist = apsp.from(beg).distanceTo(end);
                if (dist > max) {
                    max = dist;
                }
            }
        }
        return 1+max;
    }

@johnmay johnmay mentioned this issue Sep 5, 2017
@egonw egonw closed this as completed in #364 Sep 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants