Exemple #1
0
def vmd_load_molecule(coordsfile,
                      filetype="lammpsdata",
                      dcd=None,
                      selection="all",
                      scale=1.0,
                      molid=0,
                      vmd_material="Basic1Pantone",
                      style="CPK 1.000000 0.300000 12.000000 12.000000"):
    """
    """
    if not molecule.exists(molid):

        # load molecule in vmd
        if dcd is not None:
            molecule.load(filetype, coordsfile, "dcd", dcd)
        else:
            molecule.load(filetype, coordsfile)

        molrep.modrep(molid,
                      0,
                      style=style,
                      material=vmd_material,
                      color="Name",
                      sel=selection)
        #trans.scale(scale)
        VMD.evaltcl("scale to {}".format(scale))
Exemple #2
0
 def changeMaterial(self, material):
   """ Change the material for the rep to 'material'."""
   for id,name in self.molecules.items():
     repid = molrep.repindex(id, name)
     if not molrep.modrep(id, repid, material=material):
       raise ValueError, "Invalid material'%s'" % material 
   self.material = str(material)
Exemple #3
0
 def changeSelection(self, selection):
   """ Change the atom selection of the rep to 'selection'."""
   for id,name in self.molecules.items():
     repid = molrep.repindex(id, name)
     if not molrep.modrep(id, repid, sel=selection):
       raise ValueError, "Invalid selection '%s'" % selection 
   self.selection = str(selection)
Exemple #4
0
 def changeColor(self, color):
   """ Change the coloring method the rep to 'color'."""
   for id,name in self.molecules.items():
     repid = molrep.repindex(id, name)
     if not molrep.modrep(id, repid, color=color):
       raise ValueError, "Invalid color '%s'" % color 
   self.color = str(color)
Exemple #5
0
 def changeStyle(self, style):
   """ Change the draw style of the rep to 'style'."""
   for id,name in self.molecules.items():
     repid = molrep.repindex(id, name)
     if not molrep.modrep(id, repid, style=style):
       raise ValueError, "Invalid style '%s'" % style
   self.style = str(style)
Exemple #6
0
 def changeMaterial(self, material):
     """ Change the material for the rep to 'material'."""
     for id, name in self.molecules.items():
         repid = molrep.repindex(id, name)
         if not molrep.modrep(id, repid, material=material):
             raise ValueError, "Invalid material'%s'" % material
     self.material = str(material)
Exemple #7
0
 def changeSelection(self, selection):
     """ Change the atom selection of the rep to 'selection'."""
     for id, name in self.molecules.items():
         repid = molrep.repindex(id, name)
         if not molrep.modrep(id, repid, sel=selection):
             raise ValueError, "Invalid selection '%s'" % selection
     self.selection = str(selection)
Exemple #8
0
 def changeColor(self, color):
     """ Change the coloring method the rep to 'color'."""
     for id, name in self.molecules.items():
         repid = molrep.repindex(id, name)
         if not molrep.modrep(id, repid, color=color):
             raise ValueError, "Invalid color '%s'" % color
     self.color = str(color)
Exemple #9
0
 def changeStyle(self, style):
     """ Change the draw style of the rep to 'style'."""
     for id, name in self.molecules.items():
         repid = molrep.repindex(id, name)
         if not molrep.modrep(id, repid, style=style):
             raise ValueError, "Invalid style '%s'" % style
     self.style = str(style)
Exemple #10
0
VMD.evaltcl("display shadows off")
color_display = color.get_colormap("Display")
color_display["Background"] = "white"
color.set_colormap("Display", color_display)
display.set(depthcue=0)

# load mol and change its representation
# geometry optimized cbz
licor_style = "Licorice 0.1 50 50"
sel_no_h = "not element H"

if molecule.exists(0) != 1:
    molecule.load("xyz", cbz_gOpt)
    molrep.modrep(0,
                  0,
                  sel=sel_no_h,
                  style=licor_style,
                  material="AOChalky",
                  color="ColorID 7")

if molecule.exists(1) != 1:
    #molecule.load("lammpsdata", cbz_gaff2_lmpdat, "dcd", cbz_gaff2_dcd)
    molecule.load("lammpsdata", cbz_gaff2_lmpdat)
    molrep.modrep(1,
                  0,
                  sel=sel_no_h,
                  style=licor_style,
                  material="AOChalky",
                  color="ColorID 0")

if molecule.exists(2) != 1:
    #molecule.load("lammpsdata", cbz_gaff_lmpdat, "dcd", cbz_gaff_dcd)
Exemple #11
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)