On Fri, Mar 27, 2009 at 4:56 PM, Markus Hartenfeller
<hartenfel...@bioinformatik.uni-frankfurt.de> wrote:
> Thanks again. Now it works!

Excellent.

> I attached a code fragment that converts a "normal" molecule into a
> NoNotifying one.
> My code runs 3x faster with these molecules without any consequence on the
> results.

Nice! That's much bigger an improvement that the tests I ran in the
past; it indeed very much depends on how often the molecule is
changed.

> Probably useful to anyone who deals with many molecules that get manipulated
> a lot.

Yes, I should write this up in my blog... some comments on the code below:

>     private IMolecule makeMolNoNotifying(IMolecule mol){
>         IMolecule nnMol =
> NoNotificationChemObjectBuilder.getInstance().newMolecule(mol);
>
>        //*atoms
>         Iterator atoms = nnMol.atoms();
>
>         int countAtoms =0;
>
>         while(atoms.hasNext()){
>             IAtom at = (Atom)atoms.next();

1. make sure to cast to the interface not the implementation:

Iterator atoms = nnMol.atoms();
while(atoms.hasNext()) {
  IAtom at = (IAtom)atoms.next();

2. you can als use the for syntax to merge the above three lines:

for (IAtom at : nnMol.atoms()) {

>        //* bonds
>         Iterator bonds = nnMol.bonds();
>
>         int countBonds =0;
>         IBond[] newBonds = new IBond[mol.getBondCount()];
>
>         while(bonds.hasNext()){
>             IBond oldBond = (Bond)bonds.next();

Likewise, cast to IBond, possibly use for().

Question: why do you need to convert it into a NNMolecule? Most file
IO methods allow you to pass a NoNotification object too... which code
are you using that returns a Molecule, instead of allowing you to have
it return a NoNotification object? That is... what CDK code requires
you to actually make the conversion?

The idea of these interfaces is something like this:

public class MyCode {

  public void main() {
    // 1. decide what implementation you want to use
    // 2. set up your data using this builder
    // 3. use the CDK to process the data in this chosen implementation
    // 4. output results
  }

}

So, the idea is that you pick on the implementation of your choice on
beforehand (e.g. the NoNotification implementation), and never
actually use any other implementation... I know not all CDK code
allows this yet, but if you tell me what CDK code you are using that
still has hardcoded use of Molecule (data module implementation), I'll
fix that asap...

BTW, to all others listening in: all CDK code is supposed to use
interfaces, not one of the implementations (unit tests excepted), but
not all code does that. Converting it is a lot of work, but clearly of
benefit of users. If you are using some code that still uses Molecule
(etc) instead of IMolecule (etc), please file a bug report.

Egon

-- 
Post-doc @ Uppsala University
http://chem-bla-ics.blogspot.com/

------------------------------------------------------------------------------
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to