예제 #1
0
def getWaterLocations(f, TOP, TRAJ, printNumFrames):
	print("Start getWaterLocations()")
	molid = molecule.load(getFileType(TOP), TOP)
	molecule.read(molid, getFileType(TRAJ), TRAJ, beg=1, end=-1, skip=1, waitfor=-1)
	n_frames = molecule.numframes(molid)
	if(printNumFrames): f.write("numFrames:" + str(n_frames) + "\n")
	grid = create_grid(n_frames)
	print_file_header(f)
	waters = atomsel.atomsel('water', molid= molid)
	# waters = atomsel.atomsel('resname IP3', molid= molid)
	coords = getAllCoords(molid, n_frames)
	return grid, waters, coords, n_frames
예제 #2
0
 def replot(self):
     if self.fig is None or self.ax is None:
         return
     self.ax.cla()
     self.ax.set_xlabel('Frame')
     if self.observable is not None:
         self.ax.plot(self.observable, 'r.')
     self.ax.plot(self.change_times, 0.5 * (self.ylim[0] + self.ylim[1])
             * np.ones(len(self.change_times)), 'ro')
     self.ax.set_xlim((0, molecule.numframes(self.molid)))
     self.ax.set_ylim(self.ylim)
     self.fig.canvas.draw()
     self.dataplot = self.fig.canvas.copy_from_bbox(self.ax.bbox)
예제 #3
0
 def numFrames(self):
   """ Returns the number of coordinate frames in the molecule. """
   return molecule.numframes(self.id)
예제 #4
0
    #### Read in input topology, trajectory files, outTraj file
    top_file = sys.argv[1]
    traj_file = sys.argv[2]
    out_traj_file = sys.argv[3]
    if ("-crys" in sys.argv):
        include_crys = True
    else:
        include_crys = False

    #### load topology and trajectories
    traj_molid = molecule.load('pdb', top_file)
    molecule.read(traj_molid, 'netcdf', traj_file, beg=0, end=-1, waitfor=-1)

    #### align all frames
    refsel = atomsel("protein", molid=traj_molid, frame=0)
    for i in range(molecule.numframes(traj_molid)):
        molecule.set_frame(traj_molid, i)
        b = atomsel("protein", molid=traj_molid, frame=i)
        T = b.fit(refsel)
        atomsel("all", molid=traj_molid, frame=i).move(T)

    #### Read out file
    if (include_crys == True):
        molecule.write(traj_molid, 'dcd', out_traj_file, beg=0, end=-1)
    else:
        molecule.write(traj_molid, 'dcd', out_traj_file, beg=1, end=-1)

    toc = time.clock()
    print("Time for wrapAlign.py = " + str(toc - tic))
예제 #5
0
def set_times(molid, times):
    import molecule
    offset = molecule.numframes(molid) - len(times)
    assert offset == 1 or offset == 0 # frame 0 may be the system file
    for i, t in enumerate(times):
        molecule.set_physical_time(t, molid, i+offset)
