Hi Zheng,

Unless the molecule is a query the IteratingSDFReader (using MDLV2000Reader) 
will automatically add the implicit hydrogens for you - however your code is 
still correct. Do you have an example input molecule?

You are correct in presuming ‘getBond(IAtom, IAtom)’ for the atom container may 
be slow. There isn’t a connivence method to do this but a good way is to create 
a map with a commutative tuple key. For example...

Map<AtomPair,IBond> bondMap = new HashMap<>();
 
for (IBond bond : container.bonds())
    bondMap.put(new AtomPair(bond.getAtom(0), bond.getAtom(1)), 
                bond);
// where AtomPair...                
class AtomPair { 
    IAtom a, b;
    AtomPair(IAtom a, IAtom b) {
        this.a = a, this.b = b;
    }
    public int hashCode() {
       return a.hashCode() ^ b.hashCode();
    }
    public boolean equals(Object obj) {
        // null check etc
        AtomPair that = (AtomPair) obj;
        return this.a.equals(that.a) && this.b.equal(that.b) || 
this.a.equals(that.b) && this.b.equal(that.a);
    } 
}

J

> Begin forwarded message:
> 
>> From: Zheng Shi <[email protected]>
>> Date: 13 September 2014 22:34:39 BST
>> To: John May <[email protected]>
>> Subject: questions about adding implicit hydrogen and get paths of a certain 
>> length in a molecule
>> 
>> Hi, John,
>> 
>> Thanks for you help.
>> 
>> I have some questions to ask you again. First is adding implicit hydrogen 
>> for a given molecule. I write as below, but when I want to see the result, 
>> it seems the implicit hydrogen is not added. I hope you could help.
>> IAtomContainer container = sdfr.next();
>>                      CDKHydrogenAdder adder = 
>> CDKHydrogenAdder.getInstance(container.getBuilder());
>>                      
>> AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container);
>>                      adder.addImplicitHydrogens(container);
>>                      System.out.println(container);
>> The other question is that I can use the class of PathTools to get paths of 
>> given length in a molecule. But the result is a list of atoms along the 
>> paths. I just wonder how I can get the bonds along the paths. I know using 
>> getbond() for two atoms. The problem is that I have to use getbond() again 
>> and again for every two atoms along the path. Is there a efficient way to do 
>> this? Thank you.
> ------------------------------------------------------------------------------
> Want excitement?
> Manually upgrade your production database.
> When you want reliability, choose Perforce
> Perforce version control. Predictably reliable.
> http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk_______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user

------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to