Example #1
0
    def testRepsExist(self):
        cmd.viewport(200, 150)
        cmd.load(self.datafile('1oky-frag.pdb'), 'm1')

        # make some nonbonded
        cmd.unbond('resi 115-', 'resi 115-')

        # labels
        cmd.label('all', 'name')

        # measurements
        cmd.distance('measure1', 'index 1', 'index 10')
        cmd.angle('measure1', 'index 1', 'index 10', 'index 20')
        cmd.dihedral('measure1', 'index 1', 'index 10', 'index 20', 'index 30')

        # color test setup
        cmd.color('white', '*')
        cmd.set('ambient', 1)
        cmd.set('depth_cue', 0)
        cmd.set('antialias', 0)
        cmd.set('line_smooth', 0)
        cmd.orient()

        # test most reps
        for rep in REPS:
            cmd.show_as(rep)
            self.assertImageHasColor('white', msg='rep missing: ' + rep)

        # test cartoon
        cmd.show_as('cartoon')
        for cart in CARTOONS:
            cmd.cartoon(cart)
            self.assertImageHasColor('white', msg='cartoon missing: ' + cart)
Example #2
0
    def testRepsExist(self):
        cmd.viewport(200, 150)
        cmd.load(self.datafile('1oky-frag.pdb'), 'm1')

        # make some nonbonded
        cmd.unbond('resi 115-', 'resi 115-')

        # labels
        cmd.label('all', 'name')

        # measurements
        cmd.distance('measure1', 'index 1', 'index 10')
        cmd.angle('measure1', 'index 1', 'index 10', 'index 20')
        cmd.dihedral('measure1', 'index 1', 'index 10', 'index 20', 'index 30')

        # color test setup
        cmd.color('white', '*')
        cmd.set('ambient', 1)
        cmd.set('depth_cue', 0)
        cmd.set('antialias', 0)
        cmd.set('line_smooth', 0)
        cmd.orient()

        # test most reps
        for rep in REPS:
            cmd.show_as(rep)
            self.assertImageHasColor('white', msg='rep missing: ' + rep)

        # test cartoon
        cmd.show_as('cartoon')
        for cart in CARTOONS:
            cmd.cartoon(cart)
            self.assertImageHasColor('white', msg='cartoon missing: ' + cart)
