def get_6dof_cst(D3, D2, D1, U1, U2, U3): cur_cst = { "distanceAB": [0.0, 0.2, 80.0, 0, 0], "angle_A": [0.0, 5.0, 10.0, 360, 0], "angle_B": [0.0, 5.0, 10.0, 360, 0], "torsion_A": [0.0, 10.0, 10.0, 360, 0], "torsion_AB": [0.0, 10.0, 10.0, 360, 0], "torsion_B": [0.0, 10.0, 10.0, 360, 0] } if U1.split("/")[-1] == "NZ" and U2.split("/")[-1] == "CE" and U3.split( "/")[-1] == "2HZ": #means processing constraint for LYS cur_cst = { "distanceAB": [ 0.0, 0.1, 80.0, 1, 0 ], #the only difference is periodicity will be set at 1 indicating covalent interaction in the cst file "angle_A": [0.0, 5.0, 10.0, 360, 0], "angle_B": [0.0, 5.0, 10.0, 360, 0], "torsion_A": [0.0, 10.0, 10.0, 360, 0], "torsion_AB": [0.0, 10.0, 10.0, 360, 0], "torsion_B": [0.0, 10.0, 10.0, 360, 0] } cur_cst["distanceAB"][0] = round(cmd.get_distance(D1, U1), 1) cur_cst["angle_A"][0] = round(cmd.get_angle(D2, D1, U1), 1) cur_cst["angle_B"][0] = round(cmd.get_angle(D1, U1, U2), 1) cur_cst["torsion_A"][0] = round(cmd.get_dihedral(D3, D2, D1, U1), 1) cur_cst["torsion_AB"][0] = round(cmd.get_dihedral(D2, D1, U1, U2), 1) cur_cst["torsion_B"][0] = round(cmd.get_dihedral(D1, U1, U2, U3), 1) return cur_cst
def check_disulphide_criteria(pdb, resnum_i, resnum_j, f): selection_i = "resi " + str(resnum_i) selection_j = "resi " + str(resnum_j) for frame_i in [1, 2]: rotamer_i_pymol_prefix = "/" + "rotamer_" + str(resnum_i) + "_" + str(frame_i) + "///" + resnum_i + "/" chi1_i = cmd.get_dihedral(rotamer_i_pymol_prefix + "N", rotamer_i_pymol_prefix + "CA", rotamer_i_pymol_prefix + "CB", rotamer_i_pymol_prefix + "SG") theta_i = cmd.get_angle(rotamer_i_pymol_prefix + "CA", rotamer_i_pymol_prefix + "CB", rotamer_i_pymol_prefix + "SG") for frame_j in [1, 2]: rotamer_j_pymol_prefix = "/" + "rotamer_" + str(resnum_j) + "_" + str(frame_j) + "///" + resnum_j + "/" chi1_j = cmd.get_dihedral(rotamer_j_pymol_prefix + "N", rotamer_j_pymol_prefix + "CA", rotamer_j_pymol_prefix + "CB", rotamer_j_pymol_prefix + "SG") theta_j = cmd.get_angle(rotamer_j_pymol_prefix + "CA", rotamer_j_pymol_prefix + "CB", rotamer_j_pymol_prefix + "SG") chi3 = cmd.get_dihedral(rotamer_i_pymol_prefix + "CB", rotamer_i_pymol_prefix + "SG", rotamer_j_pymol_prefix + "SG", rotamer_j_pymol_prefix + "CB") #Energy = compute_energy(chi1_i, chi1_j, theta_i, theta_j, chi3) s_gamma_distance = cmd.get_distance(rotamer_i_pymol_prefix + "SG", rotamer_j_pymol_prefix + "SG") if (s_gamma_distance < 3 and ((chi3 > -110 and chi3 < -60) or (chi3 > 70 and chi3 < 130))): print rotamer_i_pymol_prefix, rotamer_j_pymol_prefix, s_gamma_distance, chi3 f.write("%s\t%s\t%f\t%f\n" % (rotamer_i_pymol_prefix, rotamer_j_pymol_prefix, s_gamma_distance, chi3)) rotamer_i = "rotamer_" + str(resnum_i) + "_" + str(frame_i) rotamer_j = "rotamer_" + str(resnum_j) + "_" + str(frame_j) cmd.enable(rotamer_i) cmd.enable(rotamer_j) cmd.distance(rotamer_i_pymol_prefix + "SG", rotamer_j_pymol_prefix + "SG") cmd.create(rotamer_i + rotamer_j, rotamer_i_pymol_prefix + "or" + rotamer_j_pymol_prefix)
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()
def AnglesFromPKSelection(selections = []): """ Function doc """ angles = {} if 'pk3' in selections: angles['pk1pk2pk3'] = str(cmd.get_angle('pk1','pk2','pk3')) else: angles['pk1pk2pk3'] = None if 'pk4' in selections: angles['pk2pk3pk4'] = str(cmd.get_angle('pk2','pk3', 'pk4') ) else: angles['pk2pk3pk4'] = None return angles
def find_beta_hbonds(selection, mindist, maxdist, anglemin, verbose: bool = False, nitrogen_atomnames='N+NT', oxygen_atomnames='O+OT1+OT2', hydrogen_atomnames='H+HN+HT1+HT2+HT+H1+H2+H3'): """ Detect hydrogen bonds in beta peptides (and probably other peptides, too) Inputs: selection: a selection containing everything, """ donors = cmd.get_model('({}) and name {}'.format(selection, nitrogen_atomnames)) acceptors = cmd.get_model('({}) and name {}'.format( selection, oxygen_atomnames)) if verbose: print('Finding hydrogen bonds in selection {}'.format(selection)) print('Donors: {}'.format(len(donors.atom))) print('Acceptors: {}'.format(len(acceptors.atom))) for d in donors.atom: assert isinstance(d, chempy.Atom) hydrogens = cmd.get_model( '(neighbor (({}) and index {})) and name {}'.format( selection, d.index, hydrogen_atomnames)) if verbose: print('Looking at donor {}, having {} hydrogens'.format( d.index, len(hydrogens.atom))) for h in hydrogens.atom: assert isinstance(h, chempy.Atom) for a in acceptors.atom: assert isinstance(a, chempy.Atom) # check hydrogen-acceptor distance dist = cmd.get_distance( '({}) and name {} and index {}'.format( selection, oxygen_atomnames, a.index), '({}) and name {} and index {}'.format( selection, hydrogen_atomnames, h.index)) cmd.unpick() angle = cmd.get_angle( '({}) and name {} and index {}'.format( selection, oxygen_atomnames, a.index), '({}) and name {} and index {}'.format( selection, hydrogen_atomnames, h.index), '({}) and name {} and index {}'.format( selection, nitrogen_atomnames, d.index)) if verbose: print('Distance between hydrogen {} and acceptor {}: {}'. format(h.index, a.index, dist)) print( 'Angle between donor {}, hydrogen {} and acceptor {}: {}' .format(d.index, h.index, a.index, angle)) if (dist <= float(maxdist)) and (dist >= float(mindist)) and ( angle >= float(anglemin)): yield d.index, h.index, a.index, dist, angle
def get_hbangles(angles, resmin, resmax, resistep, selection='all', helicize=True): if helicize: helicize_beta_peptide(angles, selection) angles = [] for r, rstep in zip(range(resmin, resmax + 1), itertools.cycle(resistep)): if rstep == 0: continue if r<resmin or r+rstep<resmin or r>resmax or r+rstep>resmax: continue selections = ['({}) and resi {} and name N'.format(selection, r), '({}) and resi {} and name HN'.format(selection, r), '({}) and resi {} and name O'.format(selection, r + rstep)] if any([cmd.count_atoms(sel) == 0 for sel in selections]): continue angles.append(cmd.get_angle(*selections)) return angles
def zero_z(selection, ref_atom): try: cmd.remove("pseud_ang1") cmd.remove("pseud_ang2") except pymol.CmdException: print("No atoms removed") cmd.pseudoatom("pseud_ang1", pos=[0, get_pos(ref_atom)[0][1], 0]) cmd.pseudoatom("pseud_ang2", pos=[get_pos(ref_atom)[0][0], get_pos(ref_atom)[0][1], 0]) angle = cmd.get_angle(atom1=ref_atom, atom2="pseud_ang1", atom3="pseud_ang2") ang = rotate_sel(selection, "y", angle, ref_atom) return ang
def find_hbonds(selection_donor_and_hydrogen, selection_acceptor=None, dmin: float = 1., dmax: float = 2.5, anglemin: float = 135): dmin = float(dmin) dmax = float(dmax) anglemin = float(anglemin) selection_hydrogen = '({}) and (e. H)'.format(selection_donor_and_hydrogen) found_bonds = [] if selection_acceptor is None: selection_acceptor = selection_donor_and_hydrogen for acceptor in iterate_indices( '({}) and (e. N+O)'.format(selection_acceptor)): print('Trying acceptor idx {}'.format(acceptor)) for hydrogen in iterate_indices( '({}) and (e. H) and not (neighbor (idx {} and ({})))'.format( selection_hydrogen, acceptor, selection_acceptor)): donors = list( iterate_indices( 'neighbor ((idx {}) and ({})) and not ((idx {}) and ({}))'. format(hydrogen, selection_hydrogen, acceptor, selection_acceptor))) donor = donors[0] dist = cmd.get_distance( '(idx {}) and ({})'.format(hydrogen, selection_hydrogen), '(idx {}) and ({})'.format(acceptor, selection_acceptor)) angle = cmd.get_angle( '(idx {}) and ({})'.format(donor, selection_donor_and_hydrogen), '(idx {}) and ({})'.format(hydrogen, selection_hydrogen), '(idx {}) and ({})'.format(acceptor, selection_acceptor)) if dist >= dmin and dist <= dmax and angle >= anglemin: found_bonds.append((donor, hydrogen, acceptor, dist, angle)) for donor, hydrogen, acceptor, dist, angle in found_bonds: yield (acceptor, hydrogen, dist)
print([translation_vector[0][0],translation_vector[0][1],translation_vector[0][2]]) #translate molecule from mol file to 0,0,0 cmd.translate([translation_vector[0][0],translation_vector[0][1],translation_vector[0][2]],"circ_complex",-1,0) #get coordinates from ligand and mol file complex pos_halligand = [] pos_halcomplex = [] cmd.iterate_state(1, 'halligand', 'pos_halligand.append((x,y,z))') cmd.iterate_state(1, 'halcomplex', 'pos_halcomplex.append((x,y,z))') pos_halligand = np.array(pos_halligand) #add pseudoatom on x axis to measure angle for rotation around y axis cmd.pseudoatom("x-1",pos=[-1,0,0]) #measure angle for molfile rotation angle = cmd.get_angle(atom1="cicomplex",atom2="halcomplex",atom3="x-1") #rotate mol file cmd.rotate("z",180,"circ_complex",0,0,origin=[0,0,0]) #cmd.pseudoatom("e",pos=[-2,0,z_temp]) print(angle) print(pos_halligand[0][2]) cmd.pseudoatom("z1",pos=[0,0,1]) cmd.pseudoatom("pseudo_ciligand",pos=[pos_ciligand[0][0],pos_ciligand[0][1],pos_ciligand[0][2]]) cmd.pseudoatom("pseudo_c2ligand",pos=[pos_c2ligand[0][0],pos_c2ligand[0][1],pos_c2ligand[0][2]]) cmd.pseudoatom("pseudo_halligand",pos=[pos_halligand[0][0],pos_halligand[0][1],pos_halligand[0][2]]) cmd.select("pseudo_ligand","pseudo_*ligand")
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)
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)
with open(filename, 'r') as f: lines = f.readlines() lines = list(filter(filter_func, lines)) ang_pairs.extend(list(map(map_func, lines))) restraints.extend(list(map(map_func2, lines))) out_lines = [] for ang_pair, restraint in zip(ang_pairs, restraints): group1 = "(id %d)" % ang_pair[0] group2 = "(id %d)" % ang_pair[1] group3 = "(id %d)" % ang_pair[2] cmd.angle("%d-%d-%d" % ang_pair, group1, group2, group3) resns = [] resis = [] atoms = [] cmd.iterate("id %d+%d+%d" % ang_pair, "resns.append(resn)") cmd.iterate("id %d+%d+%d" % ang_pair, "resis.append(resi)") cmd.iterate("id %d+%d+%d" % ang_pair, "atoms.append(name)") angle = cmd.get_angle(group1, group2, group3) out_lines.append( "[ %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], angle) + restraint)) out_lines.append("%d %d %d\n" % ang_pair) # write dis_pairs to distance_pairs.ndx for analysis with open("angle_out.ndx", 'w') as f: for line in out_lines: f.write(line) print(line)