How to slice a 4D ucsf file and save the 2D plane a Pipe file?

17 views
Skip to first unread message

Thomas Evangelidis

unread,
Mar 9, 2024, 8:54:16 AMMar 9
to nmrglue-discuss
Greetings,

I have the following script that reads a 4D ucsf file, converts it to Pipe format, extracts a 2D plane at the HC, C dimensions, and writes it to a .ft2 file.

file_path = "/srv/NMR/Peak_Picking/Ubiquitin/4D_HCNH_NOESY_NUS_reconstructed.ucsf"
sdic, sdata = ng.sparky.read(file_path)
sudic = ng.sparky.guess_udic(sdic, sdata)

C = ng.convert.converter()
C.from_sparky(sdic, sdata, sudic)
pdic, pdata = C.to_pipe()

udic = ng.pipe.guess_udic(pdic, pdata)

uc = {
"hc": ng.fileiobase.uc_from_udic(udic, dim=0), # HC dimension
"c": ng.fileiobase.uc_from_udic(udic, dim=1), # C dimension
"n": ng.fileiobase.uc_from_udic(udic, dim=2), # N dimension
"hn": ng.fileiobase.uc_from_udic(udic, dim=3), # HN dimension
}

# Specific N and HN values for filtering
n_ppm = 115.438
hn_ppm = 8.671

# Convert N and HN ppm values to bin indices
N_bin_index = uc["n"](n_ppm, "ppm")
HN_bin_index = uc["hn"](hn_ppm, "ppm")

data_slice = pdata[:, :, int(N_bin_index), int(HN_bin_index)].real

output_file_path = "/srv/NMR/Peak_Picking/Ubiquitin/Hc-C_slice.ft2"

ng.pipe.write(output_file_path, pdic, data_slice, overwrite=True)


pdata has the correct dimensions: 400x160x160x352, which correspond to the number of bins of the HC,C,N,HN  dimensions in the input ucsf file. So I believe that data_slice contains the correct spectral densities.
However, pdic has the axes in the wrong order (as you can see below): N,HN,C,HC instead of HC,C,N,HN.


{'FDMAGIC': 0.0, 'FDFLTFORMAT': 4008636160.0, 'FDFLTORDER': 2.3450000286102295, 'FDSIZE': 352.0, 'FDREALSIZE': 352.0, 'FDSPECNUM': 160.0, 'FDQUADFLAG': 1.0, 'FD2DPHASE': 2.0, 'FDTRANSPOSED': 0.0, 'FDDIMCOUNT': 4.0, 'FDDIMORDER': [2.0, 1.0, 3.0, 4.0], 'FDDIMORDER1': 2.0, 'FDDIMORDER2': 1.0, 'FDDIMORDER3': 3.0, 'FDDIMORDER4': 4.0, 'FDNUSDIM': 0.0, 'FDPIPEFLAG': 0.0, 'FDCUBEFLAG': 0.0, 'FDPIPECOUNT': 0.0, 'FDSLICECOUNT': 0.0, 'FDSLICECOUNT1': 0.0, 'FDFILECOUNT': 160.0, 'FDTHREADCOUNT': 0.0, 'FDTHREADID': 0.0, 'FDFIRSTPLANE': 0.0, 'FDLASTPLANE': 0.0, 'FDPARTITION': 0.0, 'FDPLANELOC': 0.0, 'FDMAX': 0.0, 'FDMIN': 0.0, 'FDSCALEFLAG': 0.0, 'FDDISPMAX': 0.0, 'FDDISPMIN': 0.0, 'FDPTHRESH': 0.0, 'FDNTHRESH': 0.0, 'FDUSER1': 0.0, 'FDUSER2': 0.0, 'FDUSER3': 0.0, 'FDUSER4': 0.0, 'FDUSER5': 0.0, 'FDUSER6': 0.0, 'FDLASTBLOCK': 0.0, 'FDCONTBLOCK': 0.0, 'FDBASEBLOCK': 0.0, 'FDPEAKBLOCK': 0.0, 'FDBMAPBLOCK': 0.0, 'FDHISTBLOCK': 0.0, 'FD1DBLOCK': 0.0, 'FDMONTH': 3.0, 'FDDAY': 9.0, 'FDYEAR': 2024.0, 'FDHOURS': 13.0, 'FDMINS': 10.0, 'FDSECS': 3.0, 'FDMCFLAG': 0.0, 'FDNOISE': 0.0, 'FDRANK': 0.0, 'FDTEMPERATURE': 0.0, 'FDPRESSURE': 0.0, 'FD2DVIRGIN': 1.0, 'FDTAU': 0.0, 'FDDOMINFO': 0.0, 'FDMETHINFO': 0.0, 'FDSCORE': 0.0, 'FDSCANS': 0.0, 'FDSRCNAME': '', 'FDUSERNAME': '', 'FDOPERNAME': '', 'FDTITLE': '', 'FDCOMMENT': '', 'FDF2LABEL': 'HN', 'FDF2APOD': 0.0, 'FDF2SW': 2455.357177734375, 'FDF2OBS': 600.0527954101562, 'FDF2OBSMID': 0.0, 'FDF2ORIG': 3580.5758865861044, 'FDF2UNITS': 0.0, 'FDF2QUADFLAG': 1.0, 'FDF2FTFLAG': 1.0, 'FDF2AQSIGN': 0.0, 'FDF2CAR': 8.00142765045166, 'FDF2CENTER': 177.0, 'FDF2OFFPPM': 0.0, 'FDF2P0': 0.0, 'FDF2P1': 0.0, 'FDF2APODCODE': 0.0, 'FDF2APODQ1': 0.0, 'FDF2APODQ2': 0.0, 'FDF2APODQ3': 0.0, 'FDF2LB': 0.0, 'FDF2GB': 0.0, 'FDF2GOFF': 0.0, 'FDF2C1': 0.0, 'FDF2APODDF': 0.0, 'FDF2ZF': 0.0, 'FDF2X1': 0.0, 'FDF2XN': 0.0, 'FDF2FTSIZE': 352.0, 'FDF2TDSIZE': 0.0, 'FDDMXVAL': 0.0, 'FDDMXFLAG': 0.0, 'FDDELTATR': 0.0, 'FDF1LABEL': 'N', 'FDF1APOD': 0.0, 'FDF1SW': 1411.4329833984375, 'FDF1OBS': 60.80984115600586, 'FDF1OBSMID': 0.0, 'FDF1ORIG': 6601.650821324775, 'FDF1UNITS': 0.0, 'FDF1FTFLAG': 1.0, 'FDF1AQSIGN': 0, 'FDF1QUADFLAG': 1.0, 'FDF1CAR': 120.02244567871094, 'FDF1CENTER': 81.0, 'FDF1OFFPPM': 0.0, 'FDF1P0': 0.0, 'FDF1P1': 0.0, 'FDF1APODCODE': 0.0, 'FDF1APODQ1': 0.0, 'FDF1APODQ2': 0.0, 'FDF1APODQ3': 0.0, 'FDF1LB': 0.0, 'FDF1GB': 0.0, 'FDF1GOFF': 0.0, 'FDF1C1': 0.0, 'FDF1ZF': 0.0, 'FDF1X1': 0.0, 'FDF1XN': 0.0, 'FDF1FTSIZE': 160.0, 'FDF1TDSIZE': 0.0, 'FDF3LABEL': 'C', 'FDF3APOD': 0.0, 'FDF3OBS': 150.8885955810547, 'FDF3OBSMID': 0.0, 'FDF3SW': 8756.5673828125, 'FDF3ORIG': 1550.1603368850192, 'FDF3FTFLAG': 1.0, 'FDF3AQSIGN': 0.0, 'FDF3SIZE': 160.0, 'FDF3QUADFLAG': 1.0, 'FDF3UNITS': 0.0, 'FDF3P0': 0.0, 'FDF3P1': 0.0, 'FDF3CAR': 38.92749786376953, 'FDF3CENTER': 81.0, 'FDF3OFFPPM': 0.0, 'FDF3APODCODE': 0.0, 'FDF3APODQ1': 0.0, 'FDF3APODQ2': 0.0, 'FDF3APODQ3': 0.0, 'FDF3LB': 0.0, 'FDF3GB': 0.0, 'FDF3GOFF': 0.0, 'FDF3C1': 0.0, 'FDF3ZF': 0.0, 'FDF3X1': 0.0, 'FDF3XN': 0.0, 'FDF3FTSIZE': 160.0, 'FDF3TDSIZE': 0.0, 'FDF4LABEL': 'HC', 'FDF4APOD': 0.0, 'FDF4OBS': 600.0540161132812, 'FDF4OBSMID': 0.0, 'FDF4SW': 7142.85693359375, 'FDF4ORIG': 437.5167080640049, 'FDF4FTFLAG': 1.0, 'FDF4AQSIGN': 0.0, 'FDF4SIZE': 1.0, 'FDF4QUADFLAG': 1.0, 'FDF4UNITS': 0.0, 'FDF4P0': 0.0, 'FDF4P1': 0.0, 'FDF4CAR': 6.651214599609375, 'FDF4CENTER': 201.0, 'FDF4OFFPPM': 0.0, 'FDF4APODCODE': 0.0, 'FDF4APODQ1': 0.0, 'FDF4APODQ2': 0.0, 'FDF4APODQ3': 0.0, 'FDF4LB': 0.0, 'FDF4GB': 0.0, 'FDF4GOFF': 0.0, 'FDF4C1': 0.0, 'FDF4ZF': 0.0, 'FDF4X1': 0.0, 'FDF4XN': 0.0, 'FDF4FTSIZE': 400.0, 'FDF4TDSIZE': 0.0}

As a result, the output ft2 spectrum has HN, N dimensions (not even N,HN as I would expect), instead of HC,C.
How can I instruct ng.pipe.write() to extract the correct dimensions from pdic? 

I thank you in advance.
Thomas
Reply all
Reply to author
Forward
0 new messages