コード例 #1
0
ファイル: cgo07.py プロジェクト: kingdavid72/pymol-OpenSource
def random_ellipsoid(box, size, min_axis):

    # return a random ellipsoid record of the form:
    # [ ELLIPSOID, x_pos, y_pos, z_pos, size, x0, y0, z0, x1, y1, z2, x2, y2, z2 ]
    # where the xyz vectors are orthogonal and of length 1.0 or less.
    
    box = box - size
    tmp0 = cpv.random_vector()
    tmp1 = cpv.random_vector()
    tmp2 = cpv.cross_product(tmp1, tmp0)
    tmp3 = cpv.cross_product(tmp1, tmp2)
    tmp4 = cpv.cross_product(tmp2, tmp3)
    tmp2 = cpv.normalize(tmp2)
    tmp3 = cpv.normalize(tmp3)
    tmp4 = cpv.normalize(tmp4)
    primary = cpv.scale(tmp2, random())
    secondary = cpv.scale(tmp3,random())
    tertiary = cpv.scale(tmp4,random())
    factor = 1.0 / max( cpv.length(primary), cpv.length(secondary), cpv.length(tertiary))
    primary = cpv.scale(primary, factor)
    secodary = cpv.scale(secondary, factor)
    tertiary = cpv.scale(tertiary, factor)
    return [ ELLIPSOID,
             size + random() * box, size + random() * box, size + random() * box,
             max(random() * size, min_axis),
             ] + primary + secondary + tertiary
コード例 #2
0
def random_conic(box, size, min_axis):

    # return a random ellipsoid record of the form:
    # [ ELLIPSOID, x_pos, y_pos, z_pos, size, x0, y0, z0, x1, y1, z2, x2, y2, z2 ]
    # where the xyz vectors are orthogonal and of length 1.0 or less.

    box = box - size
    tmp0 = [
        size + random() * box, size + random() * box, size + random() * box
    ]
    tmp1 = cpv.random_vector()
    tmp2 = cpv.scale(tmp1, box / 10)
    tmp1 = cpv.add(tmp2, tmp0)

    return [
        CONE,
        tmp0[0],
        tmp0[1],
        tmp0[2],  # coordinates 
        tmp1[0],
        tmp1[1],
        tmp1[2],
        (abs(random()) * 0.4 + 0.2) * size,  # radii
        (abs(random()) * 0.1 + 0.01) * size,
        random(),
        random(),
        random(),  # colors
        random(),
        random(),
        random(),
        1.0,
        1.0
    ]
コード例 #3
0
ファイル: cgo08.py プロジェクト: Almad/pymol
def random_conic(box, size, min_axis):

    # return a random ellipsoid record of the form:
    # [ ELLIPSOID, x_pos, y_pos, z_pos, size, x0, y0, z0, x1, y1, z2, x2, y2, z2 ]
    # where the xyz vectors are orthogonal and of length 1.0 or less.
    
    box = box - size
    tmp0 = [ size + random() * box, size + random() * box, size + random() * box ]
    tmp1 = cpv.random_vector()
    tmp2 = cpv.scale(tmp1,box/10)
    tmp1 = cpv.add(tmp2,tmp0)
    
    return [ CONE,
             tmp0[0], tmp0[1], tmp0[2], # coordinates 
             tmp1[0], tmp1[1], tmp1[2],
             (abs(random())*0.4+0.2) * size, # radii
             (abs(random())*0.1+0.01) * size,
             random(), random(), random(), # colors
             random(), random(), random(),
             1.0, 1.0 ]
コード例 #4
0
def obscure(selection, hiding="medium", keep=0, state=-1, name_map='', name_iso='', quiet=0, _self=cmd):
    """
DESCRIPTION

    Given an object or selection, usually a small molecule, obscure it
    to protect its exact identity.

USAGE

    obscure selection [, hiding [, keep ]]

ARGUMENTS

    selection = str: atom selection to hide

    hiding = low|medium|high: level to which PyMOL obscures the object {default: medium}

    keep = 0/1: by default, PyMOL removes the obscured atoms from your file,
    this flag will keep the atoms in the file.  Be careful!

NOTES

    Large molecules are very slow.
    """
    from chempy.cpv import add, scale, random_vector

    keep = bool(keep) if not keep else int(keep)
    quiet = int(quiet)

    hiding = hiding_sc.auto_err(hiding, 'hiding level')
    hiding = ['low', 'medium', 'high'].index(hiding)

    # these parameters are fine-tuned for a good visual experience
    resolution, grid, level = [
        [2.00, 0.18, 2.00], # low
        [3.75, 0.25, 2.50], # medium
        [4.00, 0.33, 2.00], # high
    ][hiding]

    # detect if we're hiding a subset of a molecule, then add one bond, so ensure that what sticks out looks good
    tmp_sele = _self.get_unused_name("_target")
    natoms = _self.select(tmp_sele,  "(%s) extend 1" % (selection), 0)

    if not quiet:
        print(' Obscuring %d atoms' % natoms)

    # get a new name for the map/surf
    if not name_map:
        name_map = _self.get_unused_name("obsc_map")
    if not name_iso:
        name_iso = _self.get_unused_name("obsc_surf")

    if not keep:
        # randomize the coordinates
        _self.alter_state(state, tmp_sele, "(x,y,z)=perturb([x,y,z])", space={'perturb':
            lambda v: add(v, scale(random_vector(), 0.4))})

        # clear out charge and b-factor
        _self.alter(tmp_sele, "(b,q) = (10.0, 1.0)")

    # make the gaussian map and draw its surface
    _self.map_new(name_map, "gaussian", grid, tmp_sele, resolution=resolution, quiet=quiet)
    _self.isosurface(name_iso, name_map, level, quiet=quiet)

    if not keep:
        if natoms == _self.count_atoms('byobject (%s)' % (tmp_sele)):
            names = ' '.join(_self.get_object_list('(%s)' % (selection)))
            if not quiet:
                print(' Deleting object:', names)
            _self.delete(names)
        else:
            _self.remove(selection, quiet=quiet)

    _self.delete(tmp_sele)