Menu

#1304 makeAtomsMapOfBondsMap in Isomorphism does not support IQueryAtom objects?

cdk-1.4.x
open
nobody
smsd (4)
5
2016-08-10
2013-06-07
Duece99
No

Hello,

Check this code in the Isomorphism class:

public static Map<IBond, IBond> makeBondMapOfAtomMap(IAtomContainer ac1, IAtomContainer ac2, Map<IAtom, IAtom> mapping) {
        Map<IBond, IBond> maps = new HashMap<IBond, IBond>();

        for (Map.Entry<IAtom, IAtom> mapS : mapping.entrySet()) {
            IAtom indexI = mapS.getKey();
            IAtom indexJ = mapS.getValue();

            for (Map.Entry<IAtom, IAtom> mapD : mapping.entrySet()) {
                IAtom indexIPlus = mapD.getKey();
                IAtom indexJPlus = mapD.getValue();

                if (!indexI.equals(indexIPlus) && !indexJ.equals(indexJPlus)) {
                    IBond ac1Bond = ac1.getBond(indexI, indexIPlus);
                    if (ac1Bond != null) {
                        IBond ac2Bond = ac2.getBond(indexJ, indexJPlus);
                        if (ac2Bond != null) {
                            maps.put(ac1Bond, ac2Bond);
                        }
                    }
                }
            }
        }

//        System.out.println("bond Map size:" + maps.size());

        return maps;

    }

This won't work with SMARTS queries as often the bond order is ignored. Surely it should be something like this:

if (ac1Bond != null) {
                       IBond ac2Bond = ac2.getBond(indexJ, indexJPlus);
                       if (ac2Bond != null) {

                           if( ac1Bond instanceof IQueryBond ) {
                               if( ((IQueryBond) ac1Bond).matches(ac2Bond) ) {
                                   maps.put(ac1Bond, ac2Bond);
                               }
                           else {
                               if( ac1Bond.getOrder().equals( ac2Bond.getOrder() ) )
                                   maps.put(ac1Bond, ac2Bond);
                               }
                           }
                       }
                   }

Ed.

Discussion

  • John May

    John May - 2013-06-07

    Have forwarded to Asad as he can answer better. However, I don't think so. This method is called after the matching has been done. It's not really clear what the bug your reporting is Ed but it would be a bad idea to hard code in order matching with an if/else.

     
  • Duece99

    Duece99 - 2013-06-07

    Hi,

    The "bug" is that when an IQueryAtomContainer is used instead of a straight AtomContainer as the molecule, the bond map making method still matches on straight bond order rather than on the particular bond query used.

    Yeah Ideally I'd use a single statement to perform the bond-matching rather than the if-else clause, but AFAIK there's no "matches()" method for straight IBond objects (only a compare method which is different). Not sure what to replace it with.

    Ed.

     
  • Egon Willighagen

    • labels: --> smsd
     
  • Egon Willighagen

    An SMSD bug.