예제 #6
0
    def showtime(self, frame, old_frame):
        if not self.loaded_frames:
            # Initialize display
            self.loaded_frames = True
            numframes = molecule.numframes(self.molid)
            self.pairs = [set() for i in range(numframes)]
            self.gray_res_sels = ['none' for i in range(numframes)]
            self.color_res_sels = ['none' for i in range(numframes)]
            first_frame = 0
            for i, time in enumerate(self.change_times):
                while first_frame < numframes and first_frame < time:
                    first_frame += 1
                if first_frame > numframes - min(6, self.window + 1):
                    break
                if first_frame < min(5, self.window):
                    continue
                begin = max(first_frame - self.window, 0)
                for j in range(i-1,-1,-1):
                    if self.change_times[j] <= begin:
                        break
                    if len(self.changes[self.change_times[j]] & self.changes[self.change_times[i]]) > 0:
                        begin = 0
                        while begin < first_frame and begin < self.change_times[j]:
                            begin += 1
                        break
                end = min(first_frame + self.window, numframes)
                for j in range(i+1, len(self.change_times)):
                    if self.change_times[j] > end-1:
                        break
                    if len(self.changes[self.change_times[j]] & self.changes[self.change_times[i]]) > 0:
                        end = numframes
                        while end > first_frame and end-1 >= self.change_times[j]:
                            end -= 1
                        break
                if begin >= first_frame or end <= first_frame + 1:
                    continue
                all_changed = []
                for pair in self.changes[time]:
                    a0_all = self._info_to_ids(pair[0])
                    a1_all = self._info_to_ids(pair[1])
                    for a0 in a0_all:
                        for a1 in a1_all:
                            before_dists = [float(v) for v in vmd.VMDevaltcl(
                                'measure bond {%d %d} molid %d first %d last %d'
                                % (a0, a1, self.molid, begin,
                                    first_frame-1)).split()]
                            before_med = np.median(before_dists)
                            after_dists = [float(v) for v in vmd.VMDevaltcl(
                                'measure bond {%d %d} molid %d first %d last %d' 
                                % (a0, a1, self.molid, first_frame,
                                    end-1)).split()]
                            after_med = np.median(after_dists)
                            if self.label_before_after is not None:
                                label_before, label_after = \
                                        self.label_before_after(
                                                before_med, after_med, a0, a1)
                            else:
                                label_before = False
                                label_after = False
                            if label_before:
                                self.pairs[first_frame-1].add((a0,a1))
                            if label_after:
                                self.pairs[first_frame].add((a0,a1))
                    all_changed += list(a0_all) + list(a1_all)
                for f in range(begin, end):
                    sel = 'same residue as index'
                    for changed_atom in all_changed:
                        sel += ' %d' % changed_atom
                    if self.disp_h:
                        sel = ' or (%s)' % sel
                    else:
                        sel = ' or ((' + sel + ') and not (element H and' + \
                            ' withinbonds 1 of element C))'
                        if f == first_frame - 1 or f == first_frame:
                            self.color_res_sels[f] += sel
                        else:
                            self.gray_res_sels[f] += sel
            old_frame = None
        gray_repid = molrep.repindex(self.molid, self.gray_rep)
        if gray_repid == -1:
            # User deleted molrep to display residues--recreate this molrep
            molrep.addrep(self.molid, style='Licorice', color='ColorID 2',
                    selection='none', material='Opaque')
            self.gray_rep = molrep.get_repname(self.molid,
                    molrep.num(self.molid)-1)
            gray_repid = molrep.repindex(self.molid, self.gray_rep)
            old_frame = None
        color_repid = molrep.repindex(self.molid, self.color_rep)
        if color_repid == -1:
            # User deleted molrep to display residues--recreate this molrep
            molrep.addrep(self.molid, style='Licorice', color='Element',
                    selection='none', material='Opaque')
            self.color_rep = molrep.get_repname(self.molid,
                    molrep.num(self.molid)-1)
            color_repid = molrep.repindex(self.molid, self.color_rep)
            old_frame = None
        if old_frame is None \
                or self.gray_res_sels[old_frame] != self.gray_res_sels[frame]:
            molrep.modrep(self.molid, gray_repid, sel=self.gray_res_sels[frame])
        if old_frame is None or \
                self.color_res_sels[old_frame] != self.color_res_sels[frame]:
            molrep.modrep(self.molid, color_repid,
                    sel=self.color_res_sels[frame])
        if old_frame is None or self.pairs[old_frame] != self.pairs[frame]:
            labels = label.listall(label.BOND)
            for l in labels:
                label.delete(label.BOND, l)
            os.environ['VMD_QUIET_STARTUP'] = '1'
            molid_pair = (self.molid, self.molid)
            for pair in self.pairs[frame]:
                label.add(label.BOND, molid_pair, pair)
            os.environ.pop('VMD_QUIET_STARTUP')

        # Update plot of indicator variable
        if self.fig is None or self.fig.canvas.window is None:
            # Figure has not been created or was closed by user--create new
            # figure
            self.fig = plt.figure()
            # Need to replot everything if the figure window is resized
            self.fig.canvas.mpl_connect('resize_event', lambda ev,
                    s=self: s.replot())
            self.fig.show()
            self.ax = self.fig.add_subplot(111)
            self.line = self.ax.axvline(0, animated=True, color='r',
                    linewidth=2)
            self.replot()
        self.fig.canvas.restore_region(self.dataplot)
        self.line.set_xdata(frame)
        self.ax.draw_artist(self.line)
        self.fig.canvas.blit(self.ax.bbox)
예제 #7
0
 def numFrames(self):
     """ Returns the number of coordinate frames in the molecule. """
     return molecule.numframes(self.id)