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

From Jmol
Jump to navigation Jump to search
(Handle multiple frames)
m
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.5 beta    6/17/2014 -handle multiple frames
+
#  v1.6 beta    7/26/2014 -.file not .frame
 
#
 
#
 
#  Calculate or change polypeptide chain, atom number, residue names and/or residue
 
#  Calculate or change polypeptide chain, atom number, residue names and/or residue
 
#    numbers and print the resultant 1 char string
 
#    numbers and print the resultant 1 char string
 
#
 
#
gAppendNew = FALSE
+
gAppendNew = false
gBusy = FALSE
+
gBusy = false
  
 
# Search for N-C-C-0
 
# Search for N-C-C-0
Line 78: Line 78:
 
     # If n-terminal N can be found
 
     # If n-terminal N can be found
 
     var n0idx = find_n0_idx(idx)
 
     var n0idx = find_n0_idx(idx)
     var isValid = FALSE
+
     var isValid = false
 
     var newResno = 1
 
     var newResno = 1
 
     var newChain = "A"
 
     var newChain = "A"
Line 85: Line 85:
  
 
         # Prompt for new designators
 
         # Prompt for new designators
 +
        f = {atomIndex=n0idx}.file
 +
        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)}
 +
        color {selected} @gScheme
 
         select {(chain=iChain) and (file=f) and (model=m)}
 
         select {(chain=iChain) and (file=f) and (model=m)}
 
         color {selected} @gAltScheme
 
         color {selected} @gAltScheme
Line 108: Line 112:
 
                         and (newChain.size == 1)
 
                         and (newChain.size == 1)
 
                         and (newAtomno > 0)) {
 
                         and (newAtomno > 0)) {
                             isValid = TRUE
+
                             isValid = true
 
                     }
 
                     }
 
                 }
 
                 }
Line 133: Line 137:
 
         var newGreek = ""
 
         var newGreek = ""
 
         var newCount = ""
 
         var newCount = ""
         var isCB = FALSE
+
         var isCB = false
 
         var nIdx = n0idx
 
         var nIdx = n0idx
 
         var proDidx = -1
 
         var proDidx = -1
Line 150: Line 154:
 
                     s1 = "X"
 
                     s1 = "X"
 
                     newAtomName = "N"
 
                     newAtomName = "N"
                     isCB = FALSE
+
                     isCB = false
 
             }
 
             }
 
             else if (cSet.size == 1) {
 
             else if (cSet.size == 1) {
Line 250: Line 254:
 
                         else {
 
                         else {
 
                             proDidx = cSet[i].atomIndex
 
                             proDidx = cSet[i].atomIndex
                             cSet[i].selected = FALSE
+
                             cSet[i].selected = false
 
                         }
 
                         }
 
                     }
 
                     }
Line 277: Line 281:
 
                         }
 
                         }
 
                         else { # CB
 
                         else { # CB
                             isCB = TRUE
+
                             isCB = true
                             cSet[i].selected = FALSE
+
                             cSet[i].selected = false
 
                             cSet = (cSet and not cSet[i])
 
                             cSet = (cSet and not cSet[i])
 
                             continue
 
                             continue
Line 293: Line 297:
 
                                 nIdx = cSet[i].atomIndex
 
                                 nIdx = cSet[i].atomIndex
 
                             }
 
                             }
                             cSet[i].selected = FALSE
