コード例 #1
0
ファイル: querying.py プロジェクト: av-hub/pymol-testing
 def testGetVolumeHistogram(self):
     cmd.load(self.datafile('h2o-elf.cube'), 'map1')
     hist1 = cmd.get_volume_histogram('map1', 10)
     self.assertEqual(len(hist1), 14)
     hist2 = cmd.get_volume_histogram('map1', 2)
     self.assertArrayEqual(
         hist2, [-0.0151, 0.9292, 0.0692, 0.1720, 63812.0, 188.0],
         delta=1e-4)
     self.assertArrayEqual(hist1[:4], hist2[:4])
     self.assertEqual(sum(hist1[4:]), sum(hist2[4:]))
     hist2 = cmd.get_volume_histogram('map1', 2, (0.3, 0.7))
     self.assertArrayEqual(hist2,
                           [0.3, 0.7, 0.0692, 0.172, 62263.0, 1737.0],
                           delta=1e-4)
コード例 #2
0
ファイル: mmpymolx.py プロジェクト: schrodinger/pymol-testing
    def testLoadMTZ(self):
        cmd.load_mtz(self.datafile('4rwb.mtz'), 'foo',
                'cryst_1/data_1/FP',
                'cryst_1/data_1/PHIC')

        self.assertEqual(cmd.get_names(), ['foo'])

        extent = cmd.get_extent('foo')
        self.assertArrayEqual(extent, [
            [   0.000,   0.000,   0.000],
            [  37.585,  40.586,  27.214]], delta=1e-3, msg='extend wrong')

        # min, max, mean, stdev
        mmms = cmd.get_volume_histogram('foo', 0)
        self.assertArrayEqual(mmms, [-2.6767, 4.9998, 0.0, 1.0], delta=1e-4,
                msg='histogram wrong')
コード例 #3
0
    def testLoadMTZ(self):
        cmd.load_mtz(self.datafile('4rwb.mtz'), 'foo', 'cryst_1/data_1/FP',
                     'cryst_1/data_1/PHIC')

        self.assertEqual(cmd.get_names(), ['foo'])

        extent = cmd.get_extent('foo')
        self.assertArrayEqual(
            extent, [[0.000, 0.000, 0.000], [37.585, 40.586, 27.214]],
            delta=1e-3,
            msg='extend wrong')

        # min, max, mean, stdev
        mmms = cmd.get_volume_histogram('foo', 0)
        self.assertArrayEqual(mmms, [-2.6767, 4.9998, 0.0, 1.0],
                              delta=1e-4,
                              msg='histogram wrong')
コード例 #4
0
ファイル: electrostatics.py プロジェクト: speleo3/pymol-psico
def volume_esp(name, map, stops=[0.1, 1.0], neg='red', pos='blue',
        opacity=0.2, quiet=1):
    '''
DESCRIPTION

    Create a volume object from a map object with default coloring
    for electrostatic potential (similar to positive and negative
    isosurface).

ARGUMENTS

    name = string: name for the new volume object

    map = string: name of the map object to use

    stops = list of floats: 2 or 3 values in standard deviations for creating
    the volume ramp {default: [0.1, 1.0]}

    neg = string: color for negative volume {default: red}

    pos = string: color for positive volume {default: blue}

    opacity = float: maximum opacity in volume ramp {default: 0.2}

SEE ALSO

    volume
    '''
    from .setting import set_temporary

    opacity, quiet = float(opacity), int(quiet)

    if isinstance(stops, str):
        stops = cmd.safe_list_eval(stops)

    try:
        from pymol.colorramping import ColorRamp
    except ImportError:
        print(' Warning: volume_esp is deprecated')
        stdevD = cmd.get_volume_histogram(map, 0)[3]
        stops = [s * stdevD for s in stops]
        ramp = [
            -stops[1], neg, opacity,
            -stops[0], neg, 0.0,
            stops[0], pos, 0.0,
            stops[1], pos, opacity,
        ]
        if len(stops) == 3:
            ramp = [-stops[2], neg, opacity] + ramp + [stops[2], pos, opacity]
        cmd.volume(name, map, ramp, quiet=quiet)
        return

    c_neg = cmd.get_color_tuple(neg)
    c_pos = cmd.get_color_tuple(pos)

    c_pos_0 = c_pos + (0.0,)
    c_pos_1 = c_pos + (opacity,)
    c_neg_0 = c_neg + (0.0,)
    c_neg_1 = c_neg + (opacity,)

    if len(stops) == 2:
        cstops = [(c_neg_1, -999), (c_neg_1, -stops[1]), (c_neg_0, -stops[0]),
                (c_pos_0, stops[0]), (c_pos_1, stops[1]), (c_pos_1, 999)]
    elif len(stops) == 3:
        cstops = [(c_neg_0, -999), (c_neg_0, -stops[2]), (c_neg_1, -stops[1]),
                (c_neg_0, -stops[0]), (c_pos_0, stops[0]), (c_pos_1, stops[1]),
                (c_pos_0, stops[2]), (c_pos_0, 999)]
    else:
        print(' Error: need 2 or 3 stops')
        raise CmdException

    cmd.volume(name, map, quiet=quiet)

    # get_volume_histogram returns zeros without refresh
    with set_temporary(suspend_updates='off'):
        cmd.refresh()

    minD, maxD, meanD, stdevD = cmd.get_volume_histogram(name)[:4]

    v_ramp = []
    c_ramp = ColorRamp(360)
    for c, s in cstops:
        i = int(360 * ((s * stdevD) - minD) / (maxD - minD))
        i = min(max(i, 0), 359)
        v_ramp.append(i)
        v_ramp.extend(c)
        c_ramp.addColor(i, c)

    cmd.set_volume_ramp(name, v_ramp)
    cmd.volume_color(name, c_ramp.getRamp())
    cmd.recolor(name)