def draw_axis(chA, chB, scale_factor=20, w=0.6, r1=1, g1=1, b1=1, r2=1, g2=0, b2=0):
    T = transf_matrix(chA, chB)
    angle=angle_axis(chA, chB)
    angle_degrees=(angle*180)/math.pi
    axis1=[direction_cosines(chA, chB)[0], direction_cosines(chA, chB)[1], direction_cosines(chA, chB)[2]]
    p = nearest_point_to_axis(chA, chB)
    x1, y1, z1 = p[0] + (3*scale_factor*axis1[0]), p[1] + (3*scale_factor*axis1[1]), p[2] + (3*scale_factor*axis1[2])
    x2, y2, z2 = p[0] - (3*scale_factor*axis1[0]), p[1] - (3*scale_factor*axis1[1]), p[2] - (3*scale_factor*axis1[2])
    obj = [cgo.CYLINDER, x1, y1, z1, x2, y2, z2, w, r1, g1, b1, r2, g2, b2, 0.0]
    cmd.load_cgo(obj, angle_degrees)

    cmA=center_of_Mass(chA)
    cmB=cmW
    cmAver=(cmB+cmA)/2
    vector=numpy.array([(cmB[0]-cmA[0]), (cmB[1]-cmA[1]), (cmB[2]-cmA[2])])
    moduli_vector=numpy.linalg.norm(vector)
    vector_director=numpy.array([(cmB[0]-cmA[0])/moduli_vector, (cmB[1]-cmA[1])/moduli_vector, (cmB[2]-cmA[2])/moduli_vector])
    pC_A = proyeccion_centroide(chA, chA, chB)
    pC_B = proyeccion_centroide_working(chA, chB)


    trans_vector = numpy.array([(pC_B[0]-pC_A[0]), (pC_B[1]-pC_A[1]), (pC_B[2]-pC_A[2])])
    modu_tr = numpy.linalg.norm(trans_vector)
    rota_centroid_rad=numpy.dot(vector_director, axis1)
    rota_centroid = (rota_centroid_rad*180)/math.pi
    rota_centroid_absol_0= numpy.absolute(rota_centroid)
    rota_centroid_absol=round(rota_centroid_absol_0,2)


    if rota_centroid_absol == 0.00:
        p1 = '_1'
        p2 = '_2'
        p3 = '_3'
        cmd.pseudoatom (pos=[cmA[0], cmA[1], cmA[2]], object=p1)
        cmd.pseudoatom (pos=[pC_A[0], pC_A[1], pC_A[2]], object=p2)
        cmd.pseudoatom (pos=[cmB[0], cmB[1], cmB[2]], object=p3)
        cmd.angle(None, p1, p2, p3)
        print_information(T, axis1, angle_degrees,  moduli_vector, obj, x1, y1, z1, x2, y2, z2, w, r1, g1, b1, r2, g2, b2)

    if rota_centroid_absol != 0:
        p1 = '_1'
        p2 = '_2'
        p3 = '_3'
        p4 = '_4'
        cmd.pseudoatom (pos=[cmA[0], cmA[1], cmA[2]], object=p1)
        cmd.pseudoatom (pos=[pC_A[0], pC_A[1], pC_A[2]], object=p2)
        cmd.pseudoatom (pos=[pC_B[0], pC_B[1], pC_B[2]], object=p3)
        cmd.pseudoatom (pos=[cmB[0], cmB[1], cmB[2]], object=p4)
        cmd.dihedral(None, p1, p2, p3, p4)
        cmd.distance(None, p2, p3)
        print_information(T, axis1, angle_degrees,  moduli_vector, obj, x1, y1, z1, x2, y2, z2, w, r1, g1, b1, r2, g2, b2, modu_tr)

    cmd.create('working', chA)
    cmd.super('working', chB)
Example #4
0
    def testDihedralColor(self):
        cmd.fragment('ala')
        cmd.color('blue')
        cmd.dihedral('dih01', 'index 8', 'index 5', 'index 2', 'index 1')
        cmd.hide('label')
        cmd.set('fog', '0')
        cmd.set('ambient', '1')
        cmd.set('dihedral_color', 'red')
        cmd.zoom()

        #need to check to make sure screen image has red in it
        img_array = self.get_imagearray(width=100, height=100, ray=0)
        self.assertImageHasColor('red', img_array)
Example #5
0
 def doFinish(self):
     r_aA = cmd.get_distance(atom1="pw2", atom2="pw3", state=0)
     cmd.distance(self.params_str[0], "pw2", "pw3")
     th_a = cmd.get_angle(atom1="pw1", atom2="pw2", atom3="pw3", state=0)
     cmd.angle(self.params_str[1], "pw1", "pw2", "pw3")
     th_A = cmd.get_angle(atom1="pw2", atom2="pw3", atom3="pw4", state=0)
     cmd.angle(self.params_str[2], "pw2", "pw3", "pw4")
     if not (r_aA and th_a and th_A):
         showerror(self.parent, "Error!",
                   "Maybe you made a mistake when choosing atoms!")
         self.reset()
     phi_ba = cmd.get_dihedral(atom1="pw0",
                               atom2="pw1",
                               atom3="pw2",
                               atom4="pw3",
                               state=0)
     cmd.dihedral(self.params_str[3], "pw0", "pw1", "pw2", "pw3")
     phi_aA = cmd.get_dihedral(atom1="pw1",
                               atom2="pw2",
                               atom3="pw3",
                               atom4="pw4",
                               state=0)
     cmd.dihedral(self.params_str[4], "pw1", "pw2", "pw3", "pw4")
     phi_AB = cmd.get_dihedral(atom1="pw2",
                               atom2="pw3",
                               atom3="pw4",
                               atom4="pw5",
                               state=0)
     cmd.dihedral(self.params_str[5], "pw2", "pw3", "pw4", "pw5")
     index_c = cmd.id_atom("pw0")
     index_c_name = getAtomString('pw0')
     index_b = cmd.id_atom("pw1")
     index_b_name = getAtomString('pw1')
     index_a = cmd.id_atom("pw2")
     index_a_name = getAtomString('pw2')
     index_A = cmd.id_atom("pw3")
     index_A_name = getAtomString('pw3')
     index_B = cmd.id_atom("pw4")
     index_B_name = getAtomString('pw4')
     index_C = cmd.id_atom("pw5")
     index_C_name = getAtomString('pw5')
     self.setBondForceParam(r_aA, th_a, th_A, phi_ba, phi_aA, phi_AB,
                            index_c, index_b, index_a, index_A, index_B,
                            index_C)
     self.setAtomsDef(index_c_name, index_b_name, index_a_name,
                      index_A_name, index_B_name, index_C_name)
     top = Toplevel(
         self.parent)  # <- freeze when open gro file in pymol 1.X
     Output(top, self.bondForceParams, self.atoms_def)
     cmd.set_wizard()