+
                             cSet[i].selected = false
 
                         }
 
                         }
 
                         else {
 
                         else {
Line 309: Line 313:
 
                         if (cSet[i].element != "C") {
 
                         if (cSet[i].element != "C") {
 
                             nIdx = cSet[i].atomIndex
 
                             nIdx = cSet[i].atomIndex
                             cSet[i].selected = FALSE
+
                             cSet[i].selected = false
 
                             continue
 
                             continue
 
                         }
 
                         }
Line 330: Line 334:
 
                 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.size > 0) ? (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)) {
                         bRev = TRUE
+
                         bRev = true
 
                     }
 
                     }
 
                     if ((cSet[2].element == "O") or (cSet[1].element == "N")
 
                     if ((cSet[2].element == "O") or (cSet[1].element == "N")
 
                         or ((cSet[1].element == "C") and (cSet[2].element != "C"))) {
 
                         or ((cSet[1].element == "C") and (cSet[2].element != "C"))) {
                         bRev = TRUE
+
                         bRev = true
 
                     }
 
                     }
 
                     if (hasN) {
 
                     if (hasN) {
Line 365: Line 369:
 
                     if ((cSet[2].element == "O") or (cSet[1].element == "N")
 
                     if ((cSet[2].element == "O") or (cSet[1].element == "N")
 
                         or ((cSet[1].element == "C") and (cSet[2].element != "C"))) {
 
                         or ((cSet[1].element == "C") and (cSet[2].element != "C"))) {
                         bRev = TRUE
+
                         bRev = true
 
                     }
 
                     }
 
                     if (hasO) {
 
                     if (hasO) {
Line 410: Line 414:
 
                                 nIdx = cSet[i].atomIndex
 
                                 nIdx = cSet[i].atomIndex
 
                             }
 
                             }
                             cSet[i].selected = FALSE
+
                             cSet[i].selected = false
 
                         }
 
                         }
 
                         else {
 
                         else {
Line 499: Line 503:
 
         print ls1
 
         print ls1
  
 +
    }
 +
    else {
 +
        color {selected} @gScheme
 
     }
 
     }
 
}
 
}
Line 509: Line 516:
  
 
     gAppendNew = appendNew
 
     gAppendNew = appendNew
     set appendNew FALSE
+
     set appendNew false
 
     gScheme = defaultColorScheme
 
     gScheme = defaultColorScheme
 
     gAltScheme = ((gScheme == "Jmol") ? "Rasmol" : "Jmol")
 
     gAltScheme = ((gScheme == "Jmol") ? "Rasmol" : "Jmol")
Line 534: Line 541:
 
     select ((file=f) and (model=m))
 
     select ((file=f) and (model=m))
 
     color {selected} @gScheme
 
     color {selected} @gScheme
     gBusy = FALSE
+
     gBusy = false
 
     set appendNew gAppendNew
 
     set appendNew gAppendNew
  

Revision as of 19:03, 26 August 2014

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.6 beta    7/26/2014 -.file not .frame
#
#   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 cSet = {selected}
    while (cSet.size > 0) {
        for (var i = 1; i <= cSet.size; i++) {
            var idx = cSet[i].atomIndex
            var caIdx = get_bb_nward_ca_idx(idx)
            if (caIdx >= 0) {
                if ({connected({atomIndex=idx}) and not {hydrogen}}.size < 2) {
                    return idx
                }
            }
        }
        cSet = connected({selected}) and not {selected} and not {hydrogen}
        select {selected} or cset
    }
    return -1
}

# Bound to ALT-LEFT-CLICK by plico_remap
function remap_cargo_mb() {
    var f = (_frameID/1000000)
    var m = (_frameID%1000000)
    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
        f = {atomIndex=n0idx}.file
        m = {atomIndex=n0idx}.model
        var iResno = {atomIndex=n0idx}.resno
        var iChain = {atomIndex=n0idx}.chain
        var iNo = {atomIndex=n0idx}.atomno
        select {(file=f) and (model=m)}
        color {selected} @gScheme
        select {(chain=iChain) and (file=f) and (model=m)}
        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 (file=f) and (model=m)}
        delete {hoh and (file=f) and (model=m)}
        delete %B and (file=f) and (model=m)
        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.size > 0)) {
            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.size > 0) ? (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\""
        script inline @{ls}
        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() {

    # Push selected
    gSelSaves = {selected}

    gAppendNew = appendNew
    set appendNew false
    gScheme = defaultColorScheme
    gAltScheme = ((gScheme == "Jmol") ? "Rasmol" : "Jmol")
    set echo TOP LEFT
    background ECHO yellow
    gEcho = "_______REMAP_______|ALT-CLICK=select chain|DOUBLE-CLICK=exit"
    echo @gEcho
    gChain = ""
    unbind

    set picking ON
    bind "ALT-LEFT-CLICK" "_pickAtom";
    bind "ALT-LEFT-CLICK" "+:remap_cargo_mb";
    bind "DOUBLE" "remap_exit";
}

# 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
    set appendNew gAppendNew

    # Pop selected
    select gSelSaves
}
# End of REMAP.SPT

Contributors

Remig