Exemplo n.º 1
0
 def __setstate__(self, state):
   name, files, types, reps = state
   self.id = molecule.new(name, 0)
   for file, type in zip(files, types):
     self.load(file, type)
   self.clearReps()
   for rep in reps:
     self.addRep(rep)
Exemplo n.º 2
0
 def __setstate__(self, state):
     name, files, types, reps = state
     self.id = molecule.new(name, 0)
     for file, type in zip(files, types):
         self.load(file, type)
     self.clearReps()
     for rep in reps:
         self.addRep(rep)
Exemplo n.º 3
0
  def __init__(self, name=None, id=None, atoms=0):
    """
    Creating a new Molecule instance with no arguments will create a new 
    empty molecule in VMD.  Passing a valid molecule id will make the 
    Molecule instance mirror the state of the corresponding molecule in VMD. 
    If id is None, and a name is given, the new molecule will have that name.
    """
    if id is None:
      if name is None:
        name = "molecule"
      self.id = molecule.new(name, atoms)
    else:
      self.id = id
      self.atoms = molecule.numatoms(self.id)

    if not molecule.exists(self.id):
      raise ValueError, "Molecule with id %d does not exist." % self.id
Exemplo n.º 4
0
    def __init__(self, name=None, id=None, atoms=0):
        """
    Creating a new Molecule instance with no arguments will create a new 
    empty molecule in VMD.  Passing a valid molecule id will make the 
    Molecule instance mirror the state of the corresponding molecule in VMD. 
    If id is None, and a name is given, the new molecule will have that name.
    """
        if id is None:
            if name is None:
                name = "molecule"
            self.id = molecule.new(name, atoms)
        else:
            self.id = id
            self.atoms = molecule.numatoms(self.id)

        if not molecule.exists(self.id):
            raise ValueError, "Molecule with id %d does not exist." % self.id
Exemplo n.º 5
0
def vmd_draw_angle(molid,
                   frame,
                   atomids=None,
                   atm_coords=None,
                   canvas=False,
                   resolution=200,
                   radius=0.5,
                   drawcolor="blue",
                   cylinder_radius=0.01):
    """
    Draws part of a circle to visualize the measured angle.

        Input:
            > moldid     int; index of molecule to draw the angle for
            > frame      int; frame number to draw the angle for
            > atomids    tuple; all three atom ids with second one as angular
                         point
            > canvas     boolean; draw a canvas between bow and angle axis
            > resolution int; number of cylinders and spheres that form the angle

    """
    if atomids is not None:
        id1, id2, id3 = atomids
        # select all atoms
        sel = atomsel.atomsel("all", molid, frame)
        # get coordinates
        x = sel.get("x")
        y = sel.get("y")
        z = sel.get("z")
        # get rotational axis
        atm1Crds = np.array([x[id1], y[id1], z[id1]])
        atm2Crds = np.array([x[id2], y[id2], z[id2]])
        atm3Crds = np.array([x[id3], y[id3], z[id3]])
    elif atm_coords is not None:
        atm1Crds, atm2Crds, atm3Crds = atm_coords
    else:
        raise Warning(
            "At least atomic coordinates or atom ids have to be provided!")

    # draw bows in the current molecule, transparent canvas in a new molecule
    if canvas is True:
        molecule.new("angle canvas")
        graphics_id = molecule.num() - 1  # ids start with 0
    else:
        graphics_id = molid

    graphics.color(graphics_id, drawcolor)

    #pdb.set_trace()
    # define angle and rotational axis
    vt1 = atm1Crds - atm2Crds
    vt2 = atm3Crds - atm2Crds
    vtRot = np.cross(vt1, vt2)

    # unit vectors for quaternions
    vt1 /= np.linalg.norm(vt1)
    vt2 /= np.linalg.norm(vt2)
    vtRot /= np.linalg.norm(vtRot)

    # define angle offset
    max_angle = np.arccos(np.dot(
        vt1, vt2))  # denominator is 1 since vectors are normed
    print("Measured angles: {}".format(np.degrees(max_angle)))
    angle_offset = np.pi / resolution

    vt1 *= radius
    vt2 *= radius

    for cntr, theta in enumerate(np.arange(0, max_angle, angle_offset)):
        # previous vector
        if cntr == 0:
            vt_pre = vt1 + atm2Crds

        # define quaternion
        q = Quaternion(axis=vtRot, angle=theta)
        #print(q)

        # rotate vector
        vt_cur = q.rotate(vt1)
        vt_cur += atm2Crds

        if canvas is True and cntr != 0:
            graphics.triangle(graphics_id, tuple(vt_pre), tuple(atm2Crds),
                              tuple(vt_cur))
        else:
            graphics.cylinder(graphics_id,
                              tuple(vt_pre),
                              tuple(vt_cur),
                              radius=cylinder_radius,
                              resolution=20,
                              filled=1)
        vt_pre = vt_cur

    if canvas is True:
        graphics.triangle(graphics_id, tuple(vt_pre), tuple(atm2Crds),
                          tuple(vt2 + atm2Crds))
        graphics.material(graphics_id, "Transparent")
    else:
        graphics.cylinder(graphics_id,
                          tuple(vt_pre),
                          tuple(vt2 + atm2Crds),
                          radius=cylinder_radius,
                          resolution=20,
                          filled=1)
Exemplo n.º 6
0
def draw_torsion(molid,
                 frame,
                 atomids,
                 canvas=False,
                 resolution=50,
                 radius=0.5,
                 drawcolor="blue"):
    """
    """
    id1, id2, id3, id4 = atomids

    # draw bows in the current molecule, transparent canvas in a new molecule
    if canvas is True:
        molecule.new("angle canvas")
        graphics_id = molecule.num() - 1  # ids start with 0
    else:
        graphics_id = molid

    graphics.color(graphics_id, drawcolor)

    # select all atoms
    sel = atomsel.atomsel("all", molid, frame)

    # get coordinates
    x = sel.get("x")
    y = sel.get("y")
    z = sel.get("z")

    # get rotational axis
    atm1Crds = np.array([x[id1], y[id1], z[id1]])
    atm2Crds = np.array([x[id2], y[id2], z[id2]])
    atm3Crds = np.array([x[id3], y[id3], z[id3]])
    atm4Crds = np.array([x[id4], y[id4], z[id4]])

    # define angle and rotational axis
    #vt1    = atm1Crds - atm2Crds
    #vt2    = atm3Crds - atm2Crds
    #vtRot  = np.cross(vt1, vt2)

    # unit vectors for quaternions
    #vt1   /= np.linalg.norm(vt1)
    #vt2   /= np.linalg.norm(vt2)
    #vtRot /= np.linalg.norm(vtRot)
    #print(atm1Crds)
    _, cp1, cp2 = ag_geometry.get_dihedral(atm1Crds,
                                           atm2Crds,
                                           atm3Crds,
                                           atm4Crds,
                                           return_cross=True)

    # draw vectors between id2 and id3, therefor get the relevant vector
    center_pt = atm2Crds + (atm3Crds - atm2Crds) * 0.5
    cp1 += center_pt
    cp2 += center_pt
    vmd_draw_angle(molid,
                   frame,
                   atm_coords=[cp1, center_pt, cp2],
                   canvas=False,
                   resolution=resolution,
                   radius=radius,
                   drawcolor="blue")