Example #6
0
def draw_axis(chA,
              chB,
              scale_factor=20,
              w=0.6,
              r1=1,
              g1=1,
              b1=1,
              r2=1,
              g2=0,
              b2=0):
    T = transf_matrix(chA, chB)
    angle = angle_axis(chA, chB)
    angle_degrees = (angle * 180) / math.pi
    axis1 = [
        direction_cosines(chA, chB)[0],
        direction_cosines(chA, chB)[1],
        direction_cosines(chA, chB)[2]
    ]
    p = nearest_point_to_axis(chA, chB)
    x1, y1, z1 = p[0] + (3 * scale_factor * axis1[0]), p[1] + (
        3 * scale_factor * axis1[1]), p[2] + (3 * scale_factor * axis1[2])
    x2, y2, z2 = p[0] - (3 * scale_factor * axis1[0]), p[1] - (
        3 * scale_factor * axis1[1]), p[2] - (3 * scale_factor * axis1[2])
    obj = [
        cgo.CYLINDER, x1, y1, z1, x2, y2, z2, w, r1, g1, b1, r2, g2, b2, 0.0
    ]
    cmd.load_cgo(obj, angle_degrees)

    cmA = center_of_Mass(chA)
    cmB = cmW
    cmAver = (cmB + cmA) / 2
    vector = numpy.array([(cmB[0] - cmA[0]), (cmB[1] - cmA[1]),
                          (cmB[2] - cmA[2])])
    moduli_vector = numpy.linalg.norm(vector)
    vector_director = numpy.array([(cmB[0] - cmA[0]) / moduli_vector,
                                   (cmB[1] - cmA[1]) / moduli_vector,
                                   (cmB[2] - cmA[2]) / moduli_vector])
    pC_A = proyeccion_centroide(chA, chA, chB)
    pC_B = proyeccion_centroide_working(chA, chB)

    trans_vector = numpy.array([(pC_B[0] - pC_A[0]), (pC_B[1] - pC_A[1]),
                                (pC_B[2] - pC_A[2])])
    modu_tr = numpy.linalg.norm(trans_vector)
    rota_centroid_rad = numpy.dot(vector_director, axis1)
    rota_centroid = (rota_centroid_rad * 180) / math.pi
    rota_centroid_absol_0 = numpy.absolute(rota_centroid)
    rota_centroid_absol = round(rota_centroid_absol_0, 2)

    if rota_centroid_absol == 0.00:
        p1 = '_1'
        p2 = '_2'
        p3 = '_3'
        cmd.pseudoatom(pos=[cmA[0], cmA[1], cmA[2]], object=p1)
        cmd.pseudoatom(pos=[pC_A[0], pC_A[1], pC_A[2]], object=p2)
        cmd.pseudoatom(pos=[cmB[0], cmB[1], cmB[2]], object=p3)
        cmd.angle(None, p1, p2, p3)
        print_information(T, axis1, angle_degrees, moduli_vector, obj, x1, y1,
                          z1, x2, y2, z2, w, r1, g1, b1, r2, g2, b2)

    if rota_centroid_absol != 0:
        p1 = '_1'
        p2 = '_2'
        p3 = '_3'
        p4 = '_4'
        cmd.pseudoatom(pos=[cmA[0], cmA[1], cmA[2]], object=p1)
        cmd.pseudoatom(pos=[pC_A[0], pC_A[1], pC_A[2]], object=p2)
        cmd.pseudoatom(pos=[pC_B[0], pC_B[1], pC_B[2]], object=p3)
        cmd.pseudoatom(pos=[cmB[0], cmB[1], cmB[2]], object=p4)
        cmd.dihedral(None, p1, p2, p3, p4)
        cmd.distance(None, p2, p3)
        print_information(T, axis1, angle_degrees, moduli_vector, obj, x1, y1,
                          z1, x2, y2, z2, w, r1, g1, b1, r2, g2, b2, modu_tr)

    cmd.create('working', chA)
    cmd.super('working', chB)
