--[[ link NH spin systems with matching connections ]] --[[ using HncocaNH and hNcocaNH data ]] --[[ pick spin systems and H+1, N+1 correlations before running this script]] t = {} t.project=cara:getProject() t.Systems=t.project:getSystems() --t.Hdelta = 0.02 --t.Ndelta = 0.2 t.Hdelta = dlg.getDecimal("LinkNH","HN tolerance (ppm) = ",0.02) t.Ndelta = dlg.getDecimal("LinkNH","N tolerance (ppm) = ",0.2) t.newSystems = 0 t.connection = 0 t.unresolved = 0 -- -------------------------------------------------------------- for id1,system in pairs(t.Systems) do t.Spins = system:getSpins() t.succHshift=nil t.succNshift=nil if system:getSucc() == nil then for id2,spin in pairs(t.Spins) do t.Spin = spin:getLabel() if t.Spin=="H+1" then t.succHshift=spin:getShift() end if t.Spin=="N+1" then t.succNshift=spin:getShift() end end -- -------------------------------------------------------------- if t.succHshift~=nil and t.succNshift~=nil then -- find the succeeding system t.matchfound = 0 for id3,system2 in pairs(t.Systems) do t.Spins2 = system2:getSpins() t.matchHshift=nil t.matchNshift=nil for id2,spin2 in pairs(t.Spins2) do t.Spin2 = spin2:getLabel() if t.Spin2=="H" then t.matchHshift=spin2:getShift() end if t.Spin2=="N" then t.matchNshift=spin2:getShift() end end if t.matchHshift~=nil and t.matchNshift~=nil then t.Hdiff = ((t.succHshift-t.matchHshift)/t.Hdelta)^2 t.Ndiff = ((t.succNshift-t.matchNshift)/t.Ndelta)^2 if math.sqrt(t.Hdiff + t.Ndiff) < 1.0 then -- print(id1, "Hurray!", id3, t.succHshift, t.succNshift) t.succSystem = system2 t.matchfound = t.matchfound + 1 end end end if t.matchfound >= 2 then t.unresolved = t.unresolved + 1 print("Ambiguous connections found for system: "..system:getId()) else if t.matchfound == 0 then -- create new spin system t.newSystems = t.newSystems + 1 t.succSystem = t.project:createSystem() --t.succ = table.getn(t.project:getSystems()) t.succHspin = t.project:createSpin("H", t.succHshift) t.project:assignSpin(t.succHspin, t.succSystem) t.project:setLabel(t.succHspin, "H") t.succNspin = t.project:createSpin("N", t.succNshift) t.project:assignSpin(t.succNspin, t.succSystem) t.project:setLabel(t.succNspin, "N") end t.succ = t.succSystem:getId() if t.succSystem:getPred() == nil then t.project:linkSystems(system, t.succSystem) t.connection = t.connection + 1 print("Spin systems "..id1.." and "..t.succ.." linked.") else print("Spin system "..id1.." attempted target "..t.succ.." already linked.") end end end else print("Spin system "..id1.." already linked.") end end dlg.showInfo("Done", t.connection.." spin systems linked.\n"..t.newSystems.." new systems created.\n"..t.unresolved.." ambiguous connections.") t = nil