I am getting an error when I call a subclass from another class, but not when I call it directly. It seems that when I create an instance of this subclass from a different class the information in the superclass is not getting passed to the subclass.
class HBatom(object):
def __init__(self, struct, sele, **kwargs):
self.struct = struct
self.sele = sele
class HDonor(HBatom):
def __init__(self,struct,sele,**kwargs):
super(HDonor,self).__init__(struct,sele,**kwargs)
self.find_H()
def find_H(self):
bonded = self.struct.select(''.join(["bonded to ", self.sele.getSelstr()]))
This works
import HBonds
HB = HBonds.HDonor(structure,Nsel,f_wat=1)
But when I create an instance of a class that contains a dictionary of HDonors and then tell it to populate I get an error
HN = HBonds.HNtwrk(structure,1)
HN.build_HNtwrk()
AttributeError: 'HDonor' object has no attribute 'sele'
Executing with pdb shows me that in the second case self contains no attributes of the HBatom parent class. How is it possible for self to contain that info in the first case but not in the second?
Sorry, I didn't include HNtwrk in the original post. The total code is almost 400 lines, so I don't want to include more than necessary. Here are the relevant parts of HNtwrk
class HNtwrk:
def __init__(self,structure, f_wat = 0):
self.f_wat = f_wat
self.struct = structure
self.rh_o = 2.5
self.rn_o = 3.5
self.Dons = dict()
self.Accs = dict()
def build_HNtwrk(self):
Dsele = self.struct.select(DonStr)
Asele = self.struct.select(AccStr)
self.addDons(Dsele)
self.addAccs(Asele)
def addDons(self, Dsele):
for pairs in iterNeighbors(Dsele,self.rn_o,Asele):
iN = pairs[0].getIndices()[0]
iA = pairs[1].getIndices()[0]
if iN not in self.Dons:
Hdon = HDonor(self.struct,pairs[0].getSelstr,f_wat=self.f_wat)
self.Dons[iN] = Hdon
The code trips when I set Hdon because HDonor.find_H() requires HBatom attributes. It is as if HBatom.__init__() is not called during the HDonor init when an HDonor instance is created from HNtwrk. Just to be clear, HNtwrk appears in the same file as the other classes.