mercredi 2 décembre 2020

UnboundLocalError: local variable 'ff_cog' referenced before assignment, unsolved

I have got this piece of code that does not really want to work. I already tried to use Global, but it gave me a different mistake error (it tells me that ff_cog is not defined in that way), I tried to change the position of "numat", which was over the if statement before, but nothing changed. Can someone Helps me, please? I am 100% sure that there are valuee greater than dp. This if statement should be used to select the smallest distance among all the atoms whil they are calculated. I cannot understand why it gives me this problem. I am using a similar for loop other two times in my program and it seems to work just fine. It`s the first time I come across with this error. many thanks in advance

def ff(furthestcoord):
   #global ff_cog
   numat=0
   dp=np.zeros(0)
   for atom in mol.GetAtoms():
       atom_pos=np.array(mol.GetConformer().GetAtomPosition(numat))
       ffdist=np.array(np.linalg.norm(furthestcoord-atom_pos))
       print("this is ffdist",ffdist)
       if ffdist > dp:
            dp = atom_pos
            ff_cog = atom_pos
       else: pass
       numat+=1
   return ff_cog
``


Aucun commentaire:

Enregistrer un commentaire