def testSaveRef(self, format): # for rms_cur (not all formats save all identifiers) m = -1 cmd.set('retain_order') cmd.fragment('ala', 'm1') cmd.copy('m2', 'm1') cmd.copy('m3', 'm1') cmd.rotate('y', 90, 'm2') cmd.align('m3', 'm2') # with ref=m3 with testing.mktemp('.' + format) as filename: cmd.save(filename, 'm2', ref='m3') cmd.load(filename, 'm4') self.assertAlmostEqual(cmd.rms_cur('m4', 'm1', matchmaker=m), 0.00, delta=1e-2) self.assertAlmostEqual(cmd.rms_cur('m4', 'm2', matchmaker=m), 1.87, delta=1e-2) # without ref with testing.mktemp('.' + format) as filename: cmd.save(filename, 'm2') cmd.load(filename, 'm5') self.assertAlmostEqual(cmd.rms_cur('m5', 'm2', matchmaker=m), 0.00, delta=1e-2) self.assertAlmostEqual(cmd.rms_cur('m5', 'm1', matchmaker=m), 1.87, delta=1e-2)
def zoom_tetramer_1a8y(object_name): # Get a neutral, symmetric view of the molecule(s) # cmd.viewport(viewport_width_tetramer(), viewport_height_tetramer()) cmd.orient(object_name) cmd.rotate("y", 180) cmd.zoom("center", 45) return
def TMdistCheck(selection, z): """ determine cross section distances about origin of trans-membrane region of protein PDB (distance from origin to protein atoms in xy plane) """ cmd.pseudoatom("origin0", pos=[0, 0, 10]) dmax = [] for ang in range(0, 181, 10): dlist = [] cmd.rotate('z', ang, selection) xLine = "{} and z > {} and z < {} and y > {} and y < {}".format(selection, -z, z, -z, z) atoms = cmd.index(xLine) if len(atoms) == 0: print("No atoms in {}.".format(xLine)) continue # find R in only one cross-section for at1 in cmd.index("origin0"): for at2 in atoms: dist = cmd.get_distance(atom1=at1, atom2=at2, state=0) dlist.append(dist) dmax.append(max(dlist)) cmd.rotate('z', -ang, selection) if len(dmax) == 0: meanXY = -1 else: meanXY = np.mean(dmax) cmd.pseudoatom("origin0", pos=[0, 0, 0]) return meanXY
def builderMicelle(detergent, r, numberOfDetergents): i = 0 numberOfDetergents = (int)(numberOfDetergents) #FIXME: if number of detergents > 360, molecules may clash in space if numberOfDetergents > 360: x1 = range(-180, 180) x2 = range(0, 360) theta = ([random.choice(x1) for _ in range(numberOfDetergents)]) phi = ([random.choice(x2) for _ in range(numberOfDetergents)]) else: theta = random.sample(range(-180, 180), numberOfDetergents) phi = random.sample(range(0, 360), numberOfDetergents) for t, p in zip(theta, phi): i += 1 cmd.copy(f"seg{i}", detergent) # randomly sample on a sphere cmd.translate(f"[0,{r},0]", f"seg{i}") cmd.rotate("x", f"{t}", f"seg{i}") cmd.rotate("z", f"{p}", f"seg{i}") s = f"micelle_{detergent}_{(int)(r)}_{(int)(numberOfDetergents)}" cmd.create(f"{s}", "seg*") cmd.delete("seg*") #center(f"{s}") #cmd.show_as("sticks","org") # could be streched if necessary # affineStretch(s, 10) return s
def testGetObjectMatrix(self): identity = (1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0) mat_x90 = (1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0) cmd.fragment('ala', 'm1') cmd.fragment('gly', 'm2') # default/identity mat = cmd.get_object_matrix('m1', incl_ttt=1) self.assertTrue(isinstance(mat, tuple)) self.assertArrayEqual(mat, identity, delta=1e-6) mat = cmd.get_object_matrix('m1', incl_ttt=0) self.assertArrayEqual(mat, identity, delta=1e-6) # TTT cmd.rotate('x', 90, object='m1', camera=0, object_mode=0) mat = cmd.get_object_matrix('m1', incl_ttt=1) self.assertArrayEqual(mat, mat_x90, delta=1e-6) mat = cmd.get_object_matrix('m1', incl_ttt=0) self.assertArrayEqual(mat, identity, delta=1e-6) # state matrix cmd.rotate('x', 90, object='m2', camera=0, object_mode=1) mat = cmd.get_object_matrix('m2', incl_ttt=1) self.assertArrayEqual(mat, mat_x90, delta=1e-6) mat = cmd.get_object_matrix('m2', incl_ttt=0) self.assertArrayEqual(mat, mat_x90, delta=1e-6)
def rotate_and_capture(self, rotation_axis, increment, res_width, res_height): self.images_for_gif = [] self.images_for_mp4 = [] # cycles through all possible angles (multiple of increment) for current_angle in range(0, 360, increment): cmd.rotate(rotation_axis, angle=increment) # creates the file folder if it doesn't exist if not os.path.exists(str(self.file_path)): os.makedirs(str(self.file_path)) # file_name = str(self.file_path/"{}_{}.png".format(self.protein, str(current_angle))) file_name = str(self.file_path / f"{self.method.name}_{str(current_angle)}.png") cmd.zoom(complete=1) cmd.png(file_name, width=res_width, height=res_height, dpi=500, ray=1, quiet=0) self.drawLegend(file_name, res_width, res_height) self.images_for_gif.append(imageio.imread(file_name)) self.images_for_mp4.append(cv2.imread(file_name))
def rot(sel, axis, ang, cen=Vec(0, 0, 0)): # if cen is None: cen = com(sel) if abs(axis.x) < 0.00001: axis.x = 0.0 if abs(axis.y) < 0.00001: axis.y = 0.0 if abs(axis.z) < 0.00001: axis.z = 0.0 cmd.rotate([axis.x, axis.y, axis.z], ang, sel, 0, 0, None, [cen.x, cen.y, cen.z])
def my_rotate(name, axis, angle, states, **kwargs): for i in range(int(states)): cmd.create(name, name, 1, i + 1) cmd.rotate(axis, float(angle) * i / int(states), name, state=i + 1, camera=0, **kwargs)
def zoom_tetramer_deo(object_name): # Get a neutral, symmetric view of the molecule(s) # Note: this is the best view overall, but not the best view for observing the interface. # cmd.viewport(viewport_width_tetramer(), viewport_height_tetramer()) cmd.orient(object_name) # cmd.rotate("x", 180) cmd.rotate("y", 180) cmd.zoom("center", 45) return
def builderMembrane(lipid, runNumber): """ build membrane bilayer from single lipid PDB file """ refresh() cmd.load(lipid + ".pdb", "start_lipid") cmd.alter("start_lipid", "chain = 'X'") cmd.alter("start_lipid", "segi = 'mema'") # cmd.rotate('x', 90, "start_lipid") dmax = findMaxDist("start_lipid") # create lipid copies and translate them to new position nlip = 20 # number of lipids forming edge of bilayer s0 = range(1, nlip, 1) s1 = range(1, nlip + 1, 1) # excludes first lipid step_x = 0 # translation in x (TODO: automatic determination of spacing without clashes) step_y = 7 step_z = 0 step_x2 = 7 step_y2 = 0 step_z2 = 0 for i in s1: # first column cmd.copy("lip{}".format(i), "start_lipid") # row of lipids cmd.alter("lip{}".format(i), "resi={}".format(i)) # change residue numbers y = i * step_y cmd.translate("[{},{},{}]".format(step_x, y, step_z), "lip{}".format(i)) # generate remaining rows/columns in same leaflet for j in s0: k = int(nlip) * i + j # TODO: general counter to write correct lipid number cmd.copy("lip{}".format(k), "lip{}".format(i)) # adjacent row of lipids cmd.alter("lip{}".format(k), "resi={}".format(k)) # change residue numbers x2 = j * step_x2 cmd.translate("[{},{},{}]".format(x2, step_y2, step_z2), "lip{}".format(k)) cmd.sort() # sort atom order # create second leaflet # simple method by creating a single leaflet object: cmd.create("mema", "(lip*)") cmd.delete("lip*") cmd.copy("memb", "mema") cmd.alter("memb", "segi = 'memb'") cmd.rotate("x", 180, "memb") cmd.translate("[0,0,{}]".format((-1.0 * (dmax + 0.5))), "memb") # cmd.color("yellow", "segi = 'mema'") # cmd.color("blue", "segi = 'memb'") cmd.translate("[3.5,3.5,0]", "memb") # optional shift of single leaflet to avoid aliphatic clashes s = "{}_bilayer".format(lipid) cmd.create(s, "(mema,memb)") cmd.delete("mema ,memb, start_lipid") center(s) cmd.save(s + ".pdb", s) cmd.reset() return s
def testMorphRigimol(self): cmd.set('suspend_undo') import epymol.rigimol cmd.fab('ACD', 'm1') cmd.create('m1', 'm1', 1, 2) cmd.rotate('x', 90, 'm1', 2) steps = 5 cmd.morph('mout', 'm1', refinement=1, steps=steps, method='rigimol') self.assertEqual(steps, cmd.count_states('mout')) self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('mout'))
def align_helix_axis(sele='all', state=1): print('align_helix_axis', f'({sele}) and name CA') axis, cen = helix_axis(sele, state) print('axis', axis) print('cen ', cen) # showline(axis * 1000, cen) cmd.rotate(list((axis[:3] + [0, 0, 1]) / 2), 180, selection=sele) cmd.translate(list(-calc_com(f'{sele} and name CA'))) axis, cen = helix_axis(sele, state) cen[2] = 0 cmd.translate(list(-cen))
def test(self): cmd.set('suspend_undo') cmd.fragment('gly', 'm1') cmd.remove('not ID 0+1') cmd.create('m1', 'm1', 1, 2) cmd.rotate('x', 90, 'm1', 2) steps = 5 cmd.morph('mout', 'm1', refinement=0, steps=steps, method='rigimol') self.assertEqual(steps, cmd.count_states('mout')) self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('mout'))
def test_matrix_copy(self): cmd.fragment('ala') cmd.fragment('gly') cmd.rotate('x', 90, 'none', object='ala') cmd.matrix_copy('ala', 'gly') self.assertArrayEqual(cmd.get_object_matrix('gly'), (1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), 1e-4) cmd.matrix_reset('gly', mode=1) self.assertArrayEqual(cmd.get_object_matrix('gly'), (1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0), 1e-4)
def rotation_series(axis, increment, width, height, filename, with_centering): if (increment == 0): max_turns = 1 else: max_turns = (360/increment) + 1 for x in range(max_turns): if x > 0: cmd.rotate(axis, increment) if with_centering: cmd.center("(all)") cmd.ray(width, height) cmd.png(filename + "_" + str(x * increment) + ".png", dpi=dpi()) return
def testMorphMulti(self): cmd.set('suspend_undo') cmd.fab('ACD', 'm1') cmd.create('m1', 'm1', 1, 2) cmd.create('m1', 'm1', 1, 3) cmd.rotate('x', 90, 'm1', 2) cmd.rotate('x', 45, 'm1', 3) steps = 5 cmd.morph('mout', 'm1', None, 0, 0, 0, steps, 'linear') self.assertEqual(steps * 2, cmd.count_states('mout')) self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('mout')) cmd.morph('mo2', 'm1', None, 0, -1, 0, steps, 'linear') self.assertEqual(steps * 3, cmd.count_states('mo2')) self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('mo2'))
def testSaveANISO(self): cmd.read_pdbstr(v_pdbstr_anisou, 'm1') v = cmd.get_pdbstr() self.assertEqual(v, v_pdbstr_anisou, 'ANISOU records missing:\n' + v) cmd.rotate('y', 30, object='m1') cmd.translate([20, 0, 0], object='m1') cmd.rotate('z', 20, object='m1') v = cmd.get_pdbstr() self.assertEqual(v, v_pdbstr_rotated, 'ANISOU not rotated in PDB string' + v) v = cmd.get_model('m1').atom[0].u_aniso self.assertArrayEqual(v, [0.183853, 0.378995, 0.309052, -0.103350, 0.125751, 0.050349], 1e-5, 'ANISOU not rotated in chempy model')
def testOrigin(self): from chempy import cpv cmd.pseudoatom('m1') cmd.pseudoatom('m2') cmd.pseudoatom('m3', pos=[1,0,0]) # by selection cmd.origin('m3') cmd.rotate('y', 90, 'm1') # by position cmd.origin(position=[-1,0,0]) cmd.rotate('y', 90, 'm2') coords = [] cmd.iterate_state(1, 'm1 m2', 'coords.append([x,y,z])', space=locals()) d = cpv.distance(*coords) self.assertAlmostEqual(d, 2 * 2**0.5)
def testOrigin(self): from chempy import cpv cmd.pseudoatom('m1') cmd.pseudoatom('m2') cmd.pseudoatom('m3', pos=[1, 0, 0]) # by selection cmd.origin('m3') cmd.rotate('y', 90, 'm1') # by position cmd.origin(position=[-1, 0, 0]) cmd.rotate('y', 90, 'm2') coords = [] cmd.iterate_state(1, 'm1 m2', 'coords.append([x,y,z])', space=locals()) d = cpv.distance(*coords) self.assertAlmostEqual(d, 2 * 2**0.5)
def test_matrix_copy(self): cmd.fragment('ala') cmd.fragment('gly') cmd.rotate('x', 90, 'none', object='ala') cmd.matrix_copy('ala', 'gly') self.assertArrayEqual(cmd.get_object_matrix('gly'), (1.0, 0.0, 0.0, 0.0, 0.0, 0.0,-1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), 1e-4) cmd.matrix_reset('gly', mode=1) self.assertArrayEqual(cmd.get_object_matrix('gly'), (1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0), 1e-4)
def builderCorona(theta, fi, detergent, r, detR): # Build symmates with desired rotations thetaSteps = len(theta) angleVer = np.linspace(-90, 90, thetaSteps) i = 0 for t, a in zip(theta, angleVer): for f in fi: i += 1 cmd.copy(f"seg{i}", detergent) # corona cmd.rotate("x", f"{a}", f"seg{i}") cmd.translate(f"[0,{r + 0.5*detR*np.cos(np.deg2rad(a))},0]", f"seg{i}") cmd.translate(f"[0,0,{(r+detR)*np.sin(np.deg2rad(t))}]", f"seg{i}") cmd.rotate("z", f"{f}", f"seg{i}") cmd.create("corona", "seg*") cmd.delete("seg*")
def test_set_state_order(self): import numpy cmd.fragment('ala', 'm1') for i in (2, 3): cmd.create('m1', 'm1', i - 1, i); cmd.rotate('x', 10.0, 'm1', i) coords1 = cmd.get_coordset('m1', 1) coords3 = cmd.get_coordset('m1', 3) self.assertEqual(coords1.shape, (10, 3)) self.assertFalse(numpy.allclose(coords1, coords3)) cmd.set_state_order('m1', (3, 2, 1)) self.assertTrue(numpy.allclose(coords1, cmd.get_coordset('m1', 3))) self.assertTrue(numpy.allclose(coords3, cmd.get_coordset('m1', 1)))
def test_set_state_order(self): import numpy cmd.fragment('ala', 'm1') for i in (2, 3): cmd.create('m1', 'm1', i - 1, i) cmd.rotate('x', 10.0, 'm1', i) coords1 = cmd.get_coordset('m1', 1) coords3 = cmd.get_coordset('m1', 3) self.assertEqual(coords1.shape, (10, 3)) self.assertFalse(numpy.allclose(coords1, coords3)) cmd.set_state_order('m1', (3, 2, 1)) self.assertTrue(numpy.allclose(coords1, cmd.get_coordset('m1', 3))) self.assertTrue(numpy.allclose(coords3, cmd.get_coordset('m1', 1)))
def align_ligand(selection, center, angles): pos_halligand = get_pos(center) translation_vector = pos_halligand cmd.rotate("x", -angles[3], selection, 0, 0, origin=[0, 0, 0]) cmd.rotate("y", -angles[2], selection, 0, 0, origin=[0, 0, 0]) cmd.rotate("x", -angles[1], selection, 0, 0, origin=[0, 0, 0]) cmd.rotate("z", -angles[0], selection, 0, 0, origin=[0, 0, 0]) cmd.translate([ translation_vector[0][0], translation_vector[0][1], translation_vector[0][2] ], selection, -1, 0)
def show_result(tmpdir, ligname): n = 10 # number of positions of ligand ft_file = tmpdir + "/ft.000.0.0" rm_file = tmpdir + "/rm.000.0.0" ft_data = np.loadtxt(ft_file) rm_data = np.loadtxt(rm_file) for i in range(n): num_state = i + 1 name_copy = "copy_ligand_" + str(i) cmd.copy(name_copy, ligname) tv = ft_data[i, 1:4] rm = rm_data[i].reshape((3, 3)) en = ft_data[i, 4] cmd.translate(list(tv), name_copy) cmd.rotate(list(get_axis(rm)), get_angle(rm), name_copy) cmd.create("result", name_copy, 0, num_state) cmd.delete(name_copy) result = tmpdir + "/result_dock.pdb" cmd.save(result, "result") cmd.mplay()
def save_image(spath, name_maxlength, prefix = ''): fname = os.path.splitext(os.path.basename(spath))[0] image_name = prefix + image_filename(fname, name_maxlength) if exists(image_name): print 'Skip: ' + fname else: print 'Process: ' + fname cmd.load(spath, fname) cmd.disable('all') cmd.enable(fname) cmd.color('green', fname) cmd.h_add('(all)') cmd.show('surface') cmd.rotate([-1, 0.5, 0.5], 60) cmd.zoom(fname, -7.0, 0, 1) cmd.png(image_name) time.sleep(3) # wtf?! cmd.delete('all')
def test_rotate(self): from chempy import cpv from math import pi get_coord_list = lambda s: cmd.get_model(s).get_coord_list() cmd.fragment('ala') cmd.select('s1', 'hydro') c1_hydro = get_coord_list('s1') c1_other = get_coord_list('not s1') c1_hydro_rot = cpv.transform_array( cpv.rotation_matrix(pi * 0.25, [0, 0, 1]), c1_hydro) cmd.rotate('z', 45, 's1', camera=0, origin=(0, 0, 0)) c2_hydro = get_coord_list('s1') c2_other = get_coord_list('not s1') self.assertArrayEqual(c2_other, c1_other) self.assertArrayEqual(c2_hydro, c1_hydro_rot, 0.001)
def test_rotate(self): from chempy import cpv from math import pi get_coord_list = lambda s: cmd.get_model(s).get_coord_list() cmd.fragment('ala') cmd.select('s1', 'hydro') c1_hydro = get_coord_list('s1') c1_other = get_coord_list('not s1') c1_hydro_rot = cpv.transform_array( cpv.rotation_matrix(pi * 0.25, [0,0,1]), c1_hydro) cmd.rotate('z', 45, 's1', camera=0, origin=(0,0,0)) c2_hydro = get_coord_list('s1') c2_other = get_coord_list('not s1') self.assertArrayEqual(c2_other, c1_other) self.assertArrayEqual(c2_hydro, c1_hydro_rot, 0.001)
def save_image(spath, name_maxlength, prefix=''): fname = spath.split('/')[-1].split('.')[0] image_name = prefix + image_filename(fname, name_maxlength) if exists(image_name): print 'Skip: ' + fname else: print 'Process: ' + fname cmd.load(spath, fname) cmd.disable('all') cmd.enable(fname) cmd.color('green', fname) cmd.h_add('(all)') cmd.show('surface') cmd.rotate([-1, 0.5, 0.5], 60) cmd.zoom(fname, -7.0, 0, 1) cmd.png(image_name) time.sleep(3) # wtf?! cmd.delete('all')
def drowSaveN_ASUs(N,Type="Hexagonal",shape='round',ratio=1,UCp0=[0,0,0],UCa=310,UCb=100,UCaAng=0,UCbAng=60,name="ASU"): # note the 5 lines below are design specific and surpass the default input UCa, UCb, UCaAng, and UCbAng (which can than becaluculated from a,b, and UC-spacing) a = np.array((1,0)) # primitive vector "a" b = np.array((np.cos(60*np.pi/180),np.sin(60*np.pi/180))) # primitive vector "b" for p6 c0 = np.array((0.5,0.5*np.tan(30*np.pi/180))) # vector pointing from the UC corner to the oen of the C3 centers in a p6 symmetry c1 = 2*c0 # second C3 center in a p6 (also rotated by 180 around Z axis) b0 = a/2 # 90 rotation b1 = b/2 # 150 rotation b2 = (a+b)/2 # 30 rotation UC_spacing = int(537*2*np.cos(30*np.pi/180)/3) ########################## #name="ASU" # for selection purposes coefArray = genA_RotCentersInd(N,a,b,c0,shape='round') # indices of the UC for each ASU, the third element is the Z orientation (if 1 rotation of 180 degrees is applied) latticePos = genA_RotCentersPos(coefArray,a,b,c0)*UC_spacing # this is the set of ASUs CM position if ratio!=1: creatDilutedObj(name,ratio,name="ASUbase") name = "ASUbase" LofL = [] # Objects list for n,k in enumerate(range(N)): print("ASU location: ",latticePos[k]) objNew = createAndTranlateObj(name,count=k,name=name) # create a new object and return name of object print("objNew: ",objNew) cmd.color("blue", objNew+" and chain A+C+E+G+I+K") cmd.show( representation="dots", selection=objNew ) cmd.translate(list(latticePos[k]), selection = objNew,camera = 0) if coefArray[k,2]==1: cmd.rotate([0,0,1],180,selection=objNew ,camera=0,origin=latticePos[k]) LofL.append(objNew) #LofL.append([s]+LofL[n-1]) if n>0 else LofL.append([s]) # create list of list, each list contain print("Arrays object name: ", LofL) ### dumping list of selections (each dump will have an additional ASU ) A = [] # Aname = []
def test_update(self): # 3 states cmd.fragment('gly', 'm1') cmd.create('m1', 'm1', 1, 2) cmd.create('m1', 'm1', 1, 3) # second object, 90 degree rotates cmd.copy('m2', 'm1') cmd.rotate('x', 90, '(m2)', state=0) # reference coordsets cs = cmd.get_coordset cs1 = cs('m1', 1) cs2 = cs('m2', 1) # m2/3 will change (pre-check) self.assertArrayEqual(cs2, cs('m2', 3)) self.assertArrayNotEqual(cs1, cs('m2', 3)) # update explicit state cmd.update('m2', 'm1', 3, 2) # m2/3 has changed self.assertArrayEqual(cs1, cs('m2', 3)) self.assertArrayNotEqual(cs2, cs('m2', 3)) # these haven't changed self.assertArrayEqual(cs2, cs('m2', 1)) self.assertArrayEqual(cs2, cs('m2', 2)) # reset m2/3 cmd.load_coordset(cs2, 'm2', 3) self.assertArrayEqual(cs2, cs('m2', 3)) # update all states cmd.update('m2', 'm1', 0, 0) self.assertArrayEqual(cs1, cs('m2', 1)) self.assertArrayEqual(cs1, cs('m2', 2)) self.assertArrayEqual(cs1, cs('m2', 3))
def setUpAssembly(N,UCtype="hexagon32",colors=["colorCompA","colorCompB"]): if UCtype=="hexagon32": # unit cell promitive vectors and geometical parameters a = np.reshape(np.array((1,0,0)),(3,1)) # primitive vector "a" b = np.reshape(np.array((np.cos(60*np.pi/180),np.sin(60*np.pi/180),0)),(3,1)) # primitive vector "b" for p6 c0 = np.reshape(np.array((0.5,0.5*np.tan(30*np.pi/180),0)),(3,1)) # vector pointing from the UC corner to the oen of the C3 centers in a p6 symmetry c1 = 2*c0 # second C3 center in a p6 (also rotated by 180 around Z axis) b0 = a/2 # 90 rotation b1 = b/2 # 150 rotation b2 = (a+b)/2 # 30 rotation UC_spacing = int(537*2*np.cos(30*np.pi/180)/3) ### generate lattice parameters array for the A component (C3) coefArray = genA_RotCentersInd(N,a,b,c0,UC_spacing,shape='round') # note that coefArray[:,:,x] also determine the rotation of the ASU Adata = genA_RotCentersPos(coefArray,a,b,c0,UC_spacing)[1] # this was use to generate the lattice fro ma single ASU object ### generate lattice parameters array for the B component (C2) coefArrayB = genB_RotCentersInd(coefArray) Bdata = genB_RotCentersPos(coefArrayB,a,b) # here distances are still normalized (need to multiply with UC_spacing) Bdata[:,:2] = Bdata[:,:2]*UC_spacing #### databases to a list of objects objListA = [eval("compPymolObj")("A"+str(n[0]).zfill(4),"A"+str(n[0]).zfill(4),"A",3,n[1][:3],n[1][4]) for n in enumerate(Adata)] objListB = [eval("compPymolObj")("B"+str(n[0]).zfill(4),"B"+str(n[0]).zfill(4),"B",2,n[1][:3],n[1][4]) for n in enumerate(Bdata)] objListAll = objListA+objListB cmd.hide(representation="everything", selection="Acomp") cmd.hide(representation="everything", selection="Bcomp") ### initiation - generating and positioning all the objects for objComp in objListAll: # objListAll: list of objects of class compPymolObj instances to allow visualization #print("ASU location: ",latticePos[k]) createNewObj(objComp) # create a new pymol object namde (objComp.objName) from template named objComp.compType #cmd.color("blue", objNew+" and chain A+C+E+G+I+K") #cmd.show( representation="dots", selection=objNew ) cmd.translate(list(objComp.loc), selection = objComp.objName,camera = 0) rotationAngleAroundZ = np.round(objComp.orientation.as_euler('xyz')[2]*180/np.pi,4) cmd.rotate([0,0,1],rotationAngleAroundZ,selection=objComp.objName ,camera=0,origin=list(objComp.loc)) cmd.color('colorCompA',objComp.objName) if objComp.compType=="A" else cmd.color('colorCompB',objComp.objName) return objListAll
def drowN_ASUs(N,Type="Hexagonal",shape='round',UCp0=[0,0,0],UCa=310,UCb=100,UCaAng=0,UCbAng=60,name="ASU"): # note the 5 lines below are design specific and surpass the default input UCa, UCb, UCaAng, and UCbAng (which can than becaluculated from a,b, and UC-spacing) a = np.array((1,0)) b = np.array((np.cos(60*np.pi/180),np.sin(60*np.pi/180))) c0 = np.array((0.5,0.5*np.tan(30*np.pi/180))) c1 = 2*c0 UC_spacing = int(537*2*np.cos(30*np.pi/180)/3) ########################## #name="ASU" # for selection purposes coefArray = genA_RotCentersInd(N,a,b,c0,shape='round') # indices of the UC for each ASU, the third element is the Z orientation (if 1 rotation of 180 degrees is applied) latticePos = genA_RotCentersPos(coefArray,a,b,c0)*UC_spacing # this is the set of ASUs CM position LofL = [] # Objects list for n,k in enumerate(range(N)): print("ASU location: ",latticePos[k]) objNew = createAndTranlateObj("ASU",count=k,name="ASU") # create a new object and return name of object cmd.translate(list(latticePos[k]), selection = objNew,camera = 0) if coefArray[k,2]==1: cmd.rotate([0,0,1],180,selection=objNew ,camera=0,origin=latticePos[k]) LofL.append(objNew) #LofL.append([s]+LofL[n-1]) if n>0 else LofL.append([s]) # create list of list, each list contain print("Arrays object name: ", LofL)
def undock(chains, type): for chainOrName in chains: selection_string = f'chain {chainOrName}' if type is 'cif' else chainOrName translation_vector = [ random.randrange(MIN_UNDOCK_DISTANCE, MAX_UNDOCK_DISTANCE), random.randrange(MIN_UNDOCK_DISTANCE, MAX_UNDOCK_DISTANCE), random.randrange(MIN_UNDOCK_DISTANCE, MAX_UNDOCK_DISTANCE) ] cmd.translate(translation_vector, selection_string) cmd.rotate('x', random.randrange(-360, 360), selection_string) cmd.rotate('y', random.randrange(-360, 360), selection_string) cmd.rotate('z', random.randrange(-360, 360), selection_string)
def moveInPymol(self, solutionPymolString, chromosome, state): # recreate protein B at solution coordinates cmd.create(solutionPymolString, self.pymolString, 1, state) # translate to origin with proteinBcog. IMPORTANT: set camera to "0" so that the translation is not done along the camera coordinate system! cmd.translate(list(-1 * self.labelAtomsCog.reshape(-1, )), solutionPymolString, state, 0, None) # rotate and translate according to solution translation = chromosome.genes[3:6] rotX = chromosome.genes[0] # IMPORTANT: set camera to "0" so that the translation is not done along the camera coordinate system! Also set rotation origin to 0,0,0! cmd.rotate([1, 0, 0], rotX, solutionPymolString, state, 0, None, [0, 0, 0]) rotY = chromosome.genes[1] cmd.rotate([0, 1, 0], rotY, solutionPymolString, state, 0, None, [0, 0, 0]) rotZ = chromosome.genes[2] cmd.rotate([0, 0, 1], rotZ, solutionPymolString, state, 0, None, [0, 0, 0]) cmd.translate(list(translation.reshape(-1, )), solutionPymolString, state, 0, None) if chromosome.symmetry != "None": if chromosome.symmetry == "C2": monomers = 2 elif chromosome.symmetry == "C3": monomers = 3 elif chromosome.symmetry == "C4": monomers = 4 elif chromosome.symmetry == "C5": monomers = 5 elif chromosome.symmetry == "C6": monomers = 6 elif chromosome.symmetry == "C7": monomers = 7 elif chromosome.symmetry == "C8": monomers = 8 angle = 360.0 / monomers for i in range(1, monomers): cmd.create(solutionPymolString, solutionPymolString, 1, state + i) cmd.rotate([1, 0, 0], i * angle, solutionPymolString, state + i, 0, None, [0, 0, 0])
def rpcRotate(vect, objName='', state=-1): """ rotates objects Arguments: - vect: a sequence with x y and z rotations - objName: (OPTIONAL) object to be rotated - state: (OPTIONAL) if zero only visible states are rotated, if -1 (the default), all states are rotated """ cmd.rotate('x', vect[0], objName, state=state) cmd.rotate('y', vect[1], objName, state=state) cmd.rotate('z', vect[2], objName, state=state) return 1
def setOrientation(objList): ''' Updates the class instances with orientation matrix - this will occure only for non bound component input: objList all the system intances of class compPymolObj ouput: updated .orientation value with randomely generated orientation matrix ''' for N,obj in enumerate(objList): if obj.bound==False: anglesVector = (np.random.rand(3)-0.5)*30 # degrees RotObj = R.from_euler('xyz',anglesVector,degrees=True) # arbitrary rotation object around each axis in the range of [-45,45] degrees obj.orientation = obj.orientation*RotObj cmd.rotate([1,0,0],anglesVector[0],selection=obj.objName ,camera=0,origin=list(obj.loc)) cmd.rotate([0,1,0],anglesVector[1],selection=obj.objName ,camera=0,origin=list(obj.loc)) cmd.rotate([0,0,1],anglesVector[2],selection=obj.objName ,camera=0,origin=list(obj.loc)) return objList
# Create one-to-one mapping between states and frames. cmd.mset("1 -%d" % cmd.count_states()) # Zoom viewport cmd.zoom('complex') #cmd.orient('complex') #cmd.zoom('ligand') #cmd.orient('ligand') #cmd.turn('x', -90) # Render movie frame_prefix = 'frames/frame' cmd.set('ray_trace_frames', 1) cmd.set('ray_trace_frames', 0) # DEBUG for iteration in range(niterations): print "rendering frame %04d / %04d" % (iteration+1, niterations) cmd.frame(iteration+1) cmd.rotate([0,0,1], 1, 'all') state_index = int(ncfile.variables['states'][iteration, replica]) cmd.set('sphere_transparency', float(state_index) / float(nstates-1), 'ligand') cmd.png(frame_prefix + '%04d.png' % (iteration), ray=True) #cmd.mpng(frame_prefix, iteration+1, iteration+1) #cmd.load_model(model, 'complex') cmd.set('ray_trace_frames', 0) # Close file ncfile.close()