コード例 #5
0
def volume_esp(name,
               map,
               stops=[0.1, 1.0],
               neg='red',
               pos='blue',
               opacity=0.2,
               quiet=1):
    '''
DESCRIPTION

    Create a volume object from a map object with default coloring
    for electrostatic potential (similar to positive and negative
    isosurface).

ARGUMENTS

    name = string: name for the new volume object

    map = string: name of the map object to use

    stops = list of floats: 2 or 3 values in standard deviations for creating
    the volume ramp {default: [0.1, 1.0]}

    neg = string: color for negative volume {default: red}

    pos = string: color for positive volume {default: blue}

    opacity = float: maximum opacity in volume ramp {default: 0.2}

SEE ALSO

    volume
    '''
    from .setting import set_temporary

    opacity, quiet = float(opacity), int(quiet)

    if isinstance(stops, str):
        stops = cmd.safe_list_eval(stops)

    try:
        from pymol.colorramping import ColorRamp
    except ImportError:
        print(' Warning: volume_esp is deprecated')
        stdevD = cmd.get_volume_histogram(map, 0)[3]
        stops = [s * stdevD for s in stops]
        ramp = [
            -stops[1],
            neg,
            opacity,
            -stops[0],
            neg,
            0.0,
            stops[0],
            pos,
            0.0,
            stops[1],
            pos,
            opacity,
        ]
        if len(stops) == 3:
            ramp = [-stops[2], neg, opacity] + ramp + [stops[2], pos, opacity]
        cmd.volume(name, map, ramp, quiet=quiet)
        return

    c_neg = cmd.get_color_tuple(neg)
    c_pos = cmd.get_color_tuple(pos)

    c_pos_0 = c_pos + (0.0, )
    c_pos_1 = c_pos + (opacity, )
    c_neg_0 = c_neg + (0.0, )
    c_neg_1 = c_neg + (opacity, )

    if len(stops) == 2:
        cstops = [(c_neg_1, -999), (c_neg_1, -stops[1]), (c_neg_0, -stops[0]),
                  (c_pos_0, stops[0]), (c_pos_1, stops[1]), (c_pos_1, 999)]
    elif len(stops) == 3:
        cstops = [(c_neg_0, -999), (c_neg_0, -stops[2]), (c_neg_1, -stops[1]),
                  (c_neg_0, -stops[0]), (c_pos_0, stops[0]),
                  (c_pos_1, stops[1]), (c_pos_0, stops[2]), (c_pos_0, 999)]
    else:
        print(' Error: need 2 or 3 stops')
        raise CmdException

    cmd.volume(name, map, quiet=quiet)

    # get_volume_histogram returns zeros without refresh
    with set_temporary(suspend_updates='off'):
        cmd.refresh()

    minD, maxD, meanD, stdevD = cmd.get_volume_histogram(name)[:4]

    v_ramp = []
    c_ramp = ColorRamp(360)
    for c, s in cstops:
        i = int(360 * ((s * stdevD) - minD) / (maxD - minD))
        i = min(max(i, 0), 359)
        v_ramp.append(i)
        v_ramp.extend(c)
        c_ramp.addColor(i, c)

    cmd.set_volume_ramp(name, v_ramp)
    cmd.volume_color(name, c_ramp.getRamp())
    cmd.recolor(name)
コード例 #6
0
 def test(self, normalize, ref):
     cmd.set('volume_data_range', 0)
     cmd.set('normalize_ccp4_maps', normalize)
     cmd.load(self.datafile('emd_1155.ccp4'), 'map')
     mmms = cmd.get_volume_histogram('map', 0)
     self.assertArrayEqual(mmms, ref, delta=0.05)