Example #7
0
def ens_measure(pk1=None,
                pk2=None,
                pk3=None,
                pk4=None,
                name=None,
                log=None,
                verbose=True):
    '''
DESCRIPTION

    Statistics from ensemble structure measurements.  If:
      2 selections give = distance
      3 selections give = angle
      4 selections give = dihedral angle

USAGE

    ens_measure pk1, pk2, pk3, pk4, name, log, verbose

ARGUMENTS

    log = name of log file
    verbose = prints individual measurements

 EXAMPLE

    ens_measure atom1, atom2, name = 'measure', log 'ens.log'
  '''
    print('\nEnsemble measurement', file=log)

    if [pk1, pk2, pk3, pk4].count(None) > 2:
        print('\nERROR: Please supply at least 2 seletions')
        return
    number_models = cmd.count_states(pk1)
    measurements = []

    # distance
    if [pk1, pk2, pk3, pk4].count(None) == 2:
        print('Distance', file=log)
        if name == None: name = 'ens_distance'
        # display as object
        cmd.distance(name=name, selection1=pk1, selection2=pk2)

        # get individual values
        for n in range(number_models):
            measurements.append(cmd.get_distance(pk1, pk2, n + 1))
        assert len(measurements) == number_models

    # angle
    if [pk1, pk2, pk3, pk4].count(None) == 1:
        print('Angle', file=log)
        # display as object
        if name == None: name = 'ens_angle'
        cmd.angle(name=name, selection1=pk1, selection2=pk2, selection3=pk3)

        # get individual values
        for n in range(number_models):
            measurements.append(
                cmd.get_angle(atom1=pk1, atom2=pk2, atom3=pk3, state=n + 1))
        assert len(measurements) == number_models

    # Dihedral angle
    if [pk1, pk2, pk3, pk4].count(None) == 0:
        print('Dihedral angle', file=log)
        # display as object
        if name == None: name = 'ens_dihedral'
        cmd.dihedral(name=name,
                     selection1=pk1,
                     selection2=pk2,
                     selection3=pk3,
                     selection4=pk4)

        # get individual values
        for n in range(number_models):
            measurements.append(
                cmd.get_dihedral(atom1=pk1,
                                 atom2=pk2,
                                 atom3=pk3,
                                 atom4=pk4,
                                 state=n + 1))
        assert len(measurements) == number_models

    # print stats
    if verbose:
        print(' State  Value', file=log)
        for n, measurement in enumerate(measurements):
            print('  %4d  %3.3f ' % (n + 1, measurement), file=log)

    print('\nMeasurement statistics', file=log)
    print_array_stats(array=measurements, log=log)
Example #8
0
def ens_measure(pk1 = None,
                pk2 = None,
                pk3 = None,
                pk4 = None,
                name = None,
                log = None,
                verbose = True):
    '''
DESCRIPTION

    Statistics from ensemble structure measurements.  If:
      2 selections give = distance
      3 selections give = angle
      4 selections give = dihedral angle

USAGE

    ens_measure pk1, pk2, pk3, pk4, name, log, verbose

ARGUMENTS

    log = name of log file
    verbose = prints individual measurements

 EXAMPLE

    ens_measure atom1, atom2, name = 'measure', log 'ens.log'
  '''
    print >> log, '\nEnsemble measurement'

    if [pk1, pk2, pk3, pk4].count(None) > 2:
        print '\nERROR: Please supply at least 2 seletions'
        return
    number_models = cmd.count_states(pk1)
    measurements = []

    # distance
    if [pk1, pk2, pk3, pk4].count(None) == 2:
        print >> log, 'Distance'
        if name == None: name = 'ens_distance'
        # display as object
        cmd.distance(name = name,
                     selection1 = pk1,
                     selection2 = pk2)

        # get individual values
        for n in xrange(number_models):
            measurements.append( cmd.get_distance(pk1, pk2, n+1) )
        assert len(measurements) == number_models

    # angle
    if [pk1, pk2, pk3, pk4].count(None) == 1:
        print >> log, 'Angle'
        # display as object
        if name == None: name = 'ens_angle'
        cmd.angle(name = name,
                  selection1 = pk1,
                  selection2 = pk2,
                  selection3 = pk3)

        # get individual values
        for n in xrange(number_models):
            measurements.append( cmd.get_angle(atom1 = pk1,
                                               atom2 = pk2,
                                               atom3 = pk3,
                                               state = n+1) )
        assert len(measurements) == number_models

    # Dihedral angle
    if [pk1, pk2, pk3, pk4].count(None) == 0:
        print >> log, 'Dihedral angle'
        # display as object
        if name == None: name = 'ens_dihedral'
        cmd.dihedral(name = name,
                  selection1 = pk1,
                  selection2 = pk2,
                  selection3 = pk3,
                  selection4 = pk4)

        # get individual values
        for n in xrange(number_models):
            measurements.append( cmd.get_dihedral(atom1 = pk1,
                                                  atom2 = pk2,
                                                  atom3 = pk3,
                                                  atom4 = pk4,
                                                  state = n+1) )
        assert len(measurements) == number_models

    # print stats
    if verbose:
        print >> log, ' State  Value'
        for n, measurement in enumerate(measurements):
            print >> log, '  %4d  %3.3f '%(n+1, measurement)

    print >> log, '\nMeasurement statistics'
    print_array_stats(array                 = measurements,
                      log                   = log)
Example #9
0
restraints = []

for filename in filenames:
    with open(filename, 'r') as f:
        lines = f.readlines()
        lines = list(filter(filter_func , lines))
        dih_pairs.extend(list(map(map_func, lines)))
        restraints.extend(list(map(map_func2, lines)))

out_lines = []
for dih_pair,restraint in zip(dih_pairs, restraints):
    group1 = "(id %d)" % dih_pair[0]
    group2 = "(id %d)" % dih_pair[1]
    group3 = "(id %d)" % dih_pair[2]
    group4 = "(id %d)" % dih_pair[3]
    cmd.dihedral("%d-%d-%d-%d" % dih_pair, group1, group2, group3, group4)
    resns = []
    resis = []
    atoms = []
    cmd.iterate("id %d+%d+%d+%d" % dih_pair, "resns.append(resn)")
    cmd.iterate("id %d+%d+%d+%d" % dih_pair, "resis.append(resi)")
    cmd.iterate("id %d+%d+%d+%d" % dih_pair, "atoms.append(name)")
    dihedral = cmd.get_dihedral(group1, group2, group3, group4)
    out_lines.append("[ %s%s(%s)-%s%s(%s)-%s%s(%s)-%s%s(%s) ~ %.2f degree (%s, %s, %s)]\n" % ((resns[0], resis[0], atoms[0], resns[1], resis[1], atoms[1], resns[2], resis[2], atoms[2],resns[3], resis[3], atoms[3],  dihedral) + restraint))
    out_lines.append("%d %d %d %d\n" % dih_pair)

# write dis_pairs to distance_pairs.ndx for analysis
with open("dihedral_out.ndx", 'w') as f:
    for line in out_lines:
        f.write(line)
        print(line)