data structure design question
Felix Thibault
felixt at dicksonstreet.com
Sun Feb 20 20:36:03 EST 2000
More information about the Python-list mailing list
Sun Feb 20 20:36:03 EST 2000
- Previous message (by thread): data structure design question
- Next message (by thread): data structure design question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 14:02 2/17/00 GMT, Michael Zawrotny wrote: >On 17 Feb 2000 08:45:10 GMT, Thomas Hamelryck <thamelry at vub.ac.be> wrote: <Thomas explains that a graph is good for storing the connectivity of a molecule, but I need another way to store bond information. He mentions the approach used by X-PLOR, associating types with atoms and looking up information on bonds between atoms of a certain type in a dictionary.> <Michael points out that X-PLOR requires different atom types for e.g. the sp2 carbons in ethylene and formaldehyde and if I don't need this level of detail I could start out with just types for sp, sp2 and sp3 and get most of the geometry without an explosion in atom types> What I want to model is an oscillating reaction (the Belousov= Zhabotinsky reaction) and I had a scheme like this in mind: class Atom(QNode): .... class Molecule(QGraph): Node = Atom .... class Solute(Molecule): def __init__(self, concentration, *substargs): self.conc = concentration apply(Substance.__init__, (self,)+substargs) .... class Solvent(Molecule): def __init__(self, fraction, *substargs): self.frac = fraction apply(Substance.__init__, (self,)+substargs) .... class Solution: def __init__(self, solvents, solutes, volume): """set initial concentrations""" def reaction1(self): """use rate law to get changes in concentration""" .... def react(self, iterations, step=1): """run all reactions and update concentrations, every step iterations, store concentrations in the return value""" So, to begin with, the Molecule objects would just do a few things, like calculate their molecular mass, and the meat of the module would be in the reaction methods. I was thinking, though, that if I chose the right data structure for the molecules to begin with, it would be easier to do more at lower levels, later, or to drop in something like MMTK, that would make the Molecules behave so that the reactions were more...automatic. Well, that's probably asking a little too much :) But right now, I'm looking at graphs made of these: class QNode: """QNode -> nodes which keep a count of how many times they are linked """ def __repr__(self): return self._name + `self._index` def __init__(self, name, index): self._name = name self._index = index self.links = {} def link(self, other): """link(other) Set to one/increment link count to node""" self.links[other] = self.links.get(other, 0) + 1 def delink(self, other): """delink(other) Decrement/delete link count to node""" self.links[other] = self.links.get(other, 1) - 1 if not self.links[other]: del self.links[other] ...but maybe there's something I'm not getting and it's a Bad Idea for nodes to carry bond order ?
- Previous message (by thread): data structure design question
- Next message (by thread): data structure design question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list