Skip to content

DP4 analysis using NMR descriptor file fails #79

@PeteGierth

Description

@PeteGierth

When supplying an NMR descriptor file rather than raw NMR data, the importing of the proton shifts doesn't work properly- one of the arrays used is just filled with the first shift value. Error is returned, e.g.:

**Hshifts: [6.89, 6.73, 3.81, 3.81, 3.81, 3.6, 3.6, 3.6, 2.3, 2.3, 2.3, 2.0, 2.0, 2.0]
Equivalents: []
Omits: []

Calculating DP4 probabilities...
Traceback (most recent call last):
File "/home/nmr/DP5-master/PyDP4.py", line 843, in
main(settings)
File "/home/nmr/DP5-master/PyDP4.py", line 529, in main
DP4data = DP4.InternalScaling(DP4data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nmr/DP5-master/DP4.py", line 139, in InternalScaling
DP4data.Hscaled.append(ScaleNMR(Hshifts, Hexp))
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nmr/DP5-master/DP4.py", line 151, in ScaleNMR
slope, intercept, r_value, p_value, std_err = stats.linregress(expShifts,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nmr/anaconda3/envs/dp5/lib/python3.11/site-packages/scipy/stats/_stats_mstats_common.py", line 157, in linregress
raise ValueError("Cannot calculate a linear regression "
ValueError: Cannot calculate a linear regression if all x values are identical**

However inspection of the variable that inputs to the regression shows it just contains 6.89,6.89,6.89....

In NMR.py we have :

exp_ind = 0

    for shift ,label in zip( sortedCCalc , sortedClabels):

        if label not in NMRData.Omits:

            ind = tempCCalcs.index(shift)

            assignedCExp[ind] = sortedCExp[exp_ind]

            tempCCalcs[ind] = ''

            exp_ind += 1

    # Proton

    exp_ind = 0

    for shift,label in zip( sortedHCalc,sortedHlabels):

        if label not in NMRData.Omits:

            ind = tempHCalcs.index(shift)

            assignedHExp[ind] = sortedHExp[exp_ind]

            tempHCalcs[ind] = ''

    # update isomers class

    iso.Cexp = assignedCExp
    iso.Hexp = assignedHExp

ie there is no increment of the index for reading the proton shifts here. Inserting exp_ind += 1 after tempHCalcs[ind] = '' solves the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions