Goodman-lab / DP5

Python workflow for DP5 and DP4 analysis of organic molecules
Other
175 stars 102 forks source link

UnboundLocalError: local variable 'labels' referenced before assignment #28

Closed WeiYongqiang55 closed 4 years ago

WeiYongqiang55 commented 4 years ago

File "PyDP4.py", line 293, in main Isomers = DFT.ReadShieldings(Isomers) File "/home/wyq/Downloads/DP4-AI-master3/DP4-AI-master/Gaussian.py", line 504, in ReadShieldings iso.ShieldingLabels = labels UnboundLocalError: local variable 'labels' referenced before assignment

fixed by move labels=[] out second for loop

for iso in Isomers:

     labels = []
    for GOutpFile in iso.NMROutputFiles:

        gausfile = open(GOutpFile, 'r')
        GOutp = gausfile.readlines()
        gausfile.close()

        index = 0
        shieldings = []
        # labels = []

        # Find the NMR shielding calculation section
        while not 'Magnetic shielding' in GOutp[index]:
            index = index + 1

        # Read shielding constants and labels
        for line in GOutp[index:]:
            if 'Isotropic' in line:
                data = [_f for _f in line.split(' ') if _f]
                shieldings.append(float(data[4]))
                labels.append(data[1] + data[0])

        print(GOutpFile,len(shieldings))

        iso.ConformerShieldings.append(shieldings)

    iso.ShieldingLabels = labels
KristapsE commented 4 years ago

Same issue as previously - this only happens if there are no NMR output files found for that particular isomer, so probably again issue of wrong input file and/or output folder specification. There is little point in the proposed fix as there is no point in continuing with DP4 process if it has no DFT NMR data, it will just fail somehwhere later down the line. But I will improve the error message.