From: Rajarshi G. <rg...@in...> - 2007-07-24 15:34:03
|
On Jul 24, 2007, at 7:52 AM, Stefan Kuhn wrote: >> What if an IAtomContainer is created as a shallow copy of another >> one - which parent should be pointed by IAtom instances? >> I vaguely remember there are (has been) procedures doing shallow >> copies >> of atom containers. > The same problem could arise with AtomContainers and Rings. If I > remember it > correctly Molecule extends AtomContainer and Ring does as well. So > if you > have a Molecule or AtomContainer and do a RingSearch on it, you get > back Ring > objects containing the same atoms as the original Molecule - or the > ring > searches would need to do deep copies, which is often not desired, > since you > want be able to compare atoms in the Rings and the original > AtomContainer > with This is one aspect that has puzzled me from time to time. If I understand correctly, the way that the CDK checks for equality of two IAtom objects is by testing their hashcode. I realize that this is very fast, but the side effect of this is that different atom containers can refer to the same atom (as in the example above). This is handy in many ways since you can avoid doing deep copies, but also can lead to obscure code. Why doesn't the equals() method check the properties of the two atoms (say, symbol, coordinates, charge, num bonds etc)? It seems that this would allow one to maintain the current status quo (of avoiding deep copies) but also allow one to compare deep copies properly. [Conceptually, if two atoms have the same properties they should be equal even if their hashcodes differ] ------------------------------------------------------------------- Rajarshi Guha <rg...@in...> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- Q: What's polite and works for the phone company? A: A deferential operator. |