Hi Egon,

Thanks again. Now it works!

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.

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

Best regards
Markus



/**
* This method creates a NoNotification version of the given molecule. That means that the returned molecule does not fire * ChemObjectChangedEvents everytime anything is changed. this speeds up the process especially if a lot of modification
    * are applied.
    *
* @return: molecule that has the same connectivity, same atoms, same formal charges and same bond orders as the original one but does not fire * ChemObjectChangedEvents. AtomTypes and other properties like aromaticity are NOT copied to returned molecule by now.
    *
    */
   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();
nnMol.setAtom(countAtoms,nnMol.getBuilder().newAtom(at.getSymbol())); nnMol.getAtom(countAtoms).setFormalCharge(mol.getAtom(countAtoms).getFormalCharge()); //set charge to new atom countAtoms++;
       }
//* bonds
       Iterator bonds = nnMol.bonds();
int countBonds =0;
       IBond[] newBonds = new IBond[mol.getBondCount()];
while(bonds.hasNext()){
           IBond oldBond = (Bond)bonds.next();
newBonds[countBonds] = nnMol.getBuilder().newBond(nnMol.getAtom(mol.getAtomNumber(oldBond.getAtom(0))), nnMol.getAtom(mol.getAtomNumber(oldBond.getAtom(1))), oldBond.getOrder()); countBonds++;
       }
nnMol.setBonds(newBonds); return nnMol;
   }



Egon Willighagen schrieb:
On Thu, Mar 26, 2009 at 4:20 PM, Markus Hartenfeller
<hartenfel...@bioinformatik.uni-frankfurt.de> wrote:
I have tried that for every molecule I am using:

IMolecule x ...
x = NoNotificationChemObjectBuilder.getInstance().newMolecule(libFrag);

But still profiling tells me that a lot of time is spent at method
notifyChanged() and that I have nearly 500.000 (still growing) instances of
the class ChemObjectChangedEvent in memory, nearly all referenced by class
Atom (some by Bond).

So that does not seem to fix it.
Any ideas?

What code are you using in your profiling? The code that modifies the
molecule must use the x.getBuilder.newAtom() methods... Same applies
to libFrag, that must be created using the
NoNotificationChemObjectBuilder too...

If you could post the full code, then I can check it for you...

Egon



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

Reply via email to