Difference between revisions of "User:Remig/plico/remap"

From Jmol
Jump to navigation Jump to search
(Add menu toggle)
m
 
(One intermediate revision by the same user not shown)
Line 13: Line 13:
 
Copy and paste the following to a text editor and save to your scripts directory as remap.spt:
 
Copy and paste the following to a text editor and save to your scripts directory as remap.spt:
 
<pre>#  remap - Jmol script by Ron Mignery
 
<pre>#  remap - Jmol script by Ron Mignery
#  v1.8 beta    7/24/2015 -add menu toggle
+
#  v1.10 beta    4/12/2016 -require latest common includes
 
#
 
#
 
#  Calculate or change polypeptide chain, atom number, residue names and/or residue
 
#  Calculate or change polypeptide chain, atom number, residue names and/or residue
Line 49: Line 49:
  
 
     select {atomIndex=aIdx}
 
     select {atomIndex=aIdx}
     var cSet = {selected}
+
     var sSet = {selected}
     while (cSet.size > 0) {
+
     while (sSet) {
         for (var i = 1; i <= cSet.size; i++) {
+
         for (var i = 1; i <= sSet.size; i++) {
             var idx = cSet[i].atomIndex
+
             var idx = sSet[i].atomIndex
 
             var caIdx = get_bb_nward_ca_idx(idx)
 
             var caIdx = get_bb_nward_ca_idx(idx)
 
             if (caIdx >= 0) {
 
             if (caIdx >= 0) {
                 if ({connected({atomIndex=idx}) and not {hydrogen}}.size < 2) {
+
                 var cset = connected({atomIndex=idx}) and not {hydrogen}
                     return idx
+
                var ccset = connected(cset) and not {hydrogen}
 +
                if (cset.size < 2) {
 +
                     return idx #***
 +
                }
 +
                else if (({ccset and {carbon}}.size = 3) and (ccset.size == 4)) {
 +
                    return idx #***
 
                 }
 
                 }
 
             }
 
             }
         }
+
         } # endfor
         cSet = connected({selected}) and not {selected} and not {hydrogen}
+
          
         select {selected} or cset
+
        sSet = connected({selected}) and not {selected} and not {hydrogen}
     }
+
         select {selected} or sSet
 +
     } # endwhile
 +
   
 
     return -1
 
     return -1
 
}
 
}
Line 68: Line 75:
 
# Bound to ALT-LEFT-CLICK by plico_remap
 
# Bound to ALT-LEFT-CLICK by plico_remap
 
function remap_cargo_mb() {
 
function remap_cargo_mb() {
    var f = (_frameID/1000000)
 
    var m = (_frameID%1000000)
 
 
     var idx =_atomPicked
 
     var idx =_atomPicked
  
Line 85: Line 90:
  
 
         # Prompt for new designators
 
         # Prompt for new designators
         f = {atomIndex=n0idx}.file
+
         var f = {atomIndex=n0idx}.file
         m = {atomIndex=n0idx}.model
+
         var m = {atomIndex=n0idx}.model
 
         var iResno = {atomIndex=n0idx}.resno
 
         var iResno = {atomIndex=n0idx}.resno
 
         var iChain = {atomIndex=n0idx}.chain
 
         var iChain = {atomIndex=n0idx}.chain
 
         var iNo = {atomIndex=n0idx}.atomno
 
         var iNo = {atomIndex=n0idx}.atomno
         select {(file=f) and (model=m)}
+
         select {thisModel}
 
         color {selected} @gScheme
 
         color {selected} @gScheme
         select {(chain=iChain) and (file=f) and (model=m)}
+
         select {(chain=iChain) and thisModel}
 
         color {selected} @gAltScheme
 
         color {selected} @gAltScheme
 
         refresh
 
         refresh
Line 120: Line 125:
 
     if (isValid) {
 
     if (isValid) {
  
         delete {hydrogen and (file=f) and (model=m)}
+
         delete {hydrogen and thisModel}
         delete {hoh and (file=f) and (model=m)}
+
         delete {hoh and thisModel}
         delete %B and (file=f) and (model=m)
+
         delete %B and thisModel
 
         ssbonds off
 
         ssbonds off
  
Line 141: Line 146:
 
         var proDidx = -1
 
         var proDidx = -1
 
         var oxtIdx = -1
 
         var oxtIdx = -1
         while ((nIdx >= n0idx) or (cSet.size > 0)) {
+
         while ((nIdx >= n0idx) or (cSet)) {
 
             var s = array(1, 2, 3)
 
             var s = array(1, 2, 3)
 
             var pTrp = 0
 
             var pTrp = 0
Line 334: Line 339:
 
                 else if (newAtomName == "XD") { # LEU ASP ASN
 
                 else if (newAtomName == "XD") { # LEU ASP ASN
 
                     var cTrp = (connected(cSet[2]) and not {selected})
 
                     var cTrp = (connected(cSet[2]) and not {selected})
                     var sTrp = ((trp.size > 0) ? (trp[1].element=="N") : false)
+
                     var sTrp = ((trp) ? (trp[1].element=="N") : false)
 
                     if ((cSet[2].element != "C") or sTrp
 
                     if ((cSet[2].element != "C") or sTrp
 
                         or ((connected(cSet[1]) and not {selected}).size == 0)) {
 
                         or ((connected(cSet[1]) and not {selected}).size == 0)) {
Line 515: Line 520:
 
function plico_remap() {
 
function plico_remap() {
  
     # Push selected
+
     # Load common functions if not already
     gSelSaves = {selected}
+
     if (kCommon < 7) {
 +
        script $SCRIPT_PATH$plicoCommon.spt
 +
        if (kCommon < 7) {
 +
            prompt ("A newer version of plicoCommon.SPT is required")
 +
            quit
 +
        }
 +
    }
  
     gScheme = defaultColorScheme
+
     gPlico = "Remap"
     gAltScheme = ((gScheme == "Jmol") ? "Rasmol" : "Jmol")
+
     plico_prelim(false, true)
     set echo TOP LEFT
+
      
    background ECHO yellow
+
     gEcho = "_______REMAP_______|ALT-CLICK=select chain|SHIFT-DOUBLE-CLICK=exit"
     gEcho = "_______REMAP_______|ALT-CLICK=select chain|DOUBLE-CLICK=exit"
 
 
     echo @gEcho
 
     echo @gEcho
    gChain = ""
 
    gMenuMin = false
 
    unbind
 
  
 
     set picking ON
 
     set picking ON
 
     bind "ALT-LEFT-CLICK" "_pickAtom";
 
     bind "ALT-LEFT-CLICK" "_pickAtom";
 
     bind "ALT-LEFT-CLICK" "+:remap_cargo_mb";
 
     bind "ALT-LEFT-CLICK" "+:remap_cargo_mb";
     bind "DOUBLE" "remap_exit";
+
     bind "SHIFT-DOUBLE" "plico_exit(true)";
 
     bind "LEFT-CLICK" "+:plico_menu_toggle";
 
     bind "LEFT-CLICK" "+:plico_menu_toggle";
 
}
 
}
  
# Bound to DOUBLE by plico_remap
 
function remap_exit() {
 
    unbind
 
    halo off
 
    echo
 
    var f = (_frameID/1000000)
 
    var m = (_frameID%1000000)
 
    select ((file=f) and (model=m))
 
    color {selected} @gScheme
 
    gBusy = false
 
 
    # Pop selected
 
    select gSelSaves
 
}
 
 
# End of REMAP.SPT</pre>
 
# End of REMAP.SPT</pre>

Latest revision as of 17:17, 12 April 2016

Remap allows you to change the chain ID, atom numbers and/or residue numbers of a polypeptide chain by mouse actions. It also calculates group values [amino acid names (GLY, THR, etc.)]. Finally it prints the 1 char resultant string to the console.

When you click on a polypeptide chain, it gives the current chain ID, residue, residue number and atom number of the most nward atom in that chain. You may then edit any value (except residue). Remap then remaps the entire chain based on those values by conventional increments and identifies each amino acid residue.

Note that it will also remove all waters, hydrogens and %B alternates when any chain is updated.

Remap is a member of the Plico suite of protein folding tools described here. It may be installed and accessed as a macro with the file:

Title=PLICO Remap
Script=script <path to your scripts directory>/remap.spt;plico_remap

saved as plicoRemap.macro in your .jmol/macros directory as described in Macro.

Copy and paste the following to a text editor and save to your scripts directory as remap.spt:

#   remap - Jmol script by Ron Mignery
#   v1.10 beta    4/12/2016 -require latest common includes
#
#   Calculate or change polypeptide chain, atom number, residue names and/or residue
#    numbers and print the resultant 1 char string
#
gAppendNew = false
gBusy = false

# Search for N-C-C-0
function get_bb_nward_ca_idx(idx) {
    if ({atomIndex=idx}.element == "N") {
        var c1 = (connected({atomIndex=idx}) and not {hydrogen})
        for (var i1 = 1; i1 <= c1.size; i1++) {
            if (c1[i1].element == "C") {
                var c2 = (connected({atomIndex=@{c1[i1].atomIndex}}) and not {hydrogen})
                for (var i2 = 1; i2 <= c2.size; i2++) {
                    if (c2[i2].element == "C") {
                        var c3 = (connected({atomIndex=@{c2[i2].atomIndex}})
                            and not {hydrogen})
                        for (var i3 = 1; i3 <= c3.size; i3++) {
                            if (c3[i3].element == "O") {
                                return c1[i1].atomIndex
                            }
                        }
                    }
                }
            }
        }
    }
    return -1
}

# Find N-terminal N
function find_n0_idx(aIdx) {

    select {atomIndex=aIdx}
    var sSet = {selected}
    while (sSet) {
        for (var i = 1; i <= sSet.size; i++) {
            var idx = sSet[i].atomIndex
            var caIdx = get_bb_nward_ca_idx(idx)
            if (caIdx >= 0) {
                var cset = connected({atomIndex=idx}) and not {hydrogen}
                var ccset = connected(cset) and not {hydrogen}
                if (cset.size < 2) {
                    return idx #***
                }
                else if (({ccset and {carbon}}.size = 3) and (ccset.size == 4)) { 
                    return idx #***
                }
            }
        } # endfor
        
        sSet = connected({selected}) and not {selected} and not {hydrogen}
        select {selected} or sSet
    } # endwhile
    
    return -1
}

# Bound to ALT-LEFT-CLICK by plico_remap
function remap_cargo_mb() {
    var idx =_atomPicked

    if ({atomIndex=idx}.element == "H") {
        idx = connected({atomIndex=idx})[1].atomIndex
    }

    # If n-terminal N can be found
    var n0idx = find_n0_idx(idx)
    var isValid = false
    var newResno = 1
    var newChain = "A"
    var newAtomno = 1
    if (n0idx >= 0) {

        # Prompt for new designators
        var f = {atomIndex=n0idx}.file
        var m = {atomIndex=n0idx}.model
        var iResno = {atomIndex=n0idx}.resno
        var iChain = {atomIndex=n0idx}.chain
        var iNo = {atomIndex=n0idx}.atomno
        select {thisModel}
        color {selected} @gScheme
        select {(chain=iChain) and thisModel}
        color {selected} @gAltScheme
        refresh
        var p = prompt("Enter n-terminal atom designator as\n"
            + "   <resno>:<chain>.N#<atomno>",
            format("%d:%s.N#%d", iResno, iChain, iNo)%0)

        # If valid
        var iColon = p.find(":")
        if (iColon > 0) {
            var iDot = p.find(".")
            if (iDot > 0) {
                var iHash = p.find("#")
                if (iHash > 0) {
                    newResno = 0 + (p[1][iColon-1])
                    newChain = p[iColon+1][iDot-1]
                    newAtomno = 0 + (p[iHash+1][0])
                    if ((newResno > 0)
                        and (newChain.size == 1)
                        and (newAtomno > 0)) {
                            isValid = true
                    }
                }
            }
        }
    }
    if (isValid) {

        delete {hydrogen and thisModel}
        delete {hoh and thisModel}
        delete %B and thisModel
        ssbonds off

        # Build inline pdb file
        var ls = "data \"append remap\"\n"
        var rs = ""
        var ls1 = format("%s:", newChain)

        select {atomIndex=n0idx}
        var cSet = {selected}
        var newAtomName = "N"
        var newGroup = "UNK"
        var s1 = "X"
        var newGreek = ""
        var newCount = ""
        var isCB = false
        var nIdx = n0idx
        var proDidx = -1
        var oxtIdx = -1
        while ((nIdx >= n0idx) or (cSet)) {
            var s = array(1, 2, 3)
            var pTrp = 0
            if (cSet.size == 0) {
                    ls += rs.replace("UNK", newGroup).replace("  SeG" , " SeG ")
                    ls1 += s1
                    rs = ""
                    newResno++
                    nIdx = -1
                    proIdx = -1
                    newGroup = "UNK"
                    s1 = "X"
                    newAtomName = "N"
                    isCB = false
            }
            else if (cSet.size == 1) {
                if (newAtomName == "N") {
                    newGreek = ""
                    newAtomName = "CA"
                }
                else if (newAtomName == "CA") {
                    newGreek = "A"
                    newAtomName = "C"
                }
                else if (newAtomName == "C") {
                    newGroup = "GLY"
                    s1 = "G"
                    newGreek = ""
                    newAtomName = "O"
                }
                else if (newAtomName == "CB") {
                    if (cSet[1].element == "C") {
                        newGroup = "ALA" # for now
                        s1 = "A"
                        newGreek = "B"
                    }
                    newAtomName = "XG"
                }
                else if (newAtomName == "XG") {
                    if (proDidx >= 0) {
                        newGroup = "PRO"
                        s1 = "P"
                        proDidx = -1
                    }
                    if (cSet[1].element == "O") { # SER CYS SEC
                        newGroup = "SER"
                        s1 = "S"
                    }
                    else if (cSet[1].element == "S") {
                        newGroup = "CYS"
                        s1 = "C"
                    }
                    else if (cSet[1].element == "Se") {
                        newGroup = "SEC"
                        s1 = "U"
                    }
                    newGreek = "G"
                    newAtomName = "XD"
                }
                else if (newAtomName == "XD") {
                    if (newGroup == "VAL") {
                        newGroup = "ILE"
                        s1 = "I"
                        newCount = "1"
                    }
                    newGreek = "D"
                    newAtomName = "XE"
                }
                else if (newAtomName == "XE") {
                    newGroup = "MET"
                    s1 = "M"
                    newGreek = "E"
                    newAtomName = "XZ"
                }
                else if (newAtomName == "XZ") {
                    if (cSet[1].element == "N") {
                        newGroup = "LYS"
                        s1 = "K"
                    }
                    else {
                        newGroup = "PHE" # for now
                        s1 = "F"
                    }
                    newGreek = "Z"
                    newAtomName = "XH"
                }
                else if (newAtomName == "XH") {
                    if (cSet[1].element == "O") {
                        newGroup = "TYR"
                        s1 = "Y"
                    }
                    else {
                        newGroup = "TRP" # for now
                        s1 = "W"
                        newCount = "2"
                    }
                    newGreek = "H"
                    newAtomName = "N"
                }
            }
            else if (cSet.size == 2) {
                var hasN = ((cSet[1].element == "N") or (cSet[2].element == "N"))
                var hasO = ((cSet[1].element == "O") or (cSet[2].element == "O"))

                # If CA 2
                if (newAtomName == "CA") {
                    var iKeep = -1
                    for (var i = 1; i <= cSet.size; i++) {
                        if (connected(cSet[i]) > 2) {
                            iKeep = i
                        }
                        else {
                            proDidx = cSet[i].atomIndex
                            cSet[i].selected = false
                        }
                    }
                    cSet = cSet[iKeep]
                    newGroup = "PRO"
                    s1 = "P"
                    newGreek = "A"
                    newAtomName = "C"
                }

                # Else if C or CB 2
                else if (newAtomName == "C") {
                    for (var i = 1; i <= cSet.size; i++) {

                        # If it connects O and (N or O)
                        var tSet = (connected(cSet[i]) and not {selected})
                        var oCount = 0
                        var nCount = 0
                        for (var j = 1; j <= tSet.size; j++) {
                            oCount += ((tSet[j].element == "O") ? 1 : 0)
                            nCount += ((tSet[j].element == "N") ? 1 : 0)
                        }
                        if ((nCount > 0) or (oCount > 1)) { # C
                            newGreek = ""
                            newAtomName = "O"
                        }
                        else { # CB
                            isCB = true
                            cSet[i].selected = false
                            cSet = (cSet and not cSet[i])
                            continue
                        }
                    } # endfor
                }

                # Else if O or N 2
                else if (newAtomName == "O") {
                    var iKeep = -1
                    for (var i = 1; i <= cSet.size; i++) {
                        if (cSet[i].element != "O") {
                            if (cSet[i].element == "N") {
                                nIdx = cSet[i].atomIndex
                            }
                            cSet[i].selected = false
                        }
                        else {
                            iKeep = i
                        }
                    }
                    cSet = cSet[iKeep]
                    newGreek = ""
                    newAtomName = (isCB ? "CB" : "N")
                }

                # Else if N or CB 2
                else if (newAtomName == "CB") {
                    for (var i = 1; i <= cSet.size; i++) {
                        if (cSet[i].element != "C") {
                            nIdx = cSet[i].atomIndex
                            cSet[i].selected = false
                            continue
                        }
                        newGreek = "B"
                        newAtomName = "XG"
                    } # endfor
                }


                # Else if XG or XGn 2
                else if (newAtomName == "XG") { # VAL THR ILE
                    newGroup = (hasO ? "THR" : "VAL")
                    s1 = (hasO ? "T" : "V")
                    newGreek = "G"
                    newAtomName = "XD"
                }


                # Else if XD or XDn 2
                else if (newAtomName == "XD") { # LEU ASP ASN
                    var cTrp = (connected(cSet[2]) and not {selected})
                    var sTrp = ((trp) ? (trp[1].element=="N") : false)
                    if ((cSet[2].element != "C") or sTrp
                        or ((connected(cSet[1]) and not {selected}).size == 0)) {
                        bRev = true
                    }
                    if ((cSet[2].element == "O") or (cSet[1].element == "N")
                        or ((cSet[1].element == "C") and (cSet[2].element != "C"))) {
                        bRev = true
                    }
                    if (hasN) {
                        if (hasO) {
                            newGroup = "ASN"
                            s1 = "N"
                        }
                        else {
                            newGroup = "HIS"
                            s1 = "H"
                        }
                    }
                    else if (hasO) {
                        newGroup = "ASP"
                        s1 = "D"
                    }
                    else {
                        newGroup = "LEU" # for now
                        s1 = "L"
                    }
                    newGreek = "D"
                    newAtomName = "XE"
                }

                # Else if XE or XEn 2
                else if (newAtomName == "XE") { # GLU GLN HIS
                    if ((cSet[2].element == "O") or (cSet[1].element == "N")
                        or ((cSet[1].element == "C") and (cSet[2].element != "C"))) {
                        bRev = true
                    }
                    if (hasO) {
                        if (hasN) {
                            newGroup = "GLN"
                            s1 = "Q"
                        }
                        else {
                            newGroup = "GLU"
                            s1 = "E"
                        }
                    }
                    newGreek = "E"
                    newAtomName = "XZ"
                }

                # Else if XZ 2
                else if (newAtomName == "XZ") { # ARG
                    if (newGroup == "TRP") {
                        pTrp = 1
                    }
                    newGreek = "Z"
                    newAtomName = "XH"
                }

                # Else if XH 2
                else if (newAtomName == "XH") { # ARG
                    newGroup = "ARG"
                    s1 = "R"
                    newGreek = "H"
                    newAtomName = "N"
                }
            }

            # Else cSet.size = 3
            else {
                # If  O
                if (newAtomName == "O") {
                    var oCount = 0
                    var iKeep = -1
                    for (var i = 1; i <= cSet.size; i++) {
                        if (cSet[i].element != "O") {
                            if (cSet[i].element == "N") {
                                nIdx = cSet[i].atomIndex
                            }
                            cSet[i].selected = false
                        }
                        else {
                            oCount++
                            if (iKeep < 0) {
                                iKeep = i
                            }
                            else {
                                oxtIdx = cSet[i].atomIndex
                            }
                        }
                    }
                    cset = cSet[iKeep[1]]
                    newGreek = ""
                    newAtomName = (isCB ? "CB" : "N")
                }
                else if (newAtomName == "CA") { # PRO
                    var iKeep = -1
                    for (var i = 1; i <= cSet.size; i++) {
                        if (connected(cSet[i]) > 2) {
                            iKeep = i
                        }
                    }
                    cSet = cSet[iKeep]

                    newGreek = "A"
                    newAtomName = "C"
                }
                else if (newAtomName == "XE") { # TRP
                    for (var i = 1; i <= cSet.size; i++) {
                        if (cSet[i].element == "N") {
                            s[1] = i
                        }
                        else if (connected(cSet[i]) > 2) {
                            s[2] = i
                        }
                        else {
                            s[3] = i
                        }
                    }
                    newGroup = "TRP"
                    s1 = "W"
                    newGreek = "E"
                    newAtomName = "XZ"
                }
                else {
                }
            }

            for (var i = 1; i <= cSet.size; i++) {
                rs += format("ATOM  %5d  %-4sUNK ", newAtomNo,
                    (cSet[s[i]].element + newGreek
                    + ((cSet.size > 1) ? (i+pTrp) : newCount)))
                rs += format("%s%4d    %8.3f", newChain, newResno, cSet[s[i]].x)
                rs += format("%8.3f%8.3f\n", cSet[s[i]].y, cSet[s[i]].z)
                if (newGreek == "XT") {
                    newGreek == ""
                }
                newAtomno++
            }
            newCount = ""
            cSet = (connected({selected}) and not {selected}
                and not {atomIndex=@nIdx} and not {atomIndex=proDidx})
            select ({selected} or cSet and not {atomIndex=nIdx}
                 and not {atomIndex=proDidx})

        } # endwhile

        # Replace chain with new chain
        if (oxtIdx >= 0) {
            rs += format("ATOM  %5d  OXT UNK %s", newAtomNo, newChain)
            rs += format("%4d    %8.3f", newResno, {atomIndex=oxtIdx}.x)
            rs += format("%8.3f%8.3f\n", {atomIndex=oxtIdx}.y, {atomIndex=oxtIdx}.z)
        }
        ls += rs.replace("UNK", newGroup).replace("  SeG" , " SeG ")
        ls1 += s1
        delete {selected}
        ls += "end \"append remap\""
        gAppendNew = appendNew
        set appendNew false
        script inline @{ls}
        set appendNew gAppendNew
        var xx = {element="Xx"}
        for (var i = 1; i <= xx.size; i++) {
             connect 1.8 {atomindex=@{xx[i].atomIndex}}
        }
        ssbonds on
        gEcho += format("|Chain %s has been rebuilt", newChain)
        set echo TOP LEFT
        echo @gEcho
        print ls1

    }
    else {
        color {selected} @gScheme
    }
}

# Top level of Remap
function plico_remap() {

    # Load common functions if not already
    if (kCommon < 7) {
        script $SCRIPT_PATH$plicoCommon.spt
        if (kCommon < 7) {
            prompt ("A newer version of plicoCommon.SPT is required")
            quit
        }
    }

    gPlico = "Remap"
    plico_prelim(false, true)
    
    gEcho = "_______REMAP_______|ALT-CLICK=select chain|SHIFT-DOUBLE-CLICK=exit"
    echo @gEcho

    set picking ON
    bind "ALT-LEFT-CLICK" "_pickAtom";
    bind "ALT-LEFT-CLICK" "+:remap_cargo_mb";
    bind "SHIFT-DOUBLE" "plico_exit(true)";
    bind "LEFT-CLICK" "+:plico_menu_toggle";
}

# End of REMAP.SPT

Contributors

Remig