This might be a dumb question, but say i want to build a program from bottom-up like so:
class Atom(object):
def __init__(self):
'''
Constructor
'''
def atom(self, foo, bar):
#...with foo and bar being arrays of atom Params of lengths m & n
"Do what atoms do"
return atom_out
...i can put my instances in a dictionary:
class Molecule(Atom):
def __init__(self):
def structure(self, a, b):
#a = 2D array of size (num_of_atoms, m); 'foo' Params for each atom
#b = 2D array of size (num_of_atoms, n); 'bar' Params for each atom
unit = self.atom()
fake_array = {"atom1": unit(a[0], b[0]),
"atom2": unit(a[1], b[1]),
: : :
: : :}
def chemicalBonds(self, this, that, theother):
: : :
: : :
My question is, is there a way to do this with numpy arrays so that each element in "real_array" would be an instance of atom--i.e., the output of the individual computations of atom function? I can extend this to class Water(molecule): which would perform fast numpy operations on the large structure and chemicalBonds outputs, hence the need for arrays...Or is it the case that i'm going about this the wrong way?
Also if i am on the right track, i'd appreciate if you wanted to throw in any tips on how to structure a "hierarchical program" like this, as i'm not sure i'm doing the above correctly and recently discovered that i don't know what i'm doing.
Thanks in advance.
self.unit = self.atom()-- aren't you missing the args in the function call? what isreal_array? what types are the elements ina, b, x, y, foo, bar?fake_arrayis a dictionary of instances soreal_arraywould replacefake_arraybut be a numpy array of instances instead.self.unitis the local variable for the function,atominherited from the lower class (which now i see should be calledunitinstead). The args are passed intounitthrough thestructurefunction. So if i wanted to describe a water molecule, i'd have mystructureas output an "array" containing[hydrogen1]: self.unit(hydrogen1 params),[hydrogen2]: self.unit(hydrogen2 params),[oxygen]: self.unit(oxygen params). Clearer?