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

From Jmol
Jump to navigation Jump to search
(Add more)
(lc all functions)
Line 2: Line 2:
  
 
<pre>#  plicoCommon - Jmol script by Ron Mignery
 
<pre>#  plicoCommon - Jmol script by Ron Mignery
#  v1.2 beta    5/1/2014 -add more
+
#  v1.3 beta    5/16/2014 -lc all functions
 
#
 
#
 
#  Routines and values common to all Plico suite scripts
 
#  Routines and values common to all Plico suite scripts
 
#  Must be present in the same directory as other Plico scripts that use it
 
#  Must be present in the same directory as other Plico scripts that use it
kCommon = 1
+
kCommon = 2
 
kDtolerance = 0.1
 
kDtolerance = 0.1
 
kAtolerance = 5.0
 
kAtolerance = 5.0
Line 22: Line 22:
 
# Return L tetrahedron point if i1<i2<i3, else R point
 
# Return L tetrahedron point if i1<i2<i3, else R point
 
# Work around - Functions returning values must be in lower case for 14.0.13
 
# Work around - Functions returning values must be in lower case for 14.0.13
function gettetidx(i1, i2, i3, dist) {
+
function get_tet_idx(i1, i2, i3, dist) {
 
     var v1 = {atomIndex=i3}.xyz - {atomIndex=i2}.xyz
 
     var v1 = {atomIndex=i3}.xyz - {atomIndex=i2}.xyz
 
     var v2 = {atomIndex=i1}.xyz - {atomIndex=i2}.xyz
 
     var v2 = {atomIndex=i1}.xyz - {atomIndex=i2}.xyz
Line 39: Line 39:
  
 
# Work around - Functions returning values must be in lower case for 14.0.13
 
# Work around - Functions returning values must be in lower case for 14.0.13
function gettrigonalidx(i1, i2, i3, dist) {
+
function get_trigonal_idx(i1, i2, i3, dist) {
 
     var v1 = {atomIndex=i1}.xyz - {atomIndex=i2}.xyz
 
     var v1 = {atomIndex=i1}.xyz - {atomIndex=i2}.xyz
 
     var v2 = {atomIndex=i3}.xyz - {atomIndex=i2}.xyz
 
     var v2 = {atomIndex=i3}.xyz - {atomIndex=i2}.xyz
Line 59: Line 59:
 
}
 
}
 
# Selected must include second parameter but not the first
 
# Selected must include second parameter but not the first
function setDistanceAtoms( static, mobile, desired) {
+
function set_distance_atoms( static, mobile, desired) {
 
     try {
 
     try {
 
         var v = mobile.xyz - static.xyz
 
         var v = mobile.xyz - static.xyz
Line 68: Line 68:
 
     }
 
     }
 
}
 
}
function setDistanceIdx( staticIdx, mobileIdx, desired) {
+
function set_distance_idx( staticIdx, mobileIdx, desired) {
     setDistanceAtoms({atomIndex=staticIdx}, {atomIndex=mobileIdx}, desired)
+
     set_distance_atoms({atomIndex=staticIdx}, {atomIndex=mobileIdx}, desired)
 
}
 
}
  
  
 
# Selected must include third parameter but not the first
 
# Selected must include third parameter but not the first
function setAngleAtoms( stator, pivot, rotor, toangle) {
+
function set_angle_atoms( stator, pivot, rotor, toangle) {
 
     try {
 
     try {
 
         var v1=stator.xyz - pivot.xyz
 
         var v1=stator.xyz - pivot.xyz
Line 85: Line 85:
 
     }
 
     }
 
}
 
}
function setAngleIdx( statorIdx, pivotIdx, rotorIdx, toangle) {
+
function set_angle_idx( statorIdx, pivotIdx, rotorIdx, toangle) {
     setAngleAtoms({atomIndex=statorIdx}, {atomIndex=pivotIdx},
+
     set_angle_atoms({atomIndex=statorIdx}, {atomIndex=pivotIdx},
 
         {atomIndex=rotorIdx}, toangle)
 
         {atomIndex=rotorIdx}, toangle)
 
}
 
}
  
function angleIdx3( a1idx, a2idx, a3idx) {
+
function angle_idx_3( a1idx, a2idx, a3idx) {
 
     return angle({atomIndex=a1idx}, {atomIndex=a2idx}, {atomIndex=a3idx})
 
     return angle({atomIndex=a1idx}, {atomIndex=a2idx}, {atomIndex=a3idx})
 
}
 
}
  
 
# Selected must include fourth parameter but not the first
 
# Selected must include fourth parameter but not the first
function setDihedralAtoms( stator, pivot1, pivot2, rotor, toangle) {
+
function set_dihedral_atoms( stator, pivot1, pivot2, rotor, toangle) {
 
     try {
 
     try {
 
         var curangle =  angle(stator, pivot1, pivot2, rotor)
 
         var curangle =  angle(stator, pivot1, pivot2, rotor)
Line 103: Line 103:
 
     }
 
     }
 
}
 
}
function setDihedralIdx( statorIdx, pivot1idx, pivot2idx, rotorIdx, toangle) {
+
function set_dihedral_idx( statorIdx, pivot1idx, pivot2idx, rotorIdx, toangle) {
     setDihedralAtoms({atomIndex = statorIdx}, {atomIndex = pivot1idx},
+
     set_dihedral_atoms({atomIndex = statorIdx}, {atomIndex = pivot1idx},
 
         {atomIndex = pivot2idx}, {atomIndex = rotorIdx}, toangle)
 
         {atomIndex = pivot2idx}, {atomIndex = rotorIdx}, toangle)
 
}
 
}
  
function angleIdx4( a1idx, a2idx, a3idx, a4idx) {
+
function angle_idx_4( a1idx, a2idx, a3idx, a4idx) {
 
     return angle({atomIndex=a1idx}, {atomIndex=a2idx},
 
     return angle({atomIndex=a1idx}, {atomIndex=a2idx},
 
         {atomIndex=a3idx}, {atomIndex=a4idx})
 
         {atomIndex=a3idx}, {atomIndex=a4idx})
Line 114: Line 114:
  
 
# Work around - Functions returning values must be in lower case for 14.0.13
 
# Work around - Functions returning values must be in lower case for 14.0.13
function countcollisions(rc) {
+
function count_collisions(rc) {
 
     var cAtoms = ({})
 
     var cAtoms = ({})
 
     for (var idx = {*}.min.atomIndex; idx <= {*}.max.atomIndex; idx++) {
 
     for (var idx = {*}.min.atomIndex; idx <= {*}.max.atomIndex; idx++) {
Line 122: Line 122:
 
                 and not {rc}
 
                 and not {rc}
 
                 and not connected({atomIndex=idx}))
 
                 and not connected({atomIndex=idx}))
 +
            if (lcAtoms.size > 0) {
 +
                cAtoms = cAtoms or lcAtoms or {atomIndex=idx}
 +
                if (rc == TRUE) {
 +
                    print format("Collision of idx=%d with %s", idx, lcAtoms)
 +
                }
 +
            }
 +
        }
 +
    }
 +
    return cAtoms
 +
}
 +
 +
function is_collision_in_select() {
 +
    is = FALSE
 +
    var cAtoms = ({})
 +
    var iChain = {selected}.chain
 +
    for (var no = {selected}.min.atomno; no <= {selected}.max.atomno; no++) {
 +
        a = {(atomno=no) and (chain=iChain)}
 +
        if (a.size > 0) {
 +
            is = TRUE
 +
            break
 +
        }
 +
    }
 +
    return is
 +
}
 +
 +
function count_collision_in_select(rc) {
 +
    var cAtoms = ({})
 +
    var iChain = {selected}.chain
 +
    for (var no = {selected}.min.atomno; no <= {selected}.max.atomno; no++) {
 +
        a = {(atomno=no) and (chain=iChain)}
 +
        if (a.size > 0) {
 +
            var lcAtoms = (within(kCtolerance, FALSE, a)
 +
                and {atomno != no} and not connected(a))
 
             if (lcAtoms.size > 0) {
 
             if (lcAtoms.size > 0) {
 
                 cAtoms = cAtoms or lcAtoms or {atomIndex=idx}
 
                 cAtoms = cAtoms or lcAtoms or {atomIndex=idx}
Line 135: Line 168:
 
# A handy debug routine
 
# A handy debug routine
 
function cc {
 
function cc {
     print countcollisions(TRUE)
+
     print count_collisions(TRUE)
 
}
 
}
  
Line 146: Line 179:
 
}
 
}
  
function plicoPrelim() {
+
function plico_prelim() {
  
 
     # Push selected
 
     # Push selected
Line 154: Line 187:
 
     # Bad idea to proceed when collisions present
 
     # Bad idea to proceed when collisions present
 
     while (TRUE) {
 
     while (TRUE) {
         var cc = countcollisions(({})).size
+
         var cc = count_collisions(({})).size
 
         if (cc > 0) {
 
         if (cc > 0) {
 
             var p = prompt(format("%d collision%s present!\nProceed anyway?",
 
             var p = prompt(format("%d collision%s present!\nProceed anyway?",
Line 196: Line 229:
 
}
 
}
  
function plicoExit() {
+
function plico_exit() {
 
     var p = ""
 
     var p = ""
 
     if (gPlico.size > 0) {
 
     if (gPlico.size > 0) {

Revision as of 14:55, 16 May 2014

This script contains routines used by other scripts of the Plico suite. It must be located in the same directory as any script that uses these routines.

#   plicoCommon - Jmol script by Ron Mignery
#   v1.3 beta    5/16/2014 -lc all functions
#
#   Routines and values common to all Plico suite scripts
#   Must be present in the same directory as other Plico scripts that use it
kCommon = 2
kDtolerance = 0.1
kAtolerance = 5.0
kCtolerance = 1.85
kMtolerance = 0.8
gMouseX = 0
gMouseY = 0
gMinNo = 1
gMaxNo = 9999
gOK = TRUE # global return value to work around jmol *feature*
gOk2 = TRUE # "    "
gScheme = "Jmol"
gAltScheme = "Rasmol"

# Return L tetrahedron point if i1<i2<i3, else R point
# Work around - Functions returning values must be in lower case for 14.0.13
function get_tet_idx(i1, i2, i3, dist) {
    var v1 = {atomIndex=i3}.xyz - {atomIndex=i2}.xyz
    var v2 = {atomIndex=i1}.xyz - {atomIndex=i2}.xyz
    var axis = cross(v1, v2)
    var pma = ({atomIndex=i1}.xyz + {atomIndex=i3}.xyz)/2
    var pmo = {atomIndex=i2}.xyz + {atomIndex=i2}.xyz - pma
    var pt = pmo + (axis/axis)

    var v = pt - {atomIndex=i2}.xyz
    var cdist = distance(pt, {atomIndex=i2})
    var factor = (dist/cdist)
    var lpt = v * factor

    return lpt + {atomIndex=i2}.xyz
}

# Work around - Functions returning values must be in lower case for 14.0.13
function get_trigonal_idx(i1, i2, i3, dist) {
    var v1 = {atomIndex=i1}.xyz - {atomIndex=i2}.xyz
    var v2 = {atomIndex=i3}.xyz - {atomIndex=i2}.xyz
    var pt = {atomIndex=i2}.xyz - (v1 + v2)

    var v = pt - {atomIndex=i2}.xyz
    var cdist = distance(pt, {atomIndex=i2})
    var factor = (dist/cdist)
    var lpt = (v * factor)

    return lpt + {atomIndex=i2}.xyz
}

function abs( x) {
    if (x < 0) {
        x = -x
    }
    return x
}
# Selected must include second parameter but not the first
function set_distance_atoms( static, mobile, desired) {
    try {
        var v = mobile.xyz - static.xyz
        var dist = distance(static, mobile)
        translateSelected @{((v * (desired/dist)) - v)}
    }
    catch {
    }
}
function set_distance_idx( staticIdx, mobileIdx, desired) {
    set_distance_atoms({atomIndex=staticIdx}, {atomIndex=mobileIdx}, desired)
}


# Selected must include third parameter but not the first
function set_angle_atoms( stator, pivot, rotor, toangle) {
    try {
        var v1=stator.xyz - pivot.xyz
        var v2=rotor.xyz - pivot.xyz
        var axis = cross(v1, v2) + pivot.xyz
        var curangle =  angle(stator, pivot, rotor)
        rotateselected @axis @pivot @{curangle-toangle}
    }
    catch {
    }
}
function set_angle_idx( statorIdx, pivotIdx, rotorIdx, toangle) {
    set_angle_atoms({atomIndex=statorIdx}, {atomIndex=pivotIdx},
        {atomIndex=rotorIdx}, toangle)
}

function angle_idx_3( a1idx, a2idx, a3idx) {
    return angle({atomIndex=a1idx}, {atomIndex=a2idx}, {atomIndex=a3idx})
}

# Selected must include fourth parameter but not the first
function set_dihedral_atoms( stator, pivot1, pivot2, rotor, toangle) {
    try {
        var curangle =  angle(stator, pivot1, pivot2, rotor)
        rotateselected {pivot2} {pivot1} @{curangle-toangle}
    }
    catch {
    }
}
function set_dihedral_idx( statorIdx, pivot1idx, pivot2idx, rotorIdx, toangle) {
    set_dihedral_atoms({atomIndex = statorIdx}, {atomIndex = pivot1idx},
        {atomIndex = pivot2idx}, {atomIndex = rotorIdx}, toangle)
}

function angle_idx_4( a1idx, a2idx, a3idx, a4idx) {
    return angle({atomIndex=a1idx}, {atomIndex=a2idx},
        {atomIndex=a3idx}, {atomIndex=a4idx})
}

# Work around - Functions returning values must be in lower case for 14.0.13
function count_collisions(rc) {
    var cAtoms = ({})
    for (var idx = {*}.min.atomIndex; idx <= {*}.max.atomIndex; idx++) {
        if ({atomIndex=idx}.size > 0) {
            var lcAtoms = (within(kCtolerance, FALSE, {atomIndex=idx})
                and {atomIndex > idx}
                and not {rc}
                and not connected({atomIndex=idx}))
            if (lcAtoms.size > 0) {
                cAtoms = cAtoms or lcAtoms or {atomIndex=idx}
                if (rc == TRUE) {
                    print format("Collision of idx=%d with %s", idx, lcAtoms)
                }
            }
        }
    }
    return cAtoms
}

function is_collision_in_select() {
    is = FALSE
    var cAtoms = ({})
    var iChain = {selected}.chain
    for (var no = {selected}.min.atomno; no <= {selected}.max.atomno; no++) {
        a = {(atomno=no) and (chain=iChain)}
        if (a.size > 0) {
            is = TRUE
            break
        }
    }
    return is
}

function count_collision_in_select(rc) {
    var cAtoms = ({})
    var iChain = {selected}.chain
    for (var no = {selected}.min.atomno; no <= {selected}.max.atomno; no++) {
        a = {(atomno=no) and (chain=iChain)}
        if (a.size > 0) {
            var lcAtoms = (within(kCtolerance, FALSE, a)
                and {atomno != no} and not connected(a))
            if (lcAtoms.size > 0) {
                cAtoms = cAtoms or lcAtoms or {atomIndex=idx}
                if (rc == TRUE) {
                    print format("Collision of idx=%d with %s", idx, lcAtoms)
                }
            }
        }
    }
    return cAtoms
}

# A handy debug routine
function cc {
    print count_collisions(TRUE)
}

# A handy debug routine
function hi {
    var selsave = {selected}
    select all
    set hoverlabel "%D %U"
    select {selsave}
}

function plico_prelim() {

    # Push selected
    gSelSaves = {selected}
    select all
    
    # Bad idea to proceed when collisions present
    while (TRUE) {
        var cc = count_collisions(({})).size
        if (cc > 0) {
            var p = prompt(format("%d collision%s present!\nProceed anyway?",
                cc, ((cc > 1) ? "s" : "")), "OK|Cancel|Repair", TRUE)
            if (p == "Cancel") {
                quit
            }
            else if (p == "Repair") {
                select all
                allSet = {selected}
                gChain = "XX"
                for (var idx = {allSet}.atomIndex.min;
                    idx <= {allSet}.atomIndex.max; idx++) {
                    if ({atomIndex=idx}.chain != gChain) {
                        gChain = {atomIndex=idx}.chain
                        select {chain=gChain}
                        handleCollisions2( idx)
                    }
                }
            }
            else {
                break
            }
        }
        else {
            break
        }
    } # endwhile

    gZoom = script("show zoom")
    gRotate = script("show rotation")
    write tugsave.pdb
    select none
    
    gScheme = defaultColorScheme
    gAltScheme = ((gScheme == "jmol") ? "rasmol" : "jmol")
    set echo TOP LEFT
    background ECHO yellow
    gChain = ""
    unbind
}

function plico_exit() {
    var p = ""
    if (gPlico.size > 0) {
        p = prompt(format("Exit %s?", gPlico), "Yes|No|Undo", TRUE)
        if (p == "Undo") {
            load tugsave.pdb
            script inline gZoom
            rotate @gRotate
            echo Tug session undone
            if (gPlicoRecord != "") {
                plicoRecord("load tugsave.pdb;")
            }
        }
    }
    if (p != "No") {
        unbind
        halo off
        echo
        select all
        halo off
        star off
        color {selected} @gScheme
        draw gSCcircle DELETE
        gBusy = FALSE
        background ECHO yellow

        # Pop selected
        select gSelSaves
    }
}
# end of plicocommon.spt

Contributors